Professional Documents
Culture Documents
Steve Holden
Holden Web LLC
PyCon TX 2006
z-ordering determines
what obscures what
(and hence which program
“sees” particular events)
http://www.onemindonevoice.org
icons desktop /hope/hopeupdate.html
Window manager
GUI GUI GUI GUI
AcroRead Firefox WingIDE Impress
© 2006 Holden Web What Do You Need to Know Today?
Each GUI Is a Data Structure
● Each widget is either
– Atomic, or
– Made up of other widgets
● You can think of a window as a
tree of graphical components
● Before you can display a window you must
– Create the component tree, and (optionally) ...
– Associate events with particular objects and actions
WAIT FOR
Can create and/or
EVENT destroy further
window objects
Y
Done?
Illustrator
required ...
FINISH
© 2006 Holden Web What Do You Need to Know Today?
Structure of a wxPython
Application
1. Create application (wx.App subclass)
2. Create (at least) main frame for application
3. Show main frame
4. Call application.MainLoop()
● Yields control to window manager
● Event handlers are run as events occur
✔ Asynchronously !!!! (scary, isn't it?)
● This is very different from a traditional program
● Controls have a
GetId() method
class MyApp(wx.App):
def OnInit(self):
f = MyFrame(None, -1, title=”My Window”)
# creating the frame establishes its contents
f.Show()
return True
if set_sizer == True:
parent.SetSizer( item0 )
if call_fit == True:
item0.SetSizeHints( parent )
return item0
Try ...
changing button labels
changing button positions
using a wx.Dialog instead of a wx.Frame
omitting some wx.Button arguments
class MyApp(wx.App):
def OnInit(self):
f = MyFrame(None, -1, "My Window")
# The frame establishes its own contents
f.Show()
return True
app = MyApp(False)
app.MainLoop() # ... and wait for events to process
btn.Bind(EVT_BUTTON, self.clickhandler)
– This is the future, so we might as well use it!
d = wx.VERTICAL
● establishes heights of controls
● adds controls top-to-bottom
● resizes horizontally
FlexGridSizer
● Each row and each column
independently sized
GUIs
– The knowledge from this class should get you started
– Nothing to fear from wxPython code!
● Good luck, and keep in touch!!
steve@holdenweb.com
http://yergler.net/talks/desktopapps_uk/
Good application with three-phase create
http://wiki.wxpython.org/index.cgi/DoubleBufferedDrawing
Tutorial with nice code