From 8fa876ca9ec87e90605808bfcab4d4226965dbad Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Tue, 9 Dec 2003 01:23:28 +0000 Subject: [PATCH] Demo updates for new wx namespace, from Jeff Grimmett git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24723 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- wxPython/demo/ActiveXWrapper_Acrobat.py | 86 +++-- wxPython/demo/ActiveXWrapper_IE.py | 140 ++++--- wxPython/demo/AnalogClockWindow.py | 59 +-- wxPython/demo/ColorPanel.py | 13 +- wxPython/demo/ColourDB.py | 124 ++++-- wxPython/demo/ColourSelect.py | 67 ++-- wxPython/demo/ContextHelp.py | 85 ++-- wxPython/demo/CustomDragAndDrop.py | 173 +++++---- wxPython/demo/DialogUnits.py | 59 +-- wxPython/demo/DragAndDrop.py | 223 ++++++----- wxPython/demo/DrawXXXList.py | 137 ++++--- wxPython/demo/ErrorDialogs.py | 144 ++++--- wxPython/demo/EventManager.py | 94 +++-- wxPython/demo/FancyText.py | 69 +++- wxPython/demo/FileBrowseButton.py | 54 ++- wxPython/demo/FloatCanvas.py | 96 +++-- wxPython/demo/FontEnumerator.py | 49 +-- wxPython/demo/GenericButtons.py | 102 ++--- wxPython/demo/GridCustEditor.py | 51 ++- wxPython/demo/GridCustTable.py | 72 ++-- wxPython/demo/GridDragAndDrop.py | 34 +- wxPython/demo/GridDragable.py | 78 ++-- wxPython/demo/GridEnterHandler.py | 25 +- wxPython/demo/GridHugeTable.py | 32 +- wxPython/demo/GridSimple.py | 106 ++--- wxPython/demo/GridStdEdRend.py | 70 ++-- wxPython/demo/ImageBrowser.py | 47 ++- wxPython/demo/LayoutAnchors.py | 208 +++++++--- wxPython/demo/Layoutf.py | 80 ++-- wxPython/demo/MDIDemo.py | 54 ++- wxPython/demo/MDISashDemo.py | 133 ++++--- wxPython/demo/MaskedEditControls.py | 472 ++++++++++++----------- wxPython/demo/OOR.py | 54 ++- wxPython/demo/PrintFramework.py | 127 ++++-- wxPython/demo/PyCrust.py | 7 +- wxPython/demo/PyShell.py | 8 +- wxPython/demo/PythonEvents.py | 72 ++-- wxPython/demo/RowColSizer.py | 94 +++-- wxPython/demo/ShapedWindow.py | 62 +-- wxPython/demo/Sizers.py | 447 ++++++++++----------- wxPython/demo/SplitTree.py | 102 +++-- wxPython/demo/TablePrint.py | 96 ++--- wxPython/demo/Threads.py | 102 +++-- wxPython/demo/Throbber.py | 141 ++++--- wxPython/demo/URLDragAndDrop.py | 76 ++-- wxPython/demo/Unicode.py | 39 +- wxPython/demo/XMLtreeview.py | 36 +- wxPython/demo/demoMainLoop.py | 40 +- wxPython/demo/encode_bitmaps.py | 7 +- wxPython/demo/infoframe.py | 117 ++++-- wxPython/demo/old_simple.py | 60 --- wxPython/demo/pyTree.py | 75 ++-- wxPython/demo/simple.py | 63 --- wxPython/demo/viewer.py | 17 +- wxPython/demo/viewer_basics.py | 40 +- wxPython/demo/widgetTest.py | 62 +-- wxPython/demo/wxArtProvider.py | 229 +++++------ wxPython/demo/wxButton.py | 55 +-- wxPython/demo/wxCalendar.py | 249 +++++++----- wxPython/demo/wxCalendarCtrl.py | 30 +- wxPython/demo/wxCheckBox.py | 38 +- wxPython/demo/wxCheckListBox.py | 62 +-- wxPython/demo/wxChoice.py | 44 ++- wxPython/demo/wxColourDialog.py | 50 ++- wxPython/demo/wxComboBox.py | 79 ++-- wxPython/demo/wxDialog.py | 113 +++--- wxPython/demo/wxDirDialog.py | 26 +- wxPython/demo/wxDragImage.py | 174 ++++++--- wxPython/demo/wxDynamicSashWindow.py | 54 +-- wxPython/demo/wxEditableListBox.py | 81 +++- wxPython/demo/wxEditor.py | 23 +- wxPython/demo/wxFileDialog.py | 54 ++- wxPython/demo/wxFileDialog_Save.py | 75 +++- wxPython/demo/wxFileHistory.py | 97 +++-- wxPython/demo/wxFindReplaceDialog.py | 90 +++-- wxPython/demo/wxFloatBar.py | 70 ++-- wxPython/demo/wxFontDialog.py | 97 +++-- wxPython/demo/wxFrame.py | 59 ++- wxPython/demo/wxGLCanvas.py | 255 ++++++------ wxPython/demo/wxGauge.py | 45 ++- wxPython/demo/wxGenericDirCtrl.py | 43 ++- wxPython/demo/wxGrid.py | 30 +- wxPython/demo/wxGridBagSizer.py | 1 - wxPython/demo/wxGrid_MegaExample.py | 146 ++++--- wxPython/demo/wxHtmlWindow.py | 112 +++--- wxPython/demo/wxIEHtmlWin.py | 130 ++++--- wxPython/demo/wxImage.py | 74 +++- wxPython/demo/wxImageFromStream.py | 32 +- wxPython/demo/wxIntCtrl.py | 101 ++--- wxPython/demo/wxKeyEvents.py | 315 +++++++-------- wxPython/demo/wxLEDNumberCtrl.py | 84 +++- wxPython/demo/wxLayoutConstraints.py | 160 ++++---- wxPython/demo/wxListBox.py | 73 ++-- wxPython/demo/wxListCtrl.py | 272 +++++++++---- wxPython/demo/wxListCtrl_virtual.py | 45 ++- wxPython/demo/wxListbook.py | 32 +- wxPython/demo/wxMDIWindows.py | 35 +- wxPython/demo/wxMVCTree.py | 46 ++- wxPython/demo/wxMask.py | 73 ++-- wxPython/demo/wxMaskedNumCtrl.py | 275 ++++++------- wxPython/demo/wxMenu.py | 168 +++++--- wxPython/demo/wxMessageDialog.py | 31 +- wxPython/demo/wxMiniFrame.py | 45 ++- wxPython/demo/wxMultiSash.py | 42 +- wxPython/demo/wxMultipleChoiceDialog.py | 65 +++- wxPython/demo/wxNotebook.py | 69 ++-- wxPython/demo/wxOGL.py | 151 +++++--- wxPython/demo/wxPageSetupDialog.py | 35 +- wxPython/demo/wxPlotCanvas.py | 29 +- wxPython/demo/wxPopupControl.py | 41 +- wxPython/demo/wxPopupWindow.py | 117 +++--- wxPython/demo/wxPrintDialog.py | 24 +- wxPython/demo/wxProcess.py | 66 ++-- wxPython/demo/wxProgressDialog.py | 40 +- wxPython/demo/wxPyColourChooser.py | 23 +- wxPython/demo/wxRadioBox.py | 62 +-- wxPython/demo/wxRadioButton.py | 81 ++-- wxPython/demo/wxRightTextCtrl.py | 65 ++-- wxPython/demo/wxSashWindow.py | 127 +++--- wxPython/demo/wxScrolledMessageDialog.py | 33 +- wxPython/demo/wxScrolledPanel.py | 71 ++-- wxPython/demo/wxScrolledWindow.py | 127 +++--- wxPython/demo/wxSingleChoiceDialog.py | 20 +- wxPython/demo/wxSlider.py | 27 +- wxPython/demo/wxSpinButton.py | 44 ++- wxPython/demo/wxSpinCtrl.py | 29 +- wxPython/demo/wxSplitterWindow.py | 32 +- wxPython/demo/wxStaticBitmap.py | 34 +- wxPython/demo/wxStaticText.py | 44 ++- wxPython/demo/wxStatusBar.py | 61 +-- wxPython/demo/wxStyledTextCtrl_1.py | 116 +++--- wxPython/demo/wxStyledTextCtrl_2.py | 129 ++++--- wxPython/demo/wxTextCtrl.py | 116 +++--- wxPython/demo/wxTextEntryDialog.py | 27 +- wxPython/demo/wxTimeCtrl.py | 230 ++++++----- wxPython/demo/wxTimer.py | 54 +-- wxPython/demo/wxToggleButton.py | 36 +- wxPython/demo/wxToolBar.py | 89 +++-- wxPython/demo/wxTreeCtrl.py | 85 ++-- wxPython/demo/wxTreeListCtrl.py | 56 +-- wxPython/demo/wxVListBox.py | 36 +- wxPython/demo/wxValidator.py | 116 +++--- wxPython/demo/wxWave.py | 36 +- wxPython/demo/wxWizard.py | 104 ++--- wxPython/demo/wxXmlResource.py | 44 ++- wxPython/demo/wxXmlResourceHandler.py | 72 ++-- wxPython/demo/wxXmlResourceSubclass.py | 40 +- 147 files changed, 7378 insertions(+), 5219 deletions(-) delete mode 100644 wxPython/demo/old_simple.py delete mode 100644 wxPython/demo/simple.py diff --git a/wxPython/demo/ActiveXWrapper_Acrobat.py b/wxPython/demo/ActiveXWrapper_Acrobat.py index 694f875463..adc9128502 100644 --- a/wxPython/demo/ActiveXWrapper_Acrobat.py +++ b/wxPython/demo/ActiveXWrapper_Acrobat.py @@ -13,58 +13,65 @@ have Acrobat Reader 4.0 installed it won't work. """ -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): @@ -75,11 +82,12 @@ class TestPanel(wxPanel): 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() @@ -96,12 +104,12 @@ class TestPanel(wxPanel): #---------------------------------------------------------------------- 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() @@ -112,17 +120,19 @@ overview = __doc__ 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() - diff --git a/wxPython/demo/ActiveXWrapper_IE.py b/wxPython/demo/ActiveXWrapper_IE.py index fd164e5761..04674a5684 100644 --- a/wxPython/demo/ActiveXWrapper_IE.py +++ b/wxPython/demo/ActiveXWrapper_IE.py @@ -18,93 +18,104 @@ shown.) """ -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): @@ -130,7 +141,7 @@ class TestPanel(wxWindow): 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) @@ -139,17 +150,20 @@ class TestPanel(wxWindow): 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): @@ -171,7 +185,6 @@ class TestPanel(wxWindow): 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 @@ -199,12 +212,12 @@ class TestPanel(wxWindow): # 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() @@ -215,23 +228,24 @@ overview = __doc__ 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() - - diff --git a/wxPython/demo/AnalogClockWindow.py b/wxPython/demo/AnalogClockWindow.py index 7d85145a33..552693eef4 100644 --- a/wxPython/demo/AnalogClockWindow.py +++ b/wxPython/demo/AnalogClockWindow.py @@ -1,52 +1,59 @@ +# 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) @@ -70,8 +77,6 @@ members of the wxPython-users group. """ - - if __name__ == '__main__': import sys,os import run diff --git a/wxPython/demo/ColorPanel.py b/wxPython/demo/ColorPanel.py index f7dc76ba0b..72f725842b 100644 --- a/wxPython/demo/ColorPanel.py +++ b/wxPython/demo/ColorPanel.py @@ -1,12 +1,19 @@ +# 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) #--------------------------------------------------------------------------- + diff --git a/wxPython/demo/ColourDB.py b/wxPython/demo/ColourDB.py index ad7c92fc74..39e35fb296 100644 --- a/wxPython/demo/ColourDB.py +++ b/wxPython/demo/ColourDB.py @@ -1,39 +1,73 @@ - -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() @@ -44,25 +78,29 @@ class TestWindow(wxScrolledWindow): 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()) @@ -70,13 +108,15 @@ class TestWindow(wxScrolledWindow): 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 @@ -89,9 +129,11 @@ class TestWindow(wxScrolledWindow): 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)) @@ -100,12 +142,13 @@ class TestWindow(wxScrolledWindow): # 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()) @@ -117,15 +160,46 @@ class TestPanel(wxPanel): 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 = """ + + +ColourDB + +

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: TheColourDatabase. + +

The colourdb 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). + +

A secondary benefit of this demo is the use of the ScrolledWindow 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. + +

+Important note + +

+With implementation of V2.5 and later, it is required to have a wx.App already +initialized before wx.updateColourDB() can be called. +Trying to do otherwise will cause an exception to be raised. + + """ diff --git a/wxPython/demo/ColourSelect.py b/wxPython/demo/ColourSelect.py index b030d1fa9e..8f220642fa 100644 --- a/wxPython/demo/ColourSelect.py +++ b/wxPython/demo/ColourSelect.py @@ -15,45 +15,61 @@ # - 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..."), ] @@ -61,15 +77,17 @@ class TestColourSelect(wxPanel): # 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): @@ -104,9 +122,6 @@ overview = """\ """ - - - if __name__ == '__main__': import sys,os import run diff --git a/wxPython/demo/ContextHelp.py b/wxPython/demo/ContextHelp.py index 505d2130f8..561a597a5b 100644 --- a/wxPython/demo/ContextHelp.py +++ b/wxPython/demo/ContextHelp.py @@ -1,70 +1,97 @@ +# 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") #---------------------------------------------------------------------- @@ -77,20 +104,14 @@ def runTest(frame, nb, log): #---------------------------------------------------------------------- - - 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 diff --git a/wxPython/demo/CustomDragAndDrop.py b/wxPython/demo/CustomDragAndDrop.py index eb8ffa3472..2ff049640e 100644 --- a/wxPython/demo/CustomDragAndDrop.py +++ b/wxPython/demo/CustomDragAndDrop.py @@ -1,42 +1,49 @@ - -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) @@ -51,7 +58,7 @@ class DoodlePad(wxWindow): self.x, self.y = event.GetPositionTuple() self.CaptureMouse() else: - wxBell() + wx.Bell() self.log.write("unknown mode!\n") @@ -66,10 +73,10 @@ class DoodlePad(wxWindow): 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() @@ -82,34 +89,35 @@ class DoodlePad(wxWindow): # 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() @@ -117,15 +125,15 @@ class DoodlePad(wxWindow): #---------------------------------------------------------------------- -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) @@ -163,25 +171,26 @@ class DoodleDropTarget(wxPyDropTarget): 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): @@ -189,12 +198,13 @@ class DoodleViewer(wxWindow): 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) @@ -202,14 +212,14 @@ class DoodleViewer(wxWindow): #---------------------------------------------------------------------- -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" @@ -217,12 +227,12 @@ class CustomDnDPanel(wxPanel): "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.") @@ -231,9 +241,9 @@ class CustomDnDPanel(wxPanel): 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) @@ -244,18 +254,18 @@ class CustomDnDPanel(wxPanel): 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): @@ -266,24 +276,24 @@ class CustomDnDPanel(wxPanel): #---------------------------------------------------------------------- #---------------------------------------------------------------------- -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) @@ -298,29 +308,30 @@ def runTest(frame, nb, log): 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() @@ -338,10 +349,8 @@ A second data object is also created containing a bitmap of the image 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. """ - - diff --git a/wxPython/demo/DialogUnits.py b/wxPython/demo/DialogUnits.py index 78974eb676..8e1e36685c 100644 --- a/wxPython/demo/DialogUnits.py +++ b/wxPython/demo/DialogUnits.py @@ -10,46 +10,50 @@ # 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 @@ -57,7 +61,6 @@ class MyFrame(wxFrame): # 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): @@ -81,7 +84,7 @@ class MyFrame(wxFrame): 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): diff --git a/wxPython/demo/DragAndDrop.py b/wxPython/demo/DragAndDrop.py index c69091d378..d04bdc7048 100644 --- a/wxPython/demo/DragAndDrop.py +++ b/wxPython/demo/DragAndDrop.py @@ -1,85 +1,116 @@ +# 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") @@ -95,11 +126,9 @@ class OtherDropTarget(wxPyDropTarget): 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 @@ -107,13 +136,14 @@ class MyFileDropTarget(wxFileDropTarget): 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 @@ -121,32 +151,43 @@ class MyTextDropTarget(wxTextDropTarget): 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) @@ -162,28 +203,29 @@ class FileDropPanel(wxPanel): #---------------------------------------------------------------------- #---------------------------------------------------------------------- -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) @@ -196,17 +238,9 @@ def runTest(frame, nb, log): #---------------------------------------------------------------------- - - - - - - - - - - -overview = """\ +overview = """\ + + 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 @@ -230,12 +264,11 @@ and target, the data provider and the data receiver. These which may 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. - + + """ - - if __name__ == '__main__': import sys,os import run diff --git a/wxPython/demo/DrawXXXList.py b/wxPython/demo/DrawXXXList.py index 0091b68c2a..1ac1338d11 100644 --- a/wxPython/demo/DrawXXXList.py +++ b/wxPython/demo/DrawXXXList.py @@ -1,6 +1,18 @@ - -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 #---------------------------------------------------------------------- @@ -28,84 +40,106 @@ colours = [ 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)) @@ -141,11 +175,13 @@ def Init(w, h, n): # 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) @@ -163,10 +199,10 @@ def Init(w, h, n): 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() @@ -179,10 +215,12 @@ def TestArrayPoints(dc,log): 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)) @@ -195,9 +233,9 @@ def TestLines(dc,log): 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() @@ -208,8 +246,8 @@ def TestRectangles(dc,log): 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) @@ -228,8 +266,8 @@ def TestEllipses(dc,log): 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) @@ -249,7 +287,7 @@ def TestRectanglesArray(dc,log): 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) @@ -274,10 +312,12 @@ def TestRectanglesLoop(dc,log): 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)) @@ -286,7 +326,7 @@ def TestPolygons(dc,log): 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) @@ -303,7 +343,7 @@ def TestText(dc,log): 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) @@ -314,14 +354,17 @@ def TestText(dc,log): -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') @@ -340,19 +383,21 @@ class TestNB(wxNotebook): 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) @@ -373,7 +418,7 @@ def runTest(frame, nb, 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:

