Added the sample code from wxPython In Action to the samples dir

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42925 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn 2006-11-01 22:36:23 +00:00
parent bb2775b9e8
commit be05b43451
184 changed files with 9122 additions and 0 deletions

View File

@ -0,0 +1,11 @@
import wx
class App(wx.App):
def OnInit(self):
frame = wx.Frame(parent=None, title='Bare')
frame.Show()
return True
app = App()
app.MainLoop()

View File

@ -0,0 +1,36 @@
#!/usr/bin/env python
"""Hello, wxPython! program."""
import wx
class Frame(wx.Frame):
"""Frame class that displays an image."""
def __init__(self, image, parent=None, id=-1,
pos=wx.DefaultPosition, title='Hello, wxPython!'):
"""Create a Frame instance and display image."""
temp = image.ConvertToBitmap()
size = temp.GetWidth(), temp.GetHeight()
wx.Frame.__init__(self, parent, id, title, pos, size)
panel = wx.Panel(self)
self.bmp = wx.StaticBitmap(parent=panel, bitmap=temp)
self.SetClientSize(size)
class App(wx.App):
"""Application class."""
def OnInit(self):
image = wx.Image('wxPython.jpg', wx.BITMAP_TYPE_JPEG)
self.frame = Frame(image)
self.frame.Show()
self.SetTopWindow(self.frame)
return True
def main():
app = App()
app.MainLoop()
if __name__ == '__main__':
main()

View File

@ -0,0 +1,36 @@
import wx
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame("Hello World", (50, 60), (450, 340))
frame.Show()
self.SetTopWindow(frame)
return True
class MyFrame(wx.Frame):
def __init__(self, title, pos, size):
wx.Frame.__init__(self, None, -1, title, pos, size)
menuFile = wx.Menu()
menuFile.Append(1, "&About...")
menuFile.AppendSeparator()
menuFile.Append(2, "E&xit")
menuBar = wx.MenuBar()
menuBar.Append(menuFile, "&File")
self.SetMenuBar(menuBar)
self.CreateStatusBar()
self.SetStatusText("Welcome to wxPython!")
self.Bind(wx.EVT_MENU, self.OnAbout, id=1)
self.Bind(wx.EVT_MENU, self.OnQuit, id=2)
def OnQuit(self, event):
self.Close()
def OnAbout(self, event):
wx.MessageBox("This is a wxPython Hello world sample",
"About Hello World", wx.OK | wx.ICON_INFORMATION, self)
if __name__ == '__main__':
app = MyApp(False)
app.MainLoop()

View File

@ -0,0 +1,21 @@
#!/bin/env python
import wx
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "My Frame", size=(300, 300))
panel = wx.Panel(self, -1)
panel.Bind(wx.EVT_MOTION, self.OnMove)
wx.StaticText(panel, -1, "Pos:", pos=(10, 12))
self.posCtrl = wx.TextCtrl(panel, -1, "", pos=(40, 10))
def OnMove(self, event):
pos = event.GetPosition()
self.posCtrl.SetValue("%s, %s" % (pos.x, pos.y))
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = MyFrame()
frame.Show(True)
app.MainLoop()

View File

@ -0,0 +1,20 @@
#!/usr/bin/env python
"""Spare.py is a starting point for simple wxPython programs."""
import wx
class Frame(wx.Frame):
pass
class App(wx.App):
def OnInit(self):
self.frame = Frame(parent=None, title='Spare')
self.frame.Show()
self.SetTopWindow(self.frame)
return True
if __name__ == '__main__':
app = App()
app.MainLoop()

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@ -0,0 +1,36 @@
#!/usr/bin/env python
import wx
import images
class App(wx.App):
def __init__(self, redirect=True, filename=None):
wx.App.__init__(self, redirect, filename)
def OnInit(self):
dlg = wx.MessageDialog(None, 'Is this the coolest thing ever!',
'MessageDialog', wx.YES_NO | wx.ICON_QUESTION)
result = dlg.ShowModal()
dlg.Destroy()
dlg = wx.TextEntryDialog(None, "Who is buried in Grant's tomb?",
'A Question', 'Cary Grant')
if dlg.ShowModal() == wx.ID_OK:
response = dlg.GetValue()
dlg.Destroy()
dlg = wx.SingleChoiceDialog(None,
'What version of Python are you using?', 'Single Choice',
['1.5.2', '2.0', '2.1.3', '2.2', '2.3.1'])
if dlg.ShowModal() == wx.ID_OK:
response = dlg.GetStringSelection()
dlg.Destroy()
return True
if __name__ == '__main__':
app = App(False, "output")
fred = app.MainLoop()

View File

@ -0,0 +1,24 @@
#----------------------------------------------------------------------
# This file was generated by encode_bitmaps.py
#
from wx import ImageFromStream, BitmapFromImage
from wx import EmptyIcon
import cStringIO
def getNewData():
return \
'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x0f\x08\x06\
\x00\x00\x00\xedsO/\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\x00\
\x00YIDATx\x9c\xed\xd31\n@!\x0c\x03\xd0\xa4\xfe\xfb\xdfX\xe3\xf0\x97R\xa5(.\
\x0ef\x13\xe45\xa2\x92Vp\x92\xcf/\xd4\xaa\xb2\xcd\xb4\xc2\x14\x00\x00in\x90\
\x84ZUDl\xa9\xa7\xc3c\xcb-\x80\xfc\x87{d8B6=B\xdb\rfy\xc0\r\xc0\xf0\x0e\xfc\
\x1d\xaf\x84\xa7\xbf\xb1\x03\xe1,\x19&\x93\x9a\xd2\x97\x00\x00\x00\x00IEND\
\xaeB`\x82'
def getNewBitmap():
return BitmapFromImage(getNewImage())
def getNewImage():
stream = cStringIO.StringIO(getNewData())
return ImageFromStream(stream)

View File

@ -0,0 +1,27 @@
#!/usr/bin/env python
import wx
class InsertFrame(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, 'Frame With Button',
size=(300, 100))
panel = wx.Panel(self)
button = wx.Button(panel, label="Close", pos=(125, 10),
size=(50, 50))
self.Bind(wx.EVT_BUTTON, self.OnCloseMe, button)
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
def OnCloseMe(self, event):
self.Close(True)
def OnCloseWindow(self, event):
self.Destroy()
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = InsertFrame(parent=None, id=-1)
frame.Show()
app.MainLoop()

View File

@ -0,0 +1,35 @@
#!/usr/bin/env python
import wx
import sys
class Frame(wx.Frame):
def __init__(self, parent, id, title):
print "Frame __init__"
wx.Frame.__init__(self, parent, id, title)
class App(wx.App):
def __init__(self, redirect=True, filename=None):
print "App __init__"
wx.App.__init__(self, redirect, filename)
def OnInit(self):
print "OnInit"
self.frame = Frame(parent=None, id=-1, title='Startup')
self.frame.Show()
self.SetTopWindow(self.frame)
print >> sys.stderr, "A pretend error message"
print "app name: <", self.GetVendorName(), ">"
return True
def OnExit(self):
print "OnExit"
if __name__ == '__main__':
app = App(redirect=True)
print "before MainLoop"
fred = app.MainLoop()
print "after MainLoop", fred

View File

@ -0,0 +1,41 @@
#!/usr/bin/env python
import wx
import images
class ToolbarFrame(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, 'Toolbars',
size=(300, 200))
panel = wx.Panel(self)
panel.SetBackgroundColour('White')
statusBar = self.CreateStatusBar()
toolbar = self.CreateToolBar()
toolbar.AddSimpleTool(wx.NewId(), images.getNewBitmap(),
"New", "Long help for 'New'")
toolbar.Realize()
menuBar = wx.MenuBar()
menu1 = wx.Menu()
menuBar.Append(menu1, "&File")
menu2 = wx.Menu()
menu2.Append(wx.NewId(), "&Copy", "Copy in status bar")
menu2.Append(wx.NewId(), "C&ut", "")
menu2.Append(wx.NewId(), "Paste", "")
menu2.AppendSeparator()
menu2.Append(wx.NewId(), "&Options...", "Display Options")
menuBar.Append(menu2, "&Edit")
self.SetMenuBar(menuBar)
def OnCloseMe(self, event):
self.Close(True)
def OnCloseWindow(self, event):
self.Destroy()
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = ToolbarFrame(parent=None, id=-1)
frame.Show()
app.MainLoop()

View File

@ -0,0 +1,64 @@
import wx
class TwoButtonEvent(wx.PyCommandEvent):
def __init__(self, evtType, id):
wx.PyCommandEvent.__init__(self, evtType, id)
self.clickCount = 0
def GetClickCount(self):
return self.clickCount
def SetClickCount(self, count):
self.clickCount = count
myEVT_TWO_BUTTON = wx.NewEventType()
EVT_TWO_BUTTON = wx.PyEventBinder(myEVT_TWO_BUTTON, 1)
class TwoButtonPanel(wx.Panel):
def __init__(self, parent, id=-1, leftText="Left",
rightText="Right"):
wx.Panel.__init__(self, parent, id)
self.leftButton = wx.Button(self, label=leftText)
self.rightButton = wx.Button(self, label=rightText,
pos=(100,0))
self.leftClick = False
self.rightClick = False
self.clickCount = 0
self.leftButton.Bind(wx.EVT_LEFT_DOWN, self.OnLeftClick)
self.rightButton.Bind(wx.EVT_LEFT_DOWN, self.OnRightClick)
def OnLeftClick(self, event):
self.leftClick = True
self.OnClick()
event.Skip()
def OnRightClick(self, event):
self.rightClick = True
self.OnClick()
event.Skip()
def OnClick(self):
self.clickCount += 1
if self.leftClick and self.rightClick:
self.leftClick = False
self.rightClick = False
evt = TwoButtonEvent(myEVT_TWO_BUTTON, self.GetId())
evt.SetClickCount(self.clickCount)
self.GetEventHandler().ProcessEvent(evt)
class CustomEventFrame(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, 'Click Count: 0',
size=(300, 100))
panel = TwoButtonPanel(self)
self.Bind(EVT_TWO_BUTTON, self.OnTwoClick, panel)
def OnTwoClick(self, event):
self.SetTitle("Click Count: %s" % event.GetClickCount())
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = CustomEventFrame(parent=None, id=-1)
frame.Show()
app.MainLoop()

View File

@ -0,0 +1,28 @@
#!/usr/bin/env python
import wx
class DoubleEventFrame(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, 'Frame With Button',
size=(300, 100))
self.panel = wx.Panel(self, -1)
self.button = wx.Button(self.panel, -1, "Click Me", pos=(100, 15))
self.Bind(wx.EVT_BUTTON, self.OnButtonClick, self.button)
self.button.Bind(wx.EVT_LEFT_DOWN, self.OnMouseDown)
def OnButtonClick(self, event):
self.panel.SetBackgroundColour('Green')
self.panel.Refresh()
def OnMouseDown(self, event):
self.button.SetLabel("Again!")
event.Skip()
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = DoubleEventFrame(parent=None, id=-1)
frame.Show()
app.MainLoop()

View File

@ -0,0 +1,24 @@
#!/usr/bin/env python
import wx
class MenuEventFrame(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, 'Menus', size=(300, 200))
menuBar = wx.MenuBar()
menu1 = wx.Menu()
menuItem = menu1.Append(-1, "&Exit...")
menuBar.Append(menu1, "&File")
self.SetMenuBar(menuBar)
self.Bind(wx.EVT_MENU, self.OnCloseMe, menuItem)
def OnCloseMe(self, event):
self.Close(True)
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = MenuEventFrame(parent=None, id=-1)
frame.Show()
app.MainLoop()

View File

@ -0,0 +1,34 @@
#!/usr/bin/env python
import wx
class MouseEventFrame(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, 'Frame With Button',
size=(300, 100))
self.panel = wx.Panel(self)
self.button = wx.Button(self.panel, label="Not Over", pos=(100, 15))
self.Bind(wx.EVT_BUTTON, self.OnButtonClick, self.button)
self.button.Bind(wx.EVT_ENTER_WINDOW, self.OnEnterWindow)
self.button.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveWindow)
def OnButtonClick(self, event):
self.panel.SetBackgroundColour('Green')
self.panel.Refresh()
def OnEnterWindow(self, event):
self.button.SetLabel("Over Me!")
event.Skip()
def OnLeaveWindow(self, event):
self.button.SetLabel("Not Over")
event.Skip()
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = MouseEventFrame(parent=None, id=-1)
frame.Show()
app.MainLoop()

View File

@ -0,0 +1,48 @@
"""PyWrap is a command line utility that runs a wxPython program with
additional runtime-tools, such as PyCrust."""
__author__ = "Patrick K. O'Brien <pobrien@orbtech.com>"
__cvsid__ = "$Id$"
__revision__ = "$Revision$"[11:-2]
import wx
from wx import py
import os
import sys
def wrap(app):
wx.InitAllImageHandlers()
frame = py.crust.CrustFrame()
frame.SetSize((750, 525))
frame.Show(True)
frame.shell.interp.locals['app'] = app
app.MainLoop()
def main(modulename=None):
sys.path.insert(0, os.curdir)
if not modulename:
if len(sys.argv) < 2:
print "Please specify a module name."
raise SystemExit
modulename = sys.argv[1]
if modulename.endswith('.py'):
modulename = modulename[:-3]
module = __import__(modulename)
# Find the App class.
App = None
d = module.__dict__
for item in d.keys():
try:
if issubclass(d[item], wx.App):
App = d[item]
except (NameError, TypeError):
pass
if App is None:
print "No App class was found."
raise SystemExit
app = App()
wrap(app)
if __name__ == '__main__':
main()

View File

@ -0,0 +1,24 @@
#----------------------------------------------------------------------
# This file was generated by encode_bitmaps.py
#
from wx import ImageFromStream, BitmapFromImage
from wx import EmptyIcon
import cStringIO
def getNewData():
return \
'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x0f\x08\x06\
\x00\x00\x00\xedsO/\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\x00\
\x00YIDATx\x9c\xed\xd31\n@!\x0c\x03\xd0\xa4\xfe\xfb\xdfX\xe3\xf0\x97R\xa5(.\
\x0ef\x13\xe45\xa2\x92Vp\x92\xcf/\xd4\xaa\xb2\xcd\xb4\xc2\x14\x00\x00in\x90\
\x84ZUDl\xa9\xa7\xc3c\xcb-\x80\xfc\x87{d8B6=B\xdb\rfy\xc0\r\xc0\xf0\x0e\xfc\
\x1d\xaf\x84\xa7\xbf\xb1\x03\xe1,\x19&\x93\x9a\xd2\x97\x00\x00\x00\x00IEND\
\xaeB`\x82'
def getNewBitmap():
return BitmapFromImage(getNewImage())
def getNewImage():
stream = cStringIO.StringIO(getNewData())
return ImageFromStream(stream)

