</body></html>
"""
-from wxPython.wx import *
+# 11/24/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for 2.5
+#
-if wxPlatform == '__WXMSW__':
- from wxPython.lib.activexwrapper import MakeActiveXClass
- import win32com.client.gencache
+import sys
+import wx
+
+if wx.Platform == '__WXMSW__':
+ import wx.lib.activexwrapper as ax
+ import win32com.client.gencache
try:
- acrobat = win32com.client.gencache.EnsureModule('{CA8A9783-280D-11CF-A24D-444553540000}', 0x0, 1, 3)
+ acrobat = win32com.client.gencache.EnsureModule(
+ '{CA8A9783-280D-11CF-A24D-444553540000}', 0x0, 1, 3
+ )
except:
raise ImportError("Can't load PDF.OCX, install Acrobat 4.0")
-
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.pdf = None
- sizer = wxBoxSizer(wxVERTICAL)
- btnSizer = wxBoxSizer(wxHORIZONTAL)
+ sizer = wx.BoxSizer(wx.VERTICAL)
+ btnSizer = wx.BoxSizer(wx.HORIZONTAL)
# this function creates a new class that can be used as
- # a wxWindow, but contains the given ActiveX control.
- ActiveXWrapper = MakeActiveXClass(acrobat.Pdf)
+ # a wx.Window, but contains the given ActiveX control.
+ ActiveXWrapper = ax.MakeActiveXClass(acrobat.Pdf)
# create an instance of the new class
- self.pdf = ActiveXWrapper( self, -1, style=wxSUNKEN_BORDER)
+ self.pdf = ActiveXWrapper( self, -1, style=wx.SUNKEN_BORDER)
- sizer.Add(self.pdf, 1, wxEXPAND)
+ sizer.Add(self.pdf, proportion=1, flag=wx.EXPAND)
- btn = wxButton(self, wxNewId(), "Open PDF File")
- EVT_BUTTON(self, btn.GetId(), self.OnOpenButton)
- btnSizer.Add(btn, 1, wxEXPAND|wxALL, 5)
+ btn = wx.Button(self, wx.NewId(), "Open PDF File")
+ self.Bind(wx.EVT_BUTTON, self.OnOpenButton)
+ btnSizer.Add(btn, proportion=1, flag=wx.EXPAND|wx.ALL, border=5)
- btn = wxButton(self, wxNewId(), "<-- Previous Page")
- EVT_BUTTON(self, btn.GetId(), self.OnPrevPageButton)
- btnSizer.Add(btn, 1, wxEXPAND|wxALL, 5)
+ btn = wx.Button(self, wx.NewId(), "<-- Previous Page")
+ self.Bind(wx.EVT_BUTTON, self.OnPrevPageButton, id=btn.GetId())
+ btnSizer.Add(btn, proportion=1, flag=wx.EXPAND|wx.ALL, border=5)
- btn = wxButton(self, wxNewId(), "Next Page -->")
- EVT_BUTTON(self, btn.GetId(), self.OnNextPageButton)
- btnSizer.Add(btn, 1, wxEXPAND|wxALL, 5)
+ btn = wx.Button(self, wx.NewId(), "Next Page -->")
+ self.Bind(wx.EVT_BUTTON, self.OnNextPageButton, id=btn.GetId())
+ btnSizer.Add(btn, proportion=1, flag=wx.EXPAND|wx.ALL, border=5)
- btnSizer.Add(50, -1, 2, wxEXPAND)
- sizer.Add(btnSizer, 0, wxEXPAND)
+ btnSizer.Add((50,-1), proportion=2, flag=wx.EXPAND)
+ sizer.Add(btnSizer, proportion=0, flag=wx.EXPAND)
self.SetSizer(sizer)
self.SetAutoLayout(True)
- EVT_WINDOW_DESTROY(self, self.OnDestroy)
+ self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
def OnDestroy(self, evt):
def OnOpenButton(self, event):
- dlg = wxFileDialog(self, wildcard="*.pdf")
- if dlg.ShowModal() == wxID_OK:
- wxBeginBusyCursor()
+ dlg = wx.FileDialog(self, wildcard="*.pdf")
+
+ if dlg.ShowModal() == wx.ID_OK:
+ wx.BeginBusyCursor()
self.pdf.LoadFile(dlg.GetPath())
- wxEndBusyCursor()
+ wx.EndBusyCursor()
dlg.Destroy()
#----------------------------------------------------------------------
def runTest(frame, nb, log):
- if wxPlatform == '__WXMSW__':
+ if wx.Platform == '__WXMSW__':
win = TestPanel(nb, log)
return win
else:
- dlg = wxMessageDialog(frame, 'This demo only works on MSW.',
- 'Sorry', wxOK | wxICON_INFORMATION)
+ dlg = wx.MessageDialog(frame, 'This demo only works on MSW.',
+ 'Sorry', wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
if __name__ == '__main__':
- class TestFrame(wxFrame):
+ class TestFrame(wx.Frame):
def __init__(self):
- wxFrame.__init__(self, None, -1, "ActiveX test -- Acrobat", size=(640, 480),
- style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
+ wx.Frame.__init__(
+ self, None, -1, "ActiveX test -- Acrobat", size=(640, 480),
+ style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE
+ )
+
self.tp = TestPanel(self, sys.stdout)
- app = wxPySimpleApp()
+ app = wx.PySimpleApp()
frame = TestFrame()
frame.Show(True)
app.MainLoop()
-
</body></html>
"""
-from wxPython.wx import *
+# 11/24/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for V2.5
+#
-if wxPlatform == '__WXMSW__':
- from wxPython.lib.activexwrapper import MakeActiveXClass
- import win32com.client.gencache
+import sys
+import wx
+
+if wx.Platform == '__WXMSW__':
+ import wx.lib.activexwrapper as ax
+ import win32com.client.gencache
try:
- browserModule = win32com.client.gencache.EnsureModule("{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}", 0, 1, 1)
+ browserModule = win32com.client.gencache.EnsureModule(
+ "{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}", 0, 1, 1
+ )
except:
raise ImportError("IE4 or greater does not appear to be installed.")
#----------------------------------------------------------------------
-class TestPanel(wxWindow):
+class TestPanel(wx.Window):
def __init__(self, parent, log, frame=None):
- wxWindow.__init__(self, parent, -1,
- style=wxCLIP_CHILDREN|wxNO_FULL_REPAINT_ON_RESIZE)
+ wx.Window.__init__(
+ self, parent, -1,
+ style=wx.CLIP_CHILDREN|wx.NO_FULL_REPAINT_ON_RESIZE
+ )
+
self.ie = None
self.log = log
self.current = "http://wxPython.org/"
self.frame = frame
+
if frame:
self.titleBase = frame.GetTitle()
-
- sizer = wxBoxSizer(wxVERTICAL)
- btnSizer = wxBoxSizer(wxHORIZONTAL)
+ sizer = wx.BoxSizer(wx.VERTICAL)
+ btnSizer = wx.BoxSizer(wx.HORIZONTAL)
# Make a new class that derives from the WebBrowser class in the
# COM module imported above. This class also derives from wxWindow and
# implements the machinery needed to integrate the two worlds.
- theClass = MakeActiveXClass(browserModule.WebBrowser,
- eventObj = self)
+ theClass = ax.MakeActiveXClass(
+ browserModule.WebBrowser, eventObj = self
+ )
# Create an instance of that class
self.ie = theClass(self, -1) ##, style=wxSUNKEN_BORDER)
- btn = wxButton(self, wxNewId(), "Open", style=wxBU_EXACTFIT)
- EVT_BUTTON(self, btn.GetId(), self.OnOpenButton)
- btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2)
+ btn = wx.Button(self, wx.NewId(), "Open", style=wx.BU_EXACTFIT)
+ self.Bind(wx.EVT_BUTTON, self.OnOpenButton, id=btn.GetId())
+ btnSizer.Add(btn, 0, wx.EXPAND|wx.ALL, 2)
- btn = wxButton(self, wxNewId(), "Home", style=wxBU_EXACTFIT)
- EVT_BUTTON(self, btn.GetId(), self.OnHomeButton)
- btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2)
+ btn = wx.Button(self, wx.NewId(), "Home", style=wx.BU_EXACTFIT)
+ self.Bind(wx.EVT_BUTTON, self.OnHomeButton, id=btn.GetId())
+ btnSizer.Add(btn, 0, wx.EXPAND|wx.ALL, 2)
- btn = wxButton(self, wxNewId(), "<--", style=wxBU_EXACTFIT)
- EVT_BUTTON(self, btn.GetId(), self.OnPrevPageButton)
- btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2)
+ btn = wx.Button(self, wx.NewId(), "<--", style=wx.BU_EXACTFIT)
+ self.Bind(wx.EVT_BUTTON, self.OnPrevPageButton, id=btn.GetId())
+ btnSizer.Add(btn, 0, wx.EXPAND|wx.ALL, 2)
- btn = wxButton(self, wxNewId(), "-->", style=wxBU_EXACTFIT)
- EVT_BUTTON(self, btn.GetId(), self.OnNextPageButton)
- btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2)
+ btn = wx.Button(self, wx.NewId(), "-->", style=wx.BU_EXACTFIT)
+ self.Bind(wx.EVT_BUTTON, self.OnNextPageButton, id=btn.GetId())
+ btnSizer.Add(btn, 0, wx.EXPAND|wx.ALL, 2)
- btn = wxButton(self, wxNewId(), "Stop", style=wxBU_EXACTFIT)
- EVT_BUTTON(self, btn.GetId(), self.OnStopButton)
- btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2)
+ btn = wx.Button(self, wx.NewId(), "Stop", style=wx.BU_EXACTFIT)
+ self.Bind(wx.EVT_BUTTON, self.OnStopButton, id=btn.GetId())
+ btnSizer.Add(btn, 0, wx.EXPAND|wx.ALL, 2)
- btn = wxButton(self, wxNewId(), "Search", style=wxBU_EXACTFIT)
- EVT_BUTTON(self, btn.GetId(), self.OnSearchPageButton)
- btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2)
+ btn = wx.Button(self, wx.NewId(), "Search", style=wx.BU_EXACTFIT)
+ self.Bind(wx.EVT_BUTTON, self.OnSearchPageButton, id=btn.GetId())
+ btnSizer.Add(btn, 0, wx.EXPAND|wx.ALL, 2)
- btn = wxButton(self, wxNewId(), "Refresh", style=wxBU_EXACTFIT)
- EVT_BUTTON(self, btn.GetId(), self.OnRefreshPageButton)
- btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2)
+ btn = wx.Button(self, wx.NewId(), "Refresh", style=wx.BU_EXACTFIT)
+ self.Bind(wx.EVT_BUTTON, self.OnRefreshPageButton, id=btn.GetId())
+ btnSizer.Add(btn, 0, wx.EXPAND|wx.ALL, 2)
- txt = wxStaticText(self, -1, "Location:")
- btnSizer.Add(txt, 0, wxCENTER|wxALL, 2)
+ txt = wx.StaticText(self, -1, "Location:")
+ btnSizer.Add(txt, 0, wx.CENTER|wx.ALL, 2)
- self.location = wxComboBox(self, wxNewId(), "", style=wxCB_DROPDOWN)
- EVT_COMBOBOX(self, self.location.GetId(), self.OnLocationSelect)
- EVT_KEY_UP(self.location, self.OnLocationKey)
- EVT_CHAR(self.location, self.IgnoreReturn)
- btnSizer.Add(self.location, 1, wxEXPAND|wxALL, 2)
+ self.location = wx.ComboBox(self, wx.NewId(), "", style=wx.CB_DROPDOWN)
+ self.Bind(wx.EVT_COMBOBOX, self.OnLocationSelect, id=self.location.GetId())
+ self.Bind(wx.EVT_KEY_UP, self.OnLocationKey, self.location)
+ self.Bind(wx.EVT_CHAR, self.IgnoreReturn, self.location)
+ btnSizer.Add(self.location, 1, wx.EXPAND|wx.ALL, 2)
- sizer.Add(btnSizer, 0, wxEXPAND)
- sizer.Add(self.ie, 1, wxEXPAND)
+ sizer.Add(btnSizer, 0, wx.EXPAND)
+ sizer.Add(self.ie, 1, wx.EXPAND)
self.ie.Navigate(self.current)
self.location.Append(self.current)
self.SetSizer(sizer)
self.SetAutoLayout(True)
- EVT_SIZE(self, self.OnSize)
-
- EVT_WINDOW_DESTROY(self, self.OnDestroy)
+ self.Bind(wx.EVT_SIZE, self.OnSize)
+ self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
def ShutdownDemo(self):
self.ie.Navigate(url)
def OnLocationKey(self, evt):
- if evt.KeyCode() == WXK_RETURN:
+ if evt.KeyCode() == wx.WXK_RETURN:
URL = self.location.GetValue()
self.location.Append(URL)
self.ie.Navigate(URL)
def IgnoreReturn(self, evt):
print 'IgnoreReturn'
- if evt.KeyCode() != WXK_RETURN:
+ if evt.KeyCode() != wx.WXK_RETURN:
evt.Skip()
def OnOpenButton(self, event):
- dlg = wxTextEntryDialog(self, "Open Location",
+ dlg = wx.TextEntryDialog(self, "Open Location",
"Enter a full URL or local path",
- self.current, wxOK|wxCANCEL)
+ self.current, wx.OK|wx.CANCEL)
+
dlg.CentreOnParent()
- if dlg.ShowModal() == wxID_OK:
+
+ if dlg.ShowModal() == wx.ID_OK:
self.current = dlg.GetValue()
self.ie.Navigate(self.current)
+
dlg.Destroy()
def OnHomeButton(self, event):
self.ie.Refresh2(3)
-
# The following event handlers are called by the web browser COM
# control since we passed self to MakeActiveXClass. It will look
# here for matching attributes and call them if they exist. See the
# for the demo framework...
def runTest(frame, nb, log):
- if wxPlatform == '__WXMSW__':
+ if wx.Platform == '__WXMSW__':
win = TestPanel(nb, log, frame)
return win
else:
- dlg = wxMessageDialog(frame, 'This demo only works on MSW.',
- 'Sorry', wxOK | wxICON_INFORMATION)
+ dlg = wx.MessageDialog(frame, 'This demo only works on MSW.',
+ 'Sorry', wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
if __name__ == '__main__':
- class TestFrame(wxFrame):
+ class TestFrame(wx.Frame):
def __init__(self):
- wxFrame.__init__(self, None, -1, "ActiveX test -- Internet Explorer",
- size=(640, 480),
- style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
+ wx.Frame.__init__(
+ self, None, -1, "ActiveX test -- Internet Explorer",
+ size=(640, 480),
+ style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE
+ )
+
self.CreateStatusBar()
self.tp = TestPanel(self, sys.stdout, self)
- EVT_CLOSE(self, self.OnCloseWindow)
+ self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
def OnCloseWindow(self, evt):
self.tp.Destroy()
self.Destroy()
- app = wxPySimpleApp()
+ app = wx.PySimpleApp()
frame = TestFrame()
frame.Show(True)
app.MainLoop()
-
-
+# 11/4/03 - grimmtooth@softhome.net (Jeff Grimmett)
+#
+# o wx Namespace
+#
-
-
-from wxPython.wx import *
-from wxPython.lib.analogclock import AnalogClockWindow
+import wx
+import wx.lib.analogclock as aclock
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
self.log = log
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
- c1 = AnalogClockWindow(self)
+ # A red background with blue hands and white markings
+ c1 = aclock.AnalogClockWindow(self)
c1.SetBackgroundColour("RED")
c1.SetHandsColour("BLUE")
c1.SetTickMarkColours("WHITE")
- c2 = AnalogClockWindow(self)
+ # A white background with red hands and blue markings
+ c2 = aclock.AnalogClockWindow(self)
c2.SetBackgroundColour("WHITE")
c2.SetHandsColour("RED")
c2.SetTickMarkColours("BLUE")
- c3 = AnalogClockWindow(self)
+ # A blue background with white hands and red markings
+ c3 = aclock.AnalogClockWindow(self)
c3.SetBackgroundColour("BLUE")
c3.SetHandsColour("WHITE")
c3.SetTickMarkColours("RED")
- c4 = AnalogClockWindow(self, style=wxRAISED_BORDER)
- c4.SetTickMarkStyle(AnalogClockWindow.TICKS_CIRCLE)
-
- c5 = AnalogClockWindow(self)
- c5.SetTickMarkStyle(AnalogClockWindow.TICKS_NONE)
+ # Raised border, circular tick marks.
+ c4 = aclock.AnalogClockWindow(self, style=wx.RAISED_BORDER)
+ c4.SetTickMarkStyle(aclock.AnalogClockWindow.TICKS_CIRCLE)
- c6 = AnalogClockWindow(self, style=wxSUNKEN_BORDER)
+ # No tick marks
+ c5 = aclock.AnalogClockWindow(self)
+ c5.SetTickMarkStyle(aclock.AnalogClockWindow.TICKS_NONE)
+ # Sunken into window
+ c6 = aclock.AnalogClockWindow(self, style=wx.SUNKEN_BORDER)
- # layout the clocks in a grid
- gs = wxGridSizer(2, 3, 4, 4)
- gs.Add(c1, 0, wxEXPAND)
- gs.Add(c2, 0, wxEXPAND)
- gs.Add(c3, 0, wxEXPAND)
- gs.Add(c4, 0, wxEXPAND)
- gs.Add(c5, 0, wxEXPAND)
- gs.Add(c6, 0, wxEXPAND)
+ # layout the clocks in a grid sizer
+ gs = wx.GridSizer(2, 3, 4, 4)
+ gs.Add(c1, 0, wx.EXPAND)
+ gs.Add(c2, 0, wx.EXPAND)
+ gs.Add(c3, 0, wx.EXPAND)
+ gs.Add(c4, 0, wx.EXPAND)
+ gs.Add(c5, 0, wx.EXPAND)
+ gs.Add(c6, 0, wx.EXPAND)
# put it in another sizer for a border
- sizer = wxBoxSizer(wxVERTICAL)
- sizer.Add(gs, 1, wxEXPAND|wxALL, 10)
+ sizer = wx.BoxSizer(wx.VERTICAL)
+ sizer.Add(gs, 1, wx.EXPAND|wx.ALL, 10)
self.SetSizer(sizer)
</body></html>
"""
-
-
if __name__ == '__main__':
import sys,os
import run
+# 11/4/03 - grimmtooth@softhome.net (Jeff Grimmett)
+#
+# o Updated for wx namespace
+#
+# Note: this module is not a demo per se, but is used by many of
+# the demo modules for various purposes.
-from wxPython.wx import *
+import wx
#---------------------------------------------------------------------------
-class ColoredPanel(wxWindow):
+class ColoredPanel(wx.Window):
def __init__(self, parent, color):
- wxWindow.__init__(self, parent, -1, style = wxSIMPLE_BORDER) #wxRAISED_BORDER)
+ wx.Window.__init__(self, parent, -1, style = wx.SIMPLE_BORDER)
self.SetBackgroundColour(color)
#---------------------------------------------------------------------------
+
-
-from wxPython.wx import *
-from wxPython.lib import colourdb
+# 11/4/03 - grimmtooth@softhome.net (Jeff Grimmett)
+#
+# o Updated to use wx namespace
+#
+# 11/24/03 - grimmtooth@softhome.net (Jeff Grimmett)
+#
+# o Had to move the call to wx.updateColourDB()
+# o Updated several places to change discrete pos and size parameters
+# into two-tuples.
+#
+
+import wx
+import wx.lib.colourdb as cdb
import images
#----------------------------------------------------------------------
-class TestWindow(wxScrolledWindow):
+class TestWindow(wx.ScrolledWindow):
def __init__(self, parent):
- wxScrolledWindow.__init__(self, parent, -1)
+ wx.ScrolledWindow.__init__(self, parent, -1)
+
+ # Populate our color list
+ self.clrList = cdb.getColourList()
- self.clrList = colourdb.getColourList()
+ # Just for style points, we'll use this as a background image.
#self.clrList.sort()
self.bg_bmp = images.getGridBGBitmap()
- EVT_PAINT(self, self.OnPaint)
- EVT_ERASE_BACKGROUND(self, self.OnEraseBackground)
+ # Event handlers
+ self.Bind(wx.EVT_PAINT, self.OnPaint)
+ self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
+
+ # This could also be done by getting the window's default font;
+ # either way, we need to have a font loaded for later on.
#self.SetBackgroundColour("WHITE")
+ self.font = wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL)
- self.font = wxFont(10, wxSWISS, wxNORMAL, wxNORMAL)
- dc = wxClientDC(self)
+ # Create drawing area and set its font
+ dc = wx.ClientDC(self)
dc.SetFont(self.font)
- w,h,d,e = dc.GetFullTextExtent("Wy") # a wide character and one that descends
+ # Using GetFullTextExtent(), we calculate a basic 'building block'
+ # that will be used to draw a depiction of the color list. We're
+ # using 'Wy' as the model becuase 'W' is a wide character and 'y'
+ # has a descender. This constitutes a 'worst case' scenario, which means
+ # that no matter what we draw later, text-wise, we'll have room for it
+ w,h,d,e = dc.GetFullTextExtent("Wy")
+
+ # Height plus descender
self.textHeight = h + d
+
+ # Pad a little bit
self.lineHeight = self.textHeight + 5
+
+ # ... and this is the basic width.
self.cellWidth = w
+ # jmg 11/8/03: why 24?
numCells = 24
- self.SetScrollbars(self.cellWidth, self.lineHeight, numCells, len(self.clrList) + 2)
+
+ # 'prep' our scroll bars.
+ self.SetScrollbars(
+ self.cellWidth, self.lineHeight, numCells, len(self.clrList) + 2
+ )
+ # tile the background bitmap loaded in __init__()
def TileBackground(self, dc):
- # tile the background bitmap
sz = self.GetClientSize()
w = self.bg_bmp.GetWidth()
h = self.bg_bmp.GetHeight()
dx, dy = (spx * vsx) % w, (spy * vsy) % h
x = -dx
+
while x < sz.width:
y = -dy
while y < sz.height:
dc.DrawBitmap(self.bg_bmp, (x, y))
y = y + h
- x = x + w
+ x = x + w
+ # Redraw the background over a 'damaged' area.
def OnEraseBackground(self, evt):
dc = evt.GetDC()
+
if not dc:
- dc = wxClientDC(self)
+ dc = wx.ClientDC(self)
rect = self.GetUpdateRegion().GetBox()
dc.SetClippingRect(rect)
+
self.TileBackground(dc)
def OnPaint(self, evt):
- dc = wxPaintDC(self)
+ dc = wx.PaintDC(self)
self.PrepareDC(dc)
self.Draw(dc, self.GetUpdateRegion(), self.GetViewStart())
def Draw(self, dc, rgn=None, vs=None):
dc.BeginDrawing()
dc.SetTextForeground("BLACK")
- dc.SetPen(wxPen("BLACK", 1, wxSOLID))
+ dc.SetPen(wx.Pen("BLACK", 1, wx.SOLID))
dc.SetFont(self.font)
colours = self.clrList
numColours = len(colours)
if rgn:
- # determine the subset that has been exposed and needs drawn
+ # determine the subset of the color list that has been exposed
+ # and needs drawn. This is based on all the precalculation we
+ # did in __init__()
rect = rgn.GetBox()
pixStart = vs[1]*self.lineHeight + rect.y
pixStop = pixStart + rect.height
for line in range(max(0,start), min(stop,numColours)):
clr = colours[line]
y = (line+1) * self.lineHeight + 2
+
+ # Updated for 2.5 - now takes tuple for pos
dc.DrawText(clr, (self.cellWidth, y))
- brush = wxBrush(clr, wxSOLID)
+ brush = wx.Brush(clr, wx.SOLID)
dc.SetBrush(brush)
dc.DrawRectangle((12 * self.cellWidth, y),
(6 * self.cellWidth, self.textHeight))
# On wxGTK there needs to be a panel under wxScrolledWindows if they are
-# going to be in a wxNotebook...
-class TestPanel(wxPanel):
+# going to be in a wxNotebook. And, in the demo, we are.
+class TestPanel(wx.Panel):
def __init__(self, parent):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.win = TestWindow(self)
- EVT_SIZE(self, self.OnSize)
+ self.Bind(wx.EVT_SIZE, self.OnSize)
+
def OnSize(self, evt):
self.win.SetSize(evt.GetSize())
def runTest(frame, nb, log):
# This loads a whole bunch of new color names and values
- # into wxTheColourDatabase
- colourdb.updateColourDB()
+ # into TheColourDatabase
+ #
+ # Note 11/24/03 - jg - I moved this into runTest() because
+ # there must be a wx.App existing before this function
+ # can be called - this is a change from 2.4 -> 2.5.
+ cdb.updateColourDB()
win = TestPanel(nb)
+
return win
#----------------------------------------------------------------------
overview = """
+<html>
+<body>
+<B><font size=+2>ColourDB</font></b>
+
+<p>wxWindows maintains a database of standard RGB colours for a predefined
+set of named colours (such as "BLACK'', "LIGHT GREY''). The application
+may add to this set if desired by using Append. There is only one instance
+of this class: <b>TheColourDatabase</b>.
+
+<p>The <code>colourdb</code> library is a lightweight API that pre-defines
+a multitude of colors for you to use 'out of the box', and this demo serves
+to show you these colors (it also serves as a handy reference).
+
+<p>A secondary benefit of this demo is the use of the <b>ScrolledWindow</b> class
+and the use of various *DC() classes, including background tiling and the use of
+font data to generate a "building block" type of construct for repetitive use.
+
+<p>
+<B><font size=+2>Important note</font></b>
+
+<p>
+With implementation of V2.5 and later, it is required to have a wx.App already
+initialized before <b><code>wx.updateColourDB()</code></b> can be called.
+Trying to do otherwise will cause an exception to be raised.
+</body>
+</html>
"""
# - use sizers
# - other minor "improvements"
#----------------------------------------------------------------------------
+# 11/22/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for V2.5
+#
+# 11/24/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Added Bind() handlers to what events can handle it. However, the
+# colourselect library must be converted before its events can be
+# bound using the Bind() method.
+#
+# 12/01/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o colourselect lib converted; demo converted to match.
+#
-from wxPython.wx import *
-from wxPython.lib.colourselect import *
+import wx
+import wx.lib.colourselect as csel
#----------------------------------------------------------------------------
-class TestColourSelect(wxPanel):
+class TestColourSelect(wx.Panel):
def __init__(self, parent, log):
self.log = log
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.SetAutoLayout(True)
- mainSizer = wxBoxSizer(wxVERTICAL)
+ mainSizer = wx.BoxSizer(wx.VERTICAL)
self.SetSizer(mainSizer)
- t = wxStaticText(self, -1,
+ t = wx.StaticText(self, -1,
"This example uses a colour selection control based on the wxButton\n"
"and wxColourDialog Classes. Click Button to get Colour Values")
- mainSizer.Add(t, 0, wxALL, 3)
+ mainSizer.Add(t, 0, wx.ALL, 3)
- b = wxButton(self, -1, "Show All Colours")
- EVT_BUTTON(self, b.GetId(), self.OnShowAll)
- mainSizer.Add(b, 0, wxALL, 3)
+ b = wx.Button(self, -1, "Show All Colours")
+ self.Bind(wx.EVT_BUTTON, self.OnShowAll, id=b.GetId())
+ mainSizer.Add(b, 0, wx.ALL, 3)
- buttonSizer = wxFlexGridSizer(1, 2) # sizer to contain all the example buttons
+ buttonSizer = wx.FlexGridSizer(1, 2) # sizer to contain all the example buttons
# show a button with all default values
- self.colourDefaults = ColourSelect(self, -1)
- EVT_COLOURSELECT(self.colourDefaults, self.colourDefaults.GetId(), self.OnSelectColour)
+ self.colourDefaults = csel.ColourSelect(self, -1)
+
+ self.colourDefaults.Bind(csel.EVT_COLOURSELECT, self.OnSelectColour, self.colourDefaults.GetId())
+
buttonSizer.AddMany([
- (wxStaticText(self, -1, "Default Colour/Size"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL),
- (self.colourDefaults, 0, wxALL, 3),
+ (wx.StaticText(self, -1, "Default Colour/Size"), 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL),
+ (self.colourDefaults, 0, wx.ALL, 3),
])
# build several examples of buttons with different colours and sizes
buttonData = [
- ("Default Size", (255, 255, 0), wxDefaultSize, ""),
+ ("Default Size", (255, 255, 0), wx.DefaultSize, ""),
("Another Size", (255, 0, 255), (60, 20), ""),
- ("Another Colour", (0, 255, 0), wxDefaultSize, ""),
+ ("Another Colour", (0, 255, 0), wx.DefaultSize, ""),
("Larger Size", (0, 0, 255), (60, 60), ""),
- ("With a Label", (127, 0, 255), wxDefaultSize, "Colour..."),
+ ("With a Label", (127, 0, 255), wx.DefaultSize, "Colour..."),
("Another Colour/Label", (255, 100, 130), (120, -1), "Choose Colour..."),
]
# build each button and save a reference to it
for name, color, size, label in buttonData:
- b = ColourSelect(self, -1, label, color, size = size)
- EVT_COLOURSELECT(b, b.GetId(), self.OnSelectColour)
+ b = csel.ColourSelect(self, -1, label, color, size = size)
+
+ b.Bind(csel.EVT_COLOURSELECT, self.OnSelectColour)
self.buttonRefs.append((name, b)) # store reference to button
+
buttonSizer.AddMany([
- (wxStaticText(self, -1, name), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL),
- (b, 0, wxALL, 3),
+ (wx.StaticText(self, -1, name), 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL),
+ (b, 0, wx.ALL, 3),
])
- mainSizer.Add(buttonSizer, 0, wxALL, 3)
+ mainSizer.Add(buttonSizer, 0, wx.ALL, 3)
self.Layout()
def OnSelectColour(self, event):
"""
-
-
-
if __name__ == '__main__':
import sys,os
import run
+# 11/4/2003 - grimmtooth@softhome.net (Jeff Grimmett)
+#
+# o Modified for V2.5
+#
+# 11/24/2003 - grimmtooth@softhome.net (Jeff Grimmett)
+#
+# o Removed import of wx.help - now part of wx.core.
+#
-from wxPython.wx import *
+import wx
#----------------------------------------------------------------------
# We first have to set an application-wide help provider. Normally you
# would do this in your app's OnInit or in other startup code...
-provider = wxSimpleHelpProvider()
-wxHelpProvider_Set(provider)
+provider = wx.SimpleHelpProvider()
+wx.HelpProvider_Set(provider)
-
-class TestPanel(wxPanel):
+# This panel is chock full of controls about which we can demonstrate the
+# help system.
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.log = log
- self.SetHelpText("This is a wxPanel.")
- sizer = wxBoxSizer(wxVERTICAL)
+ # This help text, set for the panel itself, will be used if context
+ # sensitive help cannot be found for any particular control.
+ self.SetHelpText("This is a wx.Panel.")
+
+ sizer = wx.BoxSizer(wx.VERTICAL)
+
+ # Init the context help button.
+ # And even include help text about the help button :-)
+ cBtn = wx.ContextHelpButton(self)
+ cBtn.SetHelpText("wx.ContextHelpButton")
+
+ cBtnText = wx.StaticText(self, -1,
+ "This is a wx.ContextHelpButton. Clicking it puts the\n"
+ "app into context sensitive help mode."
+ )
- cBtn = wxContextHelpButton(self)
- cBtn.SetHelpText("wxContextHelpButton")
- cBtnText = wxStaticText(self, -1, "This is a wxContextHelpButton. Clicking it puts the\n"
- "app into context sensitive help mode.")
+ # Yes, even static text can have help text associated with it :-)
cBtnText.SetHelpText("Some helpful text...")
- s = wxBoxSizer(wxHORIZONTAL)
+ s = wx.BoxSizer(wx.HORIZONTAL)
s.Add(cBtn, 0, wxALL, 5)
s.Add(cBtnText, 0, wxALL, 5)
sizer.Add((20,20))
sizer.Add(s)
- text = wxTextCtrl(self, -1, "Each sub-window can have its own help message",
- size=(240, 60), style = wxTE_MULTILINE)
+ # A text control with help text.
+ text = wx.TextCtrl(self, -1, "Each sub-window can have its own help message",
+ size=(240, 60), style=wx.TE_MULTILINE)
text.SetHelpText("This is my very own help message. This is a really long long long long long long long long long long long long long long long long long long long long message!")
sizer.Add((20,20))
sizer.Add(text)
- text = wxTextCtrl(self, -1, "You can also intercept the help event if you like. Watch the log window when you click here...",
- size=(240, 60), style = wxTE_MULTILINE)
+ # Same thing, but this time to demonstrate how the help event can be
+ # intercepted.
+ text = wx.TextCtrl(self, -1, "You can also intercept the help event if you like. Watch the log window when you click here...",
+ size=(240, 60), style = wx.TE_MULTILINE)
text.SetHelpText("Yet another context help message.")
sizer.Add((20,20))
sizer.Add(text)
- EVT_HELP(text, text.GetId(), self.OnCtxHelp)
+ self.Bind(wx.EVT_HELP, self.OnCtxHelp, text)
- text = wxTextCtrl(self, -1, "This one displays the tip itself...",
- size=(240, 60), style = wxTE_MULTILINE)
+ text = wx.TextCtrl(self, -1, "This one displays the tip itself...",
+ size=(240, 60), style = wx.TE_MULTILINE)
sizer.Add((20,20))
sizer.Add(text)
- EVT_HELP(text, text.GetId(), self.OnCtxHelp2)
+ self.Bind(wx.EVT_HELP, self.OnCtxHelp2, text)
- border = wxBoxSizer(wxVERTICAL)
- border.Add(sizer, 0, wxALL, 25)
+ border = wx.BoxSizer(wx.VERTICAL)
+ border.Add(sizer, 0, wx.ALL, 25)
self.SetAutoLayout(True)
self.SetSizer(border)
self.Layout()
+ # On the second text control above, we intercept the help event. This is where
+ # we process it. Anything could happen here. In this case we're just printing
+ # some stuff about it, then passing it on, at which point we see the help tip.
def OnCtxHelp(self, evt):
self.log.write("OnCtxHelp: %s" % evt)
evt.Skip()
-
+ # On the third text control above, we intercept the help event.
+ # Here, we print a note about it, generate our own tip window, and,
+ # unlike last time, we don't pass it on to the underlying provider.
def OnCtxHelp2(self, evt):
self.log.write("OnCtxHelp: %s\n" % evt)
- tip = wxTipWindow(self, "This is a wxTipWindow")
+ tip = wx.TipWindow(self, "This is a wx.TipWindow")
#----------------------------------------------------------------------
#----------------------------------------------------------------------
-
-
overview = """
This demo shows how to incorporate Context Sensitive
-help into your application using the wxSimpleHelpProvider class.
+help into your application using the wx.SimpleHelpProvider class.
"""
-
-
#----------------------------------------------------------------------
-
-
if __name__ == '__main__':
import sys,os
import run
-
-from wxPython.wx import *
-
-import cPickle
+# 11/5/2003 - Modified by grimmtooth@softhome.net (Jeff Grimmett)
+#
+# o Updated for wx namespace
+#
+# 11/24/2003 - Modified by grimmtooth@softhome.net (Jeff Grimmett)
+#
+# o Issues around line 167. I'm stuck.
+#
+
+import cPickle
+import wx
#----------------------------------------------------------------------
-class DoodlePad(wxWindow):
+class DoodlePad(wx.Window):
def __init__(self, parent, log):
- wxWindow.__init__(self, parent, -1, style=wxSUNKEN_BORDER)
+ wx.Window.__init__(self, parent, -1, style=wx.SUNKEN_BORDER)
self.log = log
- self.SetBackgroundColour(wxWHITE)
+ self.SetBackgroundColour(wx.WHITE)
self.lines = []
self.x = self.y = 0
self.SetMode("Draw")
- EVT_LEFT_DOWN(self, self.OnLeftDown)
- EVT_LEFT_UP(self, self.OnLeftUp)
- EVT_RIGHT_UP(self, self.OnRightUp)
- EVT_MOTION(self, self.OnMotion)
- EVT_PAINT(self, self.OnPaint)
+ wx.EVT_LEFT_DOWN(self, self.OnLeftDown)
+ wx.EVT_LEFT_UP(self, self.OnLeftUp)
+ wx.EVT_RIGHT_UP(self, self.OnRightUp)
+ wx.EVT_MOTION(self, self.OnMotion)
+ wx.EVT_PAINT(self, self.OnPaint)
def SetMode(self, mode):
self.mode = mode
if self.mode == "Draw":
- self.SetCursor(wxStockCursor(wxCURSOR_PENCIL))
+ self.SetCursor(wx.StockCursor(wx.CURSOR_PENCIL))
else:
- self.SetCursor(wxSTANDARD_CURSOR)
+ self.SetCursor(wx.STANDARD_CURSOR)
def OnPaint(self, event):
- dc = wxPaintDC(self)
+ dc = wx.PaintDC(self)
self.DrawSavedLines(dc)
def DrawSavedLines(self, dc):
dc.BeginDrawing()
- dc.SetPen(wxPen(wxBLUE, 3))
+ dc.SetPen(wx.Pen(wx.BLUE, 3))
for line in self.lines:
for coords in line:
dc.DrawLineXY(*coords)
self.x, self.y = event.GetPositionTuple()
self.CaptureMouse()
else:
- wxBell()
+ wx.Bell()
self.log.write("unknown mode!\n")
def OnMotion(self, event):
if event.Dragging() and not self.mode == "Drag":
- dc = wxClientDC(self)
+ dc = wx.ClientDC(self)
dc.BeginDrawing()
- dc.SetPen(wxPen(wxBLUE, 3))
- coords = (self.x, self.y) + event.GetPositionTuple()
+ dc.SetPen(wx.Pen(wx.BLUE, 3))
+ coords = ((self.x, self.y), event.GetPosition())
self.curLine.append(coords)
dc.DrawLineXY(*coords)
self.x, self.y = event.GetPositionTuple()
# create our own data format and use it in a
# custom data object
- ldata = wxCustomDataObject(wxCustomDataFormat("DoodleLines"))
+ ldata = wx.CustomDataObject(wx.CustomDataFormat("DoodleLines"))
ldata.SetData(linesdata)
# Also create a Bitmap version of the drawing
size = self.GetSize()
- bmp = wxEmptyBitmap(size.width, size.height)
- dc = wxMemoryDC()
+ bmp = wx.EmptyBitmap(size.width, size.height)
+ dc = wx.MemoryDC()
dc.SelectObject(bmp)
- dc.SetBackground(wxWHITE_BRUSH)
+ dc.SetBackground(wx.WHITE_BRUSH)
dc.Clear()
self.DrawSavedLines(dc)
- dc.SelectObject(wxNullBitmap)
+ dc.SelectObject(wx.NullBitmap)
# Now make a data object for the bitmap and also a composite
# data object holding both of the others.
- bdata = wxBitmapDataObject(bmp)
- data = wxDataObjectComposite()
+ bdata = wx.BitmapDataObject(bmp)
+ data = wx.DataObjectComposite()
data.Add(ldata)
data.Add(bdata)
# And finally, create the drop source and begin the drag
# and drop opperation
- dropSource = wxDropSource(self)
+ dropSource = wx.DropSource(self)
dropSource.SetData(data)
self.log.WriteText("Begining DragDrop\n")
- result = dropSource.DoDragDrop(wxDrag_AllowMove)
+ result = dropSource.DoDragDrop(wx.Drag_AllowMove)
self.log.WriteText("DragDrop completed: %d\n" % result)
- if result == wxDragMove:
+
+ if result == wx.DragMove:
self.lines = []
self.Refresh()
#----------------------------------------------------------------------
-class DoodleDropTarget(wxPyDropTarget):
+class DoodleDropTarget(wx.PyDropTarget):
def __init__(self, window, log):
- wxPyDropTarget.__init__(self)
+ wx.PyDropTarget.__init__(self)
self.log = log
self.dv = window
# specify the type of data we will accept
- self.df = wxCustomDataFormat("DoodleLines")
- self.data = wxCustomDataObject(self.df)
+ self.df = wx.CustomDataFormat("DoodleLines")
+ self.data = wx.CustomDataObject(self.df)
self.SetDataObject(self.data)
if self.GetData():
# convert it back to a list of lines and give it to the viewer
linesdata = self.data.GetData()
- lines = cPickle.loads(linesdata)
+ lines = wx.InputStream(cPickle.loads(linesdata))
self.dv.SetLines(lines)
- return d # what is returned signals the source what to do
- # with the original data (move, copy, etc.) In this
- # case we just return the suggested value given to us.
-
-
+
+ # what is returned signals the source what to do
+ # with the original data (move, copy, etc.) In this
+ # case we just return the suggested value given to us.
+ return d
+
-class DoodleViewer(wxWindow):
+class DoodleViewer(wx.Window):
def __init__(self, parent, log):
- wxWindow.__init__(self, parent, -1, style=wxSUNKEN_BORDER)
+ wx.Window.__init__(self, parent, -1, style=wx.SUNKEN_BORDER)
self.log = log
- self.SetBackgroundColour(wxWHITE)
+ self.SetBackgroundColour(wx.WHITE)
self.lines = []
self.x = self.y = 0
dt = DoodleDropTarget(self, log)
self.SetDropTarget(dt)
- EVT_PAINT(self, self.OnPaint)
+ wx.EVT_PAINT(self, self.OnPaint)
def SetLines(self, lines):
self.Refresh()
def OnPaint(self, event):
- dc = wxPaintDC(self)
+ dc = wx.PaintDC(self)
self.DrawSavedLines(dc)
def DrawSavedLines(self, dc):
dc.BeginDrawing()
- dc.SetPen(wxPen(wxRED, 3))
+ dc.SetPen(wx.Pen(wx.RED, 3))
+
for line in self.lines:
for coords in line:
dc.DrawLineXY(*coords)
#----------------------------------------------------------------------
-class CustomDnDPanel(wxPanel):
+class CustomDnDPanel(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
- self.SetFont(wxFont(10, wxSWISS, wxNORMAL, wxBOLD, False))
+ self.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD, False))
# Make the controls
- text1 = wxStaticText(self, -1,
+ text1 = wx.StaticText(self, -1,
"Draw a little picture in this window\n"
"then switch the mode below and drag the\n"
"picture to the lower window or to another\n"
"target.\n"
)
- rb1 = wxRadioButton(self, -1, "Draw", style=wxRB_GROUP)
+ rb1 = wx.RadioButton(self, -1, "Draw", style=wx.RB_GROUP)
rb1.SetValue(True)
- rb2 = wxRadioButton(self, -1, "Drag")
+ rb2 = wx.RadioButton(self, -1, "Drag")
rb2.SetValue(False)
- text2 = wxStaticText(self, -1,
+ text2 = wx.StaticText(self, -1,
"The lower window is accepting a\n"
"custom data type that is a pickled\n"
"Python list of lines data.")
view = DoodleViewer(self, log)
# put them in sizers
- sizer = wxBoxSizer(wxHORIZONTAL)
- box = wxBoxSizer(wxVERTICAL)
- rbox = wxBoxSizer(wxHORIZONTAL)
+ sizer = wx.BoxSizer(wx.HORIZONTAL)
+ box = wx.BoxSizer(wx.VERTICAL)
+ rbox = wx.BoxSizer(wx.HORIZONTAL)
rbox.Add(rb1)
rbox.Add(rb2)
sizer.Add(box)
- dndsizer = wxBoxSizer(wxVERTICAL)
- dndsizer.Add(self.pad, 1, wxEXPAND|wxALL, 5)
- dndsizer.Add(view, 1, wxEXPAND|wxALL, 5)
+ dndsizer = wx.BoxSizer(wx.VERTICAL)
+ dndsizer.Add(self.pad, 1, wx.EXPAND|wx.ALL, 5)
+ dndsizer.Add(view, 1, wx.EXPAND|wx.ALL, 5)
- sizer.Add(dndsizer, 1, wxEXPAND)
+ sizer.Add(dndsizer, 1, wx.EXPAND)
self.SetAutoLayout(True)
self.SetSizer(sizer)
# Events
- EVT_RADIOBUTTON(self, rb1.GetId(), self.OnRadioButton)
- EVT_RADIOBUTTON(self, rb2.GetId(), self.OnRadioButton)
+ wx.EVT_RADIOBUTTON(self, rb1.GetId(), self.OnRadioButton)
+ wx.EVT_RADIOBUTTON(self, rb2.GetId(), self.OnRadioButton)
def OnRadioButton(self, evt):
#----------------------------------------------------------------------
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.SetAutoLayout(True)
- sizer = wxBoxSizer(wxVERTICAL)
+ sizer = wx.BoxSizer(wx.VERTICAL)
msg = "Custom Drag-And-Drop"
- text = wxStaticText(self, -1, "", style=wxALIGN_CENTRE)
- text.SetFont(wxFont(24, wxSWISS, wxNORMAL, wxBOLD, False))
+ text = wx.StaticText(self, -1, "", style=wx.ALIGN_CENTRE)
+ text.SetFont(wx.Font(24, wx.SWISS, wx.NORMAL, wx.BOLD, False))
text.SetLabel(msg)
w,h = text.GetTextExtent(msg)
- text.SetSize(wxSize(w,h+1))
- text.SetForegroundColour(wxBLUE)
- sizer.Add(text, 0, wxEXPAND|wxALL, 5)
- sizer.Add(wxStaticLine(self, -1), 0, wxEXPAND)
+ text.SetSize(wx.Size(w,h+1))
+ text.SetForegroundColour(wx.BLUE)
+ sizer.Add(text, 0, wx.EXPAND|wx.ALL, 5)
+ sizer.Add(wx.StaticLine(self, -1), 0, wx.EXPAND)
- sizer.Add(CustomDnDPanel(self, log), 1, wxEXPAND)
+ sizer.Add(CustomDnDPanel(self, log), 1, wx.EXPAND)
self.SetSizer(sizer)
if __name__ == '__main__':
import sys
+
class DummyLog:
def WriteText(self, text):
sys.stdout.write(text)
- class TestApp(wxApp):
+ class TestApp(wx.App):
def OnInit(self):
- wxInitAllImageHandlers()
+ wx.InitAllImageHandlers()
self.MakeFrame()
return True
def MakeFrame(self, event=None):
- frame = wxFrame(None, -1, "Custom Drag and Drop", size=(550,400))
- menu = wxMenu()
+ frame = wx.Frame(None, -1, "Custom Drag and Drop", size=(550,400))
+ menu = wx.Menu()
menu.Append(6543, "Window")
- mb = wxMenuBar()
+ mb = wx.MenuBar()
mb.Append(menu, "New")
frame.SetMenuBar(mb)
- EVT_MENU(frame, 6543, self.MakeFrame)
+ wx.EVT_MENU(frame, 6543, self.MakeFrame)
panel = TestPanel(frame, DummyLog())
frame.Show(True)
self.SetTopWindow(frame)
-
+ #----------------------------------------------------------------------
app = TestApp(0)
app.MainLoop()
and is made available to any drop target that accepts bitmaps, such as
MS Word.
-The two data objects are combined in a wxDataObjectComposite and the
+The two data objects are combined in a wx.DataObjectComposite and the
rest is handled by the framework.
</body></html>
"""
-
-
# Copyright: (c) 1998 by Total Control Software
# Licence: wxWindows license
#----------------------------------------------------------------------------
+# Updated 11/9/2003 by Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Converted for V2.5 compatability
+#
-
-## import all of the wxPython GUI package
-from wxPython.wx import *
-
+import wx
#---------------------------------------------------------------------------
-## Create a new frame class, derived from the wxPython Frame.
-class MyFrame(wxFrame):
+# Create a new frame class, derived from the wxPython Frame.
+class MyFrame(wx.Frame):
def __init__(self, parent, id, title):
# First, call the base class' __init__ method to create the frame
- wxFrame.__init__(self, parent, id, title,
- wxPoint(100, 100), wxSize(160, 100))
+ wx.Frame.__init__(self, parent, id, title, (100, 100), (160, 100))
# Associate some events with methods of this class
- EVT_SIZE(self, self.OnSize)
- EVT_MOVE(self, self.OnMove)
- EVT_CLOSE(self, self.OnCloseWindow)
+ self.Bind(wx.EVT_SIZE, self.OnSize)
+ self.Bind(wx.EVT_MOVE, self.OnMove)
+ self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
# Add a panel and some controls to display the size and position
- panel = wxPanel(self, -1)
- wxStaticText(panel, -1, "Size:",
- wxDLG_PNT(panel, wxPoint(4, 4)), wxDefaultSize)
- wxStaticText(panel, -1, "Pos:",
- wxDLG_PNT(panel, wxPoint(4, 16)), wxDefaultSize)
- self.sizeCtrl = wxTextCtrl(panel, -1, "",
- wxDLG_PNT(panel, wxPoint(24, 4)),
- wxDLG_SZE(panel, wxSize(36, -1)),
- wxTE_READONLY)
+ panel = wx.Panel(self, -1)
- self.posCtrl = wxTextCtrl(panel, -1, "",
- wxDLG_PNT(panel, wxPoint(24, 16)),
- wxDLG_SZE(panel, wxSize(36, -1)),
- wxTE_READONLY)
+ wx.StaticText(panel, -1, "Size:",
+ wx.DLG_PNT(panel, (4, 4)), wx.DefaultSize
+ )
- #print wxDLG_PNT(panel, wxPoint(24, 4)), wxDLG_SZE(panel, wxSize(36, -1))
- #print wxDLG_PNT(panel, wxPoint(24, 16)),wxDLG_SZE(panel, wxSize(36, -1))
+ wx.StaticText(panel, -1, "Pos:",
+ wx.DLG_PNT(panel, (4, 16)), wx.DefaultSize
+ )
+ self.sizeCtrl = wx.TextCtrl(panel, -1, "",
+ wx.DLG_PNT(panel, (24, 4)),
+ wx.DLG_SZE(panel, (36, -1)),
+ wx.TE_READONLY)
+
+ self.posCtrl = wx.TextCtrl(panel, -1, "",
+ wx.DLG_PNT(panel, (24, 16)),
+ wx.DLG_SZE(panel, (36, -1)),
+ wx.TE_READONLY)
+
+ #print wx.DLG_PNT(panel, (24, 4)), wx.DLG_SZE(panel, (36, -1))
+ #print wx.DLG_PNT(panel, (24, 16)),wx.DLG_SZE(panel, (36, -1))
# This method is called automatically when the CLOSE event is
# sent to this window
# tell the window to kill itself
self.Destroy()
-
# This method is called by the System when the window is resized,
# because of the association above.
def OnSize(self, event):
if __name__ == "__main__":
# Every wxWindows application must have a class derived from wxApp
- class MyApp(wxApp):
+ class MyApp(wx.App):
# wxWindows calls this method to initialize the application
def OnInit(self):
+# 11/5/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+# o Got rid of all the hardcoded window IDs.
+# o Fixed a bug in class TestPanel() (empty sizer Add())
+#
+# 11/25/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Fixed a bug in the BMP file dialog; was using GetFilename()
+# instead of GetPath() to get the file to load.
+#
+
+import wx
-from wxPython.wx import *
+#----------------------------------------------------------------------
+
+ID_CopyBtn = wx.NewId()
+ID_PasteBtn = wx.NewId()
+ID_BitmapBtn = wx.NewId()
#----------------------------------------------------------------------
-class ClipTextPanel(wxPanel):
+class ClipTextPanel(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.log = log
- #self.SetFont(wxFont(10, wxSWISS, wxNORMAL, wxBOLD, False))
-
- sizer = wxBoxSizer(wxVERTICAL)
- sizer.Add(wxStaticText(self, -1,
- "Copy/Paste text to/from\n"
- "this window and other apps"), 0, wxEXPAND|wxALL, 2)
-
- self.text = wxTextCtrl(self, -1, "", style=wxTE_MULTILINE|wxHSCROLL)
- sizer.Add(self.text, 1, wxEXPAND)
-
- hsz = wxBoxSizer(wxHORIZONTAL)
- hsz.Add(wxButton(self, 6050, " Copy "), 1, wxEXPAND|wxALL, 2)
- hsz.Add(wxButton(self, 6051, " Paste "), 1, wxEXPAND|wxALL, 2)
- sizer.Add(hsz, 0, wxEXPAND)
- sizer.Add(wxButton(self, 6052, " Copy Bitmap "), 0, wxEXPAND|wxALL, 2)
-
- EVT_BUTTON(self, 6050, self.OnCopy)
- EVT_BUTTON(self, 6051, self.OnPaste)
- EVT_BUTTON(self, 6052, self.OnCopyBitmap)
+ #self.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD, False))
+
+ sizer = wx.BoxSizer(wx.VERTICAL)
+ sizer.Add(
+ wx.StaticText(
+ self, -1, "Copy/Paste text to/from\n"
+ "this window and other apps"
+ ),
+ 0, wx.EXPAND|wx.ALL, 2
+ )
+
+ self.text = wx.TextCtrl(self, -1, "", style=wx.TE_MULTILINE|wx.HSCROLL)
+ sizer.Add(self.text, 1, wx.EXPAND)
+
+ hsz = wx.BoxSizer(wx.HORIZONTAL)
+ hsz.Add(wx.Button(self, ID_CopyBtn, " Copy "), 1, wx.EXPAND|wx.ALL, 2)
+ hsz.Add(wx.Button(self, ID_PasteBtn, " Paste "), 1, wx.EXPAND|wx.ALL, 2)
+ sizer.Add(hsz, 0, wx.EXPAND)
+ sizer.Add(
+ wx.Button(self, ID_BitmapBtn, " Copy Bitmap "),
+ 0, wx.EXPAND|wx.ALL, 2
+ )
+
+ self.Bind(wx.EVT_BUTTON, self.OnCopy, id=ID_CopyBtn)
+ self.Bind(wx.EVT_BUTTON, self.OnPaste, id=ID_PasteBtn)
+ self.Bind(wx.EVT_BUTTON, self.OnCopyBitmap, id=ID_BitmapBtn)
self.SetAutoLayout(True)
self.SetSizer(sizer)
def OnCopy(self, evt):
- self.do = wxTextDataObject()
+ self.do = wx.TextDataObject()
self.do.SetText(self.text.GetValue())
- wxTheClipboard.Open()
- wxTheClipboard.SetData(self.do)
- wxTheClipboard.Close()
+ wx.TheClipboard.Open()
+ wx.TheClipboard.SetData(self.do)
+ wx.TheClipboard.Close()
def OnPaste(self, evt):
- do = wxTextDataObject()
- wxTheClipboard.Open()
- success = wxTheClipboard.GetData(do)
- wxTheClipboard.Close()
+ do = wx.TextDataObject()
+ wx.TheClipboard.Open()
+ success = wx.TheClipboard.GetData(do)
+ wx.TheClipboard.Close()
+
if success:
self.text.SetValue(do.GetText())
else:
- wxMessageBox("There is no data in the clipboard in the required format",
- "Error")
+ wx.MessageBox(
+ "There is no data in the clipboard in the required format",
+ "Error"
+ )
def OnCopyBitmap(self, evt):
- dlg = wxFileDialog(self, "Choose a bitmap to copy", wildcard="*.bmp")
- if dlg.ShowModal() == wxID_OK:
- bmp = wxBitmap(dlg.GetFilename(), wxBITMAP_TYPE_BMP)
- bmpdo = wxBitmapDataObject(bmp)
- wxTheClipboard.Open()
- wxTheClipboard.SetData(bmpdo)
- wxTheClipboard.Close()
-
- wxMessageBox("The bitmap is now in the Clipboard. Switch to a graphics\n"
- "editor and try pasting it in...")
+ dlg = wx.FileDialog(self, "Choose a bitmap to copy", wildcard="*.bmp")
+
+ if dlg.ShowModal() == wx.ID_OK:
+ bmp = wx.Bitmap(dlg.GetPath(), wx.BITMAP_TYPE_BMP)
+ bmpdo = wx.BitmapDataObject(bmp)
+ wx.TheClipboard.Open()
+ wx.TheClipboard.SetData(bmpdo)
+ wx.TheClipboard.Close()
+
+ wx.MessageBox(
+ "The bitmap is now in the Clipboard. Switch to a graphics\n"
+ "editor and try pasting it in..."
+ )
+
dlg.Destroy()
#----------------------------------------------------------------------
-class OtherDropTarget(wxPyDropTarget):
+class OtherDropTarget(wx.PyDropTarget):
def __init__(self, window, log):
- wxPyDropTarget.__init__(self)
+ wx.PyDropTarget.__init__(self)
self.log = log
- self.do = wxFileDataObject()
+ self.do = wx.FileDataObject()
self.SetDataObject(self.do)
def OnEnter(self, x, y, d):
self.log.WriteText("OnEnter: %d, %d, %d\n" % (x, y, d))
- return wxDragCopy
+ return wx.DragCopy
#def OnDragOver(self, x, y, d):
# self.log.WriteText("OnDragOver: %d, %d, %d\n" % (x, y, d))
- # return wxDragCopy
+ # return wx.DragCopy
def OnLeave(self):
self.log.WriteText("OnLeave\n")
return d
-
-
-class MyFileDropTarget(wxFileDropTarget):
+class MyFileDropTarget(wx.FileDropTarget):
def __init__(self, window, log):
- wxFileDropTarget.__init__(self)
+ wx.FileDropTarget.__init__(self)
self.window = window
self.log = log
self.window.SetInsertionPointEnd()
self.window.WriteText("\n%d file(s) dropped at %d,%d:\n" %
(len(filenames), x, y))
+
for file in filenames:
self.window.WriteText(file + '\n')
-class MyTextDropTarget(wxTextDropTarget):
+class MyTextDropTarget(wx.TextDropTarget):
def __init__(self, window, log):
- wxTextDropTarget.__init__(self)
+ wx.TextDropTarget.__init__(self)
self.window = window
self.log = log
self.window.WriteText("(%d, %d)\n%s\n" % (x, y, text))
def OnDragOver(self, x, y, d):
- return wxDragCopy
+ return wx.DragCopy
-class FileDropPanel(wxPanel):
+class FileDropPanel(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
+
+ #self.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD, False))
- #self.SetFont(wxFont(10, wxSWISS, wxNORMAL, wxBOLD, False))
+ sizer = wx.BoxSizer(wx.VERTICAL)
+ sizer.Add(
+ wx.StaticText(self, -1, " \nDrag some files here:"),
+ 0, wx.EXPAND|wx.ALL, 2
+ )
- sizer = wxBoxSizer(wxVERTICAL)
- sizer.Add(wxStaticText(self, -1, " \nDrag some files here:"),
- 0, wxEXPAND|wxALL, 2)
+ self.text = wx.TextCtrl(
+ self, -1, "",
+ style = wx.TE_MULTILINE|wx.HSCROLL|wx.TE_READONLY
+ )
- self.text = wxTextCtrl(self, -1, "",
- style = wxTE_MULTILINE|wxHSCROLL|wxTE_READONLY)
dt = MyFileDropTarget(self, log)
self.text.SetDropTarget(dt)
- sizer.Add(self.text, 1, wxEXPAND)
+ sizer.Add(self.text, 1, wx.EXPAND)
+
+ sizer.Add(
+ wx.StaticText(self, -1, " \nDrag some text here:"),
+ 0, wx.EXPAND|wx.ALL, 2
+ )
+
+ self.text2 = wx.TextCtrl(
+ self, -1, "",
+ style = wx.TE_MULTILINE|wx.HSCROLL|wx.TE_READONLY
+ )
- sizer.Add(wxStaticText(self, -1, " \nDrag some text here:"),
- 0, wxEXPAND|wxALL, 2)
- self.text2 = wxTextCtrl(self, -1, "",
- style = wxTE_MULTILINE|wxHSCROLL|wxTE_READONLY)
dt = MyTextDropTarget(self.text2, log)
self.text2.SetDropTarget(dt)
- sizer.Add(self.text2, 1, wxEXPAND)
+ sizer.Add(self.text2, 1, wx.EXPAND)
self.SetAutoLayout(True)
self.SetSizer(sizer)
#----------------------------------------------------------------------
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.SetAutoLayout(True)
- outsideSizer = wxBoxSizer(wxVERTICAL)
+ outsideSizer = wx.BoxSizer(wx.VERTICAL)
msg = "Clipboard / Drag-And-Drop"
- text = wxStaticText(self, -1, "", style=wxALIGN_CENTRE)
- text.SetFont(wxFont(24, wxSWISS, wxNORMAL, wxBOLD, False))
+ text = wx.StaticText(self, -1, "", style=wx.ALIGN_CENTRE)
+ text.SetFont(wx.Font(24, wx.SWISS, wx.NORMAL, wx.BOLD, False))
text.SetLabel(msg)
+
w,h = text.GetTextExtent(msg)
- text.SetSize(wxSize(w,h+1))
- text.SetForegroundColour(wxBLUE)
- outsideSizer.Add(text, 0, wxEXPAND|wxALL, 5)
- outsideSizer.Add(wxStaticLine(self, -1), 0, wxEXPAND)
+ text.SetSize(wx.Size(w,h+1))
+ text.SetForegroundColour(wx.BLUE)
+ outsideSizer.Add(text, 0, wx.EXPAND|wx.ALL, 5)
+ outsideSizer.Add(wx.StaticLine(self, -1), 0, wx.EXPAND)
- inSizer = wxBoxSizer(wxHORIZONTAL)
- inSizer.Add(ClipTextPanel(self, log), 1, wxEXPAND)
- inSizer.Add(FileDropPanel(self, log), 1, wxEXPAND)
+ inSizer = wx.BoxSizer(wx.HORIZONTAL)
+ inSizer.Add(ClipTextPanel(self, log), 1, wx.EXPAND)
+ inSizer.Add(FileDropPanel(self, log), 1, wx.EXPAND)
- outsideSizer.Add(inSizer, 1, wxEXPAND)
+ outsideSizer.Add(inSizer, 1, wx.EXPAND)
self.SetSizer(outsideSizer)
#----------------------------------------------------------------------
-
-
-
-
-
-
-
-
-
-
-overview = """<html><body>\
+overview = """\
+<html>
+<body>
This demo shows some examples of data transfer through clipboard or
drag and drop. In wxWindows, these two ways to transfer data (either
between different applications or inside one and the same) are very
be in the same application and even the same window when, for example,
you drag some text from one position to another in a word
processor. Let us describe what each of them should do.
-</body></html>
+</body>
+</html>
"""
-
-
if __name__ == '__main__':
import sys,os
import run
-
-from wxPython.wx import *
-import whrandom, time
+# 11/5/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+# o Replaced all calls to deprecated whrandom module with up to date random calls.
+# See Python docs regarding whrandom for details.
+#
+# 11/25/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o New binding
+#
+
+import random
+import time
+
+import wx
#----------------------------------------------------------------------
def makeRandomPoints(num, w, h):
pnts = []
+
for i in range(num):
- x = whrandom.randint(0, w)
- y = whrandom.randint(0, h)
+ x = random.randint(0, w)
+ y = random.randint(0, h)
pnts.append( (x,y) )
+
return pnts
def makeRandomLines(num, w, h):
pnts = []
+
for i in range(num):
- x1 = whrandom.randint(0, w)
- y1 = whrandom.randint(0, h)
- x2 = whrandom.randint(0, w)
- y2 = whrandom.randint(0, h)
+ x1 = random.randint(0, w)
+ y1 = random.randint(0, h)
+ x2 = random.randint(0, w)
+ y2 = random.randint(0, h)
pnts.append( (x1,y1, x2,y2) )
+
return pnts
def makeRandomRectangles(num, W, H):
rects = []
+
for i in range(num):
- w = whrandom.randint(10, W/2)
- h = whrandom.randint(10, H/2)
- x = whrandom.randint(0, W - w)
- y = whrandom.randint(0, H - h)
+ w = random.randint(10, W/2)
+ h = random.randint(10, H/2)
+ x = random.randint(0, W - w)
+ y = random.randint(0, H - h)
rects.append( (x, y, w, h) )
+
return rects
def makeRandomText(num):
Np = 8 # number of characters in text
text = []
+
for i in range(num):
word = []
+
for i in range(Np):
- c = chr( whrandom.randint(48, 122) )
+ c = chr( random.randint(48, 122) )
word.append( c )
+
text.append( "".join(word) )
+
return text
def makeRandomPolygons(num, W, H):
Np = 8 # number of points per polygon
polys = []
+
for i in range(num):
poly = []
+
for i in range(Np):
- x = whrandom.randint(0, W)
- y = whrandom.randint(0, H)
+ x = random.randint(0, W)
+ y = random.randint(0, H)
poly.append( (x,y) )
+
polys.append( poly )
- return polys
+ return polys
def makeRandomPens(num, cache):
pens = []
+
for i in range(num):
- c = whrandom.choice(colours)
- t = whrandom.randint(1, 4)
+ c = random.choice(colours)
+ t = random.randint(1, 4)
+
if not cache.has_key( (c, t) ):
- cache[(c, t)] = wxPen(c, t)
+ cache[(c, t)] = wx.Pen(c, t)
+
pens.append( cache[(c, t)] )
+
return pens
def makeRandomBrushes(num, cache):
brushes = []
+
for i in range(num):
- c = whrandom.choice(colours)
+ c = random.choice(colours)
+
if not cache.has_key(c):
- cache[c] = wxBrush(c)
+ cache[c] = wx.Brush(c)
+
brushes.append( cache[c] )
+
return brushes
def makeRandomColors(num):
colors = []
+
for i in range(num):
c = whrandom.choice(colours)
colors.append(wxNamedColour(c))
# make some lists of random shapes
points = makeRandomPoints(n, w, h)
+
try:
import Numeric
Apoints = Numeric.array(points)
except:
pass
+
lines = makeRandomLines(n, w, h)
rectangles = makeRandomRectangles(n, w, h)
polygons = makeRandomPolygons(n, w, h)
def TestPoints(dc,log):
dc.BeginDrawing()
start = time.time()
- dc.SetPen(wxPen("BLACK", 4))
+ dc.SetPen(wx.Pen("BLACK", 4))
dc.DrawPointList(points)
- dc.DrawPointList(points, wxPen("RED", 2))
+ dc.DrawPointList(points, wx.Pen("RED", 2))
dc.DrawPointList(points, pens)
dc.EndDrawing()
dc.BeginDrawing()
start = time.time()
- dc.SetPen(wxPen("BLACK", 1))
+ dc.SetPen(wx.Pen("BLACK", 1))
+
for i in range(1):
dc.DrawPointList(Apoints)
- #dc.DrawPointList(Apoints, wxPen("RED", 2))
+
+ #dc.DrawPointList(Apoints, wx.Pen("RED", 2))
#dc.DrawPointList(Apoints, pens)
dc.EndDrawing()
log.write("DrawTime: %s seconds with DrawPointList an Numpy Array\n" % (time.time() - start))
dc.BeginDrawing()
start = time.time()
- dc.SetPen(wxPen("BLACK", 2))
+ dc.SetPen(wx.Pen("BLACK", 2))
dc.DrawLineList(lines)
- dc.DrawLineList(lines, wxPen("RED", 2))
+ dc.DrawLineList(lines, wx.Pen("RED", 2))
dc.DrawLineList(lines, pens)
dc.EndDrawing()
dc.BeginDrawing()
start = time.time()
- dc.SetPen( wxPen("BLACK",1) )
- dc.SetBrush( wxBrush("RED") )
+ dc.SetPen( wx.Pen("BLACK",1) )
+ dc.SetBrush( wx.Brush("RED") )
dc.DrawRectangleList(rectangles)
dc.DrawRectangleList(rectangles,pens)
dc.BeginDrawing()
start = time.time()
- dc.SetPen( wxPen("BLACK",1) )
- dc.SetBrush( wxBrush("RED") )
+ dc.SetPen( wx.Pen("BLACK",1) )
+ dc.SetBrush( wx.Brush("RED") )
dc.DrawEllipseList(rectangles)
dc.DrawEllipseList(rectangles,pens)
dc.BeginDrawing()
start = time.time()
- dc.SetPen(wxPen("BLACK", 1))
+ dc.SetPen(wx.Pen("BLACK", 1))
dc.DrawRectangleList(rectangles)
dc.DrawRectangleList(rectangles,pens)
dc.DrawRectangleList(rectangles,pens[0],brushes)
log.write("DrawTime: %s seconds with DrawRectanglesList\n" % (time.time() - start))
start = time.time()
+
for i in range(len(rectangles)):
dc.SetPen( pens[i] )
dc.SetBrush( brushes[i] )
dc.DrawRectangle(rectangles[i][0],rectangles[i][1],rectangles[i][2],rectangles[i][3])
+
dc.EndDrawing()
log.write("DrawTime: %s seconds with Python loop\n" % (time.time() - start))
dc.BeginDrawing()
start = time.time()
- dc.SetPen(wxPen("BLACK", 1))
+ dc.SetPen(wx.Pen("BLACK", 1))
dc.DrawPolygonList(polygons)
dc.DrawPolygonList(polygons,pens)
dc.DrawPolygonList(polygons,pens[0],brushes)
start = time.time()
# NOTE: you need to set BackgroundMode for the background colors to be used.
- dc.SetBackgroundMode(wxSOLID)
+ dc.SetBackgroundMode(wx.SOLID)
foreground = colors1
background = colors2
dc.DrawTextList(text, points, foreground, background)
-class TestNB(wxNotebook):
+class TestNB(wx.Notebook):
def __init__(self, parent, id, log):
- style = wxNB_BOTTOM
- if wxPlatform == "__WXMAC__":
+ style = wx.NB_BOTTOM
+
+ if wx.Platform == "__WXMAC__":
style = 0
- wxNotebook.__init__(self, parent, id, style=style)
+
+ wx.Notebook.__init__(self, parent, id, style=style)
self.log = log
+ # Initialize our various samples and add them to the notebook.
win = DrawPanel(self, TestEllipses, log)
self.AddPage(win, 'Ellipses')
win = DrawPanel(self, TestRectangles, log)
self.AddPage(win, 'Rectangles')
-
-class DrawPanel(wxPanel):
+# Class used for all the various sample pages; the mechanics are the same
+# for each one with regards to the notebook. The only difference is
+# the function we use to draw on it.
+class DrawPanel(wx.Panel):
def __init__(self, parent, drawFun, log):
- wxPanel.__init__(self, parent, -1)
- self.SetBackgroundColour(wxWHITE)
+ wx.Panel.__init__(self, parent, -1)
+ self.SetBackgroundColour(wx.WHITE)
self.log = log
self.drawFun = drawFun
- EVT_PAINT(self, self.OnPaint)
+ self.Bind(wx.EVT_PAINT, self.OnPaint)
def OnPaint(self, evt):
- dc = wxPaintDC(self)
+ dc = wx.PaintDC(self)
dc.Clear()
self.drawFun(dc,self.log)
overview = """\
-Some methods have been added to wxDC to help with optimization of
+Some methods have been added to wx.DC to help with optimization of
drawing routines. Currently they are:
<pre>
# usual wxWindows license stuff here.
# by Chris Fama, with thanks to Robin Dunn, and others on the wxPython-users
# mailing list.
+#
+# 11/22/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+# 11/25/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Looks like we have issues until the library is updated.
+# - Had to rename back to wx* naming conventions
+# - Getting unusual failures in the library itself when that is done.
+#
+
+import sys
+
+import wx
+import wx.lib.ErrorDialogs as edlg
-from wxPython.wx import *
-from wxPython.lib.ErrorDialogs import *
_debug = 0
+
ID_TEXT = 10000
ID_BUTTON_wxPyNonFatalError = 10001
ID_BUTTON_wxPyFatalError = 10002
ID_BUTTON_wxPyNonFatalErrorDialogWithTraceback = 10006
def ErrorDialogsDemoPanelFunc( parent, call_fit = True, set_sizer = True ):
- item0 = wxBoxSizer( wxVERTICAL )
+ item0 = wx.BoxSizer( wx.VERTICAL )
- item1 = wxStaticText( parent, ID_TEXT, "Please select one of the buttons below for an example using explicit errors...", wxDefaultPosition, wxDefaultSize, 0 )
- item0.AddWindow( item1, 0, wxALIGN_CENTRE|wxALL, 5 )
+ item1 = wx.StaticText(
+ parent, ID_TEXT,
+ "Please select one of the buttons below for an example using explicit errors..."
+ )
+
+ item0.AddWindow( item1, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
- item2 = wxFlexGridSizer( 0, 2, 0, 0 )
+ item2 = wx.FlexGridSizer( 0, 2, 0, 0 )
- item3 = wxButton( parent, ID_BUTTON_wxPyNonFatalError, "wxPyNonFatalError", wxDefaultPosition, wxDefaultSize, 0 )
- item2.AddWindow( item3, 0, wxALIGN_CENTRE|wxALL, 5 )
+ item3 = wx.Button( parent, ID_BUTTON_wxPyNonFatalError, "wxPyNonFatalError")
+ item2.AddWindow( item3, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
- item4 = wxButton( parent, ID_BUTTON_wxPyFatalError, "wxPyFatalError", wxDefaultPosition, wxDefaultSize, 0 )
- item2.AddWindow( item4, 0, wxALIGN_CENTRE|wxALL, 5 )
+ item4 = wx.Button( parent, ID_BUTTON_wxPyFatalError, "wxPyFatalError")
+ item2.AddWindow( item4, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
- item0.AddSizer( item2, 0, wxALIGN_CENTRE|wxALL, 5 )
+ item0.AddSizer( item2, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
- item5 = wxStaticText( parent, ID_TEXT, "Please select one of the buttons below for interpreter errors...", wxDefaultPosition, wxDefaultSize, 0 )
- item0.AddWindow( item5, 0, wxALIGN_CENTRE|wxALL, 5 )
+ item5 = wx.StaticText( parent, ID_TEXT, "Please select one of the buttons below for interpreter errors...")
+ item0.AddWindow( item5, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
- item6 = wxFlexGridSizer( 0, 2, 0, 0 )
+ item6 = wx.FlexGridSizer( 0, 2, 0, 0 )
- item7 = wxButton( parent, ID_BUTTON_wxPyFatalErrorDialog, "wxPyFatalErrorDialog", wxDefaultPosition, wxDefaultSize, 0 )
- item6.AddWindow( item7, 0, wxALIGN_CENTRE|wxALL, 5 )
+ item7 = wx.Button( parent, ID_BUTTON_wxPyFatalErrorDialog, "wxPyFatalErrorDialog")
+ item6.AddWindow( item7, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
- item8 = wxButton( parent, ID_BUTTON_wxPyNonFatalErrorDialog, "wxPyNonFatalErrorDialog", wxDefaultPosition, wxDefaultSize, 0 )
- item6.AddWindow( item8, 0, wxALIGN_CENTRE|wxALL, 5 )
+ item8 = wx.Button( parent, ID_BUTTON_wxPyNonFatalErrorDialog, "wxPyNonFatalErrorDialog")
+ item6.AddWindow( item8, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
- item9 = wxButton( parent, ID_BUTTON_wxPyFatalErrorDialogWithTraceback, "wxPyFatalErrorDialogWithTraceback", wxDefaultPosition, wxDefaultSize, 0 )
- item6.AddWindow( item9, 0, wxALIGN_CENTRE|wxALL, 5 )
+ item9 = wx.Button(
+ parent, ID_BUTTON_wxPyFatalErrorDialogWithTraceback,
+ "wxPyFatalErrorDialogWithTraceback"
+ )
+ item6.AddWindow( item9, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
- item10 = wxButton( parent, ID_BUTTON_wxPyNonFatalErrorDialogWithTraceback, "wxPyNonFatalErrorDialogWithTraceback", wxDefaultPosition, wxDefaultSize, 0 )
+ item10 = wx.Button(
+ parent, ID_BUTTON_wxPyNonFatalErrorDialogWithTraceback,
+ "wxPyNonFatalErrorDialogWithTraceback"
+ )
item10.SetDefault()
- item6.AddWindow( item10, 0, wxALIGN_CENTRE|wxALL, 5 )
+ item6.AddWindow( item10, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
- item0.AddSizer( item6, 0, wxALIGN_CENTRE|wxALL, 5 )
+ item0.AddSizer( item6, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
- item11 = wxFlexGridSizer( 0, 2, 0, 0 )
+ item11 = wx.FlexGridSizer( 0, 2, 0, 0 )
- item0.AddSizer( item11, 0, wxALIGN_CENTRE|wxALL, 5 )
+ item0.AddSizer( item11, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
if set_sizer == True:
parent.SetAutoLayout( True )
# End of generated file
-class MyPanel(wxPanel):
+class MyPanel(wx.Panel):
def __init__(self,parent=None):
- wxPanel.__init__(self,parent,-1)
+ wx.Panel.__init__(self,parent,-1)
+
args = (None, -1)
kwargs = {
'programname': "sumthing",
'mailto': "me@sumwear",
- 'whendismissed': "from wxPython.wx import * ; wxBell()"}
+ 'whendismissed': "from wxPython.wx import * ; wxBell()"
+ }
+
self.dialogs = map(apply,
- [wxPyNonFatalErrorDialogWithTraceback,
- wxPyNonFatalErrorDialog,#WithTraceback
- wxPyFatalErrorDialogWithTraceback,
- wxPyFatalErrorDialog],#WithTraceback
+ [edlg.wxPyNonFatalErrorDialogWithTraceback,
+ edlg.wxPyNonFatalErrorDialog,#WithTraceback
+ edlg.wxPyFatalErrorDialogWithTraceback,
+ edlg.wxPyFatalErrorDialog #WithTraceback
+ ],
(args,) * 4,
- (kwargs,) * 4)
- ErrorDialogsDemoPanelFunc(self)
+ (kwargs,) * 4
+ )
- EVT_BUTTON(self,
- ID_BUTTON_wxPyFatalErrorDialog,
- self.DoDialog)
- EVT_BUTTON(self,
- ID_BUTTON_wxPyNonFatalError,
- self.DoDialog)
- EVT_BUTTON(self,
- ID_BUTTON_wxPyFatalError,
- self.DoDialog)
- EVT_BUTTON(self,
- ID_BUTTON_wxPyFatalErrorDialogWithTraceback,
- self.DoDialog)
- EVT_BUTTON(self,
- ID_BUTTON_wxPyNonFatalErrorDialog,
- self.DoDialog)
- EVT_BUTTON(self,
- ID_BUTTON_wxPyNonFatalErrorDialogWithTraceback,
- self.DoDialog)
+ ErrorDialogsDemoPanelFunc(self)
+ self.Bind(wx.EVT_BUTTON, self.DoDialog, id=ID_BUTTON_wxPyFatalErrorDialog)
+ self.Bind(wx.EVT_BUTTON, self.DoDialog, id=ID_BUTTON_wxPyNonFatalError)
+ self.Bind(wx.EVT_BUTTON, self.DoDialog, id=ID_BUTTON_wxPyFatalError)
+ self.Bind(wx.EVT_BUTTON, self.DoDialog, id=ID_BUTTON_wxPyFatalErrorDialogWithTraceback)
+ self.Bind(wx.EVT_BUTTON, self.DoDialog, id=ID_BUTTON_wxPyNonFatalErrorDialog)
+ self.Bind(wx.EVT_BUTTON, self.DoDialog, id=ID_BUTTON_wxPyNonFatalErrorDialogWithTraceback)
IndexFromID = {
ID_BUTTON_wxPyFatalErrorDialog: 3,
def DoDialog(self,event):
id = event.GetId()
+
if id in [ID_BUTTON_wxPyFatalError,ID_BUTTON_wxPyNonFatalError]:
if id == ID_BUTTON_wxPyFatalError:
print "%s.DoDialog(): testing explicit wxPyFatalError..."\
% self
- wxPyFatalError(self,"Test Non-fatal error.<p>"
+ edlg.wxPyFatalError(self,"Test Non-fatal error.<p>"
"Nearly arbitrary HTML (i.e., that which is"
" understood by <B><I>wxHtmlWindow</i></b>)."
"<p><table border=\"2\"><tr><td>This</td><td>is</td></tr>"
else:
print "%s.DoDialog(): testing explicit wxPyNonFatalError..."\
% self
- wxPyNonFatalError(self,"Test Non-fatal error.<p>"
+ edlg.wxPyNonFatalError(self,"Test Non-fatal error.<p>"
"Nearly arbitrary HTML (i.e., that which is"
" understood by <B><I>wxHtmlWindow</i></b>)."
"<p><table border=\"2\"><tr><td>This</td><td>is</td></tr>"
-class MyFrame(wxFrame):
+class MyFrame(wx.Frame):
def __init__(self,parent=None):
- wxFrame.__init__(self,parent,-1,
+ wx.Frame.__init__(self,parent,-1,
"Please make a selection...",
)
- self. panel = MyPanel(self)
- EVT_CLOSE (self,self.OnCloseWindow)
+ self.panel = MyPanel(self)
+ self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
def OnCloseWindow(self,event):
self.panel.Close()
self.Destroy()
-class MyApp(wxApp):
+class MyApp(wx.App):
def OnInit(self):
frame = MyFrame()
frame.Show(True)
panel = MyPanel(nb)
return panel
-from wxPython.lib import ErrorDialogs
-ErrorDialogs._debug = 1
+edlg._debug = 1
if __name__ == "__main__":
- sys.stderr = wxPyNonWindowingErrorHandler()
+ sys.stderr = edlg.wxPyNonWindowingErrorHandler()
app = MyApp(0)
app.MainLoop()
sys.exit()
else:
- overview = ErrorDialogs.__doc__
+ overview = edlg.__doc__
# Copyright: (c) 2002 by Robb Shecter (robb@acm.org)
# Licence: wxWindows license
#---------------------------------------------------------------------------
+#
+# 11/22/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+# 11/25/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o What happened to wx.Color()?
+#
+
-from wxPython.wx import *
-from wxPython.lib.evtmgr import eventManager
+import wx
+import wx.lib.evtmgr as em
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.log = log
fsize = self.GetFont().GetPointSize()
- f1 = wxFont(fsize+0, wxSWISS, wxNORMAL, wxNORMAL)
- f2 = wxFont(fsize+2, wxSWISS, wxNORMAL, wxBOLD)
- f3 = wxFont(fsize+6, wxSWISS, wxNORMAL, wxBOLD)
+ f1 = wx.Font(fsize+0, wx.SWISS, wx.NORMAL, wx.NORMAL)
+ f2 = wx.Font(fsize+2, wx.SWISS, wx.NORMAL, wx.BOLD)
+ f3 = wx.Font(fsize+6, wx.SWISS, wx.NORMAL, wx.BOLD)
- title1 = wxStaticText(self, -1, 'EventManager')
+ title1 = wx.StaticText(self, -1, 'EventManager')
title1.SetFont(f3)
txt = """\
This demo shows (1) basic uses and features of the EventManager, as well
as (2) how it helps with a real-world task: creating independent, object-
oriented components."""
- message0 = wxStaticText(self, -1, txt)
+ message0 = wx.StaticText(self, -1, txt)
message0.SetFont(f1)
- title2 = wxStaticText(self, -1, 'Event Listeners')
+ title2 = wx.StaticText(self, -1, 'Event Listeners')
title2.SetFont(f2)
txt = """\
These objects listen to motion events from the target window, using the ability
to register one event with multiple listeners. They also register for mouse events
on themselves to implement toggle-button functionality."""
- message1 = wxStaticText(self, -1, txt)
+ message1 = wx.StaticText(self, -1, txt)
message1.SetFont(f1)
- title3 = wxStaticText(self, -1, 'Target Window')
+ title3 = wx.StaticText(self, -1, 'Target Window')
title3.SetFont(f2)
txt = """\
A passive window that's used as an event generator. Move the mouse over it to
send events to the listeners above."""
- message2 = wxStaticText(self, -1, txt)
+ message2 = wx.StaticText(self, -1, txt)
message2.SetFont(f1)
targetPanel = Tile(self, log, bgColor=wxColour(80,10,10), active=0)
buttonPanel.SetSizer(sizer)
sizer.Fit(buttonPanel)
- sizer = wxBoxSizer(wxVERTICAL)
- sizer.Add(title1, 0, wxALIGN_CENTER | wxTOP | wxBOTTOM, 6)
- sizer.Add(message0, 0, wxALIGN_CENTER | wxALL, 6)
- sizer.Add(title2, 0, wxALIGN_CENTER | wxLEFT | wxTOP | wxRIGHT, 16)
- sizer.Add(message1, 0, wxALIGN_CENTER | wxALL, 6)
- sizer.Add(buttonPanel, 0, wxEXPAND | wxLEFT | wxBOTTOM | wxRIGHT, 16)
- sizer.Add(title3, 0, wxALIGN_CENTER | wxLEFT | wxRIGHT, 16)
- sizer.Add(message2, 0, wxALIGN_CENTER | wxALL, 6)
- sizer.Add(targetPanel, 2, wxEXPAND | wxLEFT | wxBOTTOM | wxRIGHT, 16)
+ sizer = wx.BoxSizer(wx.VERTICAL)
+ sizer.Add(title1, 0, wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, 6)
+ sizer.Add(message0, 0, wx.ALIGN_CENTER | wx.ALL, 6)
+ sizer.Add(title2, 0, wx.ALIGN_CENTER | wx.LEFT | wx.TOP | wx.RIGHT, 16)
+ sizer.Add(message1, 0, wx.ALIGN_CENTER | wx.ALL, 6)
+ sizer.Add(buttonPanel, 0, wx.EXPAND | wx.LEFT | wx.BOTTOM | wx.RIGHT, 16)
+ sizer.Add(title3, 0, wx.ALIGN_CENTER | wx.LEFT | wx.RIGHT, 16)
+ sizer.Add(message2, 0, wx.ALIGN_CENTER | wx.ALL, 6)
+ sizer.Add(targetPanel, 2, wx.EXPAND | wx.LEFT | wx.BOTTOM | wx.RIGHT, 16)
self.SetAutoLayout(1)
self.SetSizer(sizer)
-class Tile(wxPanel):
+class Tile(wx.Panel):
"""
This outer class is responsible for changing
its border color in response to certain mouse
events over its contained 'InnerTile'.
"""
- normal = wxColour(150,150,150)
- active = wxColour(250,245,245)
- hover = wxColour(210,220,210)
+ normal = wx.Colour(150,150,150)
+ active = wx.Colour(250,245,245)
+ hover = wx.Colour(210,220,210)
def __init__(self, parent, log, factor=1, thingToWatch=None, bgColor=None, active=1, size=(38,38), borderWidth=3):
- wxPanel.__init__(self, parent, -1, size=size, style=wxCLIP_CHILDREN)
+ wx.Panel.__init__(self, parent, -1, size=size, style=wx.CLIP_CHILDREN)
self.tile = InnerTile(self, log, factor, thingToWatch, bgColor)
self.log = log
- sizer = wxBoxSizer(wxHORIZONTAL)
- sizer.Add(self.tile, 1, wxEXPAND | wxALL, borderWidth)
+ sizer = wx.BoxSizer(wx.HORIZONTAL)
+ sizer.Add(self.tile, 1, wx.EXPAND | wx.ALL, borderWidth)
self.SetAutoLayout(1)
self.SetSizer(sizer)
self.Layout()
if active:
# Register myself for mouse events over self.tile in order to
# create typical button/hyperlink visual effects.
- eventManager.Register(self.setHover, EVT_ENTER_WINDOW, self.tile)
- eventManager.Register(self.setNormal, EVT_LEAVE_WINDOW, self.tile)
- eventManager.Register(self.setActive, EVT_LEFT_DOWN, self.tile)
- eventManager.Register(self.setHover, EVT_LEFT_UP, self.tile)
+ em.eventManager.Register(self.setHover, wx.EVT_ENTER_WINDOW, self.tile)
+ em.eventManager.Register(self.setNormal, wx.EVT_LEAVE_WINDOW, self.tile)
+ em.eventManager.Register(self.setActive, wx.EVT_LEFT_DOWN, self.tile)
+ em.eventManager.Register(self.setHover, wx.EVT_LEFT_UP, self.tile)
def setHover(self, event):
class InnerTile(wxPanel):
- IDLE_COLOR = wxColour( 80, 10, 10)
- START_COLOR = wxColour(200, 70, 50)
- FINAL_COLOR = wxColour( 20, 80,240)
- OFF_COLOR = wxColour(185,190,185)
+ IDLE_COLOR = wx.Colour( 80, 10, 10)
+ START_COLOR = wx.Colour(200, 70, 50)
+ FINAL_COLOR = wx.Colour( 20, 80,240)
+ OFF_COLOR = wx.Colour(185,190,185)
# Some pre-computation.
DELTAS = map(lambda a,b: b-a, START_COLOR.Get(), FINAL_COLOR.Get())
START_COLOR_TUPLE = START_COLOR.Get()
events over the 'thingToWatch'.
"""
def __init__(self, parent, log, factor, thingToWatch=None, bgColor=None):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.log=log
if bgColor:
self.SetBackgroundColour(bgColor)
self.state = 0
self.toggleOnOff()
# Watch for the mouse click to enable/disable myself.
- eventManager.Register(self.toggleOnOff, EVT_LEFT_UP, self)
+ em.eventManager.Register(self.toggleOnOff, wx.EVT_LEFT_UP, self)
def toggleOnOff(self, event=None):
# Implement being on or off by registering and
# de-registering self.makeColor() from the event manager.
if self.state:
- eventManager.DeregisterListener(self.makeColor)
+ em.eventManager.DeregisterListener(self.makeColor)
else:
- eventManager.Register(self.makeColor, EVT_MOTION, self.thingToWatch)
+ em.eventManager.Register(self.makeColor, wx.EVT_MOTION, self.thingToWatch)
self.state = 1 - self.state
self.resetColor()
r = InnerTile.START_COLOR_TUPLE[0] + (InnerTile.DELTAS[0] * percent)
g = InnerTile.START_COLOR_TUPLE[1] + (InnerTile.DELTAS[1] * percent)
b = InnerTile.START_COLOR_TUPLE[2] + (InnerTile.DELTAS[2] * percent)
- self.setColor(wxColour(int(r), int(g), int(b)))
+ self.setColor(wx.Colour(int(r), int(g), int(b)))
-
-from wxPython.wx import *
-from wxPython.lib import fancytext
+# 11/5/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated to wx namespace
+#
+# 11/25/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Issues previously noted have evaporated.
+# o Hoo boy, the doc string in the lib needs fixed :-)
+#
+# 12/02/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Making the library's doc string acceptable for the overview rendered
+# it unusable in the library's own test code, so I copied it over
+# and massaged the XML into useful HTML.
+#
+
+import wx
+import wx.lib.fancytext as fancytext
#----------------------------------------------------------------------
test_str2 = '<font family="swiss" color="dark green" size="40">big green text</font>'
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent):
- wxPanel.__init__(self, parent, -1)
- EVT_PAINT(self, self.OnPaint)
-
+ wx.Panel.__init__(self, parent, -1)
+ self.Bind(wx.EVT_PAINT, self.OnPaint)
def OnPaint(self, evt):
- dc = wxPaintDC(self)
+ dc = wx.PaintDC(self)
w, h = fancytext.GetExtent(test_str, dc)
fancytext.RenderToDC(test_str, dc, 20, 20)
-overview = fancytext.__doc__.replace("<", "<")
-
+overview = \
+"""
+<html>
+<body>
+<h1>FancyText -- <i>methods for rendering XML specified text</i></h1>
+
+<p>This module exports four main methods::
+<pre>
+ def GetExtent(str, dc=None, enclose=True)
+ def GetFullExtent(str, dc=None, enclose=True)
+ def RenderToBitmap(str, background=None, enclose=True)
+ def RenderToDC(str, dc, x, y, enclose=True)
+</pre>
+
+In all cases, 'str' is an XML string. Note that start and end tags
+are only required if *enclose* is set to False. In this case the
+text should be wrapped in FancyText tags.
+
+<p>In addition, the module exports one class::
+<pre>
+ class StaticFancyText(self, window, id, text, background, ...)
+</pre>
+This class works similar to StaticText except it interprets its text
+as FancyText.
+
+<p>The text can support<sup>superscripts</sup> and <sub>subscripts</sub>, text
+in different <font size="+3">sizes</font>, <font color="blue">colors</font>,
+<i>styles</i>, <b>weights</b> and
+<font family="script">families</font>. It also supports a limited set of symbols,
+currently <times/>, <infinity/>, <angle/> as well as greek letters in both
+upper case (<Alpha/><Beta/>...<Omega/>) and lower case (<alpha/><beta/>...<omega/>).
+
+</font></font>
+The End
+</body>
+</html>
+"""
+# 11/7/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+# o Uncommented fbbhCallback in TestPanel.fbbh init. Appears to work fine.
+# Wonder why it was commented.
+# o Unrelated: TestPanel.dbb appears to cause a program error in the demo. If
+# it is commented out, everything works fine. Investigating.
+# o Bernhard has responded to query, does not plan on updating demo.
+#
+# 11/25/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o All issues, including the program error, have gone away in V2.5.
+#
+
""" Demonstrate filebrowsebutton module of the wxPython.lib Library.
14.1.2001 Bernhard Reiter <bernhard@intevation.de>
Added demo for DirBrowseButton and improved overview text.
"""
-from wxPython.wx import *
-from wxPython.lib.filebrowsebutton import FileBrowseButton, FileBrowseButtonWithHistory,DirBrowseButton
+import wx
+import wx.lib.filebrowsebutton as filebrowse
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, ID, log):
- wxPanel.__init__(self, parent, ID)
+ wx.Panel.__init__(self, parent, ID)
self.log = log
- self.fbb = FileBrowseButton(self, -1, wxPoint(20,20), wxSize(450, -1),
- changeCallback = self.fbbCallback)
- self.fbbh = FileBrowseButtonWithHistory(self, -1, wxPoint(20, 50),
- wxSize(450, -1),
- #changeCallback = self.fbbhCallback
- )
- self.dbb = DirBrowseButton(self, -1, wxPoint(20,80), wxSize(450,-1),
- changeCallback = self.dbbCallback)
+ self.fbb = filebrowse.FileBrowseButton(
+ self, -1, (20, 20), (450, -1), changeCallback = self.fbbCallback
+ )
+
+ self.fbbh = filebrowse.FileBrowseButtonWithHistory(
+ self, -1, (20, 50), (450, -1), changeCallback = self.fbbhCallback
+ )
+
+ self.dbb = filebrowse.DirBrowseButton(
+ self, -1, (20, 80), (450, -1), changeCallback = self.dbbCallback
+ )
self.fbbh.SetHistory(['You', 'can', 'put', 'some', 'file', 'names', 'here'])
self.log.write('FileBrowseButton: %s\n' % evt.GetString())
-
def fbbhCallback(self, evt):
if hasattr(self, 'fbbh'):
value = evt.GetString()
history.append(value)
self.fbbh.SetHistory(history)
+
def dbbCallback(self, evt):
self.log.write('DirBrowseButton: %s\n' % evt.GetString())
-
#----------------------------------------------------------------------
def runTest(frame, nb, log):
return win
-
#----------------------------------------------------------------------
overview = """<html><body>
</pre></small>
</body><</html>
-""" % ( FileBrowseButton.__doc__,
- FileBrowseButtonWithHistory.__doc__ ,
- str(DirBrowseButton.__doc__) )
-
-
+""" % ( filebrowse.FileBrowseButton.__doc__,
+ filebrowse.FileBrowseButtonWithHistory.__doc__ ,
+ filebrowse.DirBrowseButton.__doc__
+ )
if __name__ == '__main__':
+# 11/25/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for V2.5
+#
-from wxPython.wx import *
+import wx
-
-## Stuff to integrate FloatCanvas into wxPython Demo
+# Stuff to integrate FloatCanvas into wxPython Demo
try:
import Numeric
haveNumeric = True
http://sourceforge.net/projects/numpy
"""
def runTest(frame, nb, log):
- dlg = wxMessageDialog(frame, errorText,
- 'Sorry', wxOK | wxICON_INFORMATION)
+ dlg = wx.MessageDialog(
+ frame, errorText, 'Sorry', wx.OK | wx.ICON_INFORMATION
+ )
+
dlg.ShowModal()
dlg.Destroy()
from wxPython.lib import floatcanvas
import wxPython.lib.colourdb
- ID_ABOUT_MENU = wxNewId()
- ID_EXIT_MENU = wxNewId()
- ID_ZOOM_TO_FIT_MENU = wxNewId()
- ID_DRAWTEST_MENU = wxNewId()
- ID_LINETEST_MENU = wxNewId()
- ID_DRAWMAP_MENU = wxNewId()
- ID_DRAWMAP2_MENU = wxNewId()
- ID_CLEAR_MENU = wxNewId()
+ ID_ABOUT_MENU = wx.NewId()
+ ID_EXIT_MENU = wx.NewId()
+ ID_ZOOM_TO_FIT_MENU = wx.NewId()
+ ID_DRAWTEST_MENU = wx.NewId()
+ ID_LINETEST_MENU = wx.NewId()
+ ID_DRAWMAP_MENU = wx.NewId()
+ ID_DRAWMAP2_MENU = wx.NewId()
+ ID_CLEAR_MENU = wx.NewId()
+
colors = []
LineStyles = floatcanvas.draw_object.LineStyleList.keys()
- class DrawFrame(wxFrame):
+ class DrawFrame(wx.Frame):
"""
"""
- def __init__(self,parent, id,title,position,size):
- wxFrame.__init__(self,parent, id,title,position, size)
+ def __init__(self, parent, id, title, position, size):
+ wx.Frame.__init__(self,parent, id,title,position, size)
- ## Set up the MenuBar
+ # Set up the MenuBar
- MenuBar = wxMenuBar()
+ MenuBar = wx.MenuBar()
- file_menu = wxMenu()
+ file_menu = wx.Menu()
file_menu.Append(ID_EXIT_MENU, "&Close","Close this frame")
- EVT_MENU(self, ID_EXIT_MENU, self.OnQuit)
+ self.Bind(wx.EVT_MENU, self.OnQuit, id=ID_EXIT_MENU)
MenuBar.Append(file_menu, "&File")
- draw_menu = wxMenu()
+ draw_menu = wx.Menu()
draw_menu.Append(ID_DRAWTEST_MENU, "&Draw Test","Run a test of drawing random components")
- EVT_MENU(self, ID_DRAWTEST_MENU,self.DrawTest)
+ self.Bind(wx.EVT_MENU, self.DrawTest, id=ID_DRAWTEST_MENU)
draw_menu.Append(ID_LINETEST_MENU, "&Line Test","Run a test of drawing random lines")
- EVT_MENU(self, ID_LINETEST_MENU,self.LineTest)
+ self.Bind(wx.EVT_MENU, self.LineTest, id=ID_LINETEST_MENU)
draw_menu.Append(ID_DRAWMAP_MENU, "Draw &Map","Run a test of drawing a map")
- EVT_MENU(self, ID_DRAWMAP_MENU,self.DrawMap)
+ self.Bind(wx.EVT_MENU, self.DrawMap, id=ID_DRAWMAP_MENU)
draw_menu.Append(ID_CLEAR_MENU, "&Clear","Clear the Canvas")
- EVT_MENU(self, ID_CLEAR_MENU,self.Clear)
+ self.Bind(wx.EVT_MENU, self.Clear, id=ID_CLEAR_MENU)
MenuBar.Append(draw_menu, "&Draw")
-
-
- view_menu = wxMenu()
+
+ view_menu = wx.Menu()
view_menu.Append(ID_ZOOM_TO_FIT_MENU, "Zoom to &Fit","Zoom to fit the window")
- EVT_MENU(self, ID_ZOOM_TO_FIT_MENU,self.ZoomToFit)
+ self.Bind(wx.EVT_MENU, self.ZoomToFit, id=ID_ZOOM_TO_FIT_MENU)
MenuBar.Append(view_menu, "&View")
- help_menu = wxMenu()
+ help_menu = wx.Menu()
help_menu.Append(ID_ABOUT_MENU, "&About",
"More information About this program")
- EVT_MENU(self, ID_ABOUT_MENU, self.OnAbout)
+ self.Bind(wx.EVT_MENU, self.OnAbout, id=ID_ABOUT_MENU)
MenuBar.Append(help_menu, "&Help")
self.SetMenuBar(MenuBar)
self.CreateStatusBar()
self.SetStatusText("")
- EVT_CLOSE(self, self.OnCloseWindow)
+ self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
# Other event handlers:
- EVT_RIGHT_DOWN(self, self.RightButtonEvent)
+ self.Bind(wx.EVT_RIGHT_DOWN, self.RightButtonEvent)
# Add the Canvas
self.Canvas = floatcanvas.FloatCanvas(self,-1,(500,500),
event.Skip()
def OnAbout(self, event):
- dlg = wxMessageDialog(self, "This is a small program to demonstrate\n"
+ dlg = wx.MessageDialog(self, "This is a small program to demonstrate\n"
"the use of the FloatCanvas\n",
- "About Me", wxOK | wxICON_INFORMATION)
+ "About Me", wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
def SetMode(self,event):
for id in [ID_ZOOM_IN_BUTTON,ID_ZOOM_OUT_BUTTON,ID_MOVE_MODE_BUTTON]:
self.ToolBar.ToggleTool(id,0)
+
self.ToolBar.ToggleTool(event.GetId(),1)
+
if event.GetId() == ID_ZOOM_IN_BUTTON:
self.Canvas.SetGUIMode("ZoomIn")
+
elif event.GetId() == ID_ZOOM_OUT_BUTTON:
self.Canvas.SetGUIMode("ZoomOut")
+
elif event.GetId() == ID_MOVE_MODE_BUTTON:
self.Canvas.SetGUIMode("Move")
self.Destroy()
def DrawTest(self,event):
- wxGetApp().Yield()
+ wx.GetApp().Yield()
+
import random
import RandomArray
+
Range = (-10,10)
Canvas = self.Canvas
object_list = self.object_list
- ## Random tests of everything:
+ # Random tests of everything:
# Rectangles
for i in range(5):
self.Canvas.ZoomToBB()
def DrawMap(self,event = None):
- wxGetApp().Yield()
+ wx.GetApp().Yield()
import os, time
## Test of Actual Map Data
self.Clear()
## print "It took %f seconds to draw %i lines"%(time.clock() - start,len(linepoints) )
def LineTest(self,event = None):
- wxGetApp().Yield()
+ wx.GetApp().Yield()
import os, time
import random
Range = (-10,10)
self.Canvas.ZoomToBB()
print "It took %f seconds to draw %i lines"%(time.clock() - start,len(linepoints) )
- class DemoApp(wxApp):
+ class DemoApp(wx.App):
"""
How the demo works:
print errorText
else:
app = DemoApp(0)
+
+ import wx.lib.colourdb
+ wx.lib.colourdb.updateColourDB()
+ colors = wx.lib.colourdb.getColourList()
+
app.MainLoop()
+# 11/25/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for V2.5
+#
-from wxPython.wx import *
+import wx
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
- e = wxFontEnumerator()
+ e = wx.FontEnumerator()
e.EnumerateFacenames()
list = e.GetFacenames()
list.sort()
- s1 = wxStaticText(self, -1, "Face names:")
- self.lb1 = wxListBox(self, -1, wxDefaultPosition, (200, 250),
- list, wxLB_SINGLE)
- EVT_LISTBOX(self, self.lb1.GetId(), self.OnSelect)
+ s1 = wx.StaticText(self, -1, "Face names:")
- self.txt = wxStaticText(self, -1, "Sample text...", (285, 50))
+ self.lb1 = wx.ListBox(self, -1, wx.DefaultPosition, (200, 250),
+ list, wx.LB_SINGLE)
- row = wxBoxSizer(wxHORIZONTAL)
- row.Add(s1, 0, wxALL, 5)
- row.Add(self.lb1, 0, wxALL, 5)
- row.Add(self.txt, 0, wxALL|wxADJUST_MINSIZE, 5)
+ self.Bind(wx.EVT_LISTBOX, self.OnSelect, id=self.lb1.GetId())
- sizer = wxBoxSizer(wxVERTICAL)
- sizer.Add(row, 0, wxALL, 30)
+ self.txt = wx.StaticText(self, -1, "Sample text...", (285, 50))
+
+ row = wx.BoxSizer(wx.HORIZONTAL)
+ row.Add(s1, 0, wx.ALL, 5)
+ row.Add(self.lb1, 0, wx.ALL, 5)
+ row.Add(self.txt, 0, wx.ALL|wx.ADJUST_MINSIZE, 5)
+
+ sizer = wx.BoxSizer(wx.VERTICAL)
+ sizer.Add(row, 0, wx.ALL, 30)
self.SetSizer(sizer)
self.Layout()
self.lb1.SetSelection(0)
self.OnSelect(None)
- wxFutureCall(300, self.SetTextSize)
+ wx.FutureCall(300, self.SetTextSize)
def SetTextSize(self):
#print "OnSelect: "
face = self.lb1.GetStringSelection()
#print '\t '+face
- font = wxFont(28, wxDEFAULT, wxNORMAL, wxNORMAL, False, face)
+ font = wx.Font(28, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False, face)
#print "\t got font"
self.txt.SetLabel(face)
#print "\t set label"
## st = font.GetNativeFontInfo().ToString()
-## ni2 = wxNativeFontInfo()
+## ni2 = wx.NativeFontInfo()
## ni2.FromString(st)
-## font2 = wxFontFromNativeInfo(ni2)
+## font2 = wx.FontFromNativeInfo(ni2)
#----------------------------------------------------------------------
-
-
-
-
-
overview = """<html><body>
wxFontEnumerator enumerates either all available fonts on the system or only
the ones with given attributes - either only fixed-width (suited for use in
+# 11/6/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
-from wxPython.lib.buttons import *
+import wx
+import wx.lib.buttons as buttons
import images
-#----------------------------------------------------------------------
+#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.log = log
- sizer = wxFlexGridSizer(1, 3, 20, 20)
- b = wxButton(self, -1, "A real button")
+ sizer = wx.FlexGridSizer(1, 3, 20, 20)
+
+ # A regular button, selected as the default button
+ b = wx.Button(self, -1, "A real button")
b.SetDefault()
- EVT_BUTTON(self, b.GetId(), self.OnButton)
+ self.Bind(wx.EVT_BUTTON, self.OnButton, id=b.GetId())
sizer.Add(b)
- b = wxButton(self, -1, "non-default")
- EVT_BUTTON(self, b.GetId(), self.OnButton)
+ # Same thing, but NOT set as the default button
+ b = wx.Button(self, -1, "non-default")
+ self.Bind(wx.EVT_BUTTON, self.OnButton, id=b.GetId())
sizer.Add(b)
sizer.Add((10,10))
- b = wxGenButton(self, -1, 'Hello')
- EVT_BUTTON(self, b.GetId(), self.OnButton)
+ # Plain old text button based off GenButton()
+ b = buttons.GenButton(self, -1, 'Hello')
+ self.Bind(wx.EVT_BUTTON, self.OnButton, id=b.GetId())
sizer.Add(b)
- b = wxGenButton(self, -1, 'disabled')
- EVT_BUTTON(self, b.GetId(), self.OnButton)
+ # Plain old text button, disabled.
+ b = buttons.GenButton(self, -1, 'disabled')
+ self.Bind(wx.EVT_BUTTON, self.OnButton, id=b.GetId())
b.Enable(False)
sizer.Add(b)
- b = wxGenButton(self, -1, 'bigger')
- EVT_BUTTON(self, b.GetId(), self.OnBiggerButton)
- b.SetFont(wxFont(20, wxSWISS, wxNORMAL, wxBOLD, False))
+ # This time, we let the botton be as big as it can be.
+ # Also, this one is fancier, with custom colors and bezel size.
+ b = buttons.GenButton(self, -1, 'bigger')
+ self.Bind(wx.EVT_BUTTON, self.OnBiggerButton, id=b.GetId())
+ b.SetFont(wx.Font(20, wx.SWISS, wx.NORMAL, wx.BOLD, False))
b.SetBezelWidth(5)
###b.SetBestSize()
b.SetBackgroundColour("Navy")
- b.SetForegroundColour(wxWHITE)
+ b.SetForegroundColour(wx.WHITE)
b.SetToolTipString("This is a BIG button...")
- sizer.Add(b, flag=wxADJUST_MINSIZE) # let the sizer set best size
+ # let the sizer set best size
+ sizer.Add(b, flag=wx.ADJUST_MINSIZE)
+ # An image button
bmp = images.getTest2Bitmap()
- b = wxGenBitmapButton(self, -1, bmp)
- EVT_BUTTON(self, b.GetId(), self.OnButton)
+ b = buttons.GenBitmapButton(self, -1, bmp)
+ self.Bind(wx.EVT_BUTTON, self.OnButton, id=b.GetId())
sizer.Add(b)
+ # An image button, disabled.
bmp = images.getTest2Bitmap()
- b = wxGenBitmapButton(self, -1, bmp)
- EVT_BUTTON(self, b.GetId(), self.OnButton)
+ b = buttons.GenBitmapButton(self, -1, bmp)
+ self.Bind(wx.EVT_BUTTON, self.OnButton, id=b.GetId())
sizer.Add(b)
b.Enable(False)
- b = wxGenBitmapButton(self, -1, None)
- EVT_BUTTON(self, b.GetId(), self.OnButton)
+ # An image button, using a mask to get rid of the
+ # undesireable part of the image
+ b = buttons.GenBitmapButton(self, -1, None)
+ self.Bind(wx.EVT_BUTTON, self.OnButton, id=b.GetId())
bmp = images.getBulb1Bitmap()
- mask = wxMaskColour(bmp, wxBLUE)
+ mask = wx.MaskColour(bmp, wx.BLUE)
bmp.SetMask(mask)
b.SetBitmapLabel(bmp)
bmp = images.getBulb2Bitmap()
- mask = wxMaskColour(bmp, wxBLUE)
+ mask = wx.MaskColour(bmp, wx.BLUE)
bmp.SetMask(mask)
b.SetBitmapSelected(bmp)
b.SetBestSize()
sizer.Add(b)
- b = wxGenToggleButton(self, -1, "Toggle Button")
- EVT_BUTTON(self, b.GetId(), self.OnToggleButton)
+ # A toggle button
+ b = buttons.GenToggleButton(self, -1, "Toggle Button")
+ self.Bind(wx.EVT_BUTTON, self.OnToggleButton, id=b.GetId())
sizer.Add(b)
- b = wxGenBitmapToggleButton(self, -1, None)
- EVT_BUTTON(self, b.GetId(), self.OnToggleButton)
+ # An image toggle button
+ b = buttons.GenBitmapToggleButton(self, -1, None)
+ self.Bind(wx.EVT_BUTTON, self.OnToggleButton, id=b.GetId())
bmp = images.getBulb1Bitmap()
- mask = wxMaskColour(bmp, wxBLUE)
+ mask = wx.MaskColour(bmp, wx.BLUE)
bmp.SetMask(mask)
b.SetBitmapLabel(bmp)
bmp = images.getBulb2Bitmap()
- mask = wxMaskColour(bmp, wxBLUE)
+ mask = wx.MaskColour(bmp, wx.BLUE)
bmp.SetMask(mask)
b.SetBitmapSelected(bmp)
b.SetToggle(True)
b.SetBestSize()
sizer.Add(b)
- b = wxGenBitmapTextButton(self, -1, None, "Bitmapped Text", size = (200, 45))
- EVT_BUTTON(self, b.GetId(), self.OnButton)
+ # A bitmap button with text.
+ b = buttons.GenBitmapTextButton(self, -1, None, "Bitmapped Text", size = (200, 45))
+ self.Bind(wx.EVT_BUTTON, self.OnButton, id=b.GetId())
bmp = images.getBulb1Bitmap()
- mask = wxMaskColour(bmp, wxBLUE)
+ mask = wx.MaskColour(bmp, wx.BLUE)
bmp.SetMask(mask)
b.SetBitmapLabel(bmp)
bmp = images.getBulb2Bitmap()
- mask = wxMaskColour(bmp, wxBLUE)
+ mask = wx.MaskColour(bmp, wx.BLUE)
bmp.SetMask(mask)
b.SetBitmapSelected(bmp)
b.SetUseFocusIndicator(False)
b.SetBestSize()
sizer.Add(b)
- border = wxBoxSizer(wxVERTICAL)
- border.Add(sizer, 0, wxALL, 25)
+ border = wx.BoxSizer(wx.VERTICAL)
+ border.Add(sizer, 0, wx.ALL, 25)
self.SetSizer(border)
#----------------------------------------------------------------------
-import wxPython.lib.buttons
-overview = wxPython.lib.buttons.__doc__
-
-
+overview = buttons.__doc__
if __name__ == '__main__':
import sys,os
-
-from wxPython.wx import *
-from wxPython.grid import *
+# 11/6/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# Modified for wx namespace
+#
import string
+
+import wx
+import wx.grid as gridlib
+
#---------------------------------------------------------------------------
-class MyCellEditor(wxPyGridCellEditor):
+class MyCellEditor(gridlib.PyGridCellEditor):
"""
This is a sample GridCellEditor that shows you how to make your own custom
grid editors. All the methods that can be overridden are show here. The
def __init__(self, log):
self.log = log
self.log.write("MyCellEditor ctor\n")
- wxPyGridCellEditor.__init__(self)
+ gridlib.PyGridCellEditor.__init__(self)
def Create(self, parent, id, evtHandler):
"""
- Called to create the control, which must derive from wxControl.
+ Called to create the control, which must derive from wx.Control.
*Must Override*
"""
self.log.write("MyCellEditor: Create\n")
- self._tc = wxTextCtrl(parent, id, "")
+ self._tc = wx.TextCtrl(parent, id, "")
self._tc.SetInsertionPoint(0)
self.SetControl(self._tc)
+
if evtHandler:
self._tc.PushEventHandler(evtHandler)
"""
self.log.write("MyCellEditor: SetSize %s\n" % rect)
self._tc.SetDimensions(rect.x, rect.y, rect.width+2, rect.height+2,
- wxSIZE_ALLOW_MINUS_ONE)
+ wx.SIZE_ALLOW_MINUS_ONE)
def Show(self, show, attr):
changed = False
val = self._tc.GetValue()
+
if val != self.startValue:
changed = True
grid.GetTable().SetValue(row, col, val) # update the table
##return self.base_IsAcceptedKey(evt)
return (not (evt.ControlDown() or evt.AltDown()) and
- evt.GetKeyCode() != WXK_SHIFT)
+ evt.GetKeyCode() != wx.WXK_SHIFT)
def StartingKey(self, evt):
self.log.write("MyCellEditor: StartingKey %d\n" % evt.GetKeyCode())
key = evt.GetKeyCode()
ch = None
- if key in [WXK_NUMPAD0, WXK_NUMPAD1, WXK_NUMPAD2, WXK_NUMPAD3, WXK_NUMPAD4,
- WXK_NUMPAD5, WXK_NUMPAD6, WXK_NUMPAD7, WXK_NUMPAD8, WXK_NUMPAD9]:
- ch = ch = chr(ord('0') + key - WXK_NUMPAD0)
+ if key in [ wx.WXK_NUMPAD0, wx.WXK_NUMPAD1, wx.WXK_NUMPAD2, wx.WXK_NUMPAD3,
+ wx.WXK_NUMPAD4, wx.WXK_NUMPAD5, wx.WXK_NUMPAD6, wx.WXK_NUMPAD7,
+ wx.WXK_NUMPAD8, wx.WXK_NUMPAD9
+ ]:
+
+ ch = ch = chr(ord('0') + key - wx.WXK_NUMPAD0)
elif key < 256 and key >= 0 and chr(key) in string.printable:
ch = chr(key)
#---------------------------------------------------------------------------
-class GridEditorTest(wxGrid):
+class GridEditorTest(gridlib.Grid):
def __init__(self, parent, log):
- wxGrid.__init__(self, parent, -1)
+ gridlib.Grid.__init__(self, parent, -1)
self.log = log
self.CreateGrid(10, 3)
#self.SetDefaultEditor(MyCellEditor(self.log))
# Or we could just do it like this:
- #self.RegisterDataType(wxGRID_VALUE_STRING,
- # wxGridCellStringRenderer(),
+ #self.RegisterDataType(wx.GRID_VALUE_STRING,
+ # wx.GridCellStringRenderer(),
# MyCellEditor(self.log))
+ # )
# but for this example, we'll just set the custom editor on one cell
self.SetCellEditor(1, 0, MyCellEditor(self.log))
self.SetCellValue(1, 0, "Try to edit this box")
# and on a column
- attr = wxGridCellAttr()
+ attr = gridlib.GridCellAttr()
attr.SetEditor(MyCellEditor(self.log))
self.SetColAttr(2, attr)
self.SetCellValue(1, 2, "or any in this column")
#---------------------------------------------------------------------------
-class TestFrame(wxFrame):
+class TestFrame(wx.Frame):
def __init__(self, parent, log):
- wxFrame.__init__(self, parent, -1, "Custom Grid Cell Editor Test",
+ wx.Frame.__init__(self, parent, -1, "Custom Grid Cell Editor Test",
size=(640,480))
grid = GridEditorTest(self, log)
if __name__ == '__main__':
import sys
- app = wxPySimpleApp()
+ app = wx.PySimpleApp()
frame = TestFrame(None, sys.stdout)
frame.Show(True)
app.MainLoop()
-from wxPython.wx import *
-from wxPython.grid import *
+# 11/6/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+# o Also corrected minor bug where 'true' was being used instead of 'True'.
+# Doesn't fail for * import (I guess that is still defined in wx), but does
+# in the manner we're importing wx now.
-#---------------------------------------------------------------------------
+import wx
+import wx.grid as gridlib
-class CustomDataTable(wxPyGridTableBase):
- """
- """
+#---------------------------------------------------------------------------
+class CustomDataTable(gridlib.PyGridTableBase):
def __init__(self, log):
- wxPyGridTableBase.__init__(self)
+ gridlib.PyGridTableBase.__init__(self)
self.log = log
self.colLabels = ['ID', 'Description', 'Severity', 'Priority', 'Platform',
'Opened?', 'Fixed?', 'Tested?', 'TestFloat']
- self.dataTypes = [wxGRID_VALUE_NUMBER,
- wxGRID_VALUE_STRING,
- wxGRID_VALUE_CHOICE + ':only in a million years!,wish list,minor,normal,major,critical',
- wxGRID_VALUE_NUMBER + ':1,5',
- wxGRID_VALUE_CHOICE + ':all,MSW,GTK,other',
- wxGRID_VALUE_BOOL,
- wxGRID_VALUE_BOOL,
- wxGRID_VALUE_BOOL,
- wxGRID_VALUE_FLOAT + ':6,2',
+ self.dataTypes = [gridlib.GRID_VALUE_NUMBER,
+ gridlib.GRID_VALUE_STRING,
+ gridlib.GRID_VALUE_CHOICE + ':only in a million years!,wish list,minor,normal,major,critical',
+ gridlib.GRID_VALUE_NUMBER + ':1,5',
+ gridlib.GRID_VALUE_CHOICE + ':all,MSW,GTK,other',
+ gridlib.GRID_VALUE_BOOL,
+ gridlib.GRID_VALUE_BOOL,
+ gridlib.GRID_VALUE_BOOL,
+ gridlib.GRID_VALUE_FLOAT + ':6,2',
]
self.data = [
self.SetValue(row, col, value)
# tell the grid we've added a row
- msg = wxGridTableMessage(self, # The table
- wxGRIDTABLE_NOTIFY_ROWS_APPENDED, # what we did to it
- 1) # how many
+ msg = gridlib.GridTableMessage(self, # The table
+ gridlib.GRIDTABLE_NOTIFY_ROWS_APPENDED, # what we did to it
+ 1 # how many
+ )
self.GetView().ProcessTableMessage(msg)
-class CustTableGrid(wxGrid):
+class CustTableGrid(gridlib.Grid):
def __init__(self, parent, log):
- wxGrid.__init__(self, parent, -1)
+ gridlib.Grid.__init__(self, parent, -1)
table = CustomDataTable(log)
self.SetMargins(0,0)
self.AutoSizeColumns(False)
- EVT_GRID_CELL_LEFT_DCLICK(self, self.OnLeftDClick)
-
+ gridlib.EVT_GRID_CELL_LEFT_DCLICK(self, self.OnLeftDClick)
# I do this because I don't like the default behaviour of not starting the
#---------------------------------------------------------------------------
-class TestFrame(wxFrame):
+class TestFrame(wx.Frame):
def __init__(self, parent, log):
- wxFrame.__init__(self, parent, -1, "Custom Table, data driven Grid Demo", size=(640,480))
- p = wxPanel(self, -1, style=0)
+
+ wx.Frame.__init__(
+ self, parent, -1, "Custom Table, data driven Grid Demo", size=(640,480)
+ )
+
+ p = wx.Panel(self, -1, style=0)
grid = CustTableGrid(p, log)
- b = wxButton(p, -1, "Another Control...")
+ b = wx.Button(p, -1, "Another Control...")
b.SetDefault()
- EVT_BUTTON(self, b.GetId(), self.OnButton)
- EVT_SET_FOCUS(b, self.OnButtonFocus)
- bs = wxBoxSizer(wxVERTICAL)
- bs.Add(grid, 1, wxGROW|wxALL, 5)
+ self.Bind(wx.EVT_BUTTON, self.OnButton, b)
+ b.Bind(wx.EVT_SET_FOCUS, self.OnButtonFocus)
+ bs = wx.BoxSizer(wx.VERTICAL)
+ bs.Add(grid, 1, wx.GROW|wx.ALL, 5)
bs.Add(b)
p.SetSizer(bs)
if __name__ == '__main__':
import sys
- app = wxPySimpleApp()
+ app = wx.PySimpleApp()
frame = TestFrame(None, sys.stdout)
frame.Show(True)
app.MainLoop()
+# 11/6/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+
"""
Example showing how to make a grid a drop target for files.
"""
-from wxPython.wx import *
-from wxPython.grid import *
+import wx
+import wx.grid as gridlib
#---------------------------------------------------------------------------
# Set VIRTUAL to 1 to use a virtual grid
-
VIRTUAL = 1
+#---------------------------------------------------------------------------
-class GridFileDropTarget(wxFileDropTarget):
+class GridFileDropTarget(wx.FileDropTarget):
def __init__(self, grid):
- wxFileDropTarget.__init__(self)
+ wx.FileDropTarget.__init__(self)
self.grid = grid
def OnDropFiles(self, x, y, filenames):
-class FooTable(wxPyGridTableBase):
+class FooTable(gridlib.PyGridTableBase):
def __init__(self):
- wxPyGridTableBase.__init__(self)
+ gridlib.PyGridTableBase.__init__(self)
self.dropTargets = {(0,0):"Drag",
(1,0):"A",
(2,0):"File",
return self.dropTargets.get((row, col), "")
-
-class SimpleGrid(wxGrid):
+class SimpleGrid(gridlib.Grid):
def __init__(self, parent, log):
- wxGrid.__init__(self, parent, -1)
+ gridlib.Grid.__init__(self, parent, -1)
self.log = log
self.moveTo = None
+
if VIRTUAL:
self.table = FooTable()
self.SetTable(self.table)
if VIRTUAL:
self.table.dropTargets[row, col] = value
else:
- wxGrid.SetCellValue(self, row, col, value)
-
+ gridlib.Grid.SetCellValue(self, row, col, value)
-class TestFrame(wxFrame):
+class TestFrame(wx.Frame):
def __init__(self, parent, log):
- wxFrame.__init__(self, parent, -1, "DragAndDrop Grid", size=(640,480))
+ wx.Frame.__init__(self, parent, -1, "DragAndDrop Grid", size=(640,480))
grid = SimpleGrid(self, log)
if __name__ == '__main__':
import sys
- app = wxPySimpleApp()
+ app = wx.PySimpleApp()
frame = TestFrame(None, sys.stdout)
frame.Show(True)
app.MainLoop()
-from wxPython.wx import *
-from wxPython.grid import *
-from wxPython.lib.gridmovers import wxGridColMover, EVT_GRID_COL_MOVE
-from wxPython.lib.gridmovers import wxGridRowMover, EVT_GRID_ROW_MOVE
+# 11/6/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Modified for V2.5
+#
+# 11/25/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o wx renamer didn't appear to 'catch' all the classes in
+# wx.lib.gridmovers
+# o Event binder not working properly with wx.lib.gridmovers
+#
+
+import wx
+import wx.grid as gridlib
+import wx.lib.gridmovers as gridmovers
#---------------------------------------------------------------------------
-class CustomDataTable(wxPyGridTableBase):
- """
- """
-
+class CustomDataTable(gridlib.PyGridTableBase):
def __init__(self, log):
- wxPyGridTableBase.__init__(self)
+ gridlib.PyGridTableBase.__init__(self)
self.log = log
self.identifiers = ['id','ds','sv','pr','pl','op','fx','ts']
# Move the column
def MoveColumn(self,frm,to):
grid = self.GetView()
+
if grid:
# Move the identifiers
old = self.identifiers[frm]
del self.identifiers[frm]
+
if to > frm:
self.identifiers.insert(to-1,old)
else:
# Notify the grid
grid.BeginBatch()
- msg = wxGridTableMessage(self,wxGRIDTABLE_NOTIFY_COLS_DELETED,
- frm,1)
+ msg = gridlib.GridTableMessage(
+ self, gridlib.GRIDTABLE_NOTIFY_COLS_DELETED, frm, 1
+ )
+
grid.ProcessTableMessage(msg)
- msg = wxGridTableMessage(self,wxGRIDTABLE_NOTIFY_COLS_INSERTED,
- to,1)
+
+ msg = gridlib.GridTableMessage(
+ self, gridlib.GRIDTABLE_NOTIFY_COLS_INSERTED, to, 1
+ )
+
grid.ProcessTableMessage(msg)
grid.EndBatch()
# Move the row
def MoveRow(self,frm,to):
grid = self.GetView()
+
if grid:
# Move the rowLabels and data rows
oldLabel = self.rowLabels[frm]
oldData = self.data[frm]
del self.rowLabels[frm]
del self.data[frm]
+
if to > frm:
self.rowLabels.insert(to-1,oldLabel)
self.data.insert(to-1,oldData)
# Notify the grid
grid.BeginBatch()
- msg = wxGridTableMessage(self,wxGRIDTABLE_NOTIFY_ROWS_DELETED,
- frm,1)
+
+ msg = gridlib.GridTableMessage(
+ self, gridlib.GRIDTABLE_NOTIFY_ROWS_DELETED, frm, 1
+ )
+
grid.ProcessTableMessage(msg)
- msg = wxGridTableMessage(self,wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
- to,1)
+
+ msg = gridlib.GridTableMessage(
+ self, gridlib.GRIDTABLE_NOTIFY_ROWS_INSERTED, to, 1
+ )
+
grid.ProcessTableMessage(msg)
grid.EndBatch()
#---------------------------------------------------------------------------
-class DragableGrid(wxGrid):
+class DragableGrid(gridlib.Grid):
def __init__(self, parent, log):
- wxGrid.__init__(self, parent, -1)
+ gridlib.Grid.__init__(self, parent, -1)
table = CustomDataTable(log)
self.SetTable(table, True)
# Enable Column moving
- wxGridColMover(self)
- EVT_GRID_COL_MOVE(self,self.GetId(),self.OnColMove)
+ #>> TODO - renamer didn't get this one
+ gridmovers.wxGridColMover(self)
+ #>> TODO - Bind() not working here
+ gridmovers.EVT_GRID_COL_MOVE(self,self.GetId(),self.OnColMove)
# Enable Row moving
- wxGridRowMover(self)
- EVT_GRID_ROW_MOVE(self,self.GetId(),self.OnRowMove)
+ #>> TODO - renamer didn't get this one
+ gridmovers.wxGridRowMover(self)
+ #>> TODO - Bind() not working here
+ gridmovers.EVT_GRID_ROW_MOVE(self,self.GetId(),self.OnRowMove)
# Event method called when a column move needs to take place
def OnColMove(self,evt):
#---------------------------------------------------------------------------
-class TestFrame(wxFrame):
+class TestFrame(wx.Frame):
def __init__(self, parent, log):
- wxFrame.__init__(self, parent, -1, "Custom Table, data driven Grid Demo", size=(640,480))
+ wx.Frame.__init__(self, parent, -1, "Custom Table, data driven Grid Demo", size=(640,480))
grid = DragableGrid(self, log)
if __name__ == '__main__':
import sys
- app = wxPySimpleApp()
+ app = wx.PySimpleApp()
frame = TestFrame(None, sys.stdout)
frame.Show(True)
app.MainLoop()
-from wxPython.wx import *
-from wxPython.grid import *
+# 11/6/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+
+import wx
+import wx.grid as gridlib
#---------------------------------------------------------------------------
-class NewEnterHandlingGrid(wxGrid):
+class NewEnterHandlingGrid(gridlib.Grid):
def __init__(self, parent, log):
- wxGrid.__init__(self, parent, -1)
+ gridlib.Grid.__init__(self, parent, -1)
self.log = log
self.CreateGrid(20, 6)
self.SetColSize(0, 150)
self.SetColSize(5, 150)
- EVT_KEY_DOWN(self, self.OnKeyDown)
+ self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
def OnKeyDown(self, evt):
- if evt.KeyCode() != WXK_RETURN:
+ if evt.KeyCode() != wx.WXK_RETURN:
evt.Skip()
return
self.DisableCellEditControl()
success = self.MoveCursorRight(evt.ShiftDown())
+
if not success:
newRow = self.GetGridCursorRow() + 1
+
if newRow < self.GetTable().GetNumberRows():
self.SetGridCursor(newRow, 0)
self.MakeCellVisible(newRow, 0)
#---------------------------------------------------------------------------
-class TestFrame(wxFrame):
+class TestFrame(wx.Frame):
def __init__(self, parent, log):
- wxFrame.__init__(self, parent, -1, "Simple Grid Demo", size=(640,480))
+ wx.Frame.__init__(self, parent, -1, "Simple Grid Demo", size=(640,480))
grid = NewEnterHandlingGrid(self, log)
if __name__ == '__main__':
import sys
- app = wxPySimpleApp()
+ app = wx.PySimpleApp()
frame = TestFrame(None, sys.stdout)
frame.Show(True)
app.MainLoop()
-from wxPython.wx import *
-from wxPython.grid import *
+# 11/6/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+
+import wx
+import wx.grid as gridlib
#---------------------------------------------------------------------------
-class HugeTable(wxPyGridTableBase):
+class HugeTable(gridlib.PyGridTableBase):
"""
This is all it takes to make a custom data table to plug into a
"""
def __init__(self, log):
- wxPyGridTableBase.__init__(self)
+ gridlib.PyGridTableBase.__init__(self)
self.log = log
self.odd=wxGridCellAttr()
-class HugeTableGrid(wxGrid):
+class HugeTableGrid(gridlib.Grid):
def __init__(self, parent, log):
- wxGrid.__init__(self, parent, -1)
+ gridlib.Grid.__init__(self, parent, -1)
table = HugeTable(log)
# a reference to it and call it's Destroy method later.
self.SetTable(table, True)
- EVT_GRID_CELL_RIGHT_CLICK(self, self.OnRightDown) #added
+ self.Bind(gridlib.EVT_GRID_CELL_RIGHT_CLICK, self.OnRightDown)
- def OnRightDown(self, event): #added
+ def OnRightDown(self, event):
print "hello"
- print self.GetSelectedRows() #added
-
-
-
+ print self.GetSelectedRows()
#---------------------------------------------------------------------------
-class TestFrame(wxFrame):
+class TestFrame(wx.Frame):
def __init__(self, parent, log):
- wxFrame.__init__(self, parent, -1, "Huge (virtual) Table Demo", size=(640,480))
+ wx.Frame.__init__(self, parent, -1, "Huge (virtual) Table Demo", size=(640,480))
grid = HugeTableGrid(self, log)
grid.SetReadOnly(5,5, True)
if __name__ == '__main__':
import sys
- app = wxPySimpleApp()
+ app = wx.PySimpleApp()
frame = TestFrame(None, sys.stdout)
frame.Show(True)
app.MainLoop()
-from wxPython.wx import *
-from wxPython.grid import *
-from wxPython.lib.mixins.grid import wxGridAutoEditMixin
+# 11/6/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for V2.5
+# o The mixin features were all commented out. Is it broke? Should it even
+# be in the source? Or is it left as an exercise to the reader?
+#
+# 11/25/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Robin confirms, this is tutorial code. But be warned! It has not been
+# converted OR tested!
+#
+
+import wx
+import wx.grid as gridlib
+#import wx.lib.mixins.grid as mixins
#---------------------------------------------------------------------------
-class SimpleGrid(wxGrid): ##, wxGridAutoEditMixin):
+class SimpleGrid(gridlib.Grid): ##, mixins.GridAutoEditMixin):
def __init__(self, parent, log):
- wxGrid.__init__(self, parent, -1)
- ##wxGridAutoEditMixin.__init__(self)
+ gridlib.Grid.__init__(self, parent, -1)
+ ##mixins.GridAutoEditMixin.__init__(self)
self.log = log
self.moveTo = None
- EVT_IDLE(self, self.OnIdle)
+ self.Bind(wx.EVT_IDLE, self.OnIdle)
self.CreateGrid(25, 25) #, wxGrid.wxGridSelectRows)
##self.EnableEditing(False)
self.SetCellValue(1, 1, "Another cell")
self.SetCellValue(2, 2, "Yet another cell")
self.SetCellValue(3, 3, "This cell is read-only")
- self.SetCellFont(0, 0, wxFont(12, wxROMAN, wxITALIC, wxNORMAL))
- self.SetCellTextColour(1, 1, wxRED)
- self.SetCellBackgroundColour(2, 2, wxCYAN)
+ self.SetCellFont(0, 0, wx.Font(12, wx.ROMAN, wx.ITALIC, wx.NORMAL))
+ self.SetCellTextColour(1, 1, wx.RED)
+ self.SetCellBackgroundColour(2, 2, wx.CYAN)
self.SetReadOnly(3, 3, True)
- self.SetCellEditor(5, 0, wxGridCellNumberEditor(1,1000))
+ self.SetCellEditor(5, 0, gridlib.GridCellNumberEditor(1,1000))
self.SetCellValue(5, 0, "123")
- self.SetCellEditor(6, 0, wxGridCellFloatEditor())
+ self.SetCellEditor(6, 0, gridlib.GridCellFloatEditor())
self.SetCellValue(6, 0, "123.34")
- self.SetCellEditor(7, 0, wxGridCellNumberEditor())
+ self.SetCellEditor(7, 0, gridlib.GridCellNumberEditor())
self.SetCellValue(6, 3, "You can veto editing this cell")
# attribute objects let you keep a set of formatting values
# in one spot, and reuse them if needed
- attr = wxGridCellAttr()
- attr.SetTextColour(wxBLACK)
- attr.SetBackgroundColour(wxRED)
- attr.SetFont(wxFont(10, wxSWISS, wxNORMAL, wxBOLD))
+ attr = gridlib.GridCellAttr()
+ attr.SetTextColour(wx.BLACK)
+ attr.SetBackgroundColour(wx.RED)
+ attr.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
# you can set cell attributes for the whole row (or column)
self.SetRowAttr(5, attr)
self.SetColLabelValue(1, "column")
self.SetColLabelValue(2, "labels")
- self.SetColLabelAlignment(wxALIGN_LEFT, wxALIGN_BOTTOM)
+ self.SetColLabelAlignment(wx.ALIGN_LEFT, wx.ALIGN_BOTTOM)
#self.SetDefaultCellOverflow(False)
#r = wxGridCellAutoWrapStringRenderer()
# overflow cells
self.SetCellValue( 9, 1, "This default cell will overflow into neighboring cells, but not if you turn overflow off.");
self.SetCellSize(11, 1, 3, 3);
- self.SetCellAlignment(11, 1, wxALIGN_CENTRE, wxALIGN_CENTRE);
+ self.SetCellAlignment(11, 1, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE);
self.SetCellValue(11, 1, "This cell is set to span 3 rows and 3 columns");
- editor = wxGridCellTextEditor()
+ editor = gridlib.GridCellTextEditor()
editor.SetParameters('10')
self.SetCellEditor(0, 4, editor)
self.SetCellValue(0, 4, "Limited text")
# test all the events
- EVT_GRID_CELL_LEFT_CLICK(self, self.OnCellLeftClick)
- EVT_GRID_CELL_RIGHT_CLICK(self, self.OnCellRightClick)
- EVT_GRID_CELL_LEFT_DCLICK(self, self.OnCellLeftDClick)
- EVT_GRID_CELL_RIGHT_DCLICK(self, self.OnCellRightDClick)
+ self.Bind(gridlib.EVT_GRID_CELL_LEFT_CLICK, self.OnCellLeftClick)
+ self.Bind(gridlib.EVT_GRID_CELL_RIGHT_CLICK, self.OnCellRightClick)
+ self.Bind(gridlib.EVT_GRID_CELL_LEFT_DCLICK, self.OnCellLeftDClick)
+ self.Bind(gridlib.EVT_GRID_CELL_RIGHT_DCLICK, self.OnCellRightDClick)
- EVT_GRID_LABEL_LEFT_CLICK(self, self.OnLabelLeftClick)
- EVT_GRID_LABEL_RIGHT_CLICK(self, self.OnLabelRightClick)
- EVT_GRID_LABEL_LEFT_DCLICK(self, self.OnLabelLeftDClick)
- EVT_GRID_LABEL_RIGHT_DCLICK(self, self.OnLabelRightDClick)
+ self.Bind(gridlib.EVT_GRID_LABEL_LEFT_CLICK, self.OnLabelLeftClick)
+ self.Bind(gridlib.EVT_GRID_LABEL_RIGHT_CLICK, self.OnLabelRightClick)
+ self.Bind(gridlib.EVT_GRID_LABEL_LEFT_DCLICK, self.OnLabelLeftDClick)
+ self.Bind(gridlib.EVT_GRID_LABEL_RIGHT_DCLICK, self.OnLabelRightDClick)
- EVT_GRID_ROW_SIZE(self, self.OnRowSize)
- EVT_GRID_COL_SIZE(self, self.OnColSize)
+ self.Bind(gridlib.EVT_GRID_ROW_SIZE, self.OnRowSize)
+ self.Bind(gridlib.EVT_GRID_COL_SIZE, self.OnColSize)
- EVT_GRID_RANGE_SELECT(self, self.OnRangeSelect)
- EVT_GRID_CELL_CHANGE(self, self.OnCellChange)
- EVT_GRID_SELECT_CELL(self, self.OnSelectCell)
-
- EVT_GRID_EDITOR_SHOWN(self, self.OnEditorShown)
- EVT_GRID_EDITOR_HIDDEN(self, self.OnEditorHidden)
- EVT_GRID_EDITOR_CREATED(self, self.OnEditorCreated)
+ self.Bind(gridlib.EVT_GRID_RANGE_SELECT, self.OnRangeSelect)
+ self.Bind(gridlib.EVT_GRID_CELL_CHANGE, self.OnCellChange)
+ self.Bind(gridlib.EVT_GRID_SELECT_CELL, self.OnSelectCell)
+ self.Bind(gridlib.EVT_GRID_EDITOR_SHOWN, self.OnEditorShown)
+ self.Bind(gridlib.EVT_GRID_EDITOR_HIDDEN, self.OnEditorHidden)
+ self.Bind(gridlib.EVT_GRID_EDITOR_CREATED, self.OnEditorCreated)
def OnCellLeftClick(self, evt):
(evt.GetRow(), evt.GetCol(), evt.GetPosition()))
evt.Skip()
-
def OnRowSize(self, evt):
self.log.write("OnRowSize: row %d, %s\n" %
(evt.GetRowOrCol(), evt.GetPosition()))
# won't have any effect. Instead, set coordinates to move to in
# idle time.
value = self.GetCellValue(evt.GetRow(), evt.GetCol())
+
if value == 'no good':
self.moveTo = evt.GetRow(), evt.GetCol()
if self.moveTo != None:
self.SetGridCursor(self.moveTo[0], self.moveTo[1])
self.moveTo = None
+
evt.Skip()
# Another way to stay in a cell that has a bad value...
row = self.GetGridCursorRow()
col = self.GetGridCursorCol()
+
if self.IsCellEditControlEnabled():
self.HideCellEditControl()
self.DisableCellEditControl()
+
value = self.GetCellValue(row, col)
+
if value == 'no good 2':
return # cancels the cell selection
+
evt.Skip()
def OnEditorShown(self, evt):
if evt.GetRow() == 6 and evt.GetCol() == 3 and \
- wxMessageBox("Are you sure you wish to edit this cell?",
- "Checking", wxYES_NO) == wxNO:
+ wx.MessageBox("Are you sure you wish to edit this cell?",
+ "Checking", wx.YES_NO) == wx.NO:
evt.Veto()
return
def OnEditorHidden(self, evt):
if evt.GetRow() == 6 and evt.GetCol() == 3 and \
- wxMessageBox("Are you sure you wish to finish editing this cell?",
- "Checking", wxYES_NO) == wxNO:
+ wx.MessageBox("Are you sure you wish to finish editing this cell?",
+ "Checking", wx.YES_NO) == wx.NO:
evt.Veto()
return
#---------------------------------------------------------------------------
-class TestFrame(wxFrame):
+class TestFrame(wx.Frame):
def __init__(self, parent, log):
- wxFrame.__init__(self, parent, -1, "Simple Grid Demo", size=(640,480))
+ wx.Frame.__init__(self, parent, -1, "Simple Grid Demo", size=(640,480))
grid = SimpleGrid(self, log)
if __name__ == '__main__':
import sys
- app = wxPySimpleApp()
+ app = wx.PySimpleApp()
frame = TestFrame(None, sys.stdout)
frame.Show(True)
app.MainLoop()
-from wxPython.wx import *
-from wxPython.grid import *
+# 11/25/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for V2.5
+# o There is one wx.Size() I haven't figured out how to get rid of yet.
+#
-import random
+import random
+
+import wx
+import wx.grid as gridlib
#---------------------------------------------------------------------------
-class MyCustomRenderer(wxPyGridCellRenderer):
+class MyCustomRenderer(gridlib.PyGridCellRenderer):
def __init__(self):
- wxPyGridCellRenderer.__init__(self)
+ gridlib.PyGridCellRenderer.__init__(self)
def Draw(self, grid, attr, dc, rect, row, col, isSelected):
dc.SetBackgroundMode(wxSOLID)
dc.SetPen(wxTRANSPARENT_PEN)
dc.DrawRectangleRect(rect)
- dc.SetBackgroundMode(wxTRANSPARENT)
+ dc.SetBackgroundMode(wx.TRANSPARENT)
dc.SetFont(attr.GetFont())
text = grid.GetCellValue(row, col)
colors = ["RED", "WHITE", "SKY BLUE"]
x = rect.x + 1
y = rect.y + 1
+
for ch in text:
dc.SetTextForeground(random.choice(colors))
dc.DrawText(ch, (x, y))
text = grid.GetCellValue(row, col)
dc.SetFont(attr.GetFont())
w, h = dc.GetTextExtent(text)
- return wxSize(w, h)
+ return wx.Size(w, h)
def Clone(self):
#---------------------------------------------------------------------------
rendererDemoData = [
- ('wxGridCellStringRenderer\n(the default)', 'this is a text value', wxGridCellStringRenderer, ()),
- ('wxGridCellNumberRenderer', '12345', wxGridCellNumberRenderer, ()),
- ('wxGridCellFloatRenderer', '1234.5678', wxGridCellFloatRenderer, (6,2)),
- ('wxGridCellBoolRenderer', '1', wxGridCellBoolRenderer, ()),
+ ('GridCellStringRenderer\n(the default)', 'this is a text value', gridlib.GridCellStringRenderer, ()),
+ ('GridCellNumberRenderer', '12345', gridlib.GridCellNumberRenderer, ()),
+ ('GridCellFloatRenderer', '1234.5678', gridlib.GridCellFloatRenderer, (6,2)),
+ ('GridCellBoolRenderer', '1', gridlib.GridCellBoolRenderer, ()),
('MyCustomRenderer', 'This is my renderer', MyCustomRenderer, ()),
]
editorDemoData = [
- ('wxGridCellTextEditor\n(the default)', 'Here is some more text', wxGridCellTextEditor, ()),
- ('wxGridCellNumberEditor\nwith min,max', '101', wxGridCellNumberEditor, (5, 10005)),
- ('wxGridCellNumberEditor\nwithout bounds', '101', wxGridCellNumberEditor, ()),
- ('wxGridCellFloatEditor', '1234.5678', wxGridCellFloatEditor, ()),
- ('wxGridCellBoolEditor', '1', wxGridCellBoolEditor, ()),
- ('wxGridCellChoiceEditor', 'one', wxGridCellChoiceEditor, (['one', 'two', 'three', 'four',
+ ('GridCellTextEditor\n(the default)', 'Here is some more text', gridlib.GridCellTextEditor, ()),
+ ('GridCellNumberEditor\nwith min,max', '101', gridlib.GridCellNumberEditor, (5, 10005)),
+ ('GridCellNumberEditor\nwithout bounds', '101', gridlib.GridCellNumberEditor, ()),
+ ('GridCellFloatEditor', '1234.5678', gridlib.GridCellFloatEditor, ()),
+ ('GridCellBoolEditor', '1', gridlib.GridCellBoolEditor, ()),
+ ('GridCellChoiceEditor', 'one', gridlib.GridCellChoiceEditor, (['one', 'two', 'three', 'four',
'kick', 'Microsoft', 'out the',
'door'], False)),
]
-
comboDemoData = [
- ('wxGridCellNumberRenderer\nwxGridCellNumberEditor', '20792', wxGridCellNumberRenderer, wxGridCellNumberEditor),
- ('wxGridCellBoolRenderer\nwxGridCellBoolEditor', '1', wxGridCellBoolRenderer, wxGridCellBoolEditor),
+ ('GridCellNumberRenderer\nGridCellNumberEditor', '20792', gridlib.GridCellNumberRenderer, gridlib.GridCellNumberEditor),
+ ('GridCellBoolRenderer\nGridCellBoolEditor', '1', gridlib.GridCellBoolRenderer, gridlib.GridCellBoolEditor),
]
-class EditorsAndRenderersGrid(wxGrid):
+class EditorsAndRenderersGrid(gridlib.Grid):
def __init__(self, parent, log):
- wxGrid.__init__(self, parent, -1)
+ gridlib.Grid.__init__(self, parent, -1)
self.log = log
self.CreateGrid(25, 8)
''')
row = 2
+
for label, value, renderClass, args in rendererDemoData:
renderer = renderClass(*args)
self.SetCellValue(row, renCol, label)
row = 2
+
for label, value, editorClass, args in editorDemoData:
editor = editorClass(*args)
self.SetCellValue(row, edCol, label)
row = 18
+
for label, value, renClass, edClass in comboDemoData:
self.SetCellValue(row, renCol, label)
self.SetCellValue(row, renCol+1, value)
self.SetCellRenderer(row, renCol+1, renderer)
row = row + 2
-
font = self.GetFont()
- font.SetWeight(wxBOLD)
- attr = wxGridCellAttr()
+ font.SetWeight(wx.BOLD)
+ attr = gridlib.GridCellAttr()
attr.SetFont(font)
- attr.SetBackgroundColour(wxLIGHT_GREY)
+ attr.SetBackgroundColour(wx.LIGHT_GREY)
attr.SetReadOnly(True)
- attr.SetAlignment(wxRIGHT, -1)
+ attr.SetAlignment(wx.RIGHT, -1)
self.SetColAttr(renCol, attr)
attr.IncRef()
self.SetColAttr(edCol, attr)
self.AutoSizeColumns(True)
self.AutoSizeRows(True)
- EVT_GRID_CELL_LEFT_DCLICK(self, self.OnLeftDClick)
+ self.Bind(gridlib.EVT_GRID_CELL_LEFT_DCLICK, self.OnLeftDClick)
# I do this because I don't like the default behaviour of not starting the
#---------------------------------------------------------------------------
-class TestFrame(wxFrame):
+class TestFrame(wx.Frame):
def __init__(self, parent, log):
- wxFrame.__init__(self, parent, -1, "Editors and Renderers Demo", size=(640,480))
+ wx.Frame.__init__(self, parent, -1, "Editors and Renderers Demo", size=(640,480))
grid = EditorsAndRenderersGrid(self, log)
if __name__ == '__main__':
import sys
- app = wxPySimpleApp()
+ app = wx.PySimpleApp()
frame = TestFrame(None, sys.stdout)
frame.Show(True)
app.MainLoop()
# Date: Feb 26, 2001
# Licence: wxWindows license
#----------------------------------------------------------------------------
+#
+# 11/23/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+# 11/25/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Library has to be updated, it is using obsolete names
+# (wxPyDefaultSize, etc)
+#
-from wxPython.wx import *
-from wxPython.lib.imagebrowser import *
-import os
+import os
+import wx
+import wx.lib.imagebrowser as ib
#---------------------------------------------------------------------------
def runTest(frame, nb, log):
- dir = os.getcwd() # get working directory
- initial_dir = os.path.join(dir, 'bitmaps') # set the initial directory for the demo bitmaps
- win = ImageDialog(frame, initial_dir) # open the image browser dialog
+ # get current working directory
+ dir = os.getcwd()
+
+ # set the initial directory for the demo bitmaps
+ initial_dir = os.path.join(dir, 'bitmaps')
+
+ # open the image browser dialog
+ win = ib.ImageDialog(frame, initial_dir)
+
win.Centre()
- if win.ShowModal() == wxID_OK:
- log.WriteText("You Selected File: " + win.GetFile()) # show the selected file
+
+ if win.ShowModal() == wx.ID_OK:
+ # show the selected file
+ log.WriteText("You Selected File: " + win.GetFile())
else:
log.WriteText("You pressed Cancel\n")
+ win.Destroy()
+
#---------------------------------------------------------------------------
-
-
-
-
-
-
-
-
overview = """\
"""
-
-
-
if __name__ == '__main__':
import sys,os
import run
+# 11/6/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+# o In the lambda function at the top, removed the leading 'wx' from the
+# ID names to remove confusion with 'official' wx members.
+#
-from wxPython.wx import *
-from wxPython.lib.anchors import LayoutAnchors
+import wx
+import wx.lib.anchors as anchors
#----------------------------------------------------------------------
-
-[wxID_ANCHORSDEMOFRAMEANCHOREDPANEL, wxID_ANCHORSDEMOFRAMEHELPSTATICTEXT,
- wxID_ANCHORSDEMOFRAMEMAINPANEL, wxID_ANCHORSDEMOFRAMEBACKGROUNDPANEL,
- wxID_ANCHORSDEMOFRAMERIGHTCHECKBOX, wxID_ANCHORSDEMOFRAMEOKBUTTON,
- wxID_ANCHORSDEMOFRAMETOPCHECKBOX, wxID_ANCHORSDEMOFRAMEBOTTOMCHECKBOX,
- wxID_ANCHORSDEMOFRAME, wxID_ANCHORSDEMOFRAMELEFTCHECKBOX,
- ] = map(lambda _init_ctrls: wxNewId(), range(10))
-
-class AnchorsDemoFrame(wxFrame):
+# Nifty little trick here; apply wx.NewId() to generate a series of
+# IDs used later on in the app.
+
+[ ID_ANCHORSDEMOFRAMEANCHOREDPANEL,
+ ID_ANCHORSDEMOFRAMEHELPSTATICTEXT,
+ ID_ANCHORSDEMOFRAMEMAINPANEL,
+ ID_ANCHORSDEMOFRAMEBACKGROUNDPANEL,
+ ID_ANCHORSDEMOFRAMERIGHTCHECKBOX,
+ ID_ANCHORSDEMOFRAMEOKBUTTON,
+ ID_ANCHORSDEMOFRAMETOPCHECKBOX,
+ ID_ANCHORSDEMOFRAMEBOTTOMCHECKBOX,
+ ID_ANCHORSDEMOFRAME,
+ ID_ANCHORSDEMOFRAMELEFTCHECKBOX,
+ ] = map(lambda _init_ctrls: wx.NewId(), range(10))
+
+# A small note here: while only certain parts of this frame are actually demonstrating
+# the capabilities of the LayoutAnchors feature, all the controls are within the same
+# frame; therefore, all controls and windows within the frame must use LayoutAnchors.
+# You can't mix LayoutAnchors and sizers.
+class AnchorsDemoFrame(wx.Frame):
def _init_utils(self):
pass
def _init_ctrls(self, prnt):
- wxFrame.__init__(self, size = wxSize(328, 187), id = wxID_ANCHORSDEMOFRAME, title = 'LayoutAnchors Demonstration', parent = prnt, name = 'AnchorsDemoFrame', style = wxDEFAULT_FRAME_STYLE | wxCLIP_CHILDREN, pos = wxPoint(261, 123))
- self._init_utils()
-
- self.mainPanel = wxPanel(size = wxSize(320, 160), parent = self, id = wxID_ANCHORSDEMOFRAMEMAINPANEL, name = 'panel1', style = wxTAB_TRAVERSAL | wxCLIP_CHILDREN, pos = wxPoint(0, 0))
- self.mainPanel.SetAutoLayout(True)
-
- self.okButton = wxButton(label = 'OK', id = wxID_ANCHORSDEMOFRAMEOKBUTTON, parent = self.mainPanel, name = 'okButton', size = wxSize(72, 24), style = 0, pos = wxPoint(240, 128))
- self.okButton.SetConstraints(LayoutAnchors(self.okButton, False, False, True, True))
- EVT_BUTTON(self.okButton, wxID_ANCHORSDEMOFRAMEOKBUTTON, self.OnOkButtonButton)
-
- self.backgroundPanel = wxPanel(size = wxSize(304, 80), parent = self.mainPanel, id = wxID_ANCHORSDEMOFRAMEBACKGROUNDPANEL, name = 'backgroundPanel', style = wxSIMPLE_BORDER | wxCLIP_CHILDREN, pos = wxPoint(8, 40))
- self.backgroundPanel.SetBackgroundColour(wxColour(255, 255, 255))
- self.backgroundPanel.SetConstraints(LayoutAnchors(self.backgroundPanel, True, True, True, True))
-
- self.anchoredPanel = wxPanel(size = wxSize(88, 48), id = wxID_ANCHORSDEMOFRAMEANCHOREDPANEL, parent = self.backgroundPanel, name = 'anchoredPanel', style = wxSIMPLE_BORDER, pos = wxPoint(104, 16))
- self.anchoredPanel.SetBackgroundColour(wxColour(0, 0, 222))
- self.anchoredPanel.SetConstraints(LayoutAnchors(self.anchoredPanel, False, False, False, False))
-
- self.leftCheckBox = wxCheckBox(label = 'Left', id = wxID_ANCHORSDEMOFRAMELEFTCHECKBOX, parent = self.mainPanel, name = 'leftCheckBox', size = wxSize(40, 16), style = 0, pos = wxPoint(8, 8))
- self.leftCheckBox.SetConstraints(LayoutAnchors(self.leftCheckBox, False, True, False, False))
- EVT_CHECKBOX(self.leftCheckBox, wxID_ANCHORSDEMOFRAMELEFTCHECKBOX, self.OnCheckboxCheckbox)
+ wx.Frame.__init__(
+ self, size=(328, 187), id=ID_ANCHORSDEMOFRAME,
+ title='LayoutAnchors Demonstration', parent=prnt,
+ name='AnchorsDemoFrame',
+ style = wx.DEFAULT_FRAME_STYLE | wx.CLIP_CHILDREN, pos=(261, 123)
+ )
- self.topCheckBox = wxCheckBox(label = 'Top', id = wxID_ANCHORSDEMOFRAMETOPCHECKBOX, parent = self.mainPanel, name = 'topCheckBox', size = wxSize(40, 16), style = 0, pos = wxPoint(88, 8))
- self.topCheckBox.SetConstraints(LayoutAnchors(self.topCheckBox, False, True, False, False))
- EVT_CHECKBOX(self.topCheckBox, wxID_ANCHORSDEMOFRAMETOPCHECKBOX, self.OnCheckboxCheckbox)
+ self._init_utils()
- self.rightCheckBox = wxCheckBox(label = 'Right', id = wxID_ANCHORSDEMOFRAMERIGHTCHECKBOX, parent = self.mainPanel, name = 'rightCheckBox', size = wxSize(48, 16), style = 0, pos = wxPoint(168, 8))
- self.rightCheckBox.SetConstraints(LayoutAnchors(self.rightCheckBox, False, True, False, False))
- EVT_CHECKBOX(self.rightCheckBox, wxID_ANCHORSDEMOFRAMERIGHTCHECKBOX, self.OnCheckboxCheckbox)
+ self.mainPanel = wx.Panel(
+ size=(320, 160), parent=self,
+ id=ID_ANCHORSDEMOFRAMEMAINPANEL, name='panel1',
+ style=wx.TAB_TRAVERSAL | wx.CLIP_CHILDREN,
+ pos=(0, 0)
+ )
- self.bottomCheckBox = wxCheckBox(label = 'Bottom', id = wxID_ANCHORSDEMOFRAMEBOTTOMCHECKBOX, parent = self.mainPanel, name = 'bottomCheckBox', size = wxSize(56, 16), style = 0, pos = wxPoint(248, 8))
- self.bottomCheckBox.SetConstraints(LayoutAnchors(self.bottomCheckBox, False, True, False, False))
- EVT_CHECKBOX(self.bottomCheckBox, wxID_ANCHORSDEMOFRAMEBOTTOMCHECKBOX, self.OnCheckboxCheckbox)
+ self.mainPanel.SetAutoLayout(True)
- self.helpStaticText = wxStaticText(label = 'Select anchor options above, then resize window to see the effect', id = wxID_ANCHORSDEMOFRAMEHELPSTATICTEXT, parent = self.mainPanel, name = 'helpStaticText', size = wxSize(224, 24), style = wxST_NO_AUTORESIZE, pos = wxPoint(8, 128))
- self.helpStaticText.SetConstraints(LayoutAnchors(self.helpStaticText, True, False, True, True))
+ self.okButton = wx.Button(
+ label='OK', id=ID_ANCHORSDEMOFRAMEOKBUTTON,
+ parent=self.mainPanel, name='okButton',
+ size=(72, 24), style=0, pos=(240, 128)
+ )
+
+ self.okButton.SetConstraints(
+ anchors.LayoutAnchors(self.okButton, False, False, True, True)
+ )
+
+ self.Bind(
+ wx.EVT_BUTTON, self.OnOkButtonButton, id=ID_ANCHORSDEMOFRAMEOKBUTTON
+ )
+
+ self.backgroundPanel = wx.Panel(
+ size=(304, 80), parent=self.mainPanel,
+ id=ID_ANCHORSDEMOFRAMEBACKGROUNDPANEL,
+ name='backgroundPanel',
+ style=wx.SIMPLE_BORDER | wx.CLIP_CHILDREN,
+ pos = (8, 40)
+ )
+
+ self.backgroundPanel.SetBackgroundColour(wx.Colour(255, 255, 255))
+ self.backgroundPanel.SetConstraints(
+ anchors.LayoutAnchors(self.backgroundPanel, True, True, True, True)
+ )
+
+ self.anchoredPanel = wx.Panel(
+ size=(88, 48), id=ID_ANCHORSDEMOFRAMEANCHOREDPANEL,
+ parent=self.backgroundPanel, name='anchoredPanel',
+ style=wx.SIMPLE_BORDER, pos=(104, 16)
+ )
+
+ self.anchoredPanel.SetBackgroundColour(wx.Colour(0, 0, 222))
+ self.anchoredPanel.SetConstraints(
+ anchors.LayoutAnchors(self.anchoredPanel, False, False, False, False)
+ )
+
+ self.leftCheckBox = wx.CheckBox(
+ label='Left', id=ID_ANCHORSDEMOFRAMELEFTCHECKBOX,
+ parent=self.mainPanel, name='leftCheckBox',
+ size=(40, 16), style=0, pos=(8, 8)
+ )
+
+ self.leftCheckBox.SetConstraints(
+ anchors.LayoutAnchors(self.leftCheckBox, False, True, False, False)
+ )
+
+ self.Bind(
+ wx.EVT_CHECKBOX, self.OnCheckboxCheckbox, source=self.leftCheckBox,
+ id=ID_ANCHORSDEMOFRAMELEFTCHECKBOX
+ )
+
+ self.topCheckBox = wx.CheckBox(
+ label='Top', id=ID_ANCHORSDEMOFRAMETOPCHECKBOX,
+ parent=self.mainPanel, name='topCheckBox',
+ size=(40, 16), style=0, pos=(88, 8)
+ )
+
+ self.topCheckBox.SetConstraints(
+ anchors.LayoutAnchors(self.topCheckBox, False, True, False, False)
+ )
+
+ self.Bind(
+ wx.EVT_CHECKBOX, self.OnCheckboxCheckbox, source=self.topCheckBox,
+ id=ID_ANCHORSDEMOFRAMETOPCHECKBOX
+ )
+
+ self.rightCheckBox = wx.CheckBox(
+ label='Right', id=ID_ANCHORSDEMOFRAMERIGHTCHECKBOX,
+ parent=self.mainPanel, name='rightCheckBox',
+ size=(48, 16), style=0, pos=(168, 8)
+ )
+
+ self.rightCheckBox.SetConstraints(
+ anchors.LayoutAnchors(self.rightCheckBox, False, True, False, False)
+ )
+
+ self.Bind(
+ wx.EVT_CHECKBOX, self.OnCheckboxCheckbox, source=self.rightCheckBox,
+ id=ID_ANCHORSDEMOFRAMERIGHTCHECKBOX
+ )
+
+ self.bottomCheckBox = wx.CheckBox(
+ label='Bottom', id=ID_ANCHORSDEMOFRAMEBOTTOMCHECKBOX,
+ parent=self.mainPanel, name='bottomCheckBox',
+ size=(56, 16), style=0, pos=(248, 8)
+ )
+
+ self.bottomCheckBox.SetConstraints(
+ anchors.LayoutAnchors(self.bottomCheckBox, False, True, False, False)
+ )
+
+ self.Bind(
+ wx.EVT_CHECKBOX, self.OnCheckboxCheckbox, source=self.bottomCheckBox,
+ id=ID_ANCHORSDEMOFRAMEBOTTOMCHECKBOX
+ )
+
+ self.helpStaticText = wx.StaticText(
+ label='Select anchor options above, then resize window to see the effect',
+ id=ID_ANCHORSDEMOFRAMEHELPSTATICTEXT,
+ parent=self.mainPanel, name='helpStaticText',
+ size=(224, 24), style=wx.ST_NO_AUTORESIZE,
+ pos=(8, 128)
+ )
+
+ self.helpStaticText.SetConstraints(
+ anchors.LayoutAnchors(self.helpStaticText, True, False, True, True)
+ )
def __init__(self, parent):
self._init_ctrls(parent)
+ # Based on the values of the above checkboxes, we will adjust the layout constraints
+ # on the sample window whenever one of the checkboxes changes state.
def OnCheckboxCheckbox(self, event):
self.anchoredPanel.SetConstraints(
- LayoutAnchors(self.anchoredPanel,
+ anchors.LayoutAnchors(self.anchoredPanel,
self.leftCheckBox.GetValue(), self.topCheckBox.GetValue(),
- self.rightCheckBox.GetValue(), self.bottomCheckBox.GetValue()) )
+ self.rightCheckBox.GetValue(), self.bottomCheckBox.GetValue()
+ )
+ )
def OnOkButtonButton(self, event):
self.Close()
#----------------------------------------------------------------------
-
-
overview = """<html><body>
<h2>LayoutAnchors</h2>
A class that implements Delphi's Anchors with wxLayoutConstraints.
-
-
-
-
if __name__ == '__main__':
import sys,os
import run
+# 11/12/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+# o Controls now use dynamic IDs instead of hardcoded IDs.
+#
-from wxPython.wx import *
-from wxPython.lib.layoutf import Layoutf
+import wx
+import wx.lib.layoutf as layoutf
#---------------------------------------------------------------------------
-class TestLayoutf(wxPanel):
+ID_Button = wx.NewId()
+
+#---------------------------------------------------------------------------
+
+class TestLayoutf(wx.Panel):
def __init__(self, parent):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.SetAutoLayout(True)
- EVT_BUTTON(self, 100, self.OnButton)
+ self.Bind(EVT_BUTTON, self.OnButton, id=ID_Button)
- self.panelA = wxWindow(self, -1, style=wxSIMPLE_BORDER)
- self.panelA.SetBackgroundColour(wxBLUE)
- self.panelA.SetConstraints(Layoutf('t=t10#1;l=l10#1;b=b10#1;r%r50#1',(self,)))
+ self.panelA = wx.Window(self, -1, style=wx.SIMPLE_BORDER)
+ self.panelA.SetBackgroundColour(wx.BLUE)
+ self.panelA.SetConstraints(
+ layoutf.Layoutf('t=t10#1;l=l10#1;b=b10#1;r%r50#1',(self,))
+ )
- self.panelB = wxWindow(self, -1, style=wxSIMPLE_BORDER)
- self.panelB.SetBackgroundColour(wxRED)
- self.panelB.SetConstraints(Layoutf('t=t10#1;r=r10#1;b%b30#1;l>10#2', (self,self.panelA)))
+ self.panelB = wx.Window(self, -1, style=wx.SIMPLE_BORDER)
+ self.panelB.SetBackgroundColour(wx.RED)
+ self.panelB.SetConstraints(
+ layoutf.Layoutf('t=t10#1;r=r10#1;b%b30#1;l>10#2', (self,self.panelA))
+ )
- self.panelC = wxWindow(self, -1, style=wxSIMPLE_BORDER)
- self.panelC.SetBackgroundColour(wxWHITE)
- self.panelC.SetConstraints(Layoutf('t_10#3;r=r10#1;b=b10#1;l>10#2', (self,self.panelA,self.panelB)))
+ self.panelC = wx.Window(self, -1, style=wx.SIMPLE_BORDER)
+ self.panelC.SetBackgroundColour(wx.WHITE)
+ self.panelC.SetConstraints(
+ layoutf.Layoutf('t_10#3;r=r10#1;b=b10#1;l>10#2', (self,self.panelA,self.panelB))
+ )
- b = wxButton(self.panelA, 100, ' Panel A ')
- b.SetConstraints(Layoutf('X=X#1;Y=Y#1;h*;w%w50#1', (self.panelA,)))
+ b = wx.Button(self.panelA, ID_Button, ' Panel A ')
+ b.SetConstraints(layoutf.Layoutf('X=X#1;Y=Y#1;h*;w%w50#1', (self.panelA,)))
- b = wxButton(self.panelB, 100, ' Panel B ')
- b.SetConstraints(Layoutf('t=t2#1;r=r4#1;h*;w*', (self.panelB,)))
+ b = wx.Button(self.panelB, ID_Button, ' Panel B ')
+ b.SetConstraints(layoutf.Layoutf('t=t2#1;r=r4#1;h*;w*', (self.panelB,)))
- self.panelD = wxWindow(self.panelC, -1, style=wxSIMPLE_BORDER)
- self.panelD.SetBackgroundColour(wxGREEN)
- self.panelD.SetConstraints(Layoutf('b%h50#1;r%w50#1;h=h#2;w=w#2', (self.panelC, b)))
+ self.panelD = wx.Window(self.panelC, -1, style=wx.SIMPLE_BORDER)
+ self.panelD.SetBackgroundColour(wx.GREEN)
+ self.panelD.SetConstraints(
+ layoutf.Layoutf('b%h50#1;r%w50#1;h=h#2;w=w#2', (self.panelC, b))
+ )
- b = wxButton(self.panelC, 100, ' Panel C ')
- b.SetConstraints(Layoutf('t_#1;l>#1;h*;w*', (self.panelD,)))
+ b = wx.Button(self.panelC, ID_Button, ' Panel C ')
+ b.SetConstraints(layoutf.Layoutf('t_#1;l>#1;h*;w*', (self.panelD,)))
- wxStaticText(self.panelD, -1, "Panel D", wxPoint(4, 4)).SetBackgroundColour(wxGREEN)
+ wx.StaticText(self.panelD, -1, "Panel D", (4, 4)).SetBackgroundColour(wx.GREEN)
def OnButton(self, event):
- wxBell()
+ wx.Bell()
#---------------------------------------------------------------------------
-
-
-
-
-
-
-
-
-overview = Layoutf.__doc__
-
-
-
+overview = layoutf.Layoutf.__doc__
if __name__ == '__main__':
import sys,os
#!/usr/bin/env python
-from wxPython.wx import *
-from wxScrolledWindow import MyCanvas
+# 11/12/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+# o Replaced hardcoded menu IDs with dynamic IDs
+#
+
+import wx
+
+# Importing wxScrolledWindow demo to make use of the MyCanvas
+# class defined within.
+import wxScrolledWindow
+import images
-import images
SHOW_BACKGROUND = 1
+#----------------------------------------------------------------------
+ID_New = wx.NewId()
+ID_Exit = wx.NewId()
#----------------------------------------------------------------------
-class MyParentFrame(wxMDIParentFrame):
+class MyParentFrame(wx.MDIParentFrame):
def __init__(self):
- wxMDIParentFrame.__init__(self, None, -1, "MDI Parent", size=(600,400))
+ wx.MDIParentFrame.__init__(self, None, -1, "MDI Parent", size=(600,400))
self.winCount = 0
- menu = wxMenu()
- menu.Append(5000, "&New Window")
+ menu = wx.Menu()
+ menu.Append(ID_New, "&New Window")
menu.AppendSeparator()
- menu.Append(5001, "E&xit")
+ menu.Append(ID_Exit, "E&xit")
- menubar = wxMenuBar()
+ menubar = wx.MenuBar()
menubar.Append(menu, "&File")
self.SetMenuBar(menubar)
self.CreateStatusBar()
- EVT_MENU(self, 5000, self.OnNewWindow)
- EVT_MENU(self, 5001, self.OnExit)
+ self.Bind(wx.EVT_MENU, self.OnNewWindow, id=ID_New)
+ self.Bind(wx.EVT_MENU, self.OnExit, id=ID_Exit)
if SHOW_BACKGROUND:
self.bg_bmp = images.getGridBGBitmap()
- EVT_ERASE_BACKGROUND(self.GetClientWindow(), self.OnEraseBackground)
+ self.GetClientWindow().Bind(
+ wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground
+ )
def OnExit(self, evt):
def OnNewWindow(self, evt):
self.winCount = self.winCount + 1
- win = wxMDIChildFrame(self, -1, "Child Window: %d" % self.winCount)
- canvas = MyCanvas(win)
+ win = wx.MDIChildFrame(self, -1, "Child Window: %d" % self.winCount)
+ canvas = wxScrolledWindow.MyCanvas(win)
win.Show(True)
def OnEraseBackground(self, evt):
dc = evt.GetDC()
+
if not dc:
- dc = wxClientDC(self.GetClientWindow())
+ dc = wx.ClientDC(self.GetClientWindow())
# tile the background bitmap
sz = self.GetClientSize()
w = self.bg_bmp.GetWidth()
h = self.bg_bmp.GetHeight()
x = 0
+
while x < sz.width:
y = 0
+
while y < sz.height:
dc.DrawBitmap(self.bg_bmp, (x, y))
y = y + h
+
x = x + w
#----------------------------------------------------------------------
if __name__ == '__main__':
- class MyApp(wxApp):
+ class MyApp(wx.App):
def OnInit(self):
- wxInitAllImageHandlers()
+ wx.InitAllImageHandlers()
frame = MyParentFrame()
frame.Show(True)
self.SetTopWindow(frame)
return True
- app = MyApp(0)
+ app = MyApp(False)
app.MainLoop()
#!/usr/bin/env python
-from wxPython.wx import *
-from wxScrolledWindow import MyCanvas
+# 11/6/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+
+import wx
+
+import wxScrolledWindow
#----------------------------------------------------------------------
+# There are better ways to do IDs, but this demo requires that the window
+# IDs be in a specific range. There are better ways to do that, too, but
+# this will do for purposes of this demo.
-class MyParentFrame(wxMDIParentFrame):
- ID_WINDOW_TOP = 5100
- ID_WINDOW_LEFT1 = 5101
- ID_WINDOW_LEFT2 = 5102
- ID_WINDOW_BOTTOM = 5103
+ID_Menu_New = 5004
+ID_Menu_Exit = 5005
+ID_WINDOW_TOP = 5000
+ID_WINDOW_LEFT1 = 5001
+ID_WINDOW_LEFT2 = 5002
+ID_WINDOW_BOTTOM = 5003
+
+#----------------------------------------------------------------------
+
+class MyParentFrame(wx.MDIParentFrame):
def __init__(self):
- wxMDIParentFrame.__init__(self, None, -1, "MDI Parent", size=(600,400),
- style = wxDEFAULT_FRAME_STYLE | wxHSCROLL | wxVSCROLL)
+ wx.MDIParentFrame.__init__(
+ self, None, -1, "MDI Parent", size=(600,400),
+ style = wx.DEFAULT_FRAME_STYLE | wx.HSCROLL | wx.VSCROLL
+ )
self.winCount = 0
- menu = wxMenu()
- menu.Append(5000, "&New Window")
+ menu = wx.Menu()
+ menu.Append(ID_Menu_New, "&New Window")
menu.AppendSeparator()
- menu.Append(5001, "E&xit")
+ menu.Append(ID_Menu_Exit, "E&xit")
- menubar = wxMenuBar()
+ menubar = wx.MenuBar()
menubar.Append(menu, "&File")
self.SetMenuBar(menubar)
#self.CreateStatusBar()
- EVT_MENU(self, 5000, self.OnNewWindow)
- EVT_MENU(self, 5001, self.OnExit)
+ self.Bind(wx.EVT_MENU, self.OnNewWindow, id=ID_Menu_New)
+ self.Bind(wx.EVT_MENU, self.OnExit, id=ID_Menu_Exit)
+ self.Bind(
+ wx.EVT_SASH_DRAGGED_RANGE, self.OnSashDrag, id=ID_WINDOW_TOP,
+ id2=ID_WINDOW_BOTTOM
+ )
- EVT_SASH_DRAGGED_RANGE(self,
- self.ID_WINDOW_TOP, self.ID_WINDOW_BOTTOM,
- self.OnSashDrag)
- EVT_SIZE(self, self.OnSize)
+ self.Bind(wx.EVT_SIZE, self.OnSize)
# Create some layout windows
# A window like a toolbar
- win = wxSashLayoutWindow(self, self.ID_WINDOW_TOP, style = wxNO_BORDER|wxSW_3D)
+ win = wx.SashLayoutWindow(self, ID_WINDOW_TOP, style=wx.NO_BORDER|wx.SW_3D)
win.SetDefaultSize((1000, 30))
- win.SetOrientation(wxLAYOUT_HORIZONTAL)
- win.SetAlignment(wxLAYOUT_TOP)
- win.SetBackgroundColour(wxColour(255, 0, 0))
- win.SetSashVisible(wxSASH_BOTTOM, True)
+ win.SetOrientation(wx.LAYOUT_HORIZONTAL)
+ win.SetAlignment(wx.LAYOUT_TOP)
+ win.SetBackgroundColour(wx.Colour(255, 0, 0))
+ win.SetSashVisible(wx.SASH_BOTTOM, True)
self.topWindow = win
# A window like a statusbar
- win = wxSashLayoutWindow(self, self.ID_WINDOW_BOTTOM, style = wxNO_BORDER|wxSW_3D)
+ win = wx.SashLayoutWindow(self, ID_WINDOW_BOTTOM, style=wx.NO_BORDER|wx.SW_3D)
win.SetDefaultSize((1000, 30))
- win.SetOrientation(wxLAYOUT_HORIZONTAL)
- win.SetAlignment(wxLAYOUT_BOTTOM)
- win.SetBackgroundColour(wxColour(0, 0, 255))
- win.SetSashVisible(wxSASH_TOP, True)
+ win.SetOrientation(wx.LAYOUT_HORIZONTAL)
+ win.SetAlignment(wx.LAYOUT_BOTTOM)
+ win.SetBackgroundColour(wx.Colour(0, 0, 255))
+ win.SetSashVisible(wx.SASH_TOP, True)
self.bottomWindow = win
# A window to the left of the client window
- win = wxSashLayoutWindow(self, self.ID_WINDOW_LEFT1, style = wxNO_BORDER|wxSW_3D)
+ win = wx.SashLayoutWindow(self, ID_WINDOW_LEFT1, style=wx.NO_BORDER|wx.SW_3D)
win.SetDefaultSize((120, 1000))
- win.SetOrientation(wxLAYOUT_VERTICAL)
- win.SetAlignment(wxLAYOUT_LEFT)
- win.SetBackgroundColour(wxColour(0, 255, 0))
- win.SetSashVisible(wxSASH_RIGHT, True)
+ win.SetOrientation(wx.LAYOUT_VERTICAL)
+ win.SetAlignment(wx.LAYOUT_LEFT)
+ win.SetBackgroundColour(wx.Colour(0, 255, 0))
+ win.SetSashVisible(wx.SASH_RIGHT, True)
win.SetExtraBorderSize(10)
- textWindow = wxTextCtrl(win, -1, "", wxDefaultPosition, wxDefaultSize,
- wxTE_MULTILINE|wxSUNKEN_BORDER)
+ textWindow = wx.TextCtrl(win, -1, "", style=wx.TE_MULTILINE|wx.SUNKEN_BORDER)
textWindow.SetValue("A sub window")
self.leftWindow1 = win
# Another window to the left of the client window
- win = wxSashLayoutWindow(self, self.ID_WINDOW_LEFT2, style = wxNO_BORDER|wxSW_3D)
+ win = wx.SashLayoutWindow(self, ID_WINDOW_LEFT2, style=wx.NO_BORDER|wx.SW_3D)
win.SetDefaultSize((120, 1000))
- win.SetOrientation(wxLAYOUT_VERTICAL)
- win.SetAlignment(wxLAYOUT_LEFT)
- win.SetBackgroundColour(wxColour(0, 255, 255))
- win.SetSashVisible(wxSASH_RIGHT, True)
+ win.SetOrientation(wx.LAYOUT_VERTICAL)
+ win.SetAlignment(wx.LAYOUT_LEFT)
+ win.SetBackgroundColour(wx.Colour(0, 255, 255))
+ win.SetSashVisible(wx.SASH_RIGHT, True)
self.leftWindow2 = win
def OnSashDrag(self, event):
- if event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE:
+ if event.GetDragStatus() == wx.SASH_STATUS_OUT_OF_RANGE:
return
eID = event.GetId()
- if eID == self.ID_WINDOW_TOP:
- self.topWindow.SetDefaultSize(wxSize(1000, event.GetDragRect().height))
-
- elif eID == self.ID_WINDOW_LEFT1:
- self.leftWindow1.SetDefaultSize(wxSize(event.GetDragRect().width, 1000))
+
+ if eID == ID_WINDOW_TOP:
+ self.topWindow.SetDefaultSize((1000, event.GetDragRect().height))
+ elif eID == ID_WINDOW_LEFT1:
+ self.leftWindow1.SetDefaultSize((event.GetDragRect().width, 1000))
- elif eID == self.ID_WINDOW_LEFT2:
- self.leftWindow2.SetDefaultSize(wxSize(event.GetDragRect().width, 1000))
+ elif eID == ID_WINDOW_LEFT2:
+ self.leftWindow2.SetDefaultSize((event.GetDragRect().width, 1000))
- elif eID == self.ID_WINDOW_BOTTOM:
- self.bottomWindow.SetDefaultSize(wxSize(1000, event.GetDragRect().height))
+ elif eID == ID_WINDOW_BOTTOM:
+ self.bottomWindow.SetDefaultSize((1000, event.GetDragRect().height))
- wxLayoutAlgorithm().LayoutMDIFrame(self)
+ wx.LayoutAlgorithm().LayoutMDIFrame(self)
self.GetClientWindow().Refresh()
def OnSize(self, event):
- wxLayoutAlgorithm().LayoutMDIFrame(self)
+ wx.LayoutAlgorithm().LayoutMDIFrame(self)
def OnExit(self, evt):
def OnNewWindow(self, evt):
self.winCount = self.winCount + 1
- win = wxMDIChildFrame(self, -1, "Child Window: %d" % self.winCount)
- canvas = MyCanvas(win)
+ win = wx.MDIChildFrame(self, -1, "Child Window: %d" % self.winCount)
+ canvas = wxScrolledWindow.MyCanvas(win)
win.Show(True)
#----------------------------------------------------------------------
if __name__ == '__main__':
- class MyApp(wxApp):
+ class MyApp(wx.App):
def OnInit(self):
- wxInitAllImageHandlers()
+ wx.InitAllImageHandlers()
frame = MyParentFrame()
frame.Show(True)
self.SetTopWindow(frame)
return True
-
- app = MyApp(0)
+ app = MyApp(False)
app.MainLoop()
-from wxPython.wx import *
-from wxPython.lib.maskededit import Field, wxMaskedTextCtrl, wxMaskedComboBox, wxIpAddrCtrl, states, state_names, months
-from wxPython.lib.maskededit import __doc__ as maskededit_doc
-from wxPython.lib.maskededit import autoformats
-from wxPython.lib.maskedctrl import wxMaskedCtrl, controlTypes, MASKEDCOMBO
-from wxPython.lib.scrolledpanel import wxScrolledPanel
-import string, sys, traceback
+# 11/23/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+# 11/26/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o the three libraries below all have not been hit by the
+# wx renamer.
+#
+
+import string
+import sys
+import traceback
+
+import wx
+import wx.lib.maskededit as med
+import wx.lib.maskedctrl as mctl
+import wx.lib.scrolledpanel as scroll
class demoMixin:
Centralized routines common to demo pages, to remove repetition.
"""
def labelGeneralTable(self, sizer):
- description = wxStaticText( self, -1, "Description", )
- mask = wxStaticText( self, -1, "Mask Value" )
- formatcode = wxStaticText( self, -1, "Format" )
- regex = wxStaticText( self, -1, "Regexp Validator(opt.)" )
- ctrl = wxStaticText( self, -1, "wxMaskedTextCtrl" )
-
- description.SetFont( wxFont(9, wxSWISS, wxNORMAL, wxBOLD))
- mask.SetFont( wxFont(9, wxSWISS, wxNORMAL, wxBOLD))
- formatcode.SetFont( wxFont(9, wxSWISS, wxNORMAL, wxBOLD) )
- regex.SetFont( wxFont(9, wxSWISS, wxNORMAL, wxBOLD))
- ctrl.SetFont( wxFont(9, wxSWISS, wxNORMAL, wxBOLD))
+ description = wx.StaticText( self, -1, "Description", )
+ mask = wx.StaticText( self, -1, "Mask Value" )
+ formatcode = wx.StaticText( self, -1, "Format" )
+ regex = wx.StaticText( self, -1, "Regexp Validator(opt.)" )
+ ctrl = wx.StaticText( self, -1, "wxMaskedTextCtrl" )
+
+ description.SetFont( wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD))
+ mask.SetFont( wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD))
+ formatcode.SetFont( wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD) )
+ regex.SetFont( wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD))
+ ctrl.SetFont( wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD))
sizer.Add(description)
sizer.Add(mask)
def layoutGeneralTable(self, controls, sizer):
for control in controls:
- sizer.Add( wxStaticText( self, -1, control[0]) )
- sizer.Add( wxStaticText( self, -1, control[1]) )
- sizer.Add( wxStaticText( self, -1, control[3]) )
- sizer.Add( wxStaticText( self, -1, control[4]) )
+ sizer.Add( wx.StaticText( self, -1, control[0]) )
+ sizer.Add( wx.StaticText( self, -1, control[1]) )
+ sizer.Add( wx.StaticText( self, -1, control[3]) )
+ sizer.Add( wx.StaticText( self, -1, control[4]) )
if control in controls:
- newControl = wxMaskedTextCtrl( self, -1, "",
+ newControl = med.wxMaskedTextCtrl( self, -1, "",
mask = control[1],
excludeChars = control[2],
formatcodes = control[3],
def changeControlParams(self, event, parameter, checked_value, notchecked_value):
- if event.Checked(): value = checked_value
+ if event.IsChecked(): value = checked_value
else: value = notchecked_value
+
kwargs = {parameter: value}
+
for control in self.editList:
control.SetCtrlParameters(**kwargs)
control.Refresh()
+
self.Refresh()
#----------------------------------------------------------------------------
-class demoPage1(wxScrolledPanel, demoMixin):
+class demoPage1(scroll.wxScrolledPanel, demoMixin):
def __init__(self, parent, log):
- wxScrolledPanel.__init__(self, parent, -1)
- self.sizer = wxBoxSizer( wxVERTICAL )
+ scroll.wxScrolledPanel.__init__(self, parent, -1)
+ self.sizer = wx.BoxSizer( wx.VERTICAL )
self.editList = []
- label = wxStaticText( self, -1, """\
-Here are some basic wxMaskedTextCtrls to give you an idea of what you can do
+ label = wx.StaticText( self, -1, """\
+Here are some basic MaskedTextCtrls to give you an idea of what you can do
with this control. Note that all controls have been auto-sized by including 'F' in
the format codes.
Smith, Jones, Williams). Signs on numbers can be toggled with the minus key.
""")
label.SetForegroundColour( "Blue" )
- header = wxBoxSizer( wxHORIZONTAL )
- header.Add( label, 0, flag=wxALIGN_LEFT|wxALL, border = 5 )
+ header = wx.BoxSizer( wx.HORIZONTAL )
+ header.Add( label, 0, flag=wx.ALIGN_LEFT|wx.ALL, border = 5 )
- highlight = wxCheckBox( self, -1, "Highlight Empty" )
- disallow = wxCheckBox( self, -1, "Disallow Empty" )
- showFill = wxCheckBox( self, -1, "change fillChar" )
+ highlight = wx.CheckBox( self, -1, "Highlight Empty" )
+ disallow = wx.CheckBox( self, -1, "Disallow Empty" )
+ showFill = wx.CheckBox( self, -1, "change fillChar" )
- vbox = wxBoxSizer( wxVERTICAL )
- vbox.Add( highlight, 0, wxALIGN_LEFT|wxALL, 5 )
- vbox.Add( disallow, 0, wxALIGN_LEFT|wxALL, 5 )
- vbox.Add( showFill, 0, wxALIGN_LEFT|wxALL, 5 )
- header.AddSpacer(15, 0)
- header.Add(vbox, 0, flag=wxALIGN_LEFT|wxALL, border=5 )
+ vbox = wx.BoxSizer( wx.VERTICAL )
+ vbox.Add( highlight, 0, wx.ALIGN_LEFT|wx.ALL, 5 )
+ vbox.Add( disallow, 0, wx.ALIGN_LEFT|wx.ALL, 5 )
+ vbox.Add( showFill, 0, wx.ALIGN_LEFT|wx.ALL, 5 )
+ header.Add((15, 0))
+ header.Add(vbox, 0, flag=wx.ALIGN_LEFT|wx.ALL, border=5 )
- EVT_CHECKBOX( self, highlight.GetId(), self.onHighlightEmpty )
- EVT_CHECKBOX( self, disallow.GetId(), self.onDisallowEmpty )
- EVT_CHECKBOX( self, showFill.GetId(), self.onShowFill )
+ self.Bind(wx.EVT_CHECKBOX, self.onHighlightEmpty, id=highlight.GetId())
+ self.Bind(wx.EVT_CHECKBOX, self.onDisallowEmpty, id=disallow.GetId())
+ self.Bind(wx.EVT_CHECKBOX, self.onShowFill, id=showFill.GetId())
- grid = wxFlexGridSizer( 0, 5, vgap=10, hgap=10 )
+ grid = wx.FlexGridSizer( 0, 5, vgap=10, hgap=10 )
self.labelGeneralTable(grid)
# The following list is of the controls for the demo. Feel free to play around with
]
self.layoutGeneralTable(controls, grid)
- self.sizer.Add( header, 0, flag=wxALIGN_LEFT|wxALL, border=5 )
- self.sizer.Add( grid, 0, flag= wxALIGN_LEFT|wxLEFT, border=5 )
+ self.sizer.Add( header, 0, flag=wx.ALIGN_LEFT|wx.ALL, border=5 )
+ self.sizer.Add( grid, 0, flag= wx.ALIGN_LEFT|wx.LEFT, border=5 )
self.SetSizer(self.sizer)
self.SetupScrolling()
self.SetAutoLayout(1)
self.changeControlParams( event, "fillChar", '?', ' ' )
-class demoPage2(wxScrolledPanel, demoMixin):
+class demoPage2(scroll.wxScrolledPanel, demoMixin):
def __init__( self, parent, log ):
self.log = log
- wxScrolledPanel.__init__( self, parent, -1 )
- self.sizer = wxBoxSizer( wxVERTICAL )
+ scroll.wxScrolledPanel.__init__( self, parent, -1 )
+ self.sizer = wx.BoxSizer( wx.VERTICAL )
- label = wxStaticText( self, -1, """\
+ label = wx.StaticText( self, -1, """\
All these controls have been created by passing a single parameter, the autoformat code,
and use the factory class wxMaskedCtrl with its default controlType.
The maskededit module contains an internal dictionary of types and formats (autoformats).
""")
label.SetForegroundColour( "Blue" )
- self.sizer.Add( label, 0, wxALIGN_LEFT|wxALL, 5 )
+ self.sizer.Add( label, 0, wx.ALIGN_LEFT|wx.ALL, 5 )
- description = wxStaticText( self, -1, "Description")
- autofmt = wxStaticText( self, -1, "AutoFormat Code")
- ctrl = wxStaticText( self, -1, "wxMaskedCtrl")
+ description = wx.StaticText( self, -1, "Description")
+ autofmt = wx.StaticText( self, -1, "AutoFormat Code")
+ ctrl = wx.StaticText( self, -1, "MaskedCtrl")
- description.SetFont( wxFont( 9, wxSWISS, wxNORMAL, wxBOLD ) )
- autofmt.SetFont( wxFont( 9, wxSWISS, wxNORMAL, wxBOLD ) )
- ctrl.SetFont( wxFont( 9, wxSWISS, wxNORMAL, wxBOLD ) )
+ description.SetFont( wx.Font( 9, wx.SWISS, wx.NORMAL, wx.BOLD ) )
+ autofmt.SetFont( wx.Font( 9, wx.SWISS, wx.NORMAL, wx.BOLD ) )
+ ctrl.SetFont( wx.Font( 9, wx.SWISS, wx.NORMAL, wx.BOLD ) )
- grid = wxFlexGridSizer( 0, 3, vgap=10, hgap=5 )
- grid.Add( description, 0, wxALIGN_LEFT )
- grid.Add( autofmt, 0, wxALIGN_LEFT )
- grid.Add( ctrl, 0, wxALIGN_LEFT )
+ grid = wx.FlexGridSizer( 0, 3, vgap=10, hgap=5 )
+ grid.Add( description, 0, wx.ALIGN_LEFT )
+ grid.Add( autofmt, 0, wx.ALIGN_LEFT )
+ grid.Add( ctrl, 0, wx.ALIGN_LEFT )
- for autoformat, desc in autoformats:
- grid.Add( wxStaticText( self, -1, desc), 0, wxALIGN_LEFT )
- grid.Add( wxStaticText( self, -1, autoformat), 0, wxALIGN_LEFT )
- grid.Add( wxMaskedCtrl( self, -1, "",
+ for autoformat, desc in med.autoformats:
+ grid.Add( wx.StaticText( self, -1, desc), 0, wx.ALIGN_LEFT )
+ grid.Add( wx.StaticText( self, -1, autoformat), 0, wx.ALIGN_LEFT )
+ grid.Add( mctl.wxMaskedCtrl( self, -1, "",
autoformat = autoformat,
demo = True,
name = autoformat),
- 0, wxALIGN_LEFT )
+ 0, wx.ALIGN_LEFT )
- self.sizer.Add( grid, 0, wxALIGN_LEFT|wxALL, border=5 )
+ self.sizer.Add( grid, 0, wx.ALIGN_LEFT|wx.ALL, border=5 )
self.SetSizer( self.sizer )
self.SetAutoLayout( 1 )
self.SetupScrolling()
-class demoPage3(wxScrolledPanel, demoMixin):
+class demoPage3(scroll.wxScrolledPanel, demoMixin):
def __init__(self, parent, log):
self.log = log
- wxScrolledPanel.__init__(self, parent, -1)
- self.sizer = wxBoxSizer( wxVERTICAL )
+ scroll.wxScrolledPanel.__init__(self, parent, -1)
+ self.sizer = wx.BoxSizer( wx.VERTICAL )
self.editList = []
- label = wxStaticText( self, -1, """\
+ label = wx.StaticText( self, -1, """\
Here wxMaskedTextCtrls that have default values. The states
control has a list of valid values, and the unsigned integer
has a legal range specified.
""")
label.SetForegroundColour( "Blue" )
- requireValid = wxCheckBox( self, -1, "Require Valid Value" )
- EVT_CHECKBOX( self, requireValid.GetId(), self.onRequireValid )
+ requireValid = wx.CheckBox( self, -1, "Require Valid Value" )
+ self.Bind(wx.EVT_CHECKBOX, self.onRequireValid, id=requireValid.GetId())
- header = wxBoxSizer( wxHORIZONTAL )
- header.Add( label, 0, flag=wxALIGN_LEFT|wxALL, border = 5)
- header.AddSpacer(75, 0)
- header.Add( requireValid, 0, flag=wxALIGN_LEFT|wxALL, border=10 )
+ header = wx.BoxSizer( wx.HORIZONTAL )
+ header.Add( label, 0, flag=wx.ALIGN_LEFT|wx.ALL, border = 5)
+ header.Add((75, 0))
+ header.Add( requireValid, 0, flag=wx.ALIGN_LEFT|wx.ALL, border=10 )
- grid = wxFlexGridSizer( 0, 5, vgap=10, hgap=10 )
+ grid = wx.FlexGridSizer( 0, 5, vgap=10, hgap=10 )
self.labelGeneralTable( grid )
controls = [
#description mask excl format regexp range,list,initial
- ("U.S. State (2 char)", "AA", "", 'F!_', "[A-Z]{2}", '',states, states[0]),
+ ("U.S. State (2 char)", "AA", "", 'F!_', "[A-Z]{2}", '',med.states, med.states[0]),
("Integer (signed)", "#{6}", "", 'F-_', "", '','', ' 0 '),
("Integer (unsigned)\n(1-399)","######", "", 'F_', "", (1,399),'', '1 '),
("Float (signed)", "#{6}.#{9}", "", 'F-_R', "", '','', '000000.000000000'),
- ("Date (MDY) + Time", "##/##/#### ##:##:## AM", 'BCDEFGHIJKLMNOQRSTUVWXYZ','DF!',"", '','', wxDateTime_Now().Format("%m/%d/%Y %I:%M:%S %p")),
+ ("Date (MDY) + Time", "##/##/#### ##:##:## AM", 'BCDEFGHIJKLMNOQRSTUVWXYZ','DF!',"", '','', wx.DateTime_Now().Format("%m/%d/%Y %I:%M:%S %p")),
]
self.layoutGeneralTable( controls, grid )
- self.sizer.Add( header, 0, flag=wxALIGN_LEFT|wxALL, border=5 )
- self.sizer.Add( grid, 0, flag=wxALIGN_LEFT|wxALL, border=5 )
+ self.sizer.Add( header, 0, flag=wx.ALIGN_LEFT|wx.ALL, border=5 )
+ self.sizer.Add( grid, 0, flag=wx.ALIGN_LEFT|wx.ALL, border=5 )
self.SetSizer( self.sizer )
self.SetAutoLayout( 1 )
self.changeControlParams( event, "validRequired", True, False )
-class demoPage4(wxScrolledPanel, demoMixin):
+class demoPage4(scroll.wxScrolledPanel, demoMixin):
def __init__( self, parent, log ):
self.log = log
- wxScrolledPanel.__init__( self, parent, -1 )
- self.sizer = wxBoxSizer( wxVERTICAL )
+ scroll.wxScrolledPanel.__init__( self, parent, -1 )
+ self.sizer = wx.BoxSizer( wx.VERTICAL )
- label = wxStaticText( self, -1, """\
+ label = wx.StaticText( self, -1, """\
These controls have field-specific choice lists and allow autocompletion.
Down arrow or Page Down in an uncompleted field with an auto-completable field will attempt
""")
label.SetForegroundColour( "Blue" )
- self.sizer.Add( label, 0, wxALIGN_LEFT|wxALL, 5 )
+ self.sizer.Add( label, 0, wx.ALIGN_LEFT|wx.ALL, 5 )
- description = wxStaticText( self, -1, "Description" )
- autofmt = wxStaticText( self, -1, "AutoFormat Code" )
- fields = wxStaticText( self, -1, "Field Objects" )
- ctrl = wxStaticText( self, -1, "wxMaskedTextCtrl" )
+ description = wx.StaticText( self, -1, "Description" )
+ autofmt = wx.StaticText( self, -1, "AutoFormat Code" )
+ fields = wx.StaticText( self, -1, "Field Objects" )
+ ctrl = wx.StaticText( self, -1, "wxMaskedTextCtrl" )
- description.SetFont( wxFont( 9, wxSWISS, wxNORMAL, wxBOLD ) )
- autofmt.SetFont( wxFont( 9, wxSWISS, wxNORMAL, wxBOLD ) )
- fields.SetFont( wxFont( 9, wxSWISS, wxNORMAL, wxBOLD ) )
- ctrl.SetFont( wxFont( 9, wxSWISS, wxNORMAL, wxBOLD ) )
+ description.SetFont( wx.Font( 9, wx.SWISS, wx.NORMAL, wx.BOLD ) )
+ autofmt.SetFont( wx.Font( 9, wx.SWISS, wx.NORMAL, wx.BOLD ) )
+ fields.SetFont( wx.Font( 9, wx.SWISS, wx.NORMAL, wx.BOLD ) )
+ ctrl.SetFont( wx.Font( 9, wx.SWISS, wx.NORMAL, wx.BOLD ) )
- grid = wxFlexGridSizer( 0, 4, vgap=10, hgap=10 )
- grid.Add( description, 0, wxALIGN_LEFT )
- grid.Add( autofmt, 0, wxALIGN_LEFT )
- grid.Add( fields, 0, wxALIGN_LEFT )
- grid.Add( ctrl, 0, wxALIGN_LEFT )
+ grid = wx.FlexGridSizer( 0, 4, vgap=10, hgap=10 )
+ grid.Add( description, 0, wx.ALIGN_LEFT )
+ grid.Add( autofmt, 0, wx.ALIGN_LEFT )
+ grid.Add( fields, 0, wx.ALIGN_LEFT )
+ grid.Add( ctrl, 0, wx.ALIGN_LEFT )
autoformat = "USPHONEFULLEXT"
- fieldsDict = {0: Field(choices=["617","781","508","978","413"], choiceRequired=True)}
+ fieldsDict = {0: med.Field(choices=["617","781","508","978","413"], choiceRequired=True)}
fieldsLabel = """\
{0: Field(choices=[
"617","781",
"508","978","413"],
choiceRequired=True)}"""
- grid.Add( wxStaticText( self, -1, "Restricted Area Code"), 0, wxALIGN_LEFT )
- grid.Add( wxStaticText( self, -1, autoformat), 0, wxALIGN_LEFT )
- grid.Add( wxStaticText( self, -1, fieldsLabel), 0, wxALIGN_LEFT )
- grid.Add( wxMaskedTextCtrl( self, -1, "",
+ grid.Add( wx.StaticText( self, -1, "Restricted Area Code"), 0, wx.ALIGN_LEFT )
+ grid.Add( wx.StaticText( self, -1, autoformat), 0, wx.ALIGN_LEFT )
+ grid.Add( wx.StaticText( self, -1, fieldsLabel), 0, wx.ALIGN_LEFT )
+ grid.Add( med.wxMaskedTextCtrl( self, -1, "",
autoformat = autoformat,
fields = fieldsDict,
demo = True,
name = autoformat),
- 0, wxALIGN_LEFT )
+ 0, wx.ALIGN_LEFT )
autoformat = "EXPDATEMMYY"
- fieldsDict = {1: Field(choices=["03", "04", "05"], choiceRequired=True)}
+ fieldsDict = {1: med.Field(choices=["03", "04", "05"], choiceRequired=True)}
fieldsLabel = """\
{1: Field(choices=[
"03", "04", "05"],
choiceRequired=True)}"""
- exp = wxMaskedTextCtrl( self, -1, "",
+ exp = med.wxMaskedTextCtrl( self, -1, "",
autoformat = autoformat,
fields = fieldsDict,
demo = True,
name = autoformat)
- grid.Add( wxStaticText( self, -1, "Restricted Expiration"), 0, wxALIGN_LEFT )
- grid.Add( wxStaticText( self, -1, autoformat), 0, wxALIGN_LEFT )
- grid.Add( wxStaticText( self, -1, fieldsLabel), 0, wxALIGN_LEFT )
- grid.Add( exp, 0, wxALIGN_LEFT )
+ grid.Add( wx.StaticText( self, -1, "Restricted Expiration"), 0, wx.ALIGN_LEFT )
+ grid.Add( wx.StaticText( self, -1, autoformat), 0, wx.ALIGN_LEFT )
+ grid.Add( wx.StaticText( self, -1, fieldsLabel), 0, wx.ALIGN_LEFT )
+ grid.Add( exp, 0, wx.ALIGN_LEFT )
- fieldsDict = {0: Field(choices=["02134","02155"], choiceRequired=True),
- 1: Field(choices=["1234", "5678"], choiceRequired=False)}
+ fieldsDict = {0: med.Field(choices=["02134","02155"], choiceRequired=True),
+ 1: med.Field(choices=["1234", "5678"], choiceRequired=False)}
fieldsLabel = """\
{0: Field(choices=["02134","02155"],
choiceRequired=True),
1: Field(choices=["1234", "5678"],
choiceRequired=False)}"""
autoformat = "USZIPPLUS4"
- zip = wxMaskedTextCtrl( self, -1, "",
+ zip = med.wxMaskedTextCtrl( self, -1, "",
autoformat = autoformat,
fields = fieldsDict,
demo = True,
name = autoformat)
- grid.Add( wxStaticText( self, -1, "Restricted Zip + 4"), 0, wxALIGN_LEFT )
- grid.Add( wxStaticText( self, -1, autoformat), 0, wxALIGN_LEFT )
- grid.Add( wxStaticText( self, -1, fieldsLabel), 0, wxALIGN_LEFT )
- grid.Add( zip, 0, wxALIGN_LEFT )
+ grid.Add( wx.StaticText( self, -1, "Restricted Zip + 4"), 0, wx.ALIGN_LEFT )
+ grid.Add( wx.StaticText( self, -1, autoformat), 0, wx.ALIGN_LEFT )
+ grid.Add( wx.StaticText( self, -1, fieldsLabel), 0, wx.ALIGN_LEFT )
+ grid.Add( zip, 0, wx.ALIGN_LEFT )
- self.sizer.Add( grid, 0, wxALIGN_LEFT|wxALL, border=5 )
+ self.sizer.Add( grid, 0, wx.ALIGN_LEFT|wx.ALL, border=5 )
self.SetSizer( self.sizer )
self.SetAutoLayout(1)
self.SetupScrolling()
-class demoPage5(wxScrolledPanel, demoMixin):
+class demoPage5(scroll.wxScrolledPanel, demoMixin):
def __init__( self, parent, log ):
self.log = log
- wxScrolledPanel.__init__( self, parent, -1 )
- self.sizer = wxBoxSizer( wxVERTICAL )
+ scroll.wxScrolledPanel.__init__( self, parent, -1 )
+ self.sizer = wx.BoxSizer( wx.VERTICAL )
- labelMaskedCombos = wxStaticText( self, -1, """\
+ labelMaskedCombos = wx.StaticText( self, -1, """\
These are some examples of wxMaskedComboBox:""")
labelMaskedCombos.SetForegroundColour( "Blue" )
- label_statecode = wxStaticText( self, -1, """\
+ label_statecode = wx.StaticText( self, -1, """\
A state selector; only
"legal" values can be
entered:""")
- statecode = wxMaskedComboBox( self, -1, states[0],
- choices = states,
+ statecode = med.wxMaskedComboBox( self, -1, med.states[0],
+ choices = med.states,
autoformat="USSTATE")
- label_statename = wxStaticText( self, -1, """\
+ label_statename = wx.StaticText( self, -1, """\
A state name selector,
with auto-select:""")
# Create this one using factory function:
- statename = wxMaskedCtrl( self, -1, state_names[0],
- controlType = controlTypes.MASKEDCOMBO,
- choices = state_names,
+ statename = mctl.wxMaskedCtrl( self, -1, med.state_names[0],
+ controlType = mctl.controlTypes.MASKEDCOMBO,
+ choices = med.state_names,
autoformat="USSTATENAME",
autoSelect=True)
statename.SetCtrlParameters(formatcodes = 'F!V_')
numerators = [ str(i) for i in range(1, 4) ]
denominators = [ string.ljust(str(i), 2) for i in [2,3,4,5,8,16,32,64] ]
- fieldsDict = {0: Field(choices=numerators, choiceRequired=False),
- 1: Field(choices=denominators, choiceRequired=True)}
+ fieldsDict = {0: med.Field(choices=numerators, choiceRequired=False),
+ 1: med.Field(choices=denominators, choiceRequired=True)}
choices = []
for n in numerators:
for d in denominators:
choices.append( '%s/%s' % (n,d) )
- label_fraction = wxStaticText( self, -1, """\
+ label_fraction = wx.StaticText( self, -1, """\
A masked ComboBox for fraction selection.
Choices for each side of the fraction can
be selected with PageUp/Down:""")
- fraction = wxMaskedCtrl( self, -1, "",
- controlType = MASKEDCOMBO,
+ fraction = mctl.wxMaskedCtrl( self, -1, "",
+ controlType = mctl.MASKEDCOMBO,
choices = choices,
choiceRequired = True,
mask = "#/##",
fields = fieldsDict )
- label_code = wxStaticText( self, -1, """\
+ label_code = wx.StaticText( self, -1, """\
A masked ComboBox to validate
text from a list of numeric codes:""")
choices = ["91", "136", "305", "4579"]
- code = wxMaskedComboBox( self, -1, choices[0],
+ code = med.wxMaskedComboBox( self, -1, choices[0],
choices = choices,
choiceRequired = True,
formatcodes = "F_r",
mask = "####")
- label_selector = wxStaticText( self, -1, """\
+ label_selector = wx.StaticText( self, -1, """\
Programmatically set
choice sets:""")
- self.list_selector = wxComboBox(self, -1, '', choices = ['list1', 'list2', 'list3'])
- self.dynamicbox = wxMaskedCtrl( self, -1, ' ',
- controlType = controlTypes.MASKEDCOMBO,
+ self.list_selector = wx.ComboBox(self, -1, '', choices = ['list1', 'list2', 'list3'])
+ self.dynamicbox = mctl.wxMaskedCtrl( self, -1, ' ',
+ controlType = mctl.controlTypes.MASKEDCOMBO,
mask = 'XXXX',
formatcodes = 'F_',
# these are to give dropdown some initial height,
self.dynamicbox.Clear() # get rid of initial choices used to size the dropdown
- labelIpAddrs = wxStaticText( self, -1, """\
+ labelIpAddrs = wx.StaticText( self, -1, """\
Here are some examples of wxIpAddrCtrl, a control derived from wxMaskedTextCtrl:""")
labelIpAddrs.SetForegroundColour( "Blue" )
- label_ipaddr1 = wxStaticText( self, -1, "An empty control:")
- ipaddr1 = wxIpAddrCtrl( self, -1, style = wxTE_PROCESS_TAB )
+ label_ipaddr1 = wx.StaticText( self, -1, "An empty control:")
+ ipaddr1 = med.wxIpAddrCtrl( self, -1, style = wx.TE_PROCESS_TAB )
- label_ipaddr2 = wxStaticText( self, -1, "A restricted mask:")
- ipaddr2 = wxIpAddrCtrl( self, -1, mask=" 10. 1.109.###" )
+ label_ipaddr2 = wx.StaticText( self, -1, "A restricted mask:")
+ ipaddr2 = med.wxIpAddrCtrl( self, -1, mask=" 10. 1.109.###" )
- label_ipaddr3 = wxStaticText( self, -1, """\
+ label_ipaddr3 = wx.StaticText( self, -1, """\
A control with restricted legal values:
10. (1|2) . (129..255) . (0..255)""")
- ipaddr3 = wxMaskedCtrl( self, -1,
- controlType = controlTypes.IPADDR,
+ ipaddr3 = mctl.wxMaskedCtrl( self, -1,
+ controlType = mctl.controlTypes.IPADDR,
mask=" 10. #.###.###")
ipaddr3.SetFieldParameters(0, validRegex="1|2",validRequired=False ) # requires entry to match or not allowed
- labelNumerics = wxStaticText( self, -1, """\
+ labelNumerics = wx.StaticText( self, -1, """\
Here are some useful configurations of a wxMaskedTextCtrl for integer and floating point input that still treat
the control as a text control. (For a true numeric control, check out the wxMaskedNumCtrl class!)""")
labelNumerics.SetForegroundColour( "Blue" )
- label_intctrl1 = wxStaticText( self, -1, """\
+ label_intctrl1 = wx.StaticText( self, -1, """\
An integer entry control with
shifting insert enabled:""")
- self.intctrl1 = wxMaskedTextCtrl(self, -1, name='intctrl', mask="#{9}", formatcodes = '_-,F>')
- label_intctrl2 = wxStaticText( self, -1, """\
+ self.intctrl1 = med.wxMaskedTextCtrl(self, -1, name='intctrl', mask="#{9}", formatcodes = '_-,F>')
+ label_intctrl2 = wx.StaticText( self, -1, """\
Right-insert integer entry:""")
- self.intctrl2 = wxMaskedTextCtrl(self, -1, name='intctrl', mask="#{9}", formatcodes = '_-,Fr')
+ self.intctrl2 = med.wxMaskedTextCtrl(self, -1, name='intctrl', mask="#{9}", formatcodes = '_-,Fr')
- label_floatctrl = wxStaticText( self, -1, """\
+ label_floatctrl = wx.StaticText( self, -1, """\
A floating point entry control
with right-insert for ordinal:""")
- self.floatctrl = wxMaskedTextCtrl(self, -1, name='floatctrl', mask="#{9}.#{2}", formatcodes="F,_-R", useParensForNegatives=False)
+ self.floatctrl = med.wxMaskedTextCtrl(self, -1, name='floatctrl', mask="#{9}.#{2}", formatcodes="F,_-R", useParensForNegatives=False)
self.floatctrl.SetFieldParameters(0, formatcodes='r<', validRequired=True) # right-insert, require explicit cursor movement to change fields
self.floatctrl.SetFieldParameters(1, defaultValue='00') # don't allow blank fraction
- label_numselect = wxStaticText( self, -1, """\
+ label_numselect = wx.StaticText( self, -1, """\
<= Programmatically set the value
of the float entry ctrl:""")
- numselect = wxComboBox(self, -1, choices = [ '', '111', '222.22', '-3', '54321.666666666', '-1353.978',
+ numselect = wx.ComboBox(self, -1, choices = [ '', '111', '222.22', '-3', '54321.666666666', '-1353.978',
'1234567', '-1234567', '123456789', '-123456789.1',
'1234567890.', '-1234567890.1' ])
- parens_check = wxCheckBox(self, -1, "Use () to indicate negatives in above controls")
-
-
-
- gridCombos = wxFlexGridSizer( 0, 4, vgap=10, hgap = 10 )
- gridCombos.Add( label_statecode, 0, wxALIGN_LEFT )
- gridCombos.Add( statecode, 0, wxALIGN_LEFT )
- gridCombos.Add( label_fraction, 0, wxALIGN_LEFT )
- gridCombos.Add( fraction, 0, wxALIGN_LEFT )
- gridCombos.Add( label_statename, 0, wxALIGN_LEFT )
- gridCombos.Add( statename, 0, wxALIGN_LEFT )
- gridCombos.Add( label_code, 0, wxALIGN_LEFT )
- gridCombos.Add( code, 0, wxALIGN_LEFT )
- gridCombos.Add( label_selector, 0, wxALIGN_LEFT)
- hbox = wxBoxSizer( wxHORIZONTAL )
- hbox.Add( self.list_selector, 0, wxALIGN_LEFT )
- hbox.Add(wxStaticText(self, -1, ' => '), 0, wxALIGN_LEFT)
- hbox.Add( self.dynamicbox, 0, wxALIGN_LEFT )
- gridCombos.Add( hbox, 0, wxALIGN_LEFT )
-
- gridIpAddrs = wxFlexGridSizer( 0, 4, vgap=10, hgap = 15 )
- gridIpAddrs.Add( label_ipaddr1, 0, wxALIGN_LEFT )
- gridIpAddrs.Add( ipaddr1, 0, wxALIGN_LEFT )
- gridIpAddrs.Add( label_ipaddr2, 0, wxALIGN_LEFT )
- gridIpAddrs.Add( ipaddr2, 0, wxALIGN_LEFT )
- gridIpAddrs.Add( label_ipaddr3, 0, wxALIGN_LEFT )
- gridIpAddrs.Add( ipaddr3, 0, wxALIGN_LEFT )
-
- gridNumerics = wxFlexGridSizer( 0, 4, vgap=10, hgap = 10 )
- gridNumerics.Add( label_intctrl1, 0, wxALIGN_LEFT )
- gridNumerics.Add( self.intctrl1, 0, wxALIGN_LEFT )
- gridNumerics.Add( label_intctrl2, 0, wxALIGN_RIGHT )
- gridNumerics.Add( self.intctrl2, 0, wxALIGN_LEFT )
- gridNumerics.Add( label_floatctrl, 0, wxALIGN_LEFT )
- gridNumerics.Add( self.floatctrl, 0, wxALIGN_LEFT )
- gridNumerics.Add( label_numselect, 0, wxALIGN_RIGHT )
- gridNumerics.Add( numselect, 0, wxALIGN_LEFT )
-
- self.sizer.Add( labelMaskedCombos, 0, wxALIGN_LEFT|wxALL, 5 )
- self.sizer.Add( gridCombos, 0, wxALIGN_LEFT|wxALL, border=5 )
- self.sizer.Add( wxStaticLine(self, -1), 0, wxEXPAND|wxTOP|wxBOTTOM, border=8 )
- self.sizer.Add( labelIpAddrs, 0, wxALIGN_LEFT|wxALL, 5 )
- self.sizer.Add( gridIpAddrs, 0, wxALIGN_LEFT|wxALL, border=5 )
- self.sizer.Add( wxStaticLine(self, -1), 0, wxEXPAND|wxTOP|wxBOTTOM, border=8 )
- self.sizer.Add( labelNumerics, 0, wxALIGN_LEFT|wxALL, 5 )
- self.sizer.Add( gridNumerics, 0, wxALIGN_LEFT|wxALL, border=5 )
- self.sizer.Add( parens_check, 0, wxALIGN_LEFT|wxALL, 5 )
+ parens_check = wx.CheckBox(self, -1, "Use () to indicate negatives in above controls")
+
+
+
+ gridCombos = wx.FlexGridSizer( 0, 4, vgap=10, hgap = 10 )
+ gridCombos.Add( label_statecode, 0, wx.ALIGN_LEFT )
+ gridCombos.Add( statecode, 0, wx.ALIGN_LEFT )
+ gridCombos.Add( label_fraction, 0, wx.ALIGN_LEFT )
+ gridCombos.Add( fraction, 0, wx.ALIGN_LEFT )
+ gridCombos.Add( label_statename, 0, wx.ALIGN_LEFT )
+ gridCombos.Add( statename, 0, wx.ALIGN_LEFT )
+ gridCombos.Add( label_code, 0, wx.ALIGN_LEFT )
+ gridCombos.Add( code, 0, wx.ALIGN_LEFT )
+ gridCombos.Add( label_selector, 0, wx.ALIGN_LEFT)
+ hbox = wx.BoxSizer( wx.HORIZONTAL )
+ hbox.Add( self.list_selector, 0, wx.ALIGN_LEFT )
+ hbox.Add(wx.StaticText(self, -1, ' => '), 0, wx.ALIGN_LEFT)
+ hbox.Add( self.dynamicbox, 0, wx.ALIGN_LEFT )
+ gridCombos.Add( hbox, 0, wx.ALIGN_LEFT )
+
+ gridIpAddrs = wx.FlexGridSizer( 0, 4, vgap=10, hgap = 15 )
+ gridIpAddrs.Add( label_ipaddr1, 0, wx.ALIGN_LEFT )
+ gridIpAddrs.Add( ipaddr1, 0, wx.ALIGN_LEFT )
+ gridIpAddrs.Add( label_ipaddr2, 0, wx.ALIGN_LEFT )
+ gridIpAddrs.Add( ipaddr2, 0, wx.ALIGN_LEFT )
+ gridIpAddrs.Add( label_ipaddr3, 0, wx.ALIGN_LEFT )
+ gridIpAddrs.Add( ipaddr3, 0, wx.ALIGN_LEFT )
+
+ gridNumerics = wx.FlexGridSizer( 0, 4, vgap=10, hgap = 10 )
+ gridNumerics.Add( label_intctrl1, 0, wx.ALIGN_LEFT )
+ gridNumerics.Add( self.intctrl1, 0, wx.ALIGN_LEFT )
+ gridNumerics.Add( label_intctrl2, 0, wx.ALIGN_RIGHT )
+ gridNumerics.Add( self.intctrl2, 0, wx.ALIGN_LEFT )
+ gridNumerics.Add( label_floatctrl, 0, wx.ALIGN_LEFT )
+ gridNumerics.Add( self.floatctrl, 0, wx.ALIGN_LEFT )
+ gridNumerics.Add( label_numselect, 0, wx.ALIGN_RIGHT )
+ gridNumerics.Add( numselect, 0, wx.ALIGN_LEFT )
+
+ self.sizer.Add( labelMaskedCombos, 0, wx.ALIGN_LEFT|wx.ALL, 5 )
+ self.sizer.Add( gridCombos, 0, wx.ALIGN_LEFT|wx.ALL, border=5 )
+ self.sizer.Add( wx.StaticLine(self, -1), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, border=8 )
+ self.sizer.Add( labelIpAddrs, 0, wx.ALIGN_LEFT|wx.ALL, 5 )
+ self.sizer.Add( gridIpAddrs, 0, wx.ALIGN_LEFT|wx.ALL, border=5 )
+ self.sizer.Add( wx.StaticLine(self, -1), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, border=8 )
+ self.sizer.Add( labelNumerics, 0, wx.ALIGN_LEFT|wx.ALL, 5 )
+ self.sizer.Add( gridNumerics, 0, wx.ALIGN_LEFT|wx.ALL, border=5 )
+ self.sizer.Add( parens_check, 0, wx.ALIGN_LEFT|wx.ALL, 5 )
self.SetSizer( self.sizer )
self.SetAutoLayout(1)
self.SetupScrolling()
- EVT_COMBOBOX( self, fraction.GetId(), self.OnComboSelection )
- EVT_COMBOBOX( self, code.GetId(), self.OnComboSelection )
- EVT_COMBOBOX( self, statecode.GetId(), self.OnComboSelection )
- EVT_COMBOBOX( self, statename.GetId(), self.OnComboSelection )
- EVT_TEXT( self, fraction.GetId(), self.OnTextChange )
- EVT_TEXT( self, code.GetId(), self.OnTextChange )
- EVT_TEXT( self, statecode.GetId(), self.OnTextChange )
- EVT_TEXT( self, statename.GetId(), self.OnTextChange )
- EVT_COMBOBOX( self, self.list_selector.GetId(), self.OnListSelection )
+ self.Bind(wx.EVT_COMBOBOX, self.OnComboSelection, id=fraction.GetId())
+ self.Bind(wx.EVT_COMBOBOX, self.OnComboSelection, id=code.GetId())
+ self.Bind(wx.EVT_COMBOBOX, self.OnComboSelection, id=statecode.GetId())
+ self.Bind(wx.EVT_COMBOBOX, self.OnComboSelection, id=statename.GetId())
+ self.Bind(wx.EVT_TEXT, self.OnTextChange, id=code.GetId())
+ self.Bind(wx.EVT_TEXT, self.OnTextChange, id=statecode.GetId())
+ self.Bind(wx.EVT_TEXT, self.OnTextChange, id=statename.GetId())
+ self.Bind(wx.EVT_COMBOBOX, self.OnListSelection, id=self.list_selector.GetId())
- EVT_TEXT( self, self.intctrl1.GetId(), self.OnTextChange )
- EVT_TEXT( self, self.intctrl2.GetId(), self.OnTextChange )
- EVT_TEXT( self, self.floatctrl.GetId(), self.OnTextChange )
- EVT_COMBOBOX( self, numselect.GetId(), self.OnNumberSelect )
- EVT_CHECKBOX( self, parens_check.GetId(), self.OnParensCheck )
+ self.Bind(wx.EVT_TEXT, self.OnTextChange, id=self.intctrl1.GetId())
+ self.Bind(wx.EVT_TEXT, self.OnTextChange, id=self.intctrl2.GetId())
+ self.Bind(wx.EVT_TEXT, self.OnTextChange, id=self.floatctrl.GetId())
+ self.Bind(wx.EVT_COMBOBOX, self.OnNumberSelect, id=numselect.GetId())
+ self.Bind(wx.EVT_CHECKBOX, self.OnParensCheck, id=parens_check.GetId())
- EVT_TEXT( self, ipaddr1.GetId(), self.OnIpAddrChange )
- EVT_TEXT( self, ipaddr2.GetId(), self.OnIpAddrChange )
- EVT_TEXT( self, ipaddr3.GetId(), self.OnIpAddrChange )
+ self.Bind(wx.EVT_TEXT, self.OnIpAddrChange, id=ipaddr1.GetId())
+ self.Bind(wx.EVT_TEXT, self.OnIpAddrChange, id=ipaddr2.GetId())
+ self.Bind(wx.EVT_TEXT, self.OnIpAddrChange, id=ipaddr3.GetId())
self.dynamicbox.SetValue(choices[0])
# ---------------------------------------------------------------------
-class TestMaskedTextCtrls(wxNotebook):
+class TestMaskedTextCtrls(wx.Notebook):
def __init__(self, parent, id, log):
- wxNotebook.__init__(self, parent, id)
+ wx.Notebook.__init__(self, parent, id)
self.log = log
win = demoPage1(self, log)
return testWin
def RunStandalone():
- app = wxPySimpleApp()
- frame = wxFrame(None, -1, "Test wxMaskedTextCtrl", size=(640, 480))
+ app = wx.PySimpleApp()
+ frame = wx.Frame(None, -1, "Test MaskedTextCtrl", size=(640, 480))
win = TestMaskedTextCtrls(frame, -1, sys.stdout)
frame.Show(True)
app.MainLoop()
#----------------------------------------------------------------------------
-if __name__ == "__main__":
- RunStandalone()
-
overview = """<html>
<PRE><FONT SIZE=-1>
-""" + maskededit_doc + """
+""" + med.__doc__ + """
</FONT></PRE>
"""
+# 11/13/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
-from wxPython.html import *
+import wx
+import wx.html as wxhtml
#----------------------------------------------------------------------
-BTN1 = wxNewId()
-BTN2 = wxNewId()
+BTN1 = wx.NewId()
+BTN2 = wx.NewId()
-
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.log = log
- sizer = wxBoxSizer(wxVERTICAL)
- html = wxHtmlWindow(self, -1)
+ sizer = wx.BoxSizer(wx.VERTICAL)
+ html = wxhtml.HtmlWindow(self, -1)
html.SetPage(overview)
- sizer.Add(html, 1, wxEXPAND|wxALL, 5)
+ sizer.Add(html, 1, wx.EXPAND|wx.ALL, 5)
- btns = wxBoxSizer(wxHORIZONTAL)
- btns.Add(50, -1, 1, wxEXPAND)
- btn1 = wxButton(self, BTN1, "Find My Alter-ego") # don't save a ref to this one
+ btns = wx.BoxSizer(wx.HORIZONTAL)
+ btns.Add((50, -1), 1, wx.EXPAND)
+ btn1 = wx.Button(self, BTN1, "Find My Alter-ego") # don't save a ref to this one
btns.Add(btn1)
- btns.Add(50, -1, 1, wxEXPAND)
- self.btn2 = wxButton(self, BTN2, "Find Myself")
+ btns.Add((50, -1), 1, wx.EXPAND)
+ self.btn2 = wx.Button(self, BTN2, "Find Myself")
btns.Add(self.btn2)
- btns.Add(50, -1, 1, wxEXPAND)
+ btns.Add((50, -1), 1, wx.EXPAND)
- sizer.Add(btns, 0, wxEXPAND|wxALL, 15)
+ sizer.Add(btns, 0, wx.EXPAND|wx.ALL, 15)
self.SetSizer(sizer)
self.SetAutoLayout(True)
self.sizer = sizer # save it for testing later
- EVT_BUTTON(self, BTN1, self.OnFindButton1)
- EVT_BUTTON(self, BTN2, self.OnFindButton2)
+ self.Bind(wx.EVT_BUTTON, self.OnFindButton1, id=BTN1)
+ self.Bind(wx.EVT_BUTTON, self.OnFindButton2, id=BTN2)
def OnFindButton1(self, evt):
win = self.FindWindowById(BTN1)
+
if win is None:
self.log.write("***** OOPS! None returned...\n")
return
+
className = win.__class__.__name__
- if className in ["wxButton", "wxButtonPtr"]:
+
+ if className in ["Button", "ButtonPtr"]:
self.log.write("The types are the same! <grin>\n")
else:
self.log.write("Got %s, expected wxButton or wxButtonPtr\n" % className)
def OnFindButton2(self, evt):
win = self.FindWindowById(BTN2)
+
if win is None:
self.log.write("***** OOPS! None returned...\n")
return
+
if win is self.btn2:
self.log.write("The objects are the same! <grin>\n")
else:
self.log.write("The objects are NOT the same! <frown>\n")
win = evt.GetEventObject()
+
if win is None:
self.log.write("***** OOPS! None returned...\n")
return
+
if win is self.btn2:
self.log.write("The objects are the same! <grin>\n")
else:
self.log.write("The objects are NOT the same! <frown>\n")
sizer = self.GetSizer()
+
if sizer is None:
self.log.write("***** OOPS! None returned...\n")
return
+
if sizer is self.sizer:
self.log.write("The objects are the same! <grin>\n")
else:
</ol>
<p>The first button below shows the first of these phases (<i>working</i>)
-and the second will show #2 (<i>working as of 2.3.2</i>)
+and the second will show #2 (<i>working as of Python 2.3.2</i>)
</body></html>
"""
+# 11/13/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+# o Got rid of static buton IDs
+# o Took at a stab at a lucid overview string.
+#
-from wxPython.wx import *
-from wxScrolledWindow import MyCanvas
+import wx
+import wxScrolledWindow
#----------------------------------------------------------------------
-class MyPrintout(wxPrintout):
+ID_Setup = wx.NewId()
+ID_Preview = wx.NewId()
+ID_Print = wx.NewId()
+
+class MyPrintout(wx.Printout):
def __init__(self, canvas, log):
- wxPrintout.__init__(self)
+ wx.Printout.__init__(self)
self.canvas = canvas
self.log = log
def OnBeginDocument(self, start, end):
- self.log.WriteText("wxPrintout.OnBeginDocument\n")
+ self.log.WriteText("wx.Printout.OnBeginDocument\n")
return self.base_OnBeginDocument(start, end)
def OnEndDocument(self):
- self.log.WriteText("wxPrintout.OnEndDocument\n")
+ self.log.WriteText("wx.Printout.OnEndDocument\n")
self.base_OnEndDocument()
def OnBeginPrinting(self):
- self.log.WriteText("wxPrintout.OnBeginPrinting\n")
+ self.log.WriteText("wx.Printout.OnBeginPrinting\n")
self.base_OnBeginPrinting()
def OnEndPrinting(self):
- self.log.WriteText("wxPrintout.OnEndPrinting\n")
+ self.log.WriteText("wx.Printout.OnEndPrinting\n")
self.base_OnEndPrinting()
def OnPreparePrinting(self):
- self.log.WriteText("wxPrintout.OnPreparePrinting\n")
+ self.log.WriteText("wx.Printout.OnPreparePrinting\n")
self.base_OnPreparePrinting()
def HasPage(self, page):
- self.log.WriteText("wxPrintout.HasPage: %d\n" % page)
+ self.log.WriteText("wx.Printout.HasPage: %d\n" % page)
if page <= 2:
return True
else:
return False
def GetPageInfo(self):
- self.log.WriteText("wxPrintout.GetPageInfo\n")
+ self.log.WriteText("wx.Printout.GetPageInfo\n")
return (1, 2, 1, 2)
def OnPrintPage(self, page):
- self.log.WriteText("wxPrintout.OnPrintPage: %d\n" % page)
+ self.log.WriteText("wx.Printout.OnPrintPage: %d\n" % page)
dc = self.GetDC()
#-------------------------------------------
#----------------------------------------------------------------------
-class TestPrintPanel(wxPanel):
+class TestPrintPanel(wx.Panel):
def __init__(self, parent, frame, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.log = log
self.frame = frame
+ self.printData = wx.PrintData()
+ self.printData.SetPaperId(wx.PAPER_LETTER)
- self.printData = wxPrintData()
- self.printData.SetPaperId(wxPAPER_LETTER)
-
- self.box = wxBoxSizer(wxVERTICAL)
- self.canvas = MyCanvas(self)
- self.box.Add(self.canvas, 1, wxGROW)
+ self.box = wx.BoxSizer(wx.VERTICAL)
+ self.canvas = wxScrolledWindow.MyCanvas(self)
+ self.box.Add(self.canvas, 1, wx.GROW)
- subbox = wxBoxSizer(wxHORIZONTAL)
- btn = wxButton(self, 1201, "Print Setup")
- EVT_BUTTON(self, 1201, self.OnPrintSetup)
- subbox.Add(btn, 1, wxGROW | wxALL, 2)
+ subbox = wx.BoxSizer(wx.HORIZONTAL)
+ btn = wx.Button(self, ID_Setup, "Print Setup")
+ self.Bind(wx.EVT_BUTTON, self.OnPrintSetup, id=ID_Setup)
+ subbox.Add(btn, 1, wx.GROW | wx.ALL, 2)
- btn = wxButton(self, 1202, "Print Preview")
- EVT_BUTTON(self, 1202, self.OnPrintPreview)
- subbox.Add(btn, 1, wxGROW | wxALL, 2)
+ btn = wx.Button(self, ID_Preview, "Print Preview")
+ self.Bind(wx.EVT_BUTTON, self.OnPrintPreview, id=ID_Preview)
+ subbox.Add(btn, 1, wx.GROW | wx.ALL, 2)
- btn = wxButton(self, 1203, "Print")
- EVT_BUTTON(self, 1203, self.OnDoPrint)
- subbox.Add(btn, 1, wxGROW | wxALL, 2)
+ btn = wx.Button(self, ID_Print, "Print")
+ self.Bind(wx.EVT_BUTTON, self.OnDoPrint, id=ID_Print)
+ subbox.Add(btn, 1, wx.GROW | wx.ALL, 2)
- self.box.Add(subbox, 0, wxGROW)
+ self.box.Add(subbox, 0, wx.GROW)
self.SetAutoLayout(True)
self.SetSizer(self.box)
def OnPrintSetup(self, event):
- printerDialog = wxPrintDialog(self)
+ printerDialog = wx.PrintDialog(self)
printerDialog.GetPrintDialogData().SetPrintData(self.printData)
printerDialog.GetPrintDialogData().SetSetupDialog(True)
printerDialog.ShowModal();
self.log.WriteText("OnPrintPreview\n")
printout = MyPrintout(self.canvas, self.log)
printout2 = MyPrintout(self.canvas, self.log)
- self.preview = wxPrintPreview(printout, printout2, self.printData)
+ self.preview = wx.PrintPreview(printout, printout2, self.printData)
+
if not self.preview.Ok():
self.log.WriteText("Houston, we have a problem...\n")
return
- frame = wxPreviewFrame(self.preview, self.frame, "This is a print preview")
+ frame = wx.PreviewFrame(self.preview, self.frame, "This is a print preview")
frame.Initialize()
frame.SetPosition(self.frame.GetPosition())
def OnDoPrint(self, event):
- pdd = wxPrintDialogData()
+ pdd = wx.PrintDialogData()
pdd.SetPrintData(self.printData)
- printer = wxPrinter(pdd)
+ printer = wx.Printer(pdd)
printout = MyPrintout(self.canvas, self.log)
+
if not printer.Print(self.frame, printout):
- wxMessageBox("There was a problem printing.\nPerhaps your current printer is not set correctly?", "Printing", wxOK)
+ wx.MessageBox("There was a problem printing.\nPerhaps your current printer is not set correctly?", "Printing", wx.OK)
else:
self.printData = printer.GetPrintDialogData().GetPrintData()
printout.Destroy()
overview = """\
-"""
-
-
+<html>
+<body>
+<h1>PrintFramework</h1>
+
+This is an overview of the classes and methods used to print documents.
+It also demonstrates how to do print previews and invoke the printer
+setup dialog.
+
+<p>Classes demonstrated here:<P>
+<ul>
+ <li><b>wx.Printout()</b> - This class encapsulates the functionality of printing out
+ an application document. A new class must be derived and members overridden
+ to respond to calls such as OnPrintPage and HasPage. Instances of this class
+ are passed to wx.Printer.Print() or a wx.PrintPreview object to initiate
+ printing or previewing.<P><p>
+
+ <li><b>wx.PrintData()</b> - This class holds a variety of information related to
+ printers and printer device contexts. This class is used to create a
+ wx.PrinterDC and a wx.PostScriptDC. It is also used as a data member of
+ wx.PrintDialogData and wx.PageSetupDialogData, as part of the mechanism for
+ transferring data between the print dialogs and the application.<p><p>
+
+ <li><b>wx.PrintDialog()</b> - This class represents the print and print setup
+ common dialogs. You may obtain a wx.PrinterDC device context from a
+ successfully dismissed print dialog.<p><p>
+
+ <li><b>wx.PrintPreview()</b> - Objects of this class manage the print preview
+ process. The object is passed a wx.Printout object, and the wx.PrintPreview
+ object itself is passed to a wx.PreviewFrame object. Previewing is started by
+ initializing and showing the preview frame. Unlike wxPrinter.Print, flow of
+ control returns to the application immediately after the frame is shown.<p><p>
+</ul>
+
+<p>Other classes are also demonstrated, but this is the gist of the printer interface
+framework in wxPython.
+
+</body>
+</html>
+"""
if __name__ == '__main__':
+# 11/13/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wx import py
-
+import wx.py as py
#----------------------------------------------------------------------
+# 11/13/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-
-from wx import py
-
+import wx.py as py
#----------------------------------------------------------------------
+# 11/13/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
-import sys
+import sys
+
+import wx
#----------------------------------------------------------------------
-myEVT_BUTTON_CLICKPOS = wxNewEventType()
+# This shows the new 'official' way to do custom events as derived
+# from the wxPython 2.5 migration guide.
+
+#######################################################\
+# *** Old and busted *** |
+# |
+# myEVT_BUTTON_CLICKPOS = wx.NewEventType() |
+# |
+# def EVT_BUTTON_CLICKPOS(win, id, func): |
+# win.Connect(id, -1, myEVT_BUTTON_CLICKPOS, func) |
+#######################################################/
-def EVT_BUTTON_CLICKPOS(win, id, func):
- win.Connect(id, -1, myEVT_BUTTON_CLICKPOS, func)
+#############################\
+# *** The new Hottness *** |
+#############################/
+myEVT_BUTTON_CLICKPOS = wx.NewEventType()
+EVT_BUTTON_CLICKPOS = wx.PyEventBinder(myEVT_BUTTON_CLICKPOS, 1)
+#----------------------------------------------------------------------
-class MyEvent(wxPyCommandEvent):
+class MyEvent(wx.PyCommandEvent):
def __init__(self, evtType, id):
- wxPyCommandEvent.__init__(self, evtType, id)
+ wx.PyCommandEvent.__init__(self, evtType, id)
self.myVal = None
#def __del__(self):
# print '__del__'
- # wxPyCommandEvent.__del__(self)
+ # wx.PyCommandEvent.__del__(self)
def SetMyVal(self, val):
self.myVal = val
return self.myVal
-
-class MyButton(wxButton):
+class MyButton(wx.Button):
def __init__(self, parent, id, txt, pos):
- wxButton.__init__(self, parent, id, txt, pos)
- EVT_LEFT_DOWN(self, self.OnLeftDown)
+ wx.Button.__init__(self, parent, id, txt, pos)
+ self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
def OnLeftDown(self, event):
pt = event.GetPosition()
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.log = log
- b = MyButton(self, -1, " Click me ", wxPoint(30,30))
- EVT_BUTTON(self, b.GetId(), self.OnClick)
- EVT_BUTTON_CLICKPOS(self, b.GetId(), self.OnMyEvent)
+ b = MyButton(self, -1, " Click me ", (30,30))
+ self.Bind(wx.EVT_BUTTON, self.OnClick, id=b.GetId())
+
+ # This is our custom event binder created above.
+ self.Bind(EVT_BUTTON_CLICKPOS, self.OnMyEvent, id=b.GetId())
- wxStaticText(self, -1, "Please see the Overview and Demo Code for details...",
- wxPoint(30, 80))
+ wx.StaticText(
+ self, -1, "Please see the Overview and Demo Code for details...",
+ (30, 80)
+ )
def OnClick(self, event):
#----------------------------------------------------------------------
-
-
overview = """\
-This demo is a contrived example of defining an event class in wxPython and sending it up the containment hierarchy for processing.
-"""
-
-
-
+This demo is a contrived example of defining an event class in wxPython and
+sending it up the containment hierarchy for processing.
+V2.5 note: this demo also shows the new style of creating event binders that
+is required if you used the *.Bind() method of setting up event handlers.
+"""
if __name__ == '__main__':
-
-from wxPython.wx import *
-from wxPython.lib.rcsizer import RowColSizer
-
+# 11/13/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+# o Gotta fix the overview.
+#
+# 11/26/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Overview fixed.
+#
+
+import wx
+import wx.lib.rcsizer as rcs
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
+
+ sizer = rcs.RowColSizer()
- sizer = RowColSizer()
text = "This sizer lays out it's items by row and column "\
"that are specified explicitly when the item is \n"\
"added to the sizer. Grid cells with nothing in "\
"handled as well. Growable rows and columns are "\
"specified just like the wxFlexGridSizer."
- sizer.Add(wxStaticText(self, -1, text), row=1, col=1, colspan=5)
-
- sizer.Add(wxTextCtrl(self, -1, "(3,1)"), flag=wxEXPAND, row=3, col=1)
- sizer.Add(wxTextCtrl(self, -1, "(3,2)"), row=3, col=2)
- sizer.Add(wxTextCtrl(self, -1, "(3,3)"), row=3, col=3)
- sizer.Add(wxTextCtrl(self, -1, "(3,4)"), row=3, col=4)
- sizer.Add(wxTextCtrl(self, -1, "(4,2) span:(2,2)"), flag=wxEXPAND,
- row=4, col=2, rowspan=2, colspan=2)
- sizer.Add(wxTextCtrl(self, -1, "(6,4)"), row=6, col=4)
- sizer.Add(wxTextCtrl(self, -1, "(7,2)"), row=7, col=2)
- sizer.Add(wxTextCtrl(self, -1, "(8,3)"), row=8, col=3)
- sizer.Add(wxTextCtrl(self, -1, "(10,1) colspan: 4"), flag=wxEXPAND, pos=(10,1), colspan=4)
- sizer.Add(wxTextCtrl(self, -1, "(3,5) rowspan: 8, growable col", style=wxTE_MULTILINE),
- flag=wxEXPAND, pos=(3,5), size=(8,1))
-
- box = wxBoxSizer(wxVERTICAL)
- box.Add(wxButton(self, -1, "A vertical box"), flag=wxEXPAND)
- box.Add(wxButton(self, -1, "sizer put in the"), flag=wxEXPAND)
- box.Add(wxButton(self, -1, "RowColSizer at (12,1)"), flag=wxEXPAND)
+ sizer.Add(wx.StaticText(self, -1, text), row=1, col=1, colspan=5)
+
+ sizer.Add(wx.TextCtrl(self, -1, "(3,1)"), flag=wx.EXPAND, row=3, col=1)
+ sizer.Add(wx.TextCtrl(self, -1, "(3,2)"), row=3, col=2)
+ sizer.Add(wx.TextCtrl(self, -1, "(3,3)"), row=3, col=3)
+ sizer.Add(wx.TextCtrl(self, -1, "(3,4)"), row=3, col=4)
+ sizer.Add(
+ wx.TextCtrl(self, -1, "(4,2) span:(2,2)"),
+ flag=wx.EXPAND, row=4, col=2, rowspan=2, colspan=2
+ )
+
+ sizer.Add(wx.TextCtrl(self, -1, "(6,4)"), row=6, col=4)
+ sizer.Add(wx.TextCtrl(self, -1, "(7,2)"), row=7, col=2)
+ sizer.Add(wx.TextCtrl(self, -1, "(8,3)"), row=8, col=3)
+ sizer.Add(
+ wx.TextCtrl(self, -1, "(10,1) colspan: 4"),
+ flag=wx.EXPAND, pos=(10,1), colspan=4
+ )
+
+ sizer.Add(
+ wx.TextCtrl(self, -1, "(3,5) rowspan: 8, growable col", style=wx.TE_MULTILINE),
+ flag=wx.EXPAND, pos=(3,5), size=(8,1)
+ )
+
+ box = wx.BoxSizer(wx.VERTICAL)
+ box.Add(wx.Button(self, -1, "A vertical box"), flag=wx.EXPAND)
+ box.Add(wx.Button(self, -1, "sizer put in the"), flag=wx.EXPAND)
+ box.Add(wx.Button(self, -1, "RowColSizer at (12,1)"), flag=wx.EXPAND)
sizer.Add(box, pos=(12,1))
- sizer.Add(wxTextCtrl(self, -1, "(12,2) align bottom"), flag=wxALIGN_BOTTOM, pos=(12,2))
- sizer.Add(wxTextCtrl(self, -1, "(12,3) align center"), flag=wxALIGN_CENTER_VERTICAL, pos=(12,3))
- sizer.Add(wxTextCtrl(self, -1, "(12,4)"),pos=(12,4))
- sizer.Add(wxTextCtrl(self, -1, "(12,5) full border"), flag=wxEXPAND|wxALL, border=15, pos=(12,5))
+ sizer.Add(
+ wx.TextCtrl(self, -1, "(12,2) align bottom"),
+ flag=wx.ALIGN_BOTTOM, pos=(12,2)
+ )
+
+ sizer.Add(
+ wx.TextCtrl(self, -1, "(12,3) align center"),
+ flag=wx.ALIGN_CENTER_VERTICAL, pos=(12,3)
+ )
+
+ sizer.Add(wx.TextCtrl(self, -1, "(12,4)"),pos=(12,4))
+ sizer.Add(
+ wx.TextCtrl(self, -1, "(12,5) full border"),
+ flag=wx.EXPAND|wx.ALL, border=15, pos=(12,5)
+ )
sizer.AddGrowableCol(5)
sizer.AddGrowableRow(9)
#----------------------------------------------------------------------
-import wxPython.lib.rcsizer
-overview = wxPython.lib.rcsizer.__doc__
-
-
+overview = rcs.__doc__
if __name__ == '__main__':
import sys,os
+# 11/13/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
-import images
+import wx
+import images
#----------------------------------------------------------------------
-class TestFrame(wxFrame):
+class TestFrame(wx.Frame):
def __init__(self, parent, log):
self.log = log
- wxFrame.__init__(self, parent, -1, "Shaped Window",
+ wx.Frame.__init__(self, parent, -1, "Shaped Window",
style =
- wxFRAME_SHAPED
- | wxSIMPLE_BORDER
- | wxFRAME_NO_TASKBAR
- | wxSTAY_ON_TOP
+ wx.FRAME_SHAPED
+ | wx.SIMPLE_BORDER
+ | wx.FRAME_NO_TASKBAR
+ | wx.STAY_ON_TOP
)
self.hasShape = False
- self.delta = wxPoint(0,0)
+ self.delta = (0,0)
- EVT_LEFT_DCLICK(self, self.OnDoubleClick)
- EVT_LEFT_DOWN(self, self.OnLeftDown)
- EVT_LEFT_UP(self, self.OnLeftUp)
- EVT_MOTION(self, self.OnMouseMove)
- EVT_RIGHT_UP(self, self.OnExit)
- EVT_PAINT(self, self.OnPaint)
+ 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.bmp = images.getTuxBitmap()
w, h = self.bmp.GetWidth(), self.bmp.GetHeight()
self.SetClientSize( (w, h) )
- if wxPlatform != "__WXMAC__":
+ if wx.Platform != "__WXMAC__":
# wxMac clips the tooltip to the window shape, YUCK!!!
self.SetToolTipString("Right-click to close the window\n"
"Double-click the image to set/unset the window shape")
- if wxPlatform == "__WXGTK__":
+ if wx.Platform == "__WXGTK__":
# wxGTK requires that the window be created before you can
# set its shape, so delay the call to SetWindowShape until
# this event.
- EVT_WINDOW_CREATE(self, self.SetWindowShape)
+ self.Bind(wx.EVT_WINDOW_CREATE, self.SetWindowShape)
else:
# On wxMSW and wxMac the window has already been created, so go for it.
self.SetWindowShape()
- dc = wxClientDC(self)
+ dc = wx.ClientDC(self)
dc.DrawBitmap(self.bmp, (0,0), True)
def SetWindowShape(self, *evt):
# Use the bitmap's mask to determine the region
- r = wxRegionFromBitmap(self.bmp)
+ r = wx.RegionFromBitmap(self.bmp)
self.hasShape = self.SetShape(r)
def OnDoubleClick(self, evt):
if self.hasShape:
- self.SetShape(wxRegion())
+ self.SetShape(wx.Region())
self.hasShape = False
else:
self.SetWindowShape()
def OnPaint(self, evt):
- dc = wxPaintDC(self)
+ dc = wx.PaintDC(self)
dc.DrawBitmap(self.bmp, (0,0), True)
def OnExit(self, evt):
def OnLeftDown(self, evt):
self.CaptureMouse()
- pos = self.ClientToScreen(evt.GetPosition())
- origin = self.GetPosition()
- dx = pos.x - origin.x
- dy = pos.y - origin.y
- self.delta = wxPoint(dx, dy)
+ x, y = self.ClientToScreen(evt.GetPosition())
+ originx, originy = self.GetPosition()
+ dx = x - originx
+ dy = y - originy
+ self.delta = ((dx, dy))
def OnLeftUp(self, evt):
def OnMouseMove(self, evt):
if evt.Dragging() and evt.LeftIsDown():
- pos = self.ClientToScreen(evt.GetPosition())
- fp = (pos.x - self.delta.x, pos.y - self.delta.y)
+ x, y = self.ClientToScreen(evt.GetPosition())
+ fp = (x - self.delta[0], y - self.delta[1])
self.Move(fp)
+# 11/13/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+# o Issues exist that will probably need to be addressed in the 2.5 build.
+#
+# 11/26/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Had to do a bit of rework for the demo; there was no panel attached
+# to the demo window, so all buttons were showing as dark gray on
+# dark gray. I have no idea why this didn't break before. Robin,
+# please examine my changes to ensure you approve. It's rather
+# hackish looking.
+#
+
#----------------------------------------------------------------------
# sizer test code
#----------------------------------------------------------------------
-from wxPython.wx import *
-from wxPython.lib.grids import wxGridSizer, wxFlexGridSizer
+import wx
#----------------------------------------------------------------------
def makeSimpleBox1(win):
- box = wxBoxSizer(wxHORIZONTAL)
- box.Add(wxButton(win, 1010, "one"), 0, wxEXPAND)
- box.Add(wxButton(win, 1010, "two"), 0, wxEXPAND)
- box.Add(wxButton(win, 1010, "three"), 0, wxEXPAND)
- box.Add(wxButton(win, 1010, "four"), 0, wxEXPAND)
+ box = wx.BoxSizer(wx.HORIZONTAL)
+ box.Add(wx.Button(win, -1, "one"), 0, wx.EXPAND)
+ box.Add(wx.Button(win, -1, "two"), 0, wx.EXPAND)
+ box.Add(wx.Button(win, -1, "three"), 0, wx.EXPAND)
+ box.Add(wx.Button(win, -1, "four"), 0, wx.EXPAND)
return box
#----------------------------------------------------------------------
def makeSimpleBox2(win):
- box = wxBoxSizer(wxVERTICAL)
- box.Add(wxButton(win, 1010, "one"), 0, wxEXPAND)
- box.Add(wxButton(win, 1010, "two"), 0, wxEXPAND)
- box.Add(wxButton(win, 1010, "three"), 0, wxEXPAND)
- box.Add(wxButton(win, 1010, "four"), 0, wxEXPAND)
+ box = wx.BoxSizer(wx.VERTICAL)
+ box.Add(wx.Button(win, -1, "one"), 0, wx.EXPAND)
+ box.Add(wx.Button(win, -1, "two"), 0, wx.EXPAND)
+ box.Add(wx.Button(win, -1, "three"), 0, wx.EXPAND)
+ box.Add(wx.Button(win, -1, "four"), 0, wx.EXPAND)
return box
#----------------------------------------------------------------------
def makeSimpleBox3(win):
- box = wxBoxSizer(wxHORIZONTAL)
- box.Add(wxButton(win, 1010, "one"), 0, wxEXPAND)
- box.Add(wxButton(win, 1010, "two"), 0, wxEXPAND)
- box.Add(wxButton(win, 1010, "three"), 0, wxEXPAND)
- box.Add(wxButton(win, 1010, "four"), 0, wxEXPAND)
- box.Add(wxButton(win, 1010, "five"), 1, wxEXPAND)
+ box = wx.BoxSizer(wx.HORIZONTAL)
+ box.Add(wx.Button(win, -1, "one"), 0, wx.EXPAND)
+ box.Add(wx.Button(win, -1, "two"), 0, wx.EXPAND)
+ box.Add(wx.Button(win, -1, "three"), 0, wx.EXPAND)
+ box.Add(wx.Button(win, -1, "four"), 0, wx.EXPAND)
+ box.Add(wx.Button(win, -1, "five"), 1, wx.EXPAND)
return box
#----------------------------------------------------------------------
def makeSimpleBox4(win):
- box = wxBoxSizer(wxHORIZONTAL)
- box.Add(wxButton(win, 1010, "one"), 0, wxEXPAND)
- box.Add(wxButton(win, 1010, "two"), 0, wxEXPAND)
- box.Add(wxButton(win, 1010, "three"), 1, wxEXPAND)
- box.Add(wxButton(win, 1010, "four"), 1, wxEXPAND)
- box.Add(wxButton(win, 1010, "five"), 1, wxEXPAND)
+ box = wx.BoxSizer(wx.HORIZONTAL)
+ box.Add(wx.Button(win, -1, "one"), 0, wx.EXPAND)
+ box.Add(wx.Button(win, -1, "two"), 0, wx.EXPAND)
+ box.Add(wx.Button(win, -1, "three"), 1, wx.EXPAND)
+ box.Add(wx.Button(win, -1, "four"), 1, wx.EXPAND)
+ box.Add(wx.Button(win, -1, "five"), 1, wx.EXPAND)
return box
#----------------------------------------------------------------------
def makeSimpleBox5(win):
- box = wxBoxSizer(wxHORIZONTAL)
- box.Add(wxButton(win, 1010, "one"), 0, wxEXPAND)
- box.Add(wxButton(win, 1010, "two"), 0, wxEXPAND)
- box.Add(wxButton(win, 1010, "three"), 3, wxEXPAND)
- box.Add(wxButton(win, 1010, "four"), 1, wxEXPAND)
- box.Add(wxButton(win, 1010, "five"), 1, wxEXPAND)
+ box = wx.BoxSizer(wx.HORIZONTAL)
+ box.Add(wx.Button(win, -1, "one"), 0, wx.EXPAND)
+ box.Add(wx.Button(win, -1, "two"), 0, wx.EXPAND)
+ box.Add(wx.Button(win, -1, "three"), 3, wx.EXPAND)
+ box.Add(wx.Button(win, -1, "four"), 1, wx.EXPAND)
+ box.Add(wx.Button(win, -1, "five"), 1, wx.EXPAND)
return box
#----------------------------------------------------------------------
def makeSimpleBox6(win):
- box = wxBoxSizer(wxHORIZONTAL)
- box.Add(wxButton(win, 1010, "one"), 1, wxALIGN_TOP)
- box.Add(wxButton(win, 1010, "two"), 1, wxEXPAND)
- box.Add(wxButton(win, 1010, "three"), 1, wxALIGN_CENTER)
- box.Add(wxButton(win, 1010, "four"), 1, wxEXPAND)
- box.Add(wxButton(win, 1010, "five"), 1, wxALIGN_BOTTOM)
+ box = wx.BoxSizer(wx.HORIZONTAL)
+ box.Add(wx.Button(win, -1, "one"), 1, wx.ALIGN_TOP)
+ box.Add(wx.Button(win, -1, "two"), 1, wx.EXPAND)
+ box.Add(wx.Button(win, -1, "three"), 1, wx.ALIGN_CENTER)
+ box.Add(wx.Button(win, -1, "four"), 1, wx.EXPAND)
+ box.Add(wx.Button(win, -1, "five"), 1, wx.ALIGN_BOTTOM)
return box
#----------------------------------------------------------------------
def makeSimpleBorder1(win):
- bdr = wxBoxSizer(wxHORIZONTAL)
- btn = wxButton(win, 1010, "border")
- btn.SetSize(wxSize(80, 80))
- bdr.Add(btn, 1, wxEXPAND|wxALL, 15)
+ bdr = wx.BoxSizer(wx.HORIZONTAL)
+ btn = wx.Button(win, -1, "border")
+ btn.SetSize((80, 80))
+ bdr.Add(btn, 1, wx.EXPAND|wx.ALL, 15)
return bdr
#----------------------------------------------------------------------
def makeSimpleBorder2(win):
- bdr = wxBoxSizer(wxHORIZONTAL)
- btn = wxButton(win, 1010, "border")
- btn.SetSize(wxSize(80, 80))
- bdr.Add(btn, 1, wxEXPAND | wxEAST | wxWEST, 15)
+ bdr = wx.BoxSizer(wx.HORIZONTAL)
+ btn = wx.Button(win, -1, "border")
+ btn.SetSize((80, 80))
+ bdr.Add(btn, 1, wx.EXPAND | wx.EAST | wx.WEST, 15)
return bdr
#----------------------------------------------------------------------
def makeSimpleBorder3(win):
- bdr = wxBoxSizer(wxHORIZONTAL)
- btn = wxButton(win, 1010, "border")
- btn.SetSize(wxSize(80, 80))
- bdr.Add(btn, 1, wxEXPAND | wxNORTH | wxWEST, 15)
+ bdr = wx.BoxSizer(wx.HORIZONTAL)
+ btn = wx.Button(win, -1, "border")
+ btn.SetSize((80, 80))
+ bdr.Add(btn, 1, wx.EXPAND | wx.NORTH | wx.WEST, 15)
return bdr
#----------------------------------------------------------------------
def makeBoxInBox(win):
- box = wxBoxSizer(wxVERTICAL)
-
- box.Add(wxButton(win, 1010, "one"), 0, wxEXPAND)
-
- box2 = wxBoxSizer(wxHORIZONTAL)
- box2.Add(wxButton(win, 1010, "two"), 0, wxEXPAND)
- btn3 = wxButton(win, 1010, "three")
- box2.Add(btn3, 0, wxEXPAND)
- box2.Add(wxButton(win, 1010, "four"), 0, wxEXPAND)
- box2.Add(wxButton(win, 1010, "five"), 0, wxEXPAND)
-
- box3 = wxBoxSizer(wxVERTICAL)
- box3.AddMany([ (wxButton(win, 1010, "six"), 0, wxEXPAND),
- (wxButton(win, 1010, "seven"), 2, wxEXPAND),
- (wxButton(win, 1010, "eight"), 1, wxEXPAND),
- (wxButton(win, 1010, "nine"), 1, wxEXPAND),
+ box = wx.BoxSizer(wx.VERTICAL)
+
+ box.Add(wx.Button(win, -1, "one"), 0, wx.EXPAND)
+
+ box2 = wx.BoxSizer(wx.HORIZONTAL)
+ box2.Add(wx.Button(win, -1, "two"), 0, wx.EXPAND)
+ btn3 = wx.Button(win, -1, "three")
+ box2.Add(btn3, 0, wx.EXPAND)
+ box2.Add(wx.Button(win, -1, "four"), 0, wx.EXPAND)
+ box2.Add(wx.Button(win, -1, "five"), 0, wx.EXPAND)
+
+ box3 = wx.BoxSizer(wx.VERTICAL)
+ box3.AddMany([ (wx.Button(win, -1, "six"), 0, wx.EXPAND),
+ (wx.Button(win, -1, "seven"), 2, wx.EXPAND),
+ (wx.Button(win, -1, "eight"), 1, wx.EXPAND),
+ (wx.Button(win, -1, "nine"), 1, wx.EXPAND),
])
- box2.Add(box3, 1, wxEXPAND)
- box.Add(box2, 1, wxEXPAND)
+ box2.Add(box3, 1, wx.EXPAND)
+ box.Add(box2, 1, wx.EXPAND)
- box.Add(wxButton(win, 1010, "ten"), 0, wxEXPAND)
+ box.Add(wx.Button(win, -1, "ten"), 0, wx.EXPAND)
##box.Hide(btn3)
#----------------------------------------------------------------------
def makeBoxInBorder(win):
- bdr = wxBoxSizer(wxHORIZONTAL)
+ bdr = wx.BoxSizer(wx.HORIZONTAL)
box = makeSimpleBox3(win)
- bdr.Add(box, 1, wxEXPAND | wxALL, 15)
+ bdr.Add(box, 1, wx.EXPAND | wx.ALL, 15)
return bdr
#----------------------------------------------------------------------
def makeBorderInBox(win):
- insideBox = wxBoxSizer(wxHORIZONTAL)
-
- box2 = wxBoxSizer(wxHORIZONTAL)
- box2.AddMany([ (wxButton(win, 1010, "one"), 0, wxEXPAND),
- (wxButton(win, 1010, "two"), 0, wxEXPAND),
- (wxButton(win, 1010, "three"), 0, wxEXPAND),
- (wxButton(win, 1010, "four"), 0, wxEXPAND),
- (wxButton(win, 1010, "five"), 0, wxEXPAND),
+ insideBox = wx.BoxSizer(wx.HORIZONTAL)
+
+ box2 = wx.BoxSizer(wx.HORIZONTAL)
+ box2.AddMany([ (wx.Button(win, -1, "one"), 0, wx.EXPAND),
+ (wx.Button(win, -1, "two"), 0, wx.EXPAND),
+ (wx.Button(win, -1, "three"), 0, wx.EXPAND),
+ (wx.Button(win, -1, "four"), 0, wx.EXPAND),
+ (wx.Button(win, -1, "five"), 0, wx.EXPAND),
])
- insideBox.Add(box2, 0, wxEXPAND)
+ insideBox.Add(box2, 0, wx.EXPAND)
- bdr = wxBoxSizer(wxHORIZONTAL)
- bdr.Add(wxButton(win, 1010, "border"), 1, wxEXPAND | wxALL)
- insideBox.Add(bdr, 1, wxEXPAND | wxALL, 20)
+ bdr = wx.BoxSizer(wx.HORIZONTAL)
+ bdr.Add(wx.Button(win, -1, "border"), 1, wx.EXPAND | wx.ALL)
+ insideBox.Add(bdr, 1, wx.EXPAND | wx.ALL, 20)
- box3 = wxBoxSizer(wxVERTICAL)
- box3.AddMany([ (wxButton(win, 1010, "six"), 0, wxEXPAND),
- (wxButton(win, 1010, "seven"), 2, wxEXPAND),
- (wxButton(win, 1010, "eight"), 1, wxEXPAND),
- (wxButton(win, 1010, "nine"), 1, wxEXPAND),
+ box3 = wx.BoxSizer(wx.VERTICAL)
+ box3.AddMany([ (wx.Button(win, -1, "six"), 0, wx.EXPAND),
+ (wx.Button(win, -1, "seven"), 2, wx.EXPAND),
+ (wx.Button(win, -1, "eight"), 1, wx.EXPAND),
+ (wx.Button(win, -1, "nine"), 1, wx.EXPAND),
])
- insideBox.Add(box3, 1, wxEXPAND)
+ insideBox.Add(box3, 1, wx.EXPAND)
- outsideBox = wxBoxSizer(wxVERTICAL)
- outsideBox.Add(wxButton(win, 1010, "top"), 0, wxEXPAND)
- outsideBox.Add(insideBox, 1, wxEXPAND)
- outsideBox.Add(wxButton(win, 1010, "bottom"), 0, wxEXPAND)
+ outsideBox = wx.BoxSizer(wx.VERTICAL)
+ outsideBox.Add(wx.Button(win, -1, "top"), 0, wx.EXPAND)
+ outsideBox.Add(insideBox, 1, wx.EXPAND)
+ outsideBox.Add(wx.Button(win, -1, "bottom"), 0, wx.EXPAND)
return outsideBox
#----------------------------------------------------------------------
def makeGrid1(win):
- gs = wxGridSizer(3, 3, 2, 2) # rows, cols, hgap, vgap
+ gs = wx.GridSizer(3, 3, 2, 2) # rows, cols, hgap, vgap
- gs.AddMany([ (wxButton(win, 1010, 'one'), 0, wxEXPAND),
- (wxButton(win, 1010, 'two'), 0, wxEXPAND),
- (wxButton(win, 1010, 'three'), 0, wxEXPAND),
- (wxButton(win, 1010, 'four'), 0, wxEXPAND),
- (wxButton(win, 1010, 'five'), 0, wxEXPAND),
+ gs.AddMany([ (wx.Button(win, -1, 'one'), 0, wx.EXPAND),
+ (wx.Button(win, -1, 'two'), 0, wx.EXPAND),
+ (wx.Button(win, -1, 'three'), 0, wx.EXPAND),
+ (wx.Button(win, -1, 'four'), 0, wx.EXPAND),
+ (wx.Button(win, -1, 'five'), 0, wx.EXPAND),
#(75, 50),
- (wxButton(win, 1010, 'six'), 0, wxEXPAND),
- (wxButton(win, 1010, 'seven'), 0, wxEXPAND),
- (wxButton(win, 1010, 'eight'), 0, wxEXPAND),
- (wxButton(win, 1010, 'nine'), 0, wxEXPAND),
+ (wx.Button(win, -1, 'six'), 0, wx.EXPAND),
+ (wx.Button(win, -1, 'seven'), 0, wx.EXPAND),
+ (wx.Button(win, -1, 'eight'), 0, wx.EXPAND),
+ (wx.Button(win, -1, 'nine'), 0, wx.EXPAND),
])
return gs
#----------------------------------------------------------------------
def makeGrid2(win):
- gs = wxGridSizer(3, 3) # rows, cols, hgap, vgap
-
- box = wxBoxSizer(wxVERTICAL)
- box.Add(wxButton(win, 1010, 'A'), 0, wxEXPAND)
- box.Add(wxButton(win, 1010, 'B'), 1, wxEXPAND)
-
- gs2 = wxGridSizer(2,2, 4, 4)
- gs2.AddMany([ (wxButton(win, 1010, 'C'), 0, wxEXPAND),
- (wxButton(win, 1010, 'E'), 0, wxEXPAND),
- (wxButton(win, 1010, 'F'), 0, wxEXPAND),
- (wxButton(win, 1010, 'G'), 0, wxEXPAND)])
-
- gs.AddMany([ (wxButton(win, 1010, 'one'), 0, wxALIGN_RIGHT | wxALIGN_BOTTOM),
- (wxButton(win, 1010, 'two'), 0, wxEXPAND),
- (wxButton(win, 1010, 'three'), 0, wxALIGN_LEFT | wxALIGN_BOTTOM),
- (wxButton(win, 1010, 'four'), 0, wxEXPAND),
- (wxButton(win, 1010, 'five'), 0, wxALIGN_CENTER),
- (wxButton(win, 1010, 'six'), 0, wxEXPAND),
- (box, 0, wxEXPAND | wxALL, 10),
- (wxButton(win, 1010, 'eight'), 0, wxEXPAND),
- (gs2, 0, wxEXPAND | wxALL, 4),
+ gs = wx.GridSizer(3, 3) # rows, cols, hgap, vgap
+
+ box = wx.BoxSizer(wx.VERTICAL)
+ box.Add(wx.Button(win, -1, 'A'), 0, wx.EXPAND)
+ box.Add(wx.Button(win, -1, 'B'), 1, wx.EXPAND)
+
+ gs2 = wx.GridSizer(2,2, 4, 4)
+ gs2.AddMany([ (wx.Button(win, -1, 'C'), 0, wx.EXPAND),
+ (wx.Button(win, -1, 'E'), 0, wx.EXPAND),
+ (wx.Button(win, -1, 'F'), 0, wx.EXPAND),
+ (wx.Button(win, -1, 'G'), 0, wx.EXPAND)])
+
+ gs.AddMany([ (wx.Button(win, -1, 'one'), 0, wx.ALIGN_RIGHT | wx.ALIGN_BOTTOM),
+ (wx.Button(win, -1, 'two'), 0, wx.EXPAND),
+ (wx.Button(win, -1, 'three'), 0, wx.ALIGN_LEFT | wx.ALIGN_BOTTOM),
+ (wx.Button(win, -1, 'four'), 0, wx.EXPAND),
+ (wx.Button(win, -1, 'five'), 0, wx.ALIGN_CENTER),
+ (wx.Button(win, -1, 'six'), 0, wx.EXPAND),
+ (box, 0, wx.EXPAND | wx.ALL, 10),
+ (wx.Button(win, -1, 'eight'), 0, wx.EXPAND),
+ (gs2, 0, wx.EXPAND | wx.ALL, 4),
])
return gs
#----------------------------------------------------------------------
def makeGrid3(win):
- gs = wxFlexGridSizer(3, 3, 2, 2) # rows, cols, hgap, vgap
+ gs = wx.FlexGridSizer(3, 3, 2, 2) # rows, cols, hgap, vgap
- gs.AddMany([ (wxButton(win, 1010, 'one'), 0, wxEXPAND),
- (wxButton(win, 1010, 'two'), 0, wxEXPAND),
- (wxButton(win, 1010, 'three'), 0, wxEXPAND),
- (wxButton(win, 1010, 'four'), 0, wxEXPAND),
+ gs.AddMany([ (wx.Button(win, -1, 'one'), 0, wx.EXPAND),
+ (wx.Button(win, -1, 'two'), 0, wx.EXPAND),
+ (wx.Button(win, -1, 'three'), 0, wx.EXPAND),
+ (wx.Button(win, -1, 'four'), 0, wx.EXPAND),
#(wxButton(win, 1010, 'five'), 0, wxEXPAND),
- (175, 50),
- (wxButton(win, 1010, 'six'), 0, wxEXPAND),
- (wxButton(win, 1010, 'seven'), 0, wxEXPAND),
- (wxButton(win, 1010, 'eight'), 0, wxEXPAND),
- (wxButton(win, 1010, 'nine'), 0, wxEXPAND),
+ ((175, 50)),
+ (wx.Button(win, -1, 'six'), 0, wx.EXPAND),
+ (wx.Button(win, -1, 'seven'), 0, wx.EXPAND),
+ (wx.Button(win, -1, 'eight'), 0, wx.EXPAND),
+ (wx.Button(win, -1, 'nine'), 0, wx.EXPAND),
])
gs.AddGrowableRow(0)
#----------------------------------------------------------------------
def makeGrid4(win):
- bpos = wxDefaultPosition
- bsize = wxSize(100, 50)
- gs = wxGridSizer(3, 3, 2, 2) # rows, cols, hgap, vgap
-
- gs.AddMany([ (wxButton(win, 1010, 'one', bpos, bsize),
- 0, wxALIGN_TOP | wxALIGN_LEFT ),
- (wxButton(win, 1010, 'two', bpos, bsize),
- 0, wxALIGN_TOP | wxALIGN_CENTER_HORIZONTAL ),
- (wxButton(win, 1010, 'three', bpos, bsize),
- 0, wxALIGN_TOP | wxALIGN_RIGHT ),
- (wxButton(win, 1010, 'four', bpos, bsize),
- 0, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT ),
- (wxButton(win, 1010, 'five', bpos, bsize),
- 0, wxALIGN_CENTER ),
- (wxButton(win, 1010, 'six', bpos, bsize),
- 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT ),
- (wxButton(win, 1010, 'seven', bpos, bsize),
- 0, wxALIGN_BOTTOM | wxALIGN_LEFT ),
- (wxButton(win, 1010, 'eight', bpos, bsize),
- 0, wxALIGN_BOTTOM | wxALIGN_CENTER_HORIZONTAL ),
- (wxButton(win, 1010, 'nine', bpos, bsize),
- 0, wxALIGN_BOTTOM | wxALIGN_RIGHT ),
+ bpos = wx.DefaultPosition
+ bsize = wx.Size(100, 50)
+ gs = wx.GridSizer(3, 3, 2, 2) # rows, cols, hgap, vgap
+
+ gs.AddMany([ (wx.Button(win, -1, 'one', bpos, bsize),
+ 0, wx.ALIGN_TOP | wx.ALIGN_LEFT ),
+ (wx.Button(win, -1, 'two', bpos, bsize),
+ 0, wx.ALIGN_TOP | wx.ALIGN_CENTER_HORIZONTAL ),
+ (wx.Button(win, -1, 'three', bpos, bsize),
+ 0, wx.ALIGN_TOP | wx.ALIGN_RIGHT ),
+ (wx.Button(win, -1, 'four', bpos, bsize),
+ 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT ),
+ (wx.Button(win, -1, 'five', bpos, bsize),
+ 0, wx.ALIGN_CENTER ),
+ (wx.Button(win, -1, 'six', bpos, bsize),
+ 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT ),
+ (wx.Button(win, -1, 'seven', bpos, bsize),
+ 0, wx.ALIGN_BOTTOM | wx.ALIGN_LEFT ),
+ (wx.Button(win, -1, 'eight', bpos, bsize),
+ 0, wx.ALIGN_BOTTOM | wx.ALIGN_CENTER_HORIZONTAL ),
+ (wx.Button(win, -1, 'nine', bpos, bsize),
+ 0, wx.ALIGN_BOTTOM | wx.ALIGN_RIGHT ),
])
return gs
#----------------------------------------------------------------------
def makeShapes(win):
- bpos = wxDefaultPosition
- bsize = wxSize(100, 50)
- gs = wxGridSizer(3, 3, 2, 2) # rows, cols, hgap, vgap
-
- gs.AddMany([ (wxButton(win, 1010, 'one', bpos, bsize),
- 0, wxSHAPED | wxALIGN_TOP | wxALIGN_LEFT ),
- (wxButton(win, 1010, 'two', bpos, bsize),
- 0, wxSHAPED | wxALIGN_TOP | wxALIGN_CENTER_HORIZONTAL ),
- (wxButton(win, 1010, 'three', bpos, bsize),
- 0, wxSHAPED | wxALIGN_TOP | wxALIGN_RIGHT ),
- (wxButton(win, 1010, 'four', bpos, bsize),
- 0, wxSHAPED | wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT ),
- (wxButton(win, 1010, 'five', bpos, bsize),
- 0, wxSHAPED | wxALIGN_CENTER ),
- (wxButton(win, 1010, 'six', bpos, bsize),
- 0, wxSHAPED | wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT ),
- (wxButton(win, 1010, 'seven', bpos, bsize),
- 0, wxSHAPED | wxALIGN_BOTTOM | wxALIGN_LEFT ),
- (wxButton(win, 1010, 'eight', bpos, bsize),
- 0, wxSHAPED | wxALIGN_BOTTOM | wxALIGN_CENTER_HORIZONTAL ),
- (wxButton(win, 1010, 'nine', bpos, bsize),
- 0, wxSHAPED | wxALIGN_BOTTOM | wxALIGN_RIGHT ),
+ bpos = wx.DefaultPosition
+ bsize = wx.Size(100, 50)
+ gs = wx.GridSizer(3, 3, 2, 2) # rows, cols, hgap, vgap
+
+ gs.AddMany([ (wx.Button(win, -1, 'one', bpos, bsize),
+ 0, wx.SHAPED | wx.ALIGN_TOP | wx.ALIGN_LEFT ),
+ (wx.Button(win, -1, 'two', bpos, bsize),
+ 0, wx.SHAPED | wx.ALIGN_TOP | wx.ALIGN_CENTER_HORIZONTAL ),
+ (wx.Button(win, -1, 'three', bpos, bsize),
+ 0, wx.SHAPED | wx.ALIGN_TOP | wx.ALIGN_RIGHT ),
+ (wx.Button(win, -1, 'four', bpos, bsize),
+ 0, wx.SHAPED | wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT ),
+ (wx.Button(win, -1, 'five', bpos, bsize),
+ 0, wx.SHAPED | wx.ALIGN_CENTER ),
+ (wx.Button(win, -1, 'six', bpos, bsize),
+ 0, wx.SHAPED | wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT ),
+ (wx.Button(win, -1, 'seven', bpos, bsize),
+ 0, wx.SHAPED | wx.ALIGN_BOTTOM | wx.ALIGN_LEFT ),
+ (wx.Button(win, -1, 'eight', bpos, bsize),
+ 0, wx.SHAPED | wx.ALIGN_BOTTOM | wx.ALIGN_CENTER_HORIZONTAL ),
+ (wx.Button(win, -1, 'nine', bpos, bsize),
+ 0, wx.SHAPED | wx.ALIGN_BOTTOM | wx.ALIGN_RIGHT ),
])
return gs
#----------------------------------------------------------------------
def makeSimpleBoxShaped(win):
- box = wxBoxSizer(wxHORIZONTAL)
- box.Add(wxButton(win, 1010, "one"), 0, wxEXPAND)
- box.Add(wxButton(win, 1010, "two"), 0, wxEXPAND)
- box.Add(wxButton(win, 1010, "three"), 0, wxEXPAND)
- box.Add(wxButton(win, 1010, "four"), 0, wxEXPAND)
- box.Add(wxButton(win, 1010, "five"), 1, wxSHAPED)
+ box = wx.BoxSizer(wx.HORIZONTAL)
+ box.Add(wx.Button(win, -1, "one"), 0, wx.EXPAND)
+ box.Add(wx.Button(win, -1, "two"), 0, wx.EXPAND)
+ box.Add(wx.Button(win, -1, "three"), 0, wx.EXPAND)
+ box.Add(wx.Button(win, -1, "four"), 0, wx.EXPAND)
+ box.Add(wx.Button(win, -1, "five"), 1, wx.SHAPED)
return box
),
# ("Percent Sizer", makeSimpleBox6,
-# "You can use the wxBoxSizer like a Percent Sizer. Just make sure that all "
+# "You can use the wx.BoxSizer like a Percent Sizer. Just make sure that all "
# "the weighting factors add up to 100!"
# ),
("", None, ""),
("Simple border sizer", makeSimpleBorder1,
- "The wxBoxSizer can leave empty space around its contents. This one "
+ "The wx.BoxSizer can leave empty space around its contents. This one "
"gives a border all the way around."
),
]
#----------------------------------------------------------------------
-class TestFrame(wxFrame):
+class TestFrame(wx.Frame):
def __init__(self, parent, title, sizerFunc):
- wxFrame.__init__(self, parent, -1, title)
- EVT_BUTTON(self, 1010, self.OnButton)
+ wx.Frame.__init__(self, parent, -1, title)
+ self.Bind(wx.EVT_BUTTON, self.OnButton)
+
+ p = wx.Panel(self, -1)
- self.sizer = sizerFunc(self)
+ self.sizer = sizerFunc(p)
self.CreateStatusBar()
self.SetStatusText("Resize this frame to see how the sizers respond...")
- self.sizer.Fit(self)
+ self.sizer.Fit(p)
- self.SetAutoLayout(True)
- self.SetSizer(self.sizer)
- EVT_CLOSE(self, self.OnCloseWindow)
+ p.SetAutoLayout(True)
+ p.SetSizer(self.sizer)
+ self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
+ self.Fit()
def OnCloseWindow(self, event):
self.MakeModal(False)
-class TestSelectionPanel(wxPanel):
+class TestSelectionPanel(wx.Panel):
def __init__(self, parent, frame):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.frame = frame
- self.list = wxListBox(self, 401,
- wxDLG_PNT(self, 10, 10), wxDLG_SZE(self, 100, 100),
+ self.list = wx.ListBox(self, -1,
+ wx.DLG_PNT(self, 10, 10), wx.DLG_SZE(self, 100, 100),
[])
- EVT_LISTBOX(self, 401, self.OnSelect)
- EVT_LISTBOX_DCLICK(self, 401, self.OnDClick)
+ self.Bind(wx.EVT_LISTBOX, self.OnSelect, id=self.list.GetId())
+ self.Bind(wx.EVT_LISTBOX_DCLICK, self.OnDClick, id=self.list.GetId())
- self.btn = wxButton(self, 402, "Try it!", wxDLG_PNT(self, 120, 10)).SetDefault()
- EVT_BUTTON(self, 402, self.OnDClick)
+ self.btn = wx.Button(self, -1, "Try it!", wx.DLG_PNT(self, 120, 10)).SetDefault()
+ self.Bind(wx.EVT_BUTTON, self.OnDClick)
- self.text = wxTextCtrl(self, -1, "",
- wxDLG_PNT(self, 10, 115),
- wxDLG_SZE(self, 200, 50),
- wxTE_MULTILINE | wxTE_READONLY)
+ self.text = wx.TextCtrl(self, -1, "",
+ wx.DLG_PNT(self, 10, 115),
+ wx.DLG_SZE(self, 200, 50),
+ wx.TE_MULTILINE | wx.TE_READONLY)
for item in theTests:
self.list.Append(item[0])
-
def OnSelect(self, event):
pos = self.list.GetSelection()
self.text.SetValue(theTests[pos][2])
if func:
win = TestFrame(self, title, func)
- win.CentreOnParent(wxBOTH)
+ win.CentreOnParent(wx.BOTH)
win.Show(True)
win.MakeModal(True)
#----------------------------------------------------------------------
-
-
if __name__ == '__main__':
- class MainFrame(wxFrame):
+ class MainFrame(wx.Frame):
def __init__(self):
- wxFrame.__init__(self, None, -1, "Testing...")
+ wx.Frame.__init__(self, None, -1, "Testing...")
self.CreateStatusBar()
- mainmenu = wxMenuBar()
- menu = wxMenu()
+ mainmenu = wx.MenuBar()
+ menu = wx.Menu()
menu.Append(200, 'E&xit', 'Get the heck outta here!')
mainmenu.Append(menu, "&File")
self.SetMenuBar(mainmenu)
- EVT_MENU(self, 200, self.OnExit)
+ self.Bind(wx.EVT_MENU, self.OnExit, id=200)
self.panel = TestSelectionPanel(self, self)
- self.SetSize(wxSize(400, 380))
- EVT_CLOSE(self, self.OnCloseWindow)
+ self.SetSize((400, 380))
+ self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
def OnCloseWindow(self, event):
self.Destroy()
self.Close(True)
- class TestApp(wxApp):
+ class TestApp(wx.App):
def OnInit(self):
frame = MainFrame()
frame.Show(True)
self.SetTopWindow(frame)
return True
- app = TestApp(0)
+ app = TestApp(False)
app.MainLoop()
-from wxPython.wx import *
-from wxPython.gizmos import *
-
-import images
+# 11/13/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+# 11/26/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Bigtime errors on startup. Blows up with a program error.
+# Error:
+#
+# 21:04:11: Debug: ..\..\src\msw\treectrl.cpp(1508): assert "IsVisible(item)"
+# failed: The item you call GetNextVisible() for must be visible itself!
+#
+# I suspect this error is in the lib itself.
+#
+
+import wx
+import wx.gizmos as gizmos
+
+import images
#----------------------------------------------------------------------
-class TestTree(wxRemotelyScrolledTreeCtrl):
- def __init__(self, parent, ID, pos=wxDefaultPosition, size=wxDefaultSize,
- style=wxTR_HAS_BUTTONS):
- wxRemotelyScrolledTreeCtrl.__init__(self, parent, ID, pos, size, style)
+class TestTree(gizmos.RemotelyScrolledTreeCtrl):
+ def __init__(self, parent, style=wx.TR_HAS_BUTTONS):
+ gizmos.RemotelyScrolledTreeCtrl.__init__(self, parent, -1, style=style)
# make an image list
im1 = im2 = -1
- self.il = wxImageList(16, 16)
+ self.il = wx.ImageList(16, 16)
im1 = self.il.Add(images.getFolder1Bitmap())
im2 = self.il.Add(images.getFile1Bitmap())
self.SetImageList(self.il)
# Add some items
root = self.AddRoot("Root")
+
for i in range(30):
item = self.AppendItem(root, "Item %d" % i, im1)
+
for j in range(10):
child = self.AppendItem(item, "Child %d" % j, im2)
-class TestValueWindow(wxTreeCompanionWindow):
- def __init__(self, parent, ID, pos=wxDefaultPosition, size=wxDefaultSize, style=0):
- wxTreeCompanionWindow.__init__(self, parent, ID, pos, size, style)
+class TestValueWindow(gizmos.TreeCompanionWindow):
+ def __init__(self, parent, style=0):
+ gizmos.TreeCompanionWindow.__init__(self, parent, -1, style=style)
self.SetBackgroundColour("WHITE")
- EVT_ERASE_BACKGROUND(self, self.OEB)
+ self.Bind(wx.EVT_ERASE_BACKGROUND, self.OEB)
def OEB(self, evt):
pass
# This method is called to draw each item in the value window
def DrawItem(self, dc, itemId, rect):
tree = self.GetTreeCtrl()
+
if tree:
text = "This is "
parent = tree.GetItemParent(itemId)
+
if parent.IsOk():
ptext = tree.GetItemText(parent)
text = text + ptext + " --> "
+
text = text + tree.GetItemText(itemId)
- pen = wxPen(wxSystemSettings_GetSystemColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID)
+ pen = wx.Pen(
+ wx.SystemSettings_GetSystemColour(wx.SYS_COLOUR_3DLIGHT),
+ 1, wx.SOLID
+ )
+
dc.SetPen(pen)
- dc.SetBrush(wxBrush(self.GetBackgroundColour(), wxSOLID))
- dc.DrawRectangle(rect.x, rect.y, rect.width+1, rect.height+1)
+ dc.SetBrush(wx.Brush(self.GetBackgroundColour(), wx.SOLID))
+ dc.DrawRectangle((rect.x, rect.y), (rect.width+1, rect.height+1))
dc.SetTextForeground("BLACK")
- dc.SetBackgroundMode(wxTRANSPARENT)
+ dc.SetBackgroundMode(wx.TRANSPARENT)
tw, th = dc.GetTextExtent(text)
x = 5
y = rect.y + max(0, (rect.height - th) / 2)
- dc.DrawText(text, x, y)
+ dc.DrawText(text, (x, y))
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.log = log
- scroller = wxSplitterScrolledWindow(self, -1, #(50,50), (350, 250),
- style=wxNO_BORDER | wxCLIP_CHILDREN | wxVSCROLL)
- splitter = wxThinSplitterWindow(scroller, -1, style=wxSP_3DBORDER | wxCLIP_CHILDREN)
+ scroller = gizmos.SplitterScrolledWindow(
+ self, -1, style=wx.NO_BORDER | wx.CLIP_CHILDREN | wx.VSCROLL
+ )
+
+ splitter = gizmos.ThinSplitterWindow(
+ scroller, -1, style=wx.SP_3DBORDER | wx.CLIP_CHILDREN
+ )
+
splitter.SetSashSize(2)
- tree = TestTree(splitter, -1, style = wxTR_HAS_BUTTONS |
- wxTR_NO_LINES |
- wxTR_ROW_LINES |
- #wxTR_HIDE_ROOT |
- wxNO_BORDER )
- valueWindow = TestValueWindow(splitter, -1, style=wxNO_BORDER)
+ tree = TestTree(splitter, -1, style = wx.TR_HAS_BUTTONS |
+ wx.TR_NO_LINES |
+ wx.TR_ROW_LINES |
+ #wx.TR_HIDE_ROOT |
+ wx.NO_BORDER )
+
+ valueWindow = TestValueWindow(splitter, style=wx.NO_BORDER)
splitter.SplitVertically(tree, valueWindow, 150)
scroller.SetTargetWindow(tree)
valueWindow.SetTreeCtrl(tree)
tree.SetCompanionWindow(valueWindow)
- sizer = wxBoxSizer(wxVERTICAL)
- sizer.Add(scroller, 1, wxEXPAND|wxALL, 25)
+ sizer = wx.BoxSizer(wx.VERTICAL)
+ sizer.Add(scroller, 1, wx.EXPAND|wx.ALL, 25)
self.SetAutoLayout(True)
self.SetSizer(sizer)
#----------------------------------------------------------------------
def runTest(frame, nb, log):
- if wxPlatform == "__WXMAC__":
- wxMessageBox("This demo currently fails on the Mac. The problem is being looked into...", "Sorry")
+ if wx.Platform == "__WXMAC__":
+ wx.MessageBox("This demo currently fails on the Mac. The problem is being looked into...", "Sorry")
return
win = TestPanel(nb, log)
#----------------------------------------------------------------------
-
-
-
overview = """\
This demo shows a collection of classes that were designed to operate
together and provide a tree control with additional columns for each
-item. The classes are wxRemotelyScrolledTreeCtrl, wxTreeCompanionWindow,
-wxThinSplitterWindow, and wxSplitterScrolledWindow, some of which may
+item. The classes are wx.RemotelyScrolledTreeCtrl, wx.TreeCompanionWindow,
+wx.ThinSplitterWindow, and wx.SplitterScrolledWindow, some of which may
also be useful by themselves.
"""
-
-from wxPython.wx import *
-from wxPython.lib.printout import PrintTable
-
-import os
+# 11/13/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+# o Color preview example generates deprecation warnings.
+#
+# 11/26/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Note: wx.NamedColour must remain because printout.py requiress it.
+# o printout.py is generating a snootful of errors all related to the
+# requirement for tuples on the base DC calls now
+#
+
+import os
+
+import wx
+import wx.lib.printout as printout
#---------------------------------------------------------------------------
}
-class TablePanel(wxPanel):
+class TablePanel(wx.Panel):
def __init__(self, parent, log, frame):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.log = log
self.frame = frame
- box = wxBoxSizer(wxVERTICAL)
- box.Add(20, 30)
+ box = wx.BoxSizer(wx.VERTICAL)
+ box.Add((20, 30))
keys = buttonDefs.keys()
keys.sort()
+
for k in keys:
text = buttonDefs[k][1]
- btn = wxButton(self, k, text)
- box.Add(btn, 0, wxALIGN_CENTER|wxALL, 15)
- EVT_BUTTON(self, k, self.OnButton)
+ btn = wx.Button(self, k, text)
+ box.Add(btn, 0, wx.ALIGN_CENTER|wx.ALL, 15)
+ self.Bind(wx.EVT_BUTTON, self.OnButton, btn)
self.SetAutoLayout(True)
self.SetSizer(box)
def PreviewWide(self):
self.ReadData()
- prt = PrintTable(self.frame)
+ prt = printout.PrintTable(self.frame)
prt.data = self.data
prt.left_margin = 0.5
prt.set_column = [1.0, 1.0, 1.0, 1.5, 1.0, 3.0]
prt.SetLandscape()
prt.SetColumnLineSize(2, 3)
- prt.SetColumnLineColour(3, wxNamedColour('RED'))
+ prt.SetColumnLineColour(3, wx.NamedColour('RED'))
prt.SetRowLineSize(1, 3)
- prt.SetRowLineColour(5, wxNamedColour('RED'))
+ prt.SetRowLineColour(5, wx.NamedColour('RED'))
- prt.SetHeader("wxWindows Applications")
+ prt.SetHeader("wx.Windows Applications")
prt.SetFooter()
- prt.SetFooter("Date: ", type = "Date", align=wxALIGN_RIGHT, indent = -2, colour = wxNamedColour('RED'))
+ prt.SetFooter("Date: ", type = "Date", align=wx.ALIGN_RIGHT, indent = -2, colour = wx.NamedColour('RED'))
prt.Preview()
def PreviewNarrow(self):
val = self.header
new_header = [val[0], val[1], val[2], val[4], val[5]]
- prt = PrintTable(self.frame)
+ prt = printout.PrintTable(self.frame)
prt.data = new_data
prt.set_column = [ 1, 1, 1, 1, 2]
prt.label = new_header
- prt.SetColAlignment(1, wxALIGN_CENTRE)
- prt.SetColBackgroundColour(0, wxNamedColour('RED'))
- prt.SetColTextColour(0, wxNamedColour('WHITE'))
- prt.SetCellColour(4, 0, wxNamedColour('LIGHT BLUE'))
- prt.SetCellColour(4, 1, wxNamedColour('LIGHT BLUE'))
- prt.SetCellColour(17, 1, wxNamedColour('LIGHT BLUE'))
-
- prt.SetColBackgroundColour(2, wxNamedColour('LIGHT BLUE'))
- prt.SetCellText(4, 2, wxNamedColour('RED'))
-
- prt.SetColTextColour(3, wxNamedColour('RED'))
- prt.label_font_colour = wxNamedColour('WHITE')
- prt.SetHeader("wxWindows Applications", colour = wxNamedColour('RED'))
-
- prt.SetHeader("Printed: ", type = "Date & Time", align=wxALIGN_RIGHT, indent = -2, colour = wxNamedColour('BLUE'))
- prt.SetFooter("Page No", colour = wxNamedColour('RED'), type ="Num")
+ prt.SetColAlignment(1, wx.ALIGN_CENTRE)
+ prt.SetColBackgroundColour(0, wx.NamedColour('RED'))
+ prt.SetColTextColour(0, wx.NamedColour('WHITE'))
+ prt.SetCellColour(4, 0, wx.NamedColour('LIGHT BLUE'))
+ prt.SetCellColour(4, 1, wx.NamedColour('LIGHT BLUE'))
+ prt.SetCellColour(17, 1, wx.NamedColour('LIGHT BLUE'))
+
+ prt.SetColBackgroundColour(2, wx.NamedColour('LIGHT BLUE'))
+ prt.SetCellText(4, 2, wx.NamedColour('RED'))
+
+ prt.SetColTextColour(3, wx.NamedColour('RED'))
+ prt.label_font_colour = wx.NamedColour('WHITE')
+ prt.SetHeader("wxWindows Applications", colour = wx.NamedColour('RED'))
+
+ prt.SetHeader("Printed: ", type = "Date & Time", align=wx.ALIGN_RIGHT, indent = -2, colour = wx.NamedColour('BLUE'))
+ prt.SetFooter("Page No", colour = wx.NamedColour('RED'), type ="Num")
prt.Preview()
def OnPreviewMatrix(self):
for val in range(total_col):
columns.append(hsize)
- prt = PrintTable(self.frame)
+ prt = printout.PrintTable(self.frame)
for row in range(total_row):
value = []
data.append(value)
for col in range(total_col):
- prt.SetColAlignment(col, wxALIGN_CENTRE)
+ prt.SetColAlignment(col, wx.ALIGN_CENTRE)
prt.SetLandscape()
prt.text_font_size = 8
prt.Preview()
def PreviewLine(self):
- prt = PrintTable(self.frame)
+ prt = printout.PrintTable(self.frame)
prt.label = ["Header 1", "Header 2", "Header 3"]
prt.set_column = []
prt.data = [["Row 1", "1", "2"], ["Row 2", "3", "4\nNew Line to see if it also can wrap around the cell region properly\nAnother new line"]]
def PrintWide(self):
self.ReadData()
- prt = PrintTable(self.frame)
+ prt = printout.PrintTable(self.frame)
prt.data = self.data
prt.left_margin = 0.5
-import os
-import wxPython.lib.printout
-
-
-
-
overview = """\
<html><body>
<h2>Table Printing</h2>
when the framework allows for it.
-""" % os.path.join(os.path.dirname(wxPython.lib.printout.__file__), "printout.py")
+""" % os.path.join(os.path.dirname(printout.__file__), "printout.py")
-
-from wxPython.wx import *
-from wxPython.lib import newevent
-
-import thread
-import time
-from whrandom import random
+# 11/13/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+# o Replaced deprecated whrandom with random module.
+#
+# 11/13/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Currently uses lib.newevent; should probably be updated to use
+# new-style event binder. OTOH, this is the only place we get
+# to see that library used that I know of.
+#
+
+import random
+import time
+import thread
+
+import wx
+import wx.lib.newevent
#----------------------------------------------------------------------
# This creates a new Event class and a EVT binder function
-UpdateBarEvent, EVT_UPDATE_BARGRAPH = newevent.NewEvent()
+(UpdateBarEvent, EVT_UPDATE_BARGRAPH) = wx.lib.newevent.NewEvent()
#----------------------------------------------------------------------
def Run(self):
while self.keepGoing:
evt = UpdateBarEvent(barNum = self.barNum, value = int(self.val))
- wxPostEvent(self.win, evt)
+ wx.PostEvent(self.win.GetEventHandler(), evt)
#del evt
- sleeptime = (random() * 2) + 0.5
+ sleeptime = (random.random() * 2) + 0.5
time.sleep(sleeptime/4)
sleeptime = sleeptime * 5
- if int(random() * 2):
+ if int(random.random() * 2):
self.val = self.val + sleeptime
else:
self.val = self.val - sleeptime
#----------------------------------------------------------------------
-class GraphWindow(wxWindow):
+class GraphWindow(wx.Window):
def __init__(self, parent, labels):
- wxWindow.__init__(self, parent, -1)
+ wx.Window.__init__(self, parent, -1)
self.values = []
for label in labels:
self.values.append((label, 0))
- font = wxFont(12, wxSWISS, wxNORMAL, wxBOLD)
+ font = wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD)
self.SetFont(font)
- self.colors = [ wxRED, wxGREEN, wxBLUE, wxCYAN,
+ self.colors = [ wx.RED, wx.GREEN, wx.BLUE, wx.CYAN,
"Yellow", "Navy" ]
- EVT_ERASE_BACKGROUND(self, self.OnEraseBackground)
- EVT_PAINT(self, self.OnPaint)
+ self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
+ self.Bind(wx.EVT_PAINT, self.OnPaint)
def SetValue(self, index, value):
def SetFont(self, font):
- wxWindow.SetFont(self, font)
+ wx.Window.SetFont(self, font)
wmax = hmax = 0
for label, val in self.values:
w,h = self.GetTextExtent(label)
def Draw(self, dc, size):
dc.SetFont(self.GetFont())
- dc.SetTextForeground(wxBLUE)
- dc.SetBackground(wxBrush(self.GetBackgroundColour()))
+ dc.SetTextForeground(wx.BLUE)
+ dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
dc.Clear()
dc.SetPen(wxPen(wxBLACK, 3, wxSOLID))
dc.DrawLine((self.linePos, 0), (self.linePos, size.height-10))
dc.DrawRectangle((self.linePos+3, ypos), (val, bh))
ypos = ypos + 2*bh
- if ypos > size.height-10:
+ if ypos > size[1]-10:
break
def OnPaint(self, evt):
- size = self.GetSize()
- bmp = wxEmptyBitmap(size.width, size.height)
- dc = wxMemoryDC()
+ width, height = self.GetSize()
+ bmp = wx.EmptyBitmap(width, height)
+
+ dc = wx.MemoryDC()
dc.SelectObject(bmp)
- self.Draw(dc, size)
- wdc = wxPaintDC(self)
+ self.Draw(dc, (width, height))
+
+ wdc = wx.PaintDC(self)
wdc.BeginDrawing()
wdc.Blit((0,0), size, dc, (0,0))
wdc.EndDrawing()
- dc.SelectObject(wxNullBitmap)
+ dc.SelectObject(wx.NullBitmap)
def OnEraseBackground(self, evt):
#----------------------------------------------------------------------
-class TestFrame(wxFrame):
+class TestFrame(wx.Frame):
def __init__(self, parent, log):
- wxFrame.__init__(self, parent, -1, "Thread Test", size=(450,300))
+ wx.Frame.__init__(self, parent, -1, "Thread Test", size=(450,300))
self.log = log
#self.CenterOnParent()
- panel = wxPanel(self, -1)
- panel.SetFont(wxFont(10, wxSWISS, wxNORMAL, wxBOLD))
- wxStaticText(panel, -1,
+ panel = wx.Panel(self, -1)
+ panel.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
+ wx.StaticText(panel, -1,
"This demo shows multiple threads interacting with this\n"
"window by sending events to it, one thread for each bar.",
- wxPoint(5,5))
+ (5,5))
panel.Fit()
self.graph = GraphWindow(self, ['Zero', 'One', 'Two', 'Three', 'Four',
'Five', 'Six', 'Seven'])
self.graph.SetSize((450, self.graph.GetBestHeight()))
- sizer = wxBoxSizer(wxVERTICAL)
- sizer.Add(panel, 0, wxEXPAND)
- sizer.Add(self.graph, 1, wxEXPAND)
+ sizer = wx.BoxSizer(wx.VERTICAL)
+ sizer.Add(panel, 0, wx.EXPAND)
+ sizer.Add(self.graph, 1, wx.EXPAND)
self.SetSizer(sizer)
self.SetAutoLayout(True)
sizer.Fit(self)
- EVT_UPDATE_BARGRAPH(self, self.OnUpdate)
+ self.Bind(EVT_UPDATE_BARGRAPH, self.OnUpdate)
+
self.threads = []
self.threads.append(CalcBarThread(self, 0, 50))
self.threads.append(CalcBarThread(self, 1, 75))
for t in self.threads:
t.Start()
- EVT_CLOSE(self, self.OnCloseWindow)
+ self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
def OnUpdate(self, evt):
def OnCloseWindow(self, evt):
- busy = wxBusyInfo("One moment please, waiting for threads to die...")
- wxYield()
+ busy = wx.BusyInfo("One moment please, waiting for threads to die...")
+ wx.Yield()
+
for t in self.threads:
t.Stop()
+
running = 1
+
while running:
running = 0
+
for t in self.threads:
running = running + t.IsRunning()
+
time.sleep(0.1)
+
self.Destroy()
Since wxPython already makes extensive use of event handlers, it is a
logical extension to allow events to be sent to GUI objects from
-alternate threads. A function called wxPostEvent allows you to do
+alternate threads. A function called wx.PostEvent allows you to do
this. It accepts an event and an event handler (window) and instead
of sending the event immediately in the current context like
ProcessEvent does, it processes it later from the context of the GUI
#
# Throbber.py - Cliff Wells <clifford.wells@attbi.com>
#
+# 11/23/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+
+import wx
+import wx.lib.rcsizer as rcs
+import wx.lib.throbber as throb
-from wxPython.wx import *
-from wxPython.lib.rcsizer import RowColSizer
-from wxPython.lib.throbber import Throbber, __doc__ as docString
import throbImages # this was created using a modified version of img2py
+from wx.lib.throbber import __doc__ as docString
+
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.log = log
# create the throbbers
for i in throbImages.index
if i not in ['eclouds', 'logo']]
- self.throbbers['plain']['throbber'] = Throbber(self, -1,
- images, size=(36, 36),
- frameDelay = 0.1)
- self.throbbers['reverse']['throbber'] = Throbber(self, -1, images, #size=(36, 36),
- frameDelay = 0.07)
+ self.throbbers['plain']['throbber'] = \
+ throb.Throbber(self, -1, images, size=(36, 36),frameDelay = 0.1)
+
+ self.throbbers['reverse']['throbber'] = \
+ throb.Throbber(self, -1, images, frameDelay = 0.07)
+
self.throbbers['reverse']['throbber'].Reverse()
- self.throbbers['autoreverse']['throbber'] = Throbber(self, -1,
- images, #size=(36, 36),
- frameDelay = 0.1,
- reverse = True)
+
+ self.throbbers['autoreverse']['throbber'] = \
+ throb.Throbber(self, -1, images, frameDelay = 0.1, reverse = True)
+
self.throbbers['autoreverse']['throbber'].sequence.append(0)
- self.throbbers['label']['throbber'] = Throbber(self, -1,
- images, #size=(36, 36),
- frameDelay = 0.1,
- label = 'Label')
- self.throbbers['label']['throbber'].SetFont(wxFont(pointSize = 10,
- family = wxDEFAULT,
- style = wxNORMAL,
- weight = wxBOLD))
- self.throbbers['overlay']['throbber'] = Throbber(self, -1,
- images, #size=(36, 36),
- frameDelay = 0.1,
- overlay = throbImages.catalog['logo'].getBitmap())
- self.throbbers['overlay+text']['throbber'] = Throbber(self, -1,
- images, #size=(36, 36),
- frameDelay = 0.1,
- overlay = throbImages.catalog['logo'].getBitmap(),
- label = "Python!")
- self.throbbers['overlay+text']['throbber'].SetFont(wxFont(pointSize = 8,
- family = wxDEFAULT,
- style = wxNORMAL,
- weight = wxBOLD))
+ self.throbbers['label']['throbber'] = \
+ throb.Throbber(self, -1, images, frameDelay = 0.1, label = 'Label')
+
+ self.throbbers['label']['throbber'].SetFont(wx.Font(
+ pointSize = 10, family = wx.DEFAULT, style = wx.NORMAL, weight = wx.BOLD
+ ))
+
+ self.throbbers['overlay']['throbber'] = \
+ throb.Throbber(
+ self, -1, images, frameDelay = 0.1,
+ overlay = throbImages.catalog['logo'].getBitmap()
+ )
+
+ self.throbbers['overlay+text']['throbber'] = \
+ throb.Throbber(
+ self, -1, images, frameDelay = 0.1,
+ overlay = throbImages.catalog['logo'].getBitmap(), label = "Python!"
+ )
+
+ self.throbbers['overlay+text']['throbber'].SetFont(wx.Font(
+ pointSize = 8, family = wx.DEFAULT, style = wx.NORMAL, weight = wx.BOLD
+ ))
# this throbber is created using a single, composite image
- self.otherThrobber = Throbber(self, -1,
- throbImages.catalog['eclouds'].getBitmap(), #size=(48, 48),
- frameDelay = 0.15,
- frames = 12,
- frameWidth = 48,
- label = "Stop")
+ self.otherThrobber = throb.Throbber(
+ self, -1, throbImages.catalog['eclouds'].getBitmap(), frameDelay = 0.15,
+ frames = 12, frameWidth = 48, label = "Stop"
+ )
- EVT_LEFT_DOWN(self.otherThrobber, self.OnClickThrobber)
+ self.otherThrobber.Bind(wx.EVT_LEFT_DOWN, self.OnClickThrobber)
- box = wxBoxSizer(wxVERTICAL)
- sizer = RowColSizer()
- box.Add(sizer, 1, wxEXPAND|wxALL, 5)
+ box = wx.BoxSizer(wx.VERTICAL)
+ sizer = rcs.RowColSizer()
+ box.Add(sizer, 1, wx.EXPAND|wx.ALL, 5)
sizer.AddGrowableCol(1)
- sizer.Add(self.otherThrobber, row = 0, col = 2, rowspan = 4, flag = wxALIGN_CENTER_VERTICAL)
+ sizer.Add(
+ self.otherThrobber, row = 0, col = 2, rowspan = 4,
+ flag = wx.ALIGN_CENTER_VERTICAL
+ )
row = 2
+
# use a list so we can keep our order
for t in ['plain', 'reverse', 'autoreverse', 'label', 'overlay', 'overlay+text']:
- sizer.Add(self.throbbers[t]['throbber'], row = row, col = 0, flag = wxALIGN_CENTER|wxALL, border=2)
- sizer.Add(wxStaticText(self, -1, self.throbbers[t]['text']), row = row, col = 1,
- flag = wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT)
+ sizer.Add(
+ self.throbbers[t]['throbber'], row = row, col = 0,
+ flag = wx.ALIGN_CENTER|wx.ALL, border=2
+ )
+
+ sizer.Add(
+ wx.StaticText(self, -1, self.throbbers[t]['text']),
+ row = row, col = 1, flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT
+ )
+
row += 1
# start and stop buttons
- startButton = wxButton(self, -1, "Start")
- EVT_BUTTON(self, startButton.GetId(), self.OnStartAnimation)
- stopButton = wxButton(self, -1, "Stop")
- EVT_BUTTON(self, stopButton.GetId(), self.OnStopAnimation)
+ startButton = wx.Button(self, -1, "Start")
+ self.Bind(wx.EVT_BUTTON, self.OnStartAnimation, id=startButton.GetId())
+
+ stopButton = wx.Button(self, -1, "Stop")
+ self.Bind(wx.EVT_BUTTON, self.OnStopAnimation, id=stopButton.GetId())
- buttonBox = wxBoxSizer(wxHORIZONTAL)
+ buttonBox = wx.BoxSizer(wx.HORIZONTAL)
buttonBox.AddMany([
- (startButton, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5),
- (stopButton, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5),
+ (startButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
+ (stopButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
])
sizer.Add(buttonBox,
row = len(self.throbbers) + 3,
col = 0,
colspan = 3,
- flag = wxALIGN_CENTER)
+ flag = wx.ALIGN_CENTER
+ )
self.SetSizer(box)
self.SetAutoLayout(True)
for t in self.throbbers.keys():
self.throbbers[t]['throbber'].Start()
+
self.otherThrobber.Start()
self.otherThrobber.Reverse()
- EVT_WINDOW_DESTROY(self, self.OnDestroy)
+ self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
def OnDestroy(self, event):
self.log.write("got destroy event")
#----------------------------------------------------------------------
def runTest(frame, nb, log):
- if wxPlatform == "__WXMAC__":
- wxMessageBox("This demo currently fails on the Mac.",
+ if wx.Platform == "__WXMAC__":
+ wx.MessageBox("This demo currently fails on the Mac.",
"Sorry")
return
else:
+# 11/15/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
+import wx
#----------------------------------------------------------------------
-class MyURLDropTarget(wxPyDropTarget):
+class MyURLDropTarget(wx.PyDropTarget):
def __init__(self, window):
- wxPyDropTarget.__init__(self)
+ wx.PyDropTarget.__init__(self)
self.window = window
- self.data = wxURLDataObject();
+ self.data = wx.URLDataObject();
self.SetDataObject(self.data)
def OnDragOver(self, x, y, d):
- return wxDragLink
+ return wx.DragLink
def OnData(self, x, y, d):
if not self.GetData():
- return wxDragNone
+ return wx.DragNone
url = self.data.GetURL()
self.window.AppendText(url + "\n")
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.SetAutoLayout(True)
- outsideSizer = wxBoxSizer(wxVERTICAL)
+ outsideSizer = wx.BoxSizer(wx.VERTICAL)
msg = "Drag-And-Drop of URLs"
- text = wxStaticText(self, -1, "", style=wxALIGN_CENTRE)
- text.SetFont(wxFont(24, wxSWISS, wxNORMAL, wxBOLD, False))
+ text = wx.StaticText(self, -1, "", style=wx.ALIGN_CENTRE)
+ text.SetFont(wx.Font(24, wx.SWISS, wx.NORMAL, wx.BOLD, False))
text.SetLabel(msg)
w,h = text.GetTextExtent(msg)
text.SetSize(wxSize(w,h+1))
outsideSizer.Add(wxStaticLine(self, -1), 0, wxEXPAND)
outsideSizer.Add((20,20))
- self.SetFont(wxFont(10, wxSWISS, wxNORMAL, wxBOLD, False))
+ self.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD, False))
- inSizer = wxFlexGridSizer(2, 2, 5, 5)
+ inSizer = wx.FlexGridSizer(2, 2, 5, 5)
inSizer.AddGrowableCol(0)
inSizer.Add((20,20))
inSizer.Add((20,20))
inSizer.Add(wxStaticText(self, -1,
"Drag URLs from your browser to\nthis window:",
- style = wxALIGN_RIGHT),
- 0, wxALIGN_RIGHT )
- self.dropText = wxTextCtrl(self, -1, "", size=(380, 180),
- style=wxTE_MULTILINE|wxTE_READONLY)
- inSizer.Add(self.dropText, 0, wxEXPAND)
+ style = wx.ALIGN_RIGHT),
+ 0, wx.ALIGN_RIGHT )
+ self.dropText = wx.TextCtrl(self, -1, "", size=(380, 180),
+ style=wx.TE_MULTILINE|wx.TE_READONLY)
+ inSizer.Add(self.dropText, 0, wx.EXPAND)
- inSizer.Add(wxStaticText(self, -1,
+ inSizer.Add(wx.StaticText(self, -1,
"Drag this URL to your browser:",
- style = wxALIGN_RIGHT),
- 0, wxALIGN_RIGHT )
- self.dragText = wxTextCtrl(self, -1, "http://wxPython.org/")
- inSizer.Add(self.dragText, 0, wxEXPAND)
- EVT_MOTION(self.dragText, self.OnStartDrag)
+ style = wx.ALIGN_RIGHT),
+ 0, wx.ALIGN_RIGHT )
+ self.dragText = wx.TextCtrl(self, -1, "http://wxPython.org/")
+ inSizer.Add(self.dragText, 0, wx.EXPAND)
+ self.dragText.Bind(wx.EVT_MOTION, self.OnStartDrag)
-## inSizer.Add(wxStaticText(self, -1,
+## inSizer.Add(wx.StaticText(self, -1,
## "Drag this TEXT to your browser:",
-## style = wxALIGN_RIGHT),
-## 0, wxALIGN_RIGHT )
-## self.dragText2 = wxTextCtrl(self, -1, "http://wxPython.org/")
-## inSizer.Add(self.dragText2, 0, wxEXPAND)
-## EVT_MOTION(self.dragText2, self.OnStartDrag2)
+## style = wx.ALIGN_RIGHT),
+## 0, wx.ALIGN_RIGHT )
+## self.dragText2 = wx.TextCtrl(self, -1, "http://wxPython.org/")
+## inSizer.Add(self.dragText2, 0, wx.EXPAND)
+## self.dragText2.Bind(EVT_MOTION, self.OnStartDrag2)
- outsideSizer.Add(inSizer, 1, wxEXPAND)
+ outsideSizer.Add(inSizer, 1, wx.EXPAND)
self.SetSizer(outsideSizer)
-
self.dropText.SetDropTarget(MyURLDropTarget(self.dropText))
-
def OnStartDrag(self, evt):
if evt.Dragging():
url = self.dragText.GetValue()
- data = wxURLDataObject()
+ data = wx.URLDataObject()
data.SetURL(url)
- dropSource = wxDropSource(self.dragText)
+ dropSource = wx.DropSource(self.dragText)
dropSource.SetData(data)
result = dropSource.DoDragDrop()
def OnStartDrag2(self, evt):
if evt.Dragging():
url = self.dragText2.GetValue()
- data = wxTextDataObject()
+ data = wx.TextDataObject()
data.SetText(url)
- dropSource = wxDropSource(self.dragText2)
+ dropSource = wx.DropSource(self.dragText2)
dropSource.SetData(data)
result = dropSource.DoDragDrop()
+# 11/13/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-
-from wxPython.wx import *
+import wx
#----------------------------------------------------------------------
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
self.log = log
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
- box = wxBoxSizer(wxVERTICAL)
+ box = wx.BoxSizer(wx.VERTICAL)
- if not wxUSE_UNICODE:
+ if not wx.USE_UNICODE:
self.AddLine(box)
self.AddText(box, "Sorry, this wxPython was not built with Unicode support.",
- font = wxFont(12, wxSWISS, wxNORMAL, wxBOLD))
+ font = wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD))
self.AddLine(box)
else:
f = self.GetFont()
- font = wxFont(14, f.GetFamily(), f.GetStyle(), wxBOLD, False,
+ font = wx.Font(14, f.GetFamily(), f.GetStyle(), wx.BOLD, False,
f.GetFaceName(), f.GetEncoding())
self.AddLine(box)
self.AddLine(box)
- border = wxBoxSizer(wxVERTICAL)
- border.Add(box, 1, wxEXPAND|wxALL, 10)
+ border = wx.BoxSizer(wx.VERTICAL)
+ border.Add(box, 1, wx.EXPAND|wx.ALL, 10)
self.SetAutoLayout(True)
self.SetSizer(border)
def AddLine(self, sizer):
- sizer.Add(wxStaticLine(self, -1), 0, wxEXPAND)
+ sizer.Add(wx.StaticLine(self, -1), 0, wx.EXPAND)
def AddText(self, sizer, text1, text2='', lang='', font=None):
# create some controls
- lang = wxStaticText(self, -1, lang)
- text1 = wxStaticText(self, -1, text1)
- text2 = wxStaticText(self, -1, text2, style=wxALIGN_RIGHT)
+ lang = wx.StaticText(self, -1, lang)
+ text1 = wx.StaticText(self, -1, text1)
+ text2 = wx.StaticText(self, -1, text2, style=wx.ALIGN_RIGHT)
if font is not None:
text1.SetFont(font)
# put them in a sizer
- row = wxBoxSizer(wxHORIZONTAL)
+ row = wx.BoxSizer(wx.HORIZONTAL)
row.Add(lang)
- row.Add(15,10)
- row.Add(text1, 1, wxEXPAND)
+ row.Add((15,10))
+ row.Add(text1, 1, wx.EXPAND)
row.Add(text2)
# put the row in the main sizer
- sizer.Add(row, 0, wxEXPAND|wxALL, 5)
+ sizer.Add(row, 0, wx.EXPAND|wx.ALL, 5)
#----------------------------------------------------------------------
+# 11/22/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-import sys
+import sys
+import wx
py2 = sys.version[0] == '2'
-from wxPython.wx import *
try:
if py2:
from xml.parsers import expat
if not haveXML:
def runTest(frame, nb, log):
- dlg = wxMessageDialog(frame, 'This demo requires the XML package. '
- 'See http://www.python.org/sigs/xml-sig/',
- 'Sorry', wxOK | wxICON_INFORMATION)
+ dlg = wx.MessageDialog(
+ frame, 'This demo requires the XML package. '
+ 'See http://www.python.org/sigs/xml-sig/',
+ 'Sorry', wx.OK | wx.ICON_INFORMATION
+ )
+
dlg.ShowModal()
dlg.Destroy()
else:
- class XMLTree(wxTreeCtrl):
+ class XMLTree(wx.TreeCtrl):
def __init__(self, parent, ID):
- wxTreeCtrl.__init__(self, parent, ID)
+ wx.TreeCtrl.__init__(self, parent, ID)
self.nodeStack = [self.AddRoot("Root")]
# Trees need an image list to do DnD...
- self.il = wxImageList(16,16)
+ self.il = wx.ImageList(16,16)
self.SetImageList(self.il)
# event handlers for DnD
- EVT_TREE_BEGIN_DRAG(self, ID, self.OnBeginDrag)
- EVT_TREE_END_DRAG(self, ID, self.OnEndDrag)
+ self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnBeginDrag)
+ self.Bind(wx.EVT_TREE_END_DRAG, self.OnEndDrag)
def OnBeginDrag(self, event):
item = event.GetItem()
+
if item != self.GetRootItem():
self.draggingItem = item
event.Allow() # if DnD of this item is okay Allow it.
def StartElement(self, name, attrs ):
if py2:
name = name.encode()
+
id = self.AppendItem(self.nodeStack[-1], name)
self.nodeStack.append(id)
if data.strip():
if py2:
data = data.encode()
+
self.AppendItem(self.nodeStack[-1], data)
-
-
-
overview = """\
"""
-
-
-
if __name__ == '__main__':
import sys,os
import run
#!/usr/bin/env python
#---------------------------------------------------------------------------
+# 11/9/2003 - Jeff Grimmett (grimmtooth@softhome.net
+#
+# o Updated for V2.5
+# o Mainloop is freezing up app.
+#
+
"""
This demo attempts to override the C++ MainLoop and implement it
in Python. This is not part of the demo framework.
THIS FEATURE IS STILL EXPERIMENTAL...
"""
-
-import wx # This module uses the new wx namespace
import time
-
+import wx
#---------------------------------------------------------------------------
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title,
- wx.Point(100, 100), wx.Size(160, 150))
+ (100, 100), (160, 150))
- wx.EVT_SIZE(self, self.OnSize)
- wx.EVT_MOVE(self, self.OnMove)
- wx.EVT_CLOSE(self, self.OnCloseWindow)
- wx.EVT_IDLE(self, self.OnIdle)
+ self.Bind(wx.EVT_SIZE, self.OnSize)
+ self.Bind(wx.EVT_MOVE, self.OnMove)
+ self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
+ self.Bind(wx.EVT_IDLE, self.OnIdle)
self.count = 0
panel = wx.Panel(self, -1)
wx.StaticText(panel, -1, "Size:",
- wx.DLG_PNT(panel, wx.Point(4, 4)), wx.DefaultSize)
+ wx.DLG_PNT(panel, (4, 4)), wx.DefaultSize)
wx.StaticText(panel, -1, "Pos:",
- wx.DLG_PNT(panel, wx.Point(4, 16)), wx.DefaultSize)
+ wx.DLG_PNT(panel, (4, 16)), wx.DefaultSize)
wx.StaticText(panel, -1, "Idle:",
- wx.DLG_PNT(panel, wx.Point(4, 28)), wx.DefaultSize)
+ wx.DLG_PNT(panel, (4, 28)), wx.DefaultSize)
self.sizeCtrl = wx.TextCtrl(panel, -1, "",
- wx.DLG_PNT(panel, wx.Point(24, 4)),
- wx.DLG_SZE(panel, wx.Size(36, -1)),
+ wx.DLG_PNT(panel, (24, 4)),
+ wx.DLG_SZE(panel, (36, -1)),
wx.TE_READONLY)
self.posCtrl = wx.TextCtrl(panel, -1, "",
- wx.DLG_PNT(panel, wx.Point(24, 16)),
- wx.DLG_SZE(panel, wx.Size(36, -1)),
+ wx.DLG_PNT(panel, (24, 16)),
+ wx.DLG_SZE(panel, (36, -1)),
wx.TE_READONLY)
self.idleCtrl = wx.TextCtrl(panel, -1, "",
- wx.DLG_PNT(panel, wx.Point(24, 28)),
- wx.DLG_SZE(panel, wx.Size(36, -1)),
+ wx.DLG_PNT(panel, (24, 28)),
+ wx.DLG_SZE(panel, (36, -1)),
wx.TE_READONLY)
return True
-app = MyApp(0)
+app = MyApp(False)
app.MainLoop()
#!/usr/bin/env python
#----------------------------------------------------------------------
+# 11/5/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Modified for wx namespace
+#
"""
This is a way to save the startup time when running img2py on lots of
"""
import sys
-from wxPython.tools import img2py
+
+from wx.tools import img2py
command_lines = [
-
-from wxPython.wx import *
-from wxPython.lib.infoframe import *
+# 11/12/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+# o wx module doesn't like the doc string.
+#
+# 11/25/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Library didn't get hit by the wx renamer.
+# o Docstring issues resolved.
+#
+
+import sys
+
+import wx
+import wx.lib.infoframe as infoframe
#----------------------------------------------------------------------
-class MyFrame(wxFrame):
- def __init__(self,output):
- wxFrame.__init__(self,None,-1,"Close me...",size=(300,100))
- menubar = wxMenuBar()
- menu = wxMenu()
- mID = wxNewId()
- menu.Append(mID,"&Enable output","Display output frame")
- EVT_MENU(self,mID,output.EnableOutput)
- mID = wxNewId()
- menu.Append(mID,"&Disable output","Close output frame")
- EVT_MENU(self,mID,output.DisableOutput)
- menubar.Append(menu,"&Output")
+class MyFrame(wx.Frame):
+ def __init__(self, output):
+ wx.Frame.__init__(self, None, -1, "Close me...", size=(300,100))
+
+ menubar = wx.MenuBar()
+
+ # Output menu
+ menu = wx.Menu()
+
+ # Enable output menu item
+ mID = wx.NewId()
+ menu.Append(mID, "&Enable output", "Display output frame")
+ self.Bind(wx.EVT_MENU, output.EnableOutput, id=mID)
+
+ # Disable output menu item
+ mID = wx.NewId()
+ menu.Append(mID, "&Disable output", "Close output frame")
+ self.Bind(wx.EVT_MENU, output.DisableOutput, id=mID)
+
+ # Attach the menu to our menu bar
+ menubar.Append(menu, "&Output")
+
+ # Attach menu bar to frame
self.SetMenuBar(menubar)
+
+ # Point to ourselves as the output object's parent.
output.SetParent(self)
- output.SetOtherMenuBar(menubar,menuname="Output")
- EVT_CLOSE(self,self.OnClose)
- EVT_TIMER(self, -1, self.OnTimer)
+
+ # Associate menu bar with output object
+ output.SetOtherMenuBar(menubar, menuname="Output")
+
+ self.Bind(wx.EVT_CLOSE, self.OnClose)
+ # We're going to set up a timer; set up an event handler for it.
+ self.Bind(wx.EVT_TIMER, self.OnTimer)
- self.timer = wxTimer(self, -1)
+ # Set up a timer for demo purposes
+ self.timer = wx.Timer(self, -1)
self.timer.Start(1000)
+ # Get a copy of stdout and set it aside. We'll use it later.
self.save_stdout = sys.stdout
+
+ # Now point to the output object for stdout
sys.stdout = self.output = output
+ # ... and use it.
print "Hello!"
def OnClose(self,event):
+ # We stored a pointer to the original stdout above in .__init__(), and
+ # here we restore it before closing the window.
sys.stdout = self.save_stdout
+
+ # Clean up
self.output.close()
self.timer.Stop()
self.timer = None
+
self.Destroy()
+ # Event handler for timer events.
def OnTimer(self, evt):
print "This was printed with \"print\""
#----------------------------------------------------------------------
-from wxPython.lib import infoframe
overview = infoframe.__doc__
def runTest(frame, nb, log):
This method is used by the wxPython Demo Framework for integrating
this demo with the rest.
"""
- win = MyFrame(wxPyInformationalMessagesFrame())
+ win = MyFrame(infoframe.wxPyInformationalMessagesFrame())
frame.otherWin = win
win.Show(1)
## sys.stdout.close()
## self.Destroy()
- class MyApp(wxApp):
- outputWindowClass = wxPyInformationalMessagesFrame
+ # Override the default output window and point it to the
+ # custom class.
+ #>>Todo: wx renamer didn't get this
+ outputWindowClass = infoframe.wxPyInformationalMessagesFrame
+
def OnInit(self):
+
+ # At this point, we should probably check to see if self.stdioWin
+ # is actually pointed to something. By default, wx.App() sets this
+ # attribute to None. This causes problems when setting up the menus
+ # in MyFrame() above. On the other hand, since there's little that
+ # can be done at this point, you might be better served putting
+ # an error handler directly into MyFrame().
+ #
+ # That's in practice. In the case of this demo, the whole point
+ # of the exercise is to demonstrate the window, so we're being
+ # just a little lazy for clarity's sake. But do be careful in
+ # a 'real world' implementation :-)
+
frame = MyFrame(self.stdioWin)
frame.Show(True)
self.SetTopWindow(frame)
- if isinstance(sys.stdout,wxPyInformationalMessagesFrame):
+
+ # Associate the frame with stdout.
+ #>>Todo: wx renamer didn't get this
+ if isinstance(sys.stdout, infoframe.wxPyInformationalMessagesFrame):
sys.stdout.SetParent(frame)
- #self.redirectStdio(None)# this is done automatically
- # by the MyApp(1) call below
+
print "Starting.\n",
return True
- app = MyApp(1)
+ # *extremely important*
+ #
+ # In this demo, if the redirect flag is set to False, the infoframe will not
+ # be created or used. All output will go to the default stdout, which in this
+ # case will cause the app to throw an exception. In a real app, you should
+ # probably plan ahead and add a check before forging ahead. See suggestion above.
+ app = MyApp(True)
app.MainLoop()
+++ /dev/null
-
-#----------------------------------------------------------------------
-# A very simple wxPython example. Just a wxFrame, wxPanel,
-# wxStaticText, wxButton, and a wxBoxSizer, but it shows the basic
-# structure of any wxPython application.
-#----------------------------------------------------------------------
-
-from wxPython.wx import *
-print "wxVERSION_STRING = ", wxVERSION_STRING
-
-class MyFrame(wxFrame):
- """
- This is MyFrame. It just shows a few controls on a wxPanel,
- and has a simple menu.
- """
- def __init__(self, parent, title):
- wxFrame.__init__(self, parent, -1, title, size=(350, 200))
-
- menuBar = wxMenuBar()
- menu = wxMenu()
- menu.Append(101, "E&xit\tAlt-X", "Exit demo")
- EVT_MENU(self, 101, self.OnButton)
- menuBar.Append(menu, "&File")
- self.SetMenuBar(menuBar)
-
- panel = wxPanel(self, -1)
- text = wxStaticText(panel, -1, "Hello World!")
- text.SetFont(wxFont(14, wxSWISS, wxNORMAL, wxBOLD))
- text.SetSize(text.GetBestSize())
- btn = wxButton(panel, -1, "Close")
- btn.SetDefault()
-
- btn2 = wxButton(panel, -1, "Just for fun...")
-
- sizer = wxBoxSizer(wxVERTICAL)
- sizer.Add(text, 0, wxALL, 10)
- sizer.Add(btn, 0, wxALL, 10)
- sizer.Add(btn2, 0, wxALL, 10)
- panel.SetSizer(sizer)
- panel.SetAutoLayout(True)
- panel.Layout()
-
- EVT_BUTTON(self, btn.GetId(), self.OnButton)
- EVT_BUTTON(self, btn2.GetId(), self.OnFunButton)
-
- def OnButton(self, evt):
- """Event handler for the button click."""
- print "OnButton"
- self.Close()
-
- def OnFunButton(self, evt):
- """Event handler for the button click."""
- print "Having fun yet?"
-
-
-app = wxPySimpleApp()
-frame = MyFrame(None, "Simple wxPython App")
-frame.Show(True)
-app.MainLoop()
-
+# 11/13/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+
"""
Hello, and welcome to this test of the wxTreeItemData
class.
beautifully documented...
"""
-from wxPython import wx
-import sys, string # Don't use it, but it's fun expanding :-)
+import string # Used for demo purposes, nothing more. :-)
+import sys
+
+import wx
#----------------------------------------------------------------------
for i in range(func.co_firstlineno):
line = f.readline()
+
ind = _getindent(line)
msg = ""
+
while line:
msg = msg + line
line = f.readline()
# confused by multiline docstrings. Using == works most of
# the time... but not always!
if _getindent(line) == ind: break
+
return msg
#----------------------------------------------------------------------
-class pyTree(wx.wxTreeCtrl):
+class pyTree(wx.TreeCtrl):
"""
- This wxTreeCtrl derivative displays a tree view of a Python namespace.
+ This wx.TreeCtrl derivative displays a tree view of a Python namespace.
Anything from which the dir() command returns a non-empty list is a branch
in this tree.
"""
SEL_CHANGED handler attempts to display interesting
information about the selected object.
"""
- wx.wxTreeCtrl.__init__(self, parent, id)
- self.root = self.AddRoot(str(root), -1, -1, wx.wxTreeItemData(root))
+ wx.TreeCtrl.__init__(self, parent, id)
+ self.root = self.AddRoot(str(root), -1, -1, wx.TreeItemData(root))
+
if dir(root):
- self.SetItemHasChildren(self.root, wx.True)
- wx.EVT_TREE_ITEM_EXPANDING(self, self.GetId(), self.OnItemExpanding)
- wx.EVT_TREE_ITEM_COLLAPSED(self, self.GetId(), self.OnItemCollapsed)
- wx.EVT_TREE_SEL_CHANGED(self, self.GetId(), self.OnSelChanged)
+ self.SetItemHasChildren(self.root, True)
+
+ self.Bind(wx.EVT_TREE_ITEM_EXPANDING, self.OnItemExpanding, id=self.GetId())
+ self.Bind(wx.EVT_TREE_ITEM_COLLAPSED, self.OnItemCollapsed, id=self.GetId())
+ self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged, id=self.GetId())
+
self.output = None
self.Expand(self.root)
will again figure out what the offspring is.
"""
item = event.GetItem()
+
if self.IsExpanded(item): # This event can happen twice in the self.Expand call
return
+
obj = self.GetPyData( item )
lst = dir(obj)
+
for key in lst:
new_obj = getattr(obj,key)
new_item = self.AppendItem( item, key, -1, -1,
- wx.wxTreeItemData(new_obj) )
+ wx.TreeItemData(new_obj) )
+
if dir(new_obj):
- self.SetItemHasChildren(new_item, wx.True)
+ self.SetItemHasChildren(new_item, True)
def OnItemCollapsed(self, event):
"""
"""
if not self.output:
return
+
obj = self.GetPyData( event.GetItem() )
msg = str(obj)
+
if hasattr(obj, '__doc__'):
msg = msg+"\n\nDocumentation string:\n\n%s" % ( getattr(obj, '__doc__'),)
+
# Is it a function?
func = None
+
if hasattr(obj, "func_code"): # normal function
func = getattr(obj, "func_code")
+
elif hasattr(obj, "im_func"): # unbound class method
func = getattr(getattr(obj, "im_func"), "func_code")
+
if func: # if we found one, let's try to print the source
msg = msg+"\n\nFunction source:\n\n" + _sourcefinder(func)
This method is used by the wxPython Demo Framework for integrating
this demo with the rest.
"""
- #thisModule = __import__(__name__, globals())
thisModule = sys.modules[__name__]
- win = wx.wxFrame(frame, -1, "PyTreeItemData Test")
- split = wx.wxSplitterWindow(win, -1)
+ win = wx.Frame(frame, -1, "PyTreeItemData Test")
+ split = wx.SplitterWindow(win, -1)
tree = pyTree(split, -1, thisModule)
- text = wx.wxTextCtrl(split, -1, "", wx.wxDefaultPosition,
- wx.wxDefaultSize, wx.wxTE_MULTILINE)
+ text = wx.TextCtrl(split, -1, "", style=wx.TE_MULTILINE)
split.SplitVertically(tree, text, 200)
tree.SetOutput(text.SetValue)
tree.SelectItem(tree.root)
- win.SetSize(wx.wxSize(800,500))
+ win.SetSize((800,500))
frame.otherWin = win
win.Show(1)
#----------------------------------------------------------------------
if __name__ == '__main__':
- class MyFrame(wx.wxFrame):
+ class MyFrame(wx.Frame):
"""Very standard Frame class. Nothing special here!"""
def __init__(self):
"""Make a splitter window; left a tree, right a textctrl. Wow."""
import __main__
- wx.wxFrame.__init__(self, None, -1, "PyTreeItemData Test",
- wx.wxDefaultPosition, wx.wxSize(800,500))
- split = wx.wxSplitterWindow(self, -1)
+ wx.Frame.__init__(self, None, -1, "PyTreeItemData Test", size=(800,500))
+ split = wx.SplitterWindow(self, -1)
tree = pyTree(split, -1, __main__)
- text = wx.wxTextCtrl(split, -1, "", wx.wxDefaultPosition,
- wx.wxDefaultSize, wx.wxTE_MULTILINE)
+ text = wx.TextCtrl(split, -1, "", style=wx.TE_MULTILINE)
split.SplitVertically(tree, text, 200)
tree.SetOutput(text.SetValue)
tree.SelectItem(tree.root)
- class MyApp(wx.wxApp):
+ class MyApp(wx.App):
"""This class is even less interesting than MyFrame."""
def OnInit(self):
"""OnInit. Boring, boring, boring!"""
frame = MyFrame()
- frame.Show(wx.True)
+ frame.Show(True)
self.SetTopWindow(frame)
- return wx.True
+ return True
- app = MyApp(0)
+ app = MyApp(False)
app.MainLoop()
+++ /dev/null
-
-#----------------------------------------------------------------------
-# A very simple wxPython example. Just a wxFrame, wxPanel,
-# wxStaticText, wxButton, and a wxBoxSizer, but it shows the basic
-# structure of any wxPython application.
-#----------------------------------------------------------------------
-
-import wx # This module uses the new wx namespace
-print "wx.VERSION_STRING = ", wx.VERSION_STRING
-
-
-#import os; print os.getpid(); raw_input("press a key...")
-
-class MyFrame(wx.Frame):
- """
- This is MyFrame. It just shows a few controls on a wxPanel,
- and has a simple menu.
- """
- def __init__(self, parent, title):
- wx.Frame.__init__(self, parent, -1, title, size=(350, 200))
-
- menuBar = wx.MenuBar()
- menu = wx.Menu()
- menu.Append(101, "E&xit\tAlt-X", "Exit demo")
- wx.EVT_MENU(self, 101, self.OnButton)
- menuBar.Append(menu, "&File")
- self.SetMenuBar(menuBar)
-
- panel = wx.Panel(self, -1)
- text = wx.StaticText(panel, -1, "Hello World!")
- text.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD))
- text.SetSize(text.GetBestSize())
- btn = wx.Button(panel, -1, "Close")
- btn.SetDefault()
-
- btn2 = wx.Button(panel, -1, "Just for fun...")
-
- sizer = wx.BoxSizer(wx.VERTICAL)
- sizer.Add(text, 0, wx.ALL, 10)
- sizer.Add(btn, 0, wx.ALL, 10)
- sizer.Add(btn2, 0, wx.ALL, 10)
- panel.SetSizer(sizer)
- panel.SetAutoLayout(True)
- panel.Layout()
-
- wx.EVT_BUTTON(self, btn.GetId(), self.OnButton)
- wx.EVT_BUTTON(self, btn2.GetId(), self.OnFunButton)
-
- def OnButton(self, evt):
- """Event handler for the button click."""
- print "OnButton"
- self.Close()
-
- def OnFunButton(self, evt):
- """Event handler for the button click."""
- print "Having fun yet?"
-
-
-app = wx.PySimpleApp()
-frame = MyFrame(None, "Simple wxPython App")
-frame.Show(True)
-app.MainLoop()
-
#!/usr/bin/env python
+#
+# 11/15/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+
"""
Run wxPython in a second thread.
def start(self):
""" start the GUI thread
"""
- import thread,time
+ import time
+ import thread
thread.start_new_thread(self.run, ())
def run(self):
the import would occur in the main thread and
wxPython wouldn't run correctly in the second thread.
"""
- from viewer_basics import *
+ import viewer_basics
+
try:
- self.app = SecondThreadApp(0)
+ self.app = viewer_basics.SecondThreadApp(0)
self.app.MainLoop()
except TypeError:
self.app = None
send an event to the catcher window in the
other thread and tell it to create a cone window.
"""
- import viewer_basics
+ import viewer_basics
+
if self.app:
evt = viewer_basics.AddCone()
viewer_basics.wxPostEvent(self.app.catcher, evt)
-from wxPython.wx import *
-from wxPython.lib import vtk
+# 11/15/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+# o No idea what this does.
+#
+
+import wx
+import wx.lib.vtk as vtk
#---------------------------------------------------------------------------
-class VtkFrame(wxFrame):
+class VtkFrame(wx.Frame):
"""
Simple example VTK window that contains a cone.
"""
def __init__(self, parent, id, title):
- wxFrame.__init__(self, parent,id,title, size=(450, 300))
- win = vtk.wxVTKRenderWindow(self, -1)
+ wx.Frame.__init__(self, parent, id, title, size=(450, 300))
+ win = vtk.VTKRenderWindow(self, -1)
renWin = win.GetRenderWindow()
ren.AddActor(coneActor)
#---------------------------------------------------------------------------
-wxEVT_ADD_CONE = 25015
-
-def EVT_ADD_CONE(win, func):
- win.Connect(-1, -1, wxEVT_ADD_CONE, func)
-
+# Using new event binder
+wx_EVT_ADD_CONE = wx.NewEventType()
+EVT_ADD_CONE = wx.PyEventBinder(wx_EVT_ADD_CONE, 1)
-class AddCone(wxPyEvent):
+class AddCone(wx.PyEvent):
def __init__(self):
- wxPyEvent.__init__(self)
- self.SetEventType(wxEVT_ADD_CONE)
+ wx.PyEvent.__init__(self)
+ self.SetEventType(wx_EVT_ADD_CONE)
-class HiddenCatcher(wxFrame):
+class HiddenCatcher(wx.Frame):
"""
The "catcher" frame in the second thread.
It is invisible. It's only job is to receive
the appropriate windows.
"""
def __init__(self):
- wxFrame.__init__(self, None, -1, '')
- EVT_ADD_CONE(self, self.AddCone)
+ wx.Frame.__init__(self, None, -1, '')
+ self.Bind(EVT_ADD_CONE, self.AddCone)
def AddCone(self,evt):
add_cone()
#---------------------------------------------------------------------------
-class SecondThreadApp(wxApp):
+class SecondThreadApp(wx.App):
"""
wxApp that lives in the second thread.
"""
def OnInit(self):
catcher = HiddenCatcher()
#self.SetTopWindow(catcher)
- self.catcher =catcher
+ self.catcher = catcher
return True
#---------------------------------------------------------------------------
+# 11/15/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+# This file is used for the wx.HtmlWindow demo.
+#
+import sys
-import sys
-
-from wxPython.wx import *
-from wxPython.html import *
+import wx
+import wx.html as html
#----------------------------------------------------------------------
-
-class TestPanel(wxPanel):
- def __init__(self, parent, id=-1, size=wxDefaultSize, bgcolor=None):
- wxPanel.__init__(self, parent, id, size=size)
+class TestPanel(wx.Panel):
+ def __init__(self, parent, id=-1, size=wx.DefaultSize, bgcolor=None):
+ wx.Panel.__init__(self, parent, id, size=size)
if bgcolor:
self.SetBackgroundColour(bgcolor)
- wxStaticText(self, -1, 'Name:', wxPoint(10, 10))
- wxStaticText(self, -1, 'Email:', wxPoint(10, 40))
+ wx.StaticText(self, -1, 'Name:', (10, 10))
+ wx.StaticText(self, -1, 'Email:', (10, 40))
- self.name = wxTextCtrl(self, -1, '', wxPoint(50, 10), wxSize(100, -1))
- self.email = wxTextCtrl(self, -1, '', wxPoint(50, 40), wxSize(100, -1))
+ self.name = wx.TextCtrl(self, -1, '', (50, 10), (100, -1))
+ self.email = wx.TextCtrl(self, -1, '', (50, 40), (100, -1))
- wxButton(self, 12121, 'Okay', wxPoint(50, 70))
- EVT_BUTTON(self, 12121, self.OnButton)
+ wx.Button(self, -1, 'Okay', (50, 70))
+ self.Bind(wx.EVT_BUTTON, self.OnButton)
def OnButton(self, event):
name = self.name.GetValue()
email = self.email.GetValue()
- dlg = wxMessageDialog(self,
- 'You entered:\n %s\n %s' % (name, email),
- 'Results', style = wxOK | wxICON_INFORMATION)
+ dlg = wx.MessageDialog(
+ self, 'You entered:\n %s\n %s' % (name, email),
+ 'Results', style = wx.OK | wx.ICON_INFORMATION
+ )
+
dlg.ShowModal()
dlg.Destroy()
#----------------------------------------------------------------------
-class TestHtmlPanel(wxPanel):
- def __init__(self, parent, id=-1, size=wxDefaultSize):
+class TestHtmlPanel(wx.Panel):
+ def __init__(self, parent, id=-1, size=wx.DefaultSize):
+
import About
- wxPanel.__init__(self, parent, id, size=size)
- self.html = wxHtmlWindow(self, -1, wxPoint(5,5), wxSize(400, 350))
+
+ wx.Panel.__init__(self, parent, id, size=size)
+ self.html = html.HtmlWindow(self, -1, (5,5), (400, 350))
py_version = sys.version.split()[0]
- self.html.SetPage(About.MyAboutBox.text % (wx.__version__, py_version))
+ self.html.SetPage(About.MyAboutBox.text % (wx.VERSION_STRING, py_version))
ir = self.html.GetInternalRepresentation()
self.html.SetSize( (ir.GetWidth()+5, ir.GetHeight()+5) )
self.Fit()
#----------------------------------------------------------------------
+def runTest(frame, nb, log):
+ win = TestHtmlPanel(frame)
+ return win
+
+#----------------------------------------------------------------------
+
+if __name__ == '__main__':
+ import sys,os
+ import run
+ run.main(['', os.path.basename(sys.argv[0])])
+# 11/15/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
-import cStringIO
+import cStringIO
+import wx
#----------------------------------------------------------------------
-ArtClients = [ "wxART_TOOLBAR",
- "wxART_MENU",
- "wxART_FRAME_ICON",
- "wxART_CMN_DIALOG",
- "wxART_HELP_BROWSER",
- "wxART_MESSAGE_BOX",
- "wxART_OTHER",
+ArtClients = [ "wx.ART_TOOLBAR",
+ "wx.ART_MENU",
+ "wx.ART_FRAME_ICON",
+ "wx.ART_CMN_DIALOG",
+ "wx.ART_HELP_BROWSER",
+ "wx.ART_MESSAGE_BOX",
+ "wx.ART_OTHER",
]
-ArtIDs = [ "wxART_ADD_BOOKMARK",
- "wxART_DEL_BOOKMARK",
- "wxART_HELP_SIDE_PANEL",
- "wxART_HELP_SETTINGS",
- "wxART_HELP_BOOK",
- "wxART_HELP_FOLDER",
- "wxART_HELP_PAGE",
- "wxART_GO_BACK",
- "wxART_GO_FORWARD",
- "wxART_GO_UP",
- "wxART_GO_DOWN",
- "wxART_GO_TO_PARENT",
- "wxART_GO_HOME",
- "wxART_FILE_OPEN",
- "wxART_PRINT",
- "wxART_HELP",
- "wxART_TIP",
- "wxART_REPORT_VIEW",
- "wxART_LIST_VIEW",
- "wxART_NEW_DIR",
- "wxART_FOLDER",
- "wxART_GO_DIR_UP",
- "wxART_EXECUTABLE_FILE",
- "wxART_NORMAL_FILE",
- "wxART_TICK_MARK",
- "wxART_CROSS_MARK",
- "wxART_ERROR",
- "wxART_QUESTION",
- "wxART_WARNING",
- "wxART_INFORMATION",
+ArtIDs = [ "wx.ART_ADD_BOOKMARK",
+ "wx.ART_DEL_BOOKMARK",
+ "wx.ART_HELP_SIDE_PANEL",
+ "wx.ART_HELP_SETTINGS",
+ "wx.ART_HELP_BOOK",
+ "wx.ART_HELP_FOLDER",
+ "wx.ART_HELP_PAGE",
+ "wx.ART_GO_BACK",
+ "wx.ART_GO_FORWARD",
+ "wx.ART_GO_UP",
+ "wx.ART_GO_DOWN",
+ "wx.ART_GO_TO_PARENT",
+ "wx.ART_GO_HOME",
+ "wx.ART_FILE_OPEN",
+ "wx.ART_PRINT",
+ "wx.ART_HELP",
+ "wx.ART_TIP",
+ "wx.ART_REPORT_VIEW",
+ "wx.ART_LIST_VIEW",
+ "wx.ART_NEW_DIR",
+ "wx.ART_FOLDER",
+ "wx.ART_GO_DIR_UP",
+ "wx.ART_EXECUTABLE_FILE",
+ "wx.ART_NORMAL_FILE",
+ "wx.ART_TICK_MARK",
+ "wx.ART_CROSS_MARK",
+ "wx.ART_ERROR",
+ "wx.ART_QUESTION",
+ "wx.ART_WARNING",
+ "wx.ART_INFORMATION",
]
+#----------------------------------------------------------------------
-
-class MyArtProvider(wxArtProvider):
+class MyArtProvider(wx.ArtProvider):
def __init__(self, log):
- wxArtProvider.__init__(self)
+ wx.ArtProvider.__init__(self)
self.log = log
def CreateBitmap(self, artid, client, size):
# See end of file for the image data
- bmp = wxNullBitmap
+ bmp = wx.NullBitmap
# use this one for all 48x48 images
if size.width == 48:
bmp = makeBitmap(smile48_png)
# but be more specific for these
- elif size.width == 16 and artid == wxART_ADD_BOOKMARK:
+ elif size.width == 16 and artid == wx.ART_ADD_BOOKMARK:
bmp = makeBitmap(smile16_png)
- elif size.width == 32 and artid == wxART_ADD_BOOKMARK:
+ elif size.width == 32 and artid == wx.ART_ADD_BOOKMARK:
bmp = makeBitmap(smile32_png)
# and just ignore the size for these
- elif artid == wxART_GO_BACK:
+ elif artid == wx.ART_GO_BACK:
bmp = makeBitmap(left_png)
- elif artid == wxART_GO_FORWARD:
+ elif artid == wx.ART_GO_FORWARD:
bmp = makeBitmap(right_png)
- elif artid == wxART_GO_UP:
+ elif artid == wx.ART_GO_UP:
bmp = makeBitmap(up_png)
- elif artid == wxART_GO_DOWN:
+ elif artid == wx.ART_GO_DOWN:
bmp = makeBitmap(down_png)
- elif artid == wxART_GO_TO_PARENT:
+ elif artid == wx.ART_GO_TO_PARENT:
bmp = makeBitmap(back_png)
- elif artid == wxART_CROSS_MARK:
+ elif artid == wx.ART_CROSS_MARK:
bmp = makeBitmap(cross_png)
- elif artid == wxART_TICK_MARK:
+ elif artid == wx.ART_TICK_MARK:
bmp = makeBitmap(tick_png)
if bmp.Ok():
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.log = log
- sizer = wxBoxSizer(wxVERTICAL)
+ sizer = wx.BoxSizer(wx.VERTICAL)
- title = wxStaticText(self, -1, "wxArtProvider")
- title.SetFont(wxFont(18, wxSWISS, wxNORMAL, wxBOLD))
- sizer.AddWindow(title, 0, wxALIGN_CENTRE|wxALL, 5)
+ title = wx.StaticText(self, -1, "ArtProvider")
+ title.SetFont(wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD))
+ sizer.Add(title, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
- line = wxStaticLine(self, -1, size=(20,-1), style=wxLI_HORIZONTAL)
- sizer.AddWindow(line, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5)
+ line = wx.StaticLine(self, -1, size=(20,-1), style=wx.LI_HORIZONTAL)
+ sizer.Add(line, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
- fgs = wxFlexGridSizer(0, 3, 10, 10)
+ fgs = wx.FlexGridSizer(0, 3, 10, 10)
- combo = wxComboBox(self, -1, "", choices = ArtClients,
- style = wxCB_DROPDOWN|wxCB_READONLY)
- fgs.AddWindow(combo, 0, wxALIGN_CENTRE|wxALL, 5)
- EVT_COMBOBOX(self, combo.GetId(), self.OnSelectClient)
+ combo = wx.ComboBox(self, -1, "", choices = ArtClients,
+ style = wx.CB_DROPDOWN|wx.CB_READONLY)
+ fgs.Add(combo, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
+ self.Bind(wx.EVT_COMBOBOX, self.OnSelectClient, combo)
combo.Select(0)
- combo = wxComboBox(self, -1, "", choices = ArtIDs,
- style = wxCB_DROPDOWN|wxCB_READONLY)
- fgs.AddWindow(combo, 0, wxALIGN_CENTRE|wxALL, 5)
- EVT_COMBOBOX(self, combo.GetId(), self.OnSelectID)
+ combo = wx.ComboBox(self, -1, "", choices = ArtIDs,
+ style = wx.CB_DROPDOWN|wx.CB_READONLY)
+ fgs.Add(combo, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
+ self.Bind(wx.EVT_COMBOBOX, self.OnSelectID, combo)
combo.Select(0)
cb = wxCheckBox(self, -1, "Use custom provider")
- fgs.AddWindow(cb, 0, wxALIGN_CENTRE|wxALL, 5)
- EVT_CHECKBOX(self, cb.GetId(), self.OnUseCustom)
-
- fgs.Add((10, 10), 0, wxALIGN_CENTRE|wxALL, 5)
- fgs.Add((10, 10), 0, wxALIGN_CENTRE|wxALL, 5)
- fgs.Add((10, 10), 0, wxALIGN_CENTRE|wxALL, 5)
-
- box = wxBoxSizer(wxVERTICAL)
- bmp = wxEmptyBitmap(16,16)
- self.bmp16 = wxStaticBitmap(self, -1, bmp)
- box.AddWindow(self.bmp16, 0, wxALIGN_CENTRE|wxALL, 5)
- text = wxStaticText(self, -1, "16x16")
- box.AddWindow(text, 0, wxALIGN_CENTRE|wxALL, 5)
-
- fgs.AddSizer(box, 0, wxALIGN_CENTRE|wxALL, 5)
-
- box = wxBoxSizer(wxVERTICAL)
- bmp = wxEmptyBitmap(32,32)
- self.bmp32 = wxStaticBitmap(self, -1, bmp)
- box.AddWindow(self.bmp32, 0, wxALIGN_CENTRE|wxALL, 5)
- text = wxStaticText(self, -1, "32x32")
- box.AddWindow(text, 0, wxALIGN_CENTRE|wxALL, 5)
-
- fgs.AddSizer(box, 0, wxALIGN_CENTRE|wxALL, 5)
-
- box = wxBoxSizer(wxVERTICAL)
- bmp = wxEmptyBitmap(48,48)
- self.bmp48 = wxStaticBitmap(self, -1, bmp)
- box.AddWindow(self.bmp48, 0, wxALIGN_CENTRE|wxALL, 5)
- text = wxStaticText(self, -1, "48x48")
- box.AddWindow(text, 0, wxALIGN_CENTRE|wxALL, 5)
-
- fgs.AddSizer(box, 0, wxALIGN_CENTRE|wxALL, 5)
- sizer.AddSizer(fgs, 0, wxALL, 5)
+ fgs.Add(cb, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
+ self.Bind(EVT_CHECKBOX, self.OnUseCustom, cb)
+
+ fgs.Add((10, 10), 0, wx.ALIGN_CENTRE|wx.ALL, 5)
+ fgs.Add((10, 10), 0, wx.ALIGN_CENTRE|wx.ALL, 5)
+ fgs.Add((10, 10), 0, wx.ALIGN_CENTRE|wx.ALL, 5)
+
+ box = wx.BoxSizer(wx.VERTICAL)
+ bmp = wx.EmptyBitmap(16,16)
+ self.bmp16 = wx.StaticBitmap(self, -1, bmp)
+ box.Add(self.bmp16, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
+ text = wx.StaticText(self, -1, "16x16")
+ box.Add(text, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
+
+ fgs.Add(box, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
+
+ box = wx.BoxSizer(wx.VERTICAL)
+ bmp = wx.EmptyBitmap(32,32)
+ self.bmp32 = wx.StaticBitmap(self, -1, bmp)
+ box.Add(self.bmp32, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
+ text = wx.StaticText(self, -1, "32x32")
+ box.Add(text, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
+
+ fgs.Add(box, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
+
+ box = wx.BoxSizer(wx.VERTICAL)
+ bmp = wx.EmptyBitmap(48,48)
+ self.bmp48 = wx.StaticBitmap(self, -1, bmp)
+ box.Add(self.bmp48, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
+ text = wx.StaticText(self, -1, "48x48")
+ box.Add(text, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
+
+ fgs.AddSizer(box, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
+ sizer.Add(fgs, 0, wx.ALL, 5)
self.SetSizer(sizer)
self.client = eval(ArtClients[0])
def OnUseCustom(self, evt):
if evt.IsChecked():
self.log.write("Images will now be provided by MyArtProvider\n")
- wxArtProvider_PushProvider( MyArtProvider(self.log) )
+ wx.ArtProvider_PushProvider( MyArtProvider(self.log) )
else:
self.log.write("MyArtProvider deactivated\n")
- wxArtProvider_PopProvider()
+ wx.ArtProvider_PopProvider()
self.getArt()
def getArt(self):
self.log.write("Getting art for %s:%s\n" % (self.client, self.artid))
- bmp = wxArtProvider_GetBitmap(self.artid, self.client, (16,16))
+ bmp = wx.ArtProvider_GetBitmap(self.artid, self.client, (16,16))
+
if not bmp.Ok():
bmp = wxEmptyBitmap(16,16)
+
self.bmp16.SetBitmap(bmp)
- bmp = wxArtProvider_GetBitmap(self.artid, self.client, (32,32))
+ bmp = wx.ArtProvider_GetBitmap(self.artid, self.client, (32,32))
+
if not bmp.Ok():
bmp = wxEmptyBitmap(32,32)
+
self.bmp32.SetBitmap(bmp)
- bmp = wxArtProvider_GetBitmap(self.artid, self.client, (48,48))
+ bmp = wx.ArtProvider_GetBitmap(self.artid, self.client, (48,48))
+
if not bmp.Ok():
bmp = wxEmptyBitmap(48,48)
+
self.bmp48.SetBitmap(bmp)
#----------------------------------------------------------------------
-
overview = """<html><body>
<h2><center>wxArtProvider</center></h2>
def makeBitmap(data):
stream = cStringIO.StringIO(data)
- return wxBitmapFromImage(wxImageFromStream(stream))
+ return wx.BitmapFromImage(wx.ImageFromStream(stream))
back_png = \
+# 11/15/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
-
-import images
+import wx
+import images
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1,
- style=wxNO_FULL_REPAINT_ON_RESIZE)
+ wx.Panel.__init__(self, parent, -1,
+ style=wx.NO_FULL_REPAINT_ON_RESIZE)
self.log = log
- b = wxButton(self, 10, "Default Button", wxPoint(20, 20))
- EVT_BUTTON(self, 10, self.OnClick)
+ b = wx.Button(self, 10, "Default Button", (20, 20))
+ self.Bind(EVT_BUTTON, self.OnClick, b)
b.SetDefault()
b.SetSize(b.GetBestSize())
- b = wxButton(self, 20, "HELLO AGAIN!", wxPoint(20, 80), wxSize(120, 45))
- EVT_BUTTON(self, 20, self.OnClick)
+ b = wx.Button(self, 20, "HELLO AGAIN!", (20, 80), (120, 45))
+ self.Bind(EVT_BUTTON, self.OnClick, b)
b.SetToolTipString("This is a Hello button...")
- if 0: # a test case for catching wxPyAssertionError
+ if 0: # a test case for catching wx.PyAssertionError
- #wxGetApp().SetAssertMode(wxPYAPP_ASSERT_SUPPRESS)
- #wxGetApp().SetAssertMode(wxPYAPP_ASSERT_EXCEPTION)
- #wxGetApp().SetAssertMode(wxPYAPP_ASSERT_DIALOG)
- #wxGetApp().SetAssertMode(wxPYAPP_ASSERT_EXCEPTION | wxPYAPP_ASSERT_DIALOG)
+ #wx.GetApp().SetAssertMode(wx.PYAPP_ASSERT_SUPPRESS)
+ #wx.GetApp().SetAssertMode(wx.PYAPP_ASSERT_EXCEPTION)
+ #wx.GetApp().SetAssertMode(wx.PYAPP_ASSERT_DIALOG)
+ #wx.GetApp().SetAssertMode(wx.PYAPP_ASSERT_EXCEPTION | wx.PYAPP_ASSERT_DIALOG)
try:
- bmp = wxBitmap("nosuchfile.bmp", wxBITMAP_TYPE_BMP)
- mask = wxMaskColour(bmp, wxBLUE)
- except wxPyAssertionError:
- self.log.write("Caught wxPyAssertionError! I will fix the problem.\n")
+ bmp = wx.Bitmap("nosuchfile.bmp", wx.BITMAP_TYPE_BMP)
+ mask = wx.MaskColour(bmp, wx.BLUE)
+ except wx.PyAssertionError:
+ self.log.write("Caught wx.PyAssertionError! I will fix the problem.\n")
bmp = images.getTest2Bitmap()
- mask = wxMaskColour(bmp, wxBLUE)
+ mask = wx.MaskColour(bmp, wx.BLUE)
else:
bmp = images.getTest2Bitmap()
- mask = wxMaskColour(bmp, wxBLUE)
+ mask = wx.MaskColour(bmp, wx.BLUE)
bmp.SetMask(mask)
- wxBitmapButton(self, 30, bmp, wxPoint(160, 20),
- wxSize(bmp.GetWidth()+10, bmp.GetHeight()+10))
- EVT_BUTTON(self, 30, self.OnClick)
+ wx.BitmapButton(self, 30, bmp, (160, 20),
+ (bmp.GetWidth()+10, bmp.GetHeight()+10))
+ self.Bind(wx.EVT_BUTTON, self.OnClick, id=30)
def OnClick(self, event):
overview = """<html><body>
-<h2>wxButton</h2>
+<h2>Button</h2>
-A button is a control that contains a text string or a bitmap and cab be
+A button is a control that contains a text string or a bitmap and can be
placed on nearly any kind of window.
</body></html>
# Date: Feb 26, 2001
# Licence: wxWindows license
#----------------------------------------------------------------------------
+# 11/15/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+# o Some updating of the library itself will be needed for this demo to work
+# correctly.
+#
+# 11/26/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Problems have changed a little. The print dialog requires
+# a wx.Size to work with the calendar library. wx.core doesn't
+# approve, though, so we get deprecation warnings.
+# o Ugh. AFter updating to the Bind() method, things lock up
+# on various control clicks. Will have to debug. Only seems
+# to happen on windows with calendar controls, though.
+#
+# 11/30/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Lockup issue clarification: it appears that the spinner is
+# the culprit.
+#
+# 12/01/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o New Bind() method now fully supported.
+#
+
+import os
-from wxPython.wx import *
-from wxPython.lib.calendar import wxCalendar, Month, PrtCalDraw, CalenDlg
+import wx
+import wx.lib.calendar as calendar
-import images
-import os
+import images
# highlighted days in month
# test of full window calendar control functions
def GetMonthList():
+
monthlist = []
+
for i in range(13):
- name = Month[i]
+ name = calendar.Month[i]
+
if name != None:
monthlist.append(name)
+
return monthlist
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log, frame):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.log = log
self.frame = frame
- self.calend = wxCalendar(self, -1, wxPoint(100, 50), wxSize(200, 180))
+ self.calend = calendar.wxCalendar(self, -1, (100, 50), (200, 180))
# start_month = 2 # preselect the date for calendar
# start_year = 2001
start_month = self.calend.GetMonth() # get the current month & year
start_year = self.calend.GetYear()
-# month list from DateTime module
+ # month list from DateTime module
monthlist = GetMonthList()
- mID = wxNewId()
- self.date = wxComboBox(self, mID, "",
- wxPoint(100, 20), wxSize(90, -1),
- monthlist, wxCB_DROPDOWN)
+ mID = wx.NewId()
+ self.date = wx.ComboBox(self, mID, "",
+ (100, 20), (90, -1),
+ monthlist, wx.CB_DROPDOWN)
+
self.date.SetSelection(start_month-1)
- EVT_COMBOBOX(self, mID, self.EvtComboBox)
+ self.Bind(wx.EVT_COMBOBOX, self.EvtComboBox, id=mID)
-# set start month and year
+ # set start month and year
self.calend.SetMonth(start_month)
self.calend.SetYear(start_year)
-# set attributes of calendar
+ # set attributes of calendar
self.calend.hide_title = True
self.calend.HideGrid()
self.calend.SetWeekColor('WHITE', 'BLACK')
-# display routine
+ # display routine
self.ResetDisplay()
-# mouse click event
+ # mouse click event
+ self.Bind(calendar.EVT_CALENDAR, self.MouseClick, self.calend)
- self.Connect(self.calend.GetId(), -1, 2100, self.MouseClick)
+ # scroll bar for month selection
-# scroll bar for month selection
+ mID = wx.NewId()
- mID = wxNewId()
- self.scroll = wxScrollBar(self, mID, wxPoint(100, 240), wxSize(200, 20), wxSB_HORIZONTAL)
+ self.scroll = wx.ScrollBar(self, mID, (100, 240), (200, 20), wx.SB_HORIZONTAL)
self.scroll.SetScrollbar(start_month-1, 1, 12, 1, True)
- EVT_COMMAND_SCROLL(self, mID, self.Scroll)
+ self.Bind(wx.EVT_COMMAND_SCROLL, self.Scroll, id=mID)
-# spin control for year selection
+ # spin control for year selection
- self.dtext = wxTextCtrl(self, -1, str(start_year), wxPoint(200, 20), wxSize(60, -1))
+ self.dtext = wx.TextCtrl(self, -1, str(start_year), (200, 20), (60, -1))
h = self.dtext.GetSize().height
- mID = wxNewId()
- self.spin = wxSpinButton(self, mID, wxPoint(270, 20), wxSize(h*2, h))
+ mID = wx.NewId()
+ self.spin = wx.SpinButton(self, mID, (270, 20), (h*2, h))
self.spin.SetRange(1980, 2010)
self.spin.SetValue(start_year)
- EVT_SPIN(self, mID, self.OnSpin)
+ self.Bind(wx.EVT_SPIN, self.OnSpin, id=mID)
-# button for calendar dialog test
+ # button for calendar dialog test
- wxStaticText(self, -1, "Test Calendar Dialog", wxPoint(350, 50), wxSize(150, -1))
+ wx.StaticText(self, -1, "Test Calendar Dialog", (350, 50), (150, -1))
- mID = wxNewId()
+ mID = wx.NewId()
bmp = images.getCalendarBitmap()
- self.but = wxBitmapButton(self, mID, bmp, wxPoint(380, 80))#, wxSize(30, 30))
- EVT_BUTTON(self, mID, self.TestDlg)
+ self.but = wx.BitmapButton(self, mID, bmp, (380, 80))
+ self.Bind(wx.EVT_BUTTON, self.TestDlg, id=mID)
-# button for calendar window test
+ # button for calendar window test
- wxStaticText(self, -1, "Test Calendar Window", wxPoint(350, 150), wxSize(150, -1))
+ wx.StaticText(self, -1, "Test Calendar Window", (350, 150), (150, -1))
- mID = wxNewId()
- self.but = wxBitmapButton(self, mID, bmp, wxPoint(380, 180))#, wxSize(30, 30))
- EVT_BUTTON(self, mID, self.TestFrame)
+ mID = wx.NewId()
+ self.but = wx.BitmapButton(self, mID, bmp, (380, 180))
+ self.Bind(wx.EVT_BUTTON, self.TestFrame, id=mID)
- wxStaticText(self, -1, "Test Calendar Print", wxPoint(350, 250), wxSize(150, -1))
+ wx.StaticText(self, -1, "Test Calendar Print", (350, 250), (150, -1))
- mID = wxNewId()
- self.but = wxBitmapButton(self, mID, bmp, wxPoint(380, 280))#, wxSize(30, 30))
- EVT_BUTTON(self, mID, self.OnPreview)
+ mID = wx.NewId()
+ self.but = wx.BitmapButton(self, mID, bmp, (380, 280))
+ self.Bind(wx.EVT_BUTTON, self.OnPreview, id=mID)
-# calendar dialog
+ # calendar dialog
def TestDlg(self, event): # test the date dialog
- dlg = CalenDlg(self)
+ dlg = calendar.CalenDlg(self)
dlg.Centre()
- if dlg.ShowModal() == wxID_OK:
+
+ if dlg.ShowModal() == wx.ID_OK:
result = dlg.result
day = result[1]
month = result[2]
else:
self.log.WriteText('No Date Selected')
-# calendar window test
+ # calendar window test
def TestFrame(self, event):
frame = CalendFrame(self, -1, "Test Calendar", self.log)
frame.Show(True)
return True
-# calendar print preview
+ # calendar print preview
def OnPreview(self, event):
month = self.calend.GetMonth()
prt = PrintCalend(self.frame, month, year)
prt.Preview()
-# month and year control events
+ # month and year control events
def OnSpin(self, event):
year = event.GetPosition()
self.ResetDisplay()
self.log.WriteText('Month: %s\n' % value)
- name = Month[monthval]
+ name = calendar.Month[monthval]
self.date.SetValue(name)
-# log mouse events
+ # log mouse events
def MouseClick(self, evt):
text = '%s CLICK %02d/%02d/%d' % (evt.click, evt.day, evt.month, evt.year) # format date
self.log.WriteText('Date Selected: ' + text + '\n')
-# set the highlighted days for the calendar
+ # set the highlighted days for the calendar
def ResetDisplay(self):
month = self.calend.GetMonth()
+
try:
set_days = test_days[month]
except:
self.calend.SetSelDay(set_days)
self.calend.Refresh()
-# increment and decrement toolbar controls
+ # increment and decrement toolbar controls
def OnIncYear(self, event):
self.calend.IncYear()
# test of full window calendar control functions
-class CalendFrame(wxFrame):
+class CalendFrame(wx.Frame):
def __init__(self, parent, id, title, log):
- wxFrame.__init__(self, parent, id, title, size=wxSize(400, 400),
- style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
- EVT_CLOSE(self, self.OnCloseWindow)
+ wx.Frame.__init__(self, parent, id, title, size=(400, 400),
+ style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
+
+ self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
self.log = log
self.CreateStatusBar()
- self.mainmenu = wxMenuBar()
- menu = wxMenu()
+ self.mainmenu = wx.MenuBar()
+ menu = wx.Menu()
menu = self.MakeFileMenu()
self.mainmenu.Append(menu, '&File')
self.MakeToolMenu() # toolbar
self.SetMenuBar(self.mainmenu)
- self.calend = wxCalendar(self, -1)
+ self.calend = calendar.wxCalendar(self, -1)
self.calend.SetCurrentDay()
self.calend.grid_color = 'BLUE'
self.calend.SetBusType()
self.ResetDisplay()
- self.Connect(self.calend.GetId(), -1, 2100, self.MouseClick)
+ self.Bind(calendar.EVT_CALENDAR, self.MouseClick, self.calend)
def MouseClick(self, evt):
text = '%s CLICK %02d/%02d/%d' % (evt.click, evt.day, evt.month, evt.year) # format date
def ResetDisplay(self):
month = self.calend.GetMonth()
+
try:
set_days = test_days[month]
except:
self.ResetDisplay()
def MakeFileMenu(self):
- menu = wxMenu()
+ menu = wx.Menu()
- mID = wxNewId()
+ mID = wx.NewId()
menu.Append(mID, 'Decrement', 'Next')
- EVT_MENU(self, mID, self.OnDecMonth)
+ self.Bind(wx.EVT_MENU, self.OnDecMonth, id=mID)
- mID = wxNewId()
+ mID = wx.NewId()
menu.Append(mID, 'Increment', 'Dec')
- EVT_MENU(self, mID, self.OnIncMonth)
+ self.Bind(wx.EVT_MENU, self.OnIncMonth, id=mID)
menu.AppendSeparator()
- mID = wxNewId()
+ mID = wx.NewId()
menu.Append(mID, 'E&xit', 'Exit')
- EVT_MENU(self, mID, self.OnCloseWindow)
+ self.Bind(wx.EVT_MENU, self.OnCloseWindow, id=mID)
return menu
def MakeToolMenu(self):
- tb = self.CreateToolBar(wxTB_HORIZONTAL|wxNO_BORDER)
+ tb = self.CreateToolBar(wx.TB_HORIZONTAL|wx.NO_BORDER)
- mID = wxNewId()
+ mID = wx.NewId()
SetToolPath(self, tb, mID, images.getDbDecBitmap(), 'Dec Year')
- EVT_TOOL(self, mID, self.OnDecYear)
+ self.Bind(wx.EVT_TOOL, self.OnDecYear, id=mID)
- mID = wxNewId()
+ mID = wx.NewId()
SetToolPath(self, tb, mID, images.getDecBitmap(), 'Dec Month')
- EVT_TOOL(self, mID, self.OnDecMonth)
+ self.Bind(wx.EVT_TOOL, self.OnDecMonth, id=mID)
- mID = wxNewId()
+ mID = wx.NewId()
SetToolPath(self, tb, mID, images.getPtBitmap(), 'Current Month')
- EVT_TOOL(self, mID, self.OnCurrent)
+ self.Bind(wx.EVT_TOOL, self.OnCurrent, id=mID)
- mID = wxNewId()
+ mID = wx.NewId()
SetToolPath(self, tb, mID, images.getIncBitmap(), 'Inc Month')
- EVT_TOOL(self, mID, self.OnIncMonth)
+ self.Bind(wx.EVT_TOOL, self.OnIncMonth, id=mID)
- mID = wxNewId()
+ mID = wx.NewId()
SetToolPath(self, tb, mID, images.getDbIncBitmap(), 'Inc Year')
- EVT_TOOL(self, mID, self.OnIncYear)
+ self.Bind(wx.EVT_TOOL, self.OnIncYear, id=mID)
tb.Realize()
self.SetParms()
self.SetCal()
- self.printData = wxPrintData()
+ self.printData = wx.PrintData()
def SetCal(self):
self.grid_color = 'BLUE'
self.back_color = 'WHITE'
self.sel_color = 'RED'
self.high_color = 'LIGHT BLUE'
- self.font = wxSWISS
- self.bold = wxNORMAL
+ self.font = wx.SWISS
+ self.bold = wx.NORMAL
self.sel_key = None # last used by
self.sel_lst = [] # highlighted selected days
def Preview(self):
printout = SetPrintout(self)
printout2 = SetPrintout(self)
- self.preview = wxPrintPreview(printout, printout2, self.printData)
+ self.preview = wx.PrintPreview(printout, printout2, self.printData)
+
if not self.preview.Ok():
- wxMessageBox("There was a problem printing!", "Printing", wxOK)
+ wx.MessageBox("There was a problem printing!", "Printing", wx.OK)
return
self.preview.SetZoom(60) # initial zoom value
- frame = wxPreviewFrame(self.preview, self.frame, "Print preview")
+ frame = wx.PreviewFrame(self.preview, self.frame, "Print preview")
frame.Initialize()
frame.SetPosition(self.frame.GetPosition())
frame.Show(True)
def Print(self):
- pdd = wxPrintDialogData()
+ pdd = wx.PrintDialogData()
pdd.SetPrintData(self.printData)
- printer = wxPrinter(pdd)
+ printer = wx.Printer(pdd)
printout = SetPrintout(self)
- frame = wxFrame(None, -1, "Test")
+ frame = wx.Frame(None, -1, "Test")
+
if not printer.Print(frame, printout):
- wxMessageBox("There was a problem printing.\nPerhaps your current printer is not set correctly?", "Printing", wxOK)
+ wx.MessageBox("There was a problem printing.\nPerhaps your current printer is not set correctly?", "Printing", wx.OK)
else:
self.printData = printer.GetPrintDialogData().GetPrintData()
+
printout.Destroy()
def DoDrawing(self, DC):
- size = DC.GetSizeTuple()
+ size = DC.GetSize()
DC.BeginDrawing()
- cal = PrtCalDraw(self)
+ cal = calendar.PrtCalDraw(self)
if self.preview is None:
cal.SetPSize(size[0]/self.pagew, size[1]/self.pageh)
cal.font = self.font
cal.bold = self.bold
- cal_size = wxSize(3.0, 3.0)
+ cal_size = (3.0, 3.0)
cal.SetSize(cal_size)
year, month = self.year, self.month
x = 1.0
+
for i in range(2):
y = 0.5
+
for j in range(3):
cal.SetCal(year, month) # current month
cal.SetPos(x, y)
year, month = self.IncMonth(year, month)
y = y + 3.5
+
x = x + 4.0 # next column
DC.EndDrawing()
def IncMonth(self, year, month): # next month
month = month + 1
+
if month > 12:
month = 1
year = year + 1
def SetToolPath(self, tb, id, bmp, title):
tb.AddSimpleTool(id, bmp, title, title)
-class SetPrintout(wxPrintout):
+class SetPrintout(wx.Printout):
def __init__(self, canvas):
- wxPrintout.__init__(self)
+ wx.Printout.__init__(self)
self.canvas = canvas
self.end_pg = 1
def GetPageInfo(self):
self.end_pg = self.canvas.GetTotalPages()
str_pg = 1
+
try:
end_pg = self.end_pg
except:
end_pg = 1
+
return (str_pg, end_pg, str_pg, end_pg)
def OnPreparePrinting(self):
dc = self.GetDC()
self.preview = self.IsPreview()
+
if (self.preview):
self.pixelsPerInch = self.GetPPIScreen()
else:
self.pixelsPerInch = self.GetPPIPrinter()
- (w, h) = dc.GetSizeTuple()
+ (w, h) = dc.GetSize()
scaleX = float(w) / 1000
scaleY = float(h) / 1000
self.printUserScale = min(scaleX, scaleY)
def OnPrintPage(self, page):
dc = self.GetDC()
- (w, h) = dc.GetSizeTuple()
+ (w, h) = dc.GetSize()
scaleX = float(w) / 1000
scaleY = float(h) / 1000
self.printUserScale = min(scaleX, scaleY)
self.canvas.DoDrawing(dc)
return True
-class MyApp(wxApp):
+class MyApp(wx.App):
def OnInit(self):
- frame = CalendFrame(None, -1, "Test Calendar")
+ frame = CalendFrame(None, -1, "Test Calendar", log)
frame.Show(True)
self.SetTopWindow(frame)
return True
#---------------------------------------------------------------------------
def MessageDlg(self, message, type = 'Message'):
- dlg = wxMessageDialog(self, message, type, wxOK | wxICON_INFORMATION)
+ dlg = wx.MessageDialog(self, message, type, wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
overview = """\
-This control provides a calendar control class for displaying and selecting dates. In addition, the class is extended and can now be used for printing/previewing.
+This control provides a calendar control class for displaying and selecting dates.
+In addition, the class is extended and can now be used for printing/previewing.
-Additional features include weekend highlighting and business type Monday-Sunday format.
+Additional features include weekend highlighting and business type Monday-Sunday
+format.
-See example for various methods used to set display month, year, and highlighted dates (different font and background colours).
+See example for various methods used to set display month, year, and highlighted
+dates (different font and background colours).
by Lorne White
+# 11/15/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
-from wxPython.calendar import *
-
+import wx
+import wx.lib.calendar as calendar
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, ID, log):
- wxPanel.__init__(self, parent, ID)
+ wx.Panel.__init__(self, parent, ID)
self.log = log
- cal = wxCalendarCtrl(self, -1, wxDateTime_Now(), pos = (25,50),
- style = wxCAL_SHOW_HOLIDAYS
- | wxCAL_SUNDAY_FIRST
- | wxCAL_SEQUENTIAL_MONTH_SELECTION
+ cal = calendar.CalendarCtrl(self, -1, wx.DateTime_Now(), pos = (25,50),
+ style = calendar.CAL_SHOW_HOLIDAYS
+ | calendar.CAL_SUNDAY_FIRST
+ | calendar.CAL_SEQUENTIAL_MONTH_SELECTION
)
- EVT_CALENDAR(self, cal.GetId(), self.OnCalSelected)
+ self.Bind(calendar.EVT_CALENDAR, self.OnCalSelected, id=cal.GetId())
- b = wxButton(self, -1, "Destroy the Calendar", pos = (250, 50))
- EVT_BUTTON(self, b.GetId(), self.OnButton)
+ b = wx.Button(self, -1, "Destroy the Calendar", pos = (250, 50))
+ self.Bind(wx.EVT_BUTTON, self.OnButton, id= b.GetId())
self.cal = cal
# Set up control to display a set of holidays:
- EVT_CALENDAR_MONTH(self, cal.GetId(), self.OnChangeMonth)
+ self.Bind(calendar.EVT_CALENDAR_MONTH, self.OnChangeMonth, id=cal.GetId())
self.holidays = [(1,1), (10,31), (12,25) ] # (these don't move around)
self.OnChangeMonth()
def OnChangeMonth(self, evt=None):
cur_month = self.cal.GetDate().GetMonth() + 1 # convert wxDateTime 0-11 => 1-12
+
for month, day in self.holidays:
if month == cur_month:
self.cal.SetHoliday(day)
+# 11/15/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
+import wx
#---------------------------------------------------------------------------
-class TestCheckBox(wxPanel):
+class TestCheckBox(wx.Panel):
def __init__(self, parent, log):
self.log = log
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
- wxStaticText(self, -1, "This example uses the wxCheckBox control.",
- wxPoint(10, 10))
+ wx.StaticText(self, -1, "This example uses the wxCheckBox control.", (10, 10))
- cID = wxNewId()
- cb1 = wxCheckBox(self, cID, " Apples", wxPoint(65, 40), wxSize(150, 20), wxNO_BORDER)
- cb2 = wxCheckBox(self, cID+1, " Oranges", wxPoint(65, 60), wxSize(150, 20), wxNO_BORDER)
+ cID = wx.NewId()
+ cb1 = wx.CheckBox(self, cID, " Apples", (65, 40), (150, 20), wx.NO_BORDER)
+ cb2 = wx.CheckBox(self, cID+1, " Oranges", (65, 60), (150, 20), wx.NO_BORDER)
cb2.SetValue(True)
- cb3 = wxCheckBox(self, cID+2, " Pears", wxPoint(65, 80), wxSize(150, 20), wxNO_BORDER)
-
- EVT_CHECKBOX(self, cID, self.EvtCheckBox)
- EVT_CHECKBOX(self, cID+1, self.EvtCheckBox)
- EVT_CHECKBOX(self, cID+2, self.EvtCheckBox)
+ cb3 = wx.CheckBox(self, cID+2, " Pears", (65, 80), (150, 20), wx.NO_BORDER)
+ self.Bind(wx.EVT_CHECKBOX, self.EvtCheckBox, cb1)
+ self.Bind(wx.EVT_CHECKBOX, self.EvtCheckBox, cb2)
+ self.Bind(wx.EVT_CHECKBOX, self.EvtCheckBox, cb3)
def EvtCheckBox(self, event):
self.log.WriteText('EvtCheckBox: %d\n' % event.IsChecked())
-
-
-
-
-
-
-
-
-
-
overview = """\
A checkbox is a labelled box which is either on (checkmark is visible) or off (no checkmark).
+# 11/15/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+# o Why is there a popup menu in this demo?
+#
-from wxPython.wx import *
+import wx
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.log = log
sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
'six', 'seven', 'eight', 'nine', 'ten', 'eleven',
'twelve', 'thirteen', 'fourteen']
- wxStaticText(self, -1, "This example uses the wxCheckListBox control.",
- (45, 15))
+ wx.StaticText(self, -1, "This example uses the wxCheckListBox control.", (45, 15))
- lb = wxCheckListBox(self, 60, (80, 50), (80, 120),
- sampleList)
- EVT_LISTBOX(self, 60, self.EvtListBox)
- EVT_LISTBOX_DCLICK(self, 60, self.EvtListBoxDClick)
+ lb = wx.CheckListBox(self, 60, (80, 50), (80, 120), sampleList)
+ self.Bind(wx.EVT_LISTBOX, self.EvtListBox, id=60)
+ self.Bind(wx.EVT_LISTBOX_DCLICK, self.EvtListBoxDClick, id=60)
lb.SetSelection(0)
self.lb = lb
pos = lb.GetPosition().x + lb.GetSize().width + 25
- btn = wxButton(self, -1, "Test SetString", (pos, 50))
- EVT_BUTTON(self, btn.GetId(), self.OnTestButton)
-
- EVT_RIGHT_UP(self, self.OnDoPopup)
-
+ btn = wx.Button(self, -1, "Test SetString", (pos, 50))
+ self.Bind(wx.EVT_BUTTON, self.OnTestButton, id=btn.GetId())
+ self.Bind(wx.EVT_RIGHT_UP, self.OnDoPopup)
def EvtListBox(self, event):
self.log.WriteText('EvtListBox: %s\n' % event.GetString())
def OnDoPopup(self, evt):
- menu = wxMenu()
+ menu = wx.Menu()
# Make this first item bold
- item = wxMenuItem(menu, wxNewId(), "If supported, this is bold")
- df = wxSystemSettings_GetSystemFont(wxSYS_DEFAULT_GUI_FONT)
- nf = wxFont(df.GetPointSize(), df.GetFamily(), df.GetStyle(), wxBOLD,
- False, df.GetFaceName())
+ item = wx.MenuItem(menu, wx.NewId(), "If supported, this is bold")
+ df = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
+
+ nf = wx.Font(
+ df.GetPointSize(), df.GetFamily(), df.GetStyle(),
+ wx.BOLD, False, df.GetFaceName()
+ )
+
item.SetFont(nf)
menu.AppendItem(item)
- menu.AppendItem(wxMenuItem(menu, wxNewId(), "Normal Item &1"))
- menu.AppendItem(wxMenuItem(menu, wxNewId(), "Normal Item &2"))
- menu.AppendItem(wxMenuItem(menu, wxNewId(), "Normal Item &3"))
- menu.AppendItem(wxMenuItem(menu, wxNewId(), "Normal Item &4"))
+ menu.AppendItem(wx.MenuItem(menu, wx.NewId(), "Normal Item &1"))
+ menu.AppendItem(wx.MenuItem(menu, wx.NewId(), "Normal Item &2"))
+ menu.AppendItem(wx.MenuItem(menu, wx.NewId(), "Normal Item &3"))
+ menu.AppendItem(wx.MenuItem(menu, wx.NewId(), "Normal Item &4"))
self.PopupMenu(menu, evt.GetPosition())
menu.Destroy()
#----------------------------------------------------------------------
-
-
overview = """\
-"""
-
+A checklistbox is like a Listbox, but allows items to be checked or unchecked rather
+than relying on extended selection (e.g. shift-select) to select multiple items in
+the list.
+This class is currently implemented under Windows and GTK.
+This demo shows the basic CheckListBox and how to use the SetString method to change
+labels dynamically.
+"""
if __name__ == '__main__':
+# 11/15/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
+import wx
#---------------------------------------------------------------------------
-class TestChoice(wxPanel):
+class TestChoice(wx.Panel):
def __init__(self, parent, log):
self.log = log
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
'six', 'seven', 'eight']
- wxStaticText(self, -1, "This example uses the wxChoice control.",
- wxPoint(15, 10))
-
- wxStaticText(self, -1, "Select one:", wxPoint(15, 50), wxSize(75, 20))
- self.ch = wxChoice(self, 40, (80, 50), choices = sampleList)
- EVT_CHOICE(self, 40, self.EvtChoice)
+ wx.StaticText(self, -1, "This example uses the wxChoice control.", (15, 10))
+ wx.StaticText(self, -1, "Select one:", (15, 50), (75, 20))
+ self.ch = wx.Choice(self, -1, (80, 50), choices = sampleList)
+ self.Bind(wx.EVT_CHOICE, self.EvtChoice, self.ch)
def EvtChoice(self, event):
self.log.WriteText('EvtChoice: %s\n' % event.GetString())
self.ch.Append("A new item")
+
+ if event.GetString() == 'one':
+ self.log.WriteText('Well done!\n')
#---------------------------------------------------------------------------
#---------------------------------------------------------------------------
+overview = """
+A Choice control is used to select one of a list of strings. Unlike a listbox,
+only the current selection is visible until the user pulls down the menu of
+choices.
+This demo illustrates how to set up the Choice control and how to extract the
+selected choice once it is selected.
-
-
-
-
-
-
-
-
-
-overview = """\
-A choice item is used to select one of a list of strings. Unlike a listbox, only the selection is visible until the user pulls down the menu of choices.
+Note that the syntax of the constructor is different than the C++ implementation.
+The number of choices and the choice array are consilidated into one python
+<code>list</code>.
"""
-
if __name__ == '__main__':
import sys,os
import run
+# 11/15/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
+import wx
#---------------------------------------------------------------------------
def runTest(frame, nb, log):
- dlg = wxColourDialog(frame)
+ dlg = wx.ColourDialog(frame)
+
+ # Ensure the full colour dialog is displayed,
+ # not the abbreviated version.
dlg.GetColourData().SetChooseFull(True)
- if dlg.ShowModal() == wxID_OK:
+
+ if dlg.ShowModal() == wx.ID_OK:
+
+ # If the user selected OK, then the dialog's wx.ColourData will
+ # contain valid information. Fetch the data ...
data = dlg.GetColourData()
+
+ # ... then do something with it. The actual colour data will be
+ # returned as a three-tuple (r, g, b) in this particular case.
log.WriteText('You selected: %s\n' % str(data.GetColour().Get()))
+
+ # Once the dialog is destroyed, Mr. wx.ColourData is no longer your
+ # friend. Don't use it again!
dlg.Destroy()
#---------------------------------------------------------------------------
-
-
-
-
-
-
-
-
-
-
overview = """\
This class represents the colour chooser dialog.
+Use of this dialog is a multi-stage process.
-"""
-
-
+The actual information about how to display the dialog and the colors in the
+dialog's 'registers' are contained in a wx.ColourData instance that is created by
+the dialog at init time. Before displaying the dialog, you may alter these settings
+to suit your needs. In the example, we set the dialog up to show the extended colour
+data selection pane. Otherwise, only the more compact and less extensive colour
+dialog is shown. You may also preset the colour as well as other items.
+If the user selects something and selects OK, then the wxColourData instance contains
+the colour data that the user selected. Before destroying the dialog, retrieve the data.
+<b>Do not try to retain the wx.ColourData instance.</b> It will probably not be valid
+after the dialog is destroyed.
+Along with he wxColourDialog documentation, see also the wx.ColourData documentation
+for details.
+"""
if __name__ == '__main__':
import sys,os
-from wxPython.wx import *
+# 11/15/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+
+import wx
#---------------------------------------------------------------------------
-class TestComboBox(wxPanel):
+class TestComboBox(wx.Panel):
def OnSetFocus(self, evt):
print "OnSetFocus"
evt.Skip()
+
def OnKillFocus(self, evt):
print "OnKillFocus"
evt.Skip()
def __init__(self, parent, log):
self.log = log
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
- ##'this is a long item that needs a scrollbar...',
+ #'this is a long item that needs a scrollbar...',
'six', 'seven', 'eight']
- wxStaticText(self, -1, "This example uses the wxComboBox control.",
- wxPoint(8, 10))
+ wx.StaticText(self, -1, "This example uses the wxComboBox control.", (8, 10))
+ wx.StaticText(self, -1, "Select one:", (15, 50), (75, 18))
+
+ # This combobox is created with a preset list of values.
+ cb = wx.ComboBox(
+ self, 500, "default value", (90, 50),
+ (95, -1), sampleList, wx.CB_DROPDOWN #|wxTE_PROCESS_ENTER
+ )
- wxStaticText(self, -1, "Select one:", wxPoint(15, 50), wxSize(75, 18))
- cb = wxComboBox(self, 500, "default value", wxPoint(90, 50), wxSize(95, -1),
- sampleList, wxCB_DROPDOWN)#|wxTE_PROCESS_ENTER)
##import win32api, win32con
##win32api.SendMessage(cb.GetHandle(),
## win32con.CB_SETHORIZONTALEXTENT,
## 200, 0)
- EVT_COMBOBOX(self, 500, self.EvtComboBox)
- EVT_TEXT(self, 500, self.EvtText)
- EVT_TEXT_ENTER(self, 500, self.EvtTextEnter)
- EVT_SET_FOCUS(cb, self.OnSetFocus)
- EVT_KILL_FOCUS(cb, self.OnKillFocus)
+ self.Bind(wx.EVT_COMBOBOX, self.EvtComboBox, cb)
+ self.Bind(wx.EVT_TEXT, self.EvtText, cb)
+ self.Bind(wx.EVT_TEXT_ENTER, self.EvtTextEnter, cb)
+ cb.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
+ cb.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
+ # Once the combobox is set up, we append some more data to it.
cb.Append("foo", "This is some client data for this item")
- cb = wxComboBox(self, 501, "default value", wxPoint(90, 80), wxSize(95, -1),
- [], wxCB_SIMPLE)
+ # This combobox is created with no values initially.
+ cb = wx.ComboBox(
+ self, 501, "default value", (90, 80), (95, -1), [], wx.CB_SIMPLE)
+
+ # Here we dynamically add our values to the second combobox.
for item in sampleList:
cb.Append(item, item.upper())
- EVT_COMBOBOX(self, 501, self.EvtComboBox)
- EVT_TEXT(self, 501, self.EvtText)
+ self.Bind(wx.EVT_COMBOBOX, self.EvtComboBox, cb)
+ self.Bind(wx.EVT_COMBOBOX, self.EvtText, cb)
+ # The user selects something, we go here.
def EvtComboBox(self, evt):
cb = evt.GetEventObject()
data = cb.GetClientData(cb.GetSelection())
self.log.WriteText('EvtComboBox: %s\nClientData: %s\n' % (evt.GetString(), data))
+ if evt.GetString() == 'one':
+ self.log.WriteText("You follow directions well!\n\n")
+
+ # Capture events every time a user hits a key in the text entry field.
def EvtText(self, evt):
self.log.WriteText('EvtText: %s\n' % evt.GetString())
+ # Capture events when the user types something into the control then
+ # hits ENTER.
def EvtTextEnter(self, evt):
- self.log.WriteText('EvtTextEnter: does this work?')
+ self.log.WriteText('EvtTextEnter: %s' % evt.GetString())
#---------------------------------------------------------------------------
+overview = """\
+A ComboBox is like a combination of an edit control and a listbox. It can be
+displayed as static list with editable or read-only text field; or a drop-down
+list with text field; or a drop-down list without a text field.
+This example shows both a preset ComboBox and one that is dynamically created
+(that is, it is initially empty but then we 'grow' it out of program-supplied
+data). The former is common for read-only controls.
+This example also shows the two form factors for the ComboBox. The first is more
+common, and resembles a Choice control. The latter, although less common, shows
+how all the values in the ComboBox can be visible, yet the functionality is the
+same for both.
-
-overview = """\
-A combobox is like a combination of an edit control and a listbox. It can be displayed as static list with editable or read-only text field; or a drop-down list with text field; or a drop-down list without a text field.
+Finally, this demo shows how event handling can differ. The first ComboBox is set
+up to handle EVT_TEXT_ENTER events, in which text is typed in and then ENTER is
+hit by the user. This allows the user to enter a line of text which can then be
+processed by the program. EVT_TEXT can also be processed, but in that case the
+event is generated every time that the user hits a key in the ComboBox entry field.
"""
-
-
if __name__ == '__main__':
import sys,os
import run
+# 11/15/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
-##from wxPython.help import *
+import wx
#---------------------------------------------------------------------------
# Create and set a help provider. Normally you would do this in
# the app's OnInit as it must be done before any SetHelpText calls.
-provider = wxSimpleHelpProvider()
-wxHelpProvider_Set(provider)
-
-
+provider = wx.SimpleHelpProvider()
+wx.HelpProvider_Set(provider)
#---------------------------------------------------------------------------
-class TestDialog(wxDialog):
- def __init__(self, parent, ID, title,
- pos=wxDefaultPosition, size=wxDefaultSize,
- style=wxDEFAULT_DIALOG_STYLE):
+class TestDialog(wx.Dialog):
+ def __init__(
+ self, parent, ID, title, size=wx.DefaultSize, pos=wx.DefaultPosition,
+ style=wx.DEFAULT_DIALOG_STYLE
+ ):
# Instead of calling wxDialog.__init__ we precreate the dialog
- # object so we can set an extra style that must be set before
+ # so we can set an extra style that must be set before
# creation, and then we create the GUI dialog using the Create
# method.
- pre = wxPreDialog()
- pre.SetExtraStyle(wxDIALOG_EX_CONTEXTHELP)
+ pre = wx.PreDialog()
+ pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP)
pre.Create(parent, ID, title, pos, size, style)
# This next step is the most important, it turns this Python
# object into the real wrapper of the dialog (instead of pre)
# as far as the wxPython extension is concerned.
- self.PostCreate(pre)
+ self.this = pre.this
# Now continue with the normal construction of the dialog
# contents
- sizer = wxBoxSizer(wxVERTICAL)
+ sizer = wx.BoxSizer(wx.VERTICAL)
- label = wxStaticText(self, -1, "This is a wxDialog")
+ label = wx.StaticText(self, -1, "This is a wxDialog")
label.SetHelpText("This is the help text for the label")
- sizer.Add(label, 0, wxALIGN_CENTRE|wxALL, 5)
+ sizer.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
- box = wxBoxSizer(wxHORIZONTAL)
+ box = wx.BoxSizer(wx.HORIZONTAL)
- label = wxStaticText(self, -1, "Field #1:")
+ label = wx.StaticText(self, -1, "Field #1:")
label.SetHelpText("This is the help text for the label")
- box.Add(label, 0, wxALIGN_CENTRE|wxALL, 5)
+ box.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
- text = wxTextCtrl(self, -1, "", size=(80,-1))
+ text = wx.TextCtrl(self, -1, "", size=(80,-1))
text.SetHelpText("Here's some help text for field #1")
- box.Add(text, 1, wxALIGN_CENTRE|wxALL, 5)
+ box.Add(text, 1, wx.ALIGN_CENTRE|wx.ALL, 5)
- sizer.AddSizer(box, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5)
+ sizer.AddSizer(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
- box = wxBoxSizer(wxHORIZONTAL)
+ box = wx.BoxSizer(wx.HORIZONTAL)
- label = wxStaticText(self, -1, "Field #2:")
+ label = wx.StaticText(self, -1, "Field #2:")
label.SetHelpText("This is the help text for the label")
- box.Add(label, 0, wxALIGN_CENTRE|wxALL, 5)
+ box.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
- text = wxTextCtrl(self, -1, "", size=(80,-1))
+ text = wx.TextCtrl(self, -1, "", size=(80,-1))
text.SetHelpText("Here's some help text for field #2")
- box.Add(text, 1, wxALIGN_CENTRE|wxALL, 5)
+ box.Add(text, 1, wx.ALIGN_CENTRE|wx.ALL, 5)
- sizer.AddSizer(box, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5)
+ sizer.AddSizer(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
- line = wxStaticLine(self, -1, size=(20,-1), style=wxLI_HORIZONTAL)
- sizer.Add(line, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxRIGHT|wxTOP, 5)
+ line = wx.StaticLine(self, -1, size=(20,-1), style=wx.LI_HORIZONTAL)
+ sizer.Add(line, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP, 5)
- box = wxBoxSizer(wxHORIZONTAL)
+ box = wx.BoxSizer(wx.HORIZONTAL)
- if wxPlatform != "__WXMSW__":
- btn = wxContextHelpButton(self)
- box.Add(btn, 0, wxALIGN_CENTRE|wxALL, 5)
+ if wx.Platform != "__WXMSW__":
+ btn = wx.ContextHelpButton(self)
+ box.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
- btn = wxButton(self, wxID_OK, " OK ")
+ btn = wx.Button(self, wx.ID_OK, " OK ")
btn.SetDefault()
btn.SetHelpText("The OK button completes the dialog")
- box.Add(btn, 0, wxALIGN_CENTRE|wxALL, 5)
+ box.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
- btn = wxButton(self, wxID_CANCEL, " Cancel ")
- btn.SetHelpText("The Cancel button cnacels the dialog. (Duh!)")
- box.Add(btn, 0, wxALIGN_CENTRE|wxALL, 5)
+ btn = wx.Button(self, wx.ID_CANCEL, " Cancel ")
+ btn.SetHelpText("The Cancel button cnacels the dialog. (Cool, huh?)")
+ box.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
- sizer.Add(box, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5)
+ sizer.Add(box, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
self.SetSizer(sizer)
self.SetAutoLayout(True)
sizer.Fit(self)
-
-
#---------------------------------------------------------------------------
def runTest(frame, nb, log):
- win = TestDialog(frame, -1, "This is a wxDialog", size=wxSize(350, 200),
+ win = TestDialog(frame, -1, "This is a Dialog", size=(350, 200),
#style = wxCAPTION | wxSYSTEM_MENU | wxTHICK_FRAME
- style = wxDEFAULT_DIALOG_STYLE
+ style = wx.DEFAULT_DIALOG_STYLE
)
win.CenterOnScreen()
val = win.ShowModal()
- if val == wxID_OK:
+
+ if val == wx.ID_OK:
log.WriteText("You pressed OK\n")
else:
log.WriteText("You pressed Cancel\n")
+
win.Destroy()
-#---------------------------------------------------------------------------
+#---------------------------------------------------------------------------
+overview = """\
+wxPython offers quite a few general purpose dialogs for useful data input from
+the user; they are all based on the wx.Dialog class, which you can also subclass
+to create custom dialogs to suit your needs.
+The Dialog class, in addition to dialog-like behaviors, also supports the full
+wxWindows layout featureset, which means that you can incorporate sizers or
+layout constraints as needed to achieve the look and feel desired. It even supports
+context-sensitive help, which is illustrated in this example.
-overview = """\
-"""
+The example is very simple; in real world situations, a dialog that had input
+fields such as this would no doubt be required to deliver those values back to
+the calling function. The Dialog class supports data retrieval in this manner.
+<b>However, the data must be retrieved prior to the dialog being destroyed.</b>
+The example shown here is <i>modal</i>; non-modal dialogs are possible as well.
+See the documentation for the <code>Dialog</code> class for more details.
+"""
if __name__ == '__main__':
import sys,os
+# 11/17/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
+import wx
#---------------------------------------------------------------------------
def runTest(frame, nb, log):
- dlg = wxDirDialog(frame, "Choose a directory:",
- style=wxDD_DEFAULT_STYLE|wxDD_NEW_DIR_BUTTON)
- if dlg.ShowModal() == wxID_OK:
+
+ # In this case we include a "New directory" button.
+ dlg = wx.DirDialog(frame, "Choose a directory:",
+ style=wx.DD_DEFAULT_STYLE|wx.DD_NEW_DIR_BUTTON)
+
+ # If the user selects OK, then we process the dialog's data.
+ # This is done by getting the path data from the dialog - BEFORE
+ # we destroy it.
+ if dlg.ShowModal() == wx.ID_OK:
log.WriteText('You selected: %s\n' % dlg.GetPath())
+
+ # Only destroy a dialog after you're done with it.
dlg.Destroy()
#---------------------------------------------------------------------------
-
-
overview = """\
-This class represents the directory chooser dialog.
+This class represents the directory chooser dialog. It is used when all you
+need from the user is the name of a directory. Data is retrieved via utility
+methods; see the <code>DirDialog</code> documentation for specifics.
"""
+# 11/15/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
-
-import images
+import wx
+import images
#----------------------------------------------------------------------
class DragShape:
def __init__(self, bmp):
self.bmp = bmp
- self.pos = wxPoint(0,0)
+ self.pos = (0,0)
self.shown = True
self.text = None
self.fullscreen = False
-
def HitTest(self, pt):
rect = self.GetRect()
return rect.InsideXY(pt.x, pt.y)
-
def GetRect(self):
- return wxRect(self.pos.x, self.pos.y,
+ return wx.Rect(self.pos[0], self.pos[1],
self.bmp.GetWidth(), self.bmp.GetHeight())
-
- def Draw(self, dc, op = wxCOPY):
+ def Draw(self, dc, op = wx.COPY):
if self.bmp.Ok():
- memDC = wxMemoryDC()
+ memDC = wx.MemoryDC()
memDC.SelectObject(self.bmp)
dc.Blit((self.pos.x, self.pos.y),
#----------------------------------------------------------------------
-class DragCanvas(wxScrolledWindow):
+class DragCanvas(wx.ScrolledWindow):
def __init__(self, parent, ID):
- wxScrolledWindow.__init__(self, parent, ID)
+ wx.ScrolledWindow.__init__(self, parent, ID)
self.shapes = []
self.dragImage = None
self.dragShape = None
self.hiliteShape = None
- self.SetCursor(wxStockCursor(wxCURSOR_ARROW))
+ self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
self.bg_bmp = images.getBackgroundBitmap()
-
# Make a shape from an image and mask. This one will demo
# dragging outside the window
bmp = images.getTestStarBitmap()
shape = DragShape(bmp)
- shape.pos = wxPoint(5, 5)
+ shape.pos = (5, 5)
shape.fullscreen = True
self.shapes.append(shape)
-
# Make a shape from some text
text = "Some Text"
- bg_colour = wxColour(57, 115, 57) # matches the bg image
- font = wxFont(15, wxROMAN, wxNORMAL, wxBOLD)
+ bg_colour = wx.Colour(57, 115, 57) # matches the bg image
+ font = wx.Font(15, wx.ROMAN, wx.NORMAL, wx.BOLD)
textExtent = self.GetFullTextExtent(text, font)
- bmp = wxEmptyBitmap(textExtent[0], textExtent[1])
- dc = wxMemoryDC()
+
+ # create a bitmap the same size as our text
+ bmp = wx.EmptyBitmap(textExtent[0], textExtent[1])
+
+ # 'draw' the text onto the bitmap
+ dc = wx.MemoryDC()
dc.SelectObject(bmp)
- dc.SetBackground(wxBrush(bg_colour, wxSOLID))
+ dc.SetBackground(wx.Brush(bg_colour, wx.SOLID))
dc.Clear()
- dc.SetTextForeground(wxRED)
+ dc.SetTextForeground(wx.RED)
dc.SetFont(font)
dc.DrawText(text, (0, 0))
dc.SelectObject(wxNullBitmap)
mask = wxMaskColour(bmp, bg_colour)
bmp.SetMask(mask)
shape = DragShape(bmp)
- shape.pos = wxPoint(5, 100)
+ shape.pos = (5, 100)
shape.text = "Some dragging text"
self.shapes.append(shape)
# Make some shapes from some playing card images.
x = 200
+
for card in ['_01c_', '_12h_', '_13d_', '_10s_']:
bmpFunc = getattr(images, "get%sBitmap" % card)
bmp = bmpFunc()
shape = DragShape(bmp)
- shape.pos = wxPoint(x, 5)
+ shape.pos = (x, 5)
self.shapes.append(shape)
x = x + 80
- EVT_ERASE_BACKGROUND(self, self.OnEraseBackground)
- EVT_PAINT(self, self.OnPaint)
- EVT_LEFT_DOWN(self, self.OnLeftDown)
- EVT_LEFT_UP(self, self.OnLeftUp)
- EVT_MOTION(self, self.OnMotion)
- EVT_LEAVE_WINDOW(self, self.OnLeaveWindow)
-
+ self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
+ self.Bind(wx.EVT_PAINT, self.OnPaint)
+ 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_LEAVE_WINDOW, self.OnLeaveWindow)
+
+ # We're not doing anything here, but you might have reason to.
+ # for example, if you were dragging something, you might elect to
+ # 'drop it' when the cursor left the window.
def OnLeaveWindow(self, evt):
pass
+ # tile the background bitmap
def TileBackground(self, dc):
- # tile the background bitmap
sz = self.GetClientSize()
w = self.bg_bmp.GetWidth()
h = self.bg_bmp.GetHeight()
x = 0
+
while x < sz.width:
y = 0
+
while y < sz.height:
dc.DrawBitmap(self.bg_bmp, (x, y))
y = y + h
+
x = x + w
+ # Go through our list of shapes and draw them in whatever place they are.
def DrawShapes(self, dc):
for shape in self.shapes:
if shape.shown:
shape.Draw(dc)
-
+ # This is actually a sophisticated 'hit test', but in this
+ # case we're also determining which shape, if any, was 'hit'.
def FindShape(self, pt):
for shape in self.shapes:
if shape.HitTest(pt):
return shape
return None
-
+ # Remove a shape from the display
def EraseShape(self, shape, dc):
r = shape.GetRect()
dc.SetClippingRect(r)
self.DrawShapes(dc)
dc.DestroyClippingRegion()
-
+ # Clears the background, then redraws it. If the DC is passed, then
+ # we only do so in the area so designated. Otherwise, it's the whole thing.
def OnEraseBackground(self, evt):
dc = evt.GetDC()
+
if not dc:
dc = wxClientDC(self)
rect = self.GetUpdateRegion().GetBox()
dc.SetClippingRect(rect)
self.TileBackground(dc)
-
+ # Fired whenever a paint event occurs
def OnPaint(self, evt):
- dc = wxPaintDC(self)
+ dc = wx.PaintDC(self)
self.PrepareDC(dc)
self.DrawShapes(dc)
-
+ # Left mouse button is down.
def OnLeftDown(self, evt):
+ # Did the mouse go down on one of our shapes?
shape = self.FindShape(evt.GetPosition())
+
+ # If a shape was 'hit', then set that as the shape we're going to
+ # drag around. Get our start position. Dragging has not yet started.
+ # That will happen once the mouse moves, OR the mouse is released.
if shape:
- # get ready to start dragging, but wait for the user to
- # move it a bit first
self.dragShape = shape
self.dragStartPos = evt.GetPosition()
-
+ # Left mouse button up.
def OnLeftUp(self, evt):
if not self.dragImage or not self.dragShape:
self.dragImage = None
self.dragShape = None
return
- # end the dragging
+ # Hide the image, end dragging, and nuke out the drag image.
self.dragImage.Hide()
self.dragImage.EndDrag()
self.dragImage = None
- dc = wxClientDC(self)
+ dc = wx.ClientDC(self)
+
if self.hiliteShape:
self.hiliteShape.Draw(dc)
self.hiliteShape = None
# reposition and draw the shape
- self.dragShape.pos = self.dragShape.pos + evt.GetPosition() - self.dragStartPos
+
+ # Note by jmg 11/28/03
+ # Here's the original:
+ #
+ # self.dragShape.pos = self.dragShape.pos + evt.GetPosition() - self.dragStartPos
+ #
+ # So if there are any problems associated with this, use that as
+ # a starting place in your investigation. I've tried to simulate the
+ # wx.Point __add__ method here -- it won't work for tuples as we
+ # have now from the various methods
+ #
+ # There must be a better way to do this :-)
+ #
+
+ self.dragShape.pos = (
+ self.dragShape.pos[0] + evt.GetPosition()[0] - self.dragStartPos[0],
+ self.dragShape.pos[1] + evt.GetPosition()[1] - self.dragStartPos[1]
+ )
+
self.dragShape.shown = True
self.dragShape.Draw(dc)
self.dragShape = None
-
+ # The mouse is moving
def OnMotion(self, evt):
+ # Ignore mouse movement if we're not dragging.
if not self.dragShape or not evt.Dragging() or not evt.LeftIsDown():
return
return
# erase the shape since it will be drawn independently now
- dc = wxClientDC(self)
+ dc = wx.ClientDC(self)
self.dragShape.shown = False
self.EraseShape(self.dragShape, dc)
if self.dragShape.text:
- self.dragImage = wxDragString(self.dragShape.text,
- wxStockCursor(wxCURSOR_HAND))
+ self.dragImage = wx.DragString(self.dragShape.text,
+ wx.StockCursor(wx.CURSOR_HAND))
else:
- self.dragImage = wxDragImage(self.dragShape.bmp,
- wxStockCursor(wxCURSOR_HAND))
+ self.dragImage = wx.DragImage(self.dragShape.bmp,
+ wx.StockCursor(wx.CURSOR_HAND))
hotspot = self.dragStartPos - self.dragShape.pos
self.dragImage.BeginDrag(hotspot, self, self.dragShape.fullscreen)
self.dragImage.Hide()
if unhiliteOld:
- dc = wxClientDC(self)
+ dc = wx.ClientDC(self)
self.hiliteShape.Draw(dc)
self.hiliteShape = None
if hiliteNew:
- dc = wxClientDC(self)
+ dc = wx.ClientDC(self)
self.hiliteShape = onShape
- self.hiliteShape.Draw(dc, wxINVERT)
+ self.hiliteShape.Draw(dc, wx.INVERT)
# now move it and show it again if needed
self.dragImage.Move(evt.GetPosition())
#----------------------------------------------------------------------
def runTest(frame, nb, log):
- win = wxPanel(nb, -1)
+
+ win = wx.Panel(nb, -1)
canvas = DragCanvas(win, -1)
- def onSize(evt, panel=win, canvas=canvas): canvas.SetSize(panel.GetSize())
- EVT_SIZE(win, onSize)
+
+ def onSize(evt, panel=win, canvas=canvas):
+ canvas.SetSize(panel.GetSize())
+
+ win.Bind(wx.EVT_SIZE, onSize)
return win
#----------------------------------------------------------------------
overview = """\
+DragImage is used when you wish to drag an object on the screen, and a simple
+cursor is not enough.
+
+On Windows, the WIN32 API is used to do achieve smooth dragging. On other
+platforms, <code>GenericDragImage</code> is used. Applications may also prefer to use
+<code>GenericDragImage</code> on Windows, too.
+
+<b>wxPython note</b>: wxPython uses <code>GenericDragImage</code> on all
+platforms, but uses the <code>DragImage</code> name.
+
+To use this class, when you wish to start dragging an image, create a
+<code>DragImage</code> object and store it somewhere you can access it as the
+drag progresses. Call BeginDrag to start, and EndDrag to stop the drag. To move
+the image, initially call Show and then Move. If you wish to update the screen
+contents during the drag (for example, highlight an item as in the example), first
+call Hide, update the screen, call Move, and then call Show.
+
+You can drag within one window, or you can use full-screen dragging either across
+the whole screen, or just restricted to one area of the screen to save resources.
+If you want the user to drag between two windows, then you will need to use
+full-screen dragging.
+
"""
+# 11/17/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
-from wxPython.gizmos import *
-from wxPython.stc import *
+import wx
+import wx.gizmos as gizmos
+import wx.stc as stc
#----------------------------------------------------------------------
# This is an example of the complex view that manages its own scrollbars
# as described in the overview below.
-class TestView(wxStyledTextCtrl):
+class TestView(stc.StyledTextCtrl):
def __init__(self, parent, ID, log):
- wxStyledTextCtrl.__init__(self, parent, ID, style=wxNO_BORDER)
+ stc.StyledTextCtrl.__init__(self, parent, ID, style=wx.NO_BORDER)
self.dyn_sash = parent
self.log = log
self.SetupScrollBars()
self.SetMarginWidth(1,0)
- self.StyleSetFont(wxSTC_STYLE_DEFAULT,
- wxFont(10, wxMODERN, wxNORMAL, wxNORMAL))
- EVT_DYNAMIC_SASH_SPLIT(self, -1, self.OnSplit)
- EVT_DYNAMIC_SASH_UNIFY(self, -1, self.OnUnify)
+
+ self.StyleSetFont(stc.STC_STYLE_DEFAULT,
+ wx.Font(10, wx.MODERN, wx.NORMAL, wx.NORMAL))
+
+ self.Bind(gizmos.EVT_DYNAMIC_SASH_SPLIT, self.OnSplit)
+ self.Bind(gizmos.EVT_DYNAMIC_SASH_UNIFY, self.OnUnify)
#self.SetScrollWidth(500)
def SetupScrollBars(self):
# to this view
v_bar = self.dyn_sash.GetVScrollBar(self)
h_bar = self.dyn_sash.GetHScrollBar(self)
- EVT_SCROLL(v_bar, self.OnSBScroll)
- EVT_SCROLL(h_bar, self.OnSBScroll)
- EVT_SET_FOCUS(v_bar, self.OnSBFocus)
- EVT_SET_FOCUS(h_bar, self.OnSBFocus)
+ v_bar.Bind(wx.EVT_SCROLL, self.OnSBScroll)
+ h_bar.Bind(wx.EVT_SCROLL, self.OnSBScroll)
+ v_bar.Bind(wx.EVT_SET_FOCUS, self.OnSBFocus)
+ h_bar.Bind(wx.EVT_SET_FOCUS, self.OnSBFocus)
# And set the wxStyledText to use these scrollbars instead
# of its built-in ones.
In this case the views also share the same document so changes in one
are instantly seen in the others. This is a feature of the
-wxStyledTextCtrl that is used for the view class in this sample.
+StyledTextCtrl that is used for the view class in this sample.
"""
#----------------------------------------------------------------------
# This one is simpler, but doesn't do anything with the scrollbars
# except the default wxDynamicSashWindow behaviour
-class SimpleView(wxPanel):
+class SimpleView(wx.Panel):
def __init__(self, parent, ID, log):
- wxPanel.__init__(self, parent, ID)
+ wx.Panel.__init__(self, parent, ID)
self.dyn_sash = parent
self.log = log
self.SetBackgroundColour("LIGHT BLUE")
- EVT_DYNAMIC_SASH_SPLIT(self, -1, self.OnSplit)
+ self.Bind(gizmos.EVT_DYNAMIC_SASH_SPLIT, self.OnSplit)
def OnSplit(self, evt):
v = SimpleView(self.dyn_sash, -1, self.log)
#----------------------------------------------------------------------
def runTest(frame, nb, log):
- if wxPlatform == "__WXMAC__":
- wxMessageBox("This demo currently fails on the Mac. The problem is being looked into...", "Sorry")
+ if wx.Platform == "__WXMAC__":
+ wx.MessageBox("This demo currently fails on the Mac. The problem is being looked into...", "Sorry")
return
if 1:
- win = wxDynamicSashWindow(nb, -1, style = 0
- | wxCLIP_CHILDREN
+ win = gizmos.DynamicSashWindow(nb, -1, style = wx.CLIP_CHILDREN
#| wxDS_MANAGE_SCROLLBARS
#| wxDS_DRAG_CORNER
)
- win.SetFont(wxFont(10, wxMODERN, wxNORMAL, wxNORMAL))
+
+ win.SetFont(wx.Font(10, wx.MODERN, wx.NORMAL, wx.NORMAL))
view = TestView(win, -1, log)
view.SetText(sampleText)
else:
- win = wxDynamicSashWindow(nb, -1)
+ win = wx.DynamicSashWindow(nb, -1)
view = SimpleView(win, -1, log)
return win
overview = """\
<html><body>
-<h2>wxDynamicSashWindow</h2>
+<h2>DynamicSashWindow</h2>
<p>
wxDynamicSashWindow widgets manages the way other widgets are viewed.
When a wxDynamicSashWindow is first shown, it will contain one child
-from wxPython.wx import *
-from wxPython.gizmos import *
+# 11/17/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+# o Added overview text based on source code delving.
+#
+
+import wx
+import wx.gizmos as gizmos
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.log = log
- self.elb = wxEditableListBox(self, -1, "List of Stuff",
- (50,50), (250, 250),
- )
- #style=wxEL_ALLOW_NEW | wxEL_ALLOW_EDIT | wxEL_ALLOW_DELETE)
+ self.elb = gizmos.EditableListBox(
+ self, -1, "List of Stuff", (50,50), (250, 250)
+ )
+ #style=wx.EL_ALLOW_NEW | wx.EL_ALLOW_EDIT | wx.EL_ALLOW_DELETE)
self.elb.SetStrings(["This is a nifty ListBox widget",
"that is editable by the user.",
win = TestPanel(nb, log)
return win
-
#----------------------------------------------------------------------
-
-
overview = """\
-This class provides a composite control that lets the
-user easily enter and edit a list of strings.
+<html>
+<body>
+This class provides a composite control that lets the user easily enter and edit
+a list of strings.
+
+<p><b>Styles supported:</b><p>
+
+<ul>
+<li><b>EL_ALLOW_NEW</b> - Allow user to create new items.
+<li><b>EL_ALLOW_EDIT</b> - Allow user to edit text in the control.
+<li><b>EL_ALLOW_DELETE</b> - Allow user to delete text from the control.
+</ul>
+
+<p><b>Init:</b>
+<pre>
+ EditableListBox(wxWindow *parent, wxWindowID id=-1,
+ const wxString& label,
+ const wxPoint& pos = wxDefaultPosition,
+ const wxSize& size = wxDefaultSize,
+ long style = EL_ALLOW_NEW | EL_ALLOW_EDIT | EL_ALLOW_DELETE,
+ const wxString& name = "editableListBox")
+</pre>
+
+<p><b>Methods:</b>
+<ul>
+ <li><b>SetStrings(const wxArrayString& strings)</b> - Set an array of strings
+ into the control. <b>Note</b>: The wxPython method accepts a Python list instead
+ of an array of strings.
+
+ <li><b>void GetStrings(wxArrayString& strings)</b> - Retrieves an array
+ of strings from the control. The wxPython version returns a list of strings.
+
+ <li><b>GetListCtrl()</b> - Retrieves a reference to the actual list control
+ portion of the custom control.
+
+ <li><b>GetDelButton()</b> - Retrieves a reference to the BitmapButton that is used
+ as the 'delete' button in the control.
+
+ <li><b>GetNewButton()</b> - Retrieves a reference to the BitmapButton that is used
+ as the 'new' button in the control.
+
+ <li><b>GetUpButton()</b> - Retrieves a reference to the BitmapButton that is used
+ as the 'up' button in the control.
+
+ <li><b>GetDownButton()</b> - Retrieves a reference to the BitmapButton that is used
+ as the 'down' button in the control.
+
+ <li><b>GetEditButton()</b> - Retrieves a reference to the BitmapButton that is used
+ as the 'edit' button in the control.
+</ul>
+</body>
+</html>
"""
-
-
if __name__ == '__main__':
import sys,os
import run
-
-from wxPython.wx import *
-from wxPython.lib.editor import wxEditor
+# 11/17/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+# 11/28/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o editor lib hasn't been hit by the renamer yet.
+#
+
+import wx
+import wx.lib.editor as editor
#----------------------------------------------------------------------
def runTest(frame, nb, log):
- win = wxPanel(nb, -1)
- ed = wxEditor(win, -1, style=wxSUNKEN_BORDER)
- box = wxBoxSizer(wxVERTICAL)
- box.Add(ed, 1, wxALL|wxGROW, 1)
+ win = wx.Panel(nb, -1)
+ ed = editor.wxEditor(win, -1, style=wx.SUNKEN_BORDER)
+ box = wx.BoxSizer(wx.VERTICAL)
+ box.Add(ed, 1, wx.ALL|wx.GROW, 1)
win.SetSizer(box)
win.SetAutoLayout(True)
Alt key commands. In that case you would (for example) override the
SetAltFuncs() method.
-
"""
+# 11/17/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
-import os
+import os
+import wx
#---------------------------------------------------------------------------
+# This is how you pre-establish a file filter so that the dialog
+# only shows the extention(s) you want it to.
wildcard = "Python source (*.py)|*.py|" \
"Compiled Python (*.pyc)|*.pyc|" \
"All files (*.*)|*.*"
def runTest(frame, nb, log):
log.WriteText("CWD: %s\n" % os.getcwd())
- dlg = wxFileDialog(frame, "Choose a file", os.getcwd(), "", wildcard,
- wxOPEN
- | wxMULTIPLE
- #| wxCHANGE_DIR
- )
- if dlg.ShowModal() == wxID_OK:
+
+ # Create the dialog. In this case the current directory is forced as the starting
+ # directory for the dialog, and no default file name is forced. This can easilly
+ # be changed in your program. This is an 'open' dialog, and allows multitple
+ # file selection to boot.
+ #
+ # Finally, of the directory is changed in the process of getting files, this
+ # dialog is set up to change the current working directory to the path chosen.
+ dlg = wx.FileDialog(
+ frame, message="Choose a file", defaultDir=os.getcwd(),
+ defaultFile="", wildcard=wildcard, style=wx.OPEN | wx.MULTIPLE | wx.CHANGE_DIR
+ )
+
+ # Show the dialog and retrieve the user response. If it is the OK response,
+ # process the data.
+ if dlg.ShowModal() == wx.ID_OK:
+ # This returns a Python list of files that were selected.
paths = dlg.GetPaths()
+
log.WriteText('You selected %d files:' % len(paths))
+
for path in paths:
log.WriteText(' %s\n' % path)
+
+ # Compare this with the debug above; did we change working dirs?
log.WriteText("CWD: %s\n" % os.getcwd())
+
+ # Destroy the dialog. Don't do this until you are done with it!
+ # BAD things can happen otherwise!
dlg.Destroy()
#---------------------------------------------------------------------------
-
-
-
-
-
overview = """\
-This class provides the file chooser dialog.
+This class provides the file selection dialog. It incorporates OS-native features
+depending on the OS in use, and can be used both for open and save operations.
+The files displayed can be filtered by setting up a wildcard filter, multiple files
+can be selected (open only), and files can be forced in a read-only mode.
+
+There are two ways to get the results back from the dialog. GetFiles() returns only
+the file names themselves, in a Python list. GetPaths() returns the full path and
+filenames combined as a Python list.
"""
+# 11/17/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
-import os
+import os
+import wx
#---------------------------------------------------------------------------
+# This is how you pre-establish a file filter so that the dialog
+# only shows the extention(s) you want it to.
wildcard = "Python source (*.py)|*.py|" \
"Compiled Python (*.pyc)|*.pyc|" \
"SPAM files (*.spam)|*.spam|" \
def runTest(frame, nb, log):
log.WriteText("CWD: %s\n" % os.getcwd())
- dlg = wxFileDialog(frame, "Save file as...", os.getcwd(), "", wildcard,
- wxSAVE
- #| wxCHANGE_DIR
- )
+
+ # Create the dialog. In this case the current directory is forced as the starting
+ # directory for the dialog, and no default file name is forced. This can easilly
+ # be changed in your program. This is an 'save' dialog.
+ #
+ # Unlike the 'open dialog' example found elsewhere, this example does NOT
+ # force the current working directory to change if the user chooses a different
+ # directory than the one initially set.
+ dlg = wx.FileDialog(
+ frame, message="Save file as ...", defaultDir=os.getcwd(),
+ defaultFile="", wildcard=wildcard, style=wx.SAVE
+ )
+
+ # This sets the default filter that the user will initially see. Otherwise,
+ # the first filter in the list will be used by default.
dlg.SetFilterIndex(2)
- if dlg.ShowModal() == wxID_OK:
+
+ # Show the dialog and retrieve the user response. If it is the OK response,
+ # process the data.
+ if dlg.ShowModal() == wx.ID_OK:
path = dlg.GetPath()
log.WriteText('You selected "%s"' % path)
+
+ # Normally, at this point you would save your data using the file and path
+ # data that the user provided to you, but since we didn't actually start
+ # with any data to work with, that would be difficult.
+ #
+ # The code to do so would be similar to this, assuming 'data' contains
+ # the data you want to save:
+ #
+ # fp = file(path, 'w') # Create file anew
+ # fp.write(data)
+ # fp.close()
+ #
+ # You might want to add some error checking :-)
+ #
+
+ # Note that the current working dir didn't change. This is good since
+ # that's the way we set it up.
log.WriteText("CWD: %s\n" % os.getcwd())
+
+ # Destroy the dialog. Don't do this until you are done with it!
+ # BAD things can happen otherwise!
dlg.Destroy()
#---------------------------------------------------------------------------
-
-
-
-
-
overview = """\
-This class provides the file chooser dialog.
-
+This class provides the file selection dialog. It incorporates OS-native features
+depending on the OS in use, and can be used both for open and save operations.
+The files displayed can be filtered by setting up a wildcard filter, multiple files
+can be selected (open only), and files can be forced in a read-only mode.
+
+There are two ways to get the results back from the dialog. GetFiles() returns only
+the file names themselves, in a Python list. GetPaths() returns the full path and
+filenames combined as a Python list.
+
+One important thing to note: if you use the file extention filters, then files saved
+with the filter set to something will automatically get that extention appended to them
+if it is not already there. For example, suppose the dialog was displaying the 'egg'
+extention and you entered a file name of 'fried'. It would be saved as 'fried.egg.'
+Yum!
"""
+# 11/17/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
-import os
+import os
+import wx
#----------------------------------------------------------------------
text = """\
-Right-click on the panel to get a menu. This menu will be managed by
-a wxFileHistory object and so the files you select will automatically
-be added to the end of the menu and will be selectable the next time
-the menu is viewed. The filename selected, either via the Open menu
-item, or from the history, will be displayed in the log window below.
+Right-click on the panel above the line to get a menu. This menu will
+be managed by a FileHistory object and so the files you select will
+automatically be added to the end of the menu and will be selectable
+the next time the menu is viewed. The filename selected, either via the
+Open menu item, or from the history, will be displayed in the log
+window below.
"""
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
self.log = log
- wxPanel.__init__(self, parent, -1)
- box = wxBoxSizer(wxVERTICAL)
+ wx.Panel.__init__(self, parent, -1)
+ box = wx.BoxSizer(wx.VERTICAL)
# Make and layout the controls
fs = self.GetFont().GetPointSize()
- bf = wxFont(fs+4, wxSWISS, wxNORMAL, wxBOLD)
- nf = wxFont(fs+2, wxSWISS, wxNORMAL, wxNORMAL)
+ bf = wx.Font(fs+4, wx.SWISS, wx.NORMAL, wx.BOLD)
+ nf = wx.Font(fs+2, wx.SWISS, wx.NORMAL, wx.NORMAL)
- t = wxStaticText(self, -1, "wxFileHistory")
+ t = wx.StaticText(self, -1, "FileHistory")
t.SetFont(bf)
- box.Add(t, 0, wxCENTER|wxALL, 5)
+ box.Add(t, 0, wx.CENTER|wx.ALL, 5)
- box.Add(wxStaticLine(self, -1), 0, wxEXPAND)
+ box.Add(wx.StaticLine(self, -1), 0, wx.EXPAND)
box.Add((10,20))
- t = wxStaticText(self, -1, text)
+ t = wx.StaticText(self, -1, text)
t.SetFont(nf)
- box.Add(t, 0, wxCENTER|wxALL, 5)
+ box.Add(t, 0, wx.CENTER|wx.ALL, 5)
self.SetSizer(box)
self.SetAutoLayout(True)
# Make a menu
- self.menu = m = wxMenu()
- m.Append(wxID_NEW, "&New")
- m.Append(wxID_OPEN, "&Open...")
- m.Append(wxID_CLOSE, "&Close")
- m.Append(wxID_SAVE, "&Save")
- m.Append(wxID_SAVEAS, "Save &as...")
- m.Enable(wxID_NEW, False)
- m.Enable(wxID_CLOSE, False)
- m.Enable(wxID_SAVE, False)
- m.Enable(wxID_SAVEAS, False)
+ self.menu = m = wx.Menu()
+
+ # Little know wx Fact #42: there are a number of pre-set IDs
+ # in the wx package, to be used for common controls such as those
+ # illustrated below. Neat, huh?
+ m.Append(wx.ID_NEW, "&New")
+ m.Append(wx.ID_OPEN, "&Open...")
+ m.Append(wx.ID_CLOSE, "&Close")
+ m.Append(wx.ID_SAVE, "&Save")
+ m.Append(wx.ID_SAVEAS, "Save &as...")
+ m.Enable(wx.ID_NEW, False)
+ m.Enable(wx.ID_CLOSE, False)
+ m.Enable(wx.ID_SAVE, False)
+ m.Enable(wx.ID_SAVEAS, False)
# and a file history
- self.filehistory = wxFileHistory()
+ self.filehistory = wx.FileHistory()
self.filehistory.UseMenu(self.menu)
# and finally the event handler bindings
- EVT_RIGHT_UP(self, self.OnRightClick)
- EVT_MENU(self, wxID_OPEN, self.OnFileOpenDialog)
- EVT_MENU_RANGE(self, wxID_FILE1, wxID_FILE9, self.OnFileHistory)
- EVT_WINDOW_DESTROY(self, self.Cleanup)
+ self.Bind(wx.EVT_RIGHT_UP, self.OnRightClick)
+
+ self.Bind(wx.EVT_MENU, self.OnFileOpenDialog, id=wx.ID_OPEN)
+
+ self.Bind(
+ wx.EVT_MENU_RANGE, self.OnFileHistory, id=wx.ID_FILE1, id2=wx.ID_FILE9
+ )
+
+ self.Bind(wx.EVT_WINDOW_DESTROY, self.Cleanup)
def Cleanup(self, *args):
+ # A little extra cleanup is required for the FileHistory control
del self.filehistory
self.menu.Destroy()
def OnFileOpenDialog(self, evt):
- dlg = wxFileDialog(self,
+ dlg = wx.FileDialog(self,
defaultDir = os.getcwd(),
wildcard = "All Files|*",
- style = wxOPEN | wxCHANGE_DIR)
- if dlg.ShowModal() == wxID_OK:
+ style = wx.OPEN | wx.CHANGE_DIR)
+
+ if dlg.ShowModal() == wx.ID_OK:
path = dlg.GetPath()
self.log.write("You selected %s\n" % path)
def OnFileHistory(self, evt):
# get the file based on the menu ID
- fileNum = evt.GetId() - wxID_FILE1
+ fileNum = evt.GetId() - wx.ID_FILE1
path = self.filehistory.GetHistoryFile(fileNum)
self.log.write("You selected %s\n" % path)
overview = """<html><body>
-<h3>wxFileHistory</h3>
+<h3>FileHistory</h3>
wxFileHistory encapsulates functionality to record the last few files
visited, and to allow the user to quickly load these files using the
list appended to a menu, such as the File menu.
+<p>Note that this inclusion is not automatic; as illustrated in this example,
+you must add files (and remove them) as deemed necessary within the framework
+of your program.
+
+<p>Note also the additional cleanup required for this class, namely trapping the
+enclosing window's Destroy event and deleting the file history control and its
+associated menu.
</body></html>
"""
-
-from wxPython.wx import *
+# 11/17/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+# 11/28/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Changed the event binding slightly.
+# o There are issues with the GetReplaceText() method of the
+# FindDialogEvent. Must be retested when this is fixed.
+#
+
+import wx
#---------------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.log = log
- b = wxButton(self, -1, "Show Find Dialog", (25, 50))
- EVT_BUTTON(self, b.GetId(), self.OnShowFind)
+ b = wx.Button(self, -1, "Show Find Dialog", (25, 50))
+ self.Bind(wx.EVT_BUTTON, self.OnShowFind, b)
+
+ b = wx.Button(self, -1, "Show Find && Replace Dialog", (25, 90))
+ self.Bind(wx.EVT_BUTTON, self.OnShowFindReplace, b)
- b = wxButton(self, -1, "Show Find && Replace Dialog", (25, 90))
- EVT_BUTTON(self, b.GetId(), self.OnShowFindReplace)
- EVT_COMMAND_FIND(self, -1, self.OnFind)
- EVT_COMMAND_FIND_NEXT(self, -1, self.OnFind)
- EVT_COMMAND_FIND_REPLACE(self, -1, self.OnFind)
- EVT_COMMAND_FIND_REPLACE_ALL(self, -1, self.OnFind)
- EVT_COMMAND_FIND_CLOSE(self, -1, self.OnFindClose)
+ # jg - 11/28/03 - corrected a long standing issue here where
+ # EVT_COMMAND_FIND_* was being used for these event binders
+ # instead of the actual event IDs shown below. As a result,
+ # onFind() was never showing the appropriate type. I guess
+ # nobody really paid much attention to that little
+ # debugging window :-)
+ #
+ self.Bind(wx.EVT_FIND, self.OnFind)
+ self.Bind(wx.EVT_FIND_NEXT, self.OnFind)
+ self.Bind(wx.EVT_FIND_REPLACE, self.OnFind)
+ self.Bind(wx.EVT_FIND_REPLACE_ALL, self.OnFind)
+ self.Bind(wx.EVT_FIND_CLOSE, self.OnFindClose)
def OnShowFind(self, evt):
- data = wxFindReplaceData()
- dlg = wxFindReplaceDialog(self, data, "Find")
+ data = wx.FindReplaceData()
+ dlg = wx.FindReplaceDialog(self, data, "Find")
dlg.data = data # save a reference to it...
dlg.Show(True)
def OnShowFindReplace(self, evt):
- data = wxFindReplaceData()
- dlg = wxFindReplaceDialog(self, data, "Find & Replace", wxFR_REPLACEDIALOG)
+ data = wx.FindReplaceData()
+ dlg = wx.FindReplaceDialog(self, data, "Find & Replace", wx.FR_REPLACEDIALOG)
dlg.data = data # save a reference to it...
dlg.Show(True)
def OnFind(self, evt):
map = {
- wxEVT_COMMAND_FIND : "FIND",
- wxEVT_COMMAND_FIND_NEXT : "FIND_NEXT",
- wxEVT_COMMAND_FIND_REPLACE : "REPLACE",
- wxEVT_COMMAND_FIND_REPLACE_ALL : "REPLACE_ALL",
+ wx.wxEVT_COMMAND_FIND : "FIND",
+ wx.wxEVT_COMMAND_FIND_NEXT : "FIND_NEXT",
+ wx.wxEVT_COMMAND_FIND_REPLACE : "REPLACE",
+ wx.wxEVT_COMMAND_FIND_REPLACE_ALL : "REPLACE_ALL",
}
+
et = evt.GetEventType()
+
+ #print evt.GetReplaceString()
- try:
+ if et in map:
evtType = map[et]
- except KeyError:
+ else:
evtType = "**Unknown Event Type**"
- if et == wxEVT_COMMAND_FIND_REPLACE or et == wxEVT_COMMAND_FIND_REPLACE_ALL:
- replaceTxt = "Replace text: " + evt.GetReplaceString()
+ #>> Todo: the GetReplaceString() method is broken. Has to be
+ # fixed.
+ if et == wx.EVT_COMMAND_FIND_REPLACE or et == wx.EVT_COMMAND_FIND_REPLACE_ALL:
+ replaceTxt = "Replace text: %s" % evt.GetReplaceString()
else:
replaceTxt = ""
def OnFindClose(self, evt):
- self.log.write("wxFindReplaceDialog closing...\n")
+ self.log.write("FindReplaceDialog closing...\n")
evt.GetDialog().Destroy()
#---------------------------------------------------------------------------
overview = """\
-A generic find and replace dialog.
+FindReplaceDialog is a standard modeless dialog which is used to allow the user
+to search for some text (and possibly replace it with something else). The actual
+searching is supposed to be done in the owner window which is the parent of this
+dialog. Note that it means that unlike for the other standard dialogs this one
+<u>must have a parent window</u>. Also note that there is no way to use this
+dialog in a modal way; <b>it is always, by design and implementation, modeless</b>.
+
+FileReplaceDialog requires the use of <b>FindReplaceData</b>. This holds the
+data for the dialog. It is used to initialize the dialog with the default values
+and will keep the last values from the dialog when it is closed. It is also
+updated each time a FindDialogEvent is generated so instead of using the
+FindDialogEvent methods you can also directly query this object. <b>Care must be
+taken not to use this object after the dialog is destroyed.</b> The data within
+will be invalid after the parent dialog is destroyed.
"""
-from wxPython.wx import *
-from wxPython.lib.floatbar import *
+# 11/18/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+# o OK, Main.py indicates this is deprecated. But I don't see a
+# replacement yet. So conversion is done anyway.
+#
+# 11/28/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Issues - library has to be converted to work properly
+# with new namespace.
+#
-import images
+import wx
+import wx.lib.floatbar as float
+import images
-class TestFloatBar(wxFrame):
+
+class TestFloatBar(wx.Frame):
def __init__(self, parent, log):
- wxFrame.__init__(self, parent, -1, 'Test ToolBar',
- wxPoint(0,0), wxSize(500, 300))
+ wx.Frame.__init__(
+ self, parent, -1, 'Test ToolBar', wx.DefaultPosition, (500, 300)
+ )
+
self.log = log
- win = wxWindow(self, -1)
- win.SetBackgroundColour(wxNamedColour("WHITE"))
- wxStaticText(win, -1, "Drag the toolbar to float it,\n"
- "Toggle the last tool to remove\nthe title.", wxPoint(15,15))
+ win = wx.Window(self, -1)
+ win.SetBackgroundColour("WHITE")
+ wx.StaticText(
+ win, -1, "Drag the toolbar to float it,\n"
+ "Toggle the last tool to remove\nthe title.", (15,15)
+ )
- tb = wxFloatBar(self, -1)
+ tb = float.wxFloatBar(self, -1)
self.SetToolBar(tb)
tb.SetFloatable(1)
tb.SetTitle("Floating!")
self.CreateStatusBar()
tb.AddSimpleTool(10, images.getNewBitmap(), "New", "Long help for 'New'")
- EVT_TOOL(self, 10, self.OnToolClick)
- EVT_TOOL_RCLICKED(self, 10, self.OnToolRClick)
+ self.Bind(wx.EVT_TOOL, self.OnToolClick, id=10)
+ self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=10)
tb.AddSimpleTool(20, images.getOpenBitmap(), "Open")
- EVT_TOOL(self, 20, self.OnToolClick)
- EVT_TOOL_RCLICKED(self, 20, self.OnToolRClick)
+ self.Bind(wx.EVT_TOOL, self.OnToolClick, id=20)
+ self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=20)
tb.AddSeparator()
tb.AddSimpleTool(30, images.getCopyBitmap(), "Copy")
- EVT_TOOL(self, 30, self.OnToolClick)
- EVT_TOOL_RCLICKED(self, 30, self.OnToolRClick)
+ self.Bind(wx.EVT_TOOL, self.OnToolClick, id=30)
+ self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=30)
tb.AddSimpleTool(40, images.getPasteBitmap(), "Paste")
- EVT_TOOL(self, 40, self.OnToolClick)
- EVT_TOOL_RCLICKED(self, 40, self.OnToolRClick)
+ self.Bind(wx.EVT_TOOL, self.OnToolClick, id=40)
+ self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=40)
tb.AddSeparator()
-
tb.AddCheckTool(60, images.getTog1Bitmap(), images.getTog2Bitmap())
- EVT_TOOL(self, 60, self.OnToolClick)
- EVT_TOOL_RCLICKED(self, 60, self.OnToolRClick)
+ self.Bind(wx.EVT_TOOL, self.OnToolClick, id=60)
+ self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=60)
+
tb.Realize()
self.tb = tb
- EVT_CLOSE(self, self.OnCloseWindow)
+ self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
def OnCloseWindow(self, event):
def OnToolClick(self, event):
self.log.WriteText("tool %s clicked\n" % event.GetId())
+
if event.GetId() == 60:
print event.GetExtraLong(), event.Checked(), event.GetInt(), self.tb.GetToolState(60)
+
if event.GetExtraLong():
self.tb.SetTitle("")
else:
"""
-
-
-
-
-
-
if __name__ == '__main__':
import sys,os
import run
+# 11/18/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
+import wx
#---------------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.log = log
- btn = wxButton(self, -1, "Select Font")
- EVT_BUTTON(self, btn.GetId(), self.OnSelectFont)
+ btn = wx.Button(self, -1, "Select Font")
+ self.Bind(wx.EVT_BUTTON, self.OnSelectFont, btn)
- self.sampleText = wxTextCtrl(self, -1, "Sample Text")
+ self.sampleText = wx.TextCtrl(self, -1, "Sample Text")
#from wxPython.lib.stattext import wxGenStaticText
#self.sampleText = wxGenStaticText(self, -1, "Sample Text")
self.curFont = self.sampleText.GetFont()
- self.curClr = wxBLACK
+ self.curClr = wx.BLACK
- fgs = wxFlexGridSizer(cols=2, vgap=5, hgap=5)
+ fgs = wx.FlexGridSizer(cols=2, vgap=5, hgap=5)
fgs.AddGrowableCol(1)
fgs.AddGrowableRow(0)
fgs.Add(btn)
- fgs.Add(self.sampleText, 0, wxADJUST_MINSIZE|wxGROW)
+ fgs.Add(self.sampleText, 0, wx.ADJUST_MINSIZE|wx.GROW)
fgs.Add((15,15)); fgs.Add((15,15)) # an empty row
- fgs.Add(wxStaticText(self, -1, "PointSize:"))
- self.ps = wxStaticText(self, -1, "")
+ fgs.Add(wx.StaticText(self, -1, "PointSize:"))
+ self.ps = wx.StaticText(self, -1, "")
font = self.ps.GetFont()
- font.SetWeight(wxBOLD)
+ font.SetWeight(wx.BOLD)
self.ps.SetFont(font)
- fgs.Add(self.ps, 0, wxADJUST_MINSIZE)
+ fgs.Add(self.ps, 0, wx.ADJUST_MINSIZE)
- fgs.Add(wxStaticText(self, -1, "Family:"))
- self.family = wxStaticText(self, -1, "")
+ fgs.Add(wx.StaticText(self, -1, "Family:"))
+ self.family = wx.StaticText(self, -1, "")
self.family.SetFont(font)
- fgs.Add(self.family, 0, wxADJUST_MINSIZE)
+ fgs.Add(self.family, 0, wx.ADJUST_MINSIZE)
- fgs.Add(wxStaticText(self, -1, "Style:"))
- self.style = wxStaticText(self, -1, "")
+ fgs.Add(wx.StaticText(self, -1, "Style:"))
+ self.style = wx.StaticText(self, -1, "")
self.style.SetFont(font)
- fgs.Add(self.style, 0, wxADJUST_MINSIZE)
+ fgs.Add(self.style, 0, wx.ADJUST_MINSIZE)
- fgs.Add(wxStaticText(self, -1, "Weight:"))
- self.weight = wxStaticText(self, -1, "")
+ fgs.Add(wx.StaticText(self, -1, "Weight:"))
+ self.weight = wx.StaticText(self, -1, "")
self.weight.SetFont(font)
- fgs.Add(self.weight, 0, wxADJUST_MINSIZE)
+ fgs.Add(self.weight, 0, wx.ADJUST_MINSIZE)
- fgs.Add(wxStaticText(self, -1, "Face:"))
- self.face = wxStaticText(self, -1, "")
+ fgs.Add(wx.StaticText(self, -1, "Face:"))
+ self.face = wx.StaticText(self, -1, "")
self.face.SetFont(font)
- fgs.Add(self.face, 0, wxADJUST_MINSIZE)
+ fgs.Add(self.face, 0, wx.ADJUST_MINSIZE)
fgs.Add((15,15)); fgs.Add((15,15)) # an empty row
- fgs.Add(wxStaticText(self, -1, "wxNativeFontInfo:"))
- self.nfi = wxStaticText(self, -1, "")
+ fgs.Add(wx.StaticText(self, -1, "wx.NativeFontInfo:"))
+ self.nfi = wx.StaticText(self, -1, "")
self.nfi.SetFont(font)
- fgs.Add(self.nfi, 0, wxADJUST_MINSIZE)
+ fgs.Add(self.nfi, 0, wx.ADJUST_MINSIZE)
# give it some border space
- sizer = wxBoxSizer(wxVERTICAL)
- sizer.Add(fgs, 0, wxGROW|wxADJUST_MINSIZE|wxALL, 25)
+ sizer = wx.BoxSizer(wx.VERTICAL)
+ sizer.Add(fgs, 0, wx.GROW|wx.ADJUST_MINSIZE|wx.ALL, 25)
self.SetSizer(sizer)
self.UpdateUI()
def OnSelectFont(self, evt):
- data = wxFontData()
+ data = wx.FontData()
data.EnableEffects(True)
data.SetColour(self.curClr) # set colour
data.SetInitialFont(self.curFont)
- dlg = wxFontDialog(self, data)
- if dlg.ShowModal() == wxID_OK:
+ dlg = wx.FontDialog(self, data)
+
+ if dlg.ShowModal() == wx.ID_OK:
data = dlg.GetFontData()
font = data.GetChosenFont()
colour = data.GetColour()
+
self.log.WriteText('You selected: "%s", %d points, color %s\n' %
(font.GetFaceName(), font.GetPointSize(),
colour.Get()))
+
self.curFont = font
self.curClr = colour
self.UpdateUI()
- dlg.Destroy()
-
-
+ # Don't destroy the dialog until you get everything you need from the
+ # dialog!
+ dlg.Destroy()
#---------------------------------------------------------------------------
win = TestPanel(nb, log)
return win
-
#---------------------------------------------------------------------------
-
-
overview = """\
-This class allows you to use the system font chooser dialog.
+This class allows you to use the system font selection dialog
+from within your program. Generally speaking, this allows you
+to select a font by its name, font size, and weight, and
+on some systems such things as strikethrough and underline.
-"""
+As with other dialogs used in wxPython, it is important to
+use the class' methods to extract the information you need
+about the font <b>before</b> you destroy the dialog. Failure
+to observe this almost always leads to a program failure of
+some sort, often ugly.
+This demo serves two purposes; it shows how to use the dialog
+to GET font information from the user, but also shows how
+to APPLY that information once you get it.
+"""
if __name__ == '__main__':
import sys,os
+# 11/18/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
+import wx
#---------------------------------------------------------------------------
-class MyFrame(wxFrame):
- def __init__(self, parent, ID, title, pos=wxDefaultPosition,
- size=wxDefaultSize, style=wxDEFAULT_FRAME_STYLE):
- wxFrame.__init__(self, parent, ID, title, pos, size, style)
- panel = wxPanel(self, -1)
+class MyFrame(wx.Frame):
+ def __init__(
+ self, parent, ID, title, pos=wx.DefaultPosition,
+ size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE
+ ):
- button = wxButton(panel, 1003, "Close Me")
- button.SetPosition(wxPoint(15, 15))
- EVT_BUTTON(self, 1003, self.OnCloseMe)
- EVT_CLOSE(self, self.OnCloseWindow)
+ wx.Frame.__init__(self, parent, ID, title, pos, size, style)
+ panel = wx.Panel(self, -1)
+
+ button = wx.Button(panel, 1003, "Close Me")
+ button.SetPosition((15, 15))
+ self.Bind(wx.EVT_BUTTON, self.OnCloseMe, button)
+ self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
def OnCloseMe(self, event):
def runTest(frame, nb, log):
win = MyFrame(frame, -1, "This is a wxFrame", size=(350, 200),
- style = wxDEFAULT_FRAME_STYLE)# | wxFRAME_TOOL_WINDOW )
+ style = wx.DEFAULT_FRAME_STYLE)# | wx.FRAME_TOOL_WINDOW )
frame.otherWin = win
win.Show(True)
#---------------------------------------------------------------------------
-
-
-
-
-
-
-
-
overview = """\
+A Frame is a window whose size and position can (usually) be changed by
+the user. It usually has thick borders and a title bar, and can optionally
+contain a menu bar, toolbar and status bar. A frame can contain any window
+that is not a Frame or Dialog. It is one of the most fundamental of the
+wxWindows components.
+
+A Frame that has a status bar and toolbar created via the
+<code>CreateStatusBar</code> / <code>CreateToolBar</code> functions manages
+these windows, and adjusts the value returned by <code>GetClientSize</code>
+to reflect the remaining size available to application windows.
+
+By itself, a Frame is not too useful, but with the addition of Panels and
+other child objects, it encompasses the framework around which most user
+interfaces are constructed.
+
+If you plan on using Sizers and auto-layout features, be aware that the Frame
+class lacks the ability to handle these features unless it contains a Panel.
+The Panel has all the necessary functionality to both control the size of
+child components, and also communicate that information in a useful way to
+the Frame itself.
"""
-
-
if __name__ == '__main__':
import sys,os
import run
-from wxPython.wx import *
+# 11/18/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+# o Note: unable to install PyOpenGL on my system as I am running Python 2.3
+# and PyOpenGL does not support anything above Python 2.2. Did what I could,
+# but odds are good there are problems.
+#
+
+import wx
+
try:
- from wxPython.glcanvas import *
+ import wx.glcanvas as glcanvas
haveGLCanvas = True
except ImportError:
haveGLCanvas = False
try:
# The Python OpenGL package can be found at
# http://PyOpenGL.sourceforge.net/
- from OpenGL.GL import *
- from OpenGL.GLUT import *
+
+ import OpenGL.GL as gl
+ import OpenGL.GLUT as glut
haveOpenGL = True
except ImportError:
haveOpenGL = False
if not haveGLCanvas:
def runTest(frame, nb, log):
- dlg = wxMessageDialog(frame, 'The wxGLCanvas has not been included with this build of wxPython!',
- 'Sorry', wxOK | wxICON_INFORMATION)
+ dlg = wx.MessageDialog(
+ frame, 'The wxGLCanvas has not been included with this build of wxPython!',
+ 'Sorry', wx.OK | wx.ICON_INFORMATION
+ )
+
dlg.ShowModal()
dlg.Destroy()
elif not haveOpenGL:
def runTest(frame, nb, log):
- dlg = wxMessageDialog(frame,
- 'The OpenGL package was not found. You can get it at\n'
- 'http://PyOpenGL.sourceforge.net/',
- 'Sorry', wxOK | wxICON_INFORMATION)
+ dlg = wxMessageDialog(
+ frame, 'The OpenGL package was not found. You can get it at\n'
+ 'http://PyOpenGL.sourceforge.net/', 'Sorry', wx.OK | wx.ICON_INFORMATION
+ )
+
dlg.ShowModal()
dlg.Destroy()
-
-
else:
buttonDefs = {
- wxNewId() : ('CubeCanvas', 'Cube'),
- wxNewId() : ('ConeCanvas', 'Cone'),
+ wx.NewId() : ('CubeCanvas', 'Cube'),
+ wx.NewId() : ('ConeCanvas', 'Cone'),
}
- class ButtonPanel(wxPanel):
+ class ButtonPanel(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.log = log
- box = wxBoxSizer(wxVERTICAL)
- box.Add(20, 30)
+ box = wx.BoxSizer(wx.VERTICAL)
+ box.Add((20, 30))
keys = buttonDefs.keys()
keys.sort()
+
for k in keys:
text = buttonDefs[k][1]
- btn = wxButton(self, k, text)
- box.Add(btn, 0, wxALIGN_CENTER|wxALL, 15)
- EVT_BUTTON(self, k, self.OnButton)
+ btn = wx.Button(self, k, text)
+ box.Add(btn, 0, wx.ALIGN_CENTER|wx.ALL, 15)
+ self.Bind(wx.EVT_BUTTON, self.OnButton, id=k)
#** Enable this to show putting a wxGLCanvas on the wxPanel
if 0:
c = CubeCanvas(self)
c.SetSize((200, 200))
- box.Add(c, 0, wxALIGN_CENTER|wxALL, 15)
+ box.Add(c, 0, wx.ALIGN_CENTER|wx.ALL, 15)
self.SetAutoLayout(True)
self.SetSizer(box)
def OnButton(self, evt):
canvasClassName = buttonDefs[evt.GetId()][0]
canvasClass = eval(canvasClassName)
- frame = wxFrame(None, -1, canvasClassName, size=(400,400))
+ frame = wx.Frame(None, -1, canvasClassName, size=(400,400))
canvas = canvasClass(frame)
frame.Show(True)
- class MyCanvasBase(wxGLCanvas):
+ class MyCanvasBase(glcanvas.GLCanvas):
def __init__(self, parent):
- wxGLCanvas.__init__(self, parent, -1)
+ glcanvas.GLCanvas.__init__(self, parent, -1)
self.init = False
# initial mouse position
self.lastx = self.x = 30
self.lasty = self.y = 30
- EVT_ERASE_BACKGROUND(self, self.OnEraseBackground)
- EVT_SIZE(self, self.OnSize)
- EVT_PAINT(self, self.OnPaint)
- EVT_LEFT_DOWN(self, self.OnMouseDown) # needs fixing...
- EVT_LEFT_UP(self, self.OnMouseUp)
- EVT_MOTION(self, self.OnMouseMotion)
+ self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
+ self.Bind(wx.EVT_SIZE, self.OnSize)
+ self.Bind(wx.EVT_PAINT, self.OnPaint)
+ self.Bind(wx.EVT_LEFT_DOWN, self.OnMouseDown) # needs fixing...
+ self.Bind(wx.EVT_LEFT_UP, self.OnMouseUp)
+ self.Bind(wx.EVT_MOTION, self.OnMouseMotion)
def OnEraseBackground(self, event):
pass # Do nothing, to avoid flashing on MSW.
def OnSize(self, event):
size = self.GetClientSize()
+
if self.GetContext():
self.SetCurrent()
- glViewport(0, 0, size.width, size.height)
+ glcanvas.glViewport(0, 0, size.width, size.height)
def OnPaint(self, event):
- dc = wxPaintDC(self)
+ dc = wx.PaintDC(self)
self.SetCurrent()
+
if not self.init:
self.InitGL()
self.init = True
+
self.OnDraw()
def OnMouseDown(self, evt):
self.Refresh(False)
-
-
class CubeCanvas(MyCanvasBase):
def InitGL(self):
# set viewing projection
- glMatrixMode(GL_PROJECTION);
- glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0, 3.0);
+ glcanvas.glMatrixMode(glcanvas.GL_PROJECTION);
+ glcanvas.glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0, 3.0);
# position viewer
- glMatrixMode(GL_MODELVIEW);
- glTranslatef(0.0, 0.0, -2.0);
+ glcanvas.glMatrixMode(glcanvas.GL_MODELVIEW);
+ glcanvas.glTranslatef(0.0, 0.0, -2.0);
# position object
- glRotatef(self.y, 1.0, 0.0, 0.0);
- glRotatef(self.x, 0.0, 1.0, 0.0);
+ glcanvas.glRotatef(self.y, 1.0, 0.0, 0.0);
+ glcanvas.glRotatef(self.x, 0.0, 1.0, 0.0);
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
+ glcanvas.glEnable(glcanvas.GL_DEPTH_TEST);
+ glcanvas.glEnable(glcanvas.GL_LIGHTING);
+ glcanvas.glEnable(glcanvas.GL_LIGHT0);
def OnDraw(self):
# clear color and depth buffers
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glcanvas.glClear(glcanvas.GL_COLOR_BUFFER_BIT | glcanvas.GL_DEPTH_BUFFER_BIT)
# draw six faces of a cube
- glBegin(GL_QUADS)
- glNormal3f( 0.0, 0.0, 1.0)
- glVertex3f( 0.5, 0.5, 0.5)
- glVertex3f(-0.5, 0.5, 0.5)
- glVertex3f(-0.5,-0.5, 0.5)
- glVertex3f( 0.5,-0.5, 0.5)
-
- glNormal3f( 0.0, 0.0,-1.0)
- glVertex3f(-0.5,-0.5,-0.5)
- glVertex3f(-0.5, 0.5,-0.5)
- glVertex3f( 0.5, 0.5,-0.5)
- glVertex3f( 0.5,-0.5,-0.5)
-
- glNormal3f( 0.0, 1.0, 0.0)
- glVertex3f( 0.5, 0.5, 0.5)
- glVertex3f( 0.5, 0.5,-0.5)
- glVertex3f(-0.5, 0.5,-0.5)
- glVertex3f(-0.5, 0.5, 0.5)
-
- glNormal3f( 0.0,-1.0, 0.0)
- glVertex3f(-0.5,-0.5,-0.5)
- glVertex3f( 0.5,-0.5,-0.5)
- glVertex3f( 0.5,-0.5, 0.5)
- glVertex3f(-0.5,-0.5, 0.5)
-
- glNormal3f( 1.0, 0.0, 0.0)
- glVertex3f( 0.5, 0.5, 0.5)
- glVertex3f( 0.5,-0.5, 0.5)
- glVertex3f( 0.5,-0.5,-0.5)
- glVertex3f( 0.5, 0.5,-0.5)
-
- glNormal3f(-1.0, 0.0, 0.0)
- glVertex3f(-0.5,-0.5,-0.5)
- glVertex3f(-0.5,-0.5, 0.5)
- glVertex3f(-0.5, 0.5, 0.5)
- glVertex3f(-0.5, 0.5,-0.5)
- glEnd()
-
- glRotatef((self.lasty - self.y)/100., 1.0, 0.0, 0.0);
- glRotatef((self.lastx - self.x)/100., 0.0, 1.0, 0.0);
+ glcanvas.glBegin(glcanvas.GL_QUADS)
+ glcanvas.glNormal3f( 0.0, 0.0, 1.0)
+ glcanvas.glVertex3f( 0.5, 0.5, 0.5)
+ glcanvas.glVertex3f(-0.5, 0.5, 0.5)
+ glcanvas.glVertex3f(-0.5,-0.5, 0.5)
+ glcanvas.glVertex3f( 0.5,-0.5, 0.5)
+
+ glcanvas.glNormal3f( 0.0, 0.0,-1.0)
+ glcanvas.glVertex3f(-0.5,-0.5,-0.5)
+ glcanvas.glVertex3f(-0.5, 0.5,-0.5)
+ glcanvas.glVertex3f( 0.5, 0.5,-0.5)
+ glcanvas.glVertex3f( 0.5,-0.5,-0.5)
+
+ glcanvas.glNormal3f( 0.0, 1.0, 0.0)
+ glcanvas.glVertex3f( 0.5, 0.5, 0.5)
+ glcanvas.glVertex3f( 0.5, 0.5,-0.5)
+ glcanvas.glVertex3f(-0.5, 0.5,-0.5)
+ glcanvas.glVertex3f(-0.5, 0.5, 0.5)
+
+ glcanvas.glNormal3f( 0.0,-1.0, 0.0)
+ glcanvas.glVertex3f(-0.5,-0.5,-0.5)
+ glcanvas.glVertex3f( 0.5,-0.5,-0.5)
+ glcanvas.glVertex3f( 0.5,-0.5, 0.5)
+ glcanvas.glVertex3f(-0.5,-0.5, 0.5)
+
+ glcanvas.glNormal3f( 1.0, 0.0, 0.0)
+ glcanvas.glVertex3f( 0.5, 0.5, 0.5)
+ glcanvas.glVertex3f( 0.5,-0.5, 0.5)
+ glcanvas.glVertex3f( 0.5,-0.5,-0.5)
+ glcanvas.glVertex3f( 0.5, 0.5,-0.5)
+
+ glcanvas.glNormal3f(-1.0, 0.0, 0.0)
+ glcanvas.glVertex3f(-0.5,-0.5,-0.5)
+ glcanvas.glVertex3f(-0.5,-0.5, 0.5)
+ glcanvas.glVertex3f(-0.5, 0.5, 0.5)
+ glcanvas.glVertex3f(-0.5, 0.5,-0.5)
+ glcanvas.glEnd()
+
+ glcanvas.glRotatef((self.lasty - self.y)/100., 1.0, 0.0, 0.0);
+ glcanvas.glRotatef((self.lastx - self.x)/100., 0.0, 1.0, 0.0);
self.SwapBuffers()
-
-
-
class ConeCanvas(MyCanvasBase):
def InitGL( self ):
- glMatrixMode(GL_PROJECTION);
+ glcanvas.glMatrixMode(glcanvas.GL_PROJECTION);
# camera frustrum setup
- glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0, 3.0);
- glMaterial(GL_FRONT, GL_AMBIENT, [0.2, 0.2, 0.2, 1.0])
- glMaterial(GL_FRONT, GL_DIFFUSE, [0.8, 0.8, 0.8, 1.0])
- glMaterial(GL_FRONT, GL_SPECULAR, [1.0, 0.0, 1.0, 1.0])
- glMaterial(GL_FRONT, GL_SHININESS, 50.0)
- glLight(GL_LIGHT0, GL_AMBIENT, [0.0, 1.0, 0.0, 1.0])
- glLight(GL_LIGHT0, GL_DIFFUSE, [1.0, 1.0, 1.0, 1.0])
- glLight(GL_LIGHT0, GL_SPECULAR, [1.0, 1.0, 1.0, 1.0])
- glLight(GL_LIGHT0, GL_POSITION, [1.0, 1.0, 1.0, 0.0]);
- glLightModel(GL_LIGHT_MODEL_AMBIENT, [0.2, 0.2, 0.2, 1.0])
- glEnable(GL_LIGHTING)
- glEnable(GL_LIGHT0)
- glDepthFunc(GL_LESS)
- glEnable(GL_DEPTH_TEST)
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
+ glcanvas.glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0, 3.0);
+ glcanvas.glMaterial(glcanvas.GL_FRONT, glcanvas.GL_AMBIENT, [0.2, 0.2, 0.2, 1.0])
+ glcanvas.glMaterial(glcanvas.GL_FRONT, glcanvas.GL_DIFFUSE, [0.8, 0.8, 0.8, 1.0])
+ glcanvas.glMaterial(glcanvas.GL_FRONT, glcanvas.GL_SPECULAR, [1.0, 0.0, 1.0, 1.0])
+ glcanvas.glMaterial(glcanvas.GL_FRONT, glcanvas.GL_SHININESS, 50.0)
+ glcanvas.glLight(glcanvas.GL_LIGHT0, glcanvas.GL_AMBIENT, [0.0, 1.0, 0.0, 1.0])
+ glcanvas.glLight(glcanvas.GL_LIGHT0, glcanvas.GL_DIFFUSE, [1.0, 1.0, 1.0, 1.0])
+ glcanvas.glLight(glcanvas.GL_LIGHT0, glcanvas.GL_SPECULAR, [1.0, 1.0, 1.0, 1.0])
+ glcanvas.glLight(glcanvas.GL_LIGHT0, glcanvas.GL_POSITION, [1.0, 1.0, 1.0, 0.0]);
+ glcanvas.glLightModel(glcanvas.GL_LIGHT_MODEL_AMBIENT, [0.2, 0.2, 0.2, 1.0])
+ glcanvas.glEnable(glcanvas.GL_LIGHTING)
+ glcanvas.glEnable(glcanvas.GL_LIGHT0)
+ glcanvas.glDepthFunc(glcanvas.GL_LESS)
+ glcanvas.glEnable(glcanvas.GL_DEPTH_TEST)
+ glcanvas.glClear(glcanvas.GL_COLOR_BUFFER_BIT | glcanvas.GL_DEPTH_BUFFER_BIT)
# position viewer
- glMatrixMode(GL_MODELVIEW);
+ glcanvas.glMatrixMode(glcanvas.GL_MODELVIEW);
def OnDraw(self):
# clear color and depth buffers
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glcanvas.glClear(glcanvas.GL_COLOR_BUFFER_BIT | glcanvas.GL_DEPTH_BUFFER_BIT);
# use a fresh transformation matrix
- glPushMatrix()
+ glcanvas.glPushMatrix()
# position object
- glTranslate(0.0, 0.0, -2.0);
- glRotate(30.0, 1.0, 0.0, 0.0);
- glRotate(30.0, 0.0, 1.0, 0.0);
-
- glTranslate(0, -1, 0)
- glRotate(250, 1, 0, 0)
- glutSolidCone(0.5, 1, 30, 5)
- glPopMatrix()
- glRotatef((self.lasty - self.y)/100., 0.0, 0.0, 1.0);
- glRotatef(0.0, (self.lastx - self.x)/100., 1.0, 0.0);
+ glcanvas.glTranslate(0.0, 0.0, -2.0);
+ glcanvas.glRotate(30.0, 1.0, 0.0, 0.0);
+ glcanvas.glRotate(30.0, 0.0, 1.0, 0.0);
+
+ glcanvas.glTranslate(0, -1, 0)
+ glcanvas.glRotate(250, 1, 0, 0)
+ glcanvas.glutSolidCone(0.5, 1, 30, 5)
+ glcanvas.glPopMatrix()
+ glcanvas.glRotatef((self.lasty - self.y)/100., 0.0, 0.0, 1.0);
+ glcanvas.glRotatef(0.0, (self.lastx - self.x)/100., 1.0, 0.0);
# push into visible buffer
self.SwapBuffers()
-
-
-
-
-
overview = """\
"""
-
-
-
#----------------------------------------------------------------------
def _test():
class MyApp(wxApp):
def OnInit(self):
- frame = wxFrame(None, -1, "GL Demos", wxDefaultPosition, wxSize(600,300))
+ frame = wx.Frame(None, -1, "GL Demos", wx.DefaultPosition, (600,300))
#win = ConeCanvas(frame)
MySplitter(frame)
frame.Show(True)
+# 11/15/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
+import wx
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.log = log
self.count = 0
- wxStaticText(self, -1, "This example shows the wxGauge control.",
- wxPoint(45, 15))
+ wx.StaticText(self, -1, "This example shows the wxGauge control.", (45, 15))
- self.g1 = wxGauge(self, -1, 50, wxPoint(110, 50), wxSize(250, 25))
+ self.g1 = wx.Gauge(self, -1, 50, (110, 50), (250, 25))
self.g1.SetBezelFace(3)
self.g1.SetShadowWidth(3)
- self.g2 = wxGauge(self, -1, 50, wxPoint(110, 95), wxSize(250, 25),
- wxGA_HORIZONTAL|wxGA_SMOOTH)
+ self.g2 = wx.Gauge(
+ self, -1, 50, (110, 95), (250, 25),
+ wx.GA_HORIZONTAL|wx.GA_SMOOTH
+ )
+
self.g2.SetBezelFace(5)
self.g2.SetShadowWidth(5)
- EVT_IDLE(self, self.IdleHandler)
+ self.Bind(wx.EVT_IDLE, self.IdleHandler)
def IdleHandler(self, event):
self.count = self.count + 1
+
if self.count >= 50:
self.count = 0
+
self.g1.SetValue(self.count)
self.g2.SetValue(self.count)
#----------------------------------------------------------------------
-
-
-
-
-
-
-
-
overview = """\
-"""
-
+A Gauge is a horizontal or vertical bar which shows a quantity in a graphical
+fashion. It is often used to indicate progress through lengthy tasks, such as
+file copying or data analysis.
+When the Gauge is initialized, it's "complete" value is usually set; at any rate,
+before using the Gauge, the maximum value of the control must be set. As the task
+progresses, the Gauge is updated by the program via the <code>SetValue</code> method.
+This control is for use within a GUI; there is a seperate ProgressDialog class
+to present the same sort of control as a dialog to the user.
+"""
if __name__ == '__main__':
import sys,os
-from wxPython.wx import *
+# 11/18/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+
+import wx
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.log = log
- txt1 = wxStaticText(self, -1, "style=0")
- dir1 = wxGenericDirCtrl(self, -1, size=(200,225), style=0)
+ txt1 = wx.StaticText(self, -1, "style=0")
+ dir1 = wx.GenericDirCtrl(self, -1, size=(200,225), style=0)
- txt2 = wxStaticText(self, -1, "wxDIRCTRL_DIR_ONLY")
- dir2 = wxGenericDirCtrl(self, -1, size=(200,225), style=wxDIRCTRL_DIR_ONLY)
+ txt2 = wx.StaticText(self, -1, "wx.DIRCTRL_DIR_ONLY")
+ dir2 = wx.GenericDirCtrl(self, -1, size=(200,225), style=wx.DIRCTRL_DIR_ONLY)
- txt3 = wxStaticText(self, -1, "wxDIRCTRL_SHOW_FILTERS")
- dir3 = wxGenericDirCtrl(self, -1, size=(200,225), style=wxDIRCTRL_SHOW_FILTERS,
+ txt3 = wx.StaticText(self, -1, "wx.DIRCTRL_SHOW_FILTERS")
+ dir3 = wx.GenericDirCtrl(self, -1, size=(200,225), style=wx.DIRCTRL_SHOW_FILTERS,
filter="All files (*.*)|*.*|Python files (*.py)|*.py")
- sz = wxFlexGridSizer(cols=3, hgap=5, vgap=5)
+ sz = wx.FlexGridSizer(cols=3, hgap=5, vgap=5)
sz.Add((35, 35)) # some space above
sz.Add((35, 35))
sz.Add((35, 35))
sz.Add(txt2)
sz.Add(txt3)
- sz.Add(dir1, 0, wxEXPAND)
- sz.Add(dir2, 0, wxEXPAND)
- sz.Add(dir3, 0, wxEXPAND)
+ sz.Add(dir1, 0, wx.EXPAND)
+ sz.Add(dir2, 0, wx.EXPAND)
+ sz.Add(dir3, 0, wx.EXPAND)
sz.Add((35,35)) # some space below
sz.AddGrowableCol(0)
sz.AddGrowableCol(1)
sz.AddGrowableCol(2)
+
self.SetSizer(sz)
self.SetAutoLayout(True)
win = TestPanel(nb, log)
return win
-
#----------------------------------------------------------------------
-
-
-
overview = """\
This control can be used to place a directory listing (with optional files)
-on an arbitrary window.
+on an arbitrary window. The control contains a TreeCtrl window representing
+the directory hierarchy, and optionally, a Choice window containing a list
+of filters.
+
+The filters work in the same manner as in FileDialog.
+
"""
+# 11/18/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
+import wx
#---------------------------------------------------------------------------
819 : ('GridEnterHandler',' Remapping keys to behave differently '),
820 : ('GridCustEditor', ' Shows how to create a custom Cell Editor '),
821 : ('GridDragable', ' A wxGrid with dragable rows and columns '),
- 822 : ('GridDragAndDrop', 'Shows how to make a grid a drop target for files'),
+ 822 : ('GridDragAndDrop', ' Shows how to make a grid a drop target for files'),
}
-class ButtonPanel(wxPanel):
+class ButtonPanel(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.log = log
- box = wxBoxSizer(wxVERTICAL)
+ box = wxBoxSizer(wx.VERTICAL)
box.Add((20, 20))
keys = buttonDefs.keys()
keys.sort()
+
for k in keys:
text = buttonDefs[k][1]
- btn = wxButton(self, k, text)
- box.Add(btn, 0, wxALIGN_CENTER|wxALL, 10)
- EVT_BUTTON(self, k, self.OnButton)
+ btn = wx.Button(self, k, text)
+ box.Add(btn, 0, wx.ALIGN_CENTER|wx.ALL, 10)
+ self.Bind(wx.EVT_BUTTON, self.OnButton, btn)
self.SetAutoLayout(True)
self.SetSizer(box)
-
-
-
-
-
-
-
overview = """\
<html><body>
<h2>wxGrid</h2>
"""
-
-
if __name__ == '__main__':
import sys,os
import run
gbs.Add( wx.StaticText(p, -1, gbsDescription),
(0,0), (1,7), wx.ALIGN_CENTER | wx.ALL, 5)
-
gbs.Add( wx.TextCtrl(p, -1, "pos(1,0)"), (1,0) )
gbs.Add( wx.TextCtrl(p, -1, "pos(1,1)"), (1,1) )
gbs.Add( wx.TextCtrl(p, -1, "pos(2,0)"), (2,0) )
-from wxPython.wx import *
-from wxPython.grid import *
-import images
+# 11/18/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+
+import wx
+import wx.grid as Grid
-class MegaTable(wxPyGridTableBase):
+import images
+
+class MegaTable(Grid.PyGridTableBase):
"""
A custom wxGrid Table using user supplied data
"""
colname
"""
# The base class must be initialized *first*
- wxPyGridTableBase.__init__(self)
+ Grid.PyGridTableBase.__init__(self)
self.data = data
self.colnames = colnames
self.plugins = plugins or {}
# XXX
- # we need to store the row length and collength to
+ # we need to store the row length and column length to
# see if the table has changed size
self._rows = self.GetNumberRows()
self._cols = self.GetNumberCols()
def ResetView(self, grid):
"""
- (wxGrid) -> Reset the grid view. Call this to
+ (Grid) -> Reset the grid view. Call this to
update the grid if rows and columns have been added or deleted
"""
grid.BeginBatch()
+
for current, new, delmsg, addmsg in [
- (self._rows, self.GetNumberRows(), wxGRIDTABLE_NOTIFY_ROWS_DELETED, wxGRIDTABLE_NOTIFY_ROWS_APPENDED),
- (self._cols, self.GetNumberCols(), wxGRIDTABLE_NOTIFY_COLS_DELETED, wxGRIDTABLE_NOTIFY_COLS_APPENDED),
+ (self._rows, self.GetNumberRows(), Grid.GRIDTABLE_NOTIFY_ROWS_DELETED, Grid.GRIDTABLE_NOTIFY_ROWS_APPENDED),
+ (self._cols, self.GetNumberCols(), Grid.GRIDTABLE_NOTIFY_COLS_DELETED, Grid.GRIDTABLE_NOTIFY_COLS_APPENDED),
]:
+
if new < current:
- msg = wxGridTableMessage(self,delmsg,new,current-new)
+ msg = Grid.GridTableMessage(self,delmsg,new,current-new)
grid.ProcessTableMessage(msg)
elif new > current:
- msg = wxGridTableMessage(self,addmsg,new-current)
+ msg = Grid.GridTableMessage(self,addmsg,new-current)
grid.ProcessTableMessage(msg)
self.UpdateValues(grid)
+
grid.EndBatch()
self._rows = self.GetNumberRows()
def UpdateValues(self, grid):
"""Update all displayed values"""
# This sends an event to the grid table to update all of the values
- msg = wxGridTableMessage(self, wxGRIDTABLE_REQUEST_VIEW_GET_VALUES)
+ msg = Grid.GridTableMessage(self, Grid.GRIDTABLE_REQUEST_VIEW_GET_VALUES)
grid.ProcessTableMessage(msg)
def _updateColAttrs(self, grid):
Otherwise default to the default renderer.
"""
col = 0
+
for colname in self.colnames:
- attr = wxGridCellAttr()
+ attr = Grid.GridCellAttr()
if colname in self.plugins:
renderer = self.plugins[colname](self)
+
if renderer.colSize:
grid.SetColSize(col, renderer.colSize)
+
if renderer.rowSize:
grid.SetDefaultRowSize(renderer.rowSize)
+
attr.SetReadOnly(True)
attr.SetRenderer(renderer)
+
grid.SetColAttr(col, attr)
col += 1
# ------------------------------------------------------
# begin the added code to manipulate the table (non wx related)
def AppendRow(self, row):
+ #print 'append'
entry = {}
+
for name in self.colnames:
entry[name] = "Appended_%i"%row
+
# XXX Hack
# entry["A"] can only be between 1..4
entry["A"] = random.choice(range(4))
deleteCount = 0
cols = cols[:]
cols.sort()
+
for i in cols:
self.colnames.pop(i-deleteCount)
# we need to advance the delete count
# to make sure we delete the right columns
deleteCount += 1
+
if not len(self.colnames):
self.data = []
deleteCount = 0
rows = rows[:]
rows.sort()
+
for i in rows:
self.data.pop(i-deleteCount)
# we need to advance the delete count
"""
name = self.colnames[col]
_data = []
+
for row in self.data:
rowname, entry = row
_data.append((entry.get(name, None), row))
_data.sort()
self.data = []
+
for sortvalue, row in _data:
self.data.append(row)
# --------------------------------------------------------------------
# Sample wxGrid renderers
-class MegaImageRenderer(wxPyGridCellRenderer):
+class MegaImageRenderer(Grid.PyGridCellRenderer):
def __init__(self, table):
"""
Image Renderer Test. This just places an image in a cell
based on the row index. There are N choices and the
choice is made by choice[row%N]
"""
- wxPyGridCellRenderer.__init__(self)
+ Grid.PyGridCellRenderer.__init__(self)
self.table = table
self._choices = [images.getSmilesBitmap,
images.getMondrianBitmap,
images.get_10s_Bitmap,
images.get_01c_Bitmap]
-
self.colSize = None
self.rowSize = None
def Draw(self, grid, attr, dc, rect, row, col, isSelected):
choice = self.table.GetRawValue(row, col)
bmp = self._choices[ choice % len(self._choices)]()
- image = wxMemoryDC()
+ image = wx.MemoryDC()
image.SelectObject(bmp)
# clear the background
- dc.SetBackgroundMode(wxSOLID)
+ dc.SetBackgroundMode(wx.SOLID)
+
if isSelected:
- dc.SetBrush(wxBrush(wxBLUE, wxSOLID))
- dc.SetPen(wxPen(wxBLUE, 1, wxSOLID))
+ dc.SetBrush(wx.Brush(wx.BLUE, wx.SOLID))
+ dc.SetPen(wx.Pen(wx.BLUE, 1, wx.SOLID))
else:
dc.SetBrush(wxBrush(wxWHITE, wxSOLID))
dc.SetPen(wxPen(wxWHITE, 1, wxSOLID))
dc.DrawRectangleRect(rect)
+ #dc.DrawRectangle((rect.x, rect.y), (rect.width, rect.height))
+
# copy the image but only to the size of the grid cell
width, height = bmp.GetWidth(), bmp.GetHeight()
+
if width > rect.width-2:
width = rect.width-2
(0, 0), wxCOPY, True)
-class MegaFontRenderer(wxPyGridCellRenderer):
+class MegaFontRenderer(Grid.PyGridCellRenderer):
def __init__(self, table, color="blue", font="ARIAL", fontsize=8):
"""Render data in the specified color and font and fontsize"""
- wxPyGridCellRenderer.__init__(self)
+ Grid.PyGridCellRenderer.__init__(self)
self.table = table
self.color = color
- self.font = wxFont(fontsize, wxDEFAULT, wxNORMAL, wxNORMAL,
- 0, font)
- self.selectedBrush = wxBrush("blue",
- wxSOLID)
- self.normalBrush = wxBrush(wxWHITE, wxSOLID)
+ self.font = wx.Font(fontsize, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, font)
+ self.selectedBrush = wx.Brush("blue", wx.SOLID)
+ self.normalBrush = wx.Brush(wx.WHITE, wx.SOLID)
self.colSize = None
self.rowSize = 50
dc.SetClippingRect(rect)
# clear the background
- dc.SetBackgroundMode(wxSOLID)
+ dc.SetBackgroundMode(wx.SOLID)
+
if isSelected:
- dc.SetBrush(wxBrush(wxBLUE, wxSOLID))
- dc.SetPen(wxPen(wxBLUE, 1, wxSOLID))
+ dc.SetBrush(wx.Brush(wx.BLUE, wx.SOLID))
+ dc.SetPen(wx.Pen(wx.BLUE, 1, wx.SOLID))
else:
dc.SetBrush(wxBrush(wxWHITE, wxSOLID))
dc.SetPen(wxPen(wxWHITE, 1, wxSOLID))
dc.DrawRectangleRect(rect)
+ #dc.DrawRectangle((rect.x, rect.y), (rect.width, rect.height))
+
text = self.table.GetValue(row, col)
- dc.SetBackgroundMode(wxSOLID)
+ dc.SetBackgroundMode(wx.SOLID)
# change the text background based on whether the grid is selected
# or not
# when the text is larger than the grid cell
width, height = dc.GetTextExtent(text)
+
if width > rect.width-2:
width, height = dc.GetTextExtent("...")
x = rect.x+1 + rect.width-2 - width
# Sample Grid using a specialized table and renderers that can
# be plugged in based on column names
-class MegaGrid(wxGrid):
+class MegaGrid(Grid.Grid):
def __init__(self, parent, data, colnames, plugins=None):
"""parent, data, colnames, plugins=None
Initialize a grid using the data defined in data and colnames
"""
# The base class must be initialized *first*
- wxGrid.__init__(self, parent, -1)
+ Grid.Grid.__init__(self, parent, -1)
self._table = MegaTable(data, colnames, plugins)
self.SetTable(self._table)
self._plugins = plugins
- EVT_GRID_LABEL_RIGHT_CLICK(self, self.OnLabelRightClicked)
+ self.Bind(Grid.EVT_GRID_LABEL_RIGHT_CLICK, self.OnLabelRightClicked)
def Reset(self):
"""reset the view based on the data in the table. Call
def rowPopup(self, row, evt):
"""(row, evt) -> display a popup menu when a row label is right clicked"""
- appendID = wxNewId()
- deleteID = wxNewId()
+ appendID = wx.NewId()
+ deleteID = wx.NewId()
x = self.GetRowSize(row)/2
+
if not self.GetSelectedRows():
self.SelectRow(row)
- menu = wxMenu()
+
+ menu = wx.Menu()
xo, yo = evt.GetPosition()
menu.Append(appendID, "Append Row")
menu.Append(deleteID, "Delete Row(s)")
self._table.DeleteRows(rows)
self.Reset()
- EVT_MENU(self, appendID, append)
- EVT_MENU(self, deleteID, delete)
- self.PopupMenu(menu, wxPoint(x, yo))
+ self.Bind(wx.EVT_MENU, append, id=appendID)
+ self.Bind(wx.EVT_MENU, delete, id=deleteID)
+ self.PopupMenu(menu, (x, yo))
menu.Destroy()
+ return
+
def colPopup(self, col, evt):
"""(col, evt) -> display a popup menu when a column label is
right clicked"""
x = self.GetColSize(col)/2
- menu = wxMenu()
- id1 = wxNewId()
- sortID = wxNewId()
+ menu = wx.Menu()
+ id1 = wx.NewId()
+ sortID = wx.NewId()
xo, yo = evt.GetPosition()
self.SelectCol(col)
self._table.SortColumn(col)
self.Reset()
- EVT_MENU(self, id1, delete)
+ self.Bind(wx.EVT_MENU, delete, id=id1)
+
if len(cols) == 1:
- EVT_MENU(self, sortID, sort)
- self.PopupMenu(menu, wxPoint(xo, 0))
+ self.Bind(wx.EVT_MENU, sort, id=sortID)
+
+ self.PopupMenu(menu, (xo, 0))
menu.Destroy()
+ return
# -----------------------------------------------------------------
# Test data
colnames = ["Row", "This", "Is", "A", "Test"]
data = []
+
for row in range(1000):
d = {}
for name in ["This", "Test", "Is"]:
d[name] = random.random()
+
d["Row"] = len(data)
# XXX
# the "A" column can only be between one and 4
#---------------------------------------------------------------------------
-class TestFrame(wxFrame):
+class TestFrame(wx.Frame):
def __init__(self, parent, plugins={"This":MegaFontRendererFactory("red", "ARIAL", 8),
"A":MegaImageRenderer,
"Test":MegaFontRendererFactory("orange", "TIMES", 24),}):
- wxFrame.__init__(self, parent, -1,
+ wx.Frame.__init__(self, parent, -1,
"Test Frame", size=(640,480))
grid = MegaGrid(self, data, colnames, plugins)
using a virtual grid object. Hopefully the source isn't too jumbled.
Features:
- 1) Uses a virtual grid
- 2) Columns and rows have popup menus (right click on labels)
- 3) Columns and rows can be deleted (i.e. table can be
+<ol>
+ <li>Uses a virtual grid
+ <li>Columns and rows have popup menus (right click on labels)
+ <li>Columns and rows can be deleted (i.e. table can be
resized)
- 4) Dynamic renderers. Renderers are plugins based on
+ <li>Dynamic renderers. Renderers are plugins based on
column header name. Shows a simple Font Renderer and
an Image Renderer.
+</ol>
-Look for XXX in the code to indicate some workarounds for non-obvious
+Look for 'XXX' in the code to indicate some workarounds for non-obvious
behavior and various hacks.
"""
-
-
if __name__ == '__main__':
import sys,os
import run
+# 11/18/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-import sys, os
+import os
+import sys
-from wxPython.wx import *
-from wxPython.html import *
-import wxPython.lib.wxpTag
+import wx
+import wx.html as html
from Main import opj
# This shows how to catch the OnLinkClicked non-event. (It's a virtual
# method in the C++ code...)
-class MyHtmlWindow(wxHtmlWindow):
+class MyHtmlWindow(html.HtmlWindow):
def __init__(self, parent, id, log):
- wxHtmlWindow.__init__(self, parent, id, style=wxNO_FULL_REPAINT_ON_RESIZE)
+ html.HtmlWindow.__init__(self, parent, id, style=wx.NO_FULL_REPAINT_ON_RESIZE)
self.log = log
- EVT_SCROLLWIN( self, self.OnScroll )
+ self.Bind(wx.EVT_SCROLLWIN, self.OnScroll )
def OnScroll( self, event ):
#print 'event.GetOrientation()',event.GetOrientation()
#print 'event.GetPosition()',event.GetPosition()
event.Skip()
-
def OnLinkClicked(self, linkinfo):
self.log.WriteText('OnLinkClicked: %s\n' % linkinfo.GetHref())
# This filter doesn't really do anything but show how to use filters
-class MyHtmlFilter(wxHtmlFilter):
+class MyHtmlFilter(html.HtmlFilter):
def __init__(self, log):
- wxHtmlFilter.__init__(self)
+ html.HtmlFilter.__init__(self)
self.log = log
# This method decides if this filter is able to read the file
return ""
-class TestHtmlPanel(wxPanel):
+class TestHtmlPanel(wx.Panel):
def __init__(self, parent, frame, log):
- wxPanel.__init__(self, parent, -1, style=wxNO_FULL_REPAINT_ON_RESIZE)
+ wx.Panel.__init__(self, parent, -1, style=wx.NO_FULL_REPAINT_ON_RESIZE)
self.log = log
self.frame = frame
self.cwd = os.path.split(sys.argv[0])[0]
+
if not self.cwd:
self.cwd = os.getcwd()
if frame:
self.titleBase = frame.GetTitle()
- wxHtmlWindow_AddFilter(MyHtmlFilter(log))
+ html.HtmlWindow_AddFilter(MyHtmlFilter(log))
self.html = MyHtmlWindow(self, -1, log)
self.html.SetRelatedFrame(frame, self.titleBase + " -- %s")
self.html.SetRelatedStatusBar(0)
- self.printer = wxHtmlEasyPrinting()
+ self.printer = html.HtmlEasyPrinting()
- self.box = wxBoxSizer(wxVERTICAL)
- self.box.Add(self.html, 1, wxGROW)
+ self.box = wx.BoxSizer(wx.VERTICAL)
+ self.box.Add(self.html, 1, wx.GROW)
- subbox = wxBoxSizer(wxHORIZONTAL)
+ subbox = wx.BoxSizer(wx.HORIZONTAL)
- btn = wxButton(self, -1, "Load File")
- EVT_BUTTON(self, btn.GetId(), self.OnLoadFile)
- subbox.Add(btn, 1, wxGROW | wxALL, 2)
+ btn = wx.Button(self, -1, "Load File")
+ self.Bind(wx.EVT_BUTTON, self.OnLoadFile, btn)
+ subbox.Add(btn, 1, wx.GROW | wx.ALL, 2)
- btn = wxButton(self, -1, "Load URL")
- EVT_BUTTON(self, btn.GetId(), self.OnLoadURL)
- subbox.Add(btn, 1, wxGROW | wxALL, 2)
+ btn = wx.Button(self, -1, "Load URL")
+ self.Bind(wx.EVT_BUTTON, self.OnLoadURL, btn)
+ subbox.Add(btn, 1, wx.GROW | wx.ALL, 2)
- btn = wxButton(self, -1, "With Widgets")
- EVT_BUTTON(self, btn.GetId(), self.OnWithWidgets)
- subbox.Add(btn, 1, wxGROW | wxALL, 2)
+ btn = wx.Button(self, -1, "With Widgets")
+ self.Bind(wx.EVT_BUTTON, self.OnWithWidgets, btn)
+ subbox.Add(btn, 1, wx.GROW | wx.ALL, 2)
- btn = wxButton(self, -1, "Back")
- EVT_BUTTON(self, btn.GetId(), self.OnBack)
- subbox.Add(btn, 1, wxGROW | wxALL, 2)
+ btn = wx.Button(self, -1, "Back")
+ self.Bind(wx.EVT_BUTTON, self.OnBack, btn)
+ subbox.Add(btn, 1, wx.GROW | wx.ALL, 2)
- btn = wxButton(self, -1, "Forward")
- EVT_BUTTON(self, btn.GetId(), self.OnForward)
- subbox.Add(btn, 1, wxGROW | wxALL, 2)
+ btn = wx.Button(self, -1, "Forward")
+ self.Bind(wx.EVT_BUTTON, self.OnForward, btn)
+ subbox.Add(btn, 1, wx.GROW | wx.ALL, 2)
- btn = wxButton(self, -1, "Print")
- EVT_BUTTON(self, btn.GetId(), self.OnPrint)
- subbox.Add(btn, 1, wxGROW | wxALL, 2)
+ btn = wx.Button(self, -1, "Print")
+ self.Bind(wx.EVT_BUTTON, self.OnPrint, btn)
+ subbox.Add(btn, 1, wx.GROW | wx.ALL, 2)
- btn = wxButton(self, -1, "View Source")
- EVT_BUTTON(self, btn.GetId(), self.OnViewSource)
- subbox.Add(btn, 1, wxGROW | wxALL, 2)
+ btn = wx.Button(self, -1, "View Source")
+ self.Bind(wx.EVT_BUTTON, self.OnViewSource, btn)
+ subbox.Add(btn, 1, wx.GROW | wx.ALL, 2)
- self.box.Add(subbox, 0, wxGROW)
+ self.box.Add(subbox, 0, wx.GROW)
self.SetSizer(self.box)
self.SetAutoLayout(True)
# A button with this ID is created on the widget test page.
- EVT_BUTTON(self, wxID_OK, self.OnOk)
+ self.Bind(wx.EVT_BUTTON, self.OnOk, id=wx.ID_OK)
self.OnShowDefault(None)
def OnLoadFile(self, event):
- dlg = wxFileDialog(self, wildcard = '*.htm*', style=wxOPEN)
+ dlg = wx.FileDialog(self, wildcard = '*.htm*', style=wx.OPEN)
+
if dlg.ShowModal():
path = dlg.GetPath()
self.html.LoadPage(path)
+
dlg.Destroy()
def OnLoadURL(self, event):
- dlg = wxTextEntryDialog(self, "Enter a URL")
+ dlg = wx.TextEntryDialog(self, "Enter a URL")
+
if dlg.ShowModal():
url = dlg.GetValue()
self.html.LoadPage(url)
+
dlg.Destroy()
def OnBack(self, event):
if not self.html.HistoryBack():
- wxMessageBox("No more items in history!")
+ wx.MessageBox("No more items in history!")
def OnForward(self, event):
if not self.html.HistoryForward():
- wxMessageBox("No more items in history!")
+ wx.MessageBox("No more items in history!")
def OnViewSource(self, event):
- from wxPython.lib.dialogs import wxScrolledMessageDialog
+ import wx.lib.dialogs as dlgs
+
source = self.html.GetParser().GetSource()
- dlg = wxScrolledMessageDialog(self, source, 'HTML Source')
+
+ dlg = dlgs.wxScrolledMessageDialog(self, source, 'HTML Source')
dlg.ShowModal()
dlg.Destroy()
def runTest(frame, nb, log):
win = TestHtmlPanel(nb, frame, log)
- print wxWindow_FindFocus()
+ print wx.Window_FindFocus()
return win
#----------------------------------------------------------------------
-
-
-
overview = """<html><body>
<h2>wxHtmlWindow</h2>
simple HTML tags.
<p>It is not intended to be a high-end HTML browser. If you're
-looking for something like that try http://www.mozilla.org - there's a
-chance you'll be able to make their widget wxWindows-compatible. I'm
-sure everyone will enjoy your work in that case...
+looking for something like that see the IEHtmlWin class, which
+wraps the core MSIE HTML viewer.
</body></html>
"""
+# 11/18/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+# 11/28/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o iewin.py is missing
+#
-from wxPython.wx import *
+import wx
-if wxPlatform == '__WXMSW__':
- from wxPython.iewin import *
+if wx.Platform == '__WXMSW__':
+ import wx.iewin as iewin
#----------------------------------------------------------------------
-class TestPanel(wxWindow):
+class TestPanel(wx.Window):
def __init__(self, parent, log, frame=None):
- wxWindow.__init__(self, parent, -1,
- style=wxTAB_TRAVERSAL|wxCLIP_CHILDREN|wxNO_FULL_REPAINT_ON_RESIZE)
+ wx.Window.__init__(
+ self, parent, -1,
+ style=wx.TAB_TRAVERSAL|wx.CLIP_CHILDREN|wx.NO_FULL_REPAINT_ON_RESIZE
+ )
+
self.log = log
- self.current = "http://wxWindows.org/"
+ self.current = "http://wxPython.org/"
self.frame = frame
+
if frame:
self.titleBase = frame.GetTitle()
+ sizer = wx.BoxSizer(wx.VERTICAL)
+ btnSizer = wx.BoxSizer(wx.HORIZONTAL)
- sizer = wxBoxSizer(wxVERTICAL)
- btnSizer = wxBoxSizer(wxHORIZONTAL)
-
- self.ie = wxIEHtmlWin(self, -1, style = wxNO_FULL_REPAINT_ON_RESIZE)
-
+ self.ie = iewin.IEHtmlWin(self, -1, style = wx.NO_FULL_REPAINT_ON_RESIZE)
- btn = wxButton(self, wxNewId(), "Open", style=wxBU_EXACTFIT)
- EVT_BUTTON(self, btn.GetId(), self.OnOpenButton)
- btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2)
- btn = wxButton(self, wxNewId(), "Home", style=wxBU_EXACTFIT)
- EVT_BUTTON(self, btn.GetId(), self.OnHomeButton)
- btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2)
+ btn = wx.Button(self, wx.NewId(), "Open", style=wx.BU_EXACTFIT)
+ wx.EVT_BUTTON(self, btn.GetId(), self.OnOpenButton)
+ btnSizer.Add(btn, 0, wx.EXPAND|wx.ALL, 2)
- btn = wxButton(self, wxNewId(), "<--", style=wxBU_EXACTFIT)
- EVT_BUTTON(self, btn.GetId(), self.OnPrevPageButton)
- btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2)
+ btn = wx.Button(self, wx.NewId(), "Home", style=wx.BU_EXACTFIT)
+ wx.EVT_BUTTON(self, btn.GetId(), self.OnHomeButton)
+ btnSizer.Add(btn, 0, wx.EXPAND|wx.ALL, 2)
- btn = wxButton(self, wxNewId(), "-->", style=wxBU_EXACTFIT)
- EVT_BUTTON(self, btn.GetId(), self.OnNextPageButton)
- btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2)
+ btn = wx.Button(self, wx.NewId(), "<--", style=wx.BU_EXACTFIT)
+ wx.EVT_BUTTON(self, btn.GetId(), self.OnPrevPageButton)
+ btnSizer.Add(btn, 0, wx.EXPAND|wx.ALL, 2)
- btn = wxButton(self, wxNewId(), "Stop", style=wxBU_EXACTFIT)
- EVT_BUTTON(self, btn.GetId(), self.OnStopButton)
- btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2)
+ btn = wx.Button(self, wx.NewId(), "-->", style=wx.BU_EXACTFIT)
+ wx.EVT_BUTTON(self, btn.GetId(), self.OnNextPageButton)
+ btnSizer.Add(btn, 0, wx.EXPAND|wx.ALL, 2)
- btn = wxButton(self, wxNewId(), "Search", style=wxBU_EXACTFIT)
- EVT_BUTTON(self, btn.GetId(), self.OnSearchPageButton)
- btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2)
+ btn = wx.Button(self, wx.NewId(), "Stop", style=wx.BU_EXACTFIT)
+ wx.EVT_BUTTON(self, btn.GetId(), self.OnStopButton)
+ btnSizer.Add(btn, 0, wx.EXPAND|wx.ALL, 2)
- btn = wxButton(self, wxNewId(), "Refresh", style=wxBU_EXACTFIT)
- EVT_BUTTON(self, btn.GetId(), self.OnRefreshPageButton)
- btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2)
+ btn = wx.Button(self, wx.NewId(), "Search", style=wx.BU_EXACTFIT)
+ wx.EVT_BUTTON(self, btn.GetId(), self.OnSearchPageButton)
+ btnSizer.Add(btn, 0, wx.EXPAND|wx.ALL, 2)
- txt = wxStaticText(self, -1, "Location:")
- btnSizer.Add(txt, 0, wxCENTER|wxALL, 2)
+ btn = wx.Button(self, wx.NewId(), "Refresh", style=wx.BU_EXACTFIT)
+ wx.EVT_BUTTON(self, btn.GetId(), self.OnRefreshPageButton)
+ btnSizer.Add(btn, 0, wx.EXPAND|wx.ALL, 2)
- self.location = wxComboBox(self, wxNewId(), "", style=wxCB_DROPDOWN|wxPROCESS_ENTER)
- EVT_COMBOBOX(self, self.location.GetId(), self.OnLocationSelect)
- EVT_KEY_UP(self.location, self.OnLocationKey)
- EVT_CHAR(self.location, self.IgnoreReturn)
- btnSizer.Add(self.location, 1, wxEXPAND|wxALL, 2)
+ txt = wx.StaticText(self, -1, "Location:")
+ btnSizer.Add(txt, 0, wx.CENTER|wx.ALL, 2)
+ self.location = wx.ComboBox(
+ self, wx.NewId(), "", style=wx.CB_DROPDOWN|wx.PROCESS_ENTER
+ )
+
+ wx.EVT_COMBOBOX(self, self.location.GetId(), self.OnLocationSelect)
+ wx.EVT_KEY_UP(self.location, self.OnLocationKey)
+ wx.EVT_CHAR(self.location, self.IgnoreReturn)
+ btnSizer.Add(self.location, 1, wx.EXPAND|wx.ALL, 2)
- sizer.Add(btnSizer, 0, wxEXPAND)
- sizer.Add(self.ie, 1, wxEXPAND)
+ sizer.Add(btnSizer, 0, wx.EXPAND)
+ sizer.Add(self.ie, 1, wx.EXPAND)
self.ie.Navigate(self.current)
self.location.Append(self.current)
self.SetSizer(sizer)
self.SetAutoLayout(True)
- EVT_SIZE(self, self.OnSize)
+ wx.EVT_SIZE(self, self.OnSize)
# Hook up the event handlers for the IE window
- EVT_MSHTML_BEFORENAVIGATE2(self, -1, self.OnBeforeNavigate2)
- EVT_MSHTML_NEWWINDOW2(self, -1, self.OnNewWindow2)
- EVT_MSHTML_DOCUMENTCOMPLETE(self, -1, self.OnDocumentComplete)
+ iewin.EVT_MSHTML_BEFORENAVIGATE2(self, -1, self.OnBeforeNavigate2)
+ iewin.EVT_MSHTML_NEWWINDOW2(self, -1, self.OnNewWindow2)
+ iewin.EVT_MSHTML_DOCUMENTCOMPLETE(self, -1, self.OnDocumentComplete)
#EVT_MSHTML_PROGRESSCHANGE(self, -1, self.OnProgressChange)
- EVT_MSHTML_STATUSTEXTCHANGE(self, -1, self.OnStatusTextChange)
- EVT_MSHTML_TITLECHANGE(self, -1, self.OnTitleChange)
+ iewin.EVT_MSHTML_STATUSTEXTCHANGE(self, -1, self.OnStatusTextChange)
+ iewin.EVT_MSHTML_TITLECHANGE(self, -1, self.OnTitleChange)
def ShutdownDemo(self):
self.ie.Navigate(url)
def OnLocationKey(self, evt):
- if evt.KeyCode() == WXK_RETURN:
+ if evt.KeyCode() == wx.WXK_RETURN:
URL = self.location.GetValue()
self.location.Append(URL)
self.ie.Navigate(URL)
def IgnoreReturn(self, evt):
- if evt.GetKeyCode() != WXK_RETURN:
+ if evt.GetKeyCode() != wx.WXK_RETURN:
evt.Skip()
def OnOpenButton(self, event):
- dlg = wxTextEntryDialog(self, "Open Location",
+ dlg = wx.TextEntryDialog(self, "Open Location",
"Enter a full URL or local path",
- self.current, wxOK|wxCANCEL)
+ self.current, wx.OK|wx.CANCEL)
dlg.CentreOnParent()
- if dlg.ShowModal() == wxID_OK:
+
+ if dlg.ShowModal() == wx.ID_OK:
self.current = dlg.GetValue()
self.ie.Navigate(self.current)
+
dlg.Destroy()
def OnHomeButton(self, event):
self.ie.GoSearch()
def OnRefreshPageButton(self, evt):
- self.ie.Refresh(wxIEHTML_REFRESH_COMPLETELY)
-
+ self.ie.Refresh(iewin.IEHTML_REFRESH_COMPLETELY)
def logEvt(self, name, event):
# for the demo framework...
def runTest(frame, nb, log):
- if wxPlatform == '__WXMSW__':
+ if wx.Platform == '__WXMSW__':
win = TestPanel(nb, log, frame)
return win
else:
- dlg = wxMessageDialog(frame, 'This demo only works on MSW.',
- 'Sorry', wxOK | wxICON_INFORMATION)
+ dlg = wx.MessageDialog(frame, 'This demo only works on MSW.',
+ 'Sorry', wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
+# 11/19/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+
+import wx
-from wxPython.wx import *
from Main import opj
#----------------------------------------------------------------------
def runTest(frame, nb, log):
- bmp = wxImage(opj('bitmaps/image.bmp'), wxBITMAP_TYPE_BMP).ConvertToBitmap()
- gif = wxImage(opj('bitmaps/image.gif'), wxBITMAP_TYPE_GIF).ConvertToBitmap()
- png = wxImage(opj('bitmaps/image.png'), wxBITMAP_TYPE_PNG).ConvertToBitmap()
- jpg = wxImage(opj('bitmaps/image.jpg'), wxBITMAP_TYPE_JPEG).ConvertToBitmap()
+ bmp = wx.Image(opj('bitmaps/image.bmp'), wx.BITMAP_TYPE_BMP).ConvertToBitmap()
+ gif = wx.Image(opj('bitmaps/image.gif'), wx.BITMAP_TYPE_GIF).ConvertToBitmap()
+ png = wx.Image(opj('bitmaps/image.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap()
+ jpg = wx.Image(opj('bitmaps/image.jpg'), wx.BITMAP_TYPE_JPEG).ConvertToBitmap()
+
+ panel = wx.Panel(nb, -1)
- panel = wxPanel(nb, -1)
pos = 10
- wxStaticBitmap(panel, -1, bmp, wxPoint(10, pos),
- wxSize(bmp.GetWidth(), bmp.GetHeight()))
+ wx.StaticBitmap(panel, -1, bmp, (10, pos), (bmp.GetWidth(), bmp.GetHeight()))
pos = pos + bmp.GetHeight() + 10
- wxStaticBitmap(panel, -1, gif, wxPoint(10, pos),
- wxSize(gif.GetWidth(), gif.GetHeight()))
+ wx.StaticBitmap(panel, -1, gif, (10, pos), (gif.GetWidth(), gif.GetHeight()))
pos = pos + gif.GetHeight() + 10
- wxStaticBitmap(panel, -1, png, wxPoint(10, pos),
- wxSize(png.GetWidth(), png.GetHeight()))
+ wx.StaticBitmap(panel, -1, png, (10, pos), (png.GetWidth(), png.GetHeight()))
pos = pos + png.GetHeight() + 10
- wxStaticBitmap(panel, -1, jpg, wxPoint(10, pos),
- wxSize(jpg.GetWidth(), jpg.GetHeight()))
+ wx.StaticBitmap(panel, -1, jpg, (10, pos), (jpg.GetWidth(), jpg.GetHeight()))
return panel
-
-
-
-
overview = """\
-"""
-
-
+<html>
+<body>
+This class encapsulates a platform-independent image. An image can be created
+from data, or using <code>wxBitmap.ConvertToImage</code>. An image can be loaded from
+a file in a variety of formats, and is extensible to new formats via image
+format handlers. Functions are available to set and get image bits, so it can
+be used for basic image manipulation.
+
+<p>The following image handlers are available. wxBMPHandler is always installed
+by default. To use other image formats, install the appropriate handler or use
+<code>wx.InitAllImageHandlers()</code>.
+
+<p>
+<table>
+<tr><td width=25%>wxBMPHandler</td> <td>For loading and saving, always installed.</td></tr>
+<tr><td>wxPNGHandler</td> <td>For loading and saving.</td> </tr>
+<tr><td>wxJPEGHandler</td> <td>For loading and saving.</td> </tr>
+<tr><td>wxGIFHandler</td> <td>Only for loading, due to legal issues.</td> </tr>
+<tr><td>wxPCXHandler</td> <td>For loading and saving.</td> </tr>
+<tr><td>wxPNMHandler</td> <td>For loading and saving.</td> </tr>
+<tr><td>wxTIFFHandler</td> <td>For loading and saving.</td> </tr>
+<tr><td>wxIFFHandler</td> <td>For loading only.</td> </tr>
+<tr><td>wxXPMHandler</td> <td>For loading and saving.</td> </tr>
+<tr><td>wxICOHandler</td> <td>For loading and saving.</td> </tr>
+<tr><td>wxCURHandler</td> <td>For loading and saving.</td> </tr>
+<tr><td>wxANIHandler</td> <td>For loading only.</td> </tr>
+</table>
+
+<p>When saving in PCX format, wxPCXHandler will count the number of different
+colours in the image; if there are 256 or less colours, it will save as 8 bit,
+else it will save as 24 bit.
+
+<p>Loading PNMs only works for ASCII or raw RGB images. When saving in PNM format,
+wxPNMHandler will always save as raw RGB.
+
+</body>
+</html>"""
if __name__ == '__main__':
import sys,os
+# 11/19/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
-from Main import opj
+import cStringIO
+
+import wx
-from cStringIO import StringIO
+from Main import opj
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
data = open(opj('bitmaps/image.png'), "rb").read()
- stream = StringIO(data)
+ stream = cStringIO.StringIO(data)
+
+ bmp = wx.BitmapFromImage( wx.ImageFromStream( stream ))
- bmp = wxBitmapFromImage( wxImageFromStream( stream ))
+ wx.StaticText(
+ self, -1, "This image was loaded from a Python file-like object:",
+ (15, 15)
+ )
- wxStaticText(self, -1,
- "This image was loaded from a Python file-like object:",
- (15, 15))
- wxStaticBitmap(self, -1, bmp, (15, 45))#, (bmp.GetWidth(), bmp.GetHeight()))
+ wx.StaticBitmap(self, -1, bmp, (15, 45))#, (bmp.GetWidth(), bmp.GetHeight()))
using StringIO. """
-
-
if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])])
-
-from wxPython.wx import *
-from wxPython.lib.intctrl import *
+# 11/19/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+# 11/29/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o intctrl needs the renamer applied.
+# o intctrl needs new event binders.
+#
+
+import wx
+import wx.lib.intctrl as intctrl
#----------------------------------------------------------------------
-class TestPanel( wxPanel ):
+class TestPanel( wx.Panel ):
def __init__( self, parent, log ):
- wxPanel.__init__( self, parent, -1 )
+ wx.Panel.__init__( self, parent, -1 )
self.log = log
- panel = wxPanel( self, -1 )
+ panel = wx.Panel( self, -1 )
- self.set_min = wxCheckBox( panel, -1, "Set minimum value:" )
- self.min = wxIntCtrl( panel, size=wxSize( 50, -1 ) )
+ self.set_min = wx.CheckBox( panel, -1, "Set minimum value:" )
+ self.min = intctrl.wxIntCtrl( panel, size=( 50, -1 ) )
self.min.Enable( False )
- self.set_max = wxCheckBox( panel, -1, "Set maximum value:" )
- self.max = wxIntCtrl( panel, size=wxSize( 50, -1 ) )
+ self.set_max = wx.CheckBox( panel, -1, "Set maximum value:" )
+ self.max = intctrl.wxIntCtrl( panel, size=( 50, -1 ) )
self.max.Enable( False )
- self.limit_target = wxCheckBox( panel, -1, "Limit control" )
- self.allow_none = wxCheckBox( panel, -1, "Allow empty control" )
- self.allow_long = wxCheckBox( panel, -1, "Allow long integers" )
+ self.limit_target = wx.CheckBox( panel, -1, "Limit control" )
+ self.allow_none = wx.CheckBox( panel, -1, "Allow empty control" )
+ self.allow_long = wx.CheckBox( panel, -1, "Allow long integers" )
- label = wxStaticText( panel, -1, "Resulting integer control:" )
- self.target_ctl = wxIntCtrl( panel )
+ label = wx.StaticText( panel, -1, "Resulting integer control:" )
+ self.target_ctl = intctrl.wxIntCtrl( panel )
- grid = wxFlexGridSizer( 0, 2, 0, 0 )
- grid.AddWindow( self.set_min, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5 )
- grid.AddWindow( self.min, 0, wxALIGN_LEFT|wxALL, 5 )
+ grid = wx.FlexGridSizer( 0, 2, 0, 0 )
+ grid.Add( self.set_min, 0, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
+ grid.Add( self.min, 0, wx.ALIGN_LEFT|wx.ALL, 5 )
- grid.AddWindow( self.set_max, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5 )
- grid.AddWindow( self.max, 0, wxALIGN_LEFT|wxALL, 5 )
+ grid.Add(self.set_max, 0, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
+ grid.Add( self.max, 0, wx.ALIGN_LEFT|wx.ALL, 5 )
- grid.AddWindow( self.limit_target, 0, wxALIGN_LEFT|wxALL, 5 )
- grid.AddSpacer( (20, 0), 0, wxALIGN_LEFT|wxALL, 5 )
- grid.AddWindow( self.allow_none, 0, wxALIGN_LEFT|wxALL, 5 )
- grid.AddSpacer( (20, 0), 0, wxALIGN_LEFT|wxALL, 5 )
- grid.AddWindow( self.allow_long, 0, wxALIGN_LEFT|wxALL, 5 )
- grid.AddSpacer( (20, 0), 0, wxALIGN_LEFT|wxALL, 5 )
+ grid.Add( self.limit_target, 0, wx.ALIGN_LEFT|wx.ALL, 5 )
+ grid.Add( (20, 0), 0, wx.ALIGN_LEFT|wx.ALL, 5 )
+ grid.Add( self.allow_none, 0, wx.ALIGN_LEFT|wx.ALL, 5 )
+ grid.Add( (20, 0), 0, wx.ALIGN_LEFT|wx.ALL, 5 )
+ grid.Add( self.allow_long, 0, wx.ALIGN_LEFT|wx.ALL, 5 )
+ grid.Add( (20, 0), 0, wx.ALIGN_LEFT|wx.ALL, 5 )
- grid.AddSpacer( (20, 0), 0, wxALIGN_LEFT|wxALL, 5 )
- grid.AddSpacer( (20, 0), 0, wxALIGN_LEFT|wxALL, 5 )
+ grid.Add( (20, 0), 0, wx.ALIGN_LEFT|wx.ALL, 5 )
+ grid.Add( (20, 0), 0, wx.ALIGN_LEFT|wx.ALL, 5 )
- grid.AddWindow( label, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5 )
- grid.AddWindow( self.target_ctl, 0, wxALIGN_LEFT|wxALL, 5 )
+ grid.Add( label, 0, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
+ grid.Add( self.target_ctl, 0, wx.ALIGN_LEFT|wx.ALL, 5 )
- outer_box = wxBoxSizer( wxVERTICAL )
- outer_box.AddSizer( grid, 0, wxALIGN_CENTRE|wxALL, 20 )
+ outer_box = wx.BoxSizer( wx.VERTICAL )
+ outer_box.AddSizer( grid, 0, wx.ALIGN_CENTRE|wx.ALL, 20 )
panel.SetAutoLayout( True )
panel.SetSizer( outer_box )
panel.Move( (50,50) )
self.panel = panel
- EVT_CHECKBOX( self, self.set_min.GetId(), self.OnSetMin )
- EVT_CHECKBOX( self, self.set_max.GetId(), self.OnSetMax )
- EVT_CHECKBOX( self, self.limit_target.GetId(), self.SetTargetMinMax )
- EVT_CHECKBOX( self, self.allow_none.GetId(), self.OnSetAllowNone )
- EVT_CHECKBOX( self, self.allow_long.GetId(), self.OnSetAllowLong )
- EVT_INT( self, self.min.GetId(), self.SetTargetMinMax )
- EVT_INT( self, self.max.GetId(), self.SetTargetMinMax )
- EVT_INT( self, self.target_ctl.GetId(), self.OnTargetChange )
+ self.Bind(wx.EVT_CHECKBOX, self.OnSetMin, self.set_min)
+ self.Bind(wx.EVT_CHECKBOX, self.OnSetMax, self.set_max)
+ self.Bind(wx.EVT_CHECKBOX, self.SetTargetMinMax, self.limit_target)
+ self.Bind(wx.EVT_CHECKBOX, self.OnSetAllowNone, self.allow_none)
+ self.Bind(wx.EVT_CHECKBOX, self.OnSetAllowLong, self.allow_long)
+
+ # Once the intctrl library is updated, this should be too.
+ intctrl.EVT_INT(self, self.min.GetId(), self.SetTargetMinMax)
+ intctrl.EVT_INT(self, self.max.GetId(), self.SetTargetMinMax)
+ intctrl.EVT_INT(self, self.target_ctl.GetId(), self.OnTargetChange)
def OnSetMin( self, event ):
if self.set_min.GetValue():
min = self.min.GetValue()
+
if self.set_max.GetValue():
max = self.max.GetValue()
if min != cur_min and not self.target_ctl.SetMin( min ):
self.log.write( "min (%d) > current max (%d) -- bound not set\n" % ( min, self.target_ctl.GetMax() ) )
- self.min.SetForegroundColour( wxRED )
+ self.min.SetForegroundColour( wx.RED )
else:
- self.min.SetForegroundColour( wxBLACK )
+ self.min.SetForegroundColour( wx.BLACK )
+
self.min.Refresh()
if max != cur_max and not self.target_ctl.SetMax( max ):
self.log.write( "max (%d) < current min (%d) -- bound not set\n" % ( max, self.target_ctl.GetMin() ) )
- self.max.SetForegroundColour( wxRED )
+ self.max.SetForegroundColour( wx.RED )
else:
- self.max.SetForegroundColour( wxBLACK )
+ self.max.SetForegroundColour( wx.BLACK )
+
self.max.Refresh()
if min != cur_min or max != cur_max:
-
-from wxPython.wx import *
+# 11/19/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+# 11/29/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o lib.mixins.listctrl needs wx renamer applied.
+#
+
+import wx
+import wx.lib.mixins.listctrl as listmix
#----------------------------------------------------------------------
keyMap = {
- WXK_BACK : "WXK_BACK",
- WXK_TAB : "WXK_TAB",
- WXK_RETURN : "WXK_RETURN",
- WXK_ESCAPE : "WXK_ESCAPE",
- WXK_SPACE : "WXK_SPACE",
- WXK_DELETE : "WXK_DELETE",
- WXK_START : "WXK_START",
- WXK_LBUTTON : "WXK_LBUTTON",
- WXK_RBUTTON : "WXK_RBUTTON",
- WXK_CANCEL : "WXK_CANCEL",
- WXK_MBUTTON : "WXK_MBUTTON",
- WXK_CLEAR : "WXK_CLEAR",
- WXK_SHIFT : "WXK_SHIFT",
- WXK_ALT : "WXK_ALT",
- WXK_CONTROL : "WXK_CONTROL",
- WXK_MENU : "WXK_MENU",
- WXK_PAUSE : "WXK_PAUSE",
- WXK_CAPITAL : "WXK_CAPITAL",
- WXK_PRIOR : "WXK_PRIOR",
- WXK_NEXT : "WXK_NEXT",
- WXK_END : "WXK_END",
- WXK_HOME : "WXK_HOME",
- WXK_LEFT : "WXK_LEFT",
- WXK_UP : "WXK_UP",
- WXK_RIGHT : "WXK_RIGHT",
- WXK_DOWN : "WXK_DOWN",
- WXK_SELECT : "WXK_SELECT",
- WXK_PRINT : "WXK_PRINT",
- WXK_EXECUTE : "WXK_EXECUTE",
- WXK_SNAPSHOT : "WXK_SNAPSHOT",
- WXK_INSERT : "WXK_INSERT",
- WXK_HELP : "WXK_HELP",
- WXK_NUMPAD0 : "WXK_NUMPAD0",
- WXK_NUMPAD1 : "WXK_NUMPAD1",
- WXK_NUMPAD2 : "WXK_NUMPAD2",
- WXK_NUMPAD3 : "WXK_NUMPAD3",
- WXK_NUMPAD4 : "WXK_NUMPAD4",
- WXK_NUMPAD5 : "WXK_NUMPAD5",
- WXK_NUMPAD6 : "WXK_NUMPAD6",
- WXK_NUMPAD7 : "WXK_NUMPAD7",
- WXK_NUMPAD8 : "WXK_NUMPAD8",
- WXK_NUMPAD9 : "WXK_NUMPAD9",
- WXK_MULTIPLY : "WXK_MULTIPLY",
- WXK_ADD : "WXK_ADD",
- WXK_SEPARATOR : "WXK_SEPARATOR",
- WXK_SUBTRACT : "WXK_SUBTRACT",
- WXK_DECIMAL : "WXK_DECIMAL",
- WXK_DIVIDE : "WXK_DIVIDE",
- WXK_F1 : "WXK_F1",
- WXK_F2 : "WXK_F2",
- WXK_F3 : "WXK_F3",
- WXK_F4 : "WXK_F4",
- WXK_F5 : "WXK_F5",
- WXK_F6 : "WXK_F6",
- WXK_F7 : "WXK_F7",
- WXK_F8 : "WXK_F8",
- WXK_F9 : "WXK_F9",
- WXK_F10 : "WXK_F10",
- WXK_F11 : "WXK_F11",
- WXK_F12 : "WXK_F12",
- WXK_F13 : "WXK_F13",
- WXK_F14 : "WXK_F14",
- WXK_F15 : "WXK_F15",
- WXK_F16 : "WXK_F16",
- WXK_F17 : "WXK_F17",
- WXK_F18 : "WXK_F18",
- WXK_F19 : "WXK_F19",
- WXK_F20 : "WXK_F20",
- WXK_F21 : "WXK_F21",
- WXK_F22 : "WXK_F22",
- WXK_F23 : "WXK_F23",
- WXK_F24 : "WXK_F24",
- WXK_NUMLOCK : "WXK_NUMLOCK",
- WXK_SCROLL : "WXK_SCROLL",
- WXK_PAGEUP : "WXK_PAGEUP",
- WXK_PAGEDOWN : "WXK_PAGEDOWN",
- WXK_NUMPAD_SPACE : "WXK_NUMPAD_SPACE",
- WXK_NUMPAD_TAB : "WXK_NUMPAD_TAB",
- WXK_NUMPAD_ENTER : "WXK_NUMPAD_ENTER",
- WXK_NUMPAD_F1 : "WXK_NUMPAD_F1",
- WXK_NUMPAD_F2 : "WXK_NUMPAD_F2",
- WXK_NUMPAD_F3 : "WXK_NUMPAD_F3",
- WXK_NUMPAD_F4 : "WXK_NUMPAD_F4",
- WXK_NUMPAD_HOME : "WXK_NUMPAD_HOME",
- WXK_NUMPAD_LEFT : "WXK_NUMPAD_LEFT",
- WXK_NUMPAD_UP : "WXK_NUMPAD_UP",
- WXK_NUMPAD_RIGHT : "WXK_NUMPAD_RIGHT",
- WXK_NUMPAD_DOWN : "WXK_NUMPAD_DOWN",
- WXK_NUMPAD_PRIOR : "WXK_NUMPAD_PRIOR",
- WXK_NUMPAD_PAGEUP : "WXK_NUMPAD_PAGEUP",
- WXK_NUMPAD_NEXT : "WXK_NUMPAD_NEXT",
- WXK_NUMPAD_PAGEDOWN : "WXK_NUMPAD_PAGEDOWN",
- WXK_NUMPAD_END : "WXK_NUMPAD_END",
- WXK_NUMPAD_BEGIN : "WXK_NUMPAD_BEGIN",
- WXK_NUMPAD_INSERT : "WXK_NUMPAD_INSERT",
- WXK_NUMPAD_DELETE : "WXK_NUMPAD_DELETE",
- WXK_NUMPAD_EQUAL : "WXK_NUMPAD_EQUAL",
- WXK_NUMPAD_MULTIPLY : "WXK_NUMPAD_MULTIPLY",
- WXK_NUMPAD_ADD : "WXK_NUMPAD_ADD",
- WXK_NUMPAD_SEPARATOR : "WXK_NUMPAD_SEPARATOR",
- WXK_NUMPAD_SUBTRACT : "WXK_NUMPAD_SUBTRACT",
- WXK_NUMPAD_DECIMAL : "WXK_NUMPAD_DECIMAL",
- WXK_NUMPAD_DIVIDE : "WXK_NUMPAD_DIVIDE",
+ wx.WXK_BACK : "wx.WXK_BACK",
+ wx.WXK_TAB : "wx.WXK_TAB",
+ wx.WXK_RETURN : "wx.WXK_RETURN",
+ wx.WXK_ESCAPE : "wx.WXK_ESCAPE",
+ wx.WXK_SPACE : "wx.WXK_SPACE",
+ wx.WXK_DELETE : "wx.WXK_DELETE",
+ wx.WXK_START : "wx.WXK_START",
+ wx.WXK_LBUTTON : "wx.WXK_LBUTTON",
+ wx.WXK_RBUTTON : "wx.WXK_RBUTTON",
+ wx.WXK_CANCEL : "wx.WXK_CANCEL",
+ wx.WXK_MBUTTON : "wx.WXK_MBUTTON",
+ wx.WXK_CLEAR : "wx.WXK_CLEAR",
+ wx.WXK_SHIFT : "wx.WXK_SHIFT",
+ wx.WXK_ALT : "wx.WXK_ALT",
+ wx.WXK_CONTROL : "wx.WXK_CONTROL",
+ wx.WXK_MENU : "wx.WXK_MENU",
+ wx.WXK_PAUSE : "wx.WXK_PAUSE",
+ wx.WXK_CAPITAL : "wx.WXK_CAPITAL",
+ wx.WXK_PRIOR : "wx.WXK_PRIOR",
+ wx.WXK_NEXT : "wx.WXK_NEXT",
+ wx.WXK_END : "wx.WXK_END",
+ wx.WXK_HOME : "wx.WXK_HOME",
+ wx.WXK_LEFT : "wx.WXK_LEFT",
+ wx.WXK_UP : "wx.WXK_UP",
+ wx.WXK_RIGHT : "wx.WXK_RIGHT",
+ wx.WXK_DOWN : "wx.WXK_DOWN",
+ wx.WXK_SELECT : "wx.WXK_SELECT",
+ wx.WXK_PRINT : "wx.WXK_PRINT",
+ wx.WXK_EXECUTE : "wx.WXK_EXECUTE",
+ wx.WXK_SNAPSHOT : "wx.WXK_SNAPSHOT",
+ wx.WXK_INSERT : "wx.WXK_INSERT",
+ wx.WXK_HELP : "wx.WXK_HELP",
+ wx.WXK_NUMPAD0 : "wx.WXK_NUMPAD0",
+ wx.WXK_NUMPAD1 : "wx.WXK_NUMPAD1",
+ wx.WXK_NUMPAD2 : "wx.WXK_NUMPAD2",
+ wx.WXK_NUMPAD3 : "wx.WXK_NUMPAD3",
+ wx.WXK_NUMPAD4 : "wx.WXK_NUMPAD4",
+ wx.WXK_NUMPAD5 : "wx.WXK_NUMPAD5",
+ wx.WXK_NUMPAD6 : "wx.WXK_NUMPAD6",
+ wx.WXK_NUMPAD7 : "wx.WXK_NUMPAD7",
+ wx.WXK_NUMPAD8 : "wx.WXK_NUMPAD8",
+ wx.WXK_NUMPAD9 : "wx.WXK_NUMPAD9",
+ wx.WXK_MULTIPLY : "wx.WXK_MULTIPLY",
+ wx.WXK_ADD : "wx.WXK_ADD",
+ wx.WXK_SEPARATOR : "wx.WXK_SEPARATOR",
+ wx.WXK_SUBTRACT : "wx.WXK_SUBTRACT",
+ wx.WXK_DECIMAL : "wx.WXK_DECIMAL",
+ wx.WXK_DIVIDE : "wx.WXK_DIVIDE",
+ wx.WXK_F1 : "wx.WXK_F1",
+ wx.WXK_F2 : "wx.WXK_F2",
+ wx.WXK_F3 : "wx.WXK_F3",
+ wx.WXK_F4 : "wx.WXK_F4",
+ wx.WXK_F5 : "wx.WXK_F5",
+ wx.WXK_F6 : "wx.WXK_F6",
+ wx.WXK_F7 : "wx.WXK_F7",
+ wx.WXK_F8 : "wx.WXK_F8",
+ wx.WXK_F9 : "wx.WXK_F9",
+ wx.WXK_F10 : "wx.WXK_F10",
+ wx.WXK_F11 : "wx.WXK_F11",
+ wx.WXK_F12 : "wx.WXK_F12",
+ wx.WXK_F13 : "wx.WXK_F13",
+ wx.WXK_F14 : "wx.WXK_F14",
+ wx.WXK_F15 : "wx.WXK_F15",
+ wx.WXK_F16 : "wx.WXK_F16",
+ wx.WXK_F17 : "wx.WXK_F17",
+ wx.WXK_F18 : "wx.WXK_F18",
+ wx.WXK_F19 : "wx.WXK_F19",
+ wx.WXK_F20 : "wx.WXK_F20",
+ wx.WXK_F21 : "wx.WXK_F21",
+ wx.WXK_F22 : "wx.WXK_F22",
+ wx.WXK_F23 : "wx.WXK_F23",
+ wx.WXK_F24 : "wx.WXK_F24",
+ wx.WXK_NUMLOCK : "wx.WXK_NUMLOCK",
+ wx.WXK_SCROLL : "wx.WXK_SCROLL",
+ wx.WXK_PAGEUP : "wx.WXK_PAGEUP",
+ wx.WXK_PAGEDOWN : "wx.WXK_PAGEDOWN",
+ wx.WXK_NUMPAD_SPACE : "wx.WXK_NUMPAD_SPACE",
+ wx.WXK_NUMPAD_TAB : "wx.WXK_NUMPAD_TAB",
+ wx.WXK_NUMPAD_ENTER : "wx.WXK_NUMPAD_ENTER",
+ wx.WXK_NUMPAD_F1 : "wx.WXK_NUMPAD_F1",
+ wx.WXK_NUMPAD_F2 : "wx.WXK_NUMPAD_F2",
+ wx.WXK_NUMPAD_F3 : "wx.WXK_NUMPAD_F3",
+ wx.WXK_NUMPAD_F4 : "wx.WXK_NUMPAD_F4",
+ wx.WXK_NUMPAD_HOME : "wx.WXK_NUMPAD_HOME",
+ wx.WXK_NUMPAD_LEFT : "wx.WXK_NUMPAD_LEFT",
+ wx.WXK_NUMPAD_UP : "wx.WXK_NUMPAD_UP",
+ wx.WXK_NUMPAD_RIGHT : "wx.WXK_NUMPAD_RIGHT",
+ wx.WXK_NUMPAD_DOWN : "wx.WXK_NUMPAD_DOWN",
+ wx.WXK_NUMPAD_PRIOR : "wx.WXK_NUMPAD_PRIOR",
+ wx.WXK_NUMPAD_PAGEUP : "wx.WXK_NUMPAD_PAGEUP",
+ wx.WXK_NUMPAD_NEXT : "wx.WXK_NUMPAD_NEXT",
+ wx.WXK_NUMPAD_PAGEDOWN : "wx.WXK_NUMPAD_PAGEDOWN",
+ wx.WXK_NUMPAD_END : "wx.WXK_NUMPAD_END",
+ wx.WXK_NUMPAD_BEGIN : "wx.WXK_NUMPAD_BEGIN",
+ wx.WXK_NUMPAD_INSERT : "wx.WXK_NUMPAD_INSERT",
+ wx.WXK_NUMPAD_DELETE : "wx.WXK_NUMPAD_DELETE",
+ wx.WXK_NUMPAD_EQUAL : "wx.WXK_NUMPAD_EQUAL",
+ wx.WXK_NUMPAD_MULTIPLY : "wx.WXK_NUMPAD_MULTIPLY",
+ wx.WXK_NUMPAD_ADD : "wx.WXK_NUMPAD_ADD",
+ wx.WXK_NUMPAD_SEPARATOR : "wx.WXK_NUMPAD_SEPARATOR",
+ wx.WXK_NUMPAD_SUBTRACT : "wx.WXK_NUMPAD_SUBTRACT",
+ wx.WXK_NUMPAD_DECIMAL : "wx.WXK_NUMPAD_DECIMAL",
+ wx.WXK_NUMPAD_DIVIDE : "wx.WXK_NUMPAD_DIVIDE",
}
#----------------------------------------------------------------------
-class KeySink(wxWindow):
+class KeySink(wx.Window):
def __init__(self, parent):
- wxWindow.__init__(self, parent, -1, style =
- wxWANTS_CHARS
- #| wxRAISED_BORDER
- #| wxSUNKEN_BORDER
+ wx.Window.__init__(self, parent, -1, style=wx.WANTS_CHARS
+ #| wx.RAISED_BORDER
+ #| wx.SUNKEN_BORDER
)
- self.SetBackgroundColour(wxBLUE)
+
+ self.SetBackgroundColour(wx.BLUE)
self.haveFocus = False
self.callSkip = False
self.logKeyDn = True
self.logKeyUp = True
self.logChar = True
- EVT_PAINT(self, self.OnPaint)
- EVT_SET_FOCUS(self, self.OnSetFocus)
- EVT_KILL_FOCUS(self, self.OnKillFocus)
- EVT_MOUSE_EVENTS(self, self.OnMouse)
+ self.Bind(wx.EVT_PAINT, self.OnPaint)
+ self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
+ self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
+ self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouse)
- EVT_KEY_DOWN(self, self.OnKeyDown)
- EVT_KEY_UP(self, self.OnKeyUp)
- EVT_CHAR(self, self.OnChar)
+ self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
+ self.Bind(wx.EVT_KEY_UP, self.OnKeyUp)
+ self.Bind(wx.EVT_CHAR, self.OnChar)
def SetCallSkip(self, skip):
def OnPaint(self, evt):
- dc = wxPaintDC(self)
+ dc = wx.PaintDC(self)
rect = self.GetClientRect()
- dc.SetTextForeground(wxWHITE)
+ dc.SetTextForeground(wx.WHITE)
dc.DrawLabel("Click here and then press some keys",
- rect, wxALIGN_CENTER | wxALIGN_TOP)
+ rect, wx.ALIGN_CENTER | wx.ALIGN_TOP)
if self.haveFocus:
- dc.SetTextForeground(wxGREEN)
- dc.DrawLabel("Have Focus", rect, wxALIGN_RIGHT | wxALIGN_BOTTOM)
+ dc.SetTextForeground(wx.GREEN)
+ dc.DrawLabel("Have Focus", rect, wx.ALIGN_RIGHT | wx.ALIGN_BOTTOM)
else:
- dc.SetTextForeground(wxRED)
- dc.DrawLabel("Need Focus!", rect, wxALIGN_RIGHT | wxALIGN_BOTTOM)
+ dc.SetTextForeground(wx.RED)
+ dc.DrawLabel("Need Focus!", rect, wx.ALIGN_RIGHT | wx.ALIGN_BOTTOM)
def OnSetFocus(self, evt):
#----------------------------------------------------------------------
-from wxPython.lib.mixins.listctrl import wxListCtrlAutoWidthMixin
-
-class KeyLog(wxListCtrl, wxListCtrlAutoWidthMixin):
+class KeyLog(wx.ListCtrl, listmix.wxListCtrlAutoWidthMixin):
def __init__(self, parent):
- wxListCtrl.__init__(self, parent, -1,
- style = wxLC_REPORT|wxLC_VRULES|wxLC_HRULES)
- wxListCtrlAutoWidthMixin.__init__(self)
+ wx.ListCtrl.__init__(self, parent, -1,
+ style = wx.LC_REPORT|wx.LC_VRULES|wx.LC_HRULES)
+ listmix.wxListCtrlAutoWidthMixin.__init__(self)
self.InsertColumn(0, "Event Type")
self.InsertColumn(1, "Key Name")
self.InsertColumn(6, "")
for x in range(6):
- self.SetColumnWidth(x, wxLIST_AUTOSIZE_USEHEADER)
+ self.SetColumnWidth(x, wx.LIST_AUTOSIZE_USEHEADER)
self.SetColumnWidth(1, 125)
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
self.log = log
- wxPanel.__init__(self, parent, -1, style=0)
+ wx.Panel.__init__(self, parent, -1, style=0)
self.keysink = KeySink(self)
self.keysink.SetSize((100, 65))
self.keylog = KeyLog(self)
- btn = wxButton(self, -1, "Clear Log")
- EVT_BUTTON(self, btn.GetId(), self.OnClearBtn)
+ btn = wx.Button(self, -1, "Clear Log")
+ self.Bind(wx.EVT_BUTTON, self.OnClearBtn, btn)
- cb1 = wxCheckBox(self, -1, "Call evt.Skip for Key Up/Dn events")
- EVT_CHECKBOX(self, cb1.GetId(), self.OnSkipCB)
+ cb1 = wx.CheckBox(self, -1, "Call evt.Skip for Key Up/Dn events")
+ self.Bind(wx.EVT_CHECKBOX, self.OnSkipCB, cb1)
- cb2 = wxCheckBox(self, -1, "EVT_KEY_UP")
- EVT_CHECKBOX(self, cb2.GetId(), self.OnKeyUpCB)
+ cb2 = wx.CheckBox(self, -1, "EVT_KEY_UP")
+ self.Bind(wx.EVT_CHECKBOX, self.OnKeyUpCB, cb2)
cb2.SetValue(True)
- cb3 = wxCheckBox(self, -1, "EVT_KEY_DOWN")
- EVT_CHECKBOX(self, cb3.GetId(), self.OnKeyDnCB)
+ cb3 = wx.CheckBox(self, -1, "EVT_KEY_DOWN")
+ self.Bind(wx.EVT_CHECKBOX, self.OnKeyDnCB, cb3)
cb3.SetValue(True)
- cb4 = wxCheckBox(self, -1, "EVT_CHAR")
- EVT_CHECKBOX(self, cb4.GetId(), self.OnCharCB)
+ cb4 = wx.CheckBox(self, -1, "EVT_CHAR")
+ self.Bind(wx.EVT_CHECKBOX, self.OnCharCB, cb4)
cb4.SetValue(True)
- buttons = wxBoxSizer(wxHORIZONTAL)
- buttons.Add(btn, 0, wxALL, 4)
- buttons.Add(cb1, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 6)
- buttons.Add(cb2, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 6)
- buttons.Add(cb3, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 6)
- buttons.Add(cb4, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 6)
+ buttons = wx.BoxSizer(wx.HORIZONTAL)
+ buttons.Add(btn, 0, wx.ALL, 4)
+ buttons.Add(cb1, 0, wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, 6)
+ buttons.Add(cb2, 0, wx.ALIGN_CENTER_VERTICAL|wx.LEFT, 6)
+ buttons.Add(cb3, 0, wx.ALIGN_CENTER_VERTICAL|wx.LEFT, 6)
+ buttons.Add(cb4, 0, wx.ALIGN_CENTER_VERTICAL|wx.LEFT, 6)
- sizer = wxBoxSizer(wxVERTICAL)
- sizer.Add(self.keysink, 0, wxGROW)
+ sizer = wx.BoxSizer(wx.VERTICAL)
+ sizer.Add(self.keysink, 0, wx.GROW)
sizer.Add(buttons)
- sizer.Add(self.keylog, 1, wxGROW)
+ sizer.Add(self.keylog, 1, wx.GROW)
self.SetSizer(sizer)
overview = """<html><body>
<h2><center>wxKeyEvents</center></h2>
-This demo simply lets catches all key events and prints info about them.
+This demo simply catches all key events and prints info about them.
It is meant to be used as a compatibility test for cross platform work.
</body></html>
+# 11/19/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
-from wxPython.gizmos import *
+import time
-import time
+import wx
+import wx.gizmos as gizmos
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.log = log
- led = wxLEDNumberCtrl(self, -1, (25,25), (280, 50))
+ led = gizmos.LEDNumberCtrl(self, -1, (25,25), (280, 50))
led.SetValue("01234")
- led = wxLEDNumberCtrl(self, -1, (25,100), (280, 50))
+ led = gizmos.LEDNumberCtrl(self, -1, (25,100), (280, 50))
led.SetValue("56789")
- led.SetAlignment(wxLED_ALIGN_RIGHT)
+ led.SetAlignment(gizmos.LED_ALIGN_RIGHT)
led.SetDrawFaded(False)
- led = wxLEDNumberCtrl(self, -1, (25,175), (280, 50),
- wxLED_ALIGN_CENTER)# | wxLED_DRAW_FADED)
+ led = gizmos.LEDNumberCtrl(self, -1, (25,175), (280, 50),
+ gizmos.LED_ALIGN_CENTER)# | gizmos.LED_DRAW_FADED)
self.clock = led
self.OnTimer(None)
- self.timer = wxTimer(self)
+ self.timer = wx.Timer(self)
self.timer.Start(1000)
- EVT_TIMER(self, -1, self.OnTimer)
+ self.Bind(wx.EVT_TIMER, self.OnTimer)
def OnTimer(self, evt):
#----------------------------------------------------------------------
overview = """\
+<html>
+<body>
+<font size=-1>The following was gleaned as best I could from the wxWindows
+source, which was a bit reluctant to reveal its secrets. My appologies if
+I missed anything - jmg</font>
+<p>
+<code><b>wxLEDNumberCtrl</b>( parent, id=-1, pos=wx.DefaultPosition,
+size=wx.DefaultSize, style=LED_ALIGN_LEFT | LED_DRAW_FADED)</code>
+
+<p>This is a control that simulates an LED clock display. It only accepts
+numeric input.
+
+<p><b>Styles</b>
+
+<p><dl>
+<dt><b>LED_ALIGN_LEFT</b>
+<dd>Align to the left.
+
+<dt><b>LED_ALIGN_RIGHT</b>
+<dd>Align to the right.
+
+<dt><b>LED_ALIGN_CENTER</b>
+<dd>Center on display.
+
+<dt><b>LED_DRAW_FADED</b>
+<dd>Not implemented.
+
+</dl>
+
+<p><b>Methods</b> (and best guesses at what they do)
+
+<p><dl>
+<dt><b>GetAlignment()</b>
+<dd>Returns the alignment attribute for the control.
+
+<dt><b>GetDrawFaded()</b>
+<dd>Returns the DrawFaded attribute for the control.
+
+<dt><b>GetValue()</b>
+<dd>Returns the current value of the control.
+
+<dt><b>SetAlignment(alignment)</b>
+<dd>Set the alignment attribute for the control.
+
+<dt><b>SetDrawFaded(value)</b>
+<dd>Set the DrawFaded attribute for the control.
+
+<dt><b>SetValue(number)</b>
+<dd>Set the value for the control. Only numeric values are accepted.
+
+</dl>
+
+<p>Additionally, several methods of wx.Window are available as well.
+
+</body>
+</html>
"""
+# 11/19/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
+import wx
#---------------------------------------------------------------------------
-class TestLayoutConstraints(wxPanel):
+class TestLayoutConstraints(wx.Panel):
def __init__(self, parent):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.SetAutoLayout(True)
- EVT_BUTTON(self, 100, self.OnButton)
-
- self.SetBackgroundColour(wxNamedColour("MEDIUM ORCHID"))
-
- self.panelA = wxWindow(self, -1, wxDefaultPosition, wxDefaultSize,
- wxSIMPLE_BORDER)
- self.panelA.SetBackgroundColour(wxBLUE)
- txt = wxStaticText(self.panelA, -1,
- "Resize the window and see\n"
- "what happens... Notice that\n"
- "there is no OnSize handler.",
- wxPoint(5,5), wxSize(-1, 50))
- txt.SetBackgroundColour(wxBLUE)
- txt.SetForegroundColour(wxWHITE)
-
- lc = wxLayoutConstraints()
- lc.top.SameAs(self, wxTop, 10)
- lc.left.SameAs(self, wxLeft, 10)
- lc.bottom.SameAs(self, wxBottom, 10)
- lc.right.PercentOf(self, wxRight, 50)
+ self.Bind(wx.EVT_BUTTON, self.OnButton, id=100)
+
+ self.SetBackgroundColour(wx.NamedColour("MEDIUM ORCHID"))
+
+ self.panelA = wx.Window(self, -1, style=wx.SIMPLE_BORDER)
+ self.panelA.SetBackgroundColour(wx.BLUE)
+
+ txt = wx.StaticText(
+ self.panelA, -1,
+ "Resize the window and see\n"
+ "what happens... Notice that\n"
+ "there is no OnSize handler.",
+ (5,5), (-1, 50)
+ )
+
+ txt.SetBackgroundColour(wx.BLUE)
+ txt.SetForegroundColour(wx.WHITE)
+
+ lc = wx.LayoutConstraints()
+ lc.top.SameAs(self, wx.Top, 10)
+ lc.left.SameAs(self, wx.Left, 10)
+ lc.bottom.SameAs(self, wx.Bottom, 10)
+ lc.right.PercentOf(self, wx.Right, 50)
self.panelA.SetConstraints(lc)
- self.panelB = wxWindow(self, -1, wxDefaultPosition, wxDefaultSize,
- wxSIMPLE_BORDER)
- self.panelB.SetBackgroundColour(wxRED)
- lc = wxLayoutConstraints()
- lc.top.SameAs(self, wxTop, 10)
- lc.right.SameAs(self, wxRight, 10)
- lc.bottom.PercentOf(self, wxBottom, 30)
+ self.panelB = wx.Window(self, -1, style=wx.SIMPLE_BORDER)
+ self.panelB.SetBackgroundColour(wx.RED)
+ lc = wx.LayoutConstraints()
+ lc.top.SameAs(self, wx.Top, 10)
+ lc.right.SameAs(self, wx.Right, 10)
+ lc.bottom.PercentOf(self, wx.Bottom, 30)
lc.left.RightOf(self.panelA, 10)
self.panelB.SetConstraints(lc)
- self.panelC = wxWindow(self, -1, wxDefaultPosition, wxDefaultSize,
- wxSIMPLE_BORDER)
- self.panelC.SetBackgroundColour(wxWHITE)
- lc = wxLayoutConstraints()
+ self.panelC = wx.Window(self, -1, style=wx.SIMPLE_BORDER)
+ self.panelC.SetBackgroundColour(wx.WHITE)
+ lc = wx.LayoutConstraints()
lc.top.Below(self.panelB, 10)
- lc.right.SameAs(self, wxRight, 10)
- lc.bottom.SameAs(self, wxBottom, 10)
+ lc.right.SameAs(self, wx.Right, 10)
+ lc.bottom.SameAs(self, wx.Bottom, 10)
lc.left.RightOf(self.panelA, 10)
self.panelC.SetConstraints(lc)
- b = wxButton(self.panelA, 100, ' Panel A ')
- lc = wxLayoutConstraints()
- lc.centreX.SameAs (self.panelA, wxCentreX)
- lc.centreY.SameAs (self.panelA, wxCentreY)
+ b = wx.Button(self.panelA, 100, ' Panel A ')
+ lc = wx.LayoutConstraints()
+ lc.centreX.SameAs (self.panelA, wx.CentreX)
+ lc.centreY.SameAs (self.panelA, wx.CentreY)
lc.height.AsIs ()
- lc.width.PercentOf (self.panelA, wxWidth, 50)
+ lc.width.PercentOf (self.panelA, wx.Width, 50)
b.SetConstraints(lc);
- b = wxButton(self.panelB, 100, ' Panel B ')
- lc = wxLayoutConstraints()
- lc.top.SameAs (self.panelB, wxTop, 2)
- lc.right.SameAs (self.panelB, wxRight, 4)
+ b = wx.Button(self.panelB, 100, ' Panel B ')
+ lc = wx.LayoutConstraints()
+ lc.top.SameAs (self.panelB, wx.Top, 2)
+ lc.right.SameAs (self.panelB, wx.Right, 4)
lc.height.AsIs ()
lc.width.AsIs ()
b.SetConstraints(lc);
- self.panelD = wxWindow(self.panelC, -1, wxDefaultPosition, wxDefaultSize,
- wxSIMPLE_BORDER)
- self.panelD.SetBackgroundColour(wxGREEN)
- wxStaticText(self.panelD, -1, "Panel D", wxPoint(4, 4)).SetBackgroundColour(wxGREEN)
+ self.panelD = wx.Window(self.panelC, -1, style=wx.SIMPLE_BORDER)
+ self.panelD.SetBackgroundColour(wx.GREEN)
+ wx.StaticText(
+ self.panelD, -1, "Panel D", (4, 4)
+ ).SetBackgroundColour(wx.GREEN)
- b = wxButton(self.panelC, 100, ' Panel C ')
- lc = wxLayoutConstraints()
+ b = wx.Button(self.panelC, 100, ' Panel C ')
+ lc = wx.LayoutConstraints()
lc.top.Below (self.panelD)
lc.left.RightOf (self.panelD)
lc.height.AsIs ()
lc.width.AsIs ()
b.SetConstraints(lc);
- lc = wxLayoutConstraints()
- lc.bottom.PercentOf (self.panelC, wxHeight, 50)
- lc.right.PercentOf (self.panelC, wxWidth, 50)
- lc.height.SameAs (b, wxHeight)
- lc.width.SameAs (b, wxWidth)
+ lc = wx.LayoutConstraints()
+ lc.bottom.PercentOf (self.panelC, wx.Height, 50)
+ lc.right.PercentOf (self.panelC, wx.Width, 50)
+ lc.height.SameAs (b, wx.Height)
+ lc.width.SameAs (b, wx.Width)
self.panelD.SetConstraints(lc);
-
-
def OnButton(self, event):
- wxBell()
+ wx.Bell()
#---------------------------------------------------------------------------
-
-
-
-
-
-
-
-
-
-
-
-
-overview = """\<html><body>
+overview = """\
+<html><body>
Objects of this class can be associated with a window to define its
layout constraints, with respect to siblings or its parent.
-The class consists of the following eight constraints of class
+<p>The class consists of the following eight constraints of class
wxIndividualLayoutConstraint, some or all of which should be accessed
directly to set the appropriate constraints.
-left: represents the left hand edge of the window
-
-right: represents the right hand edge of the window
+<p><ul>
+<li>left: represents the left hand edge of the window
-top: represents the top edge of the window
+<li>right: represents the right hand edge of the window
-bottom: represents the bottom edge of the window
+<li>top: represents the top edge of the window
-width: represents the width of the window
+<li>bottom: represents the bottom edge of the window
-height: represents the height of the window
+<li>width: represents the width of the window
-centreX: represents the horizontal centre point of the window
+<li>height: represents the height of the window
-centreY: represents the vertical centre point of the window
+<li>centreX: represents the horizontal centre point of the window
-Most constraints are initially set to have the relationship
+<li>centreY: represents the vertical centre point of the window
+</ul>
+<p>Most constraints are initially set to have the relationship
wxUnconstrained, which means that their values should be calculated by
looking at known constraints. The exceptions are width and height,
which are set to wxAsIs to ensure that if the user does not specify a
+# 11/20/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
+import wx
#---------------------------------------------------------------------------
-class wxFindPrefixListBox(wxListBox):
- def __init__(self, parent, id, pos=wxDefaultPosition, size=wxDefaultSize,
- choices=[], style=0, validator=wxDefaultValidator):
- wxListBox.__init__(self, parent, id, pos, size, choices, style, validator)
+# This listbox subclass lets you type the starting letters of what you want to
+# select, and scrolls the list to the match if it is found.
+class FindPrefixListBox(wx.ListBox):
+ def __init__(self, parent, id, pos=wx.DefaultPosition, size=wx.DefaultSize,
+ choices=[], style=0, validator=wx.DefaultValidator):
+ wx.ListBox.__init__(self, parent, id, pos, size, choices, style, validator)
self.typedText = ''
self.log = parent.log
- EVT_KEY_DOWN(self, self.OnKey)
+ self.Bind(wx.EVT_KEY_DOWN, self.OnKey)
def FindPrefix(self, prefix):
self.log.WriteText('Looking for prefix: %s\n' % prefix)
+
if prefix:
prefix = prefix.lower()
length = len(prefix)
- for x in range(self.Number()):
+
+ # Changed in 2.5 because ListBox.Number() is no longer supported.
+ # ListBox.GetCount() is now the appropriate way to go.
+ for x in range(self.GetCount()):
text = self.GetString(x)
text = text.lower()
+
if text[:length] == prefix:
self.log.WriteText('Prefix %s is found.\n' % prefix)
return x
+
self.log.WriteText('Prefix %s is not found.\n' % prefix)
return -1
def OnKey(self, evt):
key = evt.GetKeyCode()
+
if key >= 32 and key <= 127:
self.typedText = self.typedText + chr(key)
item = self.FindPrefix(self.typedText)
+
if item != -1:
self.SetSelection(item)
- elif key == WXK_BACK: # backspace removes one character and backs up
+ elif key == wx.WXK_BACK: # backspace removes one character and backs up
self.typedText = self.typedText[:-1]
+
if not self.typedText:
self.SetSelection(0)
else:
item = self.FindPrefix(self.typedText)
+
if item != -1:
self.SetSelection(item)
-
else:
self.typedText = ''
evt.Skip()
#---------------------------------------------------------------------------
-class TestListBox(wxPanel):
+class TestListBox(wx.Panel):
def __init__(self, parent, log):
self.log = log
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
'six', 'seven', 'eight', 'nine', 'ten', 'eleven',
'twelve', 'thirteen', 'fourteen']
- wxStaticText(self, -1, "This example uses the wxListBox control.",
- wxPoint(45, 10))
-
- wxStaticText(self, -1, "Select one:", wxPoint(15, 50), wxSize(65, 18))
- self.lb1 = wxListBox(self, 60, wxPoint(80, 50), wxSize(80, 120),
- sampleList, wxLB_SINGLE)
- EVT_LISTBOX(self, 60, self.EvtListBox)
- EVT_LISTBOX_DCLICK(self, 60, self.EvtListBoxDClick)
- EVT_RIGHT_UP(self.lb1, self.EvtRightButton)
+ wx.StaticText(self, -1, "This example uses the wxListBox control.", (45, 10))
+ wx.StaticText(self, -1, "Select one:", (15, 50), (65, 18))
+ self.lb1 = wx.ListBox(self, 60, (80, 50), (80, 120), sampleList, wx.LB_SINGLE)
+ self.Bind(wx.EVT_LISTBOX, self.EvtListBox, self.lb1)
+ self.Bind(wx.EVT_LISTBOX_DCLICK, self.EvtListBoxDClick, self.lb1)
+ self.lb1.Bind(wx.EVT_RIGHT_UP, self.EvtRightButton)
self.lb1.SetSelection(3)
self.lb1.Append("with data", "This one has data");
self.lb1.SetClientData(2, "This one has data");
- wxStaticText(self, -1, "Select many:", wxPoint(200, 50), wxSize(65, 18))
- self.lb2 = wxListBox(self, 70, wxPoint(280, 50), wxSize(80, 120),
- sampleList, wxLB_EXTENDED)
- EVT_LISTBOX(self, 70, self.EvtMultiListBox)
- EVT_RIGHT_UP(self.lb2, self.EvtRightButton)
+ wx.StaticText(self, -1, "Select many:", (200, 50), (65, 18))
+ self.lb2 = wx.ListBox(self, 70, (280, 50), (80, 120), sampleList, wx.LB_EXTENDED)
+ self.Bind(wx.EVT_LISTBOX, self.EvtMultiListBox, self.lb2)
+ self.lb2.Bind(wx.EVT_RIGHT_UP, self.EvtRightButton)
self.lb2.SetSelection(0)
-
sampleList = sampleList + ['test a', 'test aa', 'test aab',
'test ab', 'test abc', 'test abcc',
'test abcd' ]
sampleList.sort()
- wxStaticText(self, -1, "Find Prefix:", wxPoint(15, 250))
- fp = wxFindPrefixListBox(self, -1, wxPoint(80, 250), wxSize(80, 120),
- sampleList, wxLB_SINGLE)
+ wx.StaticText(self, -1, "Find Prefix:", (15, 250))
+ fp = FindPrefixListBox(self, -1, (80, 250), (80, 120), sampleList, wx.LB_SINGLE)
fp.SetSelection(0)
lb = event.GetEventObject()
data = lb.GetClientData(lb.GetSelection())
+
if data is not None:
self.log.WriteText('\tdata: %s\n' % data)
def EvtRightButton(self, event):
self.log.WriteText('EvtRightButton: %s\n' % event.GetPosition())
+
if event.GetEventObject().GetId() == 70:
selections = list(self.lb2.GetSelections())
selections.reverse()
+
for index in selections:
self.lb2.Delete(index)
-
-
-
overview = """<html><body>
A listbox is used to select one or more of a list of
strings. The strings are displayed in a scrolling box, with the
# Copyright: (c) 1998 by Total Control Software
# Licence: wxWindows license
#----------------------------------------------------------------------------
+#
+# 11/20/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+# 11/29/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o listctrl mixin needs wx renamer.
+# o wx.ListItem.GetText() returns a wxString pointer, not the text.
+#
+
+import wx
+import wx.lib.mixins.listctrl as listmix
-from wxPython.wx import *
-from wxPython.lib.mixins.listctrl import wxColumnSorterMixin, wxListCtrlAutoWidthMixin
+import images
#---------------------------------------------------------------------------
54: ("David Lanz", "Leaves on the Seine", "New Age"),
}
-import images
-
-
-class TestListCtrl(wxListCtrl, wxListCtrlAutoWidthMixin):
- def __init__(self, parent, ID, pos=wxDefaultPosition,
- size=wxDefaultSize, style=0):
- wxListCtrl.__init__(self, parent, ID, pos, size, style)
- wxListCtrlAutoWidthMixin.__init__(self)
+#---------------------------------------------------------------------------
+class TestListCtrl(wx.ListCtrl, listmix.wxListCtrlAutoWidthMixin):
+ def __init__(self, parent, ID, pos=wx.DefaultPosition,
+ size=wx.DefaultSize, style=0):
+ wx.ListCtrl.__init__(self, parent, ID, pos, size, style)
+ listmix.wxListCtrlAutoWidthMixin.__init__(self)
-class TestListCtrlPanel(wxPanel, wxColumnSorterMixin):
+class TestListCtrlPanel(wx.Panel, listmix.wxColumnSorterMixin):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1, style=wxWANTS_CHARS)
+ wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS)
self.log = log
- tID = wxNewId()
+ tID = wx.NewId()
- self.il = wxImageList(16, 16)
+ self.il = wx.ImageList(16, 16)
self.idx1 = self.il.Add(images.getSmilesBitmap())
self.sm_up = self.il.Add(images.getSmallUpArrowBitmap())
self.sm_dn = self.il.Add(images.getSmallDnArrowBitmap())
self.list = TestListCtrl(self, tID,
- style=wxLC_REPORT | wxSUNKEN_BORDER
- | wxLC_EDIT_LABELS
+ style=wx.LC_REPORT
+ | wx.SUNKEN_BORDER
+ | wx.LC_EDIT_LABELS
#| wxLC_NO_HEADER
#| wxLC_VRULES | wxLC_HRULES
)
- self.list.SetImageList(self.il, wxIMAGE_LIST_SMALL)
+
+ self.list.SetImageList(self.il, wx.IMAGE_LIST_SMALL)
self.PopulateList()
# Now that the list exists we can init the other base class,
# see wxPython/lib/mixins/listctrl.py
self.itemDataMap = musicdata
- wxColumnSorterMixin.__init__(self, 3)
+ listmix.wxColumnSorterMixin.__init__(self, 3)
#self.SortListItems(0, True)
- EVT_SIZE(self, self.OnSize)
- EVT_LIST_ITEM_SELECTED(self, tID, self.OnItemSelected)
- EVT_LIST_ITEM_DESELECTED(self, tID, self.OnItemDeselected)
- EVT_LIST_ITEM_ACTIVATED(self, tID, self.OnItemActivated)
- EVT_LIST_DELETE_ITEM(self, tID, self.OnItemDelete)
- EVT_LIST_COL_CLICK(self, tID, self.OnColClick)
- EVT_LIST_COL_RIGHT_CLICK(self, tID, self.OnColRightClick)
- EVT_LIST_COL_BEGIN_DRAG(self, tID, self.OnColBeginDrag)
- EVT_LIST_COL_DRAGGING(self, tID, self.OnColDragging)
- EVT_LIST_COL_END_DRAG(self, tID, self.OnColEndDrag)
- EVT_LIST_BEGIN_LABEL_EDIT(self, tID, self.OnBeginEdit)
-
- EVT_LEFT_DCLICK(self.list, self.OnDoubleClick)
- EVT_RIGHT_DOWN(self.list, self.OnRightDown)
+ self.Bind(wx.EVT_SIZE, self.OnSize)
+
+ self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.list)
+ self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemDeselected, self.list)
+ self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated, self.list)
+ self.Bind(wx.EVT_LIST_DELETE_ITEM, self.OnItemDelete, self.list)
+ self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick, self.list)
+ self.Bind(wx.EVT_LIST_COL_RIGHT_CLICK, self.OnColRightClick, self.list)
+ self.Bind(wx.EVT_LIST_COL_BEGIN_DRAG, self.OnColBeginDrag, self.list)
+ self.Bind(wx.EVT_LIST_COL_DRAGGING, self.OnColDragging, self.list)
+ self.Bind(wx.EVT_LIST_COL_END_DRAG, self.OnColEndDrag, self.list)
+ self.Bind(wx.EVT_LIST_BEGIN_LABEL_EDIT, self.OnBeginEdit, self.list)
+
+ self.list.Bind(wx.EVT_LEFT_DCLICK, self.OnDoubleClick)
+ self.list.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
# for wxMSW
- EVT_COMMAND_RIGHT_CLICK(self.list, tID, self.OnRightClick)
+ self.list.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightClick)
# for wxGTK
- EVT_RIGHT_UP(self.list, self.OnRightClick)
+ self.list.Bind(wx.EVT_RIGHT_UP, self.OnRightClick)
def PopulateList(self):
if 0:
# for normal, simple columns, you can add them like this:
self.list.InsertColumn(0, "Artist")
- self.list.InsertColumn(1, "Title", wxLIST_FORMAT_RIGHT)
+ self.list.InsertColumn(1, "Title", wx.LIST_FORMAT_RIGHT)
self.list.InsertColumn(2, "Genre")
else:
# but since we want images on the column header we have to do it the hard way:
- info = wxListItem()
- info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE | wxLIST_MASK_FORMAT
+ info = wx.ListItem()
+ info.m_mask = wx.LIST_MASK_TEXT | wx.LIST_MASK_IMAGE | wx.LIST_MASK_FORMAT
info.m_image = -1
info.m_format = 0
info.m_text = "Artist"
self.list.InsertColumnInfo(0, info)
- info.m_format = wxLIST_FORMAT_RIGHT
+ info.m_format = wx.LIST_FORMAT_RIGHT
info.m_text = "Title"
self.list.InsertColumnInfo(1, info)
self.list.SetStringItem(x, 2, data[2])
self.list.SetItemData(x, key)
- self.list.SetColumnWidth(0, wxLIST_AUTOSIZE)
- self.list.SetColumnWidth(1, wxLIST_AUTOSIZE)
+ self.list.SetColumnWidth(0, wx.LIST_AUTOSIZE)
+ self.list.SetColumnWidth(1, wx.LIST_AUTOSIZE)
self.list.SetColumnWidth(2, 100)
# show how to select an item
- self.list.SetItemState(5, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED)
+ self.list.SetItemState(5, wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED)
# show how to change the colour of a couple items
item = self.list.GetItem(1)
- item.SetTextColour(wxBLUE)
+ item.SetTextColour(wx.BLUE)
self.list.SetItem(item)
item = self.list.GetItem(4)
- item.SetTextColour(wxRED)
+ item.SetTextColour(wx.RED)
self.list.SetItem(item)
self.currentItem = 0
self.y = event.GetY()
self.log.WriteText("x, y = %s\n" % str((self.x, self.y)))
item, flags = self.list.HitTest((self.x, self.y))
- if flags & wxLIST_HITTEST_ONITEM:
+
+ if flags & wx.LIST_HITTEST_ONITEM:
self.list.Select(item)
+
event.Skip()
self.list.GetItemText(self.currentItem),
self.getColumnText(self.currentItem, 1),
self.getColumnText(self.currentItem, 2)))
+
if self.currentItem == 10:
self.log.WriteText("OnItemSelected: Veto'd selection\n")
#event.Veto() # doesn't work
# this does
- self.list.SetItemState(10, 0, wxLIST_STATE_SELECTED)
+ self.list.SetItemState(10, 0, wx.LIST_STATE_SELECTED)
+
event.Skip()
# Show how to reselect something we don't want deselected
if evt.m_itemIndex == 11:
- wxCallAfter(self.list.SetItemState, 11, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED)
+ wx.CallAfter(self.list.SetItemState, 11, wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED)
def OnItemActivated(self, event):
# only do this part the first time so the events are only bound once
if not hasattr(self, "popupID1"):
- self.popupID1 = wxNewId()
- self.popupID2 = wxNewId()
- self.popupID3 = wxNewId()
- self.popupID4 = wxNewId()
- self.popupID5 = wxNewId()
- self.popupID6 = wxNewId()
- EVT_MENU(self, self.popupID1, self.OnPopupOne)
- EVT_MENU(self, self.popupID2, self.OnPopupTwo)
- EVT_MENU(self, self.popupID3, self.OnPopupThree)
- EVT_MENU(self, self.popupID4, self.OnPopupFour)
- EVT_MENU(self, self.popupID5, self.OnPopupFive)
- EVT_MENU(self, self.popupID6, self.OnPopupSix)
+ self.popupID1 = wx.NewId()
+ self.popupID2 = wx.NewId()
+ self.popupID3 = wx.NewId()
+ self.popupID4 = wx.NewId()
+ self.popupID5 = wx.NewId()
+ self.popupID6 = wx.NewId()
+
+ self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1)
+ self.Bind(wx.EVT_MENU, self.OnPopupTwo, id=self.popupID2)
+ self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
+ self.Bind(wx.EVT_MENU, self.OnPopupFour, id=self.popupID4)
+ self.Bind(wx.EVT_MENU, self.OnPopupFive, id=self.popupID5)
+ self.Bind(wx.EVT_MENU, self.OnPopupSix, id=self.popupID6)
# make a menu
- menu = wxMenu()
+ menu = wx.Menu()
# add some items
menu.Append(self.popupID1, "FindItem tests")
menu.Append(self.popupID2, "Iterate Selected")
# Popup the menu. If an item is selected then its handler
# will be called before PopupMenu returns.
- self.PopupMenu(menu, wxPoint(self.x, self.y))
+ self.PopupMenu(menu, (self.x, self.y))
menu.Destroy()
def OnPopupTwo(self, event):
self.log.WriteText("Selected items:\n")
index = self.list.GetFirstSelected()
+
while index != -1:
self.log.WriteText(" %s: %s\n" % (self.list.GetItemText(index), self.getColumnText(index, 1)))
index = self.list.GetNextSelected(index)
-
def OnPopupThree(self, event):
self.log.WriteText("Popup three\n")
self.list.ClearAll()
- wxCallAfter(self.PopulateList)
+ wx.CallAfter(self.PopulateList)
def OnPopupFour(self, event):
self.list.DeleteAllItems()
-
-
-
#---------------------------------------------------------------------------
def runTest(frame, nb, log):
#---------------------------------------------------------------------------
+overview = """\
+<html>
+<body>
+A list control presents lists in a number of formats: list view, report view,
+icon view and small icon view. In any case, elements are numbered from zero.
+For all these modes (but not for virtual list controls), the items are stored
+in the control and must be added to it using InsertItem method.
+<p>To intercept events from a list control, use the event table macros described in
+<code>wxListEvent.</code>
-overview = """\
-A list control presents lists in a number of formats: list view, report view, icon view and small icon view. Elements are numbered from zero.
+<h3>Mix-ins</h3>
+This example demonstrates how to use mixins. The following mixins are available.
-"""
+<h4>ColumnSorterMixin</h4>
+
+<code><b>ColumnSorterMixin(numColumns)</b></code>
+
+<p>A mixin class that handles sorting of a wxListCtrl in REPORT mode when the column
+header is clicked on.
+
+<p>There are a few requirments needed in order for this to work genericly:
+<p><ol>
+ <li>The combined class must have a <code>GetListCtrl</code> method that returns
+ the ListCtrl to be sorted, and the list control must exist at the time the
+ <code>ColumnSorterMixin.__init__()</code>method is called because it uses
+ <code>GetListCtrl</code>.
+
+ <li>Items in the list control must have a unique data value set with
+ <code>list.SetItemData</code>.
+
+ <li>The combined class must have an attribute named <code>itemDataMap</code>
+ that is a dictionary mapping the data values to a sequence of objects
+ representing the values in each column. These valuesare compared in
+ the column sorter to determine sort order.
+</ol>
+
+<p>Interesting methods to override are <code>GetColumnSorter</code>,
+<code>GetSecondarySortValues</code>, and <code>GetSortImages</code>.
+<h5>Methods</h5>
+<dl>
+<dt><code>SetColumnCount(newNumColumns)</code>
+<dd>Informs the mixin as to the number of columns in the control. When it is
+set, it also sets up an event handler for <code>EVT_LIST_COL_CLICK</code> events.
+<dt><code>SortListItems(col=-1, ascending=1)</code>
+<dd>Sort the list on demand. Can also be used to set the sort column and order.
+<dt><code>GetColumnWidths()</code>
+<dd>Returns a list of column widths. Can be used to help restore the current
+view later.
+
+<dt><code>GetSortImages()</code>
+<dd>Returns a tuple of image list indexes the indexes in the image list for an
+image to be put on the column header when sorting in descending order
+
+<dt><code>GetColumnSorter()</code>
+<dd>Returns a callable object to be used for comparing column values when sorting.
+
+<dt><code>GetSecondarySortValues(col, key1, key2)</code>
+<dd>Returns a tuple of 2 values to use for secondary sort values when the
+items in the selected column match equal. The default just returns the
+item data values.
+
+</dl>
+
+<h4>ListCtrlAutoWidthMixin</h4>
+
+<code><b>wxListCtrlAutoWidthMixin()</b></code>
+
+<p>A mix-in class that automatically resizes the last column to take up the
+remaining width of the ListCtrl.
+
+<p>This causes the ListCtrl to automatically take up the full width of the list,
+without either a horizontal scroll bar (unless absolutely necessary) or empty
+space to the right of the last column.
+
+<p><b>NOTE:</b> This only works for report-style lists.
+
+<p><b>WARNING:</b> If you override the <code>EVT_SIZE</code> event in your ListCtrl,
+make sure you call event.Skip() to ensure that the mixin's _OnResize method is
+called.
+
+<p>This mix-in class was written by <a href='mailto:ewestra@wave.co.nz'>Erik Westra </a>
+
+<h5>Methods</h5>
+<dl>
+
+<dt><code>resizeLastColumn(minWidth)</code>
+<dd>Resize the last column appropriately. If the list's columns are too wide to
+fit within the window, we use a horizontal scrollbar. Otherwise, we expand the
+right-most column to take up the remaining free space in the list. This method is
+called automatically when the ListCtrl is resized; you can also call it yourself
+whenever you want the last column to be resized appropriately (eg, when adding,
+removing or resizing columns). 'minWidth' is the preferred minimum width for
+the last column.
+
+</dl>
+
+
+<h4>ListCtrlSelectionManagerMix</h4>
+
+<code><b>ListCtrlSelectionManagerMix()</b></code>
+
+<p>Mixin that defines a platform independent selection policy
+
+<p>As selection single and multi-select list return the item index or a
+list of item indexes respectively.
+
+<h5>Methods</h5>
+<dl>
+
+<dt><code>getPopupMenu()</code>
+<dd>Override to implement dynamic menus (create)
+
+<dt><code>setPopupMenu(menu)</code>
+<dd>Must be set for default behaviour.
+
+<dt><code>afterPopupMenu()</code>
+<dd>Override to implement dynamic menus (destroy).
+
+<dt><code>getSelection()</code>
+<dd>Returns the current selection (or selections as a Python list if extended
+selection is enabled)
+
+
+</body>
+</html>
+"""
if __name__ == '__main__':
-
-from wxPython.wx import *
-import images
+# 11/20/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+# 11/29/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o wx.ListItem.GetText() returns a wxString pointer, not the text.
+#
+
+import wx
+import images
#----------------------------------------------------------------------
-class TestVirtualList(wxListCtrl):
+class TestVirtualList(wx.ListCtrl):
def __init__(self, parent, log):
- wxListCtrl.__init__(self, parent, -1,
- style=wxLC_REPORT|wxLC_VIRTUAL|wxLC_HRULES|wxLC_VRULES)
+ wx.ListCtrl.__init__(
+ self, parent, -1,
+ style=wx.LC_REPORT|wx.LC_VIRTUAL|wx.LC_HRULES|wx.LC_VRULES
+ )
+
self.log = log
- self.il = wxImageList(16, 16)
+ self.il = wx.ImageList(16, 16)
self.idx1 = self.il.Add(images.getSmilesBitmap())
- self.SetImageList(self.il, wxIMAGE_LIST_SMALL)
+ self.SetImageList(self.il, wx.IMAGE_LIST_SMALL)
self.InsertColumn(0, "First")
self.SetItemCount(1000000)
- self.attr1 = wxListItemAttr()
+ self.attr1 = wx.ListItemAttr()
self.attr1.SetBackgroundColour("yellow")
- self.attr2 = wxListItemAttr()
+ self.attr2 = wx.ListItemAttr()
self.attr2.SetBackgroundColour("light blue")
- EVT_LIST_ITEM_SELECTED(self, self.GetId(), self.OnItemSelected)
- EVT_LIST_ITEM_ACTIVATED(self, self.GetId(), self.OnItemActivated)
- EVT_LIST_ITEM_DESELECTED(self, self.GetId(), self.OnItemDeselected)
+ self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected)
+ self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated)
+ self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemDeselected)
def OnItemSelected(self, event):
#----------------------------------------------------------------------
-
-
-
overview = """\
+This example demonstrates the ListCtrl's Virtual List features. A Virtual list
+can contain any number of cells, but data is not loaded into the control itself.
+It is loaded on demand via virtual methods <code>OnGetItemText(), OnGetItemImage()</code>,
+and <code>OnGetItemAttr()</code>. This greatly reduces the amount of memory required
+without limiting what can be done with the list control itself.
"""
+# 11/22/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+# 11/29/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Bunches of imports that might need to go away for the final roll-out.
+#
-from wxPython.wx import *
+import sys
-import ColorPanel
-import GridSimple
-import wxListCtrl
-import wxScrolledWindow
-import images
+import wx
colourList = [ "Aquamarine", "Black", "Blue", "Blue Violet", "Brown", "Cadet Blue",
"Coral", "Cornflower Blue", "Cyan", "Dark Grey", "Dark Green",
#----------------------------------------------------------------------------
-class TestLB(wxListbook):
+class TestLB(wx.Listbook):
def __init__(self, parent, id, log):
- wxListbook.__init__(self, parent, id, style=
- wxLB_DEFAULT
+ wx.Listbook.__init__(self, parent, id, style=
+ wx.LB_DEFAULT
#wxLB_TOP
#wxLB_BOTTOM
#wxLB_LEFT
bmp = f()
il.Add(bmp)
self.AssignImageList(il)
-
# Now make a bunch of panels for the list book
first = True
def makeColorPanel(self, color):
- p = wxPanel(self, -1)
+ p = wx.Panel(self, -1)
win = ColorPanel.ColoredPanel(p, color)
p.win = win
def OnCPSize(evt, win=win):
win.SetSize(evt.GetSize())
- EVT_SIZE(p, OnCPSize)
+ p.Bind(wx.EVT_SIZE, OnCPSize)
return p
#----------------------------------------------------------------------------
-
-
overview = """\
<html><body>
<h2>wxListbook</h2>
run.main(['', os.path.basename(sys.argv[0])])
-
-
-
+# 11/12/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
+import wx
+
+import MDIDemo
+import MDISashDemo
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
self.log = log
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
- b1 = wxButton(self, -1, "MDI demo")
- EVT_BUTTON(self, b1.GetId(), self.ShowMDIDemo)
+ b1 = wx.Button(self, -1, "MDI demo")
+ self.Bind(wx.EVT_BUTTON, self.ShowMDIDemo, b1)
- b2 = wxButton(self, -1, "MDI with SashWindows demo")
- EVT_BUTTON(self, b2.GetId(), self.ShowMDISashDemo)
+ b2 = wx.Button(self, -1, "MDI with SashWindows demo")
+ self.Bind(wx.EVT_BUTTON, self.ShowMDIDemo, b2)
- box = wxBoxSizer(wxVERTICAL)
+ box = wx.BoxSizer(wx.VERTICAL)
box.Add((20, 30))
- box.Add(b1, 0, wxALIGN_CENTER|wxALL, 15)
- box.Add(b2, 0, wxALIGN_CENTER|wxALL, 15)
+ box.Add(b1, 0, wx.ALIGN_CENTER|wx.ALL, 15)
+ box.Add(b2, 0, wx.ALIGN_CENTER|wx.ALL, 15)
self.SetAutoLayout(True)
self.SetSizer(box)
def ShowMDIDemo(self, evt):
- import MDIDemo
frame = MDIDemo.MyParentFrame()
frame.Show()
def ShowMDISashDemo(self, evt):
- import MDISashDemo
frame = MDISashDemo.MyParentFrame()
frame.Show()
<h2><center>Multiple Document Interface</center></h2>
Although Microsoft has deprecated the MDI model, wxWindows still supports
-it. Here are a couple samples of how to use it.
+it. Here are a couple samples of how to use it - one straightforward, the other
+showing how the MDI interface can be integrated into a SashWindow interface.
</body></html>
"""
-
-
-
if __name__ == '__main__':
import sys,os
import run
+# 11/20/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+# 11/30/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Library must be updated for this to run.
+#
-import sys, os
-from wxPython.wx import *
-from wxPython.lib.mvctree import *
+import os
+import sys
+import wx
+import wx.lib.mvctree as tree
logger = None
def selchanging(evt):
logger.write("Delete\n")
def runTest(frame, nb, log):
- #f = wxFrame(frame, -1, "wxMVCTree", wxPoint(0,0), wxSize(200,500))
+ #f = wx.Frame(frame, -1, "wxMVCTree", (0,0), (200,500))
global logger
logger = log
- p = wxMVCTree(nb, -1)
- #f = wxFrame(frame, -1, "wxMVCTree")
- #p = wxMVCTree(f, -1)
+ p = tree.wxMVCTree(nb, -1)
+ #f = wx.Frame(frame, -1, "wxMVCTree")
+ #p = tree.wxMVCTree(f, -1)
p.SetAssumeChildren(True)
- p.SetModel(LateFSTreeModel(os.path.normpath(os.getcwd() + os.sep +'..')))
+ p.SetModel(tree.LateFSTreeModel(os.path.normpath(os.getcwd() + os.sep +'..')))
+
#Uncomment this to enable live filename editing!
# p.AddEditor(FileEditor(p))
+
p.SetMultiSelect(True)
- EVT_MVCTREE_SEL_CHANGING(p, p.GetId(), selchanging)
- EVT_MVCTREE_SEL_CHANGED(p, p.GetId(), selchanged)
- EVT_MVCTREE_ITEM_EXPANDED(p, p.GetId(), expanded)
- EVT_MVCTREE_ITEM_COLLAPSED(p, p.GetId(), closed)
- EVT_MVCTREE_ADD_ITEM(p, p.GetId(), add)
- EVT_MVCTREE_DELETE_ITEM(p, p.GetId(), delitem)
- EVT_MVCTREE_KEY_DOWN(p, p.GetId(), key)
+ tree.EVT_MVCTREE_SEL_CHANGING(p, p.GetId(), selchanging)
+ tree.EVT_MVCTREE_SEL_CHANGED(p, p.GetId(), selchanged)
+ tree.EVT_MVCTREE_ITEM_EXPANDED(p, p.GetId(), expanded)
+ tree.EVT_MVCTREE_ITEM_COLLAPSED(p, p.GetId(), closed)
+ tree.EVT_MVCTREE_ADD_ITEM(p, p.GetId(), add)
+ tree.EVT_MVCTREE_DELETE_ITEM(p, p.GetId(), delitem)
+ tree.EVT_MVCTREE_KEY_DOWN(p, p.GetId(), key)
return p
#frame.otherWin = f
#return None
-
-
overview = """\
wxMVCTree is a control which handles hierarchical data. It is
"""
-
-
-
if __name__ == '__main__':
import sys,os
import run
+# 11/20/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
+import wx
#----------------------------------------------------------------------
logicList = [
- ('wxAND', wxAND),
- ('wxAND_INVERT', wxAND_INVERT),
- ('wxAND_REVERSE', wxAND_REVERSE),
- ('wxCLEAR', wxCLEAR),
- ('wxCOPY', wxCOPY),
- ('wxEQUIV', wxEQUIV),
- ('wxINVERT', wxINVERT),
- ('wxNAND', wxNAND),
+ ('wx.AND', wx.AND),
+ ('wx.AND_INVERT', wx.AND_INVERT),
+ ('wx.AND_REVERSE', wx.AND_REVERSE),
+ ('wx.CLEAR', wx.CLEAR),
+ ('wx.COPY', wx.COPY),
+ ('wx.EQUIV', wx.EQUIV),
+ ('wx.INVERT', wx.INVERT),
+ ('wx.NAND', wx.NAND),
# this one causes an assert on wxGTK, and doesn't seem to
# do much on MSW anyway, so I'll just take it out....
#('wxNOR', wxNOR),
- ('wxNO_OP', wxNO_OP),
- ('wxOR', wxOR),
- ('wxOR_INVERT', wxOR_INVERT),
- ('wxOR_REVERSE', wxOR_REVERSE),
- ('wxSET', wxSET),
- ('wxSRC_INVERT', wxSRC_INVERT),
- ('wxXOR', wxXOR),
+ ('wx.NO_OP', wx.NO_OP),
+ ('wx.OR', wx.OR),
+ ('wx.OR_INVERT', wx.OR_INVERT),
+ ('wx.OR_REVERSE', wx.OR_REVERSE),
+ ('wx.SET', wx.SET),
+ ('wx.SRC_INVERT', wx.SRC_INVERT),
+ ('wx.XOR', wx.XOR),
]
import images
-class TestMaskWindow(wxScrolledWindow):
+class TestMaskWindow(wx.ScrolledWindow):
def __init__(self, parent):
- wxScrolledWindow.__init__(self, parent, -1)
- self.SetBackgroundColour(wxColour(0,128,0))
+ wx.ScrolledWindow.__init__(self, parent, -1)
+ self.SetBackgroundColour(wx.Colour(0,128,0))
# A reference bitmap that we won't mask
self.bmp_nomask = images.getTestStar2Bitmap()
self.bmp_withmask = images.getTestStar2Bitmap()
# this mask comes from a monochrome bitmap
- self.bmp_themask = wxBitmapFromImage(images.getTestMaskImage(), 1)
- mask = wxMask(self.bmp_themask)
+ self.bmp_themask = wx.BitmapFromImage(images.getTestMaskImage(), 1)
+ mask = wx.Mask(self.bmp_themask)
# set the mask on our bitmap
self.bmp_withmask.SetMask(mask)
# Now we'll create a mask in a bit of an easier way, by picking a
# colour in the image that is to be the transparent colour.
self.bmp_withcolourmask = images.getTestStar2Bitmap()
- mask = wxMaskColour(self.bmp_withcolourmask, wxWHITE)
+ mask = wx.MaskColour(self.bmp_withcolourmask, wx.WHITE)
self.bmp_withcolourmask.SetMask(mask)
self.SetScrollbars(20, 20, 700/20, 460/20)
- EVT_PAINT(self, self.OnPaint)
+ self.Bind(wx.EVT_PAINT, self.OnPaint)
def OnPaint (self, e):
- dc = wxPaintDC(self)
+ dc = wx.PaintDC(self)
self.PrepareDC(dc)
- dc.SetTextForeground(wxWHITE)
+ dc.SetTextForeground(wx.WHITE)
# make an interesting background...
- dc.SetPen(wxMEDIUM_GREY_PEN)
+ dc.SetPen(wx.MEDIUM_GREY_PEN)
for i in range(100):
dc.DrawLine((0,i*10), (i*10,0))
cx,cy = self.bmp_themask.GetWidth(), self.bmp_themask.GetHeight()
# draw array of assorted blit operations
- mdc = wxMemoryDC()
+ mdc = wx.MemoryDC()
i = 0
+
for text, code in logicList:
x,y = 120+150*(i%4), 20+100*(i/4)
dc.DrawText(text, (x, y-20))
# On wxGTK there needs to be a panel under wxScrolledWindows if they are
# going to be in a wxNotebook...
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, ID):
- wxPanel.__init__(self, parent, ID)
+ wx.Panel.__init__(self, parent, ID)
self.win = TestMaskWindow(self)
- EVT_SIZE(self, self.OnSize)
+ self.Bind(wx.EVT_SIZE, self.OnSize)
def OnSize(self, evt):
self.win.SetSize(evt.GetSize())
#----------------------------------------------------------------------
-
overview = """\
+This class encapsulates a monochrome mask bitmap, where the masked area is black
+and the unmasked area is white. When associated with a bitmap and drawn in a device
+context, the unmasked area of the bitmap will be drawn, and the masked area will
+not be drawn.
+
+This example shows not only how to create a Mask, but the effects of the Device
+Context (dc) <code>Blit()</code> method's logic codes.
"""
-from wxPython.wx import *
-from wxPython.lib.maskednumctrl import wxMaskedNumCtrl, EVT_MASKEDNUM
-from wxPython.lib.maskednumctrl import __doc__ as overviewdoc
-from wxPython.lib.maskededit import wxMaskedTextCtrl
-import string, sys, traceback
+# 11/20/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+# 11/29/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o wx.lib.maskednumctrl needs hit up with the renamer and new binders
+#
+
+import string
+import sys
+import traceback
+
+import wx
+import wx.lib.maskednumctrl as mnum
#----------------------------------------------------------------------
-class TestPanel( wxPanel ):
+class TestPanel( wx.Panel ):
def __init__( self, parent, log ):
- wxPanel.__init__( self, parent, -1 )
+ wx.Panel.__init__( self, parent, -1 )
self.log = log
- panel = wxPanel( self, -1 )
+ panel = wx.Panel( self, -1 )
- header = wxStaticText(panel, -1, """\
+ header = wx.StaticText(panel, -1, """\
This shows the various options for wxMaskedNumCtrl.
The controls at the top reconfigure the resulting control at the bottom.
""")
header.SetForegroundColour( "Blue" )
- intlabel = wxStaticText( panel, -1, "Integer width:" )
- self.integerwidth = wxMaskedNumCtrl(
- panel, value=10,
- integerWidth=2,
- allowNegative=False)
-
- fraclabel = wxStaticText( panel, -1, "Fraction width:" )
- self.fractionwidth = wxMaskedNumCtrl(
- panel, value=0,
- integerWidth=2,
- allowNegative=False )
-
- groupcharlabel = wxStaticText( panel,-1, "Grouping char:" )
- self.groupchar = wxMaskedTextCtrl( panel, -1,
- value=',',
- mask='&',
- excludeChars = '-()',
- formatcodes='F',
- emptyInvalid=True,
- validRequired=True)
-
- decimalcharlabel = wxStaticText( panel,-1, "Decimal char:" )
- self.decimalchar = wxMaskedTextCtrl( panel, -1,
- value='.',
- mask='&',
- excludeChars = '-()',
- formatcodes='F',
- emptyInvalid=True,
- validRequired=True)
-
- self.set_min = wxCheckBox( panel, -1, "Set minimum value:" )
- # Create this wxMaskedNumCtrl using factory, to show how:
- self.min = wxMaskedNumCtrl( panel, integerWidth=5, fractionWidth=2 )
+ intlabel = wx.StaticText( panel, -1, "Integer width:" )
+ self.integerwidth = mnum.wxMaskedNumCtrl(
+ panel, value=10, integerWidth=2, allowNegative=False
+ )
+
+ fraclabel = wx.StaticText( panel, -1, "Fraction width:" )
+ self.fractionwidth = mnum.wxMaskedNumCtrl(
+ panel, value=0, integerWidth=2, allowNegative=False
+ )
+
+ groupcharlabel = wx.StaticText( panel,-1, "Grouping char:" )
+ self.groupchar = mnum.wxMaskedTextCtrl(
+ panel, -1, value=',', mask='&', excludeChars = '-()',
+ formatcodes='F', emptyInvalid=True, validRequired=True
+ )
+
+ decimalcharlabel = wx.StaticText( panel,-1, "Decimal char:" )
+ self.decimalchar = mnum.wxMaskedTextCtrl(
+ panel, -1, value='.', mask='&', excludeChars = '-()',
+ formatcodes='F', emptyInvalid=True, validRequired=True
+ )
+
+ self.set_min = wx.CheckBox( panel, -1, "Set minimum value:" )
+ # Create this MaskedNumCtrl using factory, to show how:
+ self.min = mnum.wxMaskedNumCtrl( panel, integerWidth=5, fractionWidth=2 )
self.min.Enable( False )
- self.set_max = wxCheckBox( panel, -1, "Set maximum value:" )
- self.max = wxMaskedNumCtrl( panel, integerWidth=5, fractionWidth=2 )
+ self.set_max = wx.CheckBox( panel, -1, "Set maximum value:" )
+ self.max = mnum.wxMaskedNumCtrl( panel, integerWidth=5, fractionWidth=2 )
self.max.Enable( False )
- self.limit_target = wxCheckBox( panel, -1, "Limit control" )
- self.allow_none = wxCheckBox( panel, -1, "Allow empty control" )
- self.group_digits = wxCheckBox( panel, -1, "Group digits" )
+ self.limit_target = wx.CheckBox( panel, -1, "Limit control" )
+ self.allow_none = wx.CheckBox( panel, -1, "Allow empty control" )
+ self.group_digits = wx.CheckBox( panel, -1, "Group digits" )
self.group_digits.SetValue( True )
- self.allow_negative = wxCheckBox( panel, -1, "Allow negative values" )
+ self.allow_negative = wx.CheckBox( panel, -1, "Allow negative values" )
self.allow_negative.SetValue( True )
- self.use_parens = wxCheckBox( panel, -1, "Use parentheses" )
- self.select_on_entry = wxCheckBox( panel, -1, "Select on entry" )
+ self.use_parens = wx.CheckBox( panel, -1, "Use parentheses" )
+ self.select_on_entry = wx.CheckBox( panel, -1, "Select on entry" )
self.select_on_entry.SetValue( True )
- label = wxStaticText( panel, -1, "Resulting numeric control:" )
+ label = wx.StaticText( panel, -1, "Resulting numeric control:" )
font = label.GetFont()
- font.SetWeight(wxBOLD)
+ font.SetWeight(wx.BOLD)
label.SetFont(font)
- self.target_ctl = wxMaskedNumCtrl( panel, -1, name="target control" )
+ self.target_ctl = mnum.wxMaskedNumCtrl( panel, -1, name="target control" )
- label_numselect = wxStaticText( panel, -1, """\
+ label_numselect = wx.StaticText( panel, -1, """\
Programmatically set the above
value entry ctrl:""")
- self.numselect = wxComboBox(panel, -1, choices = [ '0', '111', '222.22', '-3', '54321.666666666', '-1353.978',
+ self.numselect = wx.ComboBox(panel, -1, choices = [ '0', '111', '222.22', '-3', '54321.666666666', '-1353.978',
'1234567', '-1234567', '123456789', '-123456789.1',
'1234567890.', '-9876543210.9' ])
- grid1 = wxFlexGridSizer( 0, 4, 0, 0 )
- grid1.Add( intlabel, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5)
- grid1.Add( self.integerwidth, 0, wxALIGN_LEFT|wxALL, 5 )
-
- grid1.Add( groupcharlabel, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5)
- grid1.Add( self.groupchar, 0, wxALIGN_LEFT|wxALL, 5 )
-
- grid1.Add( fraclabel, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5 )
- grid1.Add( self.fractionwidth, 0, wxALIGN_LEFT|wxALL, 5 )
-
- grid1.Add( decimalcharlabel, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5)
- grid1.Add( self.decimalchar, 0, wxALIGN_LEFT|wxALL, 5 )
-
- grid1.Add( self.set_min, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5 )
- grid1.Add( self.min, 0, wxALIGN_LEFT|wxALL, 5 )
- grid1.Add( (5,5), 0, wxALIGN_LEFT|wxALL, 5)
- grid1.Add( (5,5), 0, wxALIGN_LEFT|wxALL, 5)
-
- grid1.Add( self.set_max, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5 )
- grid1.Add( self.max, 0, wxALIGN_LEFT|wxALL, 5 )
- grid1.Add( (5,5), 0, wxALIGN_LEFT|wxALL, 5)
- grid1.Add( (5,5), 0, wxALIGN_LEFT|wxALL, 5)
-
-
- grid1.Add( self.limit_target, 0, wxALIGN_LEFT|wxALL, 5 )
- grid1.Add( self.allow_none, 0, wxALIGN_LEFT|wxALL, 5 )
- hbox1 = wxBoxSizer( wxHORIZONTAL )
- hbox1.Add( (17,5), 0, wxALIGN_LEFT|wxALL, 5)
- hbox1.Add( self.group_digits, 0, wxALIGN_LEFT|wxLEFT, 5 )
- grid1.Add( hbox1, 0, wxALIGN_LEFT|wxALL, 5)
- grid1.Add( (5,5), 0, wxALIGN_LEFT|wxALL, 5)
-
- grid1.Add( self.allow_negative, 0, wxALIGN_LEFT|wxALL, 5 )
- grid1.Add( self.use_parens, 0, wxALIGN_LEFT|wxALL, 5 )
- hbox2 = wxBoxSizer( wxHORIZONTAL )
- hbox2.Add( (17,5), 0, wxALIGN_LEFT|wxALL, 5)
- hbox2.Add( self.select_on_entry, 0, wxALIGN_LEFT|wxLEFT, 5 )
- grid1.Add( hbox2, 0, wxALIGN_LEFT|wxALL, 5)
- grid1.Add( (5,5), 0, wxALIGN_LEFT|wxALL, 5)
-
-
- grid2 = wxFlexGridSizer( 0, 2, 0, 0 )
- grid2.Add( label, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5 )
- grid2.Add( self.target_ctl, 0, wxALIGN_LEFT|wxALL, 5 )
- grid2.Add( (5,5), 0, wxALIGN_LEFT|wxALL, 5)
- grid2.Add( (5,5), 0, wxALIGN_LEFT|wxALL, 5)
- grid2.Add( label_numselect, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5 )
- grid2.Add( self.numselect, 0, wxALIGN_LEFT|wxALL, 5 )
- grid2.Add( (5,5), 0, wxALIGN_LEFT|wxALL, 5)
- grid2.Add( (5,5), 0, wxALIGN_LEFT|wxALL, 5)
+ grid1 = wx.FlexGridSizer( 0, 4, 0, 0 )
+ grid1.Add( intlabel, 0, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
+ grid1.Add( self.integerwidth, 0, wx.ALIGN_LEFT|wx.ALL, 5 )
+
+ grid1.Add( groupcharlabel, 0, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
+ grid1.Add( self.groupchar, 0, wx.ALIGN_LEFT|wx.ALL, 5 )
+
+ grid1.Add( fraclabel, 0, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
+ grid1.Add( self.fractionwidth, 0, wx.ALIGN_LEFT|wx.ALL, 5 )
+
+ grid1.Add( decimalcharlabel, 0, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
+ grid1.Add( self.decimalchar, 0, wx.ALIGN_LEFT|wx.ALL, 5 )
+
+ grid1.Add( self.set_min, 0, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
+ grid1.Add( self.min, 0, wx.ALIGN_LEFT|wx.ALL, 5 )
+ grid1.Add( (5,5), 0, wx.ALIGN_LEFT|wx.ALL, 5)
+ grid1.Add( (5,5), 0, wx.ALIGN_LEFT|wx.ALL, 5)
+
+ grid1.Add( self.set_max, 0, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
+ grid1.Add( self.max, 0, wx.ALIGN_LEFT|wx.ALL, 5 )
+ grid1.Add( (5,5), 0, wx.ALIGN_LEFT|wx.ALL, 5)
+ grid1.Add( (5,5), 0, wx.ALIGN_LEFT|wx.ALL, 5)
+
+
+ grid1.Add( self.limit_target, 0, wx.ALIGN_LEFT|wx.ALL, 5 )
+ grid1.Add( self.allow_none, 0, wx.ALIGN_LEFT|wx.ALL, 5 )
+ hbox1 = wx.BoxSizer( wx.HORIZONTAL )
+ hbox1.Add( (17,5), 0, wx.ALIGN_LEFT|wx.ALL, 5)
+ hbox1.Add( self.group_digits, 0, wx.ALIGN_LEFT|wx.LEFT, 5 )
+ grid1.Add( hbox1, 0, wx.ALIGN_LEFT|wx.ALL, 5)
+ grid1.Add( (5,5), 0, wx.ALIGN_LEFT|wx.ALL, 5)
+
+ grid1.Add( self.allow_negative, 0, wx.ALIGN_LEFT|wx.ALL, 5 )
+ grid1.Add( self.use_parens, 0, wx.ALIGN_LEFT|wx.ALL, 5 )
+ hbox2 = wx.BoxSizer( wx.HORIZONTAL )
+ hbox2.Add( (17,5), 0, wx.ALIGN_LEFT|wx.ALL, 5)
+ hbox2.Add( self.select_on_entry, 0, wx.ALIGN_LEFT|wx.LEFT, 5 )
+ grid1.Add( hbox2, 0, wx.ALIGN_LEFT|wx.ALL, 5)
+ grid1.Add( (5,5), 0, wx.ALIGN_LEFT|wx.ALL, 5)
+
+
+ grid2 = wx.FlexGridSizer( 0, 2, 0, 0 )
+ grid2.Add( label, 0, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
+ grid2.Add( self.target_ctl, 0, wx.ALIGN_LEFT|wx.ALL, 5 )
+ grid2.Add( (5,5), 0, wx.ALIGN_LEFT|wx.ALL, 5)
+ grid2.Add( (5,5), 0, wx.ALIGN_LEFT|wx.ALL, 5)
+ grid2.Add( label_numselect, 0, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
+ grid2.Add( self.numselect, 0, wx.ALIGN_LEFT|wx.ALL, 5 )
+ grid2.Add( (5,5), 0, wx.ALIGN_LEFT|wx.ALL, 5)
+ grid2.Add( (5,5), 0, wx.ALIGN_LEFT|wx.ALL, 5)
grid2.AddGrowableCol(1)
- self.outer_box = wxBoxSizer( wxVERTICAL )
- self.outer_box.Add(header, 0, wxALIGN_LEFT|wxTOP|wxLEFT, 20)
- self.outer_box.Add( grid1, 0, wxALIGN_CENTRE|wxLEFT|wxBOTTOM|wxRIGHT, 20 )
- self.outer_box.Add( grid2, 0, wxALIGN_LEFT|wxALL, 20 )
+ self.outer_box = wx.BoxSizer( wx.VERTICAL )
+ self.outer_box.Add(header, 0, wx.ALIGN_LEFT|wx.TOP|wx.LEFT, 20)
+ self.outer_box.Add( grid1, 0, wx.ALIGN_CENTRE|wx.LEFT|wx.BOTTOM|wx.RIGHT, 20 )
+ self.outer_box.Add( grid2, 0, wx.ALIGN_LEFT|wx.ALL, 20 )
self.grid2 = grid2
panel.SetAutoLayout( True )
panel.Move( (50,10) )
self.panel = panel
- EVT_MASKEDNUM( self, self.integerwidth.GetId(), self.OnSetIntWidth )
- EVT_MASKEDNUM( self, self.fractionwidth.GetId(), self.OnSetFractionWidth )
- EVT_TEXT( self, self.groupchar.GetId(), self.OnSetGroupChar )
- EVT_TEXT( self, self.decimalchar.GetId(), self.OnSetDecimalChar )
+ mnum.EVT_MASKEDNUM( self, self.integerwidth.GetId(), self.OnSetIntWidth )
+ mnum.EVT_MASKEDNUM( self, self.fractionwidth.GetId(), self.OnSetFractionWidth )
+ self.Bind(wx.EVT_TEXT, self.OnSetGroupChar, self.groupchar )
+ self.Bind(wx.EVT_TEXT, self.OnSetDecimalChar, self.decimalchar )
- EVT_CHECKBOX( self, self.set_min.GetId(), self.OnSetMin )
- EVT_CHECKBOX( self, self.set_max.GetId(), self.OnSetMax )
- EVT_MASKEDNUM( self, self.min.GetId(), self.SetTargetMinMax )
- EVT_MASKEDNUM( self, self.max.GetId(), self.SetTargetMinMax )
+ self.Bind(wx.EVT_CHECKBOX, self.OnSetMin, self.set_min )
+ self.Bind(wx.EVT_CHECKBOX, self.OnSetMax, self.set_max )
+ mnum.EVT_MASKEDNUM( self, self.min.GetId(), self.SetTargetMinMax )
+ mnum.EVT_MASKEDNUM( self, self.max.GetId(), self.SetTargetMinMax )
- EVT_CHECKBOX( self, self.limit_target.GetId(), self.SetTargetMinMax )
- EVT_CHECKBOX( self, self.allow_none.GetId(), self.OnSetAllowNone )
- EVT_CHECKBOX( self, self.group_digits.GetId(), self.OnSetGroupDigits )
- EVT_CHECKBOX( self, self.allow_negative.GetId(), self.OnSetAllowNegative )
- EVT_CHECKBOX( self, self.use_parens.GetId(), self.OnSetUseParens )
- EVT_CHECKBOX( self, self.select_on_entry.GetId(), self.OnSetSelectOnEntry )
+ self.Bind(wx.EVT_CHECKBOX, self.SetTargetMinMax, self.limit_target )
+ self.Bind(wx.EVT_CHECKBOX, self.OnSetAllowNone, self.allow_none )
+ self.Bind(wx.EVT_CHECKBOX, self.OnSetGroupDigits, self.group_digits )
+ self.Bind(wx.EVT_CHECKBOX, self.OnSetAllowNegative, self.allow_negative )
+ self.Bind(wx.EVT_CHECKBOX, self.OnSetUseParens, self.use_parens )
+ self.Bind(wx.EVT_CHECKBOX, self.OnSetSelectOnEntry, self.select_on_entry )
- EVT_MASKEDNUM( self, self.target_ctl.GetId(), self.OnTargetChange )
- EVT_COMBOBOX( self, self.numselect.GetId(), self.OnNumberSelect )
+ mnum.EVT_MASKEDNUM( self, self.target_ctl.GetId(), self.OnTargetChange )
+ self.Bind(wx.EVT_COMBOBOX, self.OnNumberSelect, self.numselect )
def OnSetIntWidth(self, event ):
width = self.integerwidth.GetValue()
+
if width < 1:
self.log.write("integer width must be positive\n")
- self.integerwidth.SetForegroundColour(wxRED)
+ self.integerwidth.SetForegroundColour(wx.RED)
else:
- self.integerwidth.SetForegroundColour(wxBLACK)
+ self.integerwidth.SetForegroundColour(wx.BLACK)
self.log.write("setting integer width to %d\n" % width)
self.target_ctl.SetParameters( integerWidth = width)
# Now resize and fit the dialog as appropriate:
char = self.groupchar.GetValue()
if self.target_ctl.GetDecimalChar() == char:
self.log.write("group and decimal chars must be different\n")
- self.groupchar.SetForegroundColour(wxRED)
+ self.groupchar.SetForegroundColour(wx.RED)
else:
- self.groupchar.SetForegroundColour(wxBLACK)
+ self.groupchar.SetForegroundColour(wx.BLACK)
self.log.write("setting group char to %s\n" % char)
self.target_ctl.SetGroupChar( char )
char = self.decimalchar.GetValue()
if self.target_ctl.GetGroupChar() == char:
self.log.write("group and decimal chars must be different\n")
- self.decimalchar.SetForegroundColour(wxRED)
+ self.decimalchar.SetForegroundColour(wx.RED)
else:
- self.decimalchar.SetForegroundColour(wxBLACK)
+ self.decimalchar.SetForegroundColour(wx.BLACK)
self.log.write("setting decimal char to %s\n" % char)
self.target_ctl.SetDecimalChar( char )
self.log.write( "min (%d) won't fit in control -- bound not set\n" % min )
else:
self.log.write( "min (%d) > current max (%d) -- bound not set\n" % ( min, self.target_ctl.GetMax() ) )
- self.min.SetParameters( signedForegroundColour=wxRED, foregroundColour=wxRED )
+ self.min.SetParameters( signedForegroundColour=wx.RED, foregroundColour=wx.RED )
else:
- self.min.SetParameters( signedForegroundColour=wxBLACK, foregroundColour=wxBLACK )
+ self.min.SetParameters( signedForegroundColour=wx.BLACK, foregroundColour=wx.BLACK )
self.min.Refresh()
if max != cur_max and not self.target_ctl.SetMax( max ):
self.log.write( "max (%d) won't fit in control -- bound not set\n" % max )
else:
self.log.write( "max (%d) < current min (%d) -- bound not set\n" % ( max, self.target_ctl.GetMin() ) )
- self.max.SetParameters( signedForegroundColour=wxRED, foregroundColour=wxRED )
+ self.max.SetParameters( signedForegroundColour=wx.RED, foregroundColour=wx.RED )
else:
- self.max.SetParameters( signedForegroundColour=wxBLACK, foregroundColour=wxBLACK )
+ self.max.SetParameters( signedForegroundColour=wx.BLACK, foregroundColour=wx.BLACK )
self.max.Refresh()
if min != cur_min or max != cur_max:
return win
#----------------------------------------------------------------------
-overview = overviewdoc
+overview = mnum.__doc__
if __name__ == '__main__':
import sys,os
# menus in wxPython 2.3.3
#
#-------------------------------------------------------------------
+# 11/20/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
-import images
-import time
+import time
+import wx
+import images
#-------------------------------------------------------------------
-class MyFrame(wxFrame):
+class MyFrame(wx.Frame):
def __init__(self, parent, id, log):
- wxFrame.__init__(self, parent, id, 'Playing with menus', size=(400, 200))
+ wx.Frame.__init__(self, parent, id, 'Playing with menus', size=(400, 200))
self.log = log
self.CenterOnScreen()
self.CreateStatusBar()
self.SetStatusText("This is the statusbar")
- tc = wxTextCtrl(self, -1, """
+ tc = wx.TextCtrl(self, -1, """
A bunch of bogus menus have been created for this frame. You
can play around with them to see how they behave and then
check the source for this sample to see how to implement them.
-""", style=wxTE_READONLY|wxTE_MULTILINE)
+""", style=wx.TE_READONLY|wx.TE_MULTILINE)
# Prepare the menu bar
- menuBar = wxMenuBar()
+ menuBar = wx.MenuBar()
# 1st menu from left
- menu1 = wxMenu()
+ menu1 = wx.Menu()
menu1.Append(101, "&Mercury", "This the text in the Statusbar")
menu1.Append(102, "&Venus", "")
menu1.Append(103, "&Earth", "You may select Earth too")
menuBar.Append(menu1, "&Planets")
# 2nd menu from left
- menu2 = wxMenu()
+ menu2 = wx.Menu()
menu2.Append(201, "Hydrogen")
menu2.Append(202, "Helium")
# a submenu in the 2nd menu
- submenu = wxMenu()
+ submenu = wx.Menu()
submenu.Append(2031,"Lanthanium")
submenu.Append(2032,"Cerium")
submenu.Append(2033,"Praseodymium")
# Append 2nd menu
menuBar.Append(menu2, "&Elements")
- menu3 = wxMenu()
- menu3.Append(301, "IDLE", "a Python shell using tcl/tk as GUI", wxITEM_RADIO)
- menu3.Append(302, "PyCrust", "a Python shell using wxPython as GUI", wxITEM_RADIO)
- menu3.Append(303, "psi", "a simple Python shell using wxPython as GUI", wxITEM_RADIO)
+ menu3 = wx.Menu()
+ # Radio items
+ menu3.Append(301, "IDLE", "a Python shell using tcl/tk as GUI", wx.ITEM_RADIO)
+ menu3.Append(302, "PyCrust", "a Python shell using wxPython as GUI", wx.ITEM_RADIO)
+ menu3.Append(303, "psi", "a simple Python shell using wxPython as GUI", wx.ITEM_RADIO)
menu3.AppendSeparator()
- menu3.Append(304, "project1", "", wxITEM_NORMAL)
- menu3.Append(305, "project2", "", wxITEM_NORMAL)
+ menu3.Append(304, "project1", "", wx.ITEM_NORMAL)
+ menu3.Append(305, "project2", "", wx.ITEM_NORMAL)
menuBar.Append(menu3, "&Shells")
- menu4 = wxMenu()
- menu4.Append(401, "letters", "abcde...", wxITEM_CHECK)
- menu4.Append(402, "digits", "123...", wxITEM_CHECK)
- menu4.Append(403, "letters and digits", "abcd... + 123...", wxITEM_CHECK)
+ menu4 = wx.Menu()
+ # Check menu items
+ menu4.Append(401, "letters", "abcde...", wx.ITEM_CHECK)
+ menu4.Append(402, "digits", "123...", wx.ITEM_CHECK)
+ menu4.Append(403, "letters and digits", "abcd... + 123...", wx.ITEM_CHECK)
menuBar.Append(menu4, "Chec&k")
- menu5 = wxMenu()
+ menu5 = wx.Menu()
# Show how to put an icon in the menu
- item = wxMenuItem(menu5, 500, "&Smile!\tCtrl+S", "This one has an icon")
+ item = wx.MenuItem(menu5, 500, "&Smile!\tCtrl+S", "This one has an icon")
item.SetBitmap(images.getSmilesBitmap())
menu5.AppendItem(item)
+ # Shortcuts
menu5.Append(501, "Interesting thing\tCtrl+A", "Note the shortcut!")
menu5.AppendSeparator()
menu5.Append(502, "Hello\tShift+H")
menu5.AppendSeparator()
menu5.Append(503, "remove the submenu")
- menu6 = wxMenu()
+ menu6 = wx.Menu()
menu6.Append(601, "Submenu Item")
menu5.AppendMenu(504, "submenu", menu6)
menu5.Append(505, "remove this menu")
self.SetMenuBar(menuBar)
# Menu events
- EVT_MENU_HIGHLIGHT_ALL(self, self.OnMenuHighlight)
-
- EVT_MENU(self, 101, self.Menu101)
- EVT_MENU(self, 102, self.Menu102)
- EVT_MENU(self, 103, self.Menu103)
- EVT_MENU(self, 104, self.CloseWindow)
-
- EVT_MENU(self, 201, self.Menu201)
- EVT_MENU(self, 202, self.Menu202)
- EVT_MENU(self, 2031, self.Menu2031)
- EVT_MENU(self, 2032, self.Menu2032)
- EVT_MENU(self, 2033, self.Menu2033)
-
- EVT_MENU(self, 301, self.Menu301To303)
- EVT_MENU(self, 302, self.Menu301To303)
- EVT_MENU(self, 303, self.Menu301To303)
- EVT_MENU(self, 304, self.Menu304)
- EVT_MENU(self, 305, self.Menu305)
-
- EVT_MENU_RANGE(self, 401, 403, self.Menu401To403)
-
- EVT_MENU(self, 500, self.Menu500)
- EVT_MENU(self, 501, self.Menu501)
- EVT_MENU(self, 502, self.Menu502)
- EVT_MENU(self, 503, self.TestRemove)
- EVT_MENU(self, 505, self.TestRemove2)
- EVT_MENU(self, 507, self.TestInsert)
- EVT_MENU(self, 508, self.TestInsert)
-
- EVT_UPDATE_UI(wxGetApp(), 506, self.TestUpdateUI)
+ self.Bind(wx.EVT_MENU_HIGHLIGHT_ALL, self.OnMenuHighlight)
+
+ self.Bind(wx.EVT_MENU, self.Menu101, id=101)
+ self.Bind(wx.EVT_MENU, self.Menu102, id=102)
+ self.Bind(wx.EVT_MENU, self.Menu103, id=103)
+ self.Bind(wx.EVT_MENU, self.CloseWindow, id=104)
+
+ self.Bind(wx.EVT_MENU, self.Menu201, id=201)
+ self.Bind(wx.EVT_MENU, self.Menu202, id=202)
+ self.Bind(wx.EVT_MENU, self.Menu2031, id=2031)
+ self.Bind(wx.EVT_MENU, self.Menu2032, id=2032)
+ self.Bind(wx.EVT_MENU, self.Menu2033, id=2033)
+
+ self.Bind(wx.EVT_MENU, self.Menu301To303, id=301)
+ self.Bind(wx.EVT_MENU, self.Menu301To303, id=302)
+ self.Bind(wx.EVT_MENU, self.Menu301To303, id=303)
+ self.Bind(wx.EVT_MENU, self.Menu304, id=304)
+ self.Bind(wx.EVT_MENU, self.Menu305, id=305)
+
+ # Range of menu items
+ self.Bind(wx.EVT_MENU_RANGE, self.Menu401To403, id=401, id2=403)
+
+ self.Bind(wx.EVT_MENU, self.Menu500, id=500)
+ self.Bind(wx.EVT_MENU, self.Menu501, id=501)
+ self.Bind(wx.EVT_MENU, self.Menu502, id=502)
+ self.Bind(wx.EVT_MENU, self.TestRemove, id=503)
+ self.Bind(wx.EVT_MENU, self.TestRemove2, id=505)
+ self.Bind(wx.EVT_MENU, self.TestInsert, id=507)
+ self.Bind(wx.EVT_MENU, self.TestInsert, id=508)
+
+ wx.GetApp().Bind(wx.EVT_UPDATE_UI, self.TestUpdateUI, id=506)
# Methods
item = self.GetMenuBar().FindItemById(id)
text = item.GetText()
help = item.GetHelp()
+
#print text, help
- event.Skip() # but in this case just call Skip so the default is done
+ # but in this case just call Skip so the default is done
+ event.Skip()
def Menu101(self, event):
def TestRemove(self, evt):
mb = self.GetMenuBar()
submenuItem = mb.FindItemById(601)
+
if not submenuItem:
return
+
submenu = submenuItem.GetMenu()
menu = submenu.GetParent()
- #menu.Remove(504) # works
- menu.RemoveItem(mb.FindItemById(504)) # this also works
- #menu.RemoveItem(submenuItem) # doesn't work, as expected since submenuItem is not on menu
+ # This works
+ #menu.Remove(504)
+
+ # this also works
+ menu.RemoveItem(mb.FindItemById(504))
+
+ # This doesn't work, as expected since submenuItem is not on menu
+ #menu.RemoveItem(submenuItem)
def TestRemove2(self, evt):
# figure out the position to insert at
pos = 0
+
for i in menu.GetMenuItems():
if i.GetId() == theID:
break
+
pos += 1
# now insert the new item
- ID = wxNewId()
+ ID = wx.NewId()
##menu.Insert(pos, ID, "NewItem " + str(ID))
- item = wxMenuItem(menu)
+ item = wx.MenuItem(menu)
item.SetId(ID)
item.SetText("NewItem " + str(ID))
menu.InsertItem(pos, item)
-
#-------------------------------------------------------------------
-wxRegisterId(10000)
+wx.RegisterId(10000)
def runTest(frame, nb, log):
win = MyFrame(frame, -1, log)
overview = """\
A demo of using wxMenuBar and wxMenu in various ways.
-"""
+A menu is a popup (or pull down) list of items, one of which may be selected
+before the menu goes away (clicking elsewhere dismisses the menu). Menus may be
+used to construct either menu bars or popup menus.
+
+A menu item has an integer ID associated with it which can be used to identify
+the selection, or to change the menu item in some way. A menu item with a special
+identifier -1 is a separator item and doesn't have an associated command but just
+makes a separator line appear in the menu.
+
+Menu items may be either normal items, check items or radio items. Normal items
+don't have any special properties while the check items have a boolean flag associated
+to them and they show a checkmark in the menu when the flag is set. wxWindows
+automatically toggles the flag value when the item is clicked and its value may
+be retrieved using either IsChecked method of wxMenu or wxMenuBar itself or by
+using wxEvent.IsChecked when you get the menu notification for the item in question.
+
+The radio items are similar to the check items except that all the other items
+in the same radio group are unchecked when a radio item is checked. The radio group
+is formed by a contiguous range of radio items, i.e. it starts at the first item of
+this kind and ends with the first item of a different kind (or the end of the menu).
+Notice that because the radio groups are defined in terms of the item positions
+inserting or removing the items in the menu containing the radio items risks to not
+work correctly. Finally note that the radio items are only supported under Windows
+and GTK+ currently.
+"""
if __name__ == '__main__':
+# 11/20/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
+import wx
#---------------------------------------------------------------------------
def runTest(frame, nb, log):
- dlg = wxMessageDialog(frame, 'Hello from Python and wxPython!',
- 'A Message Box', wxOK | wxICON_INFORMATION)
+ dlg = wx.MessageDialog(frame, 'Hello from Python and wxPython!',
+ 'A Message Box', wx.OK | wx.ICON_INFORMATION)
#wxYES_NO | wxNO_DEFAULT | wxCANCEL | wxICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
-
-
-
-
-
-
-
-
-
-
overview = """\
-Show a message to the user in a dialog
-"""
+This class represents a dialog that shows a single or multi-line message, with a
+choice of OK, Yes, No and Cancel buttons.
+Additionally, various style flags can determine whether an icon is displayed,
+and, if so, what kind.
+The dialog can be modal or not; of modal, the user's response is in the return
+code of ShowModal(). If not, the response can be taken from GetReturnCode() (inherited
+from the wxDialog super class). If not modal and the return code is required, it
+must be retrieved before the dialog is destroyed.
+"""
if __name__ == '__main__':
+# 11/20/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
+import wx
#---------------------------------------------------------------------------
-class MyMiniFrame(wxMiniFrame):
- def __init__(self, parent, title, pos=wxDefaultPosition, size=wxDefaultSize,
- style=wxDEFAULT_FRAME_STYLE ):
- wxMiniFrame.__init__(self, parent, -1, title, pos, size, style)
- panel = wxPanel(self, -1)
+class MyMiniFrame(wx.MiniFrame):
+ def __init__(
+ self, parent, title, pos=wx.DefaultPosition, size=wx.DefaultSize,
+ style=wx.DEFAULT_FRAME_STYLE
+ ):
- button = wxButton(panel, -1, "Close Me")
- button.SetPosition(wxPoint(15, 15))
- EVT_BUTTON(self, button.GetId(), self.OnCloseMe)
- EVT_CLOSE(self, self.OnCloseWindow)
+ wx.MiniFrame.__init__(self, parent, -1, title, pos, size, style)
+ panel = wx.Panel(self, -1)
+
+ button = wx.Button(panel, -1, "Close Me")
+ button.SetPosition((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 runTest(frame, nb, log):
win = MyMiniFrame(frame, "This is a wxMiniFrame",
#pos=(250,250), size=(200,200),
- style=wxDEFAULT_FRAME_STYLE | wxTINY_CAPTION_HORIZ)
+ style=wx.DEFAULT_FRAME_STYLE | wx.TINY_CAPTION_HORIZ)
win.SetSize((200, 200))
- win.CenterOnParent(wxBOTH)
+ win.CenterOnParent(wx.BOTH)
frame.otherWin = win
win.Show(True)
#---------------------------------------------------------------------------
-
-
-
-
-
-
-
-
overview = """\
+A miniframe is a frame with a small title bar. It is suitable for floating
+toolbars that must not take up too much screen area. In other respects, it's the
+same as a wxFrame.
"""
-
-
-
if __name__ == '__main__':
import sys,os
import run
-from wxPython.wx import *
-from wxPython.lib.multisash import wxMultiSash
-from wxPython.stc import *
+# 11/20/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+# 11/30/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o wx renamer needs to be applied to multisash lib.
+# o There appears to be a problem with the image that
+# the library is trying to use for the alternate cursor
+#
+
+import wx
+import wx.lib.multisash as sash
+import wx.stc as stc
#---------------------------------------------------------------------------
#---------------------------------------------------------------------------
-class TestWindow(wxStyledTextCtrl):
+class TestWindow(stc.StyledTextCtrl):
def __init__(self, parent):
- wxStyledTextCtrl.__init__(self, parent, -1, style=wxNO_BORDER)
+ stc.StyledTextCtrl.__init__(self, parent, -1, style=wx.NO_BORDER)
self.SetMarginWidth(1,0)
- if wxPlatform == '__WXMSW__':
+
+ if wx.Platform == '__WXMSW__':
fSize = 10
else:
fSize = 12
- self.StyleSetFont(wxSTC_STYLE_DEFAULT,
- wxFont(fSize, wxMODERN, wxNORMAL, wxNORMAL))
+
+ self.StyleSetFont(
+ stc.STC_STYLE_DEFAULT,
+ wx.Font(fSize, wx.MODERN, wx.NORMAL, wx.NORMAL)
+ )
+
self.SetText(sampleText)
-class TestFrame(wxFrame):
+class TestFrame(wx.Frame):
def __init__(self, parent, log):
- wxFrame.__init__(self, parent, -1, "Multi Sash Demo",
- size=(640,480))
- self.multi = wxMultiSash(self,-1,pos = wxPoint(0,0),
- size = (640,480))
+ wx.Frame.__init__(self, parent, -1, "Multi Sash Demo", size=(640,480))
+ self.multi = sash.wxMultiSash(self,-1,pos=(0,0), size=(640,480))
# Use this method to set the default class that will be created when
# a new sash is created. The class's constructor needs 1 parameter
def runTest(frame, nb, log):
- multi = wxMultiSash(nb, -1, pos = (0,0), size = (640,480))
+ multi = sash.wxMultiSash(nb, -1, pos = (0,0), size = (640,480))
# Use this method to set the default class that will be created when
# a new sash is created. The class's constructor needs 1 parameter
-
-from wxPython.wx import *
-from wxPython.lib.dialogs import wxMultipleChoiceDialog
+# 11/20/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+# 11/30/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o wx renamer not applied to lib.
+#
+
+import wx
+import wx.lib.dialogs as dlgs
#---------------------------------------------------------------------------
def runTest(frame, nb, log):
lst = [ 'apple', 'pear', 'banana', 'coconut', 'orange',
'etc', 'etc..', 'etc...' ]
- dlg = wxMultipleChoiceDialog(frame,
+
+ dlg = dlgs.wxMultipleChoiceDialog(frame,
"Pick some from\n this list\nblah blah...",
"m.s.d.", lst)
- if (dlg.ShowModal() == wxID_OK):
+
+ if (dlg.ShowModal() == wx.ID_OK):
print "Selection:", dlg.GetValue(), " -> ", dlg.GetValueString()
#---------------------------------------------------------------------------
+overview = """\
+<html>
+<body>
+This is a Python implementation of a dialog that is not yet implemented in wxWindows
+proper, so don't let the wxWindows documentation mislead you.
+<p><code><b>wxMultipleChoiceDialog</b>(self, parent, msg, title, lst,
+pos = wx.wxDefaultPosition, size = (200,200), style = wx.wxDEFAULT_DIALOG_STYLE)
+</code>
+<dl>
+<dt><code>parent</code>
+<dd>The parent window
+<dt><code>msg</code>
+<dd>The message that will be displayed above the list
+<dt><code>title</code>
+<dd>The text that will appear on the title bar
-overview = """\
-"""
+<dt><code>lst</code>
+<dd>A Python list of choices that will appear in the dialog.
+
+<dt><code>pos</code>
+<dd>The position of the dialog
+<dt><code>size</code>
+<dd>The size of the dialog
+<dt><code>style</code>
+<dd>The style for the dialog. Only styles normally available to wxDialog are
+available.
+</dl>
+<b><font size=+1><code>Methods</code></font></b>
+
+<dl>
+<dt><code>GetValue</code>
+<dd>Returns a tuple containing the indices of the selected items
+
+<dt><code>GetValueString</code>
+<dd>Returns a tuple containing the text of the selected items
+
+</dl>
+
+Additionally, wxMultipleChoiceDialog.lbox is a standard wxListBox which supports all
+methods applicable to that class.
+
+</body>
+</html>
+"""
if __name__ == '__main__':
import sys,os
+# 11/20/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
+import sys
-import ColorPanel
-import GridSimple
-import wxListCtrl
-import wxScrolledWindow
-import images
+import wx
-import sys
+import ColorPanel
+import GridSimple
+import wxListCtrl
+import wxScrolledWindow
+import images
#----------------------------------------------------------------------------
-class TestNB(wxNotebook):
+class TestNB(wx.Notebook):
def __init__(self, parent, id, log):
- wxNotebook.__init__(self, parent, id, style=
+ wx.Notebook.__init__(self, parent, id, style=
#wxNB_TOP
- wxNB_BOTTOM
+ wx.NB_BOTTOM
#wxNB_LEFT
#wxNB_RIGHT
)
self.log = log
- win = self.makeColorPanel(wxBLUE)
+ win = self.makeColorPanel(wx.BLUE)
self.AddPage(win, "Blue")
- st = wxStaticText(win.win, -1,
+ st = wx.StaticText(win.win, -1,
"You can put nearly any type of window here,\n"
"and if the platform supports it then the\n"
"tabs can be on any side of the notebook.",
- wxPoint(10, 10))
- st.SetForegroundColour(wxWHITE)
- st.SetBackgroundColour(wxBLUE)
+ (10, 10))
+
+ st.SetForegroundColour(wx.WHITE)
+ st.SetBackgroundColour(wx.BLUE)
# Show how to put an image on one of the notebook tabs,
# first make the image list:
- il = wxImageList(16, 16)
+ il = wx.ImageList(16, 16)
idx1 = il.Add(images.getSmilesBitmap())
self.AssignImageList(il)
self.SetPageImage(0, idx1)
- win = self.makeColorPanel(wxRED)
+ win = self.makeColorPanel(wx.RED)
self.AddPage(win, "Red")
win = wxScrolledWindow.MyCanvas(self)
self.AddPage(win, 'ScrolledWindow')
- win = self.makeColorPanel(wxGREEN)
+ win = self.makeColorPanel(wx.GREEN)
self.AddPage(win, "Green")
win = GridSimple.SimpleGrid(self, log)
win = wxListCtrl.TestListCtrlPanel(self, log)
self.AddPage(win, 'List')
- win = self.makeColorPanel(wxCYAN)
+ win = self.makeColorPanel(wx.CYAN)
self.AddPage(win, "Cyan")
-## win = self.makeColorPanel(wxWHITE)
-## self.AddPage(win, "White")
+# win = self.makeColorPanel(wxWHITE)
+# self.AddPage(win, "White")
-## win = self.makeColorPanel(wxBLACK)
-## self.AddPage(win, "Black")
+# win = self.makeColorPanel(wxBLACK)
+# self.AddPage(win, "Black")
- win = self.makeColorPanel(wxNamedColour('MIDNIGHT BLUE'))
+ win = self.makeColorPanel(wx.NamedColour('MIDNIGHT BLUE'))
self.AddPage(win, "MIDNIGHT BLUE")
- win = self.makeColorPanel(wxNamedColour('INDIAN RED'))
+ win = self.makeColorPanel(wx.NamedColour('INDIAN RED'))
self.AddPage(win, "INDIAN RED")
- EVT_NOTEBOOK_PAGE_CHANGED(self, self.GetId(), self.OnPageChanged)
- EVT_NOTEBOOK_PAGE_CHANGING(self, self.GetId(), self.OnPageChanging)
+ self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
+ self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGING, self.OnPageChanging)
def makeColorPanel(self, color):
- p = wxPanel(self, -1)
+ p = wx.Panel(self, -1)
win = ColorPanel.ColoredPanel(p, color)
p.win = win
+
def OnCPSize(evt, win=win):
win.SetSize(evt.GetSize())
- EVT_SIZE(p, OnCPSize)
- return p
+ p.Bind(wx.EVT_SIZE, OnCPSize)
+ return p
def OnPageChanged(self, event):
old = event.GetOldSelection()
#----------------------------------------------------------------------------
-
-
overview = """\
<html><body>
<h2>wxNotebook</h2>
"""
-
if __name__ == '__main__':
import sys,os
import run
+# 11/20/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+# 11/30/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o OGL's busted bigtime. Can't even use OGLInitialize() without a
+# program error on w2k.
+#
-from wxPython.wx import *
-from wxPython.ogl import *
+import wx
+import wx.ogl as ogl
-import images
+import images
-##wxTrap()
+##wx.Trap()
#----------------------------------------------------------------------
+# This creates some pens and brushes that the OGL library uses.
-class DiamondShape(wxPolygonShape):
+ogl.OGLInitialize()
+
+#----------------------------------------------------------------------
+
+class DiamondShape(ogl.PolygonShape):
def __init__(self, w=0.0, h=0.0):
- wxPolygonShape.__init__(self)
+ ogl.PolygonShape.__init__(self)
if w == 0.0:
w = 60.0
if h == 0.0:
h = 60.0
- ## Either wxRealPoints or 2-tuples of floats works.
+ # Either ogl.RealPoints or 2-tuples of floats works.
- #points = [ wxRealPoint(0.0, -h/2.0),
- # wxRealPoint(w/2.0, 0.0),
- # wxRealPoint(0.0, h/2.0),
- # wxRealPoint(-w/2.0, 0.0),
+ #points = [ ogl.RealPoint(0.0, -h/2.0),
+ # ogl.RealPoint(w/2.0, 0.0),
+ # ogl.RealPoint(0.0, h/2.0),
+ # ogl.RealPoint(-w/2.0, 0.0),
# ]
points = [ (0.0, -h/2.0),
(w/2.0, 0.0),
#----------------------------------------------------------------------
-class RoundedRectangleShape(wxRectangleShape):
+class RoundedRectangleShape(ogl.RectangleShape):
def __init__(self, w=0.0, h=0.0):
- wxRectangleShape.__init__(self, w, h)
+ ogl.RectangleShape.__init__(self, w, h)
self.SetCornerRadius(-0.3)
#----------------------------------------------------------------------
-class DividedShape(wxDividedShape):
+class DividedShape(ogl.DividedShape):
def __init__(self, width, height, canvas):
- wxDividedShape.__init__(self, width, height)
+ ogl.DividedShape.__init__(self, width, height)
- region1 = wxShapeRegion()
- region1.SetText('wxDividedShape')
+ region1 = ogl.ShapeRegion()
+ region1.SetText('DividedShape')
region1.SetProportions(0.0, 0.2)
- region1.SetFormatMode(FORMAT_CENTRE_HORIZ)
+ region1.SetFormatMode(ogl.FORMAT_CENTRE_HORIZ)
self.AddRegion(region1)
- region2 = wxShapeRegion()
+ region2 = ogl.ShapeRegion()
region2.SetText('This is Region number two.')
region2.SetProportions(0.0, 0.3)
- region2.SetFormatMode(FORMAT_CENTRE_HORIZ|FORMAT_CENTRE_VERT)
+ region2.SetFormatMode(ogl.FORMAT_CENTRE_HORIZ|ogl.FORMAT_CENTRE_VERT)
self.AddRegion(region2)
- region3 = wxShapeRegion()
+ region3 = ogl.ShapeRegion()
region3.SetText('Region 3\nwith embedded\nline breaks')
region3.SetProportions(0.0, 0.5)
- region3.SetFormatMode(FORMAT_NONE)
+ region3.SetFormatMode(ogl.FORMAT_NONE)
self.AddRegion(region3)
self.SetRegionSizes()
def ReformatRegions(self, canvas=None):
rnum = 0
+
if canvas is None:
canvas = self.GetCanvas()
- dc = wxClientDC(canvas) # used for measuring
+
+ dc = wx.ClientDC(canvas) # used for measuring
+
for region in self.GetRegions():
text = region.GetText()
self.FormatText(dc, text, rnum)
#----------------------------------------------------------------------
-class MyEvtHandler(wxShapeEvtHandler):
+class MyEvtHandler(ogl.ShapeEvtHandler):
def __init__(self, log, frame):
- wxShapeEvtHandler.__init__(self)
+ ogl.ShapeEvtHandler.__init__(self)
self.log = log
self.statbarFrame = frame
shape = self.GetShape()
print shape.__class__, shape.GetClassName()
canvas = shape.GetCanvas()
- dc = wxClientDC(canvas)
+ dc = wx.ClientDC(canvas)
canvas.PrepareDC(dc)
if shape.Selected():
redraw = False
shapeList = canvas.GetDiagram().GetShapeList()
toUnselect = []
+
for s in shapeList:
if s.Selected():
# If we unselect it now then some of the objects in
if toUnselect:
for s in toUnselect:
s.Select(False, dc)
+
canvas.Redraw(dc)
self.UpdateStatusBar(shape)
def OnEndDragLeft(self, x, y, keys = 0, attachment = 0):
shape = self.GetShape()
self.base_OnEndDragLeft(x, y, keys, attachment)
+
if not shape.Selected():
self.OnLeftClick(x, y, keys, attachment)
+
self.UpdateStatusBar(shape)
#----------------------------------------------------------------------
-class TestWindow(wxShapeCanvas):
+class TestWindow(ogl.ShapeCanvas):
def __init__(self, parent, log, frame):
- wxShapeCanvas.__init__(self, parent)
+ ogl.ShapeCanvas.__init__(self, parent)
maxWidth = 1000
maxHeight = 1000
self.log = log
self.frame = frame
- self.SetBackgroundColour("LIGHT BLUE") #wxWHITE)
- self.diagram = wxDiagram()
+ self.SetBackgroundColour("LIGHT BLUE") #wx.WHITE)
+ self.diagram = ogl.Diagram()
self.SetDiagram(self.diagram)
self.diagram.SetCanvas(self)
self.shapes = []
self.save_gdi = []
- rRectBrush = wxBrush("MEDIUM TURQUOISE", wxSOLID)
- dsBrush = wxBrush("WHEAT", wxSOLID)
-
- self.MyAddShape(wxCircleShape(80), 100, 100, wxPen(wxBLUE, 3), wxGREEN_BRUSH, "Circle")
- self.MyAddShape(wxRectangleShape(85, 50), 305, 60, wxBLACK_PEN, wxLIGHT_GREY_BRUSH, "Rectangle")
- ds = self.MyAddShape(DividedShape(140, 150, self), 495, 145, wxBLACK_PEN, dsBrush, '')
- self.MyAddShape(DiamondShape(90, 90), 345, 235, wxPen(wxBLUE, 3, wxDOT), wxRED_BRUSH, "Polygon")
- self.MyAddShape(RoundedRectangleShape(95,70), 140, 255, wxPen(wxRED, 2), rRectBrush, "Rounded Rect")
+ rRectBrush = wx.Brush("MEDIUM TURQUOISE", wx.SOLID)
+ dsBrush = wx.Brush("WHEAT", wx.SOLID)
+
+ self.MyAddShape(
+ ogl.CircleShape(80),
+ 100, 100, wx.Pen(wx.BLUE, 3), wx.GREEN_BRUSH, "Circle"
+ )
+
+ self.MyAddShape(
+ ogl.RectangleShape(85, 50),
+ 305, 60, wx.BLACK_PEN, wx.LIGHT_GREY_BRUSH, "Rectangle"
+ )
+
+ ds = self.MyAddShape(
+ DividedShape(140, 150, self),
+ 495, 145, wx.BLACK_PEN, dsBrush, ''
+ )
+
+ self.MyAddShape(
+ DiamondShape(90, 90),
+ 345, 235, wx.Pen(wx.BLUE, 3, wx.DOT), wx.RED_BRUSH, "Polygon"
+ )
+
+ self.MyAddShape(
+ RoundedRectangleShape(95,70),
+ 140, 255, wx.Pen(wx.RED, 2), rRectBrush, "Rounded Rect"
+ )
bmp = images.getTest2Bitmap()
- mask = wxMaskColour(bmp, wxBLUE)
+ mask = wx.MaskColour(bmp, wx.BLUE)
bmp.SetMask(mask)
- s = wxBitmapShape()
+ s = ogl.BitmapShape()
s.SetBitmap(bmp)
self.MyAddShape(s, 225, 150, None, None, "Bitmap")
- dc = wxClientDC(self)
+ dc = wx.ClientDC(self)
self.PrepareDC(dc)
+
for x in range(len(self.shapes)):
fromShape = self.shapes[x]
if x+1 == len(self.shapes):
toShape = self.shapes[0]
else:
toShape = self.shapes[x+1]
- line = wxLineShape()
+
+ line = ogl.LineShape()
line.SetCanvas(self)
- line.SetPen(wxBLACK_PEN)
- line.SetBrush(wxBLACK_BRUSH)
- line.AddArrow(ARROW_ARROW)
+ line.SetPen(wx.BLACK_PEN)
+ line.SetBrush(wx.BLACK_BRUSH)
+ line.AddArrow(ogl.ARROW_ARROW)
line.MakeLineControlPoints(2)
fromShape.AddLine(line, toShape)
self.diagram.AddShape(line)
# for some reason, the shapes have to be moved for the line to show up...
fromShape.Move(dc, fromShape.GetX(), fromShape.GetY())
- EVT_WINDOW_DESTROY(self, self.OnDestroy)
+ wx.EVT_WINDOW_DESTROY(self, self.OnDestroy)
def MyAddShape(self, shape, x, y, pen, brush, text):
if pen: shape.SetPen(pen)
if brush: shape.SetBrush(brush)
if text: shape.AddText(text)
- #shape.SetShadowMode(SHADOW_RIGHT)
+ #shape.SetShadowMode(ogl.SHADOW_RIGHT)
self.diagram.AddShape(shape)
shape.Show(True)
if shape.GetParent() == None:
shape.SetCanvas(None)
shape.Destroy()
+
self.diagram.Destroy()
# This creates some pens and brushes that the OGL library uses.
# It should be called after the app object has been created, but
# before OGL is used.
- wxOGLInitialize()
+ wx.OGLInitialize()
win = TestWindow(nb, log, frame)
return win
-
+
#----------------------------------------------------------------------
class __Cleanup:
- cleanup = wxOGLCleanUp
+ cleanup = ogl.OGLCleanUp
def __del__(self):
self.cleanup()
__cu = __Cleanup()
-
-
-
-
-
-
overview = """\
The Object Graphics Library is a library supporting the creation and
manipulation of simple and complex graphic images on a canvas.
"""
-
-
if __name__ == '__main__':
import sys,os
import run
+# 11/20/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
+import wx
#---------------------------------------------------------------------------
def runTest(frame, nb, log):
- data = wxPageSetupDialogData()
+ data = wx.PageSetupDialogData()
data.SetMarginTopLeft( (15, 15) )
data.SetMarginBottomRight( (15, 15) )
#data.SetDefaultMinMargins(True)
- data.SetPaperId(wxPAPER_LETTER)
+ data.SetPaperId(wx.PAPER_LETTER)
- dlg = wxPageSetupDialog(frame, data)
- if dlg.ShowModal() == wxID_OK:
+ dlg = wx.PageSetupDialog(frame, data)
+
+ if dlg.ShowModal() == wx.ID_OK:
data = dlg.GetPageSetupData()
tl = data.GetMarginTopLeft()
br = data.GetMarginBottomRight()
log.WriteText('Margins are: %s %s\n' % (str(tl), str(br)))
+
dlg.Destroy()
#---------------------------------------------------------------------------
-
-
-
overview = """\
-"""
+This class represents the page setup common dialog. The page setup dialog is standard
+from Windows 95 on, replacing the print setup dialog (which is retained in Windows
+and wxWindows for backward compatibility). On Windows 95 and NT 4.0 and above,
+the page setup dialog is native to the windowing system, otherwise it is emulated.
+The page setup dialog contains controls for paper size (A4, A5 etc.), orientation
+(landscape or portrait), and controls for setting left, top, right and bottom margin
+sizes in millimetres.
+When the dialog has been closed, you need to query the <code>wxPageSetupDialogData</code> object
+associated with the dialog.
+Note that the OK and Cancel buttons do not destroy the dialog; this must be done by
+the application. As with other dialogs, do not destroy the dialog until you are done
+with the data, and, conversely, do not use the wxPageSetupDialogData after the
+dialog is destroyed.
+"""
+
if __name__ == '__main__':
import sys,os
+# 11/20/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+# 11/30/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o wxPlotCanvas must be updated with new draw mechanics (tuples) before
+# it can be used with 2.5.
+#
-from wxPython.lib.wxPlotCanvas import *
-from wxPython.lib import wxPlotCanvas
+import wx
+import wx.lib.wxPlotCanvas as plot
+
+import Numeric
#---------------------------------------------------------------------------
data1 = 2.*Numeric.pi*Numeric.arange(200)/200.
data1.shape = (100, 2)
data1[:,1] = Numeric.sin(data1[:,0])
- markers1 = PolyMarker(data1, color='green', marker='circle',size=1)
+ markers1 = plot.PolyMarker(data1, color='green', marker='circle',size=1)
# 50 points cos function, plotted as red line
data1 = 2.*Numeric.pi*Numeric.arange(100)/100.
data1.shape = (50,2)
data1[:,1] = Numeric.cos(data1[:,0])
- lines = PolyLine(data1, color='red')
+ lines = plot.PolyLine(data1, color='red')
# A few more points...
pi = Numeric.pi
- markers2 = PolyMarker([(0., 0.), (pi/4., 1.), (pi/2, 0.),
+ markers2 = plot.PolyMarker([(0., 0.), (pi/4., 1.), (pi/2, 0.),
(3.*pi/4., -1)], color='blue',
fillcolor='green', marker='cross')
- return PlotGraphics([markers1, lines, markers2])
+ return plot.PlotGraphics([markers1, lines, markers2])
#---------------------------------------------------------------------------
def runTest(frame, nb, log):
- win = PlotCanvas(nb)
+ win = plot.PlotCanvas(nb)
win.draw(_InitObjects(),'automatic','automatic');
return win
-overview = wxPlotCanvas.__doc__
+overview = plot.__doc__
#---------------------------------------------------------------------------
-
-
if __name__ == '__main__':
import sys,os
import run
-from wxPython.wx import *
-from wxPython.lib.popupctl import wxPopupControl
-from wxPython.calendar import *
-
-class TestDateControl(wxPopupControl):
+# 11/20/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+# 11/30/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Is it just me or are the graphics for the control not lining up right?
+#
+
+import wx
+import wx.lib.popupctl as pop
+import wx.calendar as cal
+
+class TestDateControl(pop.wxPopupControl):
def __init__(self,*_args,**_kwargs):
- apply(wxPopupControl.__init__,(self,) + _args,_kwargs)
+ apply(pop.wxPopupControl.__init__,(self,) + _args,_kwargs)
- self.win = wxWindow(self,-1,pos = (0,0),style = 0)
- self.cal = wxCalendarCtrl(self.win,-1,pos = (0,0))
+ self.win = wx.Window(self,-1,pos = (0,0),style = 0)
+ self.cal = cal.CalendarCtrl(self.win,-1,pos = (0,0))
bz = self.cal.GetBestSize()
self.win.SetSize(bz)
self.SetPopupContent(self.win)
# Event registration for date selection
- EVT_CALENDAR_DAY(self.cal,self.cal.GetId(),self.OnCalSelected)
+ self.cal.Bind(cal.EVT_CALENDAR_DAY, self.OnCalSelected)
# Method called when a day is selected in the calendar
def OnCalSelected(self,evt):
txtValue = self.GetValue()
dmy = txtValue.split('/')
didSet = False
+
if len(dmy) == 3:
date = self.cal.GetDate()
d = int(dmy[0])
m = int(dmy[1]) - 1
y = int(dmy[2])
+
if d > 0 and d < 31:
if m >= 0 and m < 12:
if y > 1000:
- self.cal.SetDate(wxDateTimeFromDMY(d,m,y))
+ self.cal.SetDate(wx.DateTimeFromDMY(d,m,y))
didSet = True
+
if not didSet:
- self.cal.SetDate(wxDateTime_Today())
+ self.cal.SetDate(wx.DateTime_Today())
#---------------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
self.log = log
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
date = TestDateControl(self, -1, pos = (30,30), size = (100,22))
#----------------------------------------------------------------------
#----------------------------------------------------------------------
-
-
overview = """<html><body>
<h2><center>wxPopupControl</center></h2>
"""
-
if __name__ == '__main__':
import sys,os
import run
-from wxPython.wx import *
+# 11/20/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+# 11/30/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Some issues with the listbox example; I tried correcting
+# it but it's still not working the way it should. Commented
+# out for now but will be revisited.
+# o The math in determining the popup window's position is
+# a bit off.
+#
+
+import wx
havePopupWindow = 1
try:
- wxPopupWindow
+ wx.PopupWindow
except NameError:
havePopupWindow = 0
- wxPopupWindow = wxPopupTransientWindow = wxWindow
+ wx.PopupWindow = wx.PopupTransientWindow = wx.Window
#---------------------------------------------------------------------------
-class TestPopup(wxPopupWindow):
+class TestPopup(wx.PopupWindow):
"""Adds a bit of text and mouse movement to the wxPopupWindow"""
def __init__(self, parent, style):
- wxPopupWindow.__init__(self, parent, style)
+ wx.PopupWindow.__init__(self, parent, style)
self.SetBackgroundColour("CADET BLUE")
- st = wxStaticText(self, -1,
+
+ st = wx.StaticText(self, -1,
"This is a special kind of top level\n"
"window that can be used for\n"
"popup menus, combobox popups\n"
"and closed with the right."
,
pos=(10,10))
+
sz = st.GetBestSize()
self.SetSize( (sz.width+20, sz.height+20) )
- EVT_LEFT_DOWN(self, self.OnMouseLeftDown)
- EVT_MOTION(self, self.OnMouseMotion)
- EVT_LEFT_UP(self, self.OnMouseLeftUp)
- EVT_RIGHT_UP(self, self.OnRightUp)
- EVT_LEFT_DOWN(st, self.OnMouseLeftDown)
- EVT_MOTION(st, self.OnMouseMotion)
- EVT_LEFT_UP(st, self.OnMouseLeftUp)
- EVT_RIGHT_UP(st, self.OnRightUp)
+ self.Bind(wx.EVT_LEFT_DOWN, self.OnMouseLeftDown)
+ self.Bind(wx.EVT_MOTION, self.OnMouseMotion)
+ self.Bind(wx.EVT_LEFT_UP, self.OnMouseLeftUp)
+ self.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
+
+ st.Bind(wx.EVT_LEFT_DOWN, self.OnMouseLeftDown)
+ st.Bind(wx.EVT_MOTION, self.OnMouseMotion)
+ st.Bind(wx.EVT_LEFT_UP, self.OnMouseLeftUp)
+ st.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
def OnMouseLeftDown(self, evt):
self.ldPos = evt.GetEventObject().ClientToScreen(evt.GetPosition())
self.Destroy()
-class TestTransientPopup(wxPopupTransientWindow):
+class TestTransientPopup(wx.PopupTransientWindow):
"""Adds a bit of text and mouse movement to the wxPopupWindow"""
def __init__(self, parent, style, log):
- wxPopupTransientWindow.__init__(self, parent, style)
+ wx.PopupTransientWindow.__init__(self, parent, style)
self.log = log
- panel = wxPanel(self, -1)
+ panel = wx.Panel(self, -1)
panel.SetBackgroundColour("#FFB6C1")
- st = wxStaticText(panel, -1,
+ st = wx.StaticText(panel, -1,
"wxPopupTransientWindow is a\n"
"wxPopupWindow which disappears\n"
"automatically when the user\n"
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.log = log
- b = wxButton(self, -1, "Show wxPopupWindow", (25, 50))
- EVT_BUTTON(self, b.GetId(), self.OnShowPopup)
+ b = wx.Button(self, -1, "Show wxPopupWindow", (25, 50))
+ self.Bind(wx.EVT_BUTTON, self.OnShowPopup, b)
- b = wxButton(self, -1, "Show wxPopupTransientWindow", (25, 95))
- EVT_BUTTON(self, b.GetId(), self.OnShowPopupTransient)
+ b = wx.Button(self, -1, "Show wxPopupTransientWindow", (25, 95))
+ self.Bind(wx.EVT_BUTTON, self.OnShowPopupTransient, b)
- if 0:
- b = wxButton(self, -1, "Show wxPopupWindow with listbox", (25, 140))
- EVT_BUTTON(self, b.GetId(), self.OnShowPopupListbox)
+ # This isn't working so well, not sure why. Commented out for
+ # now.
+
+# b = wx.Button(self, -1, "Show wxPopupWindow with listbox", (25, 140))
+# self.Bind(wx.EVT_BUTTON, self.OnShowPopupListbox, b)
def OnShowPopup(self, evt):
- win = TestPopup(self, wxSIMPLE_BORDER)
+ win = TestPopup(self, wx.SIMPLE_BORDER)
# Show the popup right below or above the button
# depending on available screen space...
btn = evt.GetEventObject()
pos = btn.ClientToScreen( (0,0) )
sz = btn.GetSize()
- win.Position(pos, (0, sz.height))
+ win.Position(pos, (0, sz[1]))
win.Show(True)
def OnShowPopupTransient(self, evt):
- win = TestTransientPopup(self, wxSIMPLE_BORDER, self.log)
+ win = TestTransientPopup(self, wx.SIMPLE_BORDER, self.log)
# Show the popup right below or above the button
# depending on available screen space...
btn = evt.GetEventObject()
pos = btn.ClientToScreen( (0,0) )
sz = btn.GetSize()
- win.Position(pos, (0, sz.height))
+ win.Position(pos, (0, sz[1]))
win.Popup()
def OnShowPopupListbox(self, evt):
- win = TestPopupWithListbox(self, wxNO_BORDER, self.log)
+ win = TestPopupWithListbox(self, wx.NO_BORDER, self.log)
# Show the popup right below or above the button
# depending on available screen space...
btn = evt.GetEventObject()
pos = btn.ClientToScreen( (0,0) )
sz = btn.GetSize()
- win.Position(pos, (0, sz.height))
+ win.Position(pos, (0, sz[1]))
win.Show(True)
-class TestPopupWithListbox(wxPopupWindow):
+class TestPopupWithListbox(wx.PopupWindow):
def __init__(self, parent, style, log):
- wxPopupWindow.__init__(self, parent, style)
+ wx.PopupWindow.__init__(self, parent, style)
+
import keyword
- self.lb = wxListBox(self, -1, choices = keyword.kwlist)
+
+ self.lb = wx.ListBox(self, -1, choices = keyword.kwlist)
#sz = self.lb.GetBestSize()
self.SetSize((150, 75)) #sz)
self.lb.SetSize(self.GetClientSize())
self.lb.SetFocus()
- EVT_LEFT_DOWN(self.lb, self.OnLeft)
- EVT_LISTBOX(self, -1, self.OnListBox)
+ self.Bind(wx.EVT_LISTBOX, self.OnListBox)
+ self.lb.Bind(wx.EVT_LEFT_DOWN, self.OnLeft)
def OnLeft(self, evt):
- print "OnLeft", evt.GetEventObject()
+ obj = evt.GetEventObject()
+ print "OnLeft", obj
+ print 'Selected: %s' % obj.GetStringSelection()
+ obj.Show(False)
evt.Skip()
+
def OnListBox(self, evt):
- print "OnListBox", evt.GetEventObject()
+ obj = evt.GetEventObject()
+ print "OnListBox", obj
+ print 'Selected: %s' % obj.GetString()
evt.Skip()
win = TestPanel(nb, log)
return win
else:
- dlg = wxMessageDialog(frame, 'wxPopupWindow is not available on this platform.',
- 'Sorry', wxOK | wxICON_INFORMATION)
+ dlg = wx.MessageDialog(
+ frame, 'wxPopupWindow is not available on this platform.',
+ 'Sorry', wx.OK | wx.ICON_INFORMATION
+ )
+
dlg.ShowModal()
dlg.Destroy()
#---------------------------------------------------------------------------
-
-
overview = """\
"""
-
-
if __name__ == '__main__':
import sys,os
import run
+# 11/20/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
-
+import wx
#---------------------------------------------------------------------------
def runTest(frame, nb, log):
- data = wxPrintDialogData()
+ data = wx.PrintDialogData()
data.EnableSelection(True)
data.EnablePrintToFile(True)
data.SetMaxPage(5)
data.SetAllPages(True)
- dlg = wxPrintDialog(frame, data)
- if dlg.ShowModal() == wxID_OK:
+ dlg = wx.PrintDialog(frame, data)
+
+ if dlg.ShowModal() == wx.ID_OK:
data = dlg.GetPrintDialogData()
log.WriteText('GetAllPages: %d\n' % data.GetAllPages())
+
dlg.Destroy()
#---------------------------------------------------------------------------
+overview = """\
+This class represents the print and print setup common dialogs. You may obtain
+a wxPrinterDC device context from a successfully dismissed print dialog.
+User information is stored in a wxPrintDialogData object that is passed to the
+dialog at creation time, and it is filled in by the user. As with other dialogs,
+do not use this data once the dialog is dismissed, and do not destroy the dialog
+until you have everything you need from it.
-overview = """\
"""
-
if __name__ == '__main__':
import sys,os
import run
+# 11/20/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
+import wx
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, ID, log):
- wxPanel.__init__(self, parent, ID)
+ wx.Panel.__init__(self, parent, ID)
self.log = log
self.process = None
- EVT_IDLE(self, self.OnIdle)
+ self.Bind(wx.EVT_IDLE, self.OnIdle)
# We can either derive from wxProcess and override OnTerminate
# or we can let wxProcess send this window an event that is
# caught in the normal way...
- EVT_END_PROCESS(self, -1, self.OnProcessEnded)
+ self.Bind(wx.EVT_END_PROCESS, self.OnProcessEnded)
# Make the controls
- prompt = wxStaticText(self, -1, 'Command line:')
- self.cmd = wxTextCtrl(self, -1, 'python -u data/echo.py')
- self.exBtn = wxButton(self, -1, 'Execute')
+ prompt = wx.StaticText(self, -1, 'Command line:')
+ self.cmd = wx.TextCtrl(self, -1, 'python -u data/echo.py')
+ self.exBtn = wx.Button(self, -1, 'Execute')
- self.out = wxTextCtrl(self, -1, '', style=wxTE_MULTILINE|wxTE_READONLY)
+ self.out = wx.TextCtrl(self, -1, '', style=wx.TE_MULTILINE|wx.TE_READONLY)
- self.inp = wxTextCtrl(self, -1, '', style=wxTE_PROCESS_ENTER)
- self.sndBtn = wxButton(self, -1, 'Send')
- self.termBtn = wxButton(self, -1, 'Close Stream')
+ self.inp = wx.TextCtrl(self, -1, '', style=wx.TE_PROCESS_ENTER)
+ self.sndBtn = wx.Button(self, -1, 'Send')
+ self.termBtn = wx.Button(self, -1, 'Close Stream')
self.inp.Enable(False)
self.sndBtn.Enable(False)
self.termBtn.Enable(False)
# Hook up the events
- EVT_BUTTON(self, self.exBtn.GetId(), self.OnExecuteBtn)
- EVT_BUTTON(self, self.sndBtn.GetId(), self.OnSendText)
- EVT_BUTTON(self, self.termBtn.GetId(), self.OnCloseStream)
- EVT_TEXT_ENTER(self, self.inp.GetId(), self.OnSendText)
+ self.Bind(wx.EVT_BUTTON, self.OnExecuteBtn, self.exBtn)
+ self.Bind(wx.EVT_BUTTON, self.OnSendText, self.sndBtn)
+ self.Bind(wx.EVT_BUTTON, self.OnCloseStream, self.termBtn)
+ self.Bind(wx.EVT_TEXT_ENTER, self.OnSendText, self.inp)
# Do the layout
- box1 = wxBoxSizer(wxHORIZONTAL)
- box1.Add(prompt, 0, wxALIGN_CENTER)
- box1.Add(self.cmd, 1, wxALIGN_CENTER|wxLEFT|wxRIGHT, 5)
+ box1 = wx.BoxSizer(wx.HORIZONTAL)
+ box1.Add(prompt, 0, wx.ALIGN_CENTER)
+ box1.Add(self.cmd, 1, wx.ALIGN_CENTER|wx.LEFT|wx.RIGHT, 5)
box1.Add(self.exBtn, 0)
- box2 = wxBoxSizer(wxHORIZONTAL)
- box2.Add(self.inp, 1, wxALIGN_CENTER)
- box2.Add(self.sndBtn, 0, wxLEFT, 5)
- box2.Add(self.termBtn, 0, wxLEFT, 5)
+ box2 = wx.BoxSizer(wx.HORIZONTAL)
+ box2.Add(self.inp, 1, wx.ALIGN_CENTER)
+ box2.Add(self.sndBtn, 0, wx.LEFT, 5)
+ box2.Add(self.termBtn, 0, wx.LEFT, 5)
- sizer = wxBoxSizer(wxVERTICAL)
- sizer.Add(box1, 0, wxEXPAND|wxALL, 10)
- sizer.Add(self.out, 1, wxEXPAND|wxALL, 10)
- sizer.Add(box2, 0, wxEXPAND|wxALL, 10)
+ sizer = wx.BoxSizer(wx.VERTICAL)
+ sizer.Add(box1, 0, wx.EXPAND|wx.ALL, 10)
+ sizer.Add(self.out, 1, wx.EXPAND|wx.ALL, 10)
+ sizer.Add(box2, 0, wx.EXPAND|wx.ALL, 10)
self.SetSizer(sizer)
self.SetAutoLayout(True)
def OnExecuteBtn(self, evt):
cmd = self.cmd.GetValue()
- self.process = wxProcess(self)
+ self.process = wx.Process(self)
self.process.Redirect();
- pid = wxExecute(cmd, wxEXEC_ASYNC, self.process)
+ pid = wx.Execute(cmd, wx.EXEC_ASYNC, self.process)
self.log.write('OnExecuteBtn: "%s" pid: %s\n' % (cmd, pid))
self.inp.Enable(True)
(evt.GetPid(), evt.GetExitCode()))
stream = self.process.GetInputStream()
+
if stream.CanRead():
text = stream.read()
self.out.AppendText(text)
"""
-
-
-
if __name__ == '__main__':
import sys,os
import run
-
-from wxPython.wx import *
+# 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+# 11/30/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o wx.ProgressDialog appears to be broken. No abort button
+# and it's not possible to dismiss it otherwise.
+#
+
+import wx
#---------------------------------------------------------------------------
def runTest(frame, nb, log):
max = 20
- dlg = wxProgressDialog("Progress dialog example",
+
+ dlg = wx.ProgressDialog("Progress dialog example",
"An informative message",
- max,
- frame,
- wxPD_CAN_ABORT | wxPD_APP_MODAL)
+ maximum = max,
+ parent=frame,
+ style = wx.PD_CAN_ABORT | wx.PD_APP_MODAL)
keepGoing = True
count = 0
+
while keepGoing and count < max:
count = count + 1
- wxSleep(1)
+ #print count
+ wx.Sleep(1)
if count == max / 2:
keepGoing = dlg.Update(count, "Half-time!")
#---------------------------------------------------------------------------
-
-
overview = """\
-"""
+This class represents a dialog that shows a short message and a progress bar.
+Optionally, it can display an ABORT button
+
+This dialog indicates the progress of some event that takes a while to accomplish,
+usually, such as file copy progress, download progress, and so on. The display
+is <b>completely</b> under control of the program; you must update the dialog from
+within the program creating it.
+When the dialog closes, you must check to see if the user aborted the process or
+not, and act accordingly -- that is, if the PD_CAN_ABORT style flag is set.
+If not then you may progress blissfully onward.
+"""
if __name__ == '__main__':
import sys,os
-from wxPython.wx import *
-from wxPython.lib.colourchooser import wxPyColourChooser
+# 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+# 11/30/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o wx renamer not applied to library.
+#
+
+import wx
+import wx.lib.colourchooser as cc
#---------------------------------------------------------------
-class TestColourChooser(wxPanel):
+class TestColourChooser(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.log = log
- chooser = wxPyColourChooser(self, -1)
- sizer = wxBoxSizer(wxVERTICAL)
- sizer.Add(chooser, 0, wxALL, 25)
+ chooser = cc.wxPyColourChooser(self, -1)
+ sizer = wx.BoxSizer(wx.VERTICAL)
+ sizer.Add(chooser, 0, wx.ALL, 25)
self.SetAutoLayout(True)
self.SetSizer(sizer)
+# 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
+import wx
#---------------------------------------------------------------------------
-RBUT1 = wxNewId()
-RBUT2 = wxNewId()
-RBUT3 = wxNewId()
-RBUT4 = wxNewId()
-
-RBOX1 = wxNewId()
-RBOX2 = wxNewId()
-
-class TestRadioButtons(wxPanel):
+class TestRadioBox(wx.Panel):
def __init__(self, parent, log):
self.log = log
- wxPanel.__init__(self, parent, -1)
- #self.SetBackgroundColour(wxBLUE)
+ wx.Panel.__init__(self, parent, -1)
+ #self.SetBackgroundColour(wx.BLUE)
sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
'six', 'seven', 'eight']
- sizer = wxBoxSizer(wxVERTICAL)
- rb = wxRadioBox(self, RBOX1, "wxRadioBox",
- wxDefaultPosition, wxDefaultSize,
- sampleList, 2, wxRA_SPECIFY_COLS)
- EVT_RADIOBOX(self, RBOX1, self.EvtRadioBox)
- #rb.SetBackgroundColour(wxBLUE)
- rb.SetToolTip(wxToolTip("This is a ToolTip!"))
+ sizer = wx.BoxSizer(wx.VERTICAL)
+
+ rb = wx.RadioBox(
+ self, -1, "wx.RadioBox", wx.DefaultPosition, wx.DefaultSize,
+ sampleList, 2, wx.RA_SPECIFY_COLS
+ )
+
+ self.Bind(wx.EVT_RADIOBOX, self.EvtRadioBox, rb)
+ #rb.SetBackgroundColour(wx.BLUE)
+ rb.SetToolTip(wx.ToolTip("This is a ToolTip!"))
#rb.SetLabel("wxRadioBox")
- sizer.Add(rb, 0, wxALL, 20)
- rb = wxRadioBox(self, RBOX2, "", wxDefaultPosition, wxDefaultSize,
- sampleList, 3, wxRA_SPECIFY_COLS | wxNO_BORDER)
- EVT_RADIOBOX(self, RBOX2, self.EvtRadioBox)
- rb.SetToolTip(wxToolTip("This box has no label"))
- sizer.Add(rb, 0, wxLEFT|wxRIGHT|wxBOTTOM, 20)
+ sizer.Add(rb, 0, wx.ALL, 20)
+
+ rb = wx.RadioBox(
+ self, -1, "", wx.DefaultPosition, wx.DefaultSize,
+ sampleList, 3, wx.RA_SPECIFY_COLS | wx.NO_BORDER
+ )
+
+ self.Bind(wx.EVT_RADIOBOX, self.EvtRadioBox, rb)
+ rb.SetToolTip(wx.ToolTip("This box has no label"))
+
+ sizer.Add(rb, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 20)
self.SetSizer(sizer)
def EvtRadioBox(self, event):
self.log.WriteText('EvtRadioBox: %d\n' % event.GetInt())
- def EvtRadioButton(self, event):
- self.log.write('EvtRadioButton:%d\n' % event.GetId())
+# Doesn't appear to be used for anything.
+# def EvtRadioButton(self, event):
+# self.log.write('EvtRadioButton:%d\n' % event.GetId())
#---------------------------------------------------------------------------
def runTest(frame, nb, log):
- win = TestRadioButtons(nb, log)
+ win = TestRadioBox(nb, log)
return win
"""
-
if __name__ == '__main__':
import sys,os
import run
-from wxPython.wx import *
+# 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+
+import wx
+
#----------------------------------------------------------------------
-class TestPanel( wxPanel ):
+class TestPanel( wx.Panel ):
def __init__( self, parent, log ):
- wxPanel.__init__( self, parent, -1 )
+ wx.Panel.__init__( self, parent, -1 )
self.log = log
- panel = wxPanel( self, -1 )
+ panel = wx.Panel( self, -1 )
# 1st group of controls:
self.group1_ctrls = []
- radio1 = wxRadioButton( panel, -1, " Radio1 ", style = wxRB_GROUP )
- text1 = wxTextCtrl( panel, -1, "" )
- radio2 = wxRadioButton( panel, -1, " Radio2 " )
- text2 = wxTextCtrl( panel, -1, "" )
- radio3 = wxRadioButton( panel, -1, " Radio3 " )
- text3 = wxTextCtrl( panel, -1, "" )
+ radio1 = wx.RadioButton( panel, -1, " Radio1 ", style = wx.RB_GROUP )
+ text1 = wx.TextCtrl( panel, -1, "" )
+ radio2 = wx.RadioButton( panel, -1, " Radio2 " )
+ text2 = wx.TextCtrl( panel, -1, "" )
+ radio3 = wx.RadioButton( panel, -1, " Radio3 " )
+ text3 = wx.TextCtrl( panel, -1, "" )
self.group1_ctrls.append((radio1, text1))
self.group1_ctrls.append((radio2, text2))
self.group1_ctrls.append((radio3, text3))
# 2nd group of controls:
self.group2_ctrls = []
- radio4 = wxRadioButton( panel, -1, " Radio1 ", style = wxRB_GROUP )
- text4 = wxTextCtrl( panel, -1, "" )
- radio5 = wxRadioButton( panel, -1, " Radio2 " )
- text5 = wxTextCtrl( panel, -1, "" )
- radio6 = wxRadioButton( panel, -1, " Radio3 " )
- text6 = wxTextCtrl( panel, -1, "" )
+ radio4 = wx.RadioButton( panel, -1, " Radio1 ", style = wx.RB_GROUP )
+ text4 = wx.TextCtrl( panel, -1, "" )
+ radio5 = wx.RadioButton( panel, -1, " Radio2 " )
+ text5 = wx.TextCtrl( panel, -1, "" )
+ radio6 = wx.RadioButton( panel, -1, " Radio3 " )
+ text6 = wx.TextCtrl( panel, -1, "" )
self.group2_ctrls.append((radio4, text4))
self.group2_ctrls.append((radio5, text5))
self.group2_ctrls.append((radio6, text6))
# Layout controls on panel:
- vs = wxBoxSizer( wxVERTICAL )
+ vs = wx.BoxSizer( wx.VERTICAL )
+
+ box1_title = wx.StaticBox( panel, -1, "Group 1" )
+ box1 = wx.StaticBoxSizer( box1_title, wx.VERTICAL )
+ grid1 = wx.FlexGridSizer( 0, 2, 0, 0 )
- box1_title = wxStaticBox( panel, -1, "Group 1" )
- box1 = wxStaticBoxSizer( box1_title, wxVERTICAL )
- grid1 = wxFlexGridSizer( 0, 2, 0, 0 )
for radio, text in self.group1_ctrls:
- grid1.AddWindow( radio, 0, wxALIGN_CENTRE|wxLEFT|wxRIGHT|wxTOP, 5 )
- grid1.AddWindow( text, 0, wxALIGN_CENTRE|wxLEFT|wxRIGHT|wxTOP, 5 )
- box1.AddSizer( grid1, 0, wxALIGN_CENTRE|wxALL, 5 )
- vs.AddSizer( box1, 0, wxALIGN_CENTRE|wxALL, 5 )
-
- box2_title = wxStaticBox( panel, -1, "Group 2" )
- box2 = wxStaticBoxSizer( box2_title, wxVERTICAL )
- grid2 = wxFlexGridSizer( 0, 2, 0, 0 )
+ grid1.AddWindow( radio, 0, wx.ALIGN_CENTRE|wx.LEFT|wx.RIGHT|wx.TOP, 5 )
+ grid1.AddWindow( text, 0, wx.ALIGN_CENTRE|wx.LEFT|wx.RIGHT|wx.TOP, 5 )
+
+ box1.AddSizer( grid1, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
+ vs.AddSizer( box1, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
+
+ box2_title = wx.StaticBox( panel, -1, "Group 2" )
+ box2 = wx.StaticBoxSizer( box2_title, wx.VERTICAL )
+ grid2 = wx.FlexGridSizer( 0, 2, 0, 0 )
+
for radio, text in self.group2_ctrls:
- grid2.AddWindow( radio, 0, wxALIGN_CENTRE|wxLEFT|wxRIGHT|wxTOP, 5 )
- grid2.AddWindow( text, 0, wxALIGN_CENTRE|wxLEFT|wxRIGHT|wxTOP, 5 )
- box2.AddSizer( grid2, 0, wxALIGN_CENTRE|wxALL, 5 )
- vs.AddSizer( box2, 0, wxALIGN_CENTRE|wxALL, 5 )
+ grid2.AddWindow( radio, 0, wx.ALIGN_CENTRE|wx.LEFT|wx.RIGHT|wx.TOP, 5 )
+ grid2.AddWindow( text, 0, wx.ALIGN_CENTRE|wx.LEFT|wx.RIGHT|wx.TOP, 5 )
+
+ box2.AddSizer( grid2, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
+ vs.AddSizer( box2, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
panel.SetSizer( vs )
vs.Fit( panel )
# Setup event handling and initial state for controls:
for radio, text in self.group1_ctrls:
- EVT_RADIOBUTTON( self, radio.GetId(), self.OnGroup1Select )
+ self.Bind(wx.EVT_RADIOBUTTON, self.OnGroup1Select, radio )
for radio, text in self.group2_ctrls:
- EVT_RADIOBUTTON( self, radio.GetId(), self.OnGroup2Select )
+ self.Bind(wx.EVT_RADIOBUTTON, self.OnGroup2Select, radio )
for radio, text in self.group1_ctrls + self.group2_ctrls:
radio.SetValue(0)
text.Enable(False)
-
def OnGroup1Select( self, event ):
radio_selected = event.GetEventObject()
self.log.write('Group1 %s selected\n' % radio_selected.GetLabel() )
+
for radio, text in self.group1_ctrls:
if radio is radio_selected:
text.Enable(True)
def OnGroup2Select( self, event ):
radio_selected = event.GetEventObject()
self.log.write('Group2 %s selected\n' % radio_selected.GetLabel() )
+
for radio, text in self.group2_ctrls:
if radio is radio_selected:
text.Enable(True)
-
-from wxPython.wx import *
-from wxPython.lib.rightalign import wxRightTextCtrl
-import wxPython.lib.rightalign
-
+# 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+# 11/30/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o The rightalign library needs converted for this to work correctly.
+#
+
+############################################################################\
+# Note: this demo has been converted, but the control is deprecated because |
+# wx.TextCtrl now supports the wx.TE_RIGHT style flag, which makes this |
+# control completely superfluous. |
+############################################################################/
+
+import wx
+import wx.lib.rightalign as right
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
+
+ fgs = wx.FlexGridSizer(cols=2, vgap=5, hgap=5)
+
+ txt = wx.StaticText(
+ self, -1,
+ "These text controls will align their contents to\n"
+ "the right (on wxMSW) when they don't have focus.",
+ style=wx.ALIGN_RIGHT
+ )
- fgs = wxFlexGridSizer(cols=2, vgap=5, hgap=5)
- txt = wxStaticText(self, -1,
- "These text controls will align their contents to\n"
- "the right (on wxMSW) when they don't have focus.", style=wxALIGN_RIGHT )
fgs.Add(txt)
- fgs.Add(wxRightTextCtrl(self, -1, "", size=(75, -1)))
+ fgs.Add(right.wxRightTextCtrl(self, -1, "", size=(75, -1)))
- fgs.Add(10,10)
- fgs.Add(wxRightTextCtrl(self, -1, "123.45", size=(75, -1)))
+ fgs.Add((10,10))
+ fgs.Add(right.wxRightTextCtrl(self, -1, "123.45", size=(75, -1)))
- fgs.Add(10,10)
- fgs.Add(wxRightTextCtrl(self, -1, "234.56", size=(75, -1)))
+ fgs.Add((10,10))
+ fgs.Add(right.wxRightTextCtrl(self, -1, "234.56", size=(75, -1)))
- fgs.Add(10,10)
- fgs.Add(wxRightTextCtrl(self, -1, "345.67", size=(75, -1)))
+ fgs.Add((10,10))
+ fgs.Add(right.wxRightTextCtrl(self, -1, "345.67", size=(75, -1)))
- fgs.Add(10,10)
- fgs.Add(wxRightTextCtrl(self, -1, "456.78", size=(75, -1)))
+ fgs.Add((10,10))
+ fgs.Add(right.wxRightTextCtrl(self, -1, "456.78", size=(75, -1)))
- sizer = wxBoxSizer(wxVERTICAL)
- sizer.Add(fgs, 0, wxALL, 25)
+ sizer = wx.BoxSizer(wx.VERTICAL)
+ sizer.Add(fgs, 0, wx.ALL, 25)
self.SetSizer(sizer)
self.SetAutoLayout(True)
#----------------------------------------------------------------------
-overview = wxPython.lib.rightalign.__doc__
-
-
+overview = right.__doc__
if __name__ == '__main__':
+# 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+# o Should be renamed to wxSashLayoutWindow.py
+#
-from wxPython.wx import *
+import wx
#---------------------------------------------------------------------------
-class TestSashWindow(wxPanel):
+class TestSashWindow(wx.Panel):
ID_WINDOW_TOP = 5100
ID_WINDOW_LEFT1 = 5101
ID_WINDOW_LEFT2 = 5102
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.log = log
# will occupy the space not used by the Layout Algorithm
- self.remainingSpace = wxPanel(self, -1, style=wxSUNKEN_BORDER)
+ self.remainingSpace = wx.Panel(self, -1, style=wx.SUNKEN_BORDER)
- EVT_SASH_DRAGGED_RANGE(self, self.ID_WINDOW_TOP,
- self.ID_WINDOW_BOTTOM, self.OnSashDrag)
- EVT_SIZE(self, self.OnSize)
+ self.Bind(
+ wx.EVT_SASH_DRAGGED_RANGE, self.OnSashDrag,
+ id=self.ID_WINDOW_TOP, id2=self.ID_WINDOW_BOTTOM,
+ )
+
+ self.Bind(wx.EVT_SIZE, self.OnSize)
# Create some layout windows
# A window like a toolbar
- win = wxSashLayoutWindow(self, self.ID_WINDOW_TOP, wxDefaultPosition,
- wxSize(200, 30), wxNO_BORDER|wxSW_3D)
- win.SetDefaultSize(wxSize(1000, 30))
- win.SetOrientation(wxLAYOUT_HORIZONTAL)
- win.SetAlignment(wxLAYOUT_TOP)
- win.SetBackgroundColour(wxColour(255, 0, 0))
- win.SetSashVisible(wxSASH_BOTTOM, True)
+ win = wx.SashLayoutWindow(
+ self, self.ID_WINDOW_TOP, wx.DefaultPosition, (200, 30),
+ wx.NO_BORDER|wx.SW_3D
+ )
+
+ win.SetDefaultSize((1000, 30))
+ win.SetOrientation(wx.LAYOUT_HORIZONTAL)
+ win.SetAlignment(wx.LAYOUT_TOP)
+ win.SetBackgroundColour(wx.Colour(255, 0, 0))
+ win.SetSashVisible(wx.SASH_BOTTOM, True)
self.topWindow = win
# A window like a statusbar
- win = wxSashLayoutWindow(self, self.ID_WINDOW_BOTTOM,
- wxDefaultPosition, wxSize(200, 30),
- wxNO_BORDER|wxSW_3D)
- win.SetDefaultSize(wxSize(1000, 30))
- win.SetOrientation(wxLAYOUT_HORIZONTAL)
- win.SetAlignment(wxLAYOUT_BOTTOM)
- win.SetBackgroundColour(wxColour(0, 0, 255))
- win.SetSashVisible(wxSASH_TOP, True)
+ win = wx.SashLayoutWindow(
+ self, self.ID_WINDOW_BOTTOM, wx.DefaultPosition, (200, 30),
+ wx.NO_BORDER|wx.SW_3D
+ )
- self.bottomWindow = win
+ win.SetDefaultSize((1000, 30))
+ win.SetOrientation(wx.LAYOUT_HORIZONTAL)
+ win.SetAlignment(wx.LAYOUT_BOTTOM)
+ win.SetBackgroundColour(wx.Colour(0, 0, 255))
+ win.SetSashVisible(wx.SASH_TOP, True)
+ self.bottomWindow = win
# A window to the left of the client window
- win = wxSashLayoutWindow(self, self.ID_WINDOW_LEFT1,
- wxDefaultPosition, wxSize(200, 30),
- wxNO_BORDER|wxSW_3D)
- win.SetDefaultSize(wxSize(120, 1000))
- win.SetOrientation(wxLAYOUT_VERTICAL)
- win.SetAlignment(wxLAYOUT_LEFT)
- win.SetBackgroundColour(wxColour(0, 255, 0))
- win.SetSashVisible(wxSASH_RIGHT, True)
+ win = wx.SashLayoutWindow(
+ self, self.ID_WINDOW_LEFT1, wx.DefaultPosition, (200, 30),
+ wx.NO_BORDER|wx.SW_3D
+ )
+
+ win.SetDefaultSize((120, 1000))
+ win.SetOrientation(wx.LAYOUT_VERTICAL)
+ win.SetAlignment(wx.LAYOUT_LEFT)
+ win.SetBackgroundColour(wx.Colour(0, 255, 0))
+ win.SetSashVisible(wx.SASH_RIGHT, True)
win.SetExtraBorderSize(10)
- textWindow = wxTextCtrl(win, -1, "", wxDefaultPosition, wxDefaultSize,
- wxTE_MULTILINE|wxSUNKEN_BORDER)
+ textWindow = wx.TextCtrl(
+ win, -1, "", wx.DefaultPosition, wx.DefaultSize,
+ wx.TE_MULTILINE|wx.SUNKEN_BORDER
+ )
+
textWindow.SetValue("A sub window")
self.leftWindow1 = win
# Another window to the left of the client window
- win = wxSashLayoutWindow(self, self.ID_WINDOW_LEFT2,
- wxDefaultPosition, wxSize(200, 30),
- wxNO_BORDER|wxSW_3D)
- win.SetDefaultSize(wxSize(120, 1000))
- win.SetOrientation(wxLAYOUT_VERTICAL)
- win.SetAlignment(wxLAYOUT_LEFT)
- win.SetBackgroundColour(wxColour(0, 255, 255))
- win.SetSashVisible(wxSASH_RIGHT, True)
+ win = wx.SashLayoutWindow(
+ self, self.ID_WINDOW_LEFT2, wx.DefaultPosition, (200, 30),
+ wx.NO_BORDER|wx.SW_3D
+ )
+
+ win.SetDefaultSize((120, 1000))
+ win.SetOrientation(wx.LAYOUT_VERTICAL)
+ win.SetAlignment(wx.LAYOUT_LEFT)
+ win.SetBackgroundColour(wx.Colour(0, 255, 255))
+ win.SetSashVisible(wx.SASH_RIGHT, True)
self.leftWindow2 = win
def OnSashDrag(self, event):
- if event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE:
+ if event.GetDragStatus() == wx.SASH_STATUS_OUT_OF_RANGE:
return
eID = event.GetId()
+
if eID == self.ID_WINDOW_TOP:
- self.topWindow.SetDefaultSize(wxSize(1000, event.GetDragRect().height))
+ self.topWindow.SetDefaultSize((1000, event.GetDragRect().height))
elif eID == self.ID_WINDOW_LEFT1:
- self.leftWindow1.SetDefaultSize(wxSize(event.GetDragRect().width, 1000))
+ self.leftWindow1.SetDefaultSize((event.GetDragRect().width, 1000))
elif eID == self.ID_WINDOW_LEFT2:
- self.leftWindow2.SetDefaultSize(wxSize(event.GetDragRect().width, 1000))
+ self.leftWindow2.SetDefaultSize((event.GetDragRect().width, 1000))
elif eID == self.ID_WINDOW_BOTTOM:
- self.bottomWindow.SetDefaultSize(wxSize(1000, event.GetDragRect().height))
+ self.bottomWindow.SetDefaultSize((1000, event.GetDragRect().height))
- wxLayoutAlgorithm().LayoutWindow(self, self.remainingSpace)
+ wx.LayoutAlgorithm().LayoutWindow(self, self.remainingSpace)
self.remainingSpace.Refresh()
def OnSize(self, event):
- wxLayoutAlgorithm().LayoutWindow(self, self.remainingSpace)
+ wx.LayoutAlgorithm().LayoutWindow(self, self.remainingSpace)
#---------------------------------------------------------------------------
#---------------------------------------------------------------------------
-
-
overview = """\
-"""
+wxSashLayoutWindow responds to OnCalculateLayout events generated by
+wxLayoutAlgorithm. It allows the application to use simple accessors to
+specify how the window should be laid out, rather than having to respond
+to events. The fact that the class derives from wxSashWindow allows sashes
+to be used if required, to allow the windows to be user-resizable.
+The documentation for wxLayoutAlgorithm explains the purpose of this class
+in more detail.
+"""
if __name__ == '__main__':
-
-from wxPython.wx import *
-from wxPython.lib.dialogs import wxScrolledMessageDialog
+# 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+# 11/30/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o dialogs library needs updated to wx
+#
+# 12/01/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o dialogs library converted. All is well.
+#
+
+import wx
+import wx.lib.dialogs as dlgs
#---------------------------------------------------------------------------
def runTest(frame, nb, log):
f = open("Main.py", "r")
msg = f.read()
- dlg = wxScrolledMessageDialog(frame, msg, "message test")
+ f.close()
+
+ dlg = dlgs.wxScrolledMessageDialog(frame, msg, "message test")
dlg.ShowModal()
#---------------------------------------------------------------------------
-
-
-
overview = """\
-"""
+<code><b>wxScrolledMessageDialog</b>(parent, msg, caption, pos=wx.DefaultPosition, size=(500,300))</code>
+This class represents a message dialog that uses a wxTextCtrl to display the
+message. This allows more flexible information display without having to be
+as much concerned with layout requirements. A text file can simply be used
+This dialog offers no special attributes or methods beyond those supported
+by wxDialog.
+"""
if __name__ == '__main__':
import sys,os
-from wxPython.wx import *
-from wxPython.lib.scrolledpanel import wxScrolledPanel
+# 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+# 11/30/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o scrolledpanel lib needs wx update
+#
+
+import wx
+import wx.lib.scrolledpanel as scrolled
#----------------------------------------------------------------------
text = "one two buckle my shoe three four shut the door five six pick up sticks seven eight lay them straight nine ten big fat hen"
-class TestPanel(wxScrolledPanel):
+class TestPanel(scrolled.wxScrolledPanel):
def __init__(self, parent, log):
self.log = log
- wxScrolledPanel.__init__(self, parent, -1)
+ scrolled.wxScrolledPanel.__init__(self, parent, -1)
- vbox = wxBoxSizer(wxVERTICAL)
- desc = wxStaticText(self, -1,
+ vbox = wx.BoxSizer(wx.VERTICAL)
+ desc = wx.StaticText(self, -1,
"wxScrolledPanel extends wxScrolledWindow, adding all "
"the necessary bits to set up scroll handling for you.\n\n"
"Here are three fixed size examples of its use. The "
"activated."
)
desc.SetForegroundColour("Blue")
- vbox.Add(desc, 0, wxALIGN_LEFT|wxALL, 5)
- vbox.Add(wxStaticLine(self, -1, size=(1024,-1)), 0, wxALL, 5)
+ vbox.Add(desc, 0, wx.ALIGN_LEFT|wx.ALL, 5)
+ vbox.Add(wx.StaticLine(self, -1, size=(1024,-1)), 0, wx.ALL, 5)
vbox.Add((20,20))
words = text.split()
- panel1 = wxScrolledPanel(self, -1, size=(120,300),
- style = wxTAB_TRAVERSAL|wxSUNKEN_BORDER )
- fgs1 = wxFlexGridSizer(cols=2, vgap=4, hgap=4)
+ panel1 = scrolled.wxScrolledPanel(self, -1, size=(120,300),
+ style = wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER )
+ fgs1 = wx.FlexGridSizer(cols=2, vgap=4, hgap=4)
for word in words:
- label = wxStaticText(panel1, -1, word+":")
- tc = wxTextCtrl(panel1, -1, word, size=(50,-1))
- fgs1.Add(label, flag=wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL)
- fgs1.Add(tc, flag=wxEXPAND|wxRIGHT, border=25)
+ label = wx.StaticText(panel1, -1, word+":")
+ tc = wx.TextCtrl(panel1, -1, word, size=(50,-1))
+ fgs1.Add(label, flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL)
+ fgs1.Add(tc, flag=wx.EXPAND|wx.RIGHT, border=25)
panel1.SetSizer( fgs1 )
panel1.SetAutoLayout(1)
panel1.SetupScrolling( scroll_x=False )
- panel2 = wxScrolledPanel(self, -1, size=(350, 40),
- style = wxTAB_TRAVERSAL|wxSUNKEN_BORDER)
- panel3 = wxScrolledPanel(self, -1, size=(200,100),
- style = wxTAB_TRAVERSAL|wxSUNKEN_BORDER)
+ panel2 = scrolled.wxScrolledPanel(self, -1, size=(350, 40),
+ style = wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER)
+ panel3 = scrolled.wxScrolledPanel(self, -1, size=(200,100),
+ style = wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER)
- fgs2 = wxFlexGridSizer(cols=25, vgap=4, hgap=4)
- fgs3 = wxFlexGridSizer(cols=5, vgap=4, hgap=4)
+ fgs2 = wx.FlexGridSizer(cols=25, vgap=4, hgap=4)
+ fgs3 = wx.FlexGridSizer(cols=5, vgap=4, hgap=4)
for i in range(len(words)):
word = words[i]
if i % 5 != 4:
- label2 = wxStaticText(panel2, -1, word)
- fgs2.Add(label2, flag=wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL)
- label3 = wxStaticText(panel3, -1, word)
- fgs3.Add(label3, flag=wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL)
+ label2 = wx.StaticText(panel2, -1, word)
+ fgs2.Add(label2, flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
+ label3 = wx.StaticText(panel3, -1, word)
+ fgs3.Add(label3, flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
else:
- tc2 = wxTextCtrl(panel2, -1, word, size=(50,-1))
- fgs2.Add(tc2, flag=wxLEFT, border=5)
- tc3 = wxTextCtrl(panel3, -1, word )
- fgs3.Add(tc3, flag=wxLEFT, border=5)
+ tc2 = wx.TextCtrl(panel2, -1, word, size=(50,-1))
+ fgs2.Add(tc2, flag=wx.LEFT, border=5)
+ tc3 = wx.TextCtrl(panel3, -1, word )
+ fgs3.Add(tc3, flag=wx.LEFT, border=5)
panel2.SetSizer( fgs2 )
panel2.SetAutoLayout(1)
hbox.Add(panel1, 0)
hbox.Add((40, 10))
- vbox2 = wxBoxSizer(wxVERTICAL)
+ vbox2 = wx.BoxSizer(wx.VERTICAL)
vbox2.Add(panel2, 0)
vbox2.Add((20, 50))
overview = """<html><body>
wxScrolledPanel fills a "hole" in the implementation of wxScrolledWindow,
providing automatic scrollbar and scrolling behavior and the tab traversal
-management that wxScrolledWindow lacks.
+mangement that wxScrolledWindow lacks.
</body></html>
"""
+# 11/12/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+# o Rudimentary overview doc added.
+#
-from wxPython.wx import *
+import wx
-import images
+import images
BUFFERED = 1
#---------------------------------------------------------------------------
-class MyCanvas(wxScrolledWindow):
- def __init__(self, parent, id = -1, size = wxDefaultSize):
- wxScrolledWindow.__init__(self, parent, id, wxPoint(0, 0), size, wxSUNKEN_BORDER)
+class MyCanvas(wx.ScrolledWindow):
+ def __init__(self, parent, id = -1):
+ wx.ScrolledWindow.__init__(self, parent, id, (0, 0), size=size, style=wx.SUNKEN_BORDER)
self.lines = []
self.maxWidth = 1000
self.drawing = False
self.SetBackgroundColour("WHITE")
- self.SetCursor(wxStockCursor(wxCURSOR_PENCIL))
+ self.SetCursor(wx.StockCursor(wx.CURSOR_PENCIL))
bmp = images.getTest2Bitmap()
- mask = wxMaskColour(bmp, wxBLUE)
+ mask = wx.MaskColour(bmp, wx.BLUE)
bmp.SetMask(mask)
self.bmp = bmp
if BUFFERED:
# Initialize the buffer bitmap. No real DC is needed at this point.
- self.buffer = wxEmptyBitmap(self.maxWidth, self.maxHeight)
- dc = wxBufferedDC(None, self.buffer)
- dc.SetBackground(wxBrush(self.GetBackgroundColour()))
+ self.buffer = wx.EmptyBitmap(self.maxWidth, self.maxHeight)
+ dc = wx.BufferedDC(None, self.buffer)
+ dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
dc.Clear()
self.DoDrawing(dc)
- EVT_LEFT_DOWN(self, self.OnLeftButtonEvent)
- EVT_LEFT_UP(self, self.OnLeftButtonEvent)
- EVT_MOTION(self, self.OnLeftButtonEvent)
- EVT_PAINT(self, self.OnPaint)
- ##EVT_MOUSEWHEEL(self, self.OnWheel)
+ self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftButtonEvent)
+ self.Bind(wx.EVT_LEFT_UP, self.OnLeftButtonEvent)
+ self.Bind(wx.EVT_MOTION, self.OnLeftButtonEvent)
+ self.Bind(wx.EVT_PAINT, self.OnPaint)
def getWidth(self):
def OnPaint(self, event):
if BUFFERED:
# Create a buffered paint DC. It will create the real
- # wxPaintDC and then blit the bitmap to it when dc is
+ # wx.PaintDC and then blit the bitmap to it when dc is
# deleted. Since we don't need to draw anything else
# here that's all there is to it.
- dc = wxBufferedPaintDC(self, self.buffer)
+ dc = wx.BufferedPaintDC(self, self.buffer)
else:
- dc = wxPaintDC(self)
+ dc = wx.PaintDC(self)
self.PrepareDC(dc)
# since we're not buffering in this case, we have to
# paint the whole window, potentially very time consuming.
def DoDrawing(self, dc, printing=False):
dc.BeginDrawing()
- dc.SetPen(wxPen('RED'))
+ dc.SetPen(wx.Pen('RED'))
dc.DrawRectangle((5, 5), (50, 50))
- dc.SetBrush(wxLIGHT_GREY_BRUSH)
- dc.SetPen(wxPen('BLUE', 4))
+ dc.SetBrush(wx.LIGHT_GREY_BRUSH)
+ dc.SetPen(wx.Pen('BLUE', 4))
dc.DrawRectangle((15, 15), (50, 50))
- dc.SetFont(wxFont(14, wxSWISS, wxNORMAL, wxNORMAL))
- dc.SetTextForeground(wxColour(0xFF, 0x20, 0xFF))
+ dc.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.NORMAL))
+ dc.SetTextForeground(wx.Colour(0xFF, 0x20, 0xFF))
te = dc.GetTextExtent("Hello World")
dc.DrawText("Hello World", (60, 65))
- dc.SetPen(wxPen('VIOLET', 4))
+ dc.SetPen(wx.Pen('VIOLET', 4))
dc.DrawLine((5, 65+te[1]), (60+te[0], 65+te[1]))
lst = [(100,110), (150,110), (150,160), (100,160)]
dc.DrawLines(lst, -60)
- dc.SetPen(wxGREY_PEN)
+ dc.SetPen(wx.GREY_PEN)
dc.DrawPolygon(lst, 75)
- dc.SetPen(wxGREEN_PEN)
+ dc.SetPen(wx.GREEN_PEN)
dc.DrawSpline(lst+[(100,100)])
dc.DrawBitmap(self.bmp, (200, 20), True)
- dc.SetTextForeground(wxColour(0, 0xFF, 0x80))
+ dc.SetTextForeground(wx.Colour(0, 0xFF, 0x80))
dc.DrawText("a bitmap", (200, 85))
-## dc.SetFont(wxFont(14, wxSWISS, wxNORMAL, wxNORMAL))
+## dc.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.NORMAL))
## dc.SetTextForeground("BLACK")
-## dc.DrawText("TEST this STRING", 10, 200)
+## dc.DrawText("TEST this STRING", (10, 200))
## print dc.GetFullTextExtent("TEST this STRING")
- font = wxFont(20, wxSWISS, wxNORMAL, wxNORMAL)
+ font = wx.Font(20, wx.SWISS, wx.NORMAL, wx.NORMAL)
dc.SetFont(font)
- dc.SetTextForeground(wxBLACK)
+ dc.SetTextForeground(wx.BLACK)
+
for a in range(0, 360, 45):
dc.DrawRotatedText("Rotated text...", (300, 300), a)
- dc.SetPen(wxTRANSPARENT_PEN)
- dc.SetBrush(wxBLUE_BRUSH)
- dc.DrawRectangle((50,500), (50,50))
- dc.DrawRectangle((100,500), (50,50))
+ dc.SetPen(wx.TRANSPARENT_PEN)
+ dc.SetBrush(wx.BLUE_BRUSH)
+ dc.DrawRectangle((50,500),(50,50))
+ dc.DrawRectangle((100,500),(50,50))
- dc.SetPen(wxPen('RED'))
+ dc.SetPen(wx.Pen('RED'))
dc.DrawEllipticArc((200, 500), (50, 75), 0, 90)
if not printing:
# probably something to do with the pen styles and the scaling
# it does...
y = 20
- for style in [wxDOT, wxLONG_DASH, wxSHORT_DASH, wxDOT_DASH, wxUSER_DASH]:
- pen = wxPen("DARK ORCHID", 1, style)
- if style == wxUSER_DASH:
- pen.SetCap(wxCAP_BUTT)
+
+ for style in [wx.DOT, wx.LONG_DASH, wx.SHORT_DASH, wx.DOT_DASH, wx.USER_DASH]:
+ pen = wx.Pen("DARK ORCHID", 1, style)
+ if style == wx.USER_DASH:
+ pen.SetCap(wx.CAP_BUTT)
pen.SetDashes([1,2])
pen.SetColour("RED")
dc.SetPen(pen)
- dc.DrawLine((300, y), (400, y))
+ dc.DrawLine((300, y), (400, y))
y = y + 10
- dc.SetBrush(wxTRANSPARENT_BRUSH)
- dc.SetPen(wxPen(wxColour(0xFF, 0x20, 0xFF), 1, wxSOLID))
+ dc.SetBrush(wx.TRANSPARENT_BRUSH)
+ dc.SetPen(wx.Pen(wx.Colour(0xFF, 0x20, 0xFF), 1, wx.SOLID))
dc.DrawRectangle((450, 50), (100, 100))
old_pen = dc.GetPen()
- new_pen = wxPen("BLACK", 5)
+ new_pen = wx.Pen("BLACK", 5)
dc.SetPen(new_pen)
dc.DrawRectangle((470, 70), (60, 60))
dc.SetPen(old_pen)
def DrawSavedLines(self, dc):
- dc.SetPen(wxPen('MEDIUM FOREST GREEN', 4))
+ dc.SetPen(wx.Pen('MEDIUM FOREST GREEN', 4))
+
for line in self.lines:
for coords in line:
- dc.DrawLine(*coords)
+ apply(dc.DrawLine, coords)
def SetXY(self, event):
if BUFFERED:
# If doing buffered drawing, create the buffered DC, giving it
# it a real DC to blit to when done.
- cdc = wxClientDC(self)
+ cdc = wx.ClientDC(self)
self.PrepareDC(cdc)
- dc = wxBufferedDC(cdc, self.buffer)
+ dc = wx.BufferedDC(cdc, self.buffer)
else:
- dc = wxClientDC(self)
+ dc = wx.ClientDC(self)
self.PrepareDC(dc)
dc.BeginDrawing()
- dc.SetPen(wxPen('MEDIUM FOREST GREEN', 4))
- coords = ((self.x, self.y), self.ConvertEventCoords(event))
+ dc.SetPen(wx.Pen('MEDIUM FOREST GREEN', 4))
+ coords = [(self.x, self.y) , self.ConvertEventCoords(event)]
self.curLine.append(coords)
- dc.DrawLine( *coords)
+ apply(dc.DrawLine, coords)
self.SetXY(event)
dc.EndDrawing()
## This is an example of what to do for the EVT_MOUSEWHEEL event,
## but since wxScrolledWindow does this already it's not
-## necessary to do it ourselves.
+## necessary to do it ourselves. You would need to add an event table
+## entry to __init__() to direct wheelmouse events to this handler.
## wheelScroll = 0
## def OnWheel(self, evt):
-
-
-overview = """\
+overview = """
+<html>
+<body>
+The wx.ScrolledWindow class manages scrolling for its client area, transforming the
+coordinates according to the scrollbar positions, and setting the scroll positions,
+thumb sizes and ranges according to the area in view.
+</body>
+</html>
"""
-
-
if __name__ == '__main__':
import sys,os
import run
+# 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
+import wx
#---------------------------------------------------------------------------
def runTest(frame, nb, log):
- dlg = wxSingleChoiceDialog(frame, 'Test Single Choice', 'The Caption',
- ['zero', 'one', 'two', 'three', 'four', 'five',
- 'six', 'seven', 'eight'], wxCHOICEDLG_STYLE)
- if dlg.ShowModal() == wxID_OK:
+ dlg = wx.SingleChoiceDialog(
+ frame, 'Test Single Choice', 'The Caption',
+ ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight'],
+ wx.CHOICEDLG_STYLE
+ )
+
+ if dlg.ShowModal() == wx.ID_OK:
log.WriteText('You selected: %s\n' % dlg.GetStringSelection())
+
dlg.Destroy()
#---------------------------------------------------------------------------
to select one. Double-clicking on a list item is equivalent to single-clicking
and then pressing OK.
+As with all dialogs, be sure to retrieve the information you need BEFORE you
+destroy the dialog.
"""
+# 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
+import wx
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.log = log
self.count = 0
- wxStaticText(self, -1, "This is a wxSlider.", wxPoint(45, 15))
+ wx.StaticText(self, -1, "This is a wxSlider.", (45, 15))
+
+ slider = wx.Slider(
+ self, 100, 25, 1, 100, (30, 60), (250, -1),
+ wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | wx.SL_LABELS
+ )
- slider = wxSlider(self, 100, 25, 1, 100, wxPoint(30, 60),
- wxSize(250, -1),
- wxSL_HORIZONTAL | wxSL_AUTOTICKS | wxSL_LABELS )
slider.SetTickFreq(5, 1)
overview = """\
-"""
+A slider is a control with a handle which can be pulled back and forth to
+change the value.
+In Windows versions below Windows 95, a scrollbar is used to simulate the slider.
+In Windows 95, the track bar control is used.
+
+"""
if __name__ == '__main__':
+# 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+# 11/30/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o EVT_SPIN events (or something about them) freezes up the app.
+#
-from wxPython.wx import *
+import wx
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.log = log
self.count = 0
- wxStaticText(self, -1, "This example uses the wxSpinButton control.",
- wxPoint(45, 15))
+ wx.StaticText(self, -1, "This example uses the wxSpinButton control.", (45, 15))
-
- self.text = wxTextCtrl(self, -1, "1", wxPoint(30, 50), wxSize(60, -1))
+ self.text = wx.TextCtrl(self, -1, "1", (30, 50), (60, -1))
h = self.text.GetSize().height
- self.spin = wxSpinButton(self, 20, wxPoint(92, 50), wxSize(h, h),
- wxSP_VERTICAL)
+
+ self.spin = wx.SpinButton(self, -1, (92, 50), (h, h), wx.SP_VERTICAL)
self.spin.SetRange(1, 100)
self.spin.SetValue(1)
- EVT_SPIN(self, 20, self.OnSpin)
+ self.Bind(wx.EVT_SPIN, self.OnSpin, self.spin)
def OnSpin(self, event):
#----------------------------------------------------------------------
-
-
-
-
-
-
-
-
overview = """\
-"""
+A wxSpinButton has two small up and down (or left and right) arrow buttons.
+It is often used next to a text control for increment and decrementing a value.
+Portable programs should try to use wxSpinCtrl instead as wxSpinButton is not
+implemented for all platforms (Win32 and GTK only currently).
+NB: the range supported by this control (and wxSpinCtrl) depends on the platform
+but is at least -0x8000 to 0x7fff. Under GTK and Win32 with sufficiently new version
+of comctrl32.dll (at least 4.71 is required, 5.80 is recommended) the full 32 bit
+range is supported.
+"""
if __name__ == '__main__':
import sys,os
+# 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
+import wx
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.log = log
self.count = 0
- wxStaticText(self, -1, "This example uses the wxSpinCtrl control.",
- wxPoint(45, 15))
-
- sc = wxSpinCtrl(self, -1, "", wxPoint(30, 50), wxSize(80, -1))
+ wx.StaticText(self, -1, "This example uses the wxSpinCtrl control.", (45, 15))
+ sc = wx.SpinCtrl(self, -1, "", (30, 50), (80, -1))
sc.SetRange(1,100)
sc.SetValue(5)
#sc.Enable(False)
#----------------------------------------------------------------------
+overview = """\
+wxSpinCtrl combines wxTextCtrl and wxSpinButton in one control.
+Portable programs should try to use wxSpinCtrl instead as wxSpinButton is not
+implemented for all platforms (Win32 and GTK only currently).
+NB: the range supported by this control depends on the platform
+but is at least -0x8000 to 0x7fff. Under GTK and Win32 with sufficiently new version
+of comctrl32.dll (at least 4.71 is required, 5.80 is recommended) the full 32 bit
+range is supported.
-
-overview = """\
"""
-
-
-
if __name__ == '__main__':
import sys,os
import run
+# 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
-
+import wx
#---------------------------------------------------------------------------
-class MySplitter(wxSplitterWindow):
+class MySplitter(wx.SplitterWindow):
def __init__(self, parent, ID, log):
- wxSplitterWindow.__init__(self, parent, ID)
+ wx.SplitterWindow.__init__(self, parent, ID)
self.log = log
- EVT_SPLITTER_SASH_POS_CHANGED(self, self.GetId(), self.OnSashChanged)
- EVT_SPLITTER_SASH_POS_CHANGING(self, self.GetId(), self.OnSashChanging)
+
+ self.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED, self.OnSashChanged)
+ self.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGING, self.OnSashChanging)
def OnSashChanged(self, evt):
self.log.WriteText("sash changed to %s\n" % str(evt.GetSashPosition()))
def runTest(frame, nb, log):
splitter = MySplitter(nb, -1, log)
- p1 = wxWindow(splitter, -1)
- p1.SetBackgroundColour(wxRED)
- wxStaticText(p1, -1, "Panel One", wxPoint(5,5)).SetBackgroundColour(wxRED)
+ p1 = wx.Window(splitter, -1)
+ p1.SetBackgroundColour(wx.RED)
+ wx.StaticText(p1, -1, "Panel One", (5,5)).SetBackgroundColour(wx.RED)
- p2 = wxWindow(splitter, -1)
- p2.SetBackgroundColour(wxBLUE)
- wxStaticText(p2, -1, "Panel Two", wxPoint(5,5)).SetBackgroundColour(wxBLUE)
+ p2 = wx.Window(splitter, -1)
+ p2.SetBackgroundColour(wx.BLUE)
+ wx.StaticText(p2, -1, "Panel Two", (5,5)).SetBackgroundColour(wx.BLUE)
splitter.SetMinimumPaneSize(20)
splitter.SplitVertically(p1, p2, 100)
#---------------------------------------------------------------------------
-
-
overview = """\
This class manages up to two subwindows. The current view can be split
into two programmatically (perhaps from a menu command), and unsplit
either programmatically or via the wxSplitterWindow user interface.
"""
-
-
if __name__ == '__main__':
import sys,os
import run
+# 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
-
-import images
+import wx
+import images
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.log = log
self.count = 0
- wxStaticText(self, -1, "This is a wxStaticBitmap.", wxPoint(45, 15))
+ wx.StaticText(self, -1, "This is a wxStaticBitmap.", (45, 15))
bmp = images.getTest2Bitmap()
- mask = wxMaskColour(bmp, wxBLUE)
+ mask = wx.MaskColour(bmp, wx.BLUE)
bmp.SetMask(mask)
- wxStaticBitmap(self, -1, bmp, wxPoint(80, 50),
- wxSize(bmp.GetWidth(), bmp.GetHeight()))
+ wx.StaticBitmap(self, -1, bmp, (80, 50), (bmp.GetWidth(), bmp.GetHeight()))
bmp = images.getRobinBitmap()
- wxStaticBitmap(self, -1, bmp, (80, 150))
+ wx.StaticBitmap(self, -1, bmp, (80, 150))
- wxStaticText(self, -1, "Hey, if Ousterhout can do it, so can I.",
- (200, 175))
+ wx.StaticText(self, -1, "Hey, if Ousterhout can do it, so can I.", (200, 175))
#----------------------------------------------------------------------
#----------------------------------------------------------------------
+overview = """\
+A static bitmap control displays a bitmap.
+The bitmap to be displayed should have a small number of colours, such as 16,
+to avoid palette problems.
+A bitmap can be derived from most image formats using the wxImage class.
-
-overview = """\
"""
-
-
if __name__ == '__main__':
import sys,os
import run
+# 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+# o Removed the USE_GENERIC code because it doesn't work unless you use
+# the 'from wx import *' methodology.
+#
-from wxPython.wx import *
-
-USE_GENERIC = 0
-
-if USE_GENERIC:
- from wxPython.lib.stattext import wxGenStaticText as wxStaticText
+import wx
#---------------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent):
- wxPanel.__init__(self, parent, -1)
-
- wxStaticText(self, -1, "This is an example of static text", (20, 10))
+ wx.Panel.__init__(self, parent, -1)
- wxStaticText(self, -1, "using the wxStaticText Control.", (20, 30))
+ wx.StaticText(self, -1, "This is an example of static text", (20, 10))
+ wx.StaticText(self, -1, "using the wxStaticText Control.", (20, 30))
- wxStaticText(self, -1, "Is this yellow?", (20, 70), (90, -1)).SetBackgroundColour('Yellow')
+ wx.StaticText(
+ self, -1, "Is this yellow?", (20, 70), (90, -1)
+ ).SetBackgroundColour('Yellow')
- wxStaticText(self, -1, "align center", (120, 70), (90, -1), wxALIGN_CENTER).SetBackgroundColour('Yellow')
+ wx.StaticText(
+ self, -1, "align center", (120, 70), (90, -1), wx.ALIGN_CENTER
+ ).SetBackgroundColour('Yellow')
- wxStaticText(self, -1, "align right", (220, 70), (90, -1), wxALIGN_RIGHT).SetBackgroundColour('Yellow')
+ wx.StaticText(
+ self, -1, "align right", (220, 70), (90, -1), wx.ALIGN_RIGHT
+ ).SetBackgroundColour('Yellow')
str = "This is a different font."
- text = wxStaticText(self, -1, str, (20, 100))
- font = wxFont(18, wxSWISS, wxNORMAL, wxNORMAL)
+ text = wx.StaticText(self, -1, str, (20, 100))
+ font = wx.Font(18, wx.SWISS, wx.NORMAL, wx.NORMAL)
text.SetFont(font)
#text.SetSize(text.GetBestSize())
- wxStaticText(self, -1, "Multi-line wxStaticText\nline 2\nline 3\n\nafter empty line", (20,150))
- wxStaticText(self, -1, "Align right multi-line\nline 2\nline 3\n\nafter empty line", (220,150), style=wxALIGN_RIGHT)
+ wx.StaticText(self, -1, "Multi-line wxStaticText\nline 2\nline 3\n\nafter empty line", (20,150))
+ wx.StaticText(self, -1, "Align right multi-line\nline 2\nline 3\n\nafter empty line", (220,150), style=wx.ALIGN_RIGHT)
#---------------------------------------------------------------------------
#---------------------------------------------------------------------------
-
overview = '''\
A static text control displays one or more lines of read-only text.
'''
-
if __name__ == '__main__':
import sys,os
import run
+# 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
-
-import time
+import time
+import wx
#---------------------------------------------------------------------------
-class CustomStatusBar(wxStatusBar):
+class CustomStatusBar(wx.StatusBar):
def __init__(self, parent, log):
- wxStatusBar.__init__(self, parent, -1)
+ wx.StatusBar.__init__(self, parent, -1)
+
+ # This status bar has three fields
self.SetFieldsCount(3)
self.log = log
self.sizeChanged = False
- EVT_SIZE(self, self.OnSize)
- EVT_IDLE(self, self.OnIdle)
+ self.Bind(wx.EVT_SIZE, self.OnSize)
+ self.Bind(wx.EVT_IDLE, self.OnIdle)
+ # Field 0 ... just text
self.SetStatusText("A Custom StatusBar...", 0)
- self.cb = wxCheckBox(self, 1001, "toggle clock")
- EVT_CHECKBOX(self, 1001, self.OnToggleClock)
+ # This will fall into field 1 (the second field)
+ self.cb = wx.CheckBox(self, 1001, "toggle clock")
+ self.Bind(wx.EVT_CHECKBOX, self.OnToggleClock, self.cb)
self.cb.SetValue(True)
# set the initial position of the checkbox
self.Reposition()
- # start our timer
- self.timer = wxPyTimer(self.Notify)
+ # We're going to use a timer to drive a 'clock' in the last
+ # field.
+ self.timer = wx.PyTimer(self.Notify)
self.timer.Start(1000)
self.Notify()
- # Time-out handler
+ # Handles events from the timer we started in __init__().
+ # We're using it to drive a 'clock' in field 2 (the third field).
def Notify(self):
t = time.localtime(time.time())
st = time.strftime("%d-%b-%Y %I:%M:%S", t)
# reposition the checkbox
def Reposition(self):
rect = self.GetFieldRect(1)
- self.cb.SetPosition(wxPoint(rect.x+2, rect.y+2))
- self.cb.SetSize(wxSize(rect.width-4, rect.height-4))
+ self.cb.SetPosition((rect.x+2, rect.y+2))
+ self.cb.SetSize((rect.width-4, rect.height-4))
self.sizeChanged = False
-class TestCustomStatusBar(wxFrame):
+class TestCustomStatusBar(wx.Frame):
def __init__(self, parent, log):
- wxFrame.__init__(self, parent, -1, 'Test Custom StatusBar')
- #wxWindow(self, -1).SetBackgroundColour(wxNamedColour("WHITE"))
+ wx.Frame.__init__(self, parent, -1, 'Test Custom StatusBar')
self.sb = CustomStatusBar(self, log)
self.SetStatusBar(self.sb)
- tc = wxTextCtrl(self, -1, "", style=wxTE_READONLY|wxTE_MULTILINE)
+ tc = wx.TextCtrl(self, -1, "", style=wx.TE_READONLY|wx.TE_MULTILINE)
self.SetSize((500, 300))
- EVT_CLOSE(self, self.OnCloseWindow)
+ self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
def OnCloseWindow(self, event):
self.sb.timer.Stop()
#---------------------------------------------------------------------------
-
-
-
-
-
-
-
overview = """\
A status bar is a narrow window that can be placed along the bottom of
a frame to give small amounts of status information. It can contain
one or more fields, one or more of which can be variable length
-according to the size of the window. """
-
+according to the size of the window.
+This example demonstrates how to create a custom status bar with actual
+gadgets embedded in it. In this case, the first field is just plain text,
+The second one has a checkbox that enables the timer, and the third
+field has a clock that shows the current time when it is enabled.
+"""
if __name__ == '__main__':
+# 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+# 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o EVT_STC_DRAG_OVER event GetdragResult() is not an int
+# o wx.TheClipboard.Flush() generates an error on program exit.
+#
-from wxPython.wx import *
-from wxPython.stc import *
+import wx
+import wx.stc as stc
-import images
+import images
#----------------------------------------------------------------------
capabilities, (right click to try it out.)
"""
-if wxPlatform == '__WXMSW__':
+if wx.Platform == '__WXMSW__':
face1 = 'Arial'
face2 = 'Times New Roman'
face3 = 'Courier New'
#----------------------------------------------------------------------
# This shows how to catch the Modified event from the wxStyledTextCtrl
-class MySTC(wxStyledTextCtrl):
+class MySTC(stc.StyledTextCtrl):
def __init__(self, parent, ID, log):
- wxStyledTextCtrl.__init__(self, parent, ID)
+ stc.StyledTextCtrl.__init__(self, parent, ID)
self.log = log
- EVT_STC_DO_DROP(self, ID, self.OnDoDrop)
- EVT_STC_DRAG_OVER(self, ID, self.OnDragOver)
- EVT_STC_START_DRAG(self, ID, self.OnStartDrag)
- EVT_STC_MODIFIED(self, ID, self.OnModified)
+ self.Bind(stc.EVT_STC_DO_DROP, self.OnDoDrop)
+ self.Bind(stc.EVT_STC_DRAG_OVER, self.OnDragOver)
+ self.Bind(stc.EVT_STC_START_DRAG, self.OnStartDrag)
+ self.Bind(stc.EVT_STC_MODIFIED, self.OnModified)
- EVT_WINDOW_DESTROY(self, self.OnDestroy)
+ self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
def OnDestroy(self, evt):
# This is how the clipboard contents can be preserved after
# the app has exited.
- wxTheClipboard.Flush()
+ wx.TheClipboard.Flush()
evt.Skip()
def OnDragOver(self, evt):
- self.log.write("OnDragOver: x,y=(%d, %d) pos: %d DragResult: %d\n"
- % (evt.GetX(), evt.GetY(), evt.GetPosition(), evt.GetDragResult()))
+ #Todo: evt.GetdragResult() response is not an int
+
+ self.log.write(
+ "OnDragOver: x,y=(%d, %d) pos: %d DragResult: %d\n"
+ % (evt.GetX(), evt.GetY(), evt.GetPosition(), evt.GetDragResult())
+ )
if debug and evt.GetPosition() < 250:
- evt.SetDragResult(wxDragNone) # prevent dropping at the beginning of the buffer
+ evt.SetDragResult(wx.DragNone) # prevent dropping at the beginning of the buffer
def OnDoDrop(self, evt):
if debug and evt.GetPosition() < 500:
evt.SetDragText("DROPPED TEXT") # Can change text if needed
- ##evt.SetDragResult(wxDragNone) # Can also change the drag operation, but it
+ #evt.SetDragResult(wx.DragNone) # Can also change the drag operation, but it
# is probably better to do it in OnDragOver so
# there is visual feedback
- ##evt.SetPosition(25) # Can also change position, but I'm not sure why
+ #evt.SetPosition(25) # Can also change position, but I'm not sure why
# you would want to...
def transModType(self, modType):
st = ""
- table = [(wxSTC_MOD_INSERTTEXT, "InsertText"),
- (wxSTC_MOD_DELETETEXT, "DeleteText"),
- (wxSTC_MOD_CHANGESTYLE, "ChangeStyle"),
- (wxSTC_MOD_CHANGEFOLD, "ChangeFold"),
- (wxSTC_PERFORMED_USER, "UserFlag"),
- (wxSTC_PERFORMED_UNDO, "Undo"),
- (wxSTC_PERFORMED_REDO, "Redo"),
- (wxSTC_LASTSTEPINUNDOREDO, "Last-Undo/Redo"),
- (wxSTC_MOD_CHANGEMARKER, "ChangeMarker"),
- (wxSTC_MOD_BEFOREINSERT, "B4-Insert"),
- (wxSTC_MOD_BEFOREDELETE, "B4-Delete")
+ table = [(stc.STC_MOD_INSERTTEXT, "InsertText"),
+ (stc.STC_MOD_DELETETEXT, "DeleteText"),
+ (stc.STC_MOD_CHANGESTYLE, "ChangeStyle"),
+ (stc.STC_MOD_CHANGEFOLD, "ChangeFold"),
+ (stc.STC_PERFORMED_USER, "UserFlag"),
+ (stc.STC_PERFORMED_UNDO, "Undo"),
+ (stc.STC_PERFORMED_REDO, "Redo"),
+ (stc.STC_LASTSTEPINUNDOREDO, "Last-Undo/Redo"),
+ (stc.STC_MOD_CHANGEMARKER, "ChangeMarker"),
+ (stc.STC_MOD_BEFOREINSERT, "B4-Insert"),
+ (stc.STC_MOD_BEFOREDELETE, "B4-Delete")
]
for flag,text in table:
ed = p = MySTC(nb, -1, log)
else:
- p = wxPanel(nb, -1, style=wxNO_FULL_REPAINT_ON_RESIZE)
+ p = wx.Panel(nb, -1, style=wx.NO_FULL_REPAINT_ON_RESIZE)
ed = MySTC(p, -1, log)
- s = wxBoxSizer(wxHORIZONTAL)
- s.Add(ed, 1, wxEXPAND)
+ s = wx.BoxSizer(wx.HORIZONTAL)
+ s.Add(ed, 1, wx.EXPAND)
p.SetSizer(s)
p.SetAutoLayout(True)
#ed.SetWrapMode(True)
ed.SetText(demoText)
- if wxUSE_UNICODE:
+
+ if wx.USE_UNICODE:
import codecs
decode = codecs.lookup("utf-8")[1]
ed.EmptyUndoBuffer()
# make some styles
- ed.StyleSetSpec(wxSTC_STYLE_DEFAULT, "size:%d,face:%s" % (pb, face3))
+ ed.StyleSetSpec(stc.STC_STYLE_DEFAULT, "size:%d,face:%s" % (pb, face3))
ed.StyleSetSpec(1, "size:%d,bold,face:%s,fore:#0000FF" % (pb+2, face1))
ed.StyleSetSpec(2, "face:%s,italic,fore:#FF0000,size:%d" % (face2, pb))
ed.StyleSetSpec(3, "face:%s,bold,size:%d" % (face2, pb+2))
# line numbers in the margin
- ed.SetMarginType(0, wxSTC_MARGIN_NUMBER)
+ ed.SetMarginType(0, stc.STC_MARGIN_NUMBER)
ed.SetMarginWidth(0, 22)
- ed.StyleSetSpec(wxSTC_STYLE_LINENUMBER, "size:%d,face:%s" % (pb, face1))
+ ed.StyleSetSpec(stc.STC_STYLE_LINENUMBER, "size:%d,face:%s" % (pb, face1))
# setup some markers
- ed.SetMarginType(1, wxSTC_MARGIN_SYMBOL)
- ed.MarkerDefine(0, wxSTC_MARK_ROUNDRECT, "#CCFF00", "RED")
- #ed.MarkerDefine(1, wxSTC_MARK_CIRCLE, "FOREST GREEN", "SIENNA")
+ ed.SetMarginType(1, stc.STC_MARGIN_SYMBOL)
+ ed.MarkerDefine(0, stc.STC_MARK_ROUNDRECT, "#CCFF00", "RED")
+ #ed.MarkerDefine(1, stc.STC_MARK_CIRCLE, "FOREST GREEN", "SIENNA")
ed.MarkerDefineBitmap(1, images.getFolder1Bitmap())
- ed.MarkerDefine(2, wxSTC_MARK_SHORTARROW, "blue", "blue")
- ed.MarkerDefine(3, wxSTC_MARK_ARROW, "#00FF00", "#00FF00")
+ ed.MarkerDefine(2, stc.STC_MARK_SHORTARROW, "blue", "blue")
+ ed.MarkerDefine(3, stc.STC_MARK_ARROW, "#00FF00", "#00FF00")
# put some markers on some lines
ed.MarkerAdd(17, 0)
# and finally, an indicator or two
- ed.IndicatorSetStyle(0, wxSTC_INDIC_SQUIGGLE)
- ed.IndicatorSetForeground(0, wxRED)
- ed.IndicatorSetStyle(1, wxSTC_INDIC_DIAGONAL)
- ed.IndicatorSetForeground(1, wxBLUE)
- ed.IndicatorSetStyle(2, wxSTC_INDIC_STRIKE)
- ed.IndicatorSetForeground(2, wxRED)
-
- ed.StartStyling(836, wxSTC_INDICS_MASK)
- ed.SetStyling(10, wxSTC_INDIC0_MASK)
- ed.SetStyling(10, wxSTC_INDIC1_MASK)
- ed.SetStyling(10, wxSTC_INDIC2_MASK | wxSTC_INDIC1_MASK)
+ ed.IndicatorSetStyle(0, stc.STC_INDIC_SQUIGGLE)
+ ed.IndicatorSetForeground(0, wx.RED)
+ ed.IndicatorSetStyle(1, stc.STC_INDIC_DIAGONAL)
+ ed.IndicatorSetForeground(1, wx.BLUE)
+ ed.IndicatorSetStyle(2, stc.STC_INDIC_STRIKE)
+ ed.IndicatorSetForeground(2, wx.RED)
+
+ ed.StartStyling(836, stc.STC_INDICS_MASK)
+ ed.SetStyling(10, stc.STC_INDIC0_MASK)
+ ed.SetStyling(10, stc.STC_INDIC1_MASK)
+ ed.SetStyling(10, stc.STC_INDIC2_MASK | stc.STC_INDIC1_MASK)
# some test stuff...
+# 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
-from wxPython.stc import *
-import images
-import keyword
+import keyword
+
+import wx
+import wx.stc as stc
+
+import images
#----------------------------------------------------------------------
#----------------------------------------------------------------------
-if wxPlatform == '__WXMSW__':
+if wx.Platform == '__WXMSW__':
faces = { 'times': 'Times New Roman',
'mono' : 'Courier New',
'helv' : 'Arial',
#----------------------------------------------------------------------
-class PythonSTC(wxStyledTextCtrl):
+class PythonSTC(stc.StyledTextCtrl):
fold_symbols = 2
def __init__(self, parent, ID):
- wxStyledTextCtrl.__init__(self, parent, ID,
- style = wxNO_FULL_REPAINT_ON_RESIZE)
+ stc.StyledTextCtrl.__init__(self, parent, ID,
+ style = wx.NO_FULL_REPAINT_ON_RESIZE)
- self.CmdKeyAssign(ord('B'), wxSTC_SCMOD_CTRL, wxSTC_CMD_ZOOMIN)
- self.CmdKeyAssign(ord('N'), wxSTC_SCMOD_CTRL, wxSTC_CMD_ZOOMOUT)
+ self.CmdKeyAssign(ord('B'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMIN)
+ self.CmdKeyAssign(ord('N'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMOUT)
- self.SetLexer(wxSTC_LEX_PYTHON)
+ self.SetLexer(stc.STC_LEX_PYTHON)
self.SetKeyWords(0, " ".join(keyword.kwlist))
self.SetProperty("fold", "1")
#self.SetBufferedDraw(False)
#self.SetViewEOL(True)
- self.SetEdgeMode(wxSTC_EDGE_BACKGROUND)
+ self.SetEdgeMode(stc.STC_EDGE_BACKGROUND)
self.SetEdgeColumn(78)
# Setup a margin to hold fold markers
#self.SetFoldFlags(16) ### WHAT IS THIS VALUE? WHAT ARE THE OTHER FLAGS? DOES IT MATTER?
- self.SetMarginType(2, wxSTC_MARGIN_SYMBOL)
- self.SetMarginMask(2, wxSTC_MASK_FOLDERS)
+ self.SetMarginType(2, stc.STC_MARGIN_SYMBOL)
+ self.SetMarginMask(2, stc.STC_MASK_FOLDERS)
self.SetMarginSensitive(2, True)
self.SetMarginWidth(2, 12)
-
if self.fold_symbols == 0:
# Arrow pointing right for contracted folders, arrow pointing down for expanded
- self.MarkerDefine(wxSTC_MARKNUM_FOLDEROPEN, wxSTC_MARK_ARROWDOWN, "black", "black");
- self.MarkerDefine(wxSTC_MARKNUM_FOLDER, wxSTC_MARK_ARROW, "black", "black");
- self.MarkerDefine(wxSTC_MARKNUM_FOLDERSUB, wxSTC_MARK_EMPTY, "black", "black");
- self.MarkerDefine(wxSTC_MARKNUM_FOLDERTAIL, wxSTC_MARK_EMPTY, "black", "black");
- self.MarkerDefine(wxSTC_MARKNUM_FOLDEREND, wxSTC_MARK_EMPTY, "white", "black");
- self.MarkerDefine(wxSTC_MARKNUM_FOLDEROPENMID, wxSTC_MARK_EMPTY, "white", "black");
- self.MarkerDefine(wxSTC_MARKNUM_FOLDERMIDTAIL, wxSTC_MARK_EMPTY, "white", "black");
+ self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_ARROWDOWN, "black", "black");
+ self.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_ARROW, "black", "black");
+ self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_EMPTY, "black", "black");
+ self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_EMPTY, "black", "black");
+ self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_EMPTY, "white", "black");
+ self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_EMPTY, "white", "black");
+ self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_EMPTY, "white", "black");
elif self.fold_symbols == 1:
# Plus for contracted folders, minus for expanded
self.MarkerDefine(wxSTC_MARKNUM_FOLDERMIDTAIL, wxSTC_MARK_TCORNER, "white", "#808080")
- EVT_STC_UPDATEUI(self, ID, self.OnUpdateUI)
- EVT_STC_MARGINCLICK(self, ID, self.OnMarginClick)
- EVT_KEY_DOWN(self, self.OnKeyPressed)
-
+ self.Bind(stc.EVT_STC_UPDATEUI, self.OnUpdateUI)
+ self.Bind(stc.EVT_STC_MARGINCLICK, self.OnMarginClick)
+ self.Bind(wx.EVT_KEY_DOWN, self.OnKeyPressed)
# Make some styles, The lexer defines what each style is used for, we
# just have to define what each style looks like. This set is adapted from
# Scintilla sample property files.
# Global default styles for all languages
- self.StyleSetSpec(wxSTC_STYLE_DEFAULT, "face:%(helv)s,size:%(size)d" % faces)
+ self.StyleSetSpec(stc.STC_STYLE_DEFAULT, "face:%(helv)s,size:%(size)d" % faces)
self.StyleClearAll() # Reset all to be like the default
- self.StyleSetSpec(wxSTC_STYLE_LINENUMBER, "back:#C0C0C0,face:%(helv)s,size:%(size2)d" % faces)
- self.StyleSetSpec(wxSTC_STYLE_CONTROLCHAR, "face:%(other)s" % faces)
- self.StyleSetSpec(wxSTC_STYLE_BRACELIGHT, "fore:#FFFFFF,back:#0000FF,bold")
- self.StyleSetSpec(wxSTC_STYLE_BRACEBAD, "fore:#000000,back:#FF0000,bold")
+ # Global default styles for all languages
+ self.StyleSetSpec(stc.STC_STYLE_DEFAULT, "face:%(helv)s,size:%(size)d" % faces)
+ self.StyleSetSpec(stc.STC_STYLE_LINENUMBER, "back:#C0C0C0,face:%(helv)s,size:%(size2)d" % faces)
+ self.StyleSetSpec(stc.STC_STYLE_CONTROLCHAR, "face:%(other)s" % faces)
+ self.StyleSetSpec(stc.STC_STYLE_BRACELIGHT, "fore:#FFFFFF,back:#0000FF,bold")
+ self.StyleSetSpec(stc.STC_STYLE_BRACEBAD, "fore:#000000,back:#FF0000,bold")
# Python styles
# Default
- self.StyleSetSpec(wxSTC_P_DEFAULT, "fore:#000000,face:%(helv)s,size:%(size)d" % faces)
+ self.StyleSetSpec(stc.STC_P_DEFAULT, "fore:#000000,face:%(helv)s,size:%(size)d" % faces)
# Comments
- self.StyleSetSpec(wxSTC_P_COMMENTLINE, "fore:#007F00,face:%(other)s,size:%(size)d" % faces)
+ self.StyleSetSpec(stc.STC_P_COMMENTLINE, "fore:#007F00,face:%(other)s,size:%(size)d" % faces)
# Number
- self.StyleSetSpec(wxSTC_P_NUMBER, "fore:#007F7F,size:%(size)d" % faces)
+ self.StyleSetSpec(stc.STC_P_NUMBER, "fore:#007F7F,size:%(size)d" % faces)
# String
- self.StyleSetSpec(wxSTC_P_STRING, "fore:#7F007F,face:%(helv)s,size:%(size)d" % faces)
+ self.StyleSetSpec(stc.STC_P_STRING, "fore:#7F007F,face:%(helv)s,size:%(size)d" % faces)
# Single quoted string
- self.StyleSetSpec(wxSTC_P_CHARACTER, "fore:#7F007F,face:%(helv)s,size:%(size)d" % faces)
+ self.StyleSetSpec(stc.STC_P_CHARACTER, "fore:#7F007F,face:%(helv)s,size:%(size)d" % faces)
# Keyword
- self.StyleSetSpec(wxSTC_P_WORD, "fore:#00007F,bold,size:%(size)d" % faces)
+ self.StyleSetSpec(stc.STC_P_WORD, "fore:#00007F,bold,size:%(size)d" % faces)
# Triple quotes
- self.StyleSetSpec(wxSTC_P_TRIPLE, "fore:#7F0000,size:%(size)d" % faces)
+ self.StyleSetSpec(stc.STC_P_TRIPLE, "fore:#7F0000,size:%(size)d" % faces)
# Triple double quotes
- self.StyleSetSpec(wxSTC_P_TRIPLEDOUBLE, "fore:#7F0000,size:%(size)d" % faces)
+ self.StyleSetSpec(stc.STC_P_TRIPLEDOUBLE, "fore:#7F0000,size:%(size)d" % faces)
# Class name definition
- self.StyleSetSpec(wxSTC_P_CLASSNAME, "fore:#0000FF,bold,underline,size:%(size)d" % faces)
+ self.StyleSetSpec(stc.STC_P_CLASSNAME, "fore:#0000FF,bold,underline,size:%(size)d" % faces)
# Function or method name definition
- self.StyleSetSpec(wxSTC_P_DEFNAME, "fore:#007F7F,bold,size:%(size)d" % faces)
+ self.StyleSetSpec(stc.STC_P_DEFNAME, "fore:#007F7F,bold,size:%(size)d" % faces)
# Operators
- self.StyleSetSpec(wxSTC_P_OPERATOR, "bold,size:%(size)d" % faces)
+ self.StyleSetSpec(stc.STC_P_OPERATOR, "bold,size:%(size)d" % faces)
# Identifiers
- self.StyleSetSpec(wxSTC_P_IDENTIFIER, "fore:#000000,face:%(helv)s,size:%(size)d" % faces)
+ self.StyleSetSpec(stc.STC_P_IDENTIFIER, "fore:#000000,face:%(helv)s,size:%(size)d" % faces)
# Comment-blocks
- self.StyleSetSpec(wxSTC_P_COMMENTBLOCK, "fore:#7F7F7F,size:%(size)d" % faces)
+ self.StyleSetSpec(stc.STC_P_COMMENTBLOCK, "fore:#7F7F7F,size:%(size)d" % faces)
# End of line where string is not closed
- self.StyleSetSpec(wxSTC_P_STRINGEOL, "fore:#000000,face:%(mono)s,back:#E0C0E0,eol,size:%(size)d" % faces)
+ self.StyleSetSpec(stc.STC_P_STRINGEOL, "fore:#000000,face:%(mono)s,back:#E0C0E0,eol,size:%(size)d" % faces)
self.SetCaretForeground("BLUE")
self.RegisterImage(3, images.getCopy2Bitmap())
-
-
def OnKeyPressed(self, event):
if self.CallTipActive():
self.CallTipCancel()
key = event.KeyCode()
+
if key == 32 and event.ControlDown():
pos = self.GetCurrentPos()
+
# Tips
if event.ShiftDown():
self.CallTipSetBackground("yellow")
braceOpposite = -1
charBefore = None
caretPos = self.GetCurrentPos()
+
if caretPos > 0:
charBefore = self.GetCharAt(caretPos - 1)
styleBefore = self.GetStyleAt(caretPos - 1)
# check before
- if charBefore and chr(charBefore) in "[]{}()" and styleBefore == wxSTC_P_OPERATOR:
+ if charBefore and chr(charBefore) in "[]{}()" and styleBefore == stc.STC_P_OPERATOR:
braceAtCaret = caretPos - 1
# check after
if braceAtCaret < 0:
charAfter = self.GetCharAt(caretPos)
styleAfter = self.GetStyleAt(caretPos)
- if charAfter and chr(charAfter) in "[]{}()" and styleAfter == wxSTC_P_OPERATOR:
+
+ if charAfter and chr(charAfter) in "[]{}()" and styleAfter == stc.STC_P_OPERATOR:
braceAtCaret = caretPos
if braceAtCaret >= 0:
self.FoldAll()
else:
lineClicked = self.LineFromPosition(evt.GetPosition())
- if self.GetFoldLevel(lineClicked) & wxSTC_FOLDLEVELHEADERFLAG:
+
+ if self.GetFoldLevel(lineClicked) & stc.STC_FOLDLEVELHEADERFLAG:
if evt.GetShift():
self.SetFoldExpanded(lineClicked, True)
self.Expand(lineClicked, True, True, 1)
# find out if we are folding or unfolding
for lineNum in range(lineCount):
- if self.GetFoldLevel(lineNum) & wxSTC_FOLDLEVELHEADERFLAG:
+ if self.GetFoldLevel(lineNum) & stc.STC_FOLDLEVELHEADERFLAG:
expanding = not self.GetFoldExpanded(lineNum)
break;
lineNum = 0
+
while lineNum < lineCount:
level = self.GetFoldLevel(lineNum)
- if level & wxSTC_FOLDLEVELHEADERFLAG and \
- (level & wxSTC_FOLDLEVELNUMBERMASK) == wxSTC_FOLDLEVELBASE:
+ if level & stc.STC_FOLDLEVELHEADERFLAG and \
+ (level & stc.STC_FOLDLEVELNUMBERMASK) == stc.STC_FOLDLEVELBASE:
if expanding:
self.SetFoldExpanded(lineNum, True)
else:
lastChild = self.GetLastChild(lineNum, -1)
self.SetFoldExpanded(lineNum, False)
+
if lastChild > lineNum:
self.HideLines(lineNum+1, lastChild)
def Expand(self, line, doExpand, force=False, visLevels=0, level=-1):
lastChild = self.GetLastChild(line, level)
line = line + 1
+
while line <= lastChild:
if force:
if visLevels > 0:
if level == -1:
level = self.GetFoldLevel(line)
- if level & wxSTC_FOLDLEVELHEADERFLAG:
+ if level & stc.STC_FOLDLEVELHEADERFLAG:
if force:
if visLevels > 1:
self.SetFoldExpanded(line, True)
else:
self.SetFoldExpanded(line, False)
+
line = self.Expand(line, doExpand, force, visLevels-1)
else:
if not _USE_PANEL:
ed = p = PythonSTC(nb, -1)
else:
- p = wxPanel(nb, -1, style = wxNO_FULL_REPAINT_ON_RESIZE)
+ p = wx.Panel(nb, -1, style = wx.NO_FULL_REPAINT_ON_RESIZE)
ed = PythonSTC(p, -1)
- s = wxBoxSizer(wxHORIZONTAL)
- s.Add(ed, 1, wxEXPAND)
+ s = wx.BoxSizer(wx.HORIZONTAL)
+ s.Add(ed, 1, wx.EXPAND)
p.SetSizer(s)
p.SetAutoLayout(True)
ed.Colourise(0, -1)
# line numbers in the margin
- ed.SetMarginType(1, wxSTC_MARGIN_NUMBER)
+ ed.SetMarginType(1, stc.STC_MARGIN_NUMBER)
ed.SetMarginWidth(1, 25)
return p
-import sys
-from wxPython.wx import *
+# 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+
+import sys
+import wx
#---------------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def OnSetFocus(self, evt):
print "OnSetFocus"
evt.Skip()
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.log = log
- l1 = wxStaticText(self, -1, "wxTextCtrl")
- t1 = wxTextCtrl(self, -1, "Test it out and see", size=(125, -1))
+ l1 = wx.StaticText(self, -1, "wx.TextCtrl")
+ t1 = wx.TextCtrl(self, -1, "Test it out and see", size=(125, -1))
t1.SetInsertionPoint(0)
self.tc1 = t1
- EVT_TEXT(self, t1.GetId(), self.EvtText)
- EVT_CHAR(t1, self.EvtChar)
- EVT_SET_FOCUS(t1, self.OnSetFocus)
- EVT_KILL_FOCUS(t1, self.OnKillFocus)
- EVT_WINDOW_DESTROY(t1, self.OnWindowDestroy)
-
- l2 = wxStaticText(self, -1, "Password")
- t2 = wxTextCtrl(self, -1, "", size=(125, -1), style=wxTE_PASSWORD)
- EVT_TEXT(self, t2.GetId(), self.EvtText)
-
- l3 = wxStaticText(self, -1, "Multi-line")
- t3 = wxTextCtrl(self, -1,
+
+ self.Bind(wx.EVT_TEXT, self.EvtText, t1)
+ t1.Bind(wx.EVT_CHAR, self.EvtChar)
+ t1.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
+ t1.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
+ t1.Bind(wx.EVT_WINDOW_DESTROY, self.OnWindowDestroy)
+
+ l2 = wx.StaticText(self, -1, "Password")
+ t2 = wx.TextCtrl(self, -1, "", size=(125, -1), style=wx.TE_PASSWORD)
+ self.Bind(wx.EVT_TEXT, self.EvtText, t2)
+
+ l3 = wx.StaticText(self, -1, "Multi-line")
+ t3 = wx.TextCtrl(self, -1,
"Here is a looooooooooooooong line of text set in the control.\n\n"
"The quick brown fox jumped over the lazy dog...",
- size=(200, 100), style=wxTE_MULTILINE)
+ size=(200, 100), style=wx.TE_MULTILINE)
+
t3.SetInsertionPoint(0)
- EVT_TEXT(self, t3.GetId(), self.EvtText)
- b = wxButton(self, -1, "Test Replace")
- EVT_BUTTON(self, b.GetId(), self.OnTestReplace)
- b2 = wxButton(self, -1, "Test GetSelection")
- EVT_BUTTON(self, b2.GetId(), self.OnTestGetSelection)
- b3 = wxButton(self, -1, "Test WriteText")
- EVT_BUTTON(self, b3.GetId(), self.OnTestWriteText)
+ self.Bind(wx.EVT_TEXT, self.EvtText, t3)
+ b = wx.Button(self, -1, "Test Replace")
+ self.Bind(wx.EVT_BUTTON, self.OnTestReplace, b)
+ b2 = wx.Button(self, -1, "Test GetSelection")
+ self.Bind(wx.EVT_BUTTON, self.OnTestGetSelection, b2)
+ b3 = wx.Button(self, -1, "Test WriteText")
+ self.Bind(wx.EVT_BUTTON, self.OnTestWriteText, b3)
self.tc = t3
- l4 = wxStaticText(self, -1, "Rich Text")
- t4 = wxTextCtrl(self, -1, "If supported by the native control, this is red, and this is a different font.",
- size=(200, 100), style=wxTE_MULTILINE|wxTE_RICH2)
+ l4 = wx.StaticText(self, -1, "Rich Text")
+ t4 = wx.TextCtrl(self, -1, "If supported by the native control, this is red, and this is a different font.",
+ size=(200, 100), style=wx.TE_MULTILINE|wx.TE_RICH2)
t4.SetInsertionPoint(0)
- t4.SetStyle(44, 47, wxTextAttr("RED", "YELLOW"))
+ t4.SetStyle(44, 47, wx.TextAttr("RED", "YELLOW"))
points = t4.GetFont().GetPointSize() # get the current size
- f = wxFont(points+3, wxROMAN, wxITALIC, wxBOLD, True)
- t4.SetStyle(63, 77, wxTextAttr("BLUE", wxNullColour, f))
-
- l5 = wxStaticText(self, -1, "Test Positions")
- t5 = wxTextCtrl(self, -1, "0123456789\n" * 5, size=(200, 100),
- style = wxTE_MULTILINE
- #| wxTE_RICH
- | wxTE_RICH2
+ f = wx.Font(points+3, wx.ROMAN, wx.ITALIC, wx.BOLD, True)
+ t4.SetStyle(63, 77, wx.TextAttr("BLUE", wx.NullColour, f))
+
+ l5 = wx.StaticText(self, -1, "Test Positions")
+ t5 = wx.TextCtrl(self, -1, "0123456789\n" * 5, size=(200, 100),
+ style = wx.TE_MULTILINE
+ #| wx.TE_RICH
+ | wx.TE_RICH2
)
- EVT_LEFT_DOWN(t5, self.OnT5LeftDown)
+ t5.Bind(wx.EVT_LEFT_DOWN, self.OnT5LeftDown)
self.t5 = t5
+ bsizer = wx.BoxSizer(wx.VERTICAL)
+ bsizer.Add(b, 0, wx.GROW|wx.ALL, 4)
+ bsizer.Add(b2, 0, wx.GROW|wx.ALL, 4)
+ bsizer.Add(b3, 0, wx.GROW|wx.ALL, 4)
- bsizer = wxBoxSizer(wxVERTICAL)
- bsizer.Add(b, 0, wxGROW|wxALL, 4)
- bsizer.Add(b2, 0, wxGROW|wxALL, 4)
- bsizer.Add(b3, 0, wxGROW|wxALL, 4)
-
- sizer = wxFlexGridSizer(cols=3, hgap=6, vgap=6)
+ sizer = wx.FlexGridSizer(cols=3, hgap=6, vgap=6)
sizer.AddMany([ l1, t1, (0,0),
l2, t2, (0,0),
l3, t3, bsizer,
l4, t4, (0,0),
l5, t5, (0,0),
])
- border = wxBoxSizer(wxVERTICAL)
- border.Add(sizer, 0, wxALL, 25)
+ border = wx.BoxSizer(wx.VERTICAL)
+ border.Add(sizer, 0, wx.ALL, 25)
self.SetSizer(border)
self.SetAutoLayout(True)
def OnTestGetSelection(self, evt):
start, end = self.tc.GetSelection()
text = self.tc.GetValue()
- if wxPlatform == "__WXMSW__": # This is why GetStringSelection was added
+ if wx.Platform == "__WXMSW__": # This is why GetStringSelection was added
text = text.replace('\n', '\r\n')
+
self.log.write("multi-line GetSelection(): (%d, %d)\n"
"\tGetStringSelection(): %s\n"
"\tSelectedText: %s\n" %
start, end = self.tc1.GetSelection()
text = self.tc1.GetValue()
- if wxPlatform == "__WXMSW__": # This is why GetStringSelection was added
+
+ if wx.Platform == "__WXMSW__": # This is why GetStringSelection was added
text = text.replace('\n', '\r\n')
+
self.log.write("single-line GetSelection(): (%d, %d)\n"
"\tGetStringSelection(): %s\n"
"\tSelectedText: %s\n" %
def OnT5LeftDown(self, evt):
evt.Skip()
- wxCallAfter(self.LogT5Position, evt)
+ wx.CallAfter(self.LogT5Position, evt)
def LogT5Position(self, evt):
text = self.t5.GetValue()
#---------------------------------------------------------------------------
-
-
overview = """\
-"""
+A text control allows text to be displayed and (possibly) edited. It may be single
+line or multi-line, support styles or not, be read-only or not, and even supports
+text masking for such things as passwords.
+"""
if __name__ == '__main__':
+# 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
+import wx
#---------------------------------------------------------------------------
def runTest(frame, nb, log):
- dlg = wxTextEntryDialog(frame, 'What is your favorite programming language?',
- 'Duh??', 'Python')
+ dlg = wx.TextEntryDialog(
+ frame, 'What is your favorite programming language?',
+ 'Duh??', 'Python')
+
dlg.SetValue("Python is the best!")
- if dlg.ShowModal() == wxID_OK:
+
+ if dlg.ShowModal() == wx.ID_OK:
log.WriteText('You entered: %s\n' % dlg.GetValue())
+
dlg.Destroy()
-
overview = """\
+This class represents a dialog that requests a one-line text string from the user.
+It is implemented as a generic wxWindows dialog. Along with the usual wxDialog
+style flags, all of the wxTextCtrl TE_* style flags are accepted, so, for example,
+wx.TE_PASSWORD could be used to create a password dialog.
-"""
-
-
+As with other dialogs of this type, the user input must be retrieved prior to
+destroying the dialog.
+"""
if __name__ == '__main__':
-from wxPython.wx import *
-from wxPython.lib.timectrl import *
-from wxPython.lib.timectrl import __doc__ as overviewdoc
-from wxPython.lib.scrolledpanel import wxScrolledPanel
+# 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+# 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o wx renamer needed for timectrl lib
+# o presense of spin control causing probs (see spin ctrl demo for details)
+#
+
+import wx
+import wx.lib.timectrl as timectl
+import wx.lib.scrolledpanel as scrolled
#----------------------------------------------------------------------
-class TestPanel( wxScrolledPanel ):
+class TestPanel( scrolled.wxScrolledPanel ):
def __init__( self, parent, log ):
- wxScrolledPanel.__init__( self, parent, -1 )
+ scrolled.wxScrolledPanel.__init__( self, parent, -1 )
self.log = log
- text1 = wxStaticText( self, -1, "12-hour format:")
- self.time12 = wxTimeCtrl( self, -1, name="12 hour control" )
- spin1 = wxSpinButton( self, -1, wxDefaultPosition, wxSize(-1,20), 0 )
+ text1 = wx.StaticText( self, -1, "12-hour format:")
+ self.time12 = timectl.wxTimeCtrl( self, -1, name="12 hour control" )
+ spin1 = wx.SpinButton( self, -1, wx.DefaultPosition, (-1,20), 0 )
self.time12.BindSpinButton( spin1 )
- text2 = wxStaticText( self, -1, "24-hour format:")
- spin2 = wxSpinButton( self, -1, wxDefaultPosition, wxSize(-1,20), 0 )
- self.time24 = wxTimeCtrl( self, -1, name="24 hour control", fmt24hr=True, spinButton = spin2 )
-
- text3 = wxStaticText( self, -1, "No seconds\nor spin button:")
- self.spinless_ctrl = wxTimeCtrl( self, -1, name="spinless control", display_seconds = False )
-
- grid = wxFlexGridSizer( 0, 2, 10, 5 )
- grid.Add( text1, 0, wxALIGN_RIGHT )
- hbox1 = wxBoxSizer( wxHORIZONTAL )
- hbox1.Add( self.time12, 0, wxALIGN_CENTRE )
- hbox1.Add( spin1, 0, wxALIGN_CENTRE )
- grid.Add( hbox1, 0, wxLEFT )
-
- grid.Add( text2, 0, wxALIGN_RIGHT|wxTOP|wxBOTTOM )
- hbox2 = wxBoxSizer( wxHORIZONTAL )
- hbox2.Add( self.time24, 0, wxALIGN_CENTRE )
- hbox2.Add( spin2, 0, wxALIGN_CENTRE )
- grid.Add( hbox2, 0, wxLEFT )
-
- grid.Add( text3, 0, wxALIGN_RIGHT|wxTOP|wxBOTTOM )
- grid.Add( self.spinless_ctrl, 0, wxLEFT )
-
-
- buttonChange = wxButton( self, -1, "Change Controls")
- self.radio12to24 = wxRadioButton( self, -1, "Copy 12-hour time to 24-hour control", wxDefaultPosition, wxDefaultSize, wxRB_GROUP )
- self.radio24to12 = wxRadioButton( self, -1, "Copy 24-hour time to 12-hour control")
- self.radioWx = wxRadioButton( self, -1, "Set controls to 'now' using wxDateTime")
- self.radioMx = wxRadioButton( self, -1, "Set controls to 'now' using mxDateTime")
-
- radio_vbox = wxBoxSizer( wxVERTICAL )
- radio_vbox.Add( self.radio12to24, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 )
- radio_vbox.Add( self.radio24to12, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 )
- radio_vbox.Add( self.radioWx, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 )
- radio_vbox.Add( self.radioMx, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 )
-
- box_label = wxStaticBox( self, -1, "Change Controls through API" )
- buttonbox = wxStaticBoxSizer( box_label, wxHORIZONTAL )
- buttonbox.Add( buttonChange, 0, wxALIGN_CENTRE|wxALL, 5 )
- buttonbox.Add( radio_vbox, 0, wxALIGN_CENTRE|wxALL, 5 )
-
- hbox = wxBoxSizer( wxHORIZONTAL )
- hbox.Add( grid, 0, wxALIGN_LEFT|wxALL, 15 )
- hbox.Add( buttonbox, 0, wxALIGN_RIGHT|wxBOTTOM, 20 )
-
-
- box_label = wxStaticBox( self, -1, "Bounds Control" )
- boundsbox = wxStaticBoxSizer( box_label, wxHORIZONTAL )
- self.set_bounds = wxCheckBox( self, -1, "Set time bounds:" )
-
- minlabel = wxStaticText( self, -1, "minimum time:" )
- self.min = wxTimeCtrl( self, -1, name="min", display_seconds = False )
+ text2 = wx.StaticText( self, -1, "24-hour format:")
+ spin2 = wx.SpinButton( self, -1, wx.DefaultPosition, (-1,20), 0 )
+ self.time24 = timectl.wxTimeCtrl(
+ self, -1, name="24 hour control", fmt24hr=True,
+ spinButton = spin2
+ )
+
+ text3 = wx.StaticText( self, -1, "No seconds\nor spin button:")
+ self.spinless_ctrl = timectl.wxTimeCtrl(
+ self, -1, name="spinless control",
+ display_seconds = False
+ )
+
+ grid = wx.FlexGridSizer( 0, 2, 10, 5 )
+ grid.Add( text1, 0, wx.ALIGN_RIGHT )
+ hbox1 = wx.BoxSizer( wx.HORIZONTAL )
+ hbox1.Add( self.time12, 0, wx.ALIGN_CENTRE )
+ hbox1.Add( spin1, 0, wx.ALIGN_CENTRE )
+ grid.Add( hbox1, 0, wx.LEFT )
+
+ grid.Add( text2, 0, wx.ALIGN_RIGHT|wx.TOP|wx.BOTTOM )
+ hbox2 = wx.BoxSizer( wx.HORIZONTAL )
+ hbox2.Add( self.time24, 0, wx.ALIGN_CENTRE )
+ hbox2.Add( spin2, 0, wx.ALIGN_CENTRE )
+ grid.Add( hbox2, 0, wx.LEFT )
+
+ grid.Add( text3, 0, wx.ALIGN_RIGHT|wx.TOP|wx.BOTTOM )
+ grid.Add( self.spinless_ctrl, 0, wx.LEFT )
+
+
+ buttonChange = wx.Button( self, -1, "Change Controls")
+ self.radio12to24 = wx.RadioButton(
+ self, -1, "Copy 12-hour time to 24-hour control",
+ wx.DefaultPosition, wx.DefaultSize, wx.RB_GROUP
+ )
+
+ self.radio24to12 = wx.RadioButton(
+ self, -1, "Copy 24-hour time to 12-hour control"
+ )
+
+ self.radioWx = wx.RadioButton( self, -1, "Set controls to 'now' using wxDateTime")
+ self.radioMx = wx.RadioButton( self, -1, "Set controls to 'now' using mxDateTime")
+
+ radio_vbox = wx.BoxSizer( wx.VERTICAL )
+ radio_vbox.Add( self.radio12to24, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
+ radio_vbox.Add( self.radio24to12, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
+ radio_vbox.Add( self.radioWx, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
+ radio_vbox.Add( self.radioMx, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
+
+ box_label = wx.StaticBox( self, -1, "Change Controls through API" )
+ buttonbox = wx.StaticBoxSizer( box_label, wx.HORIZONTAL )
+ buttonbox.Add( buttonChange, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
+ buttonbox.Add( radio_vbox, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
+
+ hbox = wx.BoxSizer( wx.HORIZONTAL )
+ hbox.Add( grid, 0, wx.ALIGN_LEFT|wx.ALL, 15 )
+ hbox.Add( buttonbox, 0, wx.ALIGN_RIGHT|wx.BOTTOM, 20 )
+
+
+ box_label = wx.StaticBox( self, -1, "Bounds Control" )
+ boundsbox = wx.StaticBoxSizer( box_label, wx.HORIZONTAL )
+ self.set_bounds = wx.CheckBox( self, -1, "Set time bounds:" )
+
+ minlabel = wx.StaticText( self, -1, "minimum time:" )
+ self.min = timectl.wxTimeCtrl( self, -1, name="min", display_seconds = False )
self.min.Enable( False )
- maxlabel = wxStaticText( self, -1, "maximum time:" )
- self.max = wxTimeCtrl( self, -1, name="max", display_seconds = False )
+ maxlabel = wx.StaticText( self, -1, "maximum time:" )
+ self.max = timectl.wxTimeCtrl( self, -1, name="max", display_seconds = False )
self.max.Enable( False )
- self.limit_check = wxCheckBox( self, -1, "Limit control" )
+ self.limit_check = wx.CheckBox( self, -1, "Limit control" )
- label = wxStaticText( self, -1, "Resulting time control:" )
- self.target_ctrl = wxTimeCtrl( self, -1, name="new" )
+ label = wx.StaticText( self, -1, "Resulting time control:" )
+ self.target_ctrl = timectl.wxTimeCtrl( self, -1, name="new" )
- grid2 = wxFlexGridSizer( 0, 2, 0, 0 )
- grid2.Add( (20, 0), 0, wxALIGN_LEFT|wxALL, 5 )
- grid2.Add( (20, 0), 0, wxALIGN_LEFT|wxALL, 5 )
+ grid2 = wx.FlexGridSizer( 0, 2, 0, 0 )
+ grid2.Add( (20, 0), 0, wx.ALIGN_LEFT|wx.ALL, 5 )
+ grid2.Add( (20, 0), 0, wx.ALIGN_LEFT|wx.ALL, 5 )
- grid2.Add( self.set_bounds, 0, wxALIGN_LEFT|wxALL, 5 )
- grid3 = wxFlexGridSizer( 0, 2, 5, 5 )
- grid3.Add(minlabel, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL )
- grid3.Add( self.min, 0, wxALIGN_LEFT )
- grid3.Add(maxlabel, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL )
- grid3.Add( self.max, 0, wxALIGN_LEFT )
- grid2.Add(grid3, 0, wxALIGN_LEFT )
+ grid2.Add( self.set_bounds, 0, wx.ALIGN_LEFT|wx.ALL, 5 )
+ grid3 = wx.FlexGridSizer( 0, 2, 5, 5 )
+ grid3.Add(minlabel, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL )
+ grid3.Add( self.min, 0, wx.ALIGN_LEFT )
+ grid3.Add(maxlabel, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL )
+ grid3.Add( self.max, 0, wx.ALIGN_LEFT )
+ grid2.Add(grid3, 0, wx.ALIGN_LEFT )
- grid2.Add( self.limit_check, 0, wxALIGN_LEFT|wxALL, 5 )
- grid2.Add( (20, 0), 0, wxALIGN_LEFT|wxALL, 5 )
+ grid2.Add( self.limit_check, 0, wx.ALIGN_LEFT|wx.ALL, 5 )
+ grid2.Add( (20, 0), 0, wx.ALIGN_LEFT|wx.ALL, 5 )
- grid2.Add( (20, 0), 0, wxALIGN_LEFT|wxALL, 5 )
- grid2.Add( (20, 0), 0, wxALIGN_LEFT|wxALL, 5 )
- grid2.Add( label, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5 )
- grid2.Add( self.target_ctrl, 0, wxALIGN_LEFT|wxALL, 5 )
- boundsbox.Add(grid2, 0, wxALIGN_CENTER|wxEXPAND|wxALL, 5)
+ grid2.Add( (20, 0), 0, wx.ALIGN_LEFT|wx.ALL, 5 )
+ grid2.Add( (20, 0), 0, wx.ALIGN_LEFT|wx.ALL, 5 )
+ grid2.Add( label, 0, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
+ grid2.Add( self.target_ctrl, 0, wx.ALIGN_LEFT|wx.ALL, 5 )
+ boundsbox.Add(grid2, 0, wx.ALIGN_CENTER|wx.EXPAND|wx.ALL, 5)
- vbox = wxBoxSizer( wxVERTICAL )
+ vbox = wx.BoxSizer( wx.VERTICAL )
vbox.Add( (20, 20) )
- vbox.Add( hbox, 0, wxALIGN_LEFT|wxALL, 5)
- vbox.Add( boundsbox, 0, wxALIGN_LEFT|wxALL, 5 )
+ vbox.Add( hbox, 0, wx.ALIGN_LEFT|wx.ALL, 5)
+ vbox.Add( boundsbox, 0, wx.ALIGN_LEFT|wx.ALL, 5 )
- outer_box = wxBoxSizer( wxVERTICAL )
- outer_box.Add( vbox, 0, wxALIGN_LEFT|wxALL, 5)
+ outer_box = wx.BoxSizer( wx.VERTICAL )
+ outer_box.Add( vbox, 0, wx.ALIGN_LEFT|wx.ALL, 5)
# Turn on mxDateTime option only if we can import the module:
outer_box.Fit( self )
self.SetupScrolling()
- EVT_BUTTON( self, buttonChange.GetId(), self.OnButtonClick )
- EVT_TIMEUPDATE( self, self.time12.GetId(), self.OnTimeChange )
- EVT_TIMEUPDATE( self, self.time24.GetId(), self.OnTimeChange )
- EVT_TIMEUPDATE( self, self.spinless_ctrl.GetId(), self.OnTimeChange )
+ self.Bind(wx.EVT_BUTTON, self.OnButtonClick, buttonChange )
+ timectl.EVT_TIMEUPDATE( self, self.time12.GetId(), self.OnTimeChange )
+ timectl.EVT_TIMEUPDATE( self, self.time24.GetId(), self.OnTimeChange )
+ timectl.EVT_TIMEUPDATE( self, self.spinless_ctrl.GetId(), self.OnTimeChange )
- EVT_CHECKBOX( self, self.set_bounds.GetId(), self.OnBoundsCheck )
- EVT_CHECKBOX( self, self.limit_check.GetId(), self.SetTargetMinMax )
- EVT_TIMEUPDATE( self, self.min.GetId(), self.SetTargetMinMax )
- EVT_TIMEUPDATE( self, self.max.GetId(), self.SetTargetMinMax )
- EVT_TIMEUPDATE( self, self.target_ctrl.GetId(), self.OnTimeChange )
+ self.Bind(wx.EVT_CHECKBOX, self.OnBoundsCheck, self.set_bounds )
+ self.Bind(wx.EVT_CHECKBOX, self.SetTargetMinMax, self.limit_check )
+ timectl.EVT_TIMEUPDATE( self, self.min.GetId(), self.SetTargetMinMax )
+ timectl.EVT_TIMEUPDATE( self, self.max.GetId(), self.SetTargetMinMax )
+ timectl.EVT_TIMEUPDATE( self, self.target_ctrl.GetId(), self.OnTimeChange )
self.time12.SetValue( self.time24.GetValue() )
elif self.radioWx.GetValue():
- now = wxDateTime_Now()
+ now = wx.DateTime_Now()
self.time12.SetValue( now )
# (demonstrates that G/SetValue returns/takes a wxDateTime)
self.time24.SetValue( self.time12.GetValue(as_wxDateTime=True) )
def SetTargetMinMax( self, event=None ):
- min = max = None
+ min = None
+ max = None
if self.set_bounds.GetValue():
min = self.min.GetWxDateTime()
cur_min, cur_max = self.target_ctrl.GetBounds()
- if min != cur_min: self.target_ctrl.SetMin( min )
- if max != cur_max: self.target_ctrl.SetMax( max )
+ # jmg - A little expirimental change to ensure that min
+ # or max contain valid values before we use them
+ if min and (min != cur_min): self.target_ctrl.SetMin( min )
+ if max and (max != cur_max): self.target_ctrl.SetMax( max )
self.target_ctrl.SetLimited( self.limit_check.GetValue() )
if min != cur_min or max != cur_max:
new_min, new_max = self.target_ctrl.GetBounds()
+
if new_min and new_max:
self.log.write( "current min, max: (%s, %s)\n" % ( new_min.FormatTime(), new_max.FormatTime() ) )
else:
#----------------------------------------------------------------------
-overview = overviewdoc
+overview = timectl.__doc__
if __name__ == '__main__':
import sys,os
+# 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
-
-import time
+import time
+import wx
#---------------------------------------------------------------------------
+## For your convenience; an example of creating your own timer class.
+##
## class TestTimer(wxTimer):
## def __init__(self, log = None):
## wxTimer.__init__(self)
#---------------------------------------------------------------------------
-ID_Start = wxNewId()
-ID_Stop = wxNewId()
-ID_Timer = wxNewId()
-ID_Timer2 = wxNewId()
+ID_Start = wx.NewId()
+ID_Stop = wx.NewId()
+ID_Timer = wx.NewId()
+ID_Timer2 = wx.NewId()
-class TestTimerWin(wxPanel):
+class TestTimerWin(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.log = log
- wxStaticText(self, -1, "This is a timer example",
- wxPoint(15, 30))
-
- wxButton(self, ID_Start, ' Start ', wxPoint(15, 75), wxDefaultSize)
- wxButton(self, ID_Stop, ' Stop ', wxPoint(115, 75), wxDefaultSize)
+ wx.StaticText(self, -1, "This is a timer example", (15, 30))
+ wx.Button(self, ID_Start, ' Start ', (15, 75), wx.DefaultSize)
+ wx.Button(self, ID_Stop, ' Stop ', (115, 75), wx.DefaultSize)
- self.timer = wxTimer(self, # object to send the event to
- ID_Timer) # event id to use
+ self.timer = wx.Timer(self, # object to send the event to
+ ID_Timer) # event id to use
- self.timer2 = wxTimer(self, # object to send the event to
- ID_Timer2) # event id to use
+ self.timer2 = wx.Timer(self, # object to send the event to
+ ID_Timer2) # event id to use
- EVT_BUTTON(self, ID_Start, self.OnStart)
- EVT_BUTTON(self, ID_Stop, self.OnStop)
- EVT_TIMER(self, ID_Timer, self.OnTimer)
- EVT_TIMER(self, ID_Timer2, self.OnTimer2)
+ self.Bind(wx.EVT_BUTTON, self.OnStart, id=ID_Start)
+ self.Bind(wx.EVT_BUTTON, self.OnStop, id=ID_Stop)
+ self.Bind(wx.EVT_TIMER, self.OnTimer, id=ID_Timer)
+ self.Bind(wx.EVT_TIMER, self.OnTimer2, id=ID_Timer2)
def OnStart(self, event):
self.timer.Start(1000)
self.timer2.Stop()
def OnTimer(self, event):
- wxBell()
+ wx.Bell()
if self.log:
self.log.WriteText('beep!\n')
def OnTimer2(self, event):
- wxBell()
+ wx.Bell()
if self.log:
self.log.WriteText('beep 2!\n')
overview = """\
-The wxTimer class allows you to execute code at specified intervals.
+The wxTimer class allows you to execute code at specified intervals from
+within the wxPython event loop. Timers can be one-shot or repeating.
"""
+# 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
+import wx
haveToggleBtn = 1
+
try:
- wxToggleButton
+ wx.ToggleButton
except NameError:
haveToggleBtn = 0
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.log = log
- panel = wxPanel(self, -1)
- buttons = wxBoxSizer(wxHORIZONTAL)
+ panel = wx.Panel(self, -1)
+ buttons = wx.BoxSizer(wx.HORIZONTAL)
+
for word in "These are toggle buttons".split():
- b = wxToggleButton(panel, -1, word)
- EVT_TOGGLEBUTTON(self, b.GetId(), self.OnToggle)
- buttons.Add(b, flag=wxALL, border=5)
+ b = wx.ToggleButton(panel, -1, word)
+ self.Bind(wx.EVT_TOGGLEBUTTON, self.OnToggle, b)
+ buttons.Add(b, flag=wx.ALL, border=5)
panel.SetAutoLayout(True)
panel.SetSizer(buttons)
win = TestPanel(nb, log)
return win
else:
- dlg = wxMessageDialog(frame, 'wxToggleButton is not available on this platform.',
- 'Sorry', wxOK | wxICON_INFORMATION)
+ dlg = wx.MessageDialog(frame, 'wxToggleButton is not available on this platform.',
+ 'Sorry', wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
-
-
#----------------------------------------------------------------------
overview = """\
-"""
+wxToggleButton is a button that stays pressed when clicked by the user.
+In other words, it is similar to wxCheckBox in functionality but looks like a
+wxButton.
+This class is only available under wxMSW and wxGTK currently.
+"""
+# 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
-
-import images
+import wx
+import images
#---------------------------------------------------------------------------
-class TestToolBar(wxFrame):
+class TestToolBar(wx.Frame):
def __init__(self, parent, log):
- wxFrame.__init__(self, parent, -1, 'Test ToolBar', size=(500, 300))
+ wx.Frame.__init__(self, parent, -1, 'Test ToolBar', size=(500, 300))
self.log = log
self.timer = None
- EVT_CLOSE(self, self.OnCloseWindow)
+ self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
- wxWindow(self, -1).SetBackgroundColour(wxNamedColour("WHITE"))
+ wx.Window(self, -1).SetBackgroundColour(wx.NamedColour("WHITE"))
- tb = self.CreateToolBar( wxTB_HORIZONTAL
- | wxNO_BORDER
- | wxTB_FLAT
- | wxTB_TEXT
+ # Use the wxFrame internals to create the toolbar and associate it all
+ # in one tidy method call.
+ tb = self.CreateToolBar( wx.TB_HORIZONTAL
+ | wx.NO_BORDER
+ | wx.TB_FLAT
+ | wx.TB_TEXT
)
- #tb = wxToolBarSimple(self, -1, wxDefaultPosition, wxDefaultSize,
- # wxTB_HORIZONTAL | wxNO_BORDER | wxTB_FLAT)
+
+ # Here's a 'simple' toolbar example, and how to bind it using SetToolBar()
+ #tb = wx.ToolBarSimple(self, -1, wx.DefaultPosition, wx.DefaultSize,
+ # wx.TB_HORIZONTAL | wx.NO_BORDER | wx.TB_FLAT)
#self.SetToolBar(tb)
+ # But we're doing it a different way here.
log.write("Default toolbar tool size: %s\n" % tb.GetToolBitmapSize())
tb.AddSimpleTool(10, images.getNewBitmap(), "New", "Long help for 'New'")
#tb.AddLabelTool(10, "New", images.getNewBitmap(), shortHelp="New", longHelp="Long help for 'New'")
- EVT_TOOL(self, 10, self.OnToolClick)
- EVT_TOOL_RCLICKED(self, 10, self.OnToolRClick)
+ self.Bind(wx.EVT_TOOL, self.OnToolClick, id=10)
+ self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=10)
tb.AddSimpleTool(20, images.getOpenBitmap(), "Open", "Long help for 'Open'")
- EVT_TOOL(self, 20, self.OnToolClick)
- EVT_TOOL_RCLICKED(self, 20, self.OnToolRClick)
+ self.Bind(wx.EVT_TOOL, self.OnToolClick, id=20)
+ self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=20)
tb.AddSeparator()
tb.AddSimpleTool(30, images.getCopyBitmap(), "Copy", "Long help for 'Copy'")
- EVT_TOOL(self, 30, self.OnToolClick)
- EVT_TOOL_RCLICKED(self, 30, self.OnToolRClick)
+ self.Bind(wx.EVT_TOOL, self.OnToolClick, id=30)
+ self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=30)
tb.AddSimpleTool(40, images.getPasteBitmap(), "Paste", "Long help for 'Paste'")
- EVT_TOOL(self, 40, self.OnToolClick)
- EVT_TOOL_RCLICKED(self, 40, self.OnToolRClick)
+ self.Bind(wx.EVT_TOOL, self.OnToolClick, id=40)
+ self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=40)
tb.AddSeparator()
tool = tb.AddCheckTool(50, images.getTog1Bitmap(),
shortHelp="Toggle this")
- EVT_TOOL(self, 50, self.OnToolClick)
+ self.Bind(wx.EVT_TOOL, self.OnToolClick, id=50)
## tb.AddCheckTool(60, images.getTog1Bitmap(), images.getTog2Bitmap(),
## shortHelp="Toggle with 2 bitmaps")
-## EVT_TOOL(self, 60, self.OnToolClick)
+## self.Bind(EVT_TOOL, self.OnToolClick, id=60)
- EVT_TOOL_ENTER(self, -1, self.OnToolEnter)
- EVT_TOOL_RCLICKED(self, -1, self.OnToolRClick) # Match all
- EVT_TIMER(self, -1, self.OnClearSB)
+ self.Bind(wx.EVT_TOOL_ENTER, self.OnToolEnter)
+ self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick) # Match all
+ self.Bind(wx.EVT_TIMER, self.OnClearSB)
tb.AddSeparator()
- cbID = wxNewId()
- tb.AddControl(wxComboBox(tb, cbID, "", choices=["", "This", "is a", "wxComboBox"],
- size=(150,-1), style=wxCB_DROPDOWN))
- EVT_COMBOBOX(self, cbID, self.OnCombo)
- tb.AddControl(wxTextCtrl(tb, -1, "Toolbar controls!!", size=(150, -1)))
-
+ cbID = wx.NewId()
+
+ tb.AddControl(
+ wx.ComboBox(
+ tb, cbID, "", choices=["", "This", "is a", "wxComboBox"],
+ size=(150,-1), style=wx.CB_DROPDOWN
+ ))
+
+ self.Bind(wx.EVT_COMBOBOX, self.OnCombo, id=cbID)
+ tb.AddControl(wx.TextCtrl(tb, -1, "Toolbar controls!!", size=(150, -1)))
+
+ # Final thing to do for a toolbar is call the Realize() method. This
+ # causes it to render (more or less, that is).
tb.Realize()
def OnToolEnter(self, event):
self.log.WriteText('OnToolEnter: %s, %s\n' % (event.GetId(), event.GetInt()))
+
if self.timer is None:
- self.timer = wxTimer(self)
+ self.timer = wx.Timer(self)
+
if self.timer.IsRunning():
self.timer.Stop()
+
self.timer.Start(2000)
event.Skip()
-
-
-
overview = """\
"""
-
-
if __name__ == '__main__':
import sys,os
import run
+# 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
-import images
-import string
+import string
+import wx
+import images
#---------------------------------------------------------------------------
-class MyTreeCtrl(wxTreeCtrl):
+class MyTreeCtrl(wx.TreeCtrl):
def __init__(self, parent, id, pos, size, style, log):
- wxTreeCtrl.__init__(self, parent, id, pos, size, style)
+ wx.TreeCtrl.__init__(self, parent, id, pos, size, style)
self.log = log
def OnCompareItems(self, item1, item2):
#---------------------------------------------------------------------------
-class TestTreeCtrlPanel(wxPanel):
+class TestTreeCtrlPanel(wx.Panel):
def __init__(self, parent, log):
# Use the WANTS_CHARS style so the panel doesn't eat the Return key.
- wxPanel.__init__(self, parent, -1, style=wxWANTS_CHARS)
- EVT_SIZE(self, self.OnSize)
+ wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS)
+ self.Bind(wx.EVT_SIZE, self.OnSize)
self.log = log
- tID = wxNewId()
+ tID = wx.NewId()
- self.tree = MyTreeCtrl(self, tID, wxDefaultPosition, wxDefaultSize,
- wxTR_HAS_BUTTONS
- | wxTR_EDIT_LABELS
- #| wxTR_MULTIPLE
- #| wxTR_HIDE_ROOT
+ self.tree = MyTreeCtrl(self, tID, wx.DefaultPosition, wx.DefaultSize,
+ wx.TR_HAS_BUTTONS
+ | wx.TR_EDIT_LABELS
+ #| wx.TR_MULTIPLE
+ #| wx.TR_HIDE_ROOT
, self.log)
isz = (16,16)
- il = wxImageList(isz[0], isz[1])
- fldridx = il.Add(wxArtProvider_GetBitmap(wxART_FOLDER, wxART_OTHER, isz))
- fldropenidx = il.Add(wxArtProvider_GetBitmap(wxART_FILE_OPEN, wxART_OTHER, isz))
- fileidx = il.Add(wxArtProvider_GetBitmap(wxART_REPORT_VIEW, wxART_OTHER, isz))
+ il = wx.ImageList(isz[0], isz[1])
+ fldridx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, isz))
+ fldropenidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN, wx.ART_OTHER, isz))
+ fileidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_REPORT_VIEW, wx.ART_OTHER, isz))
smileidx = il.Add(images.getSmilesBitmap())
self.tree.SetImageList(il)
self.root = self.tree.AddRoot("The Root Item")
self.tree.SetPyData(self.root, None)
- self.tree.SetItemImage(self.root, fldridx, wxTreeItemIcon_Normal)
- self.tree.SetItemImage(self.root, fldropenidx, wxTreeItemIcon_Expanded)
+ self.tree.SetItemImage(self.root, fldridx, wx.TreeItemIcon_Normal)
+ self.tree.SetItemImage(self.root, fldropenidx, wx.TreeItemIcon_Expanded)
for x in range(15):
child = self.tree.AppendItem(self.root, "Item %d" % x)
self.tree.SetPyData(child, None)
- self.tree.SetItemImage(child, fldridx, wxTreeItemIcon_Normal)
- self.tree.SetItemImage(child, fldropenidx, wxTreeItemIcon_Expanded)
+ self.tree.SetItemImage(child, fldridx, wx.TreeItemIcon_Normal)
+ self.tree.SetItemImage(child, fldropenidx, wx.TreeItemIcon_Expanded)
+
for y in range(5):
last = self.tree.AppendItem(child, "item %d-%s" % (x, chr(ord("a")+y)))
self.tree.SetPyData(last, None)
- self.tree.SetItemImage(last, fldridx, wxTreeItemIcon_Normal)
- self.tree.SetItemImage(last, fldropenidx, wxTreeItemIcon_Expanded)
+ self.tree.SetItemImage(last, fldridx, wx.TreeItemIcon_Normal)
+ self.tree.SetItemImage(last, fldropenidx, wx.TreeItemIcon_Expanded)
+
for z in range(5):
item = self.tree.AppendItem(last, "item %d-%s-%d" % (x, chr(ord("a")+y), z))
self.tree.SetPyData(item, None)
- self.tree.SetItemImage(item, fileidx, wxTreeItemIcon_Normal)
- self.tree.SetItemImage(item, smileidx, wxTreeItemIcon_Selected)
+ self.tree.SetItemImage(item, fileidx, wx.TreeItemIcon_Normal)
+ self.tree.SetItemImage(item, smileidx, wx.TreeItemIcon_Selected)
self.tree.Expand(self.root)
- EVT_TREE_ITEM_EXPANDED (self, tID, self.OnItemExpanded)
- EVT_TREE_ITEM_COLLAPSED (self, tID, self.OnItemCollapsed)
- EVT_TREE_SEL_CHANGED (self, tID, self.OnSelChanged)
- EVT_TREE_BEGIN_LABEL_EDIT(self, tID, self.OnBeginEdit)
- EVT_TREE_END_LABEL_EDIT (self, tID, self.OnEndEdit)
- EVT_TREE_ITEM_ACTIVATED (self, tID, self.OnActivate)
+ self.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.OnItemExpanded, self.tree)
+ self.Bind(wx.EVT_TREE_ITEM_COLLAPSED, self.OnItemCollapsed, self.tree)
+ self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged, self.tree)
+ self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.OnBeginEdit, self.tree)
+ self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.OnEndEdit, self.tree)
+ self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnActivate, self.tree)
- EVT_LEFT_DCLICK(self.tree, self.OnLeftDClick)
- EVT_RIGHT_DOWN(self.tree, self.OnRightClick)
- EVT_RIGHT_UP(self.tree, self.OnRightUp)
+ self.tree.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick)
+ self.tree.Bind(wx.EVT_RIGHT_DOWN, self.OnRightClick)
+ self.tree.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
self.log.WriteText("OnBeginEdit\n")
# show how to prevent edit...
if self.tree.GetItemText(event.GetItem()) == "The Root Item":
- wxBell()
+ wx.Bell()
self.log.WriteText("You can't edit this one...\n")
# Lets just see what's visible of its children
cookie = 0
root = event.GetItem()
(child, cookie) = self.tree.GetFirstChild(root, cookie)
+
while child.IsOk():
self.log.WriteText("Child [%s] visible = %d" %
(self.tree.GetItemText(child),
def OnSelChanged(self, event):
self.item = event.GetItem()
self.log.WriteText("OnSelChanged: %s\n" % self.tree.GetItemText(self.item))
- if wxPlatform == '__WXMSW__':
+ if wx.Platform == '__WXMSW__':
self.log.WriteText("BoundingRect: %s\n" %
self.tree.GetBoundingRect(self.item, True))
#items = self.tree.GetSelections()
overview = """\
-A tree control presents information as a hierarchy, with items that may be expanded to show further items. Items in a tree control are referenced by wxTreeItemId handles.
+A tree control presents information as a hierarchy, with items that may be
+expanded to show further items. Items in a tree control are referenced by
+wxTreeItemId handles.
"""
+# 11/22/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
-from wxPython.gizmos import wxTreeListCtrl
+import wx
+import wx.gizmos as gizmos
-import images
+import images
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
self.log = log
- wxPanel.__init__(self, parent, -1)
- EVT_SIZE(self, self.OnSize)
+ wx.Panel.__init__(self, parent, -1)
+ self.Bind(wx.EVT_SIZE, self.OnSize)
- self.tree = wxTreeListCtrl(self, -1, style = wxTR_DEFAULT_STYLE
- #| wxTR_ROW_LINES
- #| wxTR_NO_LINES | wxTR_TWIST_BUTTONS
+ self.tree = gizmos.TreeListCtrl(self, -1, style = wx.TR_DEFAULT_STYLE
+ #| wx.TR_ROW_LINES
+ #| wx.TR_NO_LINES
+ #| wx.TR_TWIST_BUTTONS
)
isz = (16,16)
- il = wxImageList(isz[0], isz[1])
- fldridx = il.Add(wxArtProvider_GetBitmap(wxART_FOLDER, wxART_OTHER, isz))
- fldropenidx = il.Add(wxArtProvider_GetBitmap(wxART_FILE_OPEN, wxART_OTHER, isz))
- fileidx = il.Add(wxArtProvider_GetBitmap(wxART_REPORT_VIEW, wxART_OTHER, isz))
+ il = wx.ImageList(isz[0], isz[1])
+ fldridx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, isz))
+ fldropenidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN, wx.ART_OTHER, isz))
+ fileidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_REPORT_VIEW, wx.ART_OTHER, isz))
smileidx = il.Add(images.getSmilesBitmap())
self.tree.SetImageList(il)
self.root = self.tree.AddRoot("The Root Item")
self.tree.SetItemText(self.root, "col 1 root", 1)
self.tree.SetItemText(self.root, "col 2 root", 2)
- self.tree.SetItemImage(self.root, fldridx, which = wxTreeItemIcon_Normal)
- self.tree.SetItemImage(self.root, fldropenidx, which = wxTreeItemIcon_Expanded)
+ self.tree.SetItemImage(self.root, fldridx, which = wx.TreeItemIcon_Normal)
+ self.tree.SetItemImage(self.root, fldropenidx, which = wx.TreeItemIcon_Expanded)
for x in range(15):
child = self.tree.AppendItem(self.root, txt)
self.tree.SetItemText(child, txt + "(c1)", 1)
self.tree.SetItemText(child, txt + "(c2)", 2)
- self.tree.SetItemImage(child, fldridx, which = wxTreeItemIcon_Normal)
- self.tree.SetItemImage(child, fldropenidx, which = wxTreeItemIcon_Expanded)
+ self.tree.SetItemImage(child, fldridx, which = wx.TreeItemIcon_Normal)
+ self.tree.SetItemImage(child, fldropenidx, which = wx.TreeItemIcon_Expanded)
for y in range(5):
txt = "item %d-%s" % (x, chr(ord("a")+y))
last = self.tree.AppendItem(child, txt)
self.tree.SetItemText(last, txt + "(c1)", 1)
self.tree.SetItemText(last, txt + "(c2)", 2)
- self.tree.SetItemImage(last, fldridx, which = wxTreeItemIcon_Normal)
- self.tree.SetItemImage(last, fldropenidx, which = wxTreeItemIcon_Expanded)
+ self.tree.SetItemImage(last, fldridx, which = wx.TreeItemIcon_Normal)
+ self.tree.SetItemImage(last, fldropenidx, which = wx.TreeItemIcon_Expanded)
for z in range(5):
txt = "item %d-%s-%d" % (x, chr(ord("a")+y), z)
item = self.tree.AppendItem(last, txt)
self.tree.SetItemText(item, txt + "(c1)", 1)
self.tree.SetItemText(item, txt + "(c2)", 2)
- self.tree.SetItemImage(item, fileidx, which = wxTreeItemIcon_Normal)
- self.tree.SetItemImage(item, smileidx, which = wxTreeItemIcon_Selected)
+ self.tree.SetItemImage(item, fileidx, which = wx.TreeItemIcon_Normal)
+ self.tree.SetItemImage(item, smileidx, which = wx.TreeItemIcon_Selected)
self.tree.Expand(self.root)
- EVT_RIGHT_UP(self.tree.GetMainWindow(), self.OnRightUp)
+ self.tree.GetMainWindow().Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
def OnRightUp(self, evt):
pos = self.tree.GetMainWindow().ClientToScreen(pos)
pos = self.tree.ScreenToClient(pos)
item, flags, col = self.tree.HitTest(pos)
+
if item:
print flags, col, self.tree.GetItemText(item, col)
overview = """<html><body>
<h2><center>wxTreeListCtrl</center></h2>
-The wxTreeListCtrl is essentially a wxTreeCtrl with extra columns,
-such that the look is similar to a wxListCtrl.
+The wx.TreeListCtrl is essentially a wx.TreeCtrl with extra columns,
+such that the look is similar to a wx.ListCtrl.
</body></html>
"""
-
-
if __name__ == '__main__':
#raw_input("Press enter...")
import sys,os
+# 11/22/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
+import wx
#----------------------------------------------------------------------
# The wxVListBox is much like a regular wxListBox except you draw the
# items yourself and the items can vary in height.
-class MyVListBox(wxVListBox):
+class MyVListBox(wx.VListBox):
# This method must be overridden. When called it should draw the
# n'th item on the dc within the rect. How it is drawn, and what
# is drawn is entirely up to you.
def OnDrawItem(self, dc, rect, n):
dc.DrawLabel(self._getItemText(n), rect,
- wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL)
+ wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
# This method must be overridden. It should return the height
# required to draw the n'th item.
def OnMeasureItem(self, n):
height = 0
+
for line in self._getItemText(n).split('\n'):
w, h = self.GetTextExtent(line)
height += h
+
return height + 5
#----------------------------------------------------------------------
-# The wxHtmlListBox derives from wxVListBox, but draws each item
-# itself as a wxHtmlCell.
-class MyHtmlListBox(wxHtmlListBox):
+# The wx.HtmlListBox derives from wx.VListBox, but draws each item
+# itself as a wx.HtmlCell.
+class MyHtmlListBox(wx.HtmlListBox):
def OnGetItem(self, n):
if n % 2 == 0:
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
self.log = log
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
spacer = 50
- vlb = MyVListBox(self, -1, size=(150, 250), style=wxBORDER_SUNKEN)
+ vlb = MyVListBox(self, -1, size=(150, 250), style=wx.BORDER_SUNKEN)
vlb.SetItemCount(50)
vlb.SetSelection(0)
vlb.SetFocus()
- vlbSizer = wxBoxSizer(wxVERTICAL)
+ vlbSizer = wx.BoxSizer(wx.VERTICAL)
vlbSizer.Add((spacer, spacer))
- vlbSizer.Add(wxStaticText(self, -1, "wxVListBox"), 0, 5, wxALL)
+ vlbSizer.Add(wx.StaticText(self, -1, "wx.VListBox"), 0, 5, wx.ALL)
vlbSizer.Add(vlb)
- hlb = MyHtmlListBox(self, -1, size=(150, 250), style=wxBORDER_SUNKEN)
+ hlb = MyHtmlListBox(self, -1, size=(150, 250), style=wx.BORDER_SUNKEN)
hlb.SetItemCount(50)
hlb.SetSelection(0)
- hlbSizer = wxBoxSizer(wxVERTICAL)
+ hlbSizer = wx.BoxSizer(wx.VERTICAL)
hlbSizer.Add((spacer, spacer))
- hlbSizer.Add(wxStaticText(self, -1, "wxHtmlListBox"), 0, 5, wxALL)
+ hlbSizer.Add(wx.StaticText(self, -1, "wx.HtmlListBox"), 0, 5, wx.ALL)
hlbSizer.Add(hlb)
- sizer = wxBoxSizer(wxHORIZONTAL)
+ sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add((spacer, spacer))
sizer.Add(vlbSizer)
sizer.Add((spacer, spacer))
+# 11/22/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
-from wxPython.lib.grids import wxFlexGridSizer
+import string
+import wx
-import string
#----------------------------------------------------------------------
ALPHA_ONLY = 1
DIGIT_ONLY = 2
-class MyValidator(wxPyValidator):
+class MyValidator(wx.PyValidator):
def __init__(self, flag=None, pyVar=None):
- wxPyValidator.__init__(self)
+ wx.PyValidator.__init__(self)
self.flag = flag
- EVT_CHAR(self, self.OnChar)
+ self.Bind(wx.EVT_CHAR, self.OnChar)
def Clone(self):
return MyValidator(self.flag)
def Validate(self, win):
tc = self.GetWindow()
val = tc.GetValue()
+
if self.flag == ALPHA_ONLY:
for x in val:
if x not in string.letters:
def OnChar(self, event):
key = event.KeyCode()
- if key < WXK_SPACE or key == WXK_DELETE or key > 255:
+
+ if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255:
event.Skip()
return
+
if self.flag == ALPHA_ONLY and chr(key) in string.letters:
event.Skip()
return
+
if self.flag == DIGIT_ONLY and chr(key) in string.digits:
event.Skip()
return
- if not wxValidator_IsSilent():
- wxBell()
+ if not wx.Validator_IsSilent():
+ wx.Bell()
# Returning without calling even.Skip eats the event before it
# gets to the text control
#----------------------------------------------------------------------
-class TestValidatorPanel(wxPanel):
+class TestValidatorPanel(wx.Panel):
def __init__(self, parent):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.SetAutoLayout(True)
VSPACE = 10
- fgs = wxFlexGridSizer(0, 2)
+ fgs = wx.FlexGridSizer(0, 2)
fgs.Add((1,1))
fgs.Add(wxStaticText(self, -1, "These controls have validators that limit\n"
fgs.Add((1,VSPACE)); fgs.Add((1,VSPACE))
- label = wxStaticText(self, -1, "Alpha Only: ")
- fgs.Add(label, 0, wxALIGN_RIGHT|wxCENTER)
+ label = wx.StaticText(self, -1, "Alpha Only: ")
+ fgs.Add(label, 0, wx.ALIGN_RIGHT|wx.CENTER)
- fgs.Add(wxTextCtrl(self, -1, "", validator = MyValidator(ALPHA_ONLY)))
+ fgs.Add(wx.TextCtrl(self, -1, "", validator = MyValidator(ALPHA_ONLY)))
fgs.Add((1,VSPACE)); fgs.Add((1,VSPACE))
- label = wxStaticText(self, -1, "Digits Only: ")
- fgs.Add(label, 0, wxALIGN_RIGHT|wxCENTER)
- fgs.Add(wxTextCtrl(self, -1, "", validator = MyValidator(DIGIT_ONLY)))
+ label = wx.StaticText(self, -1, "Digits Only: ")
+ fgs.Add(label, 0, wx.ALIGN_RIGHT|wxCENTER)
+ fgs.Add(wx.TextCtrl(self, -1, "", validator = MyValidator(DIGIT_ONLY)))
fgs.Add((1,VSPACE)); fgs.Add((1,VSPACE))
fgs.Add((1,VSPACE)); fgs.Add((1,VSPACE))
fgs.Add((0,0))
- b = wxButton(self, -1, "Test Dialog Validation")
- EVT_BUTTON(self, b.GetId(), self.OnDoDialog)
+ b = wx.Button(self, -1, "Test Dialog Validation")
+ self.Bind(EVT_BUTTON, self.OnDoDialog, b)
fgs.Add(b)
- border = wxBoxSizer()
- border.Add(fgs, 1, wxGROW|wxALL, 25)
+ border = wx.BoxSizer()
+ border.Add(fgs, 1, wx.GROW|wx.ALL, 25)
self.SetSizer(border)
self.Layout()
#----------------------------------------------------------------------
-class TextObjectValidator(wxPyValidator):
+class TextObjectValidator(wx.PyValidator):
""" This validator is used to ensure that the user has entered something
into the text object editor dialog's text field.
"""
def __init__(self):
""" Standard constructor.
"""
- wxPyValidator.__init__(self)
+ wx.PyValidator.__init__(self)
text = textCtrl.GetValue()
if len(text) == 0:
- wxMessageBox("A text object must contain some text!", "Error")
+ wx.MessageBox("A text object must contain some text!", "Error")
textCtrl.SetBackgroundColour("pink")
textCtrl.SetFocus()
textCtrl.Refresh()
return False
else:
textCtrl.SetBackgroundColour(
- wxSystemSettings_GetColour(wxSYS_COLOUR_WINDOW))
+ wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW))
textCtrl.Refresh()
return True
#----------------------------------------------------------------------
-class TestValidateDialog(wxDialog):
+class TestValidateDialog(wx.Dialog):
def __init__(self, parent):
- wxDialog.__init__(self, parent, -1, "Validated Dialog")
+ wx.Dialog.__init__(self, parent, -1, "Validated Dialog")
self.SetAutoLayout(True)
VSPACE = 10
- fgs = wxFlexGridSizer(0, 2)
+ fgs = wx.FlexGridSizer(0, 2)
fgs.Add((1,1));
fgs.Add(wxStaticText(self, -1,
fgs.Add((1,VSPACE)); fgs.Add((1,VSPACE))
- label = wxStaticText(self, -1, "First: ")
- fgs.Add(label, 0, wxALIGN_RIGHT|wxCENTER)
+ label = wx.StaticText(self, -1, "First: ")
+ fgs.Add(label, 0, wx.ALIGN_RIGHT|wx.CENTER)
- fgs.Add(wxTextCtrl(self, -1, "", validator = TextObjectValidator()))
+ fgs.Add(wx.TextCtrl(self, -1, "", validator = TextObjectValidator()))
fgs.Add((1,VSPACE)); fgs.Add((1,VSPACE))
- label = wxStaticText(self, -1, "Second: ")
- fgs.Add(label, 0, wxALIGN_RIGHT|wxCENTER)
- fgs.Add(wxTextCtrl(self, -1, "", validator = TextObjectValidator()))
+ label = wx.StaticText(self, -1, "Second: ")
+ fgs.Add(label, 0, wx.ALIGN_RIGHT|wx.CENTER)
+ fgs.Add(wx.TextCtrl(self, -1, "", validator = TextObjectValidator()))
- buttons = wxBoxSizer(wxHORIZONTAL)
- b = wxButton(self, wxID_OK, "Okay")
+ buttons = wx.BoxSizer(wx.HORIZONTAL)
+ b = wx.Button(self, wx.ID_OK, "Okay")
b.SetDefault()
- buttons.Add(b, 0, wxALL, 10)
- buttons.Add(wxButton(self, wxID_CANCEL, "Cancel"), 0, wxALL, 10)
+ buttons.Add(b, 0, wx.ALL, 10)
+ buttons.Add(wx.Button(self, wx.ID_CANCEL, "Cancel"), 0, wx.ALL, 10)
- border = wxBoxSizer(wxVERTICAL)
- border.Add(fgs, 1, wxGROW|wxALL, 25)
+ border = wx.BoxSizer(wx.VERTICAL)
+ border.Add(fgs, 1, wx.GROW|wx.ALL, 25)
border.Add(buttons)
self.SetSizer(border)
border.Fit(self)
overview = """\
-wxValidator is the base class for a family of validator classes that mediate between a class of control, and application data.
-
-A validator has three major roles:
-
-1. to transfer data from a C++ variable or own storage to and from a control;
-
-2. to validate data in a control, and show an appropriate error message;
-
-3. to filter events (such as keystrokes), thereby changing the behaviour of the associated control.
-
-Validators can be plugged into controls dynamically.
-
+<html>
+<body>
+wxValidator is the base class for a family of validator classes that mediate
+between a class of control, and application data.
+
+<p>A validator has three major roles:
+
+<p><ol>
+<li>to transfer data from a C++ variable or own storage to and from a control;
+<li>to validate data in a control, and show an appropriate error message;
+<li>to filter events (such as keystrokes), thereby changing the behaviour of the associated control.
+</ol>
+<p>Validators can be plugged into controls dynamically.
+</body>
+</html>
"""
+# 11/22/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+
+import wx
-from wxPython.wx import *
from Main import opj
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
- b = wxButton(self, -1, "Play Sound 1", (25, 25))
- EVT_BUTTON(self, b.GetId(), self.OnButton1)
+ b = wx.Button(self, -1, "Play Sound 1", (25, 25))
+ self.Bind(wx.EVT_BUTTON, self.OnButton1, b)
- b = wxButton(self, -1, "Play Sound 2", (25, 65))
- EVT_BUTTON(self, b.GetId(), self.OnButton2)
+ b = wx.Button(self, -1, "Play Sound 2", (25, 65))
+ self.Bind(wx.EVT_BUTTON, self.OnButton2, b)
def OnButton1(self, evt):
try:
- wave = wxWave(opj('data/anykey.wav'))
+ wave = wx.Wave(opj('data/anykey.wav'))
wave.Play()
except NotImplementedError, v:
- wxMessageBox(str(v), "Exception Message")
+ wx.MessageBox(str(v), "Exception Message")
def OnButton2(self, evt):
try:
- wave = wxWave(opj('data/plan.wav'))
+ wave = wx.Wave(opj('data/plan.wav'))
wave.Play()
except NotImplementedError, v:
- wxMessageBox(str(v), "Exception Message")
-
+ wx.MessageBox(str(v), "Exception Message")
#----------------------------------------------------------------------
overview = """\
-"""
-
+This class represents a short wave file, in Windows WAV format, that can
+be stored in memory and played. Currently this class is implemented on Windows
+and GTK (Linux) only.
+This demo offers two examples, both driven by buttons, but obviously the event
+that drives the playing of the sound can come from anywhere.
+"""
if __name__ == '__main__':
-
-from wxPython.wx import *
-from wxPython.wizard import *
-
-import images
+# 11/22/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+# 11/3-/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o WizardPage* doesn't support GetId()
+#
+
+import wx
+import wx.wizard as wiz
+import images
#----------------------------------------------------------------------
def makePageTitle(wizPg, title):
- sizer = wxBoxSizer(wxVERTICAL)
+ sizer = wx.BoxSizer(wx.VERTICAL)
wizPg.SetSizer(sizer)
- title = wxStaticText(wizPg, -1, title)
- title.SetFont(wxFont(18, wxSWISS, wxNORMAL, wxBOLD))
- sizer.AddWindow(title, 0, wxALIGN_CENTRE|wxALL, 5)
- sizer.AddWindow(wxStaticLine(wizPg, -1), 0, wxEXPAND|wxALL, 5)
+ title = wx.StaticText(wizPg, -1, title)
+ title.SetFont(wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD))
+ sizer.AddWindow(title, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
+ sizer.AddWindow(wx.StaticLine(wizPg, -1), 0, wx.EXPAND|wx.ALL, 5)
return sizer
#----------------------------------------------------------------------
-class TitledPage(wxWizardPageSimple):
+class TitledPage(wiz.WizardPageSimple):
def __init__(self, parent, title):
- wxWizardPageSimple.__init__(self, parent)
+ wiz.WizardPageSimple.__init__(self, parent)
self.sizer = makePageTitle(self, title)
#----------------------------------------------------------------------
-class SkipNextPage(wxPyWizardPage):
+class SkipNextPage(wiz.PyWizardPage):
def __init__(self, parent, title):
- wxPyWizardPage.__init__(self, parent)
+ wiz.PyWizardPage.__init__(self, parent)
self.next = self.prev = None
self.sizer = makePageTitle(self, title)
- self.cb = wxCheckBox(self, -1, "Skip next page")
- self.sizer.Add(self.cb, 0, wxALL, 5)
+ self.cb = wx.CheckBox(self, -1, "Skip next page")
+ self.sizer.Add(self.cb, 0, wx.ALL, 5)
def SetNext(self, next):
self.next = next
# Classes derived from wxPyWizardPanel must override
# GetNext and GetPrev, and may also override GetBitmap
# as well as all those methods overridable by
- # wxPyWindow.
+ # wx.PyWindow.
def GetNext(self):
"""If the checkbox is set then return the next page's next page"""
#----------------------------------------------------------------------
-class UseAltBitmapPage(wxPyWizardPage):
+class UseAltBitmapPage(wiz.PyWizardPage):
def __init__(self, parent, title):
- wxPyWizardPage.__init__(self, parent)
+ wiz.PyWizardPage.__init__(self, parent)
self.next = self.prev = None
self.sizer = makePageTitle(self, title)
- self.sizer.Add(wxStaticText(self, -1, "This page uses a different bitmap"),
- 0, wxALL, 5)
+ self.sizer.Add(wx.StaticText(self, -1, "This page uses a different bitmap"),
+ 0, wx.ALL, 5)
def SetNext(self, next):
self.next = next
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
- ID_wiz = wxNewId()
+class TestPanel(wx.Panel):
+ ID_wiz = wx.NewId()
def __init__(self, parent, log):
self.log = log
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
- b = wxButton(self, -1, "Run Simple Wizard", pos=(50, 50))
- EVT_BUTTON(self, b.GetId(), self.OnRunSimpleWizard)
+ b = wx.Button(self, -1, "Run Simple Wizard", pos=(50, 50))
+ self.Bind(wx.EVT_BUTTON, self.OnRunSimpleWizard, b)
- b = wxButton(self, -1, "Run Dynamic Wizard", pos=(50, 100))
- EVT_BUTTON(self, b.GetId(), self.OnRunDynamicWizard)
+ b = wx.Button(self, -1, "Run Dynamic Wizard", pos=(50, 100))
+ self.Bind(wx.EVT_BUTTON, self.OnRunDynamicWizard, b)
- EVT_WIZARD_PAGE_CHANGED(self, self.ID_wiz, self.OnWizPageChanged)
- EVT_WIZARD_PAGE_CHANGING(self, self.ID_wiz, self.OnWizPageChanging)
- EVT_WIZARD_CANCEL(self, self.ID_wiz, self.OnWizCancel)
- EVT_WIZARD_FINISHED(self, self.ID_wiz, self.OnWizFinished)
+ wiz.EVT_WIZARD_PAGE_CHANGED(self, self.ID_wiz, self.OnWizPageChanged)
+ wiz.EVT_WIZARD_PAGE_CHANGING(self, self.ID_wiz, self.OnWizPageChanging)
+ wiz.EVT_WIZARD_CANCEL(self, self.ID_wiz, self.OnWizCancel)
def OnWizPageChanged(self, evt):
dir = "forward"
else:
dir = "backward"
+
page = evt.GetPage()
self.log.write("OnWizPageChanged: %s, %s\n" % (dir, page.__class__))
dir = "forward"
else:
dir = "backward"
+
page = evt.GetPage()
self.log.write("OnWizPageChanging: %s, %s\n" % (dir, page.__class__))
# Show how to prevent cancelling of the wizard. The
# other events can be Veto'd too.
if page is self.page1:
- wxMessageBox("Cancelling on the first page has been prevented.", "Sorry")
+ wx.MessageBox("Cancelling on the first page has been prevented.", "Sorry")
evt.Veto()
def OnWizFinished(self, evt):
def OnRunSimpleWizard(self, evt):
# Create the wizard and the pages
- wizard = wxWizard(self, self.ID_wiz, "Simple Wizard",
+ wizard = wiz.Wizard(self, self.ID_wiz, "Simple Wizard",
images.getWizTest1Bitmap())
page1 = TitledPage(wizard, "Page 1")
page2 = TitledPage(wizard, "Page 2")
page4 = TitledPage(wizard, "Page 4")
self.page1 = page1
- page1.sizer.Add(wxStaticText(page1, -1, """
+ page1.sizer.Add(wx.StaticText(page1, -1, """
This wizard is totally useless, but is meant to show how to
chain simple wizard pages together in a non-dynamic manner.
IOW, the order of the pages never changes, and so the
wxWizardPageSimple class can easily be used for the pages."""))
wizard.FitToPage(page1)
- page4.sizer.Add(wxStaticText(page4, -1, "\nThis is the last page."))
+ page4.sizer.Add(wx.StaticText(page4, -1, "\nThis is the last page."))
# Use the convenience Chain function to connect the pages
- wxWizardPageSimple_Chain(page1, page2)
- wxWizardPageSimple_Chain(page2, page3)
- wxWizardPageSimple_Chain(page3, page4)
+ wiz.WizardPageSimple_Chain(page1, page2)
+ wiz.WizardPageSimple_Chain(page2, page3)
+ wiz.WizardPageSimple_Chain(page3, page4)
if wizard.RunWizard(page1):
- wxMessageBox("Wizard completed successfully", "That's all folks!")
+ wx.MessageBox("Wizard completed successfully", "That's all folks!")
else:
- wxMessageBox("Wizard was cancelled", "That's all folks!")
+ wx.MessageBox("Wizard was cancelled", "That's all folks!")
def OnRunDynamicWizard(self, evt):
# Create the wizard and the pages
- #wizard = wxPreWizard()
- #wizard.SetExtraStyle(wxWIZARD_EX_HELPBUTTON)
+ #wizard = wx.PreWizard()
+ #wizard.SetExtraStyle(wx.WIZARD_EX_HELPBUTTON)
#wizard.Create(self, self.ID_wiz, "Simple Wizard",
# images.getWizTest1Bitmap())
- wizard = wxWizard(self, self.ID_wiz, "Simple Wizard",
+ wizard = wiz.Wizard(self, self.ID_wiz, "Simple Wizard",
images.getWizTest1Bitmap())
page1 = TitledPage(wizard, "Page 1")
page5 = TitledPage(wizard, "Page 5")
self.page1 = page1
- page1.sizer.Add(wxStaticText(page1, -1, """
+ page1.sizer.Add(wx.StaticText(page1, -1, """
This wizard shows the ability to choose at runtime the order
of the pages and also which bitmap is shown.
"""))
wizard.FitToPage(page1)
- page5.sizer.Add(wxStaticText(page5, -1, "\nThis is the last page."))
+ page5.sizer.Add(wx.StaticText(page5, -1, "\nThis is the last page."))
# Set the initial order of the pages
page1.SetNext(page2)
if wizard.RunWizard(page1):
- wxMessageBox("Wizard completed successfully", "That's all folks!")
+ wx.MessageBox("Wizard completed successfully", "That's all folks!")
else:
- wxMessageBox("Wizard was cancelled", "That's all folks!")
+ wx.MessageBox("Wizard was cancelled", "That's all folks!")
#----------------------------------------------------------------------
+# 11/22/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
+
+import wx
+import wx.xrc as xrc
-from wxPython.wx import *
-from wxPython.xrc import *
from Main import opj
#----------------------------------------------------------------------
RESFILE = opj("data/resource_wdr.xrc")
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
self.log = log
# make the components
- label = wxStaticText(self, -1, "The lower panel was built from this XML:")
- label.SetFont(wxFont(12, wxSWISS, wxNORMAL, wxBOLD))
+ label = wx.StaticText(self, -1, "The lower panel was built from this XML:")
+ label.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD))
resourceText = open(RESFILE).read()
- text = wxTextCtrl(self, -1, resourceText,
- style=wxTE_READONLY|wxTE_MULTILINE)
+ text = wx.TextCtrl(self, -1, resourceText,
+ style=wx.TE_READONLY|wx.TE_MULTILINE)
text.SetInsertionPoint(0)
- line = wxStaticLine(self, -1)
+ line = wx.StaticLine(self, -1)
# This shows a few different ways to load XML Resources
if 0:
# XML Resources can be loaded from a file like this:
- res = wxXmlResource(RESFILE)
+ res = xrc.XmlResource(RESFILE)
elif 1:
# or from a Virtual FileSystem:
- wxFileSystem_AddHandler(wxMemoryFSHandler())
- wxMemoryFSHandler_AddFile("XRC_Resources/data_file", resourceText)
- res = wxXmlResource("memory:XRC_Resources/data_file")
+ wx.FileSystem_AddHandler(wx.MemoryFSHandler())
+ wx.MemoryFSHandler_AddFile("XRC_Resources/data_file", resourceText)
+ res = xrc.XmlResource("memory:XRC_Resources/data_file")
else:
# or from a string, like this:
- res = wxEmptyXmlResource()
+ res = xrc.EmptyXmlResource()
res.LoadFromString(resourceText)
panel = res.LoadPanel(self, "MyPanel")
# and do the layout
- sizer = wxBoxSizer(wxVERTICAL)
- sizer.Add(label, 0, wxEXPAND|wxTOP|wxLEFT, 5)
- sizer.Add(text, 1, wxEXPAND|wxALL, 5)
- sizer.Add(line, 0, wxEXPAND)
- sizer.Add(panel, 1, wxEXPAND|wxALL, 5)
+ sizer = wx.BoxSizer(wx.VERTICAL)
+ sizer.Add(label, 0, wx.EXPAND|wx.TOP|wx.LEFT, 5)
+ sizer.Add(text, 1, wx.EXPAND|wx.ALL, 5)
+ sizer.Add(line, 0, wx.EXPAND)
+ sizer.Add(panel, 1, wx.EXPAND|wx.ALL, 5)
self.SetSizer(sizer)
self.SetAutoLayout(True)
"""
-
if __name__ == '__main__':
import sys,os
import run
-
-from wxPython.wx import *
-from wxPython.xrc import *
+# 11/22/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+# o There are issues using the wx namespace within the xrc code.
+#
+# 11/30/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Error report: "Error: No handler found for XML node 'object',
+# class 'wx.StaticText'!"; no text shows on panel.
+#
+
+import wx
+import wx.xrc as xrc
#----------------------------------------------------------------------
<object class="MyBluePanel" name="MyPanel">
<size>200,100</size>
- <object class="wxStaticText" name="label1">
- <label>This blue panel is a class derived from wxPanel,\nand is loaded by a custom wxXmlResourceHandler.</label>
+ <object class="wx.StaticText" name="label1">
+ <label>This blue panel is a class derived from wx.Panel,\nand is loaded by a custom XmlResourceHandler.</label>
<pos>10,10</pos>
</object>
</object>
#----------------------------------------------------------------------
-class MyBluePanel(wxPanel):
+class MyBluePanel(wx.Panel):
def __init__(self, parent, id, pos, size, style, name):
- wxPanel.__init__(self, parent, id, pos, size, style, name)
+ wx.Panel.__init__(self, parent, id, pos, size, style, name)
# This is the little bit of customization that we do for this
# silly example. It could just as easily have been done in
# class a little differently... This could obviously be done with a
# single class, but I wanted to make separate ones to make clear what
# the different requirements are.
-class PreMyBluePanel(wxPanel):
+class PreMyBluePanel(wx.Panel):
def __init__(self):
- p = wxPrePanel()
+ p = wx.PrePanel()
self.PostCreate(p)
def Create(self, parent, id, pos, size, style, name):
- wxPanel.Create(self, parent, id, pos, size, style, name)
+ wx.Panel.Create(self, parent, id, pos, size, style, name)
self.SetBackgroundColour("BLUE")
self.SetForegroundColour("WHITE")
#----------------------------------------------------------------------
-class MyBluePanelXmlHandler(wxXmlResourceHandler):
+class MyBluePanelXmlHandler(xrc.XmlResourceHandler):
def __init__(self):
- wxXmlResourceHandler.__init__(self)
+ xrc.XmlResourceHandler.__init__(self)
# Specify the styles recognized by objects of this type
- self.AddStyle("wxNO_3D", wxNO_3D);
- self.AddStyle("wxTAB_TRAVERSAL", wxTAB_TRAVERSAL);
- self.AddStyle("wxWS_EX_VALIDATE_RECURSIVELY", wxWS_EX_VALIDATE_RECURSIVELY);
- self.AddStyle("wxCLIP_CHILDREN", wxCLIP_CHILDREN);
+ self.AddStyle("wx.NO_3D", wx.NO_3D);
+ self.AddStyle("wx.TAB_TRAVERSAL", wx.TAB_TRAVERSAL);
+ self.AddStyle("wx.WS_EX_VALIDATE_RECURSIVELY", wx.WS_EX_VALIDATE_RECURSIVELY);
+ self.AddStyle("wx.CLIP_CHILDREN", wx.CLIP_CHILDREN);
self.AddWindowStyles();
# This method and the next one are required for XmlResourceHandlers
self.GetID(),
self.GetPosition(),
self.GetSize(),
- self.GetStyle("style", wxTAB_TRAVERSAL),
+ self.GetStyle("style", wx.TAB_TRAVERSAL),
self.GetName()
)
else:
self.GetID(),
self.GetPosition(),
self.GetSize(),
- self.GetStyle("style", wxTAB_TRAVERSAL),
+ self.GetStyle("style", wx.TAB_TRAVERSAL),
self.GetName()
)
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
self.log = log
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
# make the components
- label = wxStaticText(self, -1, "The lower panel was built from this XML:")
- label.SetFont(wxFont(12, wxSWISS, wxNORMAL, wxBOLD))
+ label = wx.StaticText(self, -1, "The lower panel was built from this XML:")
+ label.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD))
- text = wxTextCtrl(self, -1, resourceText,
- style=wxTE_READONLY|wxTE_MULTILINE)
+ text = wx.TextCtrl(self, -1, resourceText,
+ style=wx.TE_READONLY|wx.TE_MULTILINE)
text.SetInsertionPoint(0)
- line = wxStaticLine(self, -1)
+ line = wx.StaticLine(self, -1)
# Load the resource
- res = wxEmptyXmlResource()
+ res = xrc.EmptyXmlResource()
res.InsertHandler(MyBluePanelXmlHandler())
res.LoadFromString(resourceText)
panel = res.LoadObject(self, "MyPanel", "MyBluePanel")
# and do the layout
- sizer = wxBoxSizer(wxVERTICAL)
- sizer.Add(label, 0, wxEXPAND|wxTOP|wxLEFT, 5)
- sizer.Add(text, 1, wxEXPAND|wxALL, 5)
- sizer.Add(line, 0, wxEXPAND)
- sizer.Add(panel, 1, wxEXPAND|wxALL, 5)
+ sizer = wx.BoxSizer(wx.VERTICAL)
+ sizer.Add(label, 0, wx.EXPAND|wx.TOP|wx.LEFT, 5)
+ sizer.Add(text, 1, wx.EXPAND|wx.ALL, 5)
+ sizer.Add(line, 0, wx.EXPAND)
+ sizer.Add(panel, 1, wx.EXPAND|wx.ALL, 5)
self.SetSizer(sizer)
self.SetAutoLayout(True)
+# 11/22/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+#
-from wxPython.wx import *
-from wxPython.xrc import *
+import wx
+import wx.xrc as xrc
#----------------------------------------------------------------------
#----------------------------------------------------------------------
-class MyBluePanel(wxPanel):
+class MyBluePanel(wx.Panel):
def __init__(self):
- p = wxPrePanel()
+ p = wx.PrePanel()
self.PostCreate(p)
- EVT_WINDOW_CREATE(self, self.OnCreate)
+ self.Bind(wx.EVT_WINDOW_CREATE, self.OnCreate)
def OnCreate(self, evt):
# This is the little bit of customization that we do for this
#----------------------------------------------------------------------
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
def __init__(self, parent, log):
self.log = log
- wxPanel.__init__(self, parent, -1)
+ wx.Panel.__init__(self, parent, -1)
# make the components
- label = wxStaticText(self, -1, "The lower panel was built from this XML:")
- label.SetFont(wxFont(12, wxSWISS, wxNORMAL, wxBOLD))
+ label = wx.StaticText(self, -1, "The lower panel was built from this XML:")
+ label.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD))
- text = wxTextCtrl(self, -1, resourceText,
- style=wxTE_READONLY|wxTE_MULTILINE)
+ text = wx.TextCtrl(self, -1, resourceText,
+ style=wx.TE_READONLY|wx.TE_MULTILINE)
text.SetInsertionPoint(0)
- line = wxStaticLine(self, -1)
+ line = wx.StaticLine(self, -1)
# Load the resource
- res = wxEmptyXmlResource()
+ res = xrc.EmptyXmlResource()
res.LoadFromString(resourceText)
# Now create a panel from the resource data
panel = res.LoadPanel(self, "MyPanel")
# and do the layout
- sizer = wxBoxSizer(wxVERTICAL)
- sizer.Add(label, 0, wxEXPAND|wxTOP|wxLEFT, 5)
- sizer.Add(text, 1, wxEXPAND|wxALL, 5)
- sizer.Add(line, 0, wxEXPAND)
- sizer.Add(panel, 1, wxEXPAND|wxALL, 5)
+ sizer = wx.BoxSizer(wx.VERTICAL)
+ sizer.Add(label, 0, wx.EXPAND|wx.TOP|wx.LEFT, 5)
+ sizer.Add(text, 1, wx.EXPAND|wx.ALL, 5)
+ sizer.Add(line, 0, wx.EXPAND)
+ sizer.Add(panel, 1, wx.EXPAND|wx.ALL, 5)
self.SetSizer(sizer)
self.SetAutoLayout(True)