diff --git a/wxPython/demo/ErrorDialogs.py b/wxPython/demo/ErrorDialogs.py
index db24853b82..f264f8f92f 100644
--- a/wxPython/demo/ErrorDialogs.py
+++ b/wxPython/demo/ErrorDialogs.py
@@ -2,10 +2,25 @@
 # 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
@@ -15,44 +30,54 @@ ID_BUTTON_wxPyFatalErrorDialogWithTraceback = 10005
 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 )
@@ -70,42 +95,35 @@ def ErrorDialogsDemoPanelFunc( parent, call_fit = True, set_sizer = 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,
@@ -116,11 +134,12 @@ class MyPanel(wxPanel):
 
     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.

" + edlg.wxPyFatalError(self,"Test Non-fatal error.

" "Nearly arbitrary HTML (i.e., that which is" " understood by wxHtmlWindow)." "

" @@ -128,7 +147,7 @@ class MyPanel(wxPanel): else: print "%s.DoDialog(): testing explicit wxPyNonFatalError..."\ % self - wxPyNonFatalError(self,"Test Non-fatal error.

" + edlg.wxPyNonFatalError(self,"Test Non-fatal error.

" "Nearly arbitrary HTML (i.e., that which is" " understood by wxHtmlWindow)." "

Thisis
" @@ -144,19 +163,19 @@ class MyPanel(wxPanel): -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) @@ -167,13 +186,12 @@ def runTest(pframe, nb, log): 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__ diff --git a/wxPython/demo/EventManager.py b/wxPython/demo/EventManager.py index 0e99c94b47..b492ecc599 100644 --- a/wxPython/demo/EventManager.py +++ b/wxPython/demo/EventManager.py @@ -8,48 +8,58 @@ # 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) @@ -68,36 +78,36 @@ class TestPanel(wxPanel): 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() @@ -105,10 +115,10 @@ class Tile(wxPanel): 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): @@ -128,10 +138,10 @@ class Tile(wxPanel): 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() @@ -141,7 +151,7 @@ class InnerTile(wxPanel): 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) @@ -151,16 +161,16 @@ class InnerTile(wxPanel): 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() @@ -188,7 +198,7 @@ class InnerTile(wxPanel): 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))) diff --git a/wxPython/demo/FancyText.py b/wxPython/demo/FancyText.py index 1d3b46c581..8b08afe393 100644 --- a/wxPython/demo/FancyText.py +++ b/wxPython/demo/FancyText.py @@ -1,6 +1,21 @@ - -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 #---------------------------------------------------------------------- @@ -11,14 +26,13 @@ test_str = ('' test_str2 = 'big green text' -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) @@ -36,8 +50,43 @@ def runTest(frame, nb, log): -overview = fancytext.__doc__.replace("<", "<") - +overview = \ +""" + + +

FancyText -- methods for rendering XML specified text

+ +

This module exports four main methods:: +

+    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)
+
+ +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. + +

In addition, the module exports one class:: +

+    class StaticFancyText(self, window, id, text, background, ...)
+
+This class works similar to StaticText except it interprets its text +as FancyText. + +

The text can supportsuperscripts and subscripts, text +in different sizes, colors, +styles, weights and +families. It also supports a limited set of symbols, +currently , , as well as greek letters in both +upper case (...) and lower case (...). + + +The End + + +""" diff --git a/wxPython/demo/FileBrowseButton.py b/wxPython/demo/FileBrowseButton.py index 798f201259..41897eeb28 100644 --- a/wxPython/demo/FileBrowseButton.py +++ b/wxPython/demo/FileBrowseButton.py @@ -1,27 +1,44 @@ +# 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 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']) @@ -30,7 +47,6 @@ class TestPanel(wxPanel): self.log.write('FileBrowseButton: %s\n' % evt.GetString()) - def fbbhCallback(self, evt): if hasattr(self, 'fbbh'): value = evt.GetString() @@ -39,11 +55,11 @@ class TestPanel(wxPanel): history.append(value) self.fbbh.SetHistory(history) + def dbbCallback(self, evt): self.log.write('DirBrowseButton: %s\n' % evt.GetString()) - #---------------------------------------------------------------------- def runTest(frame, nb, log): @@ -51,7 +67,6 @@ def runTest(frame, nb, log): return win - #---------------------------------------------------------------------- overview = """ @@ -71,11 +86,10 @@ overview = """ < -""" % ( FileBrowseButton.__doc__, - FileBrowseButtonWithHistory.__doc__ , - str(DirBrowseButton.__doc__) ) - - +""" % ( filebrowse.FileBrowseButton.__doc__, + filebrowse.FileBrowseButtonWithHistory.__doc__ , + filebrowse.DirBrowseButton.__doc__ + ) if __name__ == '__main__': diff --git a/wxPython/demo/FloatCanvas.py b/wxPython/demo/FloatCanvas.py index 02aa116a2f..fc5bdeb2d3 100644 --- a/wxPython/demo/FloatCanvas.py +++ b/wxPython/demo/FloatCanvas.py @@ -1,8 +1,11 @@ +# 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 @@ -17,8 +20,10 @@ You can get it at: 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() @@ -28,21 +33,22 @@ else: 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): """ @@ -50,39 +56,38 @@ else: """ - 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) @@ -90,10 +95,10 @@ else: 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), @@ -115,20 +120,24 @@ else: 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") @@ -147,15 +156,17 @@ else: 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): @@ -240,7 +251,7 @@ else: self.Canvas.ZoomToBB() def DrawMap(self,event = None): - wxGetApp().Yield() + wx.GetApp().Yield() import os, time ## Test of Actual Map Data self.Clear() @@ -285,7 +296,7 @@ else: ## 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) @@ -310,7 +321,7 @@ else: 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: @@ -450,6 +461,11 @@ if __name__ == "__main__": print errorText else: app = DemoApp(0) + + import wx.lib.colourdb + wx.lib.colourdb.updateColourDB() + colors = wx.lib.colourdb.getColourList() + app.MainLoop() diff --git a/wxPython/demo/FontEnumerator.py b/wxPython/demo/FontEnumerator.py index 3ac7e51d4a..71ce22e784 100644 --- a/wxPython/demo/FontEnumerator.py +++ b/wxPython/demo/FontEnumerator.py @@ -1,39 +1,45 @@ +# 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): @@ -44,7 +50,7 @@ class TestPanel(wxPanel): #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" @@ -55,9 +61,9 @@ class TestPanel(wxPanel): ## st = font.GetNativeFontInfo().ToString() -## ni2 = wxNativeFontInfo() +## ni2 = wx.NativeFontInfo() ## ni2.FromString(st) -## font2 = wxFontFromNativeInfo(ni2) +## font2 = wx.FontFromNativeInfo(ni2) #---------------------------------------------------------------------- @@ -69,11 +75,6 @@ def runTest(frame, nb, log): - - - - - overview = """ wxFontEnumerator enumerates either all available fonts on the system or only the ones with given attributes - either only fixed-width (suited for use in diff --git a/wxPython/demo/GenericButtons.py b/wxPython/demo/GenericButtons.py index 3165c0f977..6ab17eb837 100644 --- a/wxPython/demo/GenericButtons.py +++ b/wxPython/demo/GenericButtons.py @@ -1,104 +1,123 @@ +# 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) @@ -131,10 +150,7 @@ def runTest(frame, nb, log): #---------------------------------------------------------------------- -import wxPython.lib.buttons -overview = wxPython.lib.buttons.__doc__ - - +overview = buttons.__doc__ if __name__ == '__main__': import sys,os diff --git a/wxPython/demo/GridCustEditor.py b/wxPython/demo/GridCustEditor.py index 50101e4b60..71b62a7a46 100644 --- a/wxPython/demo/GridCustEditor.py +++ b/wxPython/demo/GridCustEditor.py @@ -1,10 +1,15 @@ - -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 @@ -23,18 +28,19 @@ class MyCellEditor(wxPyGridCellEditor): 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) @@ -47,7 +53,7 @@ class MyCellEditor(wxPyGridCellEditor): """ 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): @@ -95,6 +101,7 @@ class MyCellEditor(wxPyGridCellEditor): changed = False val = self._tc.GetValue() + if val != self.startValue: changed = True grid.GetTable().SetValue(row, col, val) # update the table @@ -126,7 +133,7 @@ class MyCellEditor(wxPyGridCellEditor): ##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): @@ -137,9 +144,12 @@ class MyCellEditor(wxPyGridCellEditor): 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) @@ -180,9 +190,9 @@ class MyCellEditor(wxPyGridCellEditor): #--------------------------------------------------------------------------- -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) @@ -195,16 +205,17 @@ class GridEditorTest(wxGrid): #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") @@ -216,9 +227,9 @@ class GridEditorTest(wxGrid): #--------------------------------------------------------------------------- -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) @@ -226,7 +237,7 @@ class TestFrame(wxFrame): if __name__ == '__main__': import sys - app = wxPySimpleApp() + app = wx.PySimpleApp() frame = TestFrame(None, sys.stdout) frame.Show(True) app.MainLoop() diff --git a/wxPython/demo/GridCustTable.py b/wxPython/demo/GridCustTable.py index cc151f9ac7..519a2b3979 100644 --- a/wxPython/demo/GridCustTable.py +++ b/wxPython/demo/GridCustTable.py @@ -1,28 +1,32 @@ -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 = [ @@ -67,9 +71,10 @@ class CustomDataTable(wxPyGridTableBase): 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) @@ -108,9 +113,9 @@ class CustomDataTable(wxPyGridTableBase): -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) @@ -123,8 +128,7 @@ class CustTableGrid(wxGrid): 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 @@ -136,17 +140,21 @@ class CustTableGrid(wxGrid): #--------------------------------------------------------------------------- -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) @@ -161,7 +169,7 @@ class TestFrame(wxFrame): if __name__ == '__main__': import sys - app = wxPySimpleApp() + app = wx.PySimpleApp() frame = TestFrame(None, sys.stdout) frame.Show(True) app.MainLoop() diff --git a/wxPython/demo/GridDragAndDrop.py b/wxPython/demo/GridDragAndDrop.py index aae9d5f2dc..ae11c7c2fd 100644 --- a/wxPython/demo/GridDragAndDrop.py +++ b/wxPython/demo/GridDragAndDrop.py @@ -1,19 +1,24 @@ +# 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): @@ -37,9 +42,9 @@ class GridFileDropTarget(wxFileDropTarget): -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", @@ -54,12 +59,12 @@ class FooTable(wxPyGridTableBase): 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) @@ -76,13 +81,12 @@ class SimpleGrid(wxGrid): 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) @@ -91,7 +95,7 @@ class TestFrame(wxFrame): if __name__ == '__main__': import sys - app = wxPySimpleApp() + app = wx.PySimpleApp() frame = TestFrame(None, sys.stdout) frame.Show(True) app.MainLoop() diff --git a/wxPython/demo/GridDragable.py b/wxPython/demo/GridDragable.py index ea989c6116..547b19ee94 100644 --- a/wxPython/demo/GridDragable.py +++ b/wxPython/demo/GridDragable.py @@ -1,16 +1,23 @@ -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'] @@ -93,10 +100,12 @@ class CustomDataTable(wxPyGridTableBase): # 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: @@ -104,23 +113,30 @@ class CustomDataTable(wxPyGridTableBase): # 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) @@ -130,11 +146,17 @@ class CustomDataTable(wxPyGridTableBase): # 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() @@ -142,9 +164,9 @@ class CustomDataTable(wxPyGridTableBase): #--------------------------------------------------------------------------- -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) @@ -154,12 +176,16 @@ class DragableGrid(wxGrid): 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): @@ -175,9 +201,9 @@ class DragableGrid(wxGrid): #--------------------------------------------------------------------------- -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) @@ -185,7 +211,7 @@ class TestFrame(wxFrame): if __name__ == '__main__': import sys - app = wxPySimpleApp() + app = wx.PySimpleApp() frame = TestFrame(None, sys.stdout) frame.Show(True) app.MainLoop() diff --git a/wxPython/demo/GridEnterHandler.py b/wxPython/demo/GridEnterHandler.py index d6989fbcfe..0b6971b033 100644 --- a/wxPython/demo/GridEnterHandler.py +++ b/wxPython/demo/GridEnterHandler.py @@ -1,11 +1,16 @@ -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) @@ -15,11 +20,11 @@ class NewEnterHandlingGrid(wxGrid): 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 @@ -29,8 +34,10 @@ class NewEnterHandlingGrid(wxGrid): 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) @@ -42,9 +49,9 @@ class NewEnterHandlingGrid(wxGrid): #--------------------------------------------------------------------------- -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) @@ -53,7 +60,7 @@ class TestFrame(wxFrame): if __name__ == '__main__': import sys - app = wxPySimpleApp() + app = wx.PySimpleApp() frame = TestFrame(None, sys.stdout) frame.Show(True) app.MainLoop() diff --git a/wxPython/demo/GridHugeTable.py b/wxPython/demo/GridHugeTable.py index 69c840f5fd..5e8bf5eb0d 100644 --- a/wxPython/demo/GridHugeTable.py +++ b/wxPython/demo/GridHugeTable.py @@ -1,9 +1,14 @@ -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 @@ -13,7 +18,7 @@ class HugeTable(wxPyGridTableBase): """ def __init__(self, log): - wxPyGridTableBase.__init__(self) + gridlib.PyGridTableBase.__init__(self) self.log = log self.odd=wxGridCellAttr() @@ -46,9 +51,9 @@ class HugeTable(wxPyGridTableBase): -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) @@ -57,21 +62,18 @@ class HugeTableGrid(wxGrid): # 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) @@ -80,7 +82,7 @@ class TestFrame(wxFrame): if __name__ == '__main__': import sys - app = wxPySimpleApp() + app = wx.PySimpleApp() frame = TestFrame(None, sys.stdout) frame.Show(True) app.MainLoop() diff --git a/wxPython/demo/GridSimple.py b/wxPython/demo/GridSimple.py index 9075341a70..fca404d151 100644 --- a/wxPython/demo/GridSimple.py +++ b/wxPython/demo/GridSimple.py @@ -1,17 +1,29 @@ -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) @@ -23,16 +35,16 @@ class SimpleGrid(wxGrid): ##, wxGridAutoEditMixin): 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") @@ -41,10 +53,10 @@ class SimpleGrid(wxGrid): ##, wxGridAutoEditMixin): # 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) @@ -53,7 +65,7 @@ class SimpleGrid(wxGrid): ##, wxGridAutoEditMixin): 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() @@ -62,38 +74,37 @@ class SimpleGrid(wxGrid): ##, wxGridAutoEditMixin): # 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): @@ -136,7 +147,6 @@ class SimpleGrid(wxGrid): ##, wxGridAutoEditMixin): (evt.GetRow(), evt.GetCol(), evt.GetPosition())) evt.Skip() - def OnRowSize(self, evt): self.log.write("OnRowSize: row %d, %s\n" % (evt.GetRowOrCol(), evt.GetPosition())) @@ -163,6 +173,7 @@ class SimpleGrid(wxGrid): ##, wxGridAutoEditMixin): # 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() @@ -171,6 +182,7 @@ class SimpleGrid(wxGrid): ##, wxGridAutoEditMixin): if self.moveTo != None: self.SetGridCursor(self.moveTo[0], self.moveTo[1]) self.moveTo = None + evt.Skip() @@ -181,19 +193,23 @@ class SimpleGrid(wxGrid): ##, wxGridAutoEditMixin): # 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 @@ -204,8 +220,8 @@ class SimpleGrid(wxGrid): ##, wxGridAutoEditMixin): 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 @@ -222,9 +238,9 @@ class SimpleGrid(wxGrid): ##, wxGridAutoEditMixin): #--------------------------------------------------------------------------- -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) @@ -233,7 +249,7 @@ class TestFrame(wxFrame): if __name__ == '__main__': import sys - app = wxPySimpleApp() + app = wx.PySimpleApp() frame = TestFrame(None, sys.stdout) frame.Show(True) app.MainLoop() diff --git a/wxPython/demo/GridStdEdRend.py b/wxPython/demo/GridStdEdRend.py index e5e144b84a..ea84545ce8 100644 --- a/wxPython/demo/GridStdEdRend.py +++ b/wxPython/demo/GridStdEdRend.py @@ -1,13 +1,19 @@ -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) @@ -15,13 +21,14 @@ class MyCustomRenderer(wxPyGridCellRenderer): 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)) @@ -35,7 +42,7 @@ class MyCustomRenderer(wxPyGridCellRenderer): 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): @@ -45,34 +52,33 @@ class MyCustomRenderer(wxPyGridCellRenderer): #--------------------------------------------------------------------------- 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) @@ -106,6 +112,7 @@ Renderers used together. ''') row = 2 + for label, value, renderClass, args in rendererDemoData: renderer = renderClass(*args) self.SetCellValue(row, renCol, label) @@ -115,6 +122,7 @@ Renderers used together. row = 2 + for label, value, editorClass, args in editorDemoData: editor = editorClass(*args) self.SetCellValue(row, edCol, label) @@ -124,6 +132,7 @@ Renderers used together. row = 18 + for label, value, renClass, edClass in comboDemoData: self.SetCellValue(row, renCol, label) self.SetCellValue(row, renCol+1, value) @@ -133,14 +142,13 @@ Renderers used together. 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) @@ -149,7 +157,7 @@ Renderers used together. 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 @@ -161,9 +169,9 @@ Renderers used together. #--------------------------------------------------------------------------- -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) @@ -172,7 +180,7 @@ class TestFrame(wxFrame): if __name__ == '__main__': import sys - app = wxPySimpleApp() + app = wx.PySimpleApp() frame = TestFrame(None, sys.stdout) frame.Show(True) app.MainLoop() diff --git a/wxPython/demo/ImageBrowser.py b/wxPython/demo/ImageBrowser.py index 4a38b95d7c..dd1c817aff 100644 --- a/wxPython/demo/ImageBrowser.py +++ b/wxPython/demo/ImageBrowser.py @@ -8,40 +8,49 @@ # 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 diff --git a/wxPython/demo/LayoutAnchors.py b/wxPython/demo/LayoutAnchors.py index f4aa323ed6..acc7617d6c 100644 --- a/wxPython/demo/LayoutAnchors.py +++ b/wxPython/demo/LayoutAnchors.py @@ -1,67 +1,179 @@ +# 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() @@ -79,8 +191,6 @@ def runTest(frame, nb, log): #---------------------------------------------------------------------- - - overview = """

LayoutAnchors

A class that implements Delphi's Anchors with wxLayoutConstraints. @@ -132,10 +242,6 @@ overview = """ - - - - if __name__ == '__main__': import sys,os import run diff --git a/wxPython/demo/Layoutf.py b/wxPython/demo/Layoutf.py index 8a80e8a34f..bc25c3aeef 100644 --- a/wxPython/demo/Layoutf.py +++ b/wxPython/demo/Layoutf.py @@ -1,45 +1,62 @@ +# 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() @@ -51,18 +68,7 @@ def runTest(frame, nb, log): #--------------------------------------------------------------------------- - - - - - - - - -overview = Layoutf.__doc__ - - - +overview = layoutf.Layoutf.__doc__ if __name__ == '__main__': import sys,os diff --git a/wxPython/demo/MDIDemo.py b/wxPython/demo/MDIDemo.py index 5005daf946..ad86693e55 100644 --- a/wxPython/demo/MDIDemo.py +++ b/wxPython/demo/MDIDemo.py @@ -1,35 +1,49 @@ #!/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): @@ -38,42 +52,46 @@ class MyParentFrame(wxMDIParentFrame): 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() diff --git a/wxPython/demo/MDISashDemo.py b/wxPython/demo/MDISashDemo.py index a5fe68b915..00cdc3d684 100644 --- a/wxPython/demo/MDISashDemo.py +++ b/wxPython/demo/MDISashDemo.py @@ -1,115 +1,131 @@ #!/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): @@ -118,24 +134,23 @@ class MyParentFrame(wxMDIParentFrame): 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() diff --git a/wxPython/demo/MaskedEditControls.py b/wxPython/demo/MaskedEditControls.py index e661007986..edc3052e1d 100644 --- a/wxPython/demo/MaskedEditControls.py +++ b/wxPython/demo/MaskedEditControls.py @@ -1,10 +1,21 @@ -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: @@ -12,17 +23,17 @@ 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) @@ -33,13 +44,13 @@ class demoMixin: 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], @@ -56,25 +67,28 @@ class demoMixin: 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. @@ -83,25 +97,25 @@ Note that the State and Last Name fields are list-limited (valid last names are: 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 @@ -119,8 +133,8 @@ Smith, Jones, Williams). Signs on numbers can be toggled with the minus key. ] 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) @@ -139,13 +153,13 @@ Smith, Jones, Williams). Signs on numbers can be toggled with the minus key. 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). @@ -154,72 +168,72 @@ Many of these already do complicated validation; To see some examples, try """) 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 ) @@ -230,13 +244,13 @@ has a legal range specified. 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 @@ -246,111 +260,111 @@ Page Up and Shift-Up arrow will similarly cycle backwards through the list. """) 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_') @@ -358,8 +372,8 @@ with auto-select:""") 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: @@ -367,13 +381,13 @@ with auto-select:""") 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 = "#/##", @@ -382,23 +396,23 @@ be selected with PageUp/Down:""") 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, @@ -409,24 +423,24 @@ choice sets:""") 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 @@ -435,104 +449,103 @@ A control with restricted legal values: - 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()) @@ -595,9 +608,9 @@ with right-insert for ordinal:""") 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) @@ -623,19 +636,16 @@ def runTest(frame, nb, 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 = """

