Building a Doubletalk Browser with wxPython
Okay, now let’s
build something that’s actually useful and learn more about the
wxPython framework along the way. As has been
shown with the other GUI toolkits, we’ll build a small
application around the Doubletalk class library that allows browsing
and editing of transactions.
MDI Frame
We’re going to implement a Multiple
Document Interface, where the child frames are different views of the
transactional data, rather than separate “documents.”
Just as with previous samples, the first thing to do is create an
application class and have it create a main frame in its
OnInit method:
class DoubleTalkBrowserApp(wxApp):
def OnInit(self):
frame = MainFrame(NULL)
frame.Show(true)
self.SetTopWindow(frame)
return true
app = DoubleTalkBrowserApp(0)
app.MainLoop()Since we are using MDI, there is a special class to use for the frame’s base class. Here is the code for the initialization method of the main application frame:
class MainFrame(wxMDIParentFrame): title = "Doubletalk Browser - wxPython Edition" def __init__(self, parent): wxMDIParentFrame.__init__(self, parent, -1, self.title) self.bookset = None self.views = [] if wxPlatform == '__WXMSW__': self.icon = wxIcon('chart7.ico', wxBITMAP_TYPE_ICO) self.SetIcon(self.icon) # create a statusbar that shows the time and date on the right sb = self.CreateStatusBar(2) sb.SetStatusWidths([-1, 150]) self.timer = wxPyTimer(self.Notify) self.timer.Start(1000) self.Notify() menu = self.MakeMenu(false) self.SetMenuBar(menu) ...