1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| # !/usr/bin/python
# -*- coding:Latin-1 -*-
import wx
import wx.richtext as rt
import os
import images
class WidgetRichText(rt.RichTextCtrl):
def __init__(self, parent,size=(300,300)):
rt.RichTextCtrl.__init__(self,parent,-1,size=size)
rt.RichTextCtrl.WriteText(self,"Mon widget RichText")
rt.RichTextCtrl.SetScrollbar(self,wx.VERTICAL, 10, 10, 10)
rt.RichTextCtrl.SetScrollbar(self,wx.HORIZONTAL, 100, 160, 30)
class MyToolBar(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title)
### Création d'1 Toolbar :
toolbar = wx.ToolBar(parent, -1, style=wx.TB_HORIZONTAL | wx.NO_BORDER)
toolbar.AddTool(1, images.get_rt_openBitmap(),shortHelpString="Open")
toolbar.AddTool(2, images.get_rt_saveBitmap(),shortHelpString="Save")
toolbar.AddTool(3, images.get_rt_cutBitmap(),shortHelpString="Cut")
toolbar.AddTool(4, images.get_rt_copyBitmap(),shortHelpString="Copy")
toolbar.AddSeparator()
toolbar.Realize()
### Mise en place de l'ensemble de la toolbar à l'aide d'1 sizer :
box = wx.BoxSizer(wx.HORIZONTAL)
box.Add(toolbar, 0, wx.ALL, 0)
self.SetSizer(box)
class Fentre_prin(wx.Frame):
def __init__(self, parent, title='Fenetre principale'):
wx.Frame.__init__(self, parent, -1, title,size=(500,500))
### Conteneur :
panel1 = wx.Panel(self, wx.ID_ANY,size=(500,500)) # pour panel1 et panel2
panel2 = wx.Panel(panel1, wx.ID_ANY,size=(100,100)) # pour ToolBar
panel3 = wx.Panel(panel1, wx.ID_ANY,size=(400,400)) # pour RichText
### Barre Outils :
barre=MyToolBar(panel2, -1, '')
### RichTextCtrl :
myrichtext1 = WidgetRichText(panel3,size=(100,100))
### Création du 1er sizer et positionnement des 2 panels :
sizer_panel1 = wx.BoxSizer(wx.VERTICAL)
sizer_panel1.Add(panel2, 0, wx.ALL, 0)
sizer_panel1.Add(panel3, 0, wx.ALL, 0)
self.SetSizer(sizer_panel1)
### 2ème sizer pour positionnement de la richtext :
sizer_panel3 = wx.BoxSizer(wx.VERTICAL)
sizer_panel3.Add(myrichtext1, 0, wx.ALL, 0)
panel3.SetSizer(sizer_panel3)
def quitter(self, evt):
self.Close()
class MyApp(wx.App):
def OnInit(self):
frame = Fentre_prin(None)
self.SetTopWindow(frame)
frame.Show(True)
return True
try:
app = MyApp()
except:
app = MyApp(redirect=True)
app.MainLoop() |
Partager