-""" + maskededit_doc + """
+""" + med.__doc__ + """
 
""" diff --git a/wxPython/demo/OOR.py b/wxPython/demo/OOR.py index d58bc42bbd..904e191556 100644 --- a/wxPython/demo/OOR.py +++ b/wxPython/demo/OOR.py @@ -1,50 +1,56 @@ +# 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! \n") else: self.log.write("Got %s, expected wxButton or wxButtonPtr\n" % className) @@ -53,27 +59,33 @@ class TestPanel(wxPanel): 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! \n") else: self.log.write("The objects are NOT the same! \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! \n") else: self.log.write("The objects are NOT the same! \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! \n") else: @@ -132,7 +144,7 @@ and be able to then turn wxPyTypeCast in to a no-op.

The first button below shows the first of these phases (working) -and the second will show #2 (working as of 2.3.2) +and the second will show #2 (working as of Python 2.3.2) """ diff --git a/wxPython/demo/PrintFramework.py b/wxPython/demo/PrintFramework.py index 58e40f8dab..ce6c1ff603 100644 --- a/wxPython/demo/PrintFramework.py +++ b/wxPython/demo/PrintFramework.py @@ -1,48 +1,58 @@ +# 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() #------------------------------------------- @@ -88,41 +98,40 @@ class MyPrintout(wxPrintout): #---------------------------------------------------------------------- -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(); @@ -134,12 +143,13 @@ class TestPrintPanel(wxPanel): 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()) @@ -149,12 +159,13 @@ class TestPrintPanel(wxPanel): 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() @@ -174,10 +185,46 @@ def runTest(frame, nb, log): overview = """\ -""" - - + + +

PrintFramework

+ +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. + +

Classes demonstrated here:

+

    +
  • wx.Printout() - 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.

    + +

  • wx.PrintData() - 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.

    + +

  • wx.PrintDialog() - This class represents the print and print setup + common dialogs. You may obtain a wx.PrinterDC device context from a + successfully dismissed print dialog.

    + +

  • wx.PrintPreview() - 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.

    +

+ +

Other classes are also demonstrated, but this is the gist of the printer interface +framework in wxPython. + + + +""" if __name__ == '__main__': diff --git a/wxPython/demo/PyCrust.py b/wxPython/demo/PyCrust.py index 5bf452e2cc..b0c4226e6f 100644 --- a/wxPython/demo/PyCrust.py +++ b/wxPython/demo/PyCrust.py @@ -1,6 +1,9 @@ +# 11/13/2003 - Jeff Grimmett (grimmtooth@softhome.net) +# +# o Updated for wx namespace +# -from wx import py - +import wx.py as py #---------------------------------------------------------------------- diff --git a/wxPython/demo/PyShell.py b/wxPython/demo/PyShell.py index d93fc9b4ca..99d88ce078 100644 --- a/wxPython/demo/PyShell.py +++ b/wxPython/demo/PyShell.py @@ -1,7 +1,9 @@ +# 11/13/2003 - Jeff Grimmett (grimmtooth@softhome.net) +# +# o Updated for wx namespace +# - -from wx import py - +import wx.py as py #---------------------------------------------------------------------- diff --git a/wxPython/demo/PythonEvents.py b/wxPython/demo/PythonEvents.py index 911f04b4aa..55b583939a 100644 --- a/wxPython/demo/PythonEvents.py +++ b/wxPython/demo/PythonEvents.py @@ -1,24 +1,43 @@ +# 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 @@ -27,11 +46,10 @@ class MyEvent(wxPyCommandEvent): 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() @@ -44,17 +62,21 @@ class MyButton(wxButton): -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): @@ -74,15 +96,13 @@ def runTest(frame, nb, log): #---------------------------------------------------------------------- - - 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__': diff --git a/wxPython/demo/RowColSizer.py b/wxPython/demo/RowColSizer.py index 1a5ac5119e..ad76bd7c1f 100644 --- a/wxPython/demo/RowColSizer.py +++ b/wxPython/demo/RowColSizer.py @@ -1,15 +1,24 @@ - -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 "\ @@ -17,31 +26,51 @@ class TestPanel(wxPanel): "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) @@ -63,10 +92,7 @@ def runTest(frame, nb, log): #---------------------------------------------------------------------- -import wxPython.lib.rcsizer -overview = wxPython.lib.rcsizer.__doc__ - - +overview = rcs.__doc__ if __name__ == '__main__': import sys,os diff --git a/wxPython/demo/ShapedWindow.py b/wxPython/demo/ShapedWindow.py index e484f96aad..586f6b09ab 100644 --- a/wxPython/demo/ShapedWindow.py +++ b/wxPython/demo/ShapedWindow.py @@ -1,68 +1,72 @@ +# 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): @@ -71,11 +75,11 @@ class TestFrame(wxFrame): 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): @@ -85,8 +89,8 @@ class TestFrame(wxFrame): 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) diff --git a/wxPython/demo/Sizers.py b/wxPython/demo/Sizers.py index 609a13f043..252a635776 100644 --- a/wxPython/demo/Sizers.py +++ b/wxPython/demo/Sizers.py @@ -1,77 +1,90 @@ +# 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 @@ -105,30 +118,30 @@ def makeSimpleBox8(win): #---------------------------------------------------------------------- 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 @@ -136,28 +149,28 @@ def makeSimpleBorder3(win): #---------------------------------------------------------------------- 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) @@ -166,43 +179,43 @@ def makeBoxInBox(win): #---------------------------------------------------------------------- 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 @@ -210,18 +223,18 @@ def makeBorderInBox(win): #---------------------------------------------------------------------- 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 @@ -229,27 +242,27 @@ def makeGrid1(win): #---------------------------------------------------------------------- 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 @@ -257,18 +270,18 @@ def makeGrid2(win): #---------------------------------------------------------------------- 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) @@ -279,28 +292,28 @@ def makeGrid3(win): #---------------------------------------------------------------------- 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 @@ -308,28 +321,28 @@ def makeGrid4(win): #---------------------------------------------------------------------- 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 @@ -337,12 +350,12 @@ def makeShapes(win): #---------------------------------------------------------------------- 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 @@ -393,14 +406,14 @@ theTests = [ ), # ("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." ), @@ -471,19 +484,22 @@ theTests = [ ] #---------------------------------------------------------------------- -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) @@ -496,30 +512,29 @@ class TestFrame(wxFrame): -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]) @@ -532,7 +547,7 @@ class TestSelectionPanel(wxPanel): if func: win = TestFrame(self, title, func) - win.CentreOnParent(wxBOTH) + win.CentreOnParent(wx.BOTH) win.Show(True) win.MakeModal(True) @@ -549,24 +564,22 @@ overview = "" #---------------------------------------------------------------------- - - 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() @@ -575,14 +588,14 @@ if __name__ == '__main__': 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() diff --git a/wxPython/demo/SplitTree.py b/wxPython/demo/SplitTree.py index 698d2f639d..5b2a425053 100644 --- a/wxPython/demo/SplitTree.py +++ b/wxPython/demo/SplitTree.py @@ -1,26 +1,42 @@ -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) @@ -28,11 +44,11 @@ class TestTree(wxRemotelyScrolledTreeCtrl): -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 @@ -40,41 +56,54 @@ class TestValueWindow(wxTreeCompanionWindow): # 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) @@ -83,8 +112,8 @@ class TestPanel(wxPanel): 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) @@ -92,8 +121,8 @@ class TestPanel(wxPanel): #---------------------------------------------------------------------- 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) @@ -103,14 +132,11 @@ def runTest(frame, 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. """ diff --git a/wxPython/demo/TablePrint.py b/wxPython/demo/TablePrint.py index a8a45ca588..c0e60c7c8b 100644 --- a/wxPython/demo/TablePrint.py +++ b/wxPython/demo/TablePrint.py @@ -1,8 +1,19 @@ - -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 #--------------------------------------------------------------------------- @@ -15,21 +26,22 @@ buttonDefs = { } -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) @@ -60,7 +72,7 @@ class TablePanel(wxPanel): 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] @@ -68,14 +80,14 @@ class TablePanel(wxPanel): 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): @@ -87,26 +99,26 @@ class TablePanel(wxPanel): 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): @@ -121,7 +133,7 @@ class TablePanel(wxPanel): 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 = [] @@ -130,7 +142,7 @@ class TablePanel(wxPanel): 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 @@ -142,7 +154,7 @@ class TablePanel(wxPanel): 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"]] @@ -151,7 +163,7 @@ class TablePanel(wxPanel): def PrintWide(self): self.ReadData() - prt = PrintTable(self.frame) + prt = printout.PrintTable(self.frame) prt.data = self.data prt.left_margin = 0.5 @@ -173,12 +185,6 @@ def runTest(frame, nb, log): -import os -import wxPython.lib.printout - - - - overview = """\

Table Printing