View File

@ -0,0 +1,60 @@
#!/usr/bin/env python
import wx
from wx.py.shell import ShellFrame
from wx.py.filling import FillingFrame
import images
class ToolbarFrame(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, 'Toolbars',
size=(300, 200))
panel = wx.Panel(self, -1)
panel.SetBackgroundColour('White')
statusBar = self.CreateStatusBar()
toolbar = self.CreateToolBar()
toolbar.AddSimpleTool(wx.NewId(), images.getNewBitmap(),
"New", "Long help for 'New'")
toolbar.Realize()
menuBar = wx.MenuBar()
menu1 = wx.Menu()
menuBar.Append(menu1, "&File")
menu2 = wx.Menu()
menu2.Append(wx.NewId(), "&Copy", "Copy in status bar")
menu2.Append(wx.NewId(), "C&ut", "")
menu2.Append(wx.NewId(), "Paste", "")
menu2.AppendSeparator()
menu2.Append(wx.NewId(), "&Options...", "Display Options")
menuBar.Append(menu2, "&Edit")
menu3 = wx.Menu()
shell = menu3.Append(-1, "&Python shell",
"Open Python shell frame")
filling = menu3.Append(-1, "&Namespace viewer",
"Open namespace viewer frame")
menuBar.Append(menu3, "&Debug")
self.Bind(wx.EVT_MENU, self.OnShell, shell)
self.Bind(wx.EVT_MENU, self.OnFilling, filling)
self.SetMenuBar(menuBar)
def OnCloseMe(self, event):
self.Close(True)
def OnCloseWindow(self, event):
self.Destroy()
def OnShell(self, event):
frame = ShellFrame(parent=self)
frame.Show()
def OnFilling(self, event):
frame = FillingFrame(parent=self)
frame.Show()
if __name__ == '__main__':
app = wx.PySimpleApp()
app.frame = ToolbarFrame(parent=None, id=-1)
app.frame.Show()
app.MainLoop()

View File

@ -0,0 +1,4 @@
#!/usr/bin/env python
from wx.py.PyWrap import main
main()

View File

@ -0,0 +1,20 @@
#!/usr/bin/env python
"""Spare.py is a starting point for simple wxPython programs."""
import wx
class Frame(wx.Frame):
pass
class App(wx.App):
def OnInit(self):
self.frame = Frame(parent=None, id=-1, title='Spare')
self.frame.Show()
self.SetTopWindow(self.frame)
return True
if __name__ == '__main__':
app = App()
app.MainLoop()

View File

@ -0,0 +1,15 @@
class AbstractModel(object):
def __init__(self):
self.listeners = []
def addListener(self, listenerFunc):
self.listeners.append(listenerFunc)
def removeListener(self, listenerFunc):
self.listeners.remove(listenerFunc)
def update(self):
for eachFunc in self.listeners:
eachFunc(self)

View File

@ -0,0 +1,77 @@
#!/usr/bin/env python
import wx
class RefactorExample(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, 'Refactor Example',
size=(340, 200))
panel = wx.Panel(self, -1)
panel.SetBackgroundColour("White")
prevButton = wx.Button(panel, -1, "<< PREV", pos=(80, 0))
self.Bind(wx.EVT_BUTTON, self.OnPrev, prevButton)
nextButton = wx.Button(panel, -1, "NEXT >>", pos=(160, 0))
self.Bind(wx.EVT_BUTTON, self.OnNext, nextButton)
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
menuBar = wx.MenuBar()
menu1 = wx.Menu()
openMenuItem = menu1.Append(-1, "&Open", "Copy in status bar")
self.Bind(wx.EVT_MENU, self.OnOpen, openMenuItem)
quitMenuItem = menu1.Append(-1, "&Quit", "Quit")
self.Bind(wx.EVT_MENU, self.OnCloseWindow, quitMenuItem)
menuBar.Append(menu1, "&File")
menu2 = wx.Menu()
copyItem = menu2.Append(-1, "&Copy", "Copy")
self.Bind(wx.EVT_MENU, self.OnCopy, copyItem)
cutItem = menu2.Append(-1, "C&ut", "Cut")
self.Bind(wx.EVT_MENU, self.OnCut, cutItem)
pasteItem = menu2.Append(-1, "Paste", "Paste")
self.Bind(wx.EVT_MENU, self.OnPaste, pasteItem)
menuBar.Append(menu2, "&Edit")
self.SetMenuBar(menuBar)
static = wx.StaticText(panel, wx.NewId(), "First Name",
pos=(10, 50))
static.SetBackgroundColour("White")
text = wx.TextCtrl(panel, wx.NewId(), "", size=(100, -1),
pos=(80, 50))
static2 = wx.StaticText(panel, wx.NewId(), "Last Name",
pos=(10, 80))
static2.SetBackgroundColour("White")
text2 = wx.TextCtrl(panel, wx.NewId(), "", size=(100, -1),
pos=(80, 80))
firstButton = wx.Button(panel, -1, "FIRST")
self.Bind(wx.EVT_BUTTON, self.OnFirst, firstButton)
menu2.AppendSeparator()
optItem = menu2.Append(-1, "&Options...", "Display Options")
self.Bind(wx.EVT_MENU, self.OnOptions, optItem)
lastButton = wx.Button(panel, -1, "LAST", pos=(240, 0))
self.Bind(wx.EVT_BUTTON, self.OnLast, lastButton)
# Just grouping the empty event handlers together
def OnPrev(self, event): pass
def OnNext(self, event): pass
def OnLast(self, event): pass
def OnFirst(self, event): pass
def OnOpen(self, event): pass
def OnCopy(self, event): pass
def OnCut(self, event): pass
def OnPaste(self, event): pass
def OnOptions(self, event): pass
def OnCloseWindow(self, event):
self.Destroy()
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = RefactorExample(parent=None, id=-1)
frame.Show()
app.MainLoop()

View File

@ -0,0 +1,34 @@
import wx
import wx.grid
class GenericTable(wx.grid.PyGridTableBase):
def __init__(self, data, rowLabels=None, colLabels=None):
wx.grid.PyGridTableBase.__init__(self)
self.data = data
self.rowLabels = rowLabels
self.colLabels = colLabels
def GetNumberRows(self):
return len(self.data)
def GetNumberCols(self):
return len(self.data[0])
def GetColLabelValue(self, col):
if self.colLabels:
return self.colLabels[col]
def GetRowLabelValue(self, row):
if self.rowLabels:
return self.rowLabels[row]
def IsEmptyCell(self, row, col):
return False
def GetValue(self, row, col):
return self.data[row][col]
def SetValue(self, row, col, value):
pass

View File

@ -0,0 +1,96 @@
#!/usr/bin/env python
import wx
class RefactorExample(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, 'Refactor Example',
size=(340, 200))
panel = wx.Panel(self, -1)
panel.SetBackgroundColour("White")
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
self.createMenuBar()
self.createButtonBar(panel)
self.createTextFields(panel)
def menuData(self):
return (("&File",
("&Open", "Open in status bar", self.OnOpen),
("&Quit", "Quit", self.OnCloseWindow)),
("&Edit",
("&Copy", "Copy", self.OnCopy),
("C&ut", "Cut", self.OnCut),
("&Paste", "Paste", self.OnPaste),
("", "", ""),
("&Options...", "DisplayOptions", self.OnOptions)))
def createMenuBar(self):
menuBar = wx.MenuBar()
for eachMenuData in self.menuData():
menuLabel = eachMenuData[0]
menuItems = eachMenuData[1:]
menuBar.Append(self.createMenu(menuItems), menuLabel)
self.SetMenuBar(menuBar)
def createMenu(self, menuData):
menu = wx.Menu()
for eachLabel, eachStatus, eachHandler in menuData:
if not eachLabel:
menu.AppendSeparator()
continue
menuItem = menu.Append(-1, eachLabel, eachStatus)
self.Bind(wx.EVT_MENU, eachHandler, menuItem)
return menu
def buttonData(self):
return (("First", self.OnFirst),
("<< PREV", self.OnPrev),
("NEXT >>", self.OnNext),
("Last", self.OnLast))
def createButtonBar(self, panel, yPos = 0):
xPos = 0
for eachLabel, eachHandler in self.buttonData():
pos = (xPos, yPos)
button = self.buildOneButton(panel, eachLabel, eachHandler, pos)
xPos += button.GetSize().width
def buildOneButton(self, parent, label, handler, pos=(0,0)):
button = wx.Button(parent, -1, label, pos)
self.Bind(wx.EVT_BUTTON, handler, button)
return button
def textFieldData(self):
return (("First Name", (10, 50)),
("Last Name", (10, 80)))
def createTextFields(self, panel):
for eachLabel, eachPos in self.textFieldData():
self.createCaptionedText(panel, eachLabel, eachPos)
def createCaptionedText(self, panel, label, pos):
static = wx.StaticText(panel, wx.NewId(), label, pos)
static.SetBackgroundColour("White")
textPos = (pos[0] + 75, pos[1])
wx.TextCtrl(panel, wx.NewId(), "", size=(100, -1), pos=textPos)
# Just grouping the empty event handlers together
def OnPrev(self, event): pass
def OnNext(self, event): pass
def OnLast(self, event): pass
def OnFirst(self, event): pass
def OnOpen(self, event): pass
def OnCopy(self, event): pass
def OnCut(self, event): pass
def OnPaste(self, event): pass
def OnOptions(self, event): pass
def OnCloseWindow(self, event):
self.Destroy()
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = RefactorExample(parent=None, id=-1)
frame.Show()
app.MainLoop()

View File

@ -0,0 +1,34 @@
import wx
import wx.grid
import generictable
data = (("Bob", "Dernier"), ("Ryne", "Sandberg"),
("Gary", "Matthews"), ("Leon", "Durham"),
("Keith", "Moreland"), ("Ron", "Cey"),
("Jody", "Davis"), ("Larry", "Bowa"),
("Rick", "Sutcliffe"))
colLabels = ("Last", "First")
rowLabels = ("CF", "2B", "LF", "1B", "RF", "3B", "C", "SS", "P")
class SimpleGrid(wx.grid.Grid):
def __init__(self, parent):
wx.grid.Grid.__init__(self, parent, -1)
tableBase = generictable.GenericTable(data, rowLabels,
colLabels)
self.SetTable(tableBase)
class TestFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, "A Grid",
size=(275, 275))
grid = SimpleGrid(self)
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = TestFrame(None)
frame.Show(True)
app.MainLoop()

View File

@ -0,0 +1,54 @@
import wx
import wx.grid
class LineupTable(wx.grid.PyGridTableBase):
data = (("CF", "Bob", "Dernier"), ("2B", "Ryne", "Sandberg"),
("LF", "Gary", "Matthews"), ("1B", "Leon", "Durham"),
("RF", "Keith", "Moreland"), ("3B", "Ron", "Cey"),
("C", "Jody", "Davis"), ("SS", "Larry", "Bowa"),
("P", "Rick", "Sutcliffe"))
colLabels = ("Last", "First")
def __init__(self):
wx.grid.PyGridTableBase.__init__(self)
def GetNumberRows(self):
return len(self.data)
def GetNumberCols(self):
return len(self.data[0]) - 1
def GetColLabelValue(self, col):
return self.colLabels[col]
def GetRowLabelValue(self, row):
return self.data[row][0]
def IsEmptyCell(self, row, col):
return False
def GetValue(self, row, col):
return self.data[row][col + 1]
def SetValue(self, row, col, value):
pass
class SimpleGrid(wx.grid.Grid):
def __init__(self, parent):
wx.grid.Grid.__init__(self, parent, -1)
self.SetTable(LineupTable())
class TestFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, "A Grid",
size=(275, 275))
grid = SimpleGrid(self)
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = TestFrame(None)
frame.Show(True)
app.MainLoop()

View File

@ -0,0 +1,49 @@
import wx
import wx.grid
class SimpleGrid(wx.grid.Grid):
def __init__(self, parent):
wx.grid.Grid.__init__(self, parent, -1)
self.CreateGrid(9, 2)
self.SetColLabelValue(0, "First")
self.SetColLabelValue(1, "Last")
self.SetRowLabelValue(0, "CF")
self.SetCellValue(0, 0, "Bob")
self.SetCellValue(0, 1, "Dernier")
self.SetRowLabelValue(1, "2B")
self.SetCellValue(1, 0, "Ryne")
self.SetCellValue(1, 1, "Sandberg")
self.SetRowLabelValue(2, "LF")
self.SetCellValue(2, 0, "Gary")
self.SetCellValue(2, 1, "Matthews")
self.SetRowLabelValue(3, "1B")
self.SetCellValue(3, 0, "Leon")
self.SetCellValue(3, 1, "Durham")
self.SetRowLabelValue(4, "RF")
self.SetCellValue(4, 0, "Keith")
self.SetCellValue(4, 1, "Moreland")
self.SetRowLabelValue(5, "3B")
self.SetCellValue(5, 0, "Ron")
self.SetCellValue(5, 1, "Cey")
self.SetRowLabelValue(6, "C")
self.SetCellValue(6, 0, "Jody")
self.SetCellValue(6, 1, "Davis")
self.SetRowLabelValue(7, "SS")
self.SetCellValue(7, 0, "Larry")
self.SetCellValue(7, 1, "Bowa")
self.SetRowLabelValue(8, "P")
self.SetCellValue(8, 0, "Rick")
self.SetCellValue(8, 1, "Sutcliffe")
class TestFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, "A Grid",
size=(275, 275))
grid = SimpleGrid(self)
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = TestFrame(None)
frame.Show(True)
app.MainLoop()

View File

