I want to subclass My App and I hit the wall. If I don't subclass it works!
WHAT IS WRONG HERE????
import wx
ID_NEW = 10
ID_OPEN = 11
ID_CLOSE = 12
ID_SAVE = 13
ID_SAVE_AS = 14
ID_PAGE_SETUP = 15
ID_PRINT_PREVIEW = 16
ID_PRINT = 17
ID_EXIT = 18
ID_UNDO = 19
ID_REDO = 20
ID_SEARCH = 21
ID_SPELL = 22
ID_HELP = 23
class TextEditor(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(350, 600))
# self/Text editor is now a Window with all attribute of a frame
# create status bar
self.CreateStatusBar()
# set default status bar string
self.SetStatusText("For help press F1")
# define sizers
vbox = wx.BoxSizer(wx.VERTICAL)
hbox = wx.BoxSizer(wx.HORIZONTAL)
#Add menu
#define menubar and menu
menubar = wx.MenuBar()
# attach menubar to the frame
self.SetMenuBar(menubar)
#define menus
filemenu = wx.Menu()
# Append items
filemenu.Append(ID_NEW, "&New", "New Blank file")
filemenu.Append(ID_OPEN, "&Open", "Open file")
filemenu.Append(ID_CLOSE, "&Close", "Close file")
#-----------------------------------------------
filemenu.AppendSeparator()
filemenu.Append(ID_SAVE, "&Save", "Save changes")
filemenu.Append(ID_SAVE_AS, "Save As...", "Save to different location")
#-----------------------------------------------------
filemenu.AppendSeparator()
filemenu.Append(ID_PAGE_SETUP, "Page set&up", "Set up properties before printing")
filemenu.Append(ID_PRINT_PREVIEW, "Print pre&view", "Preview before printing")
filemenu.Append(ID_PRINT, "&Print", "Print file")
#-------------------------------------------------------
filemenu.AppendSeparator()
filemenu.Append(ID_EXIT, "E&xit", "Close the program")
menubar.Append(filemenu, "&File")
editmenu = wx.Menu()
menubar.Append(editmenu, "&Edit")
viewmenu = wx.Menu()
menubar.Append(viewmenu, "&View")
formatmenu = wx.Menu()
menubar.Append(formatmenu, "F&ormat")
toolsmenu = wx.Menu()
menubar.Append(toolsmenu, "&Tools")
helpmenu = wx.Menu()
menubar.Append(helpmenu, "&Help")
#------------------------------------
# Define Event handlers
#also you can bind event using method below
#self.Bind(wx.EVT_MENU, ID_EXIT, self.OnExit)
wx.EVT_MENU (self, ID_EXIT, self.OnExit)
# Add toolbars
toolbar1 = wx.ToolBar(self, -1)
toolbar1.SetToolBitmapSize((24,24 ))
toolbar1.AddLabelTool(ID_SAVE, '', wx.Bitmap('./icons/save.png'))
toolbar1.AddLabelTool(ID_UNDO, '', wx.Bitmap('./icons/undo.png'))
toolbar1.AddLabelTool(ID_REDO, '', wx.Bitmap('./icons/redo.png'))
toolbar1.AddLabelTool(ID_SEARCH, '', wx.Bitmap('./icons/search.png'))
toolbar1.AddLabelTool(ID_SPELL, '', wx.Bitmap('./icons/spellcheck.png'))
toolbar1.AddLabelTool(ID_HELP, '', wx.Bitmap('./icons/help.png'))
toolbar1.Realize()
#---------------------------------------------------------
#Add to sizer
vbox_toolbars = wx.BoxSizer(wx.VERTICAL)
vbox_toolbars.Add(toolbar1, proportion = 0, flag = wx.EXPAND, border = 0)
# put a panel
TextPanel = wx.Panel(self, -1)
#create text editor
editor_area = wx.TextCtrl(self, -1, style = wx.TE_MULTILINE)
# Add to sizer
hbox_editor_area = wx.BoxSizer(wx.HORIZONTAL)
hbox_editor_area.Add(editor_area, proportion = 1, flag = wx.EXPAND, border = 0)
TextPanel.SetSizer(hbox_editor_area)
TextPanel.Layout()
#Add to main sizer
vbox.Add(vbox_toolbars, proportion = 0, flag = wx.EXPAND, border = 0)
vbox.Add( hbox_editor_area, proportion = 1, flag = wx.EXPAND, border = 0)
self.SetSizer(vbox)
self.Layout()
#center the window
self.Center()
#show the window(without this the windows will not show up)
self.Show(True)
# Start event handlers
def OnExit (self, event):
DiaExit = wx.MessageBox(self, title = "Confirm Exit", message = "Are you sure you want to Quit?" )
identity = DiaExit.ShowModal()
if (identity == wx.ID_OK ):
self.Close()
else:
DiaExit.Destroy()
#our main application
#app = wx.App(False)
#TextEditor(None, -1, "Text Editor")
#app.MainLoop()
# Another way to make app
class TextEditorMain(wx.App):
def OnInit (self):
frame = TextEditor(None, -1, "Text Editor")
frame.Center()
frame.Show(True)
app = TextEditorMain(False)
TextEditorMain.MainLoop()