@@ -203,7 +209,7 @@ the program knows it before trying to parse through the available pages. This w 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") diff --git a/wxPython/demo/Threads.py b/wxPython/demo/Threads.py index 7da3ac6b5c..6d9f5a1d5b 100644 --- a/wxPython/demo/Threads.py +++ b/wxPython/demo/Threads.py @@ -1,15 +1,26 @@ - -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() #---------------------------------------------------------------------- @@ -33,14 +44,14 @@ class CalcBarThread: 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 @@ -53,22 +64,22 @@ class CalcBarThread: #---------------------------------------------------------------------- -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): @@ -78,7 +89,7 @@ class GraphWindow(wxWindow): 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) @@ -94,8 +105,8 @@ class GraphWindow(wxWindow): 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)) @@ -112,23 +123,25 @@ class GraphWindow(wxWindow): 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): @@ -139,34 +152,35 @@ class GraphWindow(wxWindow): #---------------------------------------------------------------------- -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)) @@ -180,7 +194,7 @@ class TestFrame(wxFrame): for t in self.threads: t.Start() - EVT_CLOSE(self, self.OnCloseWindow) + self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) def OnUpdate(self, evt): @@ -189,16 +203,22 @@ class TestFrame(wxFrame): 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() @@ -228,7 +248,7 @@ application and makes it difficult to use additional threads at all. 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 diff --git a/wxPython/demo/Throbber.py b/wxPython/demo/Throbber.py index 2aadab2f90..1029434064 100644 --- a/wxPython/demo/Throbber.py +++ b/wxPython/demo/Throbber.py @@ -1,17 +1,24 @@ # # Throbber.py - Cliff Wells # +# 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 @@ -34,83 +41,96 @@ class TestPanel(wxPanel): 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) @@ -120,10 +140,11 @@ class TestPanel(wxPanel): 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") @@ -154,8 +175,8 @@ class TestPanel(wxPanel): #---------------------------------------------------------------------- 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: diff --git a/wxPython/demo/URLDragAndDrop.py b/wxPython/demo/URLDragAndDrop.py index bb93b95e12..95fbbaef32 100644 --- a/wxPython/demo/URLDragAndDrop.py +++ b/wxPython/demo/URLDragAndDrop.py @@ -1,22 +1,26 @@ +# 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") @@ -26,16 +30,16 @@ class MyURLDropTarget(wxPyDropTarget): #---------------------------------------------------------------------- -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)) @@ -44,55 +48,53 @@ class TestPanel(wxPanel): 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() @@ -100,10 +102,10 @@ class TestPanel(wxPanel): 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() diff --git a/wxPython/demo/Unicode.py b/wxPython/demo/Unicode.py index ec8a052bf9..8aed883bf1 100644 --- a/wxPython/demo/Unicode.py +++ b/wxPython/demo/Unicode.py @@ -1,6 +1,9 @@ +# 11/13/2003 - Jeff Grimmett (grimmtooth@softhome.net) +# +# o Updated for wx namespace +# - -from wxPython.wx import * +import wx #---------------------------------------------------------------------- @@ -41,22 +44,22 @@ rus_utf8 = ('\xd0\x9f\xd0\xb8\xd1\x82\xd0\xbe\xd0\xbd - \xd0\xbb\xd1\x83\xd1\x87 #---------------------------------------------------------------------- -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) @@ -77,32 +80,32 @@ class TestPanel(wxPanel): 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) #---------------------------------------------------------------------- diff --git a/wxPython/demo/XMLtreeview.py b/wxPython/demo/XMLtreeview.py index 081ac5f0f6..48edac38e9 100644 --- a/wxPython/demo/XMLtreeview.py +++ b/wxPython/demo/XMLtreeview.py @@ -1,9 +1,13 @@ +# 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 @@ -19,30 +23,34 @@ except ImportError: 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. @@ -69,6 +77,7 @@ else: def StartElement(self, name, attrs ): if py2: name = name.encode() + id = self.AppendItem(self.nodeStack[-1], name) self.nodeStack.append(id) @@ -79,6 +88,7 @@ else: if data.strip(): if py2: data = data.encode() + self.AppendItem(self.nodeStack[-1], data) @@ -104,16 +114,10 @@ else: - - - overview = """\ """ - - - if __name__ == '__main__': import sys,os import run diff --git a/wxPython/demo/demoMainLoop.py b/wxPython/demo/demoMainLoop.py index 4b21f8f71a..53aefda9be 100755 --- a/wxPython/demo/demoMainLoop.py +++ b/wxPython/demo/demoMainLoop.py @@ -1,5 +1,11 @@ #!/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. @@ -8,10 +14,8 @@ 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 #--------------------------------------------------------------------------- @@ -19,37 +23,37 @@ class MyFrame(wx.Frame): 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) @@ -112,7 +116,7 @@ class MyApp(wx.App): return True -app = MyApp(0) +app = MyApp(False) app.MainLoop() diff --git a/wxPython/demo/encode_bitmaps.py b/wxPython/demo/encode_bitmaps.py index dd5196b416..c3864545fa 100644 --- a/wxPython/demo/encode_bitmaps.py +++ b/wxPython/demo/encode_bitmaps.py @@ -1,5 +1,9 @@ #!/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 @@ -7,7 +11,8 @@ files... """ import sys -from wxPython.tools import img2py + +from wx.tools import img2py command_lines = [ diff --git a/wxPython/demo/infoframe.py b/wxPython/demo/infoframe.py index 24ea6570e1..a9d71f950b 100644 --- a/wxPython/demo/infoframe.py +++ b/wxPython/demo/infoframe.py @@ -1,48 +1,87 @@ - -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): @@ -50,7 +89,7 @@ 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) @@ -78,18 +117,42 @@ if __name__ == "__main__": ## 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() diff --git a/wxPython/demo/old_simple.py b/wxPython/demo/old_simple.py deleted file mode 100644 index 81d3570322..0000000000 --- a/wxPython/demo/old_simple.py +++ /dev/null @@ -1,60 +0,0 @@ - -#---------------------------------------------------------------------- -# 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() - diff --git a/wxPython/demo/pyTree.py b/wxPython/demo/pyTree.py index 72cb2ff317..89d8be4468 100644 --- a/wxPython/demo/pyTree.py +++ b/wxPython/demo/pyTree.py @@ -1,3 +1,8 @@ +# 11/13/2003 - Jeff Grimmett (grimmtooth@softhome.net) +# +# o Updated for wx namespace +# + """ Hello, and welcome to this test of the wxTreeItemData class. @@ -23,8 +28,10 @@ sample not because it's used, but because it's so 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 #---------------------------------------------------------------------- @@ -47,8 +54,10 @@ def _sourcefinder(func): for i in range(func.co_firstlineno): line = f.readline() + ind = _getindent(line) msg = "" + while line: msg = msg + line line = f.readline() @@ -56,13 +65,14 @@ def _sourcefinder(func): # 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. """ @@ -75,13 +85,16 @@ class pyTree(wx.wxTreeCtrl): 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) @@ -112,16 +125,20 @@ class pyTree(wx.wxTreeCtrl): 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): """ @@ -140,16 +157,22 @@ class pyTree(wx.wxTreeCtrl): """ 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) @@ -164,17 +187,15 @@ def runTest(frame, nb, log): 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) @@ -183,33 +204,31 @@ def runTest(frame, nb, log): #---------------------------------------------------------------------- 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() diff --git a/wxPython/demo/simple.py b/wxPython/demo/simple.py deleted file mode 100644 index d726900f41..0000000000 --- a/wxPython/demo/simple.py +++ /dev/null @@ -1,63 +0,0 @@ - -#---------------------------------------------------------------------- -# 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() - diff --git a/wxPython/demo/viewer.py b/wxPython/demo/viewer.py index befb03ece6..61d6eeefc8 100644 --- a/wxPython/demo/viewer.py +++ b/wxPython/demo/viewer.py @@ -1,4 +1,10 @@ #!/usr/bin/env python +# +# 11/15/2003 - Jeff Grimmett (grimmtooth@softhome.net) +# +# o Updated for wx namespace +# + """ Run wxPython in a second thread. @@ -56,7 +62,8 @@ class viewer_thread: def start(self): """ start the GUI thread """ - import thread,time + import time + import thread thread.start_new_thread(self.run, ()) def run(self): @@ -68,9 +75,10 @@ class viewer_thread: 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 @@ -80,7 +88,8 @@ class viewer_thread: 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) diff --git a/wxPython/demo/viewer_basics.py b/wxPython/demo/viewer_basics.py index 7916c1bce2..fb8577747f 100644 --- a/wxPython/demo/viewer_basics.py +++ b/wxPython/demo/viewer_basics.py @@ -1,14 +1,20 @@ -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() @@ -22,19 +28,17 @@ class VtkFrame(wxFrame): 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 @@ -42,8 +46,8 @@ class HiddenCatcher(wxFrame): 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() @@ -51,14 +55,14 @@ class HiddenCatcher(wxFrame): #--------------------------------------------------------------------------- -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 #--------------------------------------------------------------------------- diff --git a/wxPython/demo/widgetTest.py b/wxPython/demo/widgetTest.py index 3ca627c6ab..ad4c07ee92 100644 --- a/wxPython/demo/widgetTest.py +++ b/wxPython/demo/widgetTest.py @@ -1,36 +1,42 @@ +# 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() @@ -38,17 +44,29 @@ class TestPanel(wxPanel): #---------------------------------------------------------------------- -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])]) diff --git a/wxPython/demo/wxArtProvider.py b/wxPython/demo/wxArtProvider.py index 3f0c02d75a..a71c1ad062 100644 --- a/wxPython/demo/wxArtProvider.py +++ b/wxPython/demo/wxArtProvider.py @@ -1,56 +1,60 @@ +# 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): @@ -60,32 +64,32 @@ class MyArtProvider(wxArtProvider): # 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(): @@ -94,69 +98,69 @@ class MyArtProvider(wxArtProvider): -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]) @@ -179,29 +183,35 @@ class TestPanel(wxPanel): 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) @@ -214,7 +224,6 @@ def runTest(frame, nb, log): #---------------------------------------------------------------------- - overview = """

wxArtProvider

@@ -242,7 +251,7 @@ provided by wxArtProvider_GetBitmap or wxArtProvider_GetIcon methods. def makeBitmap(data): stream = cStringIO.StringIO(data) - return wxBitmapFromImage(wxImageFromStream(stream)) + return wx.BitmapFromImage(wx.ImageFromStream(stream)) back_png = \ diff --git a/wxPython/demo/wxButton.py b/wxPython/demo/wxButton.py index eaaefd2e6d..b4ac31d997 100644 --- a/wxPython/demo/wxButton.py +++ b/wxPython/demo/wxButton.py @@ -1,47 +1,50 @@ +# 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): @@ -61,9 +64,9 @@ def runTest(frame, nb, log): overview = """ -

wxButton

+

Button

-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. diff --git a/wxPython/demo/wxCalendar.py b/wxPython/demo/wxCalendar.py index f2d5c7057a..2c31de0363 100644 --- a/wxPython/demo/wxCalendar.py +++ b/wxPython/demo/wxCalendar.py @@ -8,12 +8,37 @@ # 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 @@ -35,21 +60,25 @@ test_days ={ 0: [], # 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 @@ -57,83 +86,85 @@ class TestPanel(wxPanel): 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] @@ -143,14 +174,14 @@ class TestPanel(wxPanel): 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() @@ -159,7 +190,7 @@ class TestPanel(wxPanel): 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() @@ -183,20 +214,21 @@ class TestPanel(wxPanel): 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: @@ -206,7 +238,7 @@ class TestPanel(wxPanel): 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() @@ -230,16 +262,17 @@ class TestPanel(wxPanel): # 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') @@ -247,7 +280,7 @@ class CalendFrame(wxFrame): 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() @@ -255,7 +288,7 @@ class CalendFrame(wxFrame): 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 @@ -266,6 +299,7 @@ class CalendFrame(wxFrame): def ResetDisplay(self): month = self.calend.GetMonth() + try: set_days = test_days[month] except: @@ -297,46 +331,46 @@ class CalendFrame(wxFrame): 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() @@ -352,15 +386,15 @@ class PrintCalend: 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 @@ -404,14 +438,15 @@ class PrintCalend: 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()) @@ -419,22 +454,24 @@ class PrintCalend: 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) @@ -458,14 +495,16 @@ class PrintCalend: 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) @@ -481,6 +520,7 @@ class PrintCalend: year, month = self.IncMonth(year, month) y = y + 3.5 + x = x + 4.0 # next column DC.EndDrawing() @@ -490,6 +530,7 @@ class PrintCalend: def IncMonth(self, year, month): # next month month = month + 1 + if month > 12: month = 1 year = year + 1 @@ -520,9 +561,9 @@ class PrintCalend: 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 @@ -541,10 +582,12 @@ class SetPrintout(wxPrintout): 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): @@ -554,12 +597,13 @@ class SetPrintout(wxPrintout): 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) @@ -576,7 +620,7 @@ class SetPrintout(wxPrintout): 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) @@ -596,9 +640,9 @@ class SetPrintout(wxPrintout): 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 @@ -606,7 +650,7 @@ class MyApp(wxApp): #--------------------------------------------------------------------------- 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() @@ -620,11 +664,14 @@ def runTest(frame, nb, log): 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 diff --git a/wxPython/demo/wxCalendarCtrl.py b/wxPython/demo/wxCalendarCtrl.py index 59d3cec76e..03fc569b4d 100644 --- a/wxPython/demo/wxCalendarCtrl.py +++ b/wxPython/demo/wxCalendarCtrl.py @@ -1,29 +1,32 @@ +# 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() @@ -36,6 +39,7 @@ class TestPanel(wxPanel): 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) diff --git a/wxPython/demo/wxCheckBox.py b/wxPython/demo/wxCheckBox.py index d7cceb618c..41fb677987 100644 --- a/wxPython/demo/wxCheckBox.py +++ b/wxPython/demo/wxCheckBox.py @@ -1,26 +1,28 @@ +# 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()) @@ -37,16 +39,6 @@ def runTest(frame, nb, log): - - - - - - - - - - overview = """\ A checkbox is a labelled box which is either on (checkmark is visible) or off (no checkmark). diff --git a/wxPython/demo/wxCheckListBox.py b/wxPython/demo/wxCheckListBox.py index 8eec482923..ef80a7637b 100644 --- a/wxPython/demo/wxCheckListBox.py +++ b/wxPython/demo/wxCheckListBox.py @@ -1,33 +1,34 @@ +# 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()) @@ -40,19 +41,23 @@ class TestPanel(wxPanel): 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() @@ -68,13 +73,16 @@ def runTest(frame, nb, log): #---------------------------------------------------------------------- - - 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__': diff --git a/wxPython/demo/wxChoice.py b/wxPython/demo/wxChoice.py index d92f4f8e45..39e2db847a 100644 --- a/wxPython/demo/wxChoice.py +++ b/wxPython/demo/wxChoice.py @@ -1,27 +1,32 @@ +# 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') #--------------------------------------------------------------------------- @@ -32,25 +37,22 @@ def runTest(frame, nb, log): #--------------------------------------------------------------------------- +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 +list. """ - if __name__ == '__main__': import sys,os import run diff --git a/wxPython/demo/wxColourDialog.py b/wxPython/demo/wxColourDialog.py index 151db30873..be0fc703d4 100644 --- a/wxPython/demo/wxColourDialog.py +++ b/wxPython/demo/wxColourDialog.py @@ -1,38 +1,56 @@ +# 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. +Do not try to retain the wx.ColourData instance. 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 diff --git a/wxPython/demo/wxComboBox.py b/wxPython/demo/wxComboBox.py index 13e8fced0d..eb995d51a5 100644 --- a/wxPython/demo/wxComboBox.py +++ b/wxPython/demo/wxComboBox.py @@ -1,60 +1,80 @@ -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()) #--------------------------------------------------------------------------- @@ -66,17 +86,28 @@ def runTest(frame, nb, log): +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 diff --git a/wxPython/demo/wxDialog.py b/wxPython/demo/wxDialog.py index 9d8272a7e4..263c2cfb50 100644 --- a/wxPython/demo/wxDialog.py +++ b/wxPython/demo/wxDialog.py @@ -1,119 +1,134 @@ +# 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. +However, the data must be retrieved prior to the dialog being destroyed. +The example shown here is modal; non-modal dialogs are possible as well. +See the documentation for the Dialog class for more details. +""" if __name__ == '__main__': import sys,os diff --git a/wxPython/demo/wxDirDialog.py b/wxPython/demo/wxDirDialog.py index cfb935d9b9..dc936d2272 100644 --- a/wxPython/demo/wxDirDialog.py +++ b/wxPython/demo/wxDirDialog.py @@ -1,23 +1,35 @@ +# 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 DirDialog documentation for specifics. """ diff --git a/wxPython/demo/wxDragImage.py b/wxPython/demo/wxDragImage.py index 4c348637cf..4b1764743f 100644 --- a/wxPython/demo/wxDragImage.py +++ b/wxPython/demo/wxDragImage.py @@ -1,32 +1,32 @@ +# 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), @@ -41,100 +41,111 @@ class DragShape: #---------------------------------------------------------------------- -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) @@ -142,55 +153,80 @@ class DragCanvas(wxScrolledWindow): 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 @@ -206,17 +242,17 @@ class DragCanvas(wxScrolledWindow): 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) @@ -244,14 +280,14 @@ class DragCanvas(wxScrolledWindow): 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()) @@ -262,10 +298,14 @@ class DragCanvas(wxScrolledWindow): #---------------------------------------------------------------------- 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 #---------------------------------------------------------------------- @@ -273,6 +313,28 @@ def runTest(frame, nb, log): 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, GenericDragImage is used. Applications may also prefer to use +GenericDragImage on Windows, too. + +wxPython note: wxPython uses GenericDragImage on all +platforms, but uses the DragImage name. + +To use this class, when you wish to start dragging an image, create a +DragImage 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. + """ diff --git a/wxPython/demo/wxDynamicSashWindow.py b/wxPython/demo/wxDynamicSashWindow.py index 9c9d1fa5b7..8deeceb0d7 100644 --- a/wxPython/demo/wxDynamicSashWindow.py +++ b/wxPython/demo/wxDynamicSashWindow.py @@ -1,23 +1,29 @@ +# 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): @@ -25,10 +31,10 @@ class TestView(wxStyledTextCtrl): # 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. @@ -67,20 +73,20 @@ continue splitting the new views as much as you like. Try it and see. 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) @@ -89,21 +95,21 @@ class SimpleView(wxPanel): #---------------------------------------------------------------------- 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 @@ -111,7 +117,7 @@ def runTest(frame, nb, log): overview = """\ -