@ -0,0 +1,41 @@
import wx
import wx.grid
class LineupEntry:
def __init__(self, pos, first, last):
self.pos = pos
self.first = first
self.last = last
class LineupTable(wx.grid.PyGridTableBase):
colLabels = ("First", "Last")
colAttrs = ("first", "last")
def __init__(self, entries):
wx.grid.PyGridTableBase.__init__(self)
self.entries = entries
def GetNumberRows(self):
return len(self.entries)
def GetNumberCols(self):
return 2
def GetColLabelValue(self, col):
return self.colLabels[col]
def GetRowLabelValue(self, col):
return self.entries[row].pos
def IsEmptyCell(self, row, col):
return False
def GetValue(self, row, col):
entry = self.entries[row]
return getattr(entry, self.colAttrs[col])
def SetValue(self, row, col, value):
pass

View File

@ -0,0 +1,89 @@
#!/usr/bin/env python
import wx
import abstractmodel
class SimpleName(abstractmodel.AbstractModel):
def __init__(self, first="", last=""):
abstractmodel.AbstractModel.__init__(self)
self.set(first, last)
def set(self, first, last):
self.first = first
self.last = last
self.update()
class ModelExample(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, 'Flintstones',
size=(340, 200))
panel = wx.Panel(self)
panel.SetBackgroundColour("White")
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
self.textFields = {}
self.createTextFields(panel)
self.model = SimpleName()
self.model.addListener(self.OnUpdate)
self.createButtonBar(panel)
def buttonData(self):
return (("Fredify", self.OnFred),
("Wilmafy", self.OnWilma),
("Barnify", self.OnBarney),
("Bettify", self.OnBetty))
def createButtonBar(self, panel, yPos = 0):
xPos = 0
for eachLabel, eachHandler in self.buttonData():
pos = (xPos, yPos)
button = self.buildOneButton(panel, eachLabel, eachHandler, pos)
xPos += button.GetSize().width
def buildOneButton(self, parent, label, handler, pos=(0,0)):
button = wx.Button(parent, -1, label, pos)
self.Bind(wx.EVT_BUTTON, handler, button)
return button
def textFieldData(self):
return (("First Name", (10, 50)),
("Last Name", (10, 80)))
def createTextFields(self, panel):
for eachLabel, eachPos in self.textFieldData():
self.createCaptionedText(panel, eachLabel, eachPos)
def createCaptionedText(self, panel, label, pos):
static = wx.StaticText(panel, wx.NewId(), label, pos)
static.SetBackgroundColour("White")
textPos = (pos[0] + 75, pos[1])
self.textFields[label] = wx.TextCtrl(panel, wx.NewId(),
"", size=(100, -1), pos=textPos,
style=wx.TE_READONLY)
def OnUpdate(self, model):
self.textFields["First Name"].SetValue(model.first)
self.textFields["Last Name"].SetValue(model.last)
def OnFred(self, event):
self.model.set("Fred", "Flintstone")
def OnBarney(self, event):
self.model.set("Barney", "Rubble")
def OnWilma(self, event):
self.model.set("Wilma", "Flintstone")
def OnBetty(self, event):
self.model.set("Betty", "Rubble")
def OnCloseWindow(self, event):
self.Destroy()
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = ModelExample(parent=None, id=-1)
frame.Show()
app.MainLoop()

View File

@ -0,0 +1,37 @@
import unittest
import modelExample
import wx
class TestExample(unittest.TestCase):
def setUp(self):
self.app = wx.PySimpleApp()
self.frame = modelExample.ModelExample(parent=None, id=-1)
def tearDown(self):
self.frame.Destroy()
def testModel(self):
self.frame.OnBarney(None)
self.assertEqual("Barney", self.frame.model.first,
msg="First is wrong")
self.assertEqual("Rubble", self.frame.model.last)
def testEvent(self):
panel = self.frame.GetChildren()[0]
for each in panel.GetChildren():
if each.GetLabel() == "Wilmafy":
wilma = each
break
event = wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, wilma.GetId())
wilma.GetEventHandler().ProcessEvent(event)
self.assertEqual("Wilma", self.frame.model.first)
self.assertEqual("Flintstone", self.frame.model.last)
def suite():
suite = unittest.makeSuite(TestExample, 'test')
return suite
if __name__ == '__main__':
unittest.main(defaultTest='suite')

View File

@ -0,0 +1,26 @@
import unittest
import modelExample
import wx
class TestExample(unittest.TestCase):
def setUp(self):
self.app = wx.PySimpleApp()
self.frame = modelExample.ModelExample(parent=None, id=-1)
def tearDown(self):
self.frame.Destroy()
def testModel(self):
self.frame.OnBarney(None)
self.assertEqual("Barney", self.frame.model.first,
msg="First is wrong")
self.assertEqual("Rubble", self.frame.model.last)
def suite():
suite = unittest.makeSuite(TestExample, 'test')
return suite
if __name__ == '__main__':
unittest.main(defaultTest='suite')

View File

@ -0,0 +1,106 @@
import wx
class SketchWindow(wx.Window):
def __init__(self, parent, ID):
wx.Window.__init__(self, parent, ID)
self.SetBackgroundColour("White")
self.color = "Black"
self.thickness = 1
self.pen = wx.Pen(self.color, self.thickness, wx.SOLID)
self.lines = []
self.curLine = []
self.pos = (0, 0)
self.InitBuffer()
self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
self.Bind(wx.EVT_MOTION, self.OnMotion)
self.Bind(wx.EVT_SIZE, self.OnSize)
self.Bind(wx.EVT_IDLE, self.OnIdle)
self.Bind(wx.EVT_PAINT, self.OnPaint)
def InitBuffer(self):
size = self.GetClientSize()
#self.buffer = wx.EmptyBitmap(max(1, size.width), max(1, size.height))
self.buffer = wx.EmptyBitmap(size.width, size.height)
if self.buffer.Ok():
dc = wx.BufferedDC(None, self.buffer)
dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
dc.Clear()
self.DrawLines(dc)
self.reInitBuffer = False
def GetLinesData(self):
return self.lines[:]
def SetLinesData(self, lines):
self.lines = lines[:]
self.InitBuffer()
self.Refresh()
def OnLeftDown(self, event):
self.curLine = []
self.pos = event.GetPositionTuple()
self.CaptureMouse()
def OnLeftUp(self, event):
if self.HasCapture():
self.lines.append((self.color,
self.thickness,
self.curLine))
self.curLine = []
self.ReleaseMouse()
def OnMotion(self, event):
if event.Dragging() and event.LeftIsDown():
dc = wx.BufferedDC(wx.ClientDC(self), self.buffer)
self.drawMotion(dc, event)
event.Skip()
def drawMotion(self, dc, event):
dc.SetPen(self.pen)
newPos = event.GetPositionTuple()
coords = self.pos + newPos
self.curLine.append(coords)
dc.DrawLine(*coords)
self.pos = newPos
def OnSize(self, event):
self.reInitBuffer = True
def OnIdle(self, event):
if self.reInitBuffer:
self.InitBuffer()
self.Refresh(False)
def OnPaint(self, event):
dc = wx.BufferedPaintDC(self, self.buffer)
def DrawLines(self, dc):
for colour, thickness, line in self.lines:
pen = wx.Pen(colour, thickness, wx.SOLID)
dc.SetPen(pen)
for coords in line:
dc.DrawLine(*coords)
def SetColor(self, color):
self.color = color
self.pen = wx.Pen(self.color, self.thickness, wx.SOLID)
def SetThickness(self, num):
self.thickness = num
self.pen = wx.Pen(self.color, self.thickness, wx.SOLID)
class SketchFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, "Sketch Frame",
size=(800,600))
self.sketch = SketchWindow(self, -1)
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = SketchFrame(None)
frame.Show(True)
app.MainLoop()

View File

@ -0,0 +1,21 @@
import wx
from example1 import SketchWindow
class SketchFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, "Sketch Frame",
size=(800,600))
self.sketch = SketchWindow(self, -1)
self.sketch.Bind(wx.EVT_MOTION, self.OnSketchMotion)
self.statusbar = self.CreateStatusBar()
def OnSketchMotion(self, event):
self.statusbar.SetStatusText(str(event.GetPositionTuple()))
event.Skip()
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = SketchFrame(None)
frame.Show(True)
app.MainLoop()

View File

@ -0,0 +1,27 @@
import wx
from example1 import SketchWindow
class SketchFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, "Sketch Frame",
size=(800,600))
self.sketch = SketchWindow(self, -1)
self.sketch.Bind(wx.EVT_MOTION, self.OnSketchMotion)
self.statusbar = self.CreateStatusBar()
self.statusbar.SetFieldsCount(3)
self.statusbar.SetStatusWidths([-1, -2, -3])
def OnSketchMotion(self, event):
self.statusbar.SetStatusText("Pos: %s" %
str(event.GetPositionTuple()), 0)
self.statusbar.SetStatusText("Current Pts: %s" %
len(self.sketch.curLine), 1)
self.statusbar.SetStatusText("Line Count: %s" %
len(self.sketch.lines), 2)
event.Skip()
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = SketchFrame(None)
frame.Show(True)
app.MainLoop()

View File

@ -0,0 +1,92 @@
import wx
from example1 import SketchWindow
class SketchFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, "Sketch Frame",
size=(800,600))
self.sketch = SketchWindow(self, -1)
self.sketch.Bind(wx.EVT_MOTION, self.OnSketchMotion)
self.initStatusBar()
self.createMenuBar()
def initStatusBar(self):
self.statusbar = self.CreateStatusBar()
self.statusbar.SetFieldsCount(3)
self.statusbar.SetStatusWidths([-1, -2, -3])
def OnSketchMotion(self, event):
self.statusbar.SetStatusText("Pos: %s" %
str(event.GetPositionTuple()), 0)
self.statusbar.SetStatusText("Current Pts: %s" %
len(self.sketch.curLine), 1)
self.statusbar.SetStatusText("Line Count: %s" %
len(self.sketch.lines), 2)
event.Skip()
def menuData(self):
return [("&File", (
("&New", "New Sketch file", self.OnNew),
("&Open", "Open sketch file", self.OnOpen),
("&Save", "Save sketch file", self.OnSave),
("", "", ""),
("&Color", (
("&Black", "", self.OnColor,
wx.ITEM_RADIO),
("&Red", "", self.OnColor,
wx.ITEM_RADIO),
("&Green", "", self.OnColor,
wx.ITEM_RADIO),
("&Blue", "", self.OnColor,
wx.ITEM_RADIO))),
("", "", ""),
("&Quit", "Quit", self.OnCloseWindow)))]
def createMenuBar(self):
menuBar = wx.MenuBar()
for eachMenuData in self.menuData():
menuLabel = eachMenuData[0]
menuItems = eachMenuData[1]
menuBar.Append(self.createMenu(menuItems), menuLabel)
self.SetMenuBar(menuBar)
def createMenu(self, menuData):
menu = wx.Menu()
for eachItem in menuData:
if len(eachItem) == 2:
label = eachItem[0]
subMenu = self.createMenu(eachItem[1])
menu.AppendMenu(wx.NewId(), label, subMenu)
else:
self.createMenuItem(menu, *eachItem)
return menu
def createMenuItem(self, menu, label, status, handler,
kind=wx.ITEM_NORMAL):
if not label:
menu.AppendSeparator()
return
menuItem = menu.Append(-1, label, status, kind)
self.Bind(wx.EVT_MENU, handler, menuItem)
def OnNew(self, event): pass
def OnOpen(self, event): pass
def OnSave(self, event): pass
def OnColor(self, event):
menubar = self.GetMenuBar()
itemId = event.GetId()
item = menubar.FindItemById(itemId)
color = item.GetLabel()
self.sketch.SetColor(color)
def OnCloseWindow(self, event):
self.Destroy()
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = SketchFrame(None)
frame.Show(True)
app.MainLoop()

View File

@ -0,0 +1,132 @@
import wx
from example1 import SketchWindow
class SketchFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, "Sketch Frame",
size=(800,600))
self.sketch = SketchWindow(self, -1)
self.sketch.Bind(wx.EVT_MOTION, self.OnSketchMotion)
self.initStatusBar()
self.createMenuBar()
self.createToolBar()
def initStatusBar(self):
self.statusbar = self.CreateStatusBar()
self.statusbar.SetFieldsCount(3)
self.statusbar.SetStatusWidths([-1, -2, -3])
def OnSketchMotion(self, event):
self.statusbar.SetStatusText("Pos: %s" %
str(event.GetPositionTuple()), 0)
self.statusbar.SetStatusText("Current Pts: %s" %
len(self.sketch.curLine), 1)
self.statusbar.SetStatusText("Line Count: %s" %
len(self.sketch.lines), 2)
event.Skip()
def menuData(self):
return [("&File", (
("&New", "New Sketch file", self.OnNew),
("&Open", "Open sketch file", self.OnOpen),
("&Save", "Save sketch file", self.OnSave),
("", "", ""),
("&Color", (
("&Black", "", self.OnColor, wx.ITEM_RADIO),
("&Red", "", self.OnColor, wx.ITEM_RADIO),
("&Green", "", self.OnColor, wx.ITEM_RADIO),
("&Blue", "", self.OnColor, wx.ITEM_RADIO))),
("", "", ""),
("&Quit", "Quit", self.OnCloseWindow)))]
def createMenuBar(self):
menuBar = wx.MenuBar()
for eachMenuData in self.menuData():
menuLabel = eachMenuData[0]
menuItems = eachMenuData[1]
menuBar.Append(self.createMenu(menuItems), menuLabel)
self.SetMenuBar(menuBar)
def createMenu(self, menuData):
menu = wx.Menu()
for eachItem in menuData:
if len(eachItem) == 2:
label = eachItem[0]
subMenu = self.createMenu(eachItem[1])
menu.AppendMenu(wx.NewId(), label, subMenu)
else:
self.createMenuItem(menu, *eachItem)
return menu
def createMenuItem(self, menu, label, status, handler, kind=wx.ITEM_NORMAL):
if not label:
menu.AppendSeparator()
return
menuItem = menu.Append(-1, label, status, kind)
self.Bind(wx.EVT_MENU, handler, menuItem)
def createToolBar(self):
toolbar = self.CreateToolBar()
for each in self.toolbarData():
self.createSimpleTool(toolbar, *each)
toolbar.AddSeparator()
for each in self.toolbarColorData():
self.createColorTool(toolbar, each)
toolbar.Realize()
def createSimpleTool(self, toolbar, label, filename, help, handler):
if not label:
toolbar.AddSeparator()
return
bmp = wx.Image(filename, wx.BITMAP_TYPE_BMP).ConvertToBitmap()
tool = toolbar.AddSimpleTool(-1, bmp, label, help)
self.Bind(wx.EVT_MENU, handler, tool)
def toolbarData(self):
return (("New", "new.bmp", "Create new sketch", self.OnNew),
("", "", "", ""),
("Open", "open.bmp", "Open existing sketch", self.OnOpen),
("Save", "save.bmp", "Save existing sketch", self.OnSave))
def createColorTool(self, toolbar, color):
bmp = self.MakeBitmap(color)
tool = toolbar.AddRadioTool(-1, bmp, shortHelp=color)
self.Bind(wx.EVT_MENU, self.OnColor, tool)
def MakeBitmap(self, color):
bmp = wx.EmptyBitmap(16, 15)
dc = wx.MemoryDC()
dc.SelectObject(bmp)
dc.SetBackground(wx.Brush(color))
dc.Clear()
dc.SelectObject(wx.NullBitmap)
return bmp
def toolbarColorData(self):
return ("Black", "Red", "Green", "Blue")
def OnNew(self, event): pass
def OnOpen(self, event): pass
def OnSave(self, event): pass
def OnColor(self, event):
menubar = self.GetMenuBar()
itemId = event.GetId()
item = menubar.FindItemById(itemId)
if not item:
toolbar = self.GetToolBar()
item = toolbar.FindById(itemId)
color = item.GetShortHelp()
else:
color = item.GetLabel()
self.sketch.SetColor(color)
def OnCloseWindow(self, event):
self.Destroy()
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = SketchFrame(None)
frame.Show(True)
app.MainLoop()

