2 #----------------------------------------------------------------------------
4 # Purpose: Testing lots of stuff, controls, window types, etc.
6 # Author: Robin Dunn & Gary Dumer
10 # Copyright: (c) 1999 by Total Control Software
11 # Licence: wxWindows license
12 #----------------------------------------------------------------------------
15 from wxPython
.wx
import *
18 #---------------------------------------------------------------------------
21 _useNestedSplitter
= true
24 ('Managed Windows', ['wxFrame', 'wxDialog', 'wxMiniFrame']),
26 ('Miscellaneous Windows', ['wxGrid', 'wxSashWindow',
27 'wxScrolledWindow', 'wxSplitterWindow',
28 'wxStatusBar', 'wxToolBar', 'wxNotebook',
31 ('Common Dialogs', ['wxColourDialog', 'wxDirDialog', 'wxFileDialog',
32 'wxSingleChoiceDialog', 'wxTextEntryDialog',
33 'wxFontDialog', 'wxPageSetupDialog', 'wxPrintDialog',
34 'wxMessageDialog', 'wxProgressDialog']),
36 ('Controls', ['wxButton', 'wxCheckBox', 'wxCheckListBox', 'wxChoice',
37 'wxComboBox', 'wxGauge', 'wxListBox', 'wxListCtrl', 'wxTextCtrl',
38 'wxTreeCtrl', 'wxSpinButton', 'wxStaticText', 'wxStaticBitmap',
39 'wxRadioBox', 'wxSlider']),
41 ('Window Layout', ['wxLayoutConstraints', 'Sizers', 'OldSizers']),
43 ('Miscellaneous', ['wxTimer', 'wxValidator', 'wxGLCanvas', 'DialogUnits',
44 'wxImage', 'PrintFramework', 'wxOGL']),
46 ('wxPython Library', ['OldSizers', 'Layoutf', 'wxScrolledMessageDialog',
47 'wxMultipleChoiceDialog', 'wxPlotCanvas', 'wxFloatBar',
50 ('Cool Contribs', ['pyTree', 'hangman', 'SlashDot', 'XMLtreeview']),
54 #---------------------------------------------------------------------------
56 class wxPythonDemo(wxFrame
):
57 def __init__(self
, parent
, id, title
):
58 wxFrame
.__init
__(self
, parent
, -1, title
, size
= (725, 550))
60 if wxPlatform
== '__WXMSW__':
61 self
.icon
= wxIcon('bitmaps/mondrian.ico', wxBITMAP_TYPE_ICO
)
62 self
.SetIcon(self
.icon
)
65 EVT_IDLE(self
, self
.OnIdle
)
68 self
.CreateStatusBar(1, wxST_SIZEGRIP
)
71 splitter
= wxSplitterWindow(self
, -1)
72 if _useNestedSplitter
:
73 splitter2
= wxSplitterWindow(splitter
, -1)
74 logParent
= nbParent
= splitter2
77 logParent
= wxFrame(self
, -1, "wxPython Demo: log window",
82 logParent
= wxFrame(self
, -1, "wxPython Demo: log window",
88 # Prevent TreeCtrl from displaying all items after destruction
92 self
.mainmenu
= wxMenuBar()
95 menu
.Append(exitID
, 'E&xit\tAlt-X', 'Get the heck outta here!')
96 EVT_MENU(self
, exitID
, self
.OnFileExit
)
97 self
.mainmenu
.Append(menu
, '&File')
101 for item
in _treeList
:
103 for childItem
in item
[1]:
105 submenu
.Append(mID
, childItem
)
106 EVT_MENU(self
, mID
, self
.OnDemoMenu
)
107 menu
.AppendMenu(wxNewId(), item
[0], submenu
)
108 self
.mainmenu
.Append(menu
, '&Demo')
114 menu
.Append(helpID
, '&About\tCtrl-H', 'wxPython RULES!!!')
115 EVT_MENU(self
, helpID
, self
.OnHelpAbout
)
116 self
.mainmenu
.Append(menu
, '&Help')
117 self
.SetMenuBar(self
.mainmenu
)
119 # set the menu accellerator table...
120 aTable
= wxAcceleratorTable([(wxACCEL_ALT
, ord('X'), exitID
),
121 (wxACCEL_CTRL
, ord('H'), helpID
)])
122 self
.SetAcceleratorTable(aTable
)
129 self
.tree
= wxTreeCtrl(splitter
, tID
)
130 root
= self
.tree
.AddRoot("Overview")
131 for item
in _treeList
:
132 child
= self
.tree
.AppendItem(root
, item
[0])
133 for childItem
in item
[1]:
134 theDemo
= self
.tree
.AppendItem(child
, childItem
)
135 self
.treeMap
[childItem
] = theDemo
137 self
.tree
.Expand(root
)
138 EVT_TREE_ITEM_EXPANDED (self
.tree
, tID
, self
.OnItemExpanded
)
139 EVT_TREE_ITEM_COLLAPSED (self
.tree
, tID
, self
.OnItemCollapsed
)
140 EVT_TREE_SEL_CHANGED (self
.tree
, tID
, self
.OnSelChanged
)
143 self
.nb
= wxNotebook(nbParent
, -1)
145 # Set up a TextCtrl on the Overview Notebook page
146 self
.ovr
= wxTextCtrl(self
.nb
, -1, style
= wxTE_MULTILINE|wxTE_READONLY
)
147 self
.nb
.AddPage(self
.ovr
, "Overview")
150 # Set up a TextCtrl on the Demo Code Notebook page
151 self
.txt
= wxTextCtrl(self
.nb
, -1,
152 style
= wxTE_MULTILINE|wxTE_READONLY|wxHSCROLL
)
153 self
.txt
.SetFont(wxFont(9, wxMODERN
, wxNORMAL
, wxNORMAL
, false
))
154 self
.nb
.AddPage(self
.txt
, "Demo Code")
157 # Set up a log on the View Log Notebook page
158 self
.log
= wxTextCtrl(logParent
, -1,
159 style
= wxTE_MULTILINE|wxTE_READONLY|wxHSCROLL
)
160 (w
, self
.charHeight
) = self
.log
.GetTextExtent('X')
161 self
.WriteText('wxPython Demo Log:\n')
164 # add the windows to the splitter and split it.
166 if _useNestedSplitter
:
167 splitter2
.SplitHorizontally(self
.nb
, self
.log
)
168 splitter2
.SetSashPosition(360, true
)
169 splitter2
.SetMinimumPaneSize(20)
171 splitter
.SplitVertically(self
.tree
, splitter2
)
173 splitter
.SplitVertically(self
.tree
, self
.nb
)
175 splitter
.SetSashPosition(180, true
)
176 splitter
.SetMinimumPaneSize(20)
179 # make our log window be stdout
182 # select initial items
183 self
.nb
.SetSelection(0)
185 self
.tree
.SelectItem(root
)
187 if len(sys
.argv
) == 2:
189 selectedDemo
= self
.treeMap
[sys
.argv
[1]]
192 if selectedDemo
and _useSplitter
:
193 self
.tree
.SelectItem(selectedDemo
)
194 self
.tree
.EnsureVisible(selectedDemo
)
197 #---------------------------------------------
198 def WriteText(self
, text
):
199 self
.log
.WriteText(text
)
200 w
, h
= self
.log
.GetClientSizeTuple()
201 numLines
= h
/self
.charHeight
202 x
, y
= self
.log
.PositionToXY(self
.log
.GetLastPosition())
204 self
.log
.ShowPosition(self
.log
.XYToPosition(x
, y
-numLines
))
205 ##self.log.ShowPosition(self.log.GetLastPosition())
206 self
.log
.SetInsertionPointEnd()
208 def write(self
, txt
):
211 #---------------------------------------------
212 def OnItemExpanded(self
, event
):
213 item
= event
.GetItem()
214 self
.log
.WriteText("OnItemExpanded: %s\n" % self
.tree
.GetItemText(item
))
216 #---------------------------------------------
217 def OnItemCollapsed(self
, event
):
218 item
= event
.GetItem()
219 self
.log
.WriteText("OnItemCollapsed: %s\n" % self
.tree
.GetItemText(item
))
221 #---------------------------------------------
222 def OnSelChanged(self
, event
):
226 item
= event
.GetItem()
227 itemText
= self
.tree
.GetItemText(item
)
228 self
.RunDemo(itemText
)
231 #---------------------------------------------
232 def RunDemo(self
, itemText
):
233 if self
.nb
.GetPageCount() == 3:
234 if self
.nb
.GetSelection() == 2:
235 self
.nb
.SetSelection(0)
236 self
.nb
.DeletePage(2)
238 if itemText
== 'Overview':
239 self
.GetDemoFile('Main.py')
240 self
.SetOverview('Overview', overview
)
245 if os
.path
.exists(itemText
+ '.py'):
246 self
.GetDemoFile(itemText
+ '.py')
247 module
= __import__(itemText
, globals())
248 self
.SetOverview(itemText
, module
.overview
)
250 # in case runTest is modal, make sure things look right...
254 self
.window
= module
.runTest(self
, self
.nb
, self
)
256 self
.nb
.AddPage(self
.window
, 'Demo')
257 #self.nb.ResizeChildren()
258 self
.nb
.SetSelection(2)
259 self
.nb
.ResizeChildren()
260 #if self.window.GetAutoLayout():
261 # self.window.Layout()
270 #---------------------------------------------
272 def GetDemoFile(self
, filename
):
274 #if not self.txt.LoadFile(filename):
275 # self.txt.WriteText("Cannot open %s file." % filename)
277 self
.txt
.SetValue(open(filename
).read())
279 self
.txt
.WriteText("Cannot open %s file." % filename
)
282 self
.txt
.SetInsertionPoint(0)
283 self
.txt
.ShowPosition(0)
285 #---------------------------------------------
286 def SetOverview(self
, name
, text
):
288 self
.ovr
.WriteText(text
)
289 self
.nb
.SetPageText(0, name
)
290 self
.ovr
.SetInsertionPoint(0)
291 self
.ovr
.ShowPosition(0)
293 #---------------------------------------------
295 def OnFileExit(self
, event
):
299 def OnHelpAbout(self
, event
):
300 #about = wxMessageDialog(self,
301 # "wxPython is a Python extension module that\n"
302 # "encapsulates the wxWindows GUI classes.\n\n"
303 # "This demo shows off some of the capabilities\n"
305 # " Developed by Robin Dunn",
306 # "About wxPython", wxOK)
307 from About
import MyAboutBox
308 about
= MyAboutBox(self
)
313 #---------------------------------------------
314 def OnCloseWindow(self
, event
):
320 #---------------------------------------------
321 def OnIdle(self
, event
):
323 self
.otherWin
.Raise()
324 self
.window
= self
.otherWin
327 #---------------------------------------------
328 def OnDemoMenu(self
, event
):
331 selectedDemo
= self
.treeMap
[self
.mainmenu
.GetLabel(event
.GetId())]
335 self
.tree
.SelectItem(selectedDemo
)
336 self
.tree
.EnsureVisible(selectedDemo
)
338 self
.RunDemo(self
.mainmenu
.GetLabel(event
.GetId()))
340 #---------------------------------------------------------------------------
341 #---------------------------------------------------------------------------
345 wxImage_AddHandler(wxJPEGHandler())
346 wxImage_AddHandler(wxPNGHandler())
347 wxImage_AddHandler(wxGIFHandler())
348 frame
= wxPythonDemo(NULL
, -1, "wxPython: (A Demonstration)")
350 self
.SetTopWindow(frame
)
353 #---------------------------------------------------------------------------
360 #---------------------------------------------------------------------------
368 Python is an interpreted, interactive, object-oriented programming language often compared to Tcl, Perl, Scheme, or Java.
370 Python combines remarkable power with very clear syntax. It has modules, classes, exceptions, very high level dynamic data types, and dynamic typing. There are interfaces to many system calls and libraries, and new built-in modules are easily written in C or C++. Python is also usable as an extension language for applications that need a programmable interface.
375 wxWindows is a free C++ framework designed to make cross-platform programming child's play. Well, almost. wxWindows 2 supports Windows 3.1/95/98/NT, Unix with GTK/Motif/Lesstif, with a Mac version underway. Other ports are under consideration.
377 wxWindows is a set of libraries that allows C++ applications to compile and run on several different types of computers, with minimal source code changes. There is one library per supported GUI (such as Motif, or Windows). As well as providing a common API (Application Programming Interface) for GUI functionality, it provides functionality for accessing some commonly-used operating system facilities, such as copying or deleting files. wxWindows is a 'framework' in the sense that it provides a lot of built-in functionality, which the application can use or replace as required, thus saving a great deal of coding effort. Basic data structures such as strings, linked lists and hash tables are also supported.
382 wxPython is a Python extension module that encapsulates the wxWindows GUI classes. Currently it is only available for the Win32 and GTK ports of wxWindows, but as soon as the other ports are brought up to the same level as Win32 and GTK, it should be fairly trivial to enable wxPython to be used with the new GUI.
384 The wxPython extension module attempts to mirror the class heiarchy of wxWindows as closely as possible. This means that there is a wxFrame class in wxPython that looks, smells, tastes and acts almost the same as the wxFrame class in the C++ version. Unfortunately, because of differences in the languages, wxPython doesn't match wxWindows exactly, but the differences should be easy to absorb because they are natural to Python. For example, some methods that return multiple values via argument pointers in C++ will return a tuple of values in Python.
386 There is still much to be done for wxPython, many classes still need to be mirrored. Also, wxWindows is still somewhat of a moving target so it is a bit of an effort just keeping wxPython up to date. On the other hand, there are enough of the core classes completed that useful applications can be written.
388 wxPython is close enough to the C++ version that the majority of the wxPython documentation is actually just notes attached to the C++ documents that describe the places where wxPython is different. There is also a series of sample programs included, and a series of documentation pages that assist the programmer in getting started with wxPython.
397 #----------------------------------------------------------------------------
398 #----------------------------------------------------------------------------
400 if __name__
== '__main__':
403 #----------------------------------------------------------------------------