wxDynamicSashWindow

+

DynamicSashWindow

wxDynamicSashWindow widgets manages the way other widgets are viewed. When a wxDynamicSashWindow is first shown, it will contain one child diff --git a/wxPython/demo/wxEditableListBox.py b/wxPython/demo/wxEditableListBox.py index 97b951a6e0..6d10604a54 100644 --- a/wxPython/demo/wxEditableListBox.py +++ b/wxPython/demo/wxEditableListBox.py @@ -1,17 +1,23 @@ -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.", @@ -29,21 +35,66 @@ def runTest(frame, nb, log): 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. + + +This class provides a composite control that lets the user easily enter and edit +a list of strings. + +

Styles supported:

+ +

    +
  • EL_ALLOW_NEW - Allow user to create new items. +
  • EL_ALLOW_EDIT - Allow user to edit text in the control. +
  • EL_ALLOW_DELETE - Allow user to delete text from the control. +
+ +

Init: +

+ 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")
+
+ +

Methods: +

    +
  • SetStrings(const wxArrayString& strings) - Set an array of strings + into the control. Note: The wxPython method accepts a Python list instead + of an array of strings. + +
  • void GetStrings(wxArrayString& strings) - Retrieves an array + of strings from the control. The wxPython version returns a list of strings. + +
  • GetListCtrl() - Retrieves a reference to the actual list control + portion of the custom control. + +
  • GetDelButton() - Retrieves a reference to the BitmapButton that is used + as the 'delete' button in the control. + +
  • GetNewButton() - Retrieves a reference to the BitmapButton that is used + as the 'new' button in the control. + +
  • GetUpButton() - Retrieves a reference to the BitmapButton that is used + as the 'up' button in the control. + +
  • GetDownButton() - Retrieves a reference to the BitmapButton that is used + as the 'down' button in the control. + +
  • GetEditButton() - Retrieves a reference to the BitmapButton that is used + as the 'edit' button in the control. +
+ + """ - - if __name__ == '__main__': import sys,os import run diff --git a/wxPython/demo/wxEditor.py b/wxPython/demo/wxEditor.py index 40bb835f2b..96e827afcb 100644 --- a/wxPython/demo/wxEditor.py +++ b/wxPython/demo/wxEditor.py @@ -1,14 +1,22 @@ - -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) @@ -57,7 +65,6 @@ component. One example of this might be to change the key Alt key commands. In that case you would (for example) override the SetAltFuncs() method. - """ diff --git a/wxPython/demo/wxFileDialog.py b/wxPython/demo/wxFileDialog.py index a87dc17194..0d42aa54e6 100644 --- a/wxPython/demo/wxFileDialog.py +++ b/wxPython/demo/wxFileDialog.py @@ -1,38 +1,64 @@ +# 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. """ diff --git a/wxPython/demo/wxFileDialog_Save.py b/wxPython/demo/wxFileDialog_Save.py index 3e404a0ea6..55fdae0596 100644 --- a/wxPython/demo/wxFileDialog_Save.py +++ b/wxPython/demo/wxFileDialog_Save.py @@ -1,9 +1,15 @@ +# 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|" \ @@ -12,28 +18,69 @@ wildcard = "Python source (*.py)|*.py|" \ 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! """ diff --git a/wxPython/demo/wxFileHistory.py b/wxPython/demo/wxFileHistory.py index ebedc59f41..7a0dc4962f 100644 --- a/wxPython/demo/wxFileHistory.py +++ b/wxPython/demo/wxFileHistory.py @@ -1,68 +1,83 @@ +# 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() @@ -72,11 +87,12 @@ class TestPanel(wxPanel): 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) @@ -88,7 +104,7 @@ class TestPanel(wxPanel): 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) @@ -108,12 +124,19 @@ def runTest(frame, nb, log): overview = """ -

wxFileHistory

+

FileHistory

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. +

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. + +

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. """ diff --git a/wxPython/demo/wxFindReplaceDialog.py b/wxPython/demo/wxFindReplaceDialog.py index 306c825205..54cc07ee3b 100644 --- a/wxPython/demo/wxFindReplaceDialog.py +++ b/wxPython/demo/wxFindReplaceDialog.py @@ -1,56 +1,79 @@ - -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 = "" @@ -59,7 +82,7 @@ class TestPanel(wxPanel): def OnFindClose(self, evt): - self.log.write("wxFindReplaceDialog closing...\n") + self.log.write("FindReplaceDialog closing...\n") evt.GetDialog().Destroy() #--------------------------------------------------------------------------- @@ -74,7 +97,20 @@ def runTest(frame, nb, log): 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 +must have a parent window. Also note that there is no way to use this +dialog in a modal way; it is always, by design and implementation, modeless. + +FileReplaceDialog requires the use of FindReplaceData. 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. Care must be +taken not to use this object after the dialog is destroyed. The data within +will be invalid after the parent dialog is destroyed. """ diff --git a/wxPython/demo/wxFloatBar.py b/wxPython/demo/wxFloatBar.py index 1daf702276..3772682e03 100644 --- a/wxPython/demo/wxFloatBar.py +++ b/wxPython/demo/wxFloatBar.py @@ -1,53 +1,69 @@ -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): @@ -55,8 +71,10 @@ class TestFloatBar(wxFrame): 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: @@ -83,12 +101,6 @@ close it to make the toolbar return to its original position. """ - - - - - - if __name__ == '__main__': import sys,os import run diff --git a/wxPython/demo/wxFontDialog.py b/wxPython/demo/wxFontDialog.py index e230dbc851..2135c491f1 100644 --- a/wxPython/demo/wxFontDialog.py +++ b/wxPython/demo/wxFontDialog.py @@ -1,69 +1,73 @@ +# 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() @@ -81,26 +85,29 @@ class TestPanel(wxPanel): 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() #--------------------------------------------------------------------------- @@ -109,18 +116,26 @@ def runTest(frame, nb, log): 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 before 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 diff --git a/wxPython/demo/wxFrame.py b/wxPython/demo/wxFrame.py index 6fbc2d013f..b2028e6eb5 100644 --- a/wxPython/demo/wxFrame.py +++ b/wxPython/demo/wxFrame.py @@ -1,18 +1,25 @@ +# 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): @@ -25,7 +32,7 @@ class MyFrame(wxFrame): 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) @@ -33,20 +40,30 @@ def runTest(frame, nb, log): #--------------------------------------------------------------------------- - - - - - - - - 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 +CreateStatusBar / CreateToolBar functions manages +these windows, and adjusts the value returned by GetClientSize +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 diff --git a/wxPython/demo/wxGLCanvas.py b/wxPython/demo/wxGLCanvas.py index a4d0194cb0..3f2a482d17 100644 --- a/wxPython/demo/wxGLCanvas.py +++ b/wxPython/demo/wxGLCanvas.py @@ -1,6 +1,15 @@ -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 @@ -8,8 +17,9 @@ except ImportError: 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 @@ -18,49 +28,52 @@ except ImportError: 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) @@ -69,7 +82,7 @@ else: 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) @@ -82,35 +95,38 @@ else: - 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): @@ -126,118 +142,113 @@ else: 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() @@ -248,24 +259,16 @@ else: - - - - - 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) diff --git a/wxPython/demo/wxGauge.py b/wxPython/demo/wxGauge.py index 754e1b4b21..5d65255f09 100644 --- a/wxPython/demo/wxGauge.py +++ b/wxPython/demo/wxGauge.py @@ -1,33 +1,41 @@ +# 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) @@ -42,19 +50,18 @@ def runTest(frame, nb, log): #---------------------------------------------------------------------- - - - - - - - - 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 SetValue 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 diff --git a/wxPython/demo/wxGenericDirCtrl.py b/wxPython/demo/wxGenericDirCtrl.py index d20cb85818..30d8bbb75e 100644 --- a/wxPython/demo/wxGenericDirCtrl.py +++ b/wxPython/demo/wxGenericDirCtrl.py @@ -1,23 +1,28 @@ -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)) @@ -26,9 +31,9 @@ class TestPanel(wxPanel): 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 @@ -36,6 +41,7 @@ class TestPanel(wxPanel): sz.AddGrowableCol(0) sz.AddGrowableCol(1) sz.AddGrowableCol(2) + self.SetSizer(sz) self.SetAutoLayout(True) @@ -46,16 +52,17 @@ def runTest(frame, nb, log): 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. + """ diff --git a/wxPython/demo/wxGrid.py b/wxPython/demo/wxGrid.py index 821f1d90da..efe344be0f 100644 --- a/wxPython/demo/wxGrid.py +++ b/wxPython/demo/wxGrid.py @@ -1,5 +1,9 @@ +# 11/18/2003 - Jeff Grimmett (grimmtooth@softhome.net) +# +# o Updated for wx namespace +# -from wxPython.wx import * +import wx #--------------------------------------------------------------------------- @@ -11,24 +15,25 @@ buttonDefs = { 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) @@ -51,13 +56,6 @@ def runTest(frame, nb, log): - - - - - - - overview = """\

wxGrid

@@ -99,8 +97,6 @@ and wrapping around to the next row when needed. """ - - if __name__ == '__main__': import sys,os import run diff --git a/wxPython/demo/wxGridBagSizer.py b/wxPython/demo/wxGridBagSizer.py index 17a94c898a..51ebb0c1de 100644 --- a/wxPython/demo/wxGridBagSizer.py +++ b/wxPython/demo/wxGridBagSizer.py @@ -20,7 +20,6 @@ class TestFrame(wx.Frame): 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) ) diff --git a/wxPython/demo/wxGrid_MegaExample.py b/wxPython/demo/wxGrid_MegaExample.py index cb96511e3b..aa77588e51 100644 --- a/wxPython/demo/wxGrid_MegaExample.py +++ b/wxPython/demo/wxGrid_MegaExample.py @@ -1,8 +1,14 @@ -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 """ @@ -13,12 +19,12 @@ class MegaTable(wxPyGridTableBase): 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() @@ -46,21 +52,24 @@ class MegaTable(wxPyGridTableBase): 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() @@ -76,7 +85,7 @@ class MegaTable(wxPyGridTableBase): 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): @@ -88,25 +97,33 @@ class MegaTable(wxPyGridTableBase): 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)) @@ -123,11 +140,13 @@ class MegaTable(wxPyGridTableBase): 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 = [] @@ -139,6 +158,7 @@ class MegaTable(wxPyGridTableBase): deleteCount = 0 rows = rows[:] rows.sort() + for i in rows: self.data.pop(i-deleteCount) # we need to advance the delete count @@ -151,12 +171,14 @@ class MegaTable(wxPyGridTableBase): """ 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) @@ -167,42 +189,45 @@ class MegaTable(wxPyGridTableBase): # -------------------------------------------------------------------- # 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 @@ -214,17 +239,15 @@ class MegaImageRenderer(wxPyGridCellRenderer): (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 @@ -236,17 +259,20 @@ class MegaFontRenderer(wxPyGridCellRenderer): 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 @@ -267,6 +293,7 @@ class MegaFontRenderer(wxPyGridCellRenderer): # 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 @@ -280,7 +307,7 @@ class MegaFontRenderer(wxPyGridCellRenderer): # 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 @@ -289,12 +316,12 @@ class MegaGrid(wxGrid): """ # 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 @@ -309,12 +336,14 @@ class MegaGrid(wxGrid): 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)") @@ -328,18 +357,20 @@ class MegaGrid(wxGrid): 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) @@ -357,11 +388,14 @@ class MegaGrid(wxGrid): 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 @@ -374,10 +408,12 @@ import random 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 @@ -402,11 +438,11 @@ class MegaFontRendererFactory: #--------------------------------------------------------------------------- -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) @@ -428,22 +464,22 @@ This example attempts to show many examples and tricks of 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 +
    +
  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 resized) - 4) Dynamic renderers. Renderers are plugins based on +
  4. Dynamic renderers. Renderers are plugins based on column header name. Shows a simple Font Renderer and an Image Renderer. +
-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 diff --git a/wxPython/demo/wxHtmlWindow.py b/wxPython/demo/wxHtmlWindow.py index dd2819545b..a7b8c01e1a 100644 --- a/wxPython/demo/wxHtmlWindow.py +++ b/wxPython/demo/wxHtmlWindow.py @@ -1,9 +1,13 @@ +# 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 @@ -13,18 +17,17 @@ 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()) @@ -46,9 +49,9 @@ class MyHtmlWindow(wxHtmlWindow): # 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 @@ -62,64 +65,65 @@ class MyHtmlFilter(wxHtmlFilter): 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) @@ -136,18 +140,22 @@ class TestHtmlPanel(wxPanel): 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() @@ -162,18 +170,20 @@ class TestHtmlPanel(wxPanel): 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() @@ -186,16 +196,13 @@ class TestHtmlPanel(wxPanel): def runTest(frame, nb, log): win = TestHtmlPanel(nb, frame, log) - print wxWindow_FindFocus() + print wx.Window_FindFocus() return win #---------------------------------------------------------------------- - - - overview = """

wxHtmlWindow

@@ -203,9 +210,8 @@ overview = """ simple HTML tags.

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. """ diff --git a/wxPython/demo/wxIEHtmlWin.py b/wxPython/demo/wxIEHtmlWin.py index 1604da40cc..33e5b8c8be 100644 --- a/wxPython/demo/wxIEHtmlWin.py +++ b/wxPython/demo/wxIEHtmlWin.py @@ -1,83 +1,96 @@ +# 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): @@ -96,7 +109,7 @@ class TestPanel(wxWindow): 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) @@ -105,17 +118,19 @@ class TestPanel(wxWindow): 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): @@ -134,8 +149,7 @@ class TestPanel(wxWindow): 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): @@ -169,12 +183,12 @@ class TestPanel(wxWindow): # 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() diff --git a/wxPython/demo/wxImage.py b/wxPython/demo/wxImage.py index 23d3ee7eee..415bfd9ce7 100644 --- a/wxPython/demo/wxImage.py +++ b/wxPython/demo/wxImage.py @@ -1,31 +1,33 @@ +# 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 @@ -33,14 +35,44 @@ def runTest(frame, nb, log): - - - - overview = """\ -""" - - + + +This class encapsulates a platform-independent image. An image can be created +from data, or using wxBitmap.ConvertToImage. 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. + +

The following image handlers are available. wxBMPHandler is always installed +by default. To use other image formats, install the appropriate handler or use +wx.InitAllImageHandlers(). + +

+