View File

@ -0,0 +1,192 @@
import wx
import cPickle
import os
from example1 import SketchWindow
class SketchFrame(wx.Frame):
def __init__(self, parent):
self.title = "Sketch Frame"
wx.Frame.__init__(self, parent, -1, self.title,
size=(800,600))
self.filename = ""
self.sketch = SketchWindow(self, -1)
self.sketch.Bind(wx.EVT_MOTION, self.OnSketchMotion)
self.initStatusBar()
self.createMenuBar()
self.createToolBar()
def initStatusBar(self):
self.statusbar = self.CreateStatusBar()
self.statusbar.SetFieldsCount(3)
self.statusbar.SetStatusWidths([-1, -2, -3])
def OnSketchMotion(self, event):
self.statusbar.SetStatusText("Pos: %s" %
str(event.GetPositionTuple()), 0)
self.statusbar.SetStatusText("Current Pts: %s" %
len(self.sketch.curLine), 1)
self.statusbar.SetStatusText("Line Count: %s" %
len(self.sketch.lines), 2)
event.Skip()
def menuData(self):
return [("&File", (
("&New", "New Sketch file", self.OnNew),
("&Open", "Open sketch file", self.OnOpen),
("&Save", "Save sketch file", self.OnSave),
("", "", ""),
("&Color", (
("&Black", "", self.OnColor, wx.ITEM_RADIO),
("&Red", "", self.OnColor, wx.ITEM_RADIO),
("&Green", "", self.OnColor, wx.ITEM_RADIO),
("&Blue", "", self.OnColor, wx.ITEM_RADIO),
("&Other...", "", self.OnOtherColor, wx.ITEM_RADIO))),
("", "", ""),
("&Quit", "Quit", self.OnCloseWindow)))]
def createMenuBar(self):
menuBar = wx.MenuBar()
for eachMenuData in self.menuData():
menuLabel = eachMenuData[0]
menuItems = eachMenuData[1]
menuBar.Append(self.createMenu(menuItems), menuLabel)
self.SetMenuBar(menuBar)
def createMenu(self, menuData):
menu = wx.Menu()
for eachItem in menuData:
if len(eachItem) == 2:
label = eachItem[0]
subMenu = self.createMenu(eachItem[1])
menu.AppendMenu(wx.NewId(), label, subMenu)
else:
self.createMenuItem(menu, *eachItem)
return menu
def createMenuItem(self, menu, label, status, handler, kind=wx.ITEM_NORMAL):
if not label:
menu.AppendSeparator()
return
menuItem = menu.Append(-1, label, status, kind)
self.Bind(wx.EVT_MENU, handler, menuItem)
def createToolBar(self):
toolbar = self.CreateToolBar()
for each in self.toolbarData():
self.createSimpleTool(toolbar, *each)
toolbar.AddSeparator()
for each in self.toolbarColorData():
self.createColorTool(toolbar, each)
toolbar.Realize()
def createSimpleTool(self, toolbar, label, filename, help, handler):
if not label:
toolbar.AddSeparator()
return
bmp = wx.Image(filename, wx.BITMAP_TYPE_BMP).ConvertToBitmap()
tool = toolbar.AddSimpleTool(-1, bmp, label, help)
self.Bind(wx.EVT_MENU, handler, tool)
def toolbarData(self):
return (("New", "new.bmp", "Create new sketch", self.OnNew),
("", "", "", ""),
("Open", "open.bmp", "Open existing sketch", self.OnOpen),
("Save", "save.bmp", "Save existing sketch", self.OnSave))
def createColorTool(self, toolbar, color):
bmp = self.MakeBitmap(color)
tool = toolbar.AddRadioTool(-1, bmp, shortHelp=color)
self.Bind(wx.EVT_MENU, self.OnColor, tool)
def MakeBitmap(self, color):
bmp = wx.EmptyBitmap(16, 15)
dc = wx.MemoryDC()
dc.SelectObject(bmp)
dc.SetBackground(wx.Brush(color))
dc.Clear()
dc.SelectObject(wx.NullBitmap)
return bmp
def toolbarColorData(self):
return ("Black", "Red", "Green", "Blue")
def OnNew(self, event): pass
def OnColor(self, event):
menubar = self.GetMenuBar()
itemId = event.GetId()
item = menubar.FindItemById(itemId)
if not item:
toolbar = self.GetToolBar()
item = toolbar.FindById(itemId)
color = item.GetShortHelp()
else:
color = item.GetLabel()
self.sketch.SetColor(color)
def OnCloseWindow(self, event):
self.Destroy()
def SaveFile(self):
if self.filename:
data = self.sketch.GetLinesData()
f = open(self.filename, 'w')
cPickle.dump(data, f)
f.close()
def ReadFile(self):
if self.filename:
try:
f = open(self.filename, 'r')
data = cPickle.load(f)
f.close()
self.sketch.SetLinesData(data)
except cPickle.UnpicklingError:
wx.MessageBox("%s is not a sketch file." % self.filename,
"oops!", style=wx.OK|wx.ICON_EXCLAMATION)
wildcard = "Sketch files (*.sketch)|*.sketch|All files (*.*)|*.*"
def OnOpen(self, event):
dlg = wx.FileDialog(self, "Open sketch file...", os.getcwd(),
style=wx.OPEN, wildcard=self.wildcard)
if dlg.ShowModal() == wx.ID_OK:
self.filename = dlg.GetPath()
self.ReadFile()
self.SetTitle(self.title + ' -- ' + self.filename)
dlg.Destroy()
def OnSave(self, event):
if not self.filename:
self.OnSaveAs(event)
else:
self.SaveFile()
def OnSaveAs(self, event):
dlg = wx.FileDialog(self, "Save sketch as...", os.getcwd(),
style=wx.SAVE | wx.OVERWRITE_PROMPT,
wildcard = self.wildcard)
if dlg.ShowModal() == wx.ID_OK:
filename = dlg.GetPath()
if not os.path.splitext(filename)[1]:
filename = filename + '.sketch'
self.filename = filename
self.SaveFile()
self.SetTitle(self.title + ' -- ' + self.filename)
dlg.Destroy()
def OnOtherColor(self, event):
dlg = wx.ColourDialog(frame)
dlg.GetColourData().SetChooseFull(True)
if dlg.ShowModal() == wx.ID_OK:
self.sketch.SetColor(dlg.GetColourData().GetColour())
dlg.Destroy()
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = SketchFrame(None)
frame.Show(True)
app.MainLoop()

View File

@ -0,0 +1,331 @@
import wx
import wx.html
import cPickle
import os
from wx.lib import buttons
from example1 import SketchWindow
class SketchFrame(wx.Frame):
def __init__(self, parent):
self.title = "Sketch Frame"
wx.Frame.__init__(self, parent, -1, self.title,
size=(800,600))
self.filename = ""
self.sketch = SketchWindow(self, -1)
wx.EVT_MOTION(self.sketch, self.OnSketchMotion)
self.initStatusBar()
self.createMenuBar()
self.createToolBar()
self.createPanel()
def createPanel(self):
controlPanel = ControlPanel(self, -1, self.sketch)
box = wx.BoxSizer(wx.HORIZONTAL)
box.Add(controlPanel, 0, wx.EXPAND)
box.Add(self.sketch, 1, wx.EXPAND)
self.SetSizer(box)
def initStatusBar(self):
self.statusbar = self.CreateStatusBar()
self.statusbar.SetFieldsCount(3)
self.statusbar.SetStatusWidths([-1, -2, -3])
def OnSketchMotion(self, event):
self.statusbar.SetStatusText("Pos: %s" %
str(event.GetPositionTuple()), 0)
self.statusbar.SetStatusText("Current Pts: %s" %
len(self.sketch.curLine), 1)
self.statusbar.SetStatusText("Line Count: %s" %
len(self.sketch.lines), 2)
event.Skip()
def menuData(self):
return [("&File", (
("&New", "New Sketch file", self.OnNew),
("&Open", "Open sketch file", self.OnOpen),
("&Save", "Save sketch file", self.OnSave),
("", "", ""),
("&Color", (
("&Black", "", self.OnColor, wx.ITEM_RADIO),
("&Red", "", self.OnColor, wx.ITEM_RADIO),
("&Green", "", self.OnColor, wx.ITEM_RADIO),
("&Blue", "", self.OnColor, wx.ITEM_RADIO),
("&Other...", "", self.OnOtherColor, wx.ITEM_RADIO))),
("", "", ""),
("About...", "Show about window", self.OnAbout),
("&Quit", "Quit", self.OnCloseWindow)))]
def createMenuBar(self):
menuBar = wx.MenuBar()
for eachMenuData in self.menuData():
menuLabel = eachMenuData[0]
menuItems = eachMenuData[1]
menuBar.Append(self.createMenu(menuItems), menuLabel)
self.SetMenuBar(menuBar)
def createMenu(self, menuData):
menu = wx.Menu()
for eachItem in menuData:
if len(eachItem) == 2:
label = eachItem[0]
subMenu = self.createMenu(eachItem[1])
menu.AppendMenu(wx.NewId(), label, subMenu)
else:
self.createMenuItem(menu, *eachItem)
return menu
def createMenuItem(self, menu, label, status, handler, kind=wx.ITEM_NORMAL):
if not label:
menu.AppendSeparator()
return
menuItem = menu.Append(-1, label, status, kind)
self.Bind(wx.EVT_MENU, handler, menuItem)
def createToolBar(self):
toolbar = self.CreateToolBar()
for each in self.toolbarData():
self.createSimpleTool(toolbar, *each)
toolbar.AddSeparator()
for each in self.toolbarColorData():
self.createColorTool(toolbar, each)
toolbar.Realize()
def createSimpleTool(self, toolbar, label, filename, help, handler):
if not label:
toolbar.AddSeparator()
return
bmp = wx.Image(filename, wx.BITMAP_TYPE_BMP).ConvertToBitmap()
tool = toolbar.AddSimpleTool(-1, bmp, label, help)
self.Bind(wx.EVT_MENU, handler, tool)
def toolbarData(self):
return (("New", "new.bmp", "Create new sketch", self.OnNew),
("", "", "", ""),
("Open", "open.bmp", "Open existing sketch", self.OnOpen),
("Save", "save.bmp", "Save existing sketch", self.OnSave))
def createColorTool(self, toolbar, color):
bmp = self.MakeBitmap(color)
tool = toolbar.AddRadioTool(-1, bmp, shortHelp=color)
self.Bind(wx.EVT_MENU, self.OnColor, tool)
def MakeBitmap(self, color):
bmp = wx.EmptyBitmap(16, 15)
dc = wx.MemoryDC()
dc.SelectObject(bmp)
dc.SetBackground(wx.Brush(color))
dc.Clear()
dc.SelectObject(wx.NullBitmap)
return bmp
def toolbarColorData(self):
return ("Black", "Red", "Green", "Blue")
def OnNew(self, event): pass
def OnColor(self, event):
menubar = self.GetMenuBar()
itemId = event.GetId()
item = menubar.FindItemById(itemId)
if not item:
toolbar = self.GetToolBar()
item = toolbar.FindById(itemId)
color = item.GetShortHelp()
else:
color = item.GetLabel()
self.sketch.SetColor(color)
def OnCloseWindow(self, event):
self.Destroy()
def SaveFile(self):
if self.filename:
data = self.sketch.GetLinesData()
f = open(self.filename, 'w')
cPickle.dump(data, f)
f.close()
def ReadFile(self):
if self.filename:
try:
f = open(self.filename, 'r')
data = cPickle.load(f)
f.close()
self.sketch.SetLinesData(data)
except cPickle.UnpicklingError:
wx.MessageBox("%s is not a sketch file." % self.filename,
"oops!", style=wx.OK|wx.ICON_EXCLAMATION)
wildcard = "Sketch files (*.sketch)|*.sketch|All files (*.*)|*.*"
def OnOpen(self, event):
dlg = wx.FileDialog(self, "Open sketch file...", os.getcwd(),
style=wx.OPEN, wildcard=self.wildcard)
if dlg.ShowModal() == wx.ID_OK:
self.filename = dlg.GetPath()
self.ReadFile()
self.SetTitle(self.title + ' -- ' + self.filename)
dlg.Destroy()
def OnSave(self, event):
if not self.filename:
self.OnSaveAs(event)
else:
self.SaveFile()
def OnSaveAs(self, event):
dlg = wx.FileDialog(self, "Save sketch as...", os.getcwd(),
style=wx.SAVE | wx.OVERWRITE_PROMPT,
wildcard = self.wildcard)
if dlg.ShowModal() == wx.ID_OK:
filename = dlg.GetPath()
if not os.path.splitext(filename)[1]:
filename = filename + '.sketch'
self.filename = filename
self.SaveFile()
self.SetTitle(self.title + ' -- ' + self.filename)
dlg.Destroy()
def OnOtherColor(self, event):
dlg = wx.ColourDialog(frame)
dlg.GetColourData().SetChooseFull(True)
if dlg.ShowModal() == wx.ID_OK:
self.sketch.SetColor(dlg.GetColourData().GetColour())
dlg.Destroy()
def OnAbout(self, event):
dlg = SketchAbout(self)
dlg.ShowModal()
dlg.Destroy()
class SketchAbout(wx.Dialog):
text = '''
<html>
<body bgcolor="#ACAA60">
<center><table bgcolor="#455481" width="100%" cellspacing="0"
cellpadding="0" border="1">
<tr>
<td align="center"><h1>Sketch!</h1></td>
</tr>
</table>
</center>
<p><b>Sketch</b> is a demonstration program for <b>wxPython In Action</b>
Chapter 7. It is based on the SuperDoodle demo included with wxPython,
available at http://www.wxpython.org/
</p>
<p><b>SuperDoodle</b> and <b>wxPython</b> are brought to you by
<b>Robin Dunn</b> and <b>Total Control Software</b>, Copyright
&copy; 1997-2006.</p>
</body>
</html>
'''
def __init__(self, parent):
wx.Dialog.__init__(self, parent, -1, 'About Sketch',
size=(440, 400) )
html = wx.html.HtmlWindow(self)
html.SetPage(self.text)
button = wx.Button(self, wx.ID_OK, "Okay")
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(html, 1, wx.EXPAND|wx.ALL, 5)
sizer.Add(button, 0, wx.ALIGN_CENTER|wx.ALL, 5)
self.SetSizer(sizer)
self.Layout()
class ControlPanel(wx.Panel):
BMP_SIZE = 16
BMP_BORDER = 3
NUM_COLS = 4
SPACING = 4
colorList = ('Black', 'Yellow', 'Red', 'Green', 'Blue', 'Purple',
'Brown', 'Aquamarine', 'Forest Green', 'Light Blue',
'Goldenrod', 'Cyan', 'Orange', 'Navy', 'Dark Grey',
'Light Grey')
maxThickness = 16
def __init__(self, parent, ID, sketch):
wx.Panel.__init__(self, parent, ID, style=wx.RAISED_BORDER)
self.sketch = sketch
buttonSize = (self.BMP_SIZE + 2 * self.BMP_BORDER,
self.BMP_SIZE + 2 * self.BMP_BORDER)
colorGrid = self.createColorGrid(parent, buttonSize)
thicknessGrid = self.createThicknessGrid(buttonSize)
self.layout(colorGrid, thicknessGrid)
def createColorGrid(self, parent, buttonSize):
self.colorMap = {}
self.colorButtons = {}
colorGrid = wx.GridSizer(cols=self.NUM_COLS, hgap=2, vgap=2)
for eachColor in self.colorList:
bmp = parent.MakeBitmap(eachColor)
b = buttons.GenBitmapToggleButton(self, -1, bmp, size=buttonSize)
b.SetBezelWidth(1)
b.SetUseFocusIndicator(False)
self.Bind(wx.EVT_BUTTON, self.OnSetColour, b)
colorGrid.Add(b, 0)
self.colorMap[b.GetId()] = eachColor
self.colorButtons[eachColor] = b
self.colorButtons[self.colorList[0]].SetToggle(True)
return colorGrid
def createThicknessGrid(self, buttonSize):
self.thicknessIdMap = {}
self.thicknessButtons = {}
thicknessGrid = wx.GridSizer(cols=self.NUM_COLS, hgap=2, vgap=2)
for x in range(1, self.maxThickness + 1):
b = buttons.GenToggleButton(self, -1, str(x), size=buttonSize)
b.SetBezelWidth(1)
b.SetUseFocusIndicator(False)
self.Bind(wx.EVT_BUTTON, self.OnSetThickness, b)
thicknessGrid.Add(b, 0)
self.thicknessIdMap[b.GetId()] = x
self.thicknessButtons[x] = b
self.thicknessButtons[1].SetToggle(True)
return thicknessGrid
def layout(self, colorGrid, thicknessGrid):
box = wx.BoxSizer(wx.VERTICAL)
box.Add(colorGrid, 0, wx.ALL, self.SPACING)
box.Add(thicknessGrid, 0, wx.ALL, self.SPACING)
self.SetSizer(box)
box.Fit(self)
def OnSetColour(self, event):
color = self.colorMap[event.GetId()]
if color != self.sketch.color:
self.colorButtons[self.sketch.color].SetToggle(False)
self.sketch.SetColor(color)
def OnSetThickness(self, event):
thickness = self.thicknessIdMap[event.GetId()]
if thickness != self.sketch.thickness:
self.thicknessButtons[self.sketch.thickness].SetToggle(False)
self.sketch.SetThickness(thickness)
class SketchApp(wx.App):
def OnInit(self):
bmp = wx.Image("splash.png").ConvertToBitmap()
wx.SplashScreen(bmp, wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT,
1000, None, -1)
wx.Yield()
frame = SketchFrame(None)
frame.Show(True)
self.SetTopWindow(frame)
return True
if __name__ == '__main__':
app = SketchApp(False)
app.MainLoop()

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View File

