Can somebody tell me how to do bolding and Italicizing plus underlining
I have just started getting serious after long time "milk drinking", now I want to eat solid food.
Thanks all,
Steve
import wx
ID_EXIT =100
ID_BOLD = 101
ID_ITALIC = 102
ID_UNDERLINE = 103
ID_TEXT = 104
class SimpleEditor(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title)
#Add Menu Bar
menubar = wx.MenuBar()
self.SetMenuBar(menubar)
#file menu is added
filemenu = wx.Menu()
menubar.Append(filemenu, '&File')
filemenu.Append(ID_EXIT, '&Quit', 'Quit the Program')
# define events
wx.EVT_MENU(self, ID_EXIT, self.OnExit)
#Add panel
MainPanel = wx.Panel(self, -1)
# define sizers
MainSizer = wx.BoxSizer(wx.VERTICAL)
#toolbars font
tb1 = wx.ToolBar(MainPanel, -1)
tb1.AddLabelTool(wx.ID_BOLD, '', wx.Bitmap('./icon/format-text-bold.png'))
tb1.AddLabelTool(wx.ID_ITALIC, '', wx.Bitmap('./icon/format-text-italic.png'))
tb1.AddLabelTool(wx.ID_UNDERLINE, '', wx.Bitmap('./icon/format-text-underline.png'))
#tb1.SetToolBitmapSize((24,24 ))
tb1.Realize()
#add to sizer
MainSizer.Add(tb1, proportion = 0, flag = wx.EXPAND)
#set up event handlers
wx.EVT_MENU(self, ID_BOLD, self.OnBold)
#wx.EVT_MENU(self, ID_ITALIC, self.OnItalic)
#wx.EVT_MENU(self, ID_UNDERLINE, self.OnUnderline)
# toolbar other ops
tb2 = wx.ToolBar(MainPanel, -1)
tb2.AddLabelTool(ID_EXIT, '', wx.Bitmap('./icon/process-stop.png'))
tb2.Realize()
MainSizer.Add(tb2, proportion = 0, flag = wx.EXPAND | wx.TOP, border = 0 )
#Add text control
Tarea = wx.TextCtrl(MainPanel, ID_TEXT, style = wx.TE_MULTILINE)
#add to main sizer
MainSizer.Add(Tarea, 1, wx.EXPAND |wx.LEFT |wx.RIGHT |wx.BOTTOM, 2)
#set main sizer
MainPanel.SetSizer(MainSizer)
self.Center()
self.Show(True)
#start events exit
def OnExit(self, event):
mess = wx.MessageDialog(self, 'Are you sure you want to Quit?', 'Confirm', style = wx.YES |wx.NO |wx.ICON_QUESTION)
ret = mess.ShowModal()
if ret == wx.ID_YES:
self.Destroy()
else :
SimpleEditor.event()
#start events edit toolbar
def OnBold(self, event):
selected = GetStringSelection(self)
selected = selected.SetWeight(self, Bold)
return selected
app = wx.App(False)
SimpleEditor(None, -1,'Text Editor')
app.MainLoop()