Thisis
+ + + + + + + + + + + + +
wxBMPHandler For loading and saving, always installed.
wxPNGHandler For loading and saving.
wxJPEGHandler For loading and saving.
wxGIFHandler Only for loading, due to legal issues.
wxPCXHandler For loading and saving.
wxPNMHandler For loading and saving.
wxTIFFHandler For loading and saving.
wxIFFHandler For loading only.
wxXPMHandler For loading and saving.
wxICOHandler For loading and saving.
wxCURHandler For loading and saving.
wxANIHandler For loading only.
+ +

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. + +

Loading PNMs only works for ASCII or raw RGB images. When saving in PNM format, +wxPNMHandler will always save as raw RGB. + + +""" if __name__ == '__main__': import sys,os diff --git a/wxPython/demo/wxImageFromStream.py b/wxPython/demo/wxImageFromStream.py index 1bf4fc7645..720389a818 100644 --- a/wxPython/demo/wxImageFromStream.py +++ b/wxPython/demo/wxImageFromStream.py @@ -1,24 +1,31 @@ +# 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())) @@ -37,10 +44,7 @@ directly from any Python file-like object, such as a memory buffer using StringIO. """ - - if __name__ == '__main__': import sys,os import run run.main(['', os.path.basename(sys.argv[0])]) - diff --git a/wxPython/demo/wxIntCtrl.py b/wxPython/demo/wxIntCtrl.py index d4c48a1cd3..026b9bcdd3 100644 --- a/wxPython/demo/wxIntCtrl.py +++ b/wxPython/demo/wxIntCtrl.py @@ -1,52 +1,62 @@ -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 ) @@ -54,14 +64,16 @@ class TestPanel( wxPanel ): 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 ): @@ -79,6 +91,7 @@ class TestPanel( wxPanel ): if self.set_min.GetValue(): min = self.min.GetValue() + if self.set_max.GetValue(): max = self.max.GetValue() @@ -86,16 +99,18 @@ class TestPanel( wxPanel ): 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: diff --git a/wxPython/demo/wxKeyEvents.py b/wxPython/demo/wxKeyEvents.py index 7e214089f5..ee2259c061 100644 --- a/wxPython/demo/wxKeyEvents.py +++ b/wxPython/demo/wxKeyEvents.py @@ -1,139 +1,148 @@ - -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): @@ -150,17 +159,17 @@ class KeySink(wxWindow): 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): @@ -195,14 +204,12 @@ class KeySink(wxWindow): #---------------------------------------------------------------------- -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") @@ -213,7 +220,7 @@ class KeyLog(wxListCtrl, wxListCtrlAutoWidthMixin): 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) @@ -261,43 +268,43 @@ class KeyLog(wxListCtrl, wxListCtrlAutoWidthMixin): #---------------------------------------------------------------------- -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) @@ -331,7 +338,7 @@ def runTest(frame, nb, log): overview = """

wxKeyEvents

-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. diff --git a/wxPython/demo/wxLEDNumberCtrl.py b/wxPython/demo/wxLEDNumberCtrl.py index 4aead17541..7bb46e1647 100644 --- a/wxPython/demo/wxLEDNumberCtrl.py +++ b/wxPython/demo/wxLEDNumberCtrl.py @@ -1,32 +1,36 @@ +# 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): @@ -45,6 +49,62 @@ def runTest(frame, nb, log): #---------------------------------------------------------------------- overview = """\ + + +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 +

+wxLEDNumberCtrl( parent, id=-1, pos=wx.DefaultPosition, +size=wx.DefaultSize, style=LED_ALIGN_LEFT | LED_DRAW_FADED) + +

This is a control that simulates an LED clock display. It only accepts +numeric input. + +

Styles + +

+
LED_ALIGN_LEFT +
Align to the left. + +
LED_ALIGN_RIGHT +
Align to the right. + +
LED_ALIGN_CENTER +
Center on display. + +
LED_DRAW_FADED +
Not implemented. + +
+ +

Methods (and best guesses at what they do) + +

+
GetAlignment() +
Returns the alignment attribute for the control. + +
GetDrawFaded() +
Returns the DrawFaded attribute for the control. + +
GetValue() +
Returns the current value of the control. + +
SetAlignment(alignment) +
Set the alignment attribute for the control. + +
SetDrawFaded(value) +
Set the DrawFaded attribute for the control. + +
SetValue(number) +
Set the value for the control. Only numeric values are accepted. + +
+ +

Additionally, several methods of wx.Window are available as well. + + + """ diff --git a/wxPython/demo/wxLayoutConstraints.py b/wxPython/demo/wxLayoutConstraints.py index 1c65b303df..29ffeaf080 100644 --- a/wxPython/demo/wxLayoutConstraints.py +++ b/wxPython/demo/wxLayoutConstraints.py @@ -1,95 +1,99 @@ +# 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() #--------------------------------------------------------------------------- @@ -102,43 +106,33 @@ def runTest(frame, nb, log): - - - - - - - - - - - - -overview = """\ +overview = """\ + 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 +

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 +

+

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 diff --git a/wxPython/demo/wxListBox.py b/wxPython/demo/wxListBox.py index 074f2de5ae..c3a69d6919 100644 --- a/wxPython/demo/wxListBox.py +++ b/wxPython/demo/wxListBox.py @@ -1,49 +1,64 @@ +# 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() @@ -54,44 +69,38 @@ class wxFindPrefixListBox(wxListBox): #--------------------------------------------------------------------------- -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) @@ -101,6 +110,7 @@ class TestListBox(wxPanel): lb = event.GetEventObject() data = lb.GetClientData(lb.GetSelection()) + if data is not None: self.log.WriteText('\tdata: %s\n' % data) @@ -114,9 +124,11 @@ class TestListBox(wxPanel): 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) @@ -132,9 +144,6 @@ def runTest(frame, nb, log): - - - overview = """ A listbox is used to select one or more of a list of strings. The strings are displayed in a scrolling box, with the diff --git a/wxPython/demo/wxListCtrl.py b/wxPython/demo/wxListCtrl.py index 32b3a3f461..14870c20f9 100644 --- a/wxPython/demo/wxListCtrl.py +++ b/wxPython/demo/wxListCtrl.py @@ -9,9 +9,21 @@ # 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 #--------------------------------------------------------------------------- @@ -72,84 +84,85 @@ musicdata = { 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) @@ -165,19 +178,19 @@ class TestListCtrlPanel(wxPanel, wxColumnSorterMixin): 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 @@ -197,8 +210,10 @@ class TestListCtrlPanel(wxPanel, wxColumnSorterMixin): 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() @@ -215,11 +230,13 @@ class TestListCtrlPanel(wxPanel, wxColumnSorterMixin): 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() @@ -229,7 +246,7 @@ class TestListCtrlPanel(wxPanel, wxColumnSorterMixin): # 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): @@ -275,21 +292,22 @@ class TestListCtrlPanel(wxPanel, wxColumnSorterMixin): # 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") @@ -300,7 +318,7 @@ class TestListCtrlPanel(wxPanel, wxColumnSorterMixin): # 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() @@ -312,15 +330,15 @@ class TestListCtrlPanel(wxPanel, wxColumnSorterMixin): 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() @@ -339,9 +357,6 @@ class TestListCtrlPanel(wxPanel, wxColumnSorterMixin): - - - #--------------------------------------------------------------------------- def runTest(frame, nb, log): @@ -351,15 +366,136 @@ def runTest(frame, nb, log): #--------------------------------------------------------------------------- +overview = """\ + + +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. +

To intercept events from a list control, use the event table macros described in +wxListEvent. -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. +

Mix-ins

+This example demonstrates how to use mixins. The following mixins are available. -""" +

ColumnSorterMixin

+ +ColumnSorterMixin(numColumns) + +

A mixin class that handles sorting of a wxListCtrl in REPORT mode when the column +header is clicked on. + +

There are a few requirments needed in order for this to work genericly: +

    +
  1. The combined class must have a GetListCtrl method that returns + the ListCtrl to be sorted, and the list control must exist at the time the + ColumnSorterMixin.__init__()method is called because it uses + GetListCtrl. + +
  2. Items in the list control must have a unique data value set with + list.SetItemData. + +
  3. The combined class must have an attribute named itemDataMap + 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. +
+ +

Interesting methods to override are GetColumnSorter, +GetSecondarySortValues, and GetSortImages. +

Methods
+
+
SetColumnCount(newNumColumns) +
Informs the mixin as to the number of columns in the control. When it is +set, it also sets up an event handler for EVT_LIST_COL_CLICK events. +
SortListItems(col=-1, ascending=1) +
Sort the list on demand. Can also be used to set the sort column and order. +
GetColumnWidths() +
Returns a list of column widths. Can be used to help restore the current +view later. + +
GetSortImages() +
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 + +
GetColumnSorter() +
Returns a callable object to be used for comparing column values when sorting. + +
GetSecondarySortValues(col, key1, key2) +
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. + +
+ +

ListCtrlAutoWidthMixin

+ +wxListCtrlAutoWidthMixin() + +

A mix-in class that automatically resizes the last column to take up the +remaining width of the ListCtrl. + +

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. + +

NOTE: This only works for report-style lists. + +

WARNING: If you override the EVT_SIZE event in your ListCtrl, +make sure you call event.Skip() to ensure that the mixin's _OnResize method is +called. + +

This mix-in class was written by Erik Westra + +

Methods
+
+ +
resizeLastColumn(minWidth) +
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. + +
+ + +

ListCtrlSelectionManagerMix

+ +ListCtrlSelectionManagerMix() + +

Mixin that defines a platform independent selection policy + +

As selection single and multi-select list return the item index or a +list of item indexes respectively. + +

Methods
+
+ +
getPopupMenu() +
Override to implement dynamic menus (create) + +
setPopupMenu(menu) +
Must be set for default behaviour. + +
afterPopupMenu() +
Override to implement dynamic menus (destroy). + +
getSelection() +
Returns the current selection (or selections as a Python list if extended +selection is enabled) + + + + +""" if __name__ == '__main__': diff --git a/wxPython/demo/wxListCtrl_virtual.py b/wxPython/demo/wxListCtrl_virtual.py index ba64a193c9..75f5d97573 100644 --- a/wxPython/demo/wxListCtrl_virtual.py +++ b/wxPython/demo/wxListCtrl_virtual.py @@ -1,18 +1,29 @@ - -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") @@ -24,15 +35,15 @@ class TestVirtualList(wxListCtrl): 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): @@ -89,10 +100,12 @@ def runTest(frame, nb, log): #---------------------------------------------------------------------- - - - 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 OnGetItemText(), OnGetItemImage(), +and OnGetItemAttr(). This greatly reduces the amount of memory required +without limiting what can be done with the list control itself. """ diff --git a/wxPython/demo/wxListbook.py b/wxPython/demo/wxListbook.py index 9165966368..f7be7ba1d5 100644 --- a/wxPython/demo/wxListbook.py +++ b/wxPython/demo/wxListbook.py @@ -1,11 +1,15 @@ +# 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", @@ -26,10 +30,10 @@ colourList = [ "Aquamarine", "Black", "Blue", "Blue Violet", "Brown", "Cadet Blu #---------------------------------------------------------------------------- -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 @@ -45,7 +49,6 @@ class TestLB(wxListbook): bmp = f() il.Add(bmp) self.AssignImageList(il) - # Now make a bunch of panels for the list book first = True @@ -71,12 +74,12 @@ class TestLB(wxListbook): 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 @@ -103,8 +106,6 @@ def runTest(frame, nb, log): #---------------------------------------------------------------------------- - - overview = """\

wxListbook

@@ -122,6 +123,3 @@ if __name__ == '__main__': run.main(['', os.path.basename(sys.argv[0])]) - - - diff --git a/wxPython/demo/wxMDIWindows.py b/wxPython/demo/wxMDIWindows.py index c8f647929b..4478165dea 100644 --- a/wxPython/demo/wxMDIWindows.py +++ b/wxPython/demo/wxMDIWindows.py @@ -1,34 +1,39 @@ +# 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() @@ -48,15 +53,13 @@ overview = """

Multiple Document Interface

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. """ - - - if __name__ == '__main__': import sys,os import run diff --git a/wxPython/demo/wxMVCTree.py b/wxPython/demo/wxMVCTree.py index 17d71cd211..80301ef360 100644 --- a/wxPython/demo/wxMVCTree.py +++ b/wxPython/demo/wxMVCTree.py @@ -1,8 +1,17 @@ +# 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): @@ -23,24 +32,26 @@ def delitem(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 @@ -48,8 +59,6 @@ def runTest(frame, nb, log): #return None - - overview = """\ wxMVCTree is a control which handles hierarchical data. It is @@ -71,9 +80,6 @@ demo, to avoid accidentally renaming files! """ - - - if __name__ == '__main__': import sys,os import run diff --git a/wxPython/demo/wxMask.py b/wxPython/demo/wxMask.py index fb4f453497..ad35dfd9b5 100644 --- a/wxPython/demo/wxMask.py +++ b/wxPython/demo/wxMask.py @@ -1,37 +1,41 @@ +# 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() @@ -40,8 +44,8 @@ class TestMaskWindow(wxScrolledWindow): 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) @@ -49,21 +53,21 @@ class TestMaskWindow(wxScrolledWindow): # 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)) @@ -80,8 +84,9 @@ class TestMaskWindow(wxScrolledWindow): 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)) @@ -92,11 +97,11 @@ class TestMaskWindow(wxScrolledWindow): # 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()) @@ -111,8 +116,14 @@ def runTest(frame, nb, log): #---------------------------------------------------------------------- - 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) Blit() method's logic codes. """ diff --git a/wxPython/demo/wxMaskedNumCtrl.py b/wxPython/demo/wxMaskedNumCtrl.py index b6fe1ec61d..6bdef2cad3 100644 --- a/wxPython/demo/wxMaskedNumCtrl.py +++ b/wxPython/demo/wxMaskedNumCtrl.py @@ -1,143 +1,145 @@ -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 ) @@ -146,34 +148,35 @@ value entry ctrl:""") 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: @@ -196,9 +199,9 @@ value entry ctrl:""") 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 ) @@ -206,9 +209,9 @@ value entry ctrl:""") 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 ) @@ -238,9 +241,9 @@ value entry ctrl:""") 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 ): @@ -248,9 +251,9 @@ value entry ctrl:""") 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: @@ -327,7 +330,7 @@ def runTest( frame, nb, log ): return win #---------------------------------------------------------------------- -overview = overviewdoc +overview = mnum.__doc__ if __name__ == '__main__': import sys,os diff --git a/wxPython/demo/wxMenu.py b/wxPython/demo/wxMenu.py index 7ee390800a..516241efcf 100644 --- a/wxPython/demo/wxMenu.py +++ b/wxPython/demo/wxMenu.py @@ -4,34 +4,38 @@ # 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") @@ -41,11 +45,11 @@ check the source for this sample to see how to implement them. 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") @@ -53,33 +57,36 @@ check the source for this sample to see how to implement them. # 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") @@ -91,36 +98,37 @@ check the source for this sample to see how to implement them. 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 @@ -130,8 +138,10 @@ check the source for this sample to see how to implement them. 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): @@ -187,14 +197,21 @@ check the source for this sample to see how to implement them. 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): @@ -216,24 +233,25 @@ check the source for this sample to see how to implement them. # 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) @@ -246,9 +264,33 @@ def runTest(frame, nb, 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__': diff --git a/wxPython/demo/wxMessageDialog.py b/wxPython/demo/wxMessageDialog.py index b75d907739..009c30fb11 100644 --- a/wxPython/demo/wxMessageDialog.py +++ b/wxPython/demo/wxMessageDialog.py @@ -1,11 +1,15 @@ +# 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() @@ -14,22 +18,19 @@ def runTest(frame, nb, log): - - - - - - - - - - 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__': diff --git a/wxPython/demo/wxMiniFrame.py b/wxPython/demo/wxMiniFrame.py index b92e300eda..42e237ae4f 100644 --- a/wxPython/demo/wxMiniFrame.py +++ b/wxPython/demo/wxMiniFrame.py @@ -1,17 +1,24 @@ +# 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) @@ -25,9 +32,9 @@ class MyMiniFrame(wxMiniFrame): 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) @@ -35,21 +42,13 @@ def runTest(frame, nb, log): #--------------------------------------------------------------------------- - - - - - - - - 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 diff --git a/wxPython/demo/wxMultiSash.py b/wxPython/demo/wxMultiSash.py index 6308121201..c07aa05bad 100644 --- a/wxPython/demo/wxMultiSash.py +++ b/wxPython/demo/wxMultiSash.py @@ -1,6 +1,17 @@ -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 #--------------------------------------------------------------------------- @@ -26,24 +37,27 @@ returned by GetSaveData, as it is just another object in the dictionary. #--------------------------------------------------------------------------- -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 @@ -55,7 +69,7 @@ class TestFrame(wxFrame): 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 diff --git a/wxPython/demo/wxMultipleChoiceDialog.py b/wxPython/demo/wxMultipleChoiceDialog.py index c7f93764e1..c2a0b6638a 100644 --- a/wxPython/demo/wxMultipleChoiceDialog.py +++ b/wxPython/demo/wxMultipleChoiceDialog.py @@ -1,34 +1,85 @@ - -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 = """\ + + +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. +