@ -0,0 +1,25 @@
import wx
class BitmapButtonFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Bitmap Button Example',
size=(200, 150))
panel = wx.Panel(self, -1)
bmp = wx.Image("bitmap.bmp", wx.BITMAP_TYPE_BMP).ConvertToBitmap()
self.button = wx.BitmapButton(panel, -1, bmp, pos=(10, 20))
self.Bind(wx.EVT_BUTTON, self.OnClick, self.button)
self.button.SetDefault()
self.button2 = wx.BitmapButton(panel, -1, bmp, pos=(100, 20),
style=0)
self.Bind(wx.EVT_BUTTON, self.OnClick, self.button2)
def OnClick(self, event):
self.Destroy()
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = BitmapButtonFrame()
frame.Show()
app.MainLoop()

View File

@ -0,0 +1,21 @@
import wx
class ButtonFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Button Example',
size=(300, 100))
panel = wx.Panel(self, -1)
self.button = wx.Button(panel, -1, "Hello", pos=(50, 20))
self.Bind(wx.EVT_BUTTON, self.OnClick, self.button)
self.button.SetDefault()
def OnClick(self, event):
self.button.SetLabel("Clicked")
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = ButtonFrame()
frame.Show()
app.MainLoop()

View File

@ -0,0 +1,16 @@
import wx
class CheckBoxFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Checkbox Example',
size=(150, 200))
panel = wx.Panel(self, -1)
wx.CheckBox(panel, -1, "Alpha", (35, 40), (150, 20))
wx.CheckBox(panel, -1, "Beta", (35, 60), (150, 20))
wx.CheckBox(panel, -1, "Gamma", (35, 80), (150, 20))
if __name__ == '__main__':
app = wx.PySimpleApp()
CheckBoxFrame().Show()
app.MainLoop()

View File

@ -0,0 +1,16 @@
import wx
class ChoiceFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Choice Example',
size=(250, 200))
panel = wx.Panel(self, -1)
sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
'six', 'seven', 'eight']
wx.StaticText(panel, -1, "Select one:", (15, 20))
wx.Choice(panel, -1, (85, 18), choices=sampleList)
if __name__ == '__main__':
app = wx.PySimpleApp()
ChoiceFrame().Show()
app.MainLoop()

View File

@ -0,0 +1,19 @@
import wx
class ComboBoxFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Combo Box Example',
size=(350, 300))
panel = wx.Panel(self, -1)
sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
'six', 'seven', 'eight']
wx.StaticText(panel, -1, "Select one:", (15, 15))
wx.ComboBox(panel, -1, "default value", (15, 30), wx.DefaultSize,
sampleList, wx.CB_DROPDOWN)
wx.ComboBox(panel, -1, "default value", (150, 30), wx.DefaultSize,
sampleList, wx.CB_SIMPLE)
if __name__ == '__main__':
app = wx.PySimpleApp()
ComboBoxFrame().Show()
app.MainLoop()

View File

@ -0,0 +1,23 @@
import wx
class GaugeFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Gauge Example',
size=(350, 150))
panel = wx.Panel(self, -1)
self.count = 0
self.gauge = wx.Gauge(panel, -1, 50, (20, 50), (250, 25))
self.gauge.SetBezelFace(3)
self.gauge.SetShadowWidth(3)
self.Bind(wx.EVT_IDLE, self.OnIdle)
def OnIdle(self, event):
self.count = self.count + 1
if self.count >= 50:
self.count = 0
self.gauge.SetValue(self.count)
if __name__ == '__main__':
app = wx.PySimpleApp()
GaugeFrame().Show()
app.MainLoop()

View File

@ -0,0 +1,56 @@
import wx
import wx.lib.buttons as buttons
class GenericButtonFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Generic Button Example',
size=(500, 350))
panel = wx.Panel(self, -1)
sizer = wx.FlexGridSizer(1, 3, 20, 20)
b = wx.Button(panel, -1, "A wx.Button")
b.SetDefault()
sizer.Add(b)
b = wx.Button(panel, -1, "non-default wx.Button")
sizer.Add(b)
sizer.Add((10,10))
b = buttons.GenButton(panel, -1, 'Generic Button')
sizer.Add(b)
b = buttons.GenButton(panel, -1, 'disabled Generic')
b.Enable(False)
sizer.Add(b)
b = buttons.GenButton(panel, -1, 'bigger')
b.SetFont(wx.Font(20, wx.SWISS, wx.NORMAL, wx.BOLD, False))
b.SetBezelWidth(5)
b.SetBackgroundColour("Navy")
b.SetForegroundColour("white")
b.SetToolTipString("This is a BIG button...")
sizer.Add(b)
bmp = wx.Image("bitmap.bmp", wx.BITMAP_TYPE_BMP).ConvertToBitmap()
b = buttons.GenBitmapButton(panel, -1, bmp)
sizer.Add(b)
b = buttons.GenBitmapToggleButton(panel, -1, bmp)
sizer.Add(b)
b = buttons.GenBitmapTextButton(panel, -1, bmp, "Bitmapped Text",
size=(175, 75))
b.SetUseFocusIndicator(False)
sizer.Add(b)
b = buttons.GenToggleButton(panel, -1, "Toggle Button")
sizer.Add(b)
panel.SetSizer(sizer)
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = GenericButtonFrame()
frame.Show()
app.MainLoop()

View File

@ -0,0 +1,21 @@
import wx
class ListBoxFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'List Box Example',
size=(250, 200))
panel = wx.Panel(self, -1)
sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
'six', 'seven', 'eight', 'nine', 'ten', 'eleven',
'twelve', 'thirteen', 'fourteen']
listBox = wx.ListBox(panel, -1, (20, 20), (80, 120), sampleList,
wx.LB_SINGLE)
listBox.SetSelection(3)
if __name__ == '__main__':
app = wx.PySimpleApp()
ListBoxFrame().Show()
app.MainLoop()

View File

@ -0,0 +1,32 @@
import wx
class RadioButtonFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Radio Example',
size=(200, 200))
panel = wx.Panel(self, -1)
radio1 = wx.RadioButton(panel, -1, "Elmo", pos=(20, 50), style=wx.RB_GROUP)
radio2 = wx.RadioButton(panel, -1, "Ernie", pos=(20, 80))
radio3 = wx.RadioButton(panel, -1, "Bert", pos=(20, 110))
text1 = wx.TextCtrl(panel, -1, "", pos=(80, 50))
text2 = wx.TextCtrl(panel, -1, "", pos=(80, 80))
text3 = wx.TextCtrl(panel, -1, "", pos=(80, 110))
self.texts = {"Elmo": text1, "Ernie": text2, "Bert": text3}
for eachText in [text2, text3]:
eachText.Enable(False)
for eachRadio in [radio1, radio2, radio3]:
self.Bind(wx.EVT_RADIOBUTTON, self.OnRadio, eachRadio)
self.selectedText = text1
def OnRadio(self, event):
if self.selectedText:
self.selectedText.Enable(False)
radioSelected = event.GetEventObject()
text = self.texts[radioSelected.GetLabel()]
text.Enable(True)
self.selectedText = text
if __name__ == '__main__':
app = wx.PySimpleApp()
RadioButtonFrame().Show()
app.MainLoop()

View File

@ -0,0 +1,19 @@
import wx
class RadioBoxFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Radio Box Example',
size=(350, 200))
panel = wx.Panel(self, -1)
sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
'six', 'seven', 'eight']
wx.RadioBox(panel, -1, "A Radio Box", (10, 10), wx.DefaultSize,
sampleList, 2, wx.RA_SPECIFY_COLS)
wx.RadioBox(panel, -1, "", (150, 10), wx.DefaultSize,
sampleList, 3, wx.RA_SPECIFY_COLS | wx.NO_BORDER)
if __name__ == '__main__':
app = wx.PySimpleApp()
RadioBoxFrame().Show()
app.MainLoop()

View File

@ -0,0 +1,22 @@
import wx
class SliderFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Slider Example',
size=(300, 350))
panel = wx.Panel(self, -1)
self.count = 0
slider = wx.Slider(panel, 100, 25, 1, 100, pos=(10, 10),
size=(250, -1),
style=wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | wx.SL_LABELS )
slider.SetTickFreq(5, 1)
slider = wx.Slider(panel, 100, 25, 1, 100, pos=(125, 70),
size=(-1, 250),
style=wx.SL_VERTICAL | wx.SL_AUTOTICKS | wx.SL_LABELS )
slider.SetTickFreq(20, 1)
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = SliderFrame()
frame.Show()
app.MainLoop()

View File

@ -0,0 +1,15 @@
import wx
class SpinnerFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Spinner Example',
size=(100, 100))
panel = wx.Panel(self, -1)
sc = wx.SpinCtrl(panel, -1, "", (30, 20), (80, -1))
sc.SetRange(1,100)
sc.SetValue(5)
if __name__ == '__main__':
app = wx.PySimpleApp()
SpinnerFrame().Show()
app.MainLoop()

View File