wxMultipleChoiceDialog(self, parent, msg, title, lst, +pos = wx.wxDefaultPosition, size = (200,200), style = wx.wxDEFAULT_DIALOG_STYLE) + +

+
parent +
The parent window +
msg +
The message that will be displayed above the list +
title +
The text that will appear on the title bar -overview = """\ -""" +
lst +
A Python list of choices that will appear in the dialog. + +
pos +
The position of the dialog +
size +
The size of the dialog +
style +
The style for the dialog. Only styles normally available to wxDialog are +available. +
+Methods + +
+
GetValue +
Returns a tuple containing the indices of the selected items + +
GetValueString +
Returns a tuple containing the text of the selected items + +
+ +Additionally, wxMultipleChoiceDialog.lbox is a standard wxListBox which supports all +methods applicable to that class. + + + +""" if __name__ == '__main__': import sys,os diff --git a/wxPython/demo/wxNotebook.py b/wxPython/demo/wxNotebook.py index 1f46c2c6e8..2b6b72315b 100644 --- a/wxPython/demo/wxNotebook.py +++ b/wxPython/demo/wxNotebook.py @@ -1,39 +1,44 @@ +# 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) @@ -41,13 +46,13 @@ class TestNB(wxNotebook): 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) @@ -56,34 +61,35 @@ class TestNB(wxNotebook): 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() @@ -108,8 +114,6 @@ def runTest(frame, nb, log): #---------------------------------------------------------------------------- - - overview = """\

wxNotebook

@@ -124,7 +128,6 @@ delete the window for a page that is currently managed by wxNotebook. """ - if __name__ == '__main__': import sys,os import run diff --git a/wxPython/demo/wxOGL.py b/wxPython/demo/wxOGL.py index 042cd15721..a096704009 100644 --- a/wxPython/demo/wxOGL.py +++ b/wxPython/demo/wxOGL.py @@ -1,27 +1,41 @@ +# 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), @@ -34,34 +48,34 @@ class DiamondShape(wxPolygonShape): #---------------------------------------------------------------------- -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() @@ -70,9 +84,12 @@ class DividedShape(wxDividedShape): 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) @@ -89,9 +106,9 @@ class DividedShape(wxDividedShape): #---------------------------------------------------------------------- -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 @@ -106,7 +123,7 @@ class MyEvtHandler(wxShapeEvtHandler): shape = self.GetShape() print shape.__class__, shape.GetClassName() canvas = shape.GetCanvas() - dc = wxClientDC(canvas) + dc = wx.ClientDC(canvas) canvas.PrepareDC(dc) if shape.Selected(): @@ -116,6 +133,7 @@ class MyEvtHandler(wxShapeEvtHandler): 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 @@ -128,6 +146,7 @@ class MyEvtHandler(wxShapeEvtHandler): if toUnselect: for s in toUnselect: s.Select(False, dc) + canvas.Redraw(dc) self.UpdateStatusBar(shape) @@ -136,8 +155,10 @@ class MyEvtHandler(wxShapeEvtHandler): 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) @@ -157,9 +178,9 @@ class MyEvtHandler(wxShapeEvtHandler): #---------------------------------------------------------------------- -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 @@ -167,43 +188,64 @@ class TestWindow(wxShapeCanvas): 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) @@ -212,7 +254,7 @@ class TestWindow(wxShapeCanvas): # 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): @@ -223,7 +265,7 @@ class TestWindow(wxShapeCanvas): 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) @@ -242,6 +284,7 @@ class TestWindow(wxShapeCanvas): if shape.GetParent() == None: shape.SetCanvas(None) shape.Destroy() + self.diagram.Destroy() @@ -258,15 +301,15 @@ def runTest(frame, nb, log): # 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() @@ -274,20 +317,12 @@ class __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 diff --git a/wxPython/demo/wxPageSetupDialog.py b/wxPython/demo/wxPageSetupDialog.py index 692d21973d..a4e7e4e215 100644 --- a/wxPython/demo/wxPageSetupDialog.py +++ b/wxPython/demo/wxPageSetupDialog.py @@ -1,36 +1,53 @@ +# 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 wxPageSetupDialogData 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 diff --git a/wxPython/demo/wxPlotCanvas.py b/wxPython/demo/wxPlotCanvas.py index 5f1a42ed91..4311942af3 100644 --- a/wxPython/demo/wxPlotCanvas.py +++ b/wxPython/demo/wxPlotCanvas.py @@ -1,6 +1,17 @@ +# 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 #--------------------------------------------------------------------------- @@ -9,38 +20,36 @@ def _InitObjects(): 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 diff --git a/wxPython/demo/wxPopupControl.py b/wxPython/demo/wxPopupControl.py index b3b7ad2b7d..e9e369926d 100644 --- a/wxPython/demo/wxPopupControl.py +++ b/wxPython/demo/wxPopupControl.py @@ -1,13 +1,22 @@ -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) @@ -17,7 +26,7 @@ class TestDateControl(wxPopupControl): 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): @@ -39,26 +48,29 @@ class TestDateControl(wxPopupControl): 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)) #---------------------------------------------------------------------- @@ -69,8 +81,6 @@ def runTest(frame, nb, log): #---------------------------------------------------------------------- - - overview = """

wxPopupControl

@@ -86,7 +96,6 @@ wxPopupWindow should be used... """ - if __name__ == '__main__': import sys,os import run diff --git a/wxPython/demo/wxPopupWindow.py b/wxPython/demo/wxPopupWindow.py index 0ee3df748c..7c98e77b37 100644 --- a/wxPython/demo/wxPopupWindow.py +++ b/wxPython/demo/wxPopupWindow.py @@ -1,20 +1,34 @@ -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" @@ -27,17 +41,19 @@ class TestPopup(wxPopupWindow): "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()) @@ -59,14 +75,14 @@ class TestPopup(wxPopupWindow): 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" @@ -87,77 +103,87 @@ class TestTransientPopup(wxPopupTransientWindow): -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() @@ -169,22 +195,21 @@ def runTest(frame, nb, log): 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 diff --git a/wxPython/demo/wxPrintDialog.py b/wxPython/demo/wxPrintDialog.py index b70e484dd5..981f0ea965 100644 --- a/wxPython/demo/wxPrintDialog.py +++ b/wxPython/demo/wxPrintDialog.py @@ -1,10 +1,13 @@ +# 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) @@ -13,22 +16,29 @@ def runTest(frame, nb, log): 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 diff --git a/wxPython/demo/wxProcess.py b/wxPython/demo/wxProcess.py index b9bd6ceb66..42c46c2cd6 100644 --- a/wxPython/demo/wxProcess.py +++ b/wxPython/demo/wxProcess.py @@ -1,58 +1,62 @@ +# 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) @@ -68,9 +72,9 @@ class TestPanel(wxPanel): 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) @@ -109,6 +113,7 @@ class TestPanel(wxPanel): (evt.GetPid(), evt.GetExitCode())) stream = self.process.GetInputStream() + if stream.CanRead(): text = stream.read() self.out.AppendText(text) @@ -154,9 +159,6 @@ child process to exit its main loop. """ - - - if __name__ == '__main__': import sys,os import run diff --git a/wxPython/demo/wxProgressDialog.py b/wxPython/demo/wxProgressDialog.py index ec7bff1bd3..9144175976 100644 --- a/wxPython/demo/wxProgressDialog.py +++ b/wxPython/demo/wxProgressDialog.py @@ -1,21 +1,33 @@ - -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!") @@ -28,12 +40,20 @@ def runTest(frame, nb, log): #--------------------------------------------------------------------------- - - 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 completely 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 diff --git a/wxPython/demo/wxPyColourChooser.py b/wxPython/demo/wxPyColourChooser.py index c213042aa3..050a1a3f63 100644 --- a/wxPython/demo/wxPyColourChooser.py +++ b/wxPython/demo/wxPyColourChooser.py @@ -1,16 +1,25 @@ -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) diff --git a/wxPython/demo/wxRadioBox.py b/wxPython/demo/wxRadioBox.py index 9a31860855..cd583a3378 100644 --- a/wxPython/demo/wxRadioBox.py +++ b/wxPython/demo/wxRadioBox.py @@ -1,40 +1,44 @@ +# 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) @@ -42,13 +46,14 @@ class TestRadioButtons(wxPanel): 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 @@ -61,7 +66,6 @@ labelled buttons. """ - if __name__ == '__main__': import sys,os import run diff --git a/wxPython/demo/wxRadioButton.py b/wxPython/demo/wxRadioButton.py index 2993cec800..ad4ee8ce7c 100644 --- a/wxPython/demo/wxRadioButton.py +++ b/wxPython/demo/wxRadioButton.py @@ -1,57 +1,67 @@ -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 ) @@ -60,19 +70,19 @@ class TestPanel( wxPanel ): # 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) @@ -82,6 +92,7 @@ class TestPanel( wxPanel ): 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) diff --git a/wxPython/demo/wxRightTextCtrl.py b/wxPython/demo/wxRightTextCtrl.py index b2fa3e970b..cc5de1a014 100644 --- a/wxPython/demo/wxRightTextCtrl.py +++ b/wxPython/demo/wxRightTextCtrl.py @@ -1,36 +1,53 @@ - -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) @@ -45,9 +62,7 @@ def runTest(frame, nb, log): #---------------------------------------------------------------------- -overview = wxPython.lib.rightalign.__doc__ - - +overview = right.__doc__ if __name__ == '__main__': diff --git a/wxPython/demo/wxSashWindow.py b/wxPython/demo/wxSashWindow.py index 17105b0a9d..b70a3ee7a1 100644 --- a/wxPython/demo/wxSashWindow.py +++ b/wxPython/demo/wxSashWindow.py @@ -1,9 +1,14 @@ +# 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 @@ -11,97 +16,112 @@ class TestSashWindow(wxPanel): 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) #--------------------------------------------------------------------------- @@ -112,12 +132,17 @@ def runTest(frame, nb, log): #--------------------------------------------------------------------------- - - 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__': diff --git a/wxPython/demo/wxScrolledMessageDialog.py b/wxPython/demo/wxScrolledMessageDialog.py index a9715c6af2..5838d88444 100644 --- a/wxPython/demo/wxScrolledMessageDialog.py +++ b/wxPython/demo/wxScrolledMessageDialog.py @@ -1,28 +1,45 @@ - -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 = """\ -""" +wxScrolledMessageDialog(parent, msg, caption, pos=wx.DefaultPosition, size=(500,300)) +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 diff --git a/wxPython/demo/wxScrolledPanel.py b/wxPython/demo/wxScrolledPanel.py index a0e89ae421..63e1ed03a8 100644 --- a/wxPython/demo/wxScrolledPanel.py +++ b/wxPython/demo/wxScrolledPanel.py @@ -1,18 +1,27 @@ -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 " @@ -21,46 +30,46 @@ class TestPanel(wxScrolledPanel): "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) @@ -75,7 +84,7 @@ class TestPanel(wxScrolledPanel): hbox.Add(panel1, 0) hbox.Add((40, 10)) - vbox2 = wxBoxSizer(wxVERTICAL) + vbox2 = wx.BoxSizer(wx.VERTICAL) vbox2.Add(panel2, 0) vbox2.Add((20, 50)) @@ -103,7 +112,7 @@ def runTest(frame, nb, log): overview = """ 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. """ diff --git a/wxPython/demo/wxScrolledWindow.py b/wxPython/demo/wxScrolledWindow.py index d9aa83e3f4..8dcc92b570 100644 --- a/wxPython/demo/wxScrolledWindow.py +++ b/wxPython/demo/wxScrolledWindow.py @@ -1,15 +1,20 @@ +# 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 @@ -19,9 +24,9 @@ class MyCanvas(wxScrolledWindow): 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 @@ -29,17 +34,16 @@ class MyCanvas(wxScrolledWindow): 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): @@ -52,12 +56,12 @@ class MyCanvas(wxScrolledWindow): 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. @@ -66,49 +70,50 @@ class MyCanvas(wxScrolledWindow): 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: @@ -116,21 +121,22 @@ class MyCanvas(wxScrolledWindow): # 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) @@ -141,10 +147,11 @@ class MyCanvas(wxScrolledWindow): 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): @@ -168,18 +175,18 @@ class MyCanvas(wxScrolledWindow): 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() @@ -193,7 +200,8 @@ class MyCanvas(wxScrolledWindow): ## 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): @@ -222,14 +230,17 @@ def runTest(frame, nb, log): - - -overview = """\ +overview = """ + + +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. + + """ - - if __name__ == '__main__': import sys,os import run diff --git a/wxPython/demo/wxSingleChoiceDialog.py b/wxPython/demo/wxSingleChoiceDialog.py index 7330ac6020..34c6f50b5f 100644 --- a/wxPython/demo/wxSingleChoiceDialog.py +++ b/wxPython/demo/wxSingleChoiceDialog.py @@ -1,14 +1,22 @@ +# 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() #--------------------------------------------------------------------------- @@ -21,6 +29,8 @@ This class represents a dialog that shows a list of strings, and allows the user 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. """ diff --git a/wxPython/demo/wxSlider.py b/wxPython/demo/wxSlider.py index 8cce5b131e..11284aa86a 100644 --- a/wxPython/demo/wxSlider.py +++ b/wxPython/demo/wxSlider.py @@ -1,19 +1,25 @@ +# 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) @@ -30,8 +36,13 @@ def runTest(frame, nb, log): 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__': diff --git a/wxPython/demo/wxSpinButton.py b/wxPython/demo/wxSpinButton.py index ed64a713e5..acbe912fb1 100644 --- a/wxPython/demo/wxSpinButton.py +++ b/wxPython/demo/wxSpinButton.py @@ -1,26 +1,32 @@ +# 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): @@ -36,18 +42,18 @@ def runTest(frame, nb, log): #---------------------------------------------------------------------- - - - - - - - - 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 diff --git a/wxPython/demo/wxSpinCtrl.py b/wxPython/demo/wxSpinCtrl.py index 2e57bca067..427be32326 100644 --- a/wxPython/demo/wxSpinCtrl.py +++ b/wxPython/demo/wxSpinCtrl.py @@ -1,18 +1,20 @@ +# 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) @@ -27,18 +29,21 @@ def runTest(frame, nb, log): #---------------------------------------------------------------------- +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 diff --git a/wxPython/demo/wxSplitterWindow.py b/wxPython/demo/wxSplitterWindow.py index 33359b3ba1..d25e626923 100644 --- a/wxPython/demo/wxSplitterWindow.py +++ b/wxPython/demo/wxSplitterWindow.py @@ -1,15 +1,19 @@ +# 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())) @@ -26,13 +30,13 @@ class MySplitter(wxSplitterWindow): 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) @@ -43,16 +47,12 @@ def runTest(frame, nb, log): #--------------------------------------------------------------------------- - - 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 diff --git a/wxPython/demo/wxStaticBitmap.py b/wxPython/demo/wxStaticBitmap.py index 7dfc51722b..2bfecf0433 100644 --- a/wxPython/demo/wxStaticBitmap.py +++ b/wxPython/demo/wxStaticBitmap.py @@ -1,29 +1,30 @@ +# 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)) #---------------------------------------------------------------------- @@ -34,15 +35,16 @@ def runTest(frame, nb, log): #---------------------------------------------------------------------- +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 diff --git a/wxPython/demo/wxStaticText.py b/wxPython/demo/wxStaticText.py index c40d886405..22874ef480 100644 --- a/wxPython/demo/wxStaticText.py +++ b/wxPython/demo/wxStaticText.py @@ -1,35 +1,41 @@ +# 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) #--------------------------------------------------------------------------- @@ -42,14 +48,12 @@ def runTest(frame, nb, log): #--------------------------------------------------------------------------- - overview = '''\ A static text control displays one or more lines of read-only text. ''' - if __name__ == '__main__': import sys,os import run diff --git a/wxPython/demo/wxStatusBar.py b/wxPython/demo/wxStatusBar.py index ac7dedd0f1..0d1cd90880 100644 --- a/wxPython/demo/wxStatusBar.py +++ b/wxPython/demo/wxStatusBar.py @@ -1,35 +1,44 @@ +# 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) @@ -63,23 +72,22 @@ class CustomStatusBar(wxStatusBar): # 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() @@ -96,21 +104,18 @@ def runTest(frame, nb, log): #--------------------------------------------------------------------------- - - - - - - - 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__': diff --git a/wxPython/demo/wxStyledTextCtrl_1.py b/wxPython/demo/wxStyledTextCtrl_1.py index 1f43c910cd..5eff81c883 100644 --- a/wxPython/demo/wxStyledTextCtrl_1.py +++ b/wxPython/demo/wxStyledTextCtrl_1.py @@ -1,8 +1,17 @@ +# 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 #---------------------------------------------------------------------- @@ -37,7 +46,7 @@ text works, as well as virtually unlimited Undo and Redo capabilities, (right click to try it out.) """ -if wxPlatform == '__WXMSW__': +if wx.Platform == '__WXMSW__': face1 = 'Arial' face2 = 'Times New Roman' face3 = 'Courier New' @@ -52,22 +61,22 @@ else: #---------------------------------------------------------------------- # 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() @@ -82,11 +91,15 @@ class MySTC(wxStyledTextCtrl): 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): @@ -97,11 +110,11 @@ class MySTC(wxStyledTextCtrl): 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... @@ -122,17 +135,17 @@ class MySTC(wxStyledTextCtrl): 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: @@ -156,10 +169,10 @@ def runTest(frame, nb, log): 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) @@ -170,7 +183,8 @@ def runTest(frame, nb, log): #ed.SetWrapMode(True) ed.SetText(demoText) - if wxUSE_UNICODE: + + if wx.USE_UNICODE: import codecs decode = codecs.lookup("utf-8")[1] @@ -186,7 +200,7 @@ def runTest(frame, nb, log): 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)) @@ -207,17 +221,17 @@ def runTest(frame, nb, log): # 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) @@ -228,17 +242,17 @@ def runTest(frame, nb, log): # 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... diff --git a/wxPython/demo/wxStyledTextCtrl_2.py b/wxPython/demo/wxStyledTextCtrl_2.py index 4c738fa00c..642ed9fd85 100644 --- a/wxPython/demo/wxStyledTextCtrl_2.py +++ b/wxPython/demo/wxStyledTextCtrl_2.py @@ -1,8 +1,14 @@ +# 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 #---------------------------------------------------------------------- @@ -16,7 +22,7 @@ demoText = """\ #---------------------------------------------------------------------- -if wxPlatform == '__WXMSW__': +if wx.Platform == '__WXMSW__': faces = { 'times': 'Times New Roman', 'mono' : 'Courier New', 'helv' : 'Arial', @@ -36,18 +42,18 @@ else: #---------------------------------------------------------------------- -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") @@ -58,26 +64,25 @@ class PythonSTC(wxStyledTextCtrl): #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 @@ -110,53 +115,54 @@ class PythonSTC(wxStyledTextCtrl): 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") @@ -167,14 +173,14 @@ class PythonSTC(wxStyledTextCtrl): 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") @@ -218,19 +224,21 @@ class PythonSTC(wxStyledTextCtrl): 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: @@ -253,7 +261,8 @@ class PythonSTC(wxStyledTextCtrl): 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) @@ -274,15 +283,16 @@ class PythonSTC(wxStyledTextCtrl): # 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) @@ -291,6 +301,7 @@ class PythonSTC(wxStyledTextCtrl): else: lastChild = self.GetLastChild(lineNum, -1) self.SetFoldExpanded(lineNum, False) + if lastChild > lineNum: self.HideLines(lineNum+1, lastChild) @@ -301,6 +312,7 @@ class PythonSTC(wxStyledTextCtrl): 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: @@ -314,12 +326,13 @@ class PythonSTC(wxStyledTextCtrl): 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: @@ -341,10 +354,10 @@ def runTest(frame, nb, log): 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) @@ -354,7 +367,7 @@ def runTest(frame, nb, log): 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 diff --git a/wxPython/demo/wxTextCtrl.py b/wxPython/demo/wxTextCtrl.py index 31f8a6d320..8c954a43b1 100644 --- a/wxPython/demo/wxTextCtrl.py +++ b/wxPython/demo/wxTextCtrl.py @@ -1,9 +1,14 @@ -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() @@ -16,72 +21,73 @@ class TestPanel(wxPanel): 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) @@ -105,8 +111,9 @@ class TestPanel(wxPanel): 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" % @@ -116,8 +123,10 @@ class TestPanel(wxPanel): 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" % @@ -128,7 +137,7 @@ class TestPanel(wxPanel): def OnT5LeftDown(self, evt): evt.Skip() - wxCallAfter(self.LogT5Position, evt) + wx.CallAfter(self.LogT5Position, evt) def LogT5Position(self, evt): text = self.t5.GetValue() @@ -151,12 +160,13 @@ def runTest(frame, nb, log): #--------------------------------------------------------------------------- - - 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__': diff --git a/wxPython/demo/wxTextEntryDialog.py b/wxPython/demo/wxTextEntryDialog.py index 3fd27aee90..3083749bd1 100644 --- a/wxPython/demo/wxTextEntryDialog.py +++ b/wxPython/demo/wxTextEntryDialog.py @@ -1,14 +1,22 @@ +# 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() @@ -16,13 +24,16 @@ def runTest(frame, nb, log): - 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__': diff --git a/wxPython/demo/wxTimeCtrl.py b/wxPython/demo/wxTimeCtrl.py index c92640c1d0..8acb1a5cb8 100644 --- a/wxPython/demo/wxTimeCtrl.py +++ b/wxPython/demo/wxTimeCtrl.py @@ -1,114 +1,136 @@ -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: @@ -123,17 +145,17 @@ class TestPanel( wxScrolledPanel ): 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 ) @@ -152,7 +174,7 @@ class TestPanel( wxScrolledPanel ): 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) ) @@ -179,7 +201,8 @@ class TestPanel( wxScrolledPanel ): def SetTargetMinMax( self, event=None ): - min = max = None + min = None + max = None if self.set_bounds.GetValue(): min = self.min.GetWxDateTime() @@ -189,13 +212,16 @@ class TestPanel( wxScrolledPanel ): 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: @@ -209,7 +235,7 @@ def runTest( frame, nb, log ): #---------------------------------------------------------------------- -overview = overviewdoc +overview = timectl.__doc__ if __name__ == '__main__': import sys,os diff --git a/wxPython/demo/wxTimer.py b/wxPython/demo/wxTimer.py index 0aa39e8ee1..7f71b1f442 100644 --- a/wxPython/demo/wxTimer.py +++ b/wxPython/demo/wxTimer.py @@ -1,10 +1,15 @@ +# 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) @@ -16,32 +21,30 @@ import time #--------------------------------------------------------------------------- -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) @@ -52,12 +55,12 @@ class TestTimerWin(wxPanel): 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') @@ -72,7 +75,8 @@ def runTest(frame, nb, log): 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. """ diff --git a/wxPython/demo/wxToggleButton.py b/wxPython/demo/wxToggleButton.py index 9e90ae9887..7beec9983a 100644 --- a/wxPython/demo/wxToggleButton.py +++ b/wxPython/demo/wxToggleButton.py @@ -1,24 +1,30 @@ +# 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) @@ -35,21 +41,23 @@ def runTest(frame, nb, log): 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. +""" diff --git a/wxPython/demo/wxToolBar.py b/wxPython/demo/wxToolBar.py index b80030b795..b609061504 100644 --- a/wxPython/demo/wxToolBar.py +++ b/wxPython/demo/wxToolBar.py @@ -1,27 +1,35 @@ +# 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()) @@ -29,43 +37,50 @@ class TestToolBar(wxFrame): 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() @@ -82,10 +97,13 @@ class TestToolBar(wxFrame): 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() @@ -113,16 +131,11 @@ def runTest(frame, nb, log): - - - overview = """\ """ - - if __name__ == '__main__': import sys,os import run diff --git a/wxPython/demo/wxTreeCtrl.py b/wxPython/demo/wxTreeCtrl.py index 5aeed4fa2f..547d05c87c 100644 --- a/wxPython/demo/wxTreeCtrl.py +++ b/wxPython/demo/wxTreeCtrl.py @@ -1,13 +1,17 @@ +# 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): @@ -20,27 +24,27 @@ class MyTreeCtrl(wxTreeCtrl): #--------------------------------------------------------------------------- -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) @@ -53,37 +57,39 @@ class TestTreeCtrlPanel(wxPanel): 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) @@ -108,13 +114,14 @@ class TestTreeCtrlPanel(wxPanel): 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), @@ -159,7 +166,7 @@ class TestTreeCtrlPanel(wxPanel): 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() @@ -184,7 +191,9 @@ def runTest(frame, nb, log): 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. """ diff --git a/wxPython/demo/wxTreeListCtrl.py b/wxPython/demo/wxTreeListCtrl.py index 2fb5fc370e..4015c0665f 100644 --- a/wxPython/demo/wxTreeListCtrl.py +++ b/wxPython/demo/wxTreeListCtrl.py @@ -1,26 +1,31 @@ +# 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) @@ -37,8 +42,8 @@ class TestPanel(wxPanel): 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): @@ -46,29 +51,29 @@ class TestPanel(wxPanel): 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): @@ -79,6 +84,7 @@ class TestPanel(wxPanel): 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) @@ -100,15 +106,13 @@ def runTest(frame, nb, log): overview = """