@ -0,0 +1,38 @@
import wx
class StaticTextFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Static Text Example',
size=(400, 300))
panel = wx.Panel(self, -1)
wx.StaticText(panel, -1, "This is an example of static text",
(100, 10))
rev = wx.StaticText(panel, -1, "Static Text With Reversed Colors",
(100, 30))
rev.SetForegroundColour('white')
rev.SetBackgroundColour('black')
center = wx.StaticText(panel, -1, "align center", (100, 50),
(160, -1), wx.ALIGN_CENTER)
center.SetForegroundColour('white')
center.SetBackgroundColour('black')
right = wx.StaticText(panel, -1, "align right", (100, 70),
(160, -1), wx.ALIGN_RIGHT)
right.SetForegroundColour('white')
right.SetBackgroundColour('black')
str = "You can also change the font."
text = wx.StaticText(panel, -1, str, (20, 100))
font = wx.Font(18, wx.DECORATIVE, wx.ITALIC, wx.NORMAL)
text.SetFont(font)
wx.StaticText(panel, -1, "Your text\ncan be split\n"
"over multiple lines\n\neven blank ones", (20,150))
wx.StaticText(panel, -1, "Multi-line text\ncan also\n"
"be right aligned\n\neven with a blank", (220,150),
style=wx.ALIGN_RIGHT)
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = StaticTextFrame()
frame.Show()
app.MainLoop()

View File

@ -0,0 +1,25 @@
import wx
class TextFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Text Entry Example',
size=(300, 100))
panel = wx.Panel(self, -1)
basicLabel = wx.StaticText(panel, -1, "Basic Control:")
basicText = wx.TextCtrl(panel, -1, "I've entered some text!",
size=(175, -1))
basicText.SetInsertionPoint(0)
pwdLabel = wx.StaticText(panel, -1, "Password:")
pwdText = wx.TextCtrl(panel, -1, "password", size=(175, -1),
style=wx.TE_PASSWORD)
sizer = wx.FlexGridSizer(cols=2, hgap=6, vgap=6)
sizer.AddMany([basicLabel, basicText, pwdLabel, pwdText])
panel.SetSizer(sizer)
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = TextFrame()
frame.Show()
app.MainLoop()

View File

@ -0,0 +1,33 @@
import wx
class TextFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Text Entry Example',
size=(300, 250))
panel = wx.Panel(self, -1)
multiLabel = wx.StaticText(panel, -1, "Multi-line")
multiText = wx.TextCtrl(panel, -1,
"Here is a looooooooooooooong line of text set in the control.\n\n"
"See that it wrapped, and that this line is after a blank",
size=(200, 100), style=wx.TE_MULTILINE)
multiText.SetInsertionPoint(0)
richLabel = wx.StaticText(panel, -1, "Rich Text")
richText = wx.TextCtrl(panel, -1,
"If supported by the native control, this is reversed, and this is a different font.",
size=(200, 100), style=wx.TE_MULTILINE|wx.TE_RICH2)
richText.SetInsertionPoint(0)
richText.SetStyle(44, 52, wx.TextAttr("white", "black"))
points = richText.GetFont().GetPointSize()
f = wx.Font(points + 3, wx.ROMAN, wx.ITALIC, wx.BOLD, True)
richText.SetStyle(68, 82, wx.TextAttr("blue", wx.NullColour, f))
sizer = wx.FlexGridSizer(cols=2, hgap=6, vgap=6)
sizer.AddMany([multiLabel, multiText, richLabel, richText])
panel.SetSizer(sizer)
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = TextFrame()
frame.Show()
app.MainLoop()

View File

@ -0,0 +1,21 @@
import wx
class SubclassFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Frame Subclass',
size=(300, 100))
panel = wx.Panel(self, -1)
button = wx.Button(panel, -1, "Close Me", pos=(15, 15))
self.Bind(wx.EVT_BUTTON, self.OnCloseMe, button)
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
def OnCloseMe(self, event):
self.Close(True)
def OnCloseWindow(self, event):
self.Destroy()
if __name__ == '__main__':
app = wx.PySimpleApp()
SubclassFrame().Show()
app.MainLoop()

View File

@ -0,0 +1,16 @@
import wx
class HelpFrame(wx.Frame):
def __init__(self):
pre = wx.PreFrame()
pre.SetExtraStyle(wx.FRAME_EX_CONTEXTHELP)
pre.Create(None, -1, "Help Context", size=(300, 100),
style=wx.DEFAULT_FRAME_STYLE ^
(wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX))
self.PostCreate(pre)
if __name__ == '__main__':
app = wx.PySimpleApp()
HelpFrame().Show()
app.MainLoop()

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,29 @@
import wx
class MDIFrame(wx.MDIParentFrame):
def __init__(self):
wx.MDIParentFrame.__init__(self, None, -1, "MDI Parent",
size=(600,400))
menu = wx.Menu()
menu.Append(5000, "&New Window")
menu.Append(5001, "E&xit")
menubar = wx.MenuBar()
menubar.Append(menu, "&File")
self.SetMenuBar(menubar)
self.Bind(wx.EVT_MENU, self.OnNewWindow, id=5000)
self.Bind(wx.EVT_MENU, self.OnExit, id=5001)
def OnExit(self, evt):
self.Close(True)
def OnNewWindow(self, evt):
win = wx.MDIChildFrame(self, -1, "Child Window")
win.Show(True)
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = MDIFrame()
frame.Show()
app.MainLoop()

View File

@ -0,0 +1,21 @@
import wx
class MiniFrame(wx.MiniFrame):
def __init__(self):
wx.MiniFrame.__init__(self, None, -1, 'Mini Frame',
size=(300, 100))
panel = wx.Panel(self, -1, size=(300, 100))
button = wx.Button(panel, -1, "Close Me", pos=(15, 15))
self.Bind(wx.EVT_BUTTON, self.OnCloseMe, button)
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
def OnCloseMe(self, event):
self.Close(True)
def OnCloseWindow(self, event):
self.Destroy()
if __name__ == '__main__':
app = wx.PySimpleApp()
MiniFrame().Show()
app.MainLoop()

View File

@ -0,0 +1,26 @@
import wx
class ScrollbarFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Scrollbar Example',
size=(300, 200))
self.scroll = wx.ScrolledWindow(self, -1)
self.scroll.SetScrollbars(1, 1, 600, 400)
self.button = wx.Button(self.scroll, -1, "Scroll Me", pos=(50, 20))
self.Bind(wx.EVT_BUTTON, self.OnClickTop, self.button)
self.button2 = wx.Button(self.scroll, -1, "Scroll Back", pos=(500, 350))
self.Bind(wx.EVT_BUTTON, self.OnClickBottom, self.button2)
def OnClickTop(self, event):
self.scroll.Scroll(600, 400)
def OnClickBottom(self, event):
self.scroll.Scroll(1, 1)
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = ScrollbarFrame()
frame.Show()
app.MainLoop()

View File

@ -0,0 +1,43 @@
import wx
import images
class ShapedFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "Shaped Window",
style = wx.FRAME_SHAPED | wx.SIMPLE_BORDER |
wx.FRAME_NO_TASKBAR)
self.hasShape = False
self.bmp = images.getVippiBitmap()
self.SetClientSize((self.bmp.GetWidth(), self.bmp.GetHeight()))
dc = wx.ClientDC(self)
dc.DrawBitmap(self.bmp, 0,0, True)
self.SetWindowShape()
self.Bind(wx.EVT_LEFT_DCLICK, self.OnDoubleClick)
self.Bind(wx.EVT_RIGHT_UP, self.OnExit)
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_WINDOW_CREATE, self.SetWindowShape)
def SetWindowShape(self, evt=None):
r = wx.RegionFromBitmap(self.bmp)
self.hasShape = self.SetShape(r)
def OnDoubleClick(self, evt):
if self.hasShape:
self.SetShape(wx.Region())
self.hasShape = False
else:
self.SetWindowShape()
def OnPaint(self, evt):
dc = wx.PaintDC(self)
dc.DrawBitmap(self.bmp, 0,0, True)
def OnExit(self, evt):
self.Close()
if __name__ == '__main__':
app = wx.PySimpleApp()
ShapedFrame().Show()
app.MainLoop()

View File

@ -0,0 +1,64 @@
import wx
import images
class ShapedFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "Shaped Window",
style = wx.FRAME_SHAPED | wx.SIMPLE_BORDER )
self.hasShape = False
self.delta = wx.Point(0,0)
self.bmp = images.getVippiBitmap()
self.SetClientSize((self.bmp.GetWidth(), self.bmp.GetHeight()))
dc = wx.ClientDC(self)
dc.DrawBitmap(self.bmp, 0,0, True)
self.SetWindowShape()
self.Bind(wx.EVT_LEFT_DCLICK, self.OnDoubleClick)
self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
self.Bind(wx.EVT_MOTION, self.OnMouseMove)
self.Bind(wx.EVT_RIGHT_UP, self.OnExit)
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_WINDOW_CREATE, self.SetWindowShape)
def SetWindowShape(self, evt=None):
r = wx.RegionFromBitmap(self.bmp)
self.hasShape = self.SetShape(r)
def OnDoubleClick(self, evt):
if self.hasShape:
self.SetShape(wx.Region())
self.hasShape = False
else:
self.SetWindowShape()
def OnPaint(self, evt):
dc = wx.PaintDC(self)
dc.DrawBitmap(self.bmp, 0,0, True)
def OnExit(self, evt):
self.Close()
def OnLeftDown(self, evt):
self.CaptureMouse()
pos = self.ClientToScreen(evt.GetPosition())
origin = self.GetPosition()
self.delta = wx.Point(pos.x - origin.x, pos.y - origin.y)
def OnMouseMove(self, evt):
if evt.Dragging() and evt.LeftIsDown():
pos = self.ClientToScreen(evt.GetPosition())
newPos = (pos.x - self.delta.x, pos.y - self.delta.y)
self.Move(newPos)
def OnLeftUp(self, evt):
if self.HasCapture():
self.ReleaseMouse()
if __name__ == '__main__':
app = wx.PySimpleApp()
ShapedFrame().Show()
app.MainLoop()

View File

@ -0,0 +1,8 @@
import wx
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = wx.Frame(None, -1, "A Frame", style=wx.DEFAULT_FRAME_STYLE,
size=(200, 100))
frame.Show()
app.MainLoop()

View File

@ -0,0 +1,101 @@
import wx
class SplitterExampleFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title=title)
self.MakeMenuBar()
self.minpane = 0
self.initpos = 0
self.sp = wx.SplitterWindow(self)
self.p1 = wx.Panel(self.sp, style=wx.SUNKEN_BORDER)
self.p2 = wx.Panel(self.sp, style=wx.SUNKEN_BORDER)
self.p1.SetBackgroundColour("pink")
self.p2.SetBackgroundColour("sky blue")
self.p1.Hide()
self.p2.Hide()
self.sp.Initialize(self.p1)
self.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGING,
self.OnSashChanging, self.sp)
self.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED,
self.OnSashChanged, self.sp)
def MakeMenuBar(self):
menu = wx.Menu()
item = menu.Append(-1, "Split horizontally")
self.Bind(wx.EVT_MENU, self.OnSplitH, item)
self.Bind(wx.EVT_UPDATE_UI, self.OnCheckCanSplit, item)
item = menu.Append(-1, "Split vertically")
self.Bind(wx.EVT_MENU, self.OnSplitV, item)
self.Bind(wx.EVT_UPDATE_UI, self.OnCheckCanSplit, item)
item = menu.Append(-1, "Unsplit")
self.Bind(wx.EVT_MENU, self.OnUnsplit, item)
self.Bind(wx.EVT_UPDATE_UI, self.OnCheckCanUnsplit, item)
menu.AppendSeparator()
item = menu.Append(-1, "Set initial sash position")
self.Bind(wx.EVT_MENU, self.OnSetPos, item)
item = menu.Append(-1, "Set minimum pane size")
self.Bind(wx.EVT_MENU, self.OnSetMin, item)
menu.AppendSeparator()
item = menu.Append(wx.ID_EXIT, "E&xit")
self.Bind(wx.EVT_MENU, self.OnExit, item)
mbar = wx.MenuBar()
mbar.Append(menu, "Splitter")
self.SetMenuBar(mbar)
def OnSashChanging(self, evt):
print "OnSashChanging:", evt.GetSashPosition()
def OnSashChanged(self, evt):
print "OnSashChanged:", evt.GetSashPosition()
def OnSplitH(self, evt):
self.sp.SplitHorizontally(self.p1, self.p2, self.initpos)
def OnSplitV(self, evt):
self.sp.SplitVertically(self.p1, self.p2, self.initpos)
def OnCheckCanSplit(self, evt):
evt.Enable(not self.sp.IsSplit())
def OnCheckCanUnsplit(self, evt):
evt.Enable(self.sp.IsSplit())
def OnUnsplit(self, evt):
self.sp.Unsplit()
def OnSetMin(self, evt):
minpane = wx.GetNumberFromUser(
"Enter the minimum pane size",
"", "Minimum Pane Size", self.minpane,
0, 1000, self)
if minpane != -1:
self.minpane = minpane
self.sp.SetMinimumPaneSize(self.minpane)
def OnSetPos(self, evt):
initpos = wx.GetNumberFromUser(
"Enter the initial sash position (to be used in the Split call)",
"", "Initial Sash Position", self.initpos,
-1000, 1000, self)
if initpos != -1:
self.initpos = initpos
def OnExit(self, evt):
self.Close()
app = wx.PySimpleApp(redirect=True)
frm = SplitterExampleFrame(None, "Splitter Example")
frm.SetSize((600,500))
frm.Show()
app.SetTopWindow(frm)
app.MainLoop()

View File

@ -0,0 +1,12 @@
import wx
if __name__ == "__main__":
app = wx.PySimpleApp()
choices = ["Alpha", "Baker", "Charlie", "Delta"]
dialog = wx.SingleChoiceDialog(None, "Pick A Word", "Choices",
choices)
if dialog.ShowModal() == wx.ID_OK:
print "You selected: %s\n" % dialog.GetStringSelection()
dialog.Destroy()

View File

@ -0,0 +1,10 @@
import wx
if __name__ == "__main__":
app = wx.PySimpleApp()
dialog = wx.ColourDialog(None)
dialog.GetColourData().SetChooseFull(True)
if dialog.ShowModal() == wx.ID_OK:
data = dialog.GetColourData()
print 'You selected: %s\n' % str(data.GetColour().Get())
dialog.Destroy()

View File

@ -0,0 +1,12 @@
import wx
if __name__ == "__main__":
app = wx.PySimpleApp()
dialog = wx.DirDialog(None, "Choose a directory:",
style=wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON)
if dialog.ShowModal() == wx.ID_OK:
print dialog.GetPath()
dialog.Destroy()

View File

@ -0,0 +1,17 @@
import wx
import os
if __name__ == "__main__":
app = wx.PySimpleApp()
wildcard = "Python source (*.py)|*.py|" \
"Compiled Python (*.pyc)|*.pyc|" \
"All files (*.*)|*.*"
dialog = wx.FileDialog(None, "Choose a file", os.getcwd(),
"", wildcard, wx.OPEN)
if dialog.ShowModal() == wx.ID_OK:
print dialog.GetPath()
dialog.Destroy()

View File

@ -0,0 +1,16 @@
import wx
if __name__ == "__main__":
app = wx.PySimpleApp()
dialog = wx.FontDialog(None, wx.FontData())
if dialog.ShowModal() == wx.ID_OK:
data = dialog.GetFontData()
font = data.GetChosenFont()
colour = data.GetColour()
print 'You selected: "%s", %d points\n' % (
font.GetFaceName(), font.GetPointSize())
dialog.Destroy()

View File

@ -0,0 +1,11 @@
import wx
import wx.lib.imagebrowser as imagebrowser
if __name__ == "__main__":
app = wx.PySimpleApp()
dialog = imagebrowser.ImageDialog(None)
if dialog.ShowModal() == wx.ID_OK:
print "You Selected File: " + dialog.GetFile()
dialog.Destroy()

View File

@ -0,0 +1,16 @@
import wx
if __name__ == "__main__":
app = wx.PySimpleApp()
dlg = wx.MessageDialog(None, "Is this explanation OK?",
'A Message Box',
wx.YES_NO | wx.ICON_QUESTION)
retCode = dlg.ShowModal()
if (retCode == wx.ID_YES):
print "yes"
else:
print "no"
dlg.Destroy()
retCode = wx.MessageBox("Is this way easier?", "Via Function",
wx.YES_NO | wx.ICON_QUESTION)

View File

@ -0,0 +1,21 @@
import wx
class SubclassDialog(wx.Dialog):
def __init__(self):
wx.Dialog.__init__(self, None, -1, 'Dialog Subclass',
size=(300, 100))
okButton = wx.Button(self, wx.ID_OK, "OK", pos=(15, 15))
okButton.SetDefault()
cancelButton = wx.Button(self, wx.ID_CANCEL, "Cancel",
pos=(115, 15))
if __name__ == '__main__':
app = wx.PySimpleApp()
app.MainLoop()
dialog = SubclassDialog()
result = dialog.ShowModal()
if result == wx.ID_OK:
print "OK"
else:
print "Cancel"
dialog.Destroy()

View File

@ -0,0 +1,33 @@
import wx
class Frame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, title="ProgressDialog sample")
self.progressMax = 100
self.count = 0
self.dialog = None
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)
self.timer.Start(1000)
def OnTimer(self, evt):
if not self.dialog:
self.dialog = wx.ProgressDialog("A progress box", "Time remaining",
self.progressMax,
style=wx.PD_CAN_ABORT
| wx.PD_ELAPSED_TIME
| wx.PD_REMAINING_TIME)
self.count += 1
keepGoing = self.dialog.Update(self.count)
if not keepGoing or self.count == self.progressMax:
self.dialog.Destroy()
self.timer.Stop()
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = Frame(None)
frame.Show()
app.MainLoop()

View File

@ -0,0 +1,8 @@
import wx
if __name__ == "__main__":
app = wx.PySimpleApp()
provider = wx.CreateFileTipProvider("tips.txt", 0)
wx.ShowTip(None, provider, True)

View File

@ -0,0 +1,11 @@
import wx
if __name__ == "__main__":
app = wx.PySimpleApp()
dialog = wx.TextEntryDialog(None,
"What kind of text would you like to enter?",
"Text Entry", "Default Value", style=wx.OK|wx.CANCEL)
if dialog.ShowModal() == wx.ID_OK:
print "You entered: %s" % dialog.GetValue()
dialog.Destroy()

View File

@ -0,0 +1,2 @@
You can do startup tips very easily.
Feel the force, Luke.

View File

@ -0,0 +1,93 @@
import wx
about_txt = """\
The validator used in this example will ensure that the text
controls are not empty when you press the Ok button, and
will not let you leave if any of the Validations fail."""
class NotEmptyValidator(wx.PyValidator):
def __init__(self):
wx.PyValidator.__init__(self)
def Clone(self):
"""
Note that every validator must implement the Clone() method.
"""
return NotEmptyValidator()
def Validate(self, win):
textCtrl = self.GetWindow()
text = textCtrl.GetValue()
if len(text) == 0:
wx.MessageBox("This field must contain some text!", "Error")
textCtrl.SetBackgroundColour("pink")
textCtrl.SetFocus()
textCtrl.Refresh()
return False
else:
textCtrl.SetBackgroundColour(
wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW))
textCtrl.Refresh()
return True
def TransferToWindow(self):
return True
def TransferFromWindow(self):
return True
class MyDialog(wx.Dialog):
def __init__(self):
wx.Dialog.__init__(self, None, -1, "Validators: validating")
# Create the text controls
about = wx.StaticText(self, -1, about_txt)
name_l = wx.StaticText(self, -1, "Name:")
email_l = wx.StaticText(self, -1, "Email:")
phone_l = wx.StaticText(self, -1, "Phone:")
name_t = wx.TextCtrl(self, validator=NotEmptyValidator())
email_t = wx.TextCtrl(self, validator=NotEmptyValidator())
phone_t = wx.TextCtrl(self, validator=NotEmptyValidator())
# Use standard button IDs
okay = wx.Button(self, wx.ID_OK)
okay.SetDefault()
cancel = wx.Button(self, wx.ID_CANCEL)
# Layout with sizers
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(about, 0, wx.ALL, 5)
sizer.Add(wx.StaticLine(self), 0, wx.EXPAND|wx.ALL, 5)
fgs = wx.FlexGridSizer(3, 2, 5, 5)
fgs.Add(name_l, 0, wx.ALIGN_RIGHT)
fgs.Add(name_t, 0, wx.EXPAND)
fgs.Add(email_l, 0, wx.ALIGN_RIGHT)
fgs.Add(email_t, 0, wx.EXPAND)
fgs.Add(phone_l, 0, wx.ALIGN_RIGHT)
fgs.Add(phone_t, 0, wx.EXPAND)
fgs.AddGrowableCol(1)
sizer.Add(fgs, 0, wx.EXPAND|wx.ALL, 5)
btns = wx.StdDialogButtonSizer()
btns.AddButton(okay)
btns.AddButton(cancel)
btns.Realize()
sizer.Add(btns, 0, wx.EXPAND|wx.ALL, 5)
self.SetSizer(sizer)
sizer.Fit(self)
app = wx.PySimpleApp()
dlg = MyDialog()
dlg.ShowModal()
dlg.Destroy()
app.MainLoop()

View File

@ -0,0 +1,91 @@
import wx
import pprint
about_txt = """\
The validator used in this example shows how the validator
can be used to transfer data to and from each text control
automatically when the dialog is shown and dismissed."""
class DataXferValidator(wx.PyValidator):
def __init__(self, data, key):
wx.PyValidator.__init__(self)
self.data = data
self.key = key
def Clone(self):
"""
Note that every validator must implement the Clone() method.
"""
return DataXferValidator(self.data, self.key)
def Validate(self, win):
return True
def TransferToWindow(self):
textCtrl = self.GetWindow()
textCtrl.SetValue(self.data.get(self.key, ""))
return True
def TransferFromWindow(self):
textCtrl = self.GetWindow()
self.data[self.key] = textCtrl.GetValue()
return True
class MyDialog(wx.Dialog):
def __init__(self, data):
wx.Dialog.__init__(self, None, -1, "Validators: data transfer")
# Create the text controls
about = wx.StaticText(self, -1, about_txt)
name_l = wx.StaticText(self, -1, "Name:")
email_l = wx.StaticText(self, -1, "Email:")
phone_l = wx.StaticText(self, -1, "Phone:")
name_t = wx.TextCtrl(self, validator=DataXferValidator(data, "name"))
email_t = wx.TextCtrl(self, validator=DataXferValidator(data, "email"))
phone_t = wx.TextCtrl(self, validator=DataXferValidator(data, "phone"))
# Use standard button IDs
okay = wx.Button(self, wx.ID_OK)
okay.SetDefault()
cancel = wx.Button(self, wx.ID_CANCEL)
# Layout with sizers
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(about, 0, wx.ALL, 5)
sizer.Add(wx.StaticLine(self), 0, wx.EXPAND|wx.ALL, 5)
fgs = wx.FlexGridSizer(3, 2, 5, 5)
fgs.Add(name_l, 0, wx.ALIGN_RIGHT)
fgs.Add(name_t, 0, wx.EXPAND)
fgs.Add(email_l, 0, wx.ALIGN_RIGHT)
fgs.Add(email_t, 0, wx.EXPAND)
fgs.Add(phone_l, 0, wx.ALIGN_RIGHT)
fgs.Add(phone_t, 0, wx.EXPAND)
fgs.AddGrowableCol(1)
sizer.Add(fgs, 0, wx.EXPAND|wx.ALL, 5)
btns = wx.StdDialogButtonSizer()
btns.AddButton(okay)
btns.AddButton(cancel)
btns.Realize()
sizer.Add(btns, 0, wx.EXPAND|wx.ALL, 5)
self.SetSizer(sizer)
sizer.Fit(self)
app = wx.PySimpleApp()
data = { "name" : "Jordyn Dunn" }
dlg = MyDialog(data)
dlg.ShowModal()
dlg.Destroy()
wx.MessageBox("You entered these values:\n\n" +
pprint.pformat(data))
app.MainLoop()

View File

@ -0,0 +1,92 @@
import wx
import string
about_txt = """\
The validator used in this example will validate the input on the fly
instead of waiting until the okay button is pressed. The first field
will not allow digits to be typed, the second will allow anything
and the third will not allow alphabetic characters to be entered.
"""
class CharValidator(wx.PyValidator):
def __init__(self, flag):
wx.PyValidator.__init__(self)
self.flag = flag
self.Bind(wx.EVT_CHAR, self.OnChar)
def Clone(self):
"""
Note that every validator must implement the Clone() method.
"""
return CharValidator(self.flag)
def Validate(self, win):
return True
def TransferToWindow(self):
return True
def TransferFromWindow(self):
return True
def OnChar(self, evt):
key = chr(evt.GetKeyCode())
if self.flag == "no-alpha" and key in string.letters:
return
if self.flag == "no-digit" and key in string.digits:
return
evt.Skip()
class MyDialog(wx.Dialog):
def __init__(self):
wx.Dialog.__init__(self, None, -1, "Validators: behavior modification")
# Create the text controls
about = wx.StaticText(self, -1, about_txt)
name_l = wx.StaticText(self, -1, "Name:")
email_l = wx.StaticText(self, -1, "Email:")
phone_l = wx.StaticText(self, -1, "Phone:")
name_t = wx.TextCtrl(self, validator=CharValidator("no-digit"))
email_t = wx.TextCtrl(self, validator=CharValidator("any"))
phone_t = wx.TextCtrl(self, validator=CharValidator("no-alpha"))
# Use standard button IDs
okay = wx.Button(self, wx.ID_OK)
okay.SetDefault()
cancel = wx.Button(self, wx.ID_CANCEL)
# Layout with sizers
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(about, 0, wx.ALL, 5)
sizer.Add(wx.StaticLine(self), 0, wx.EXPAND|wx.ALL, 5)
fgs = wx.FlexGridSizer(3, 2, 5, 5)
fgs.Add(name_l, 0, wx.ALIGN_RIGHT)
fgs.Add(name_t, 0, wx.EXPAND)
fgs.Add(email_l, 0, wx.ALIGN_RIGHT)
fgs.Add(email_t, 0, wx.EXPAND)
fgs.Add(phone_l, 0, wx.ALIGN_RIGHT)
fgs.Add(phone_t, 0, wx.EXPAND)
fgs.AddGrowableCol(1)
sizer.Add(fgs, 0, wx.EXPAND|wx.ALL, 5)
btns = wx.StdDialogButtonSizer()
btns.AddButton(okay)
btns.AddButton(cancel)
btns.Realize()
sizer.Add(btns, 0, wx.EXPAND|wx.ALL, 5)
self.SetSizer(sizer)
sizer.Fit(self)
app = wx.PySimpleApp()
dlg = MyDialog()
dlg.ShowModal()
dlg.Destroy()
app.MainLoop()

View File

@ -0,0 +1,39 @@
import wx
import wx.wizard
class TitledPage(wx.wizard.WizardPageSimple):
def __init__(self, parent, title):
wx.wizard.WizardPageSimple.__init__(self, parent)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.SetSizer(self.sizer)
titleText = wx.StaticText(self, -1, title)
titleText.SetFont(
wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD))
self.sizer.Add(titleText, 0,
wx.ALIGN_CENTRE | wx.ALL, 5)
self.sizer.Add(wx.StaticLine(self, -1), 0,
wx.EXPAND | wx.ALL, 5)
if __name__ == "__main__":
app = wx.PySimpleApp()
wizard = wx.wizard.Wizard(None, -1, "Simple Wizard")
page1 = TitledPage(wizard, "Page 1")
page2 = TitledPage(wizard, "Page 2")
page3 = TitledPage(wizard, "Page 3")
page4 = TitledPage(wizard, "Page 4")
page1.sizer.Add(wx.StaticText(page1, -1,
"Testing the wizard"))
page4.sizer.Add(wx.StaticText(page4, -1,
"This is the last page."))
wx.wizard.WizardPageSimple_Chain(page1, page2)
wx.wizard.WizardPageSimple_Chain(page2, page3)
wx.wizard.WizardPageSimple_Chain(page3, page4)
wizard.FitToPage(page1)
if wizard.RunWizard(page1):
print "Success"
wizard.Destroy()

View File