wxTreeListCtrl

-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. """ - - if __name__ == '__main__': #raw_input("Press enter...") import sys,os diff --git a/wxPython/demo/wxVListBox.py b/wxPython/demo/wxVListBox.py index 51faff85d9..b588fba1e0 100644 --- a/wxPython/demo/wxVListBox.py +++ b/wxPython/demo/wxVListBox.py @@ -1,26 +1,32 @@ +# 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 @@ -42,9 +48,9 @@ class MyVListBox(wxVListBox): #---------------------------------------------------------------------- -# 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: @@ -54,30 +60,30 @@ class MyHtmlListBox(wxHtmlListBox): #---------------------------------------------------------------------- -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)) diff --git a/wxPython/demo/wxValidator.py b/wxPython/demo/wxValidator.py index b2081d9510..755d9920fd 100644 --- a/wxPython/demo/wxValidator.py +++ b/wxPython/demo/wxValidator.py @@ -1,19 +1,22 @@ +# 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) @@ -21,6 +24,7 @@ class MyValidator(wxPyValidator): 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: @@ -36,18 +40,21 @@ class MyValidator(wxPyValidator): 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 @@ -55,13 +62,13 @@ class MyValidator(wxPyValidator): #---------------------------------------------------------------------- -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" @@ -69,26 +76,26 @@ class TestValidatorPanel(wxPanel): 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() @@ -100,14 +107,14 @@ class TestValidatorPanel(wxPanel): #---------------------------------------------------------------------- -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) @@ -126,14 +133,14 @@ class TextObjectValidator(wxPyValidator): 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 @@ -157,14 +164,14 @@ class TextObjectValidator(wxPyValidator): #---------------------------------------------------------------------- -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, @@ -174,26 +181,26 @@ class TestValidateDialog(wxDialog): 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) @@ -211,18 +218,21 @@ def runTest(frame, nb, log): 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. - + + +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. + + """ diff --git a/wxPython/demo/wxWave.py b/wxPython/demo/wxWave.py index 1ea3c4998b..b84e62148b 100644 --- a/wxPython/demo/wxWave.py +++ b/wxPython/demo/wxWave.py @@ -1,35 +1,39 @@ +# 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") #---------------------------------------------------------------------- @@ -41,10 +45,14 @@ def runTest(frame, nb, log): 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__': diff --git a/wxPython/demo/wxWizard.py b/wxPython/demo/wxWizard.py index 1b1211a6ad..7c7d5d80f6 100644 --- a/wxPython/demo/wxWizard.py +++ b/wxPython/demo/wxWizard.py @@ -1,38 +1,45 @@ - -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 @@ -44,7 +51,7 @@ class SkipNextPage(wxPyWizardPage): # 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""" @@ -58,14 +65,14 @@ class SkipNextPage(wxPyWizardPage): #---------------------------------------------------------------------- -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 @@ -91,23 +98,22 @@ class UseAltBitmapPage(wxPyWizardPage): #---------------------------------------------------------------------- -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): @@ -115,6 +121,7 @@ class TestPanel(wxPanel): dir = "forward" else: dir = "backward" + page = evt.GetPage() self.log.write("OnWizPageChanged: %s, %s\n" % (dir, page.__class__)) @@ -124,6 +131,7 @@ class TestPanel(wxPanel): dir = "forward" else: dir = "backward" + page = evt.GetPage() self.log.write("OnWizPageChanging: %s, %s\n" % (dir, page.__class__)) @@ -135,7 +143,7 @@ class TestPanel(wxPanel): # 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): @@ -144,7 +152,7 @@ class TestPanel(wxPanel): 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") @@ -152,33 +160,33 @@ class TestPanel(wxPanel): 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") @@ -188,12 +196,12 @@ wxWizardPageSimple class can easily be used for the pages.""")) 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) @@ -207,9 +215,9 @@ of the pages and also which bitmap is shown. 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!") #---------------------------------------------------------------------- diff --git a/wxPython/demo/wxXmlResource.py b/wxPython/demo/wxXmlResource.py index 839a9cff1d..208e229eac 100644 --- a/wxPython/demo/wxXmlResource.py +++ b/wxPython/demo/wxXmlResource.py @@ -1,42 +1,47 @@ +# 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) @@ -44,11 +49,11 @@ class TestPanel(wxPanel): 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) @@ -68,7 +73,6 @@ overview = """ """ - if __name__ == '__main__': import sys,os import run diff --git a/wxPython/demo/wxXmlResourceHandler.py b/wxPython/demo/wxXmlResourceHandler.py index 1c078d95c1..2098c5da41 100644 --- a/wxPython/demo/wxXmlResourceHandler.py +++ b/wxPython/demo/wxXmlResourceHandler.py @@ -1,6 +1,16 @@ - -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 #---------------------------------------------------------------------- @@ -11,8 +21,8 @@ resourceText = r''' 200,100 - - + + 10,10 @@ -21,9 +31,9 @@ resourceText = r''' #---------------------------------------------------------------------- -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 @@ -36,27 +46,27 @@ class MyBluePanel(wxPanel): # 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 @@ -90,7 +100,7 @@ class MyBluePanelXmlHandler(wxXmlResourceHandler): self.GetID(), self.GetPosition(), self.GetSize(), - self.GetStyle("style", wxTAB_TRAVERSAL), + self.GetStyle("style", wx.TAB_TRAVERSAL), self.GetName() ) else: @@ -106,7 +116,7 @@ class MyBluePanelXmlHandler(wxXmlResourceHandler): self.GetID(), self.GetPosition(), self.GetSize(), - self.GetStyle("style", wxTAB_TRAVERSAL), + self.GetStyle("style", wx.TAB_TRAVERSAL), self.GetName() ) @@ -122,23 +132,23 @@ class MyBluePanelXmlHandler(wxXmlResourceHandler): #---------------------------------------------------------------------- -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) @@ -146,11 +156,11 @@ class TestPanel(wxPanel): 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) diff --git a/wxPython/demo/wxXmlResourceSubclass.py b/wxPython/demo/wxXmlResourceSubclass.py index e3dce189f1..f587ba9275 100644 --- a/wxPython/demo/wxXmlResourceSubclass.py +++ b/wxPython/demo/wxXmlResourceSubclass.py @@ -1,6 +1,10 @@ +# 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 #---------------------------------------------------------------------- @@ -24,12 +28,12 @@ and is loaded by a using a subclass attribute of the object tag. #---------------------------------------------------------------------- -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 @@ -42,34 +46,34 @@ class MyBluePanel(wxPanel): #---------------------------------------------------------------------- -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) -- 2.45.2