@ -0,0 +1,50 @@
import wx
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1,
"Add Menu Items")
p = wx.Panel(self)
self.txt = wx.TextCtrl(p, -1, "new item")
btn = wx.Button(p, -1, "Add Menu Item")
self.Bind(wx.EVT_BUTTON, self.OnAddItem, btn)
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(self.txt, 0, wx.ALL, 20)
sizer.Add(btn, 0, wx.TOP|wx.RIGHT, 20)
p.SetSizer(sizer)
self.menu = menu = wx.Menu()
simple = menu.Append(-1, "Simple menu item")
menu.AppendSeparator()
exit = menu.Append(-1, "Exit")
self.Bind(wx.EVT_MENU, self.OnSimple, simple)
self.Bind(wx.EVT_MENU, self.OnExit, exit)
menuBar = wx.MenuBar()
menuBar.Append(menu, "Menu")
self.SetMenuBar(menuBar)
def OnSimple(self, event):
wx.MessageBox("You selected the simple menu item")
def OnExit(self, event):
self.Close()
def OnAddItem(self, event):
item = self.menu.Append(-1, self.txt.GetValue())
self.Bind(wx.EVT_MENU, self.OnNewItemSelected, item)
def OnNewItemSelected(self, event):
wx.MessageBox("You selected a new item")
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = MyFrame()
frame.Show()
app.MainLoop()

View File

@ -0,0 +1,22 @@
import wx
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "Simple Menu Example")
p = wx.Panel(self)
menuBar = wx.MenuBar()
menu = wx.Menu()
menuBar.Append(menu, "Left Menu")
menu2 = wx.Menu()
menuBar.Append(menu2, "Middle Menu")
menu3 = wx.Menu()
menuBar.Append(menu3, "Right Menu")
self.SetMenuBar(menuBar)
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = MyFrame()
frame.Show()
app.MainLoop()

View File

@ -0,0 +1,29 @@
import wx
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "Simple Menu Example")
p = wx.Panel(self)
menu = wx.Menu()
simple = menu.Append(-1, "Simple menu item")
menu.AppendSeparator()
exit = menu.Append(-1, "Exit")
self.Bind(wx.EVT_MENU, self.OnSimple, simple)
self.Bind(wx.EVT_MENU, self.OnExit, exit)
menuBar = wx.MenuBar()
menuBar.Append(menu, "Simple Menu")
self.SetMenuBar(menuBar)
def OnSimple(self, event):
wx.MessageBox("You selected the simple menu item")
def OnExit(self, event):
self.Close()
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = MyFrame()
frame.Show()
app.MainLoop()

View File

@ -0,0 +1,46 @@
import wx
ID_SIMPLE = wx.NewId()
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1,
"Enable/Disable Menu Example")
p = wx.Panel(self)
self.btn = wx.Button(p, -1, "Disable Item", (20,20))
self.Bind(wx.EVT_BUTTON, self.OnToggleItem, self.btn)
menu = wx.Menu()
menu.Append(ID_SIMPLE, "Simple menu item")
self.Bind(wx.EVT_MENU, self.OnSimple, id=ID_SIMPLE)
menu.AppendSeparator()
menu.Append(wx.ID_EXIT, "Exit")
self.Bind(wx.EVT_MENU, self.OnExit, id=wx.ID_EXIT)
menuBar = wx.MenuBar()
menuBar.Append(menu, "Menu")
self.SetMenuBar(menuBar)
def OnSimple(self, event):
wx.MessageBox("You selected the simple menu item")
def OnExit(self, event):
self.Close()
def OnToggleItem(self, event):
menubar = self.GetMenuBar()
enabled = menubar.IsEnabled(ID_SIMPLE)
menubar.Enable(ID_SIMPLE, not enabled)
self.btn.SetLabel(
(enabled and "Enable" or "Disable") + " Item")
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = MyFrame()
frame.Show()
app.MainLoop()

View File

@ -0,0 +1,47 @@
import wx
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1,
"Fancier Menu Example")
p = wx.Panel(self)
menu = wx.Menu()
bmp = wx.Bitmap("open.png", wx.BITMAP_TYPE_PNG)
item = wx.MenuItem(menu, -1, "Has Open Bitmap")
item.SetBitmap(bmp)
menu.AppendItem(item)
if True or 'wxMSW' in wx.PlatformInfo:
font = wx.SystemSettings.GetFont(
wx.SYS_DEFAULT_GUI_FONT)
font.SetWeight(wx.BOLD)
item = wx.MenuItem(menu, -1, "Has Bold Font")
item.SetFont(font)
menu.AppendItem(item)
item = wx.MenuItem(menu, -1, "Has Red Text")
item.SetTextColour("red")
menu.AppendItem(item)
menu.AppendSeparator()
exit = menu.Append(-1, "Exit")
self.Bind(wx.EVT_MENU, self.OnExit, exit)
menuBar = wx.MenuBar()
menuBar.Append(menu, "Menu")
self.SetMenuBar(menuBar)
def OnExit(self, event):
self.Close()
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = MyFrame()
frame.Show()
app.MainLoop()

View File

@ -0,0 +1,52 @@
import wx
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1,
"Find Item Example")
p = wx.Panel(self)
self.txt = wx.TextCtrl(p, -1, "new item")
btn = wx.Button(p, -1, "Add Menu Item")
self.Bind(wx.EVT_BUTTON, self.OnAddItem, btn)
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(self.txt, 0, wx.ALL, 20)
sizer.Add(btn, 0, wx.TOP|wx.RIGHT, 20)
p.SetSizer(sizer)
self.menu = menu = wx.Menu()
simple = menu.Append(-1, "Simple menu item")
menu.AppendSeparator()
exit = menu.Append(-1, "Exit")
self.Bind(wx.EVT_MENU, self.OnSimple, simple)
self.Bind(wx.EVT_MENU, self.OnExit, exit)
menuBar = wx.MenuBar()
menuBar.Append(menu, "Menu")
self.SetMenuBar(menuBar)
def OnSimple(self, event):
wx.MessageBox("You selected the simple menu item")
def OnExit(self, event):
self.Close()
def OnAddItem(self, event):
item = self.menu.Append(-1, self.txt.GetValue())
self.Bind(wx.EVT_MENU, self.OnNewItemSelected, item)
def OnNewItemSelected(self, event):
item = self.GetMenuBar().FindItemById(event.GetId())
text = item.GetText()
wx.MessageBox("You selected the '%s' item" % text)
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = MyFrame()
frame.Show()
app.MainLoop()

Binary file not shown.

After

Width:  |  Height:  |  Size: 281 B

View File

@ -0,0 +1,49 @@
import wx
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1,
"Popup Menu Example")
self.panel = p = wx.Panel(self)
menu = wx.Menu()
exit = menu.Append(-1, "Exit")
self.Bind(wx.EVT_MENU, self.OnExit, exit)
menuBar = wx.MenuBar()
menuBar.Append(menu, "Menu")
self.SetMenuBar(menuBar)
wx.StaticText(p, -1,
"Right-click on the panel to show a popup menu",
(25,25))
self.popupmenu = wx.Menu()
for text in "one two three four five".split():
item = self.popupmenu.Append(-1, text)
self.Bind(wx.EVT_MENU, self.OnPopupItemSelected, item)
p.Bind(wx.EVT_CONTEXT_MENU, self.OnShowPopup)
def OnShowPopup(self, event):
pos = event.GetPosition()
pos = self.panel.ScreenToClient(pos)
self.panel.PopupMenu(self.popupmenu, pos)
def OnPopupItemSelected(self, event):
item = self.popupmenu.FindItemById(event.GetId())
text = item.GetText()
wx.MessageBox("You selected item '%s'" % text)
def OnExit(self, event):
self.Close()
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = MyFrame()
frame.Show()
app.MainLoop()

View File

@ -0,0 +1,34 @@
import wx
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1,
"Sub-menu Example")
p = wx.Panel(self)
menu = wx.Menu()
submenu = wx.Menu()
submenu.Append(-1, "Sub-item 1")
submenu.Append(-1, "Sub-item 2")
menu.AppendMenu(-1, "Sub-menu", submenu)
menu.AppendSeparator()
exit = menu.Append(-1, "Exit")
self.Bind(wx.EVT_MENU, self.OnExit, exit)
menuBar = wx.MenuBar()
menuBar.Append(menu, "Menu")
self.SetMenuBar(menuBar)
def OnExit(self, event):
self.Close()
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = MyFrame()
frame.Show()
app.MainLoop()

View File

@ -0,0 +1,36 @@
import wx
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1,
"Toggle Items Example")
p = wx.Panel(self)
menuBar = wx.MenuBar()
menu = wx.Menu()
exit = menu.Append(-1, "Exit")
self.Bind(wx.EVT_MENU, self.OnExit, exit)
menuBar.Append(menu, "Menu")
menu = wx.Menu()
menu.AppendCheckItem(-1, "Check Item 1")
menu.AppendCheckItem(-1, "Check Item 2")
menu.AppendCheckItem(-1, "Check Item 3")
menu.AppendSeparator()
menu.AppendRadioItem(-1, "Radio Item 1")
menu.AppendRadioItem(-1, "Radio Item 2")
menu.AppendRadioItem(-1, "Radio Item 3")
menuBar.Append(menu, "Toggle Items")
self.SetMenuBar(menuBar)
def OnExit(self, event):
self.Close()
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = MyFrame()
frame.Show()
app.MainLoop()

View File

@ -0,0 +1,49 @@
import wx
ID_SIMPLE = wx.NewId()
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1,
"UPDATE_UI Menu Example")
p = wx.Panel(self)
self.btn = wx.Button(p, -1, "Disable Item", (20,20))
self.Bind(wx.EVT_BUTTON, self.OnToggleItem, self.btn)
menu = wx.Menu()
menu.Append(ID_SIMPLE, "Simple menu item")
self.enabled = True
self.Bind(wx.EVT_MENU, self.OnSimple, id=ID_SIMPLE)
self.Bind(wx.EVT_UPDATE_UI, self.OnUpdateSimple, id=ID_SIMPLE)
menu.AppendSeparator()
menu.Append(wx.ID_EXIT, "Exit")
self.Bind(wx.EVT_MENU, self.OnExit, id=wx.ID_EXIT)
menuBar = wx.MenuBar()
menuBar.Append(menu, "Menu")
self.SetMenuBar(menuBar)
def OnSimple(self, event):
wx.MessageBox("You selected the simple menu item")
def OnExit(self, event):
self.Close()
def OnToggleItem(self, event):
self.btn.SetLabel(
(self.enabled and "Enable" or "Disable") + " Item")
self.enabled = not self.enabled
def OnUpdateSimple(self, event):
event.Enable(self.enabled)
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = MyFrame()
frame.Show()
app.MainLoop()

View File

@ -0,0 +1,47 @@
import wx
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1,
"Accelerator Example")
p = wx.Panel(self)
menu = wx.Menu()
simple = menu.Append(-1, "Simple &menu item") # with mnemonic
accel = menu.Append(-1, "&Accelerated\tCtrl-A") # with accelerator
menu.AppendSeparator()
exit = menu.Append(-1, "E&xit")
self.Bind(wx.EVT_MENU, self.OnSimple, simple)
self.Bind(wx.EVT_MENU, self.OnAccelerated, accel)
self.Bind(wx.EVT_MENU, self.OnExit, exit)
menuBar = wx.MenuBar()
menuBar.Append(menu, "&Menu")
self.SetMenuBar(menuBar)
# An alternate way to make accelerators
acceltbl = wx.AcceleratorTable( [
(wx.ACCEL_CTRL, ord('Q'), exit.GetId())
])
self.SetAcceleratorTable(acceltbl)
def OnSimple(self, event):
wx.MessageBox("You selected the simple menu item")
def OnAccelerated(self, event):
wx.MessageBox("You selected the accelerated menu item")
def OnExit(self, event):
self.Close()
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = MyFrame()
frame.Show()
app.MainLoop()

View File

@ -0,0 +1,20 @@
import wx
from blockwindow import BlockWindow
labels = "one two three four five six seven eight nine".split()
class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "FlexGridSizer")
sizer = wx.FlexGridSizer(rows=3, cols=3, hgap=5, vgap=5)
for label in labels:
bw = BlockWindow(self, label=label)
sizer.Add(bw, 0, 0)
center = self.FindWindowByName("five")
center.SetMinSize((150,50))
self.SetSizer(sizer)
self.Fit()
app = wx.PySimpleApp()
TestFrame().Show()
app.MainLoop()

View File

@ -0,0 +1,18 @@
import wx
from blockwindow import BlockWindow
labels = "one two three four five six seven eight nine".split()
class GridSizerFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "Basic Grid Sizer")
sizer = wx.GridSizer(rows=3, cols=3, hgap=5, vgap=5)
for label in labels:
bw = BlockWindow(self, label=label)
sizer.Add(bw, 0, 0)
self.SetSizer(sizer)
self.Fit()
app = wx.PySimpleApp()
GridSizerFrame().Show()
app.MainLoop()

View File

@ -0,0 +1,20 @@
import wx
class BlockWindow(wx.Panel):
def __init__(self, parent, ID=-1, label="",
pos=wx.DefaultPosition, size=(100, 25)):
wx.Panel.__init__(self, parent, ID, pos, size,
wx.RAISED_BORDER, label)
self.label = label
self.SetBackgroundColour("white")
self.SetMinSize(size)
self.Bind(wx.EVT_PAINT, self.OnPaint)
def OnPaint(self, evt):
sz = self.GetClientSize()
dc = wx.PaintDC(self)
w,h = dc.GetTextExtent(self.label)
dc.SetFont(self.GetFont())
dc.DrawText(self.label, (sz.width-w)/2, (sz.height-h)/2)

View File

@ -0,0 +1,23 @@
import wx
from blockwindow import BlockWindow
labels = "one two three four five six seven eight nine".split()
flags = {"one": wx.BOTTOM, "two": wx.ALL, "three": wx.TOP,
"four": wx.LEFT, "five": wx.ALL, "six": wx.RIGHT,
"seven": wx.BOTTOM | wx.TOP, "eight": wx.ALL,
"nine": wx.LEFT | wx.RIGHT}
class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "GridSizer Borders")
sizer = wx.GridSizer(rows=3, cols=3, hgap=5, vgap=5)
for label in labels:
bw = BlockWindow(self, label=label)
flag = flags.get(label, 0)
sizer.Add(bw, 0, flag, 10)
self.SetSizer(sizer)
self.Fit()
app = wx.PySimpleApp()
TestFrame().Show()
app.MainLoop()

Some files were not shown because too many files have changed in this diff Show More