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 *
16 from wxPython
.lib
.splashscreen
import SplashScreen
18 #---------------------------------------------------------------------------
21 _useNestedSplitter
= true
24 ('New since last release', ['wxMVCTree', 'wxVTKRenderWindow',
25 'FileBrowseButton', 'GenericButtons',
28 ('Managed Windows', ['wxFrame', 'wxDialog', 'wxMiniFrame']),
30 ('Non-Managed Windows', ['wxGrid', 'wxSashWindow',
31 'wxScrolledWindow', 'wxSplitterWindow',
32 'wxStatusBar', 'wxNotebook',
35 ('Common Dialogs', ['wxColourDialog', 'wxDirDialog', 'wxFileDialog',
36 'wxSingleChoiceDialog', 'wxTextEntryDialog',
37 'wxFontDialog', 'wxPageSetupDialog', 'wxPrintDialog',
38 'wxMessageDialog', 'wxProgressDialog']),
40 ('Controls', ['wxButton', 'wxCheckBox', 'wxCheckListBox', 'wxChoice',
41 'wxComboBox', 'wxGauge', 'wxListBox', 'wxListCtrl', 'wxTextCtrl',
42 'wxTreeCtrl', 'wxSpinButton', 'wxStaticText', 'wxStaticBitmap',
43 'wxRadioBox', 'wxSlider', 'wxToolBar', #'wxToggleButton'
46 ('Window Layout', ['wxLayoutConstraints', 'Sizers', 'OldSizers']),
48 ('Miscellaneous', [ 'DragAndDrop', 'CustomDragAndDrop', 'FontEnumerator',
49 'wxTimer', 'wxValidator', 'wxGLCanvas', 'DialogUnits',
50 'wxImage', 'wxMask', 'PrintFramework', 'wxOGL',
51 'PythonEvents', 'Threads']),
53 ('wxPython Library', ['Layoutf', 'wxScrolledMessageDialog',
54 'wxMultipleChoiceDialog', 'wxPlotCanvas', 'wxFloatBar',
55 'PyShell', 'wxCalendar', 'wxMVCTree', 'wxVTKRenderWindow',
56 'FileBrowseButton', 'GenericButtons']),
58 ('Cool Contribs', ['pyTree', 'hangman', 'SlashDot', 'XMLtreeview']),
62 #---------------------------------------------------------------------------
64 class wxPythonDemo(wxFrame
):
65 def __init__(self
, parent
, id, title
):
66 wxFrame
.__init
__(self
, parent
, -1, title
, size
= (725, 550))
68 self
.cwd
= os
.getcwd()
70 if wxPlatform
== '__WXMSW__':
71 self
.icon
= wxIcon('bitmaps/mondrian.ico', wxBITMAP_TYPE_ICO
)
72 self
.SetIcon(self
.icon
)
75 EVT_IDLE(self
, self
.OnIdle
)
78 self
.CreateStatusBar(1, wxST_SIZEGRIP
)
81 splitter
= wxSplitterWindow(self
, -1)
82 if _useNestedSplitter
:
83 splitter2
= wxSplitterWindow(splitter
, -1)
84 logParent
= nbParent
= splitter2
87 logParent
= wxFrame(self
, -1, "wxPython Demo: log window",
92 logParent
= wxFrame(self
, -1, "wxPython Demo: log window",
98 # Prevent TreeCtrl from displaying all items after destruction
102 self
.mainmenu
= wxMenuBar()
105 menu
.Append(exitID
, 'E&xit\tAlt-X', 'Get the heck outta here!')
106 EVT_MENU(self
, exitID
, self
.OnFileExit
)
107 self
.mainmenu
.Append(menu
, '&File')
111 for item
in _treeList
:
113 for childItem
in item
[1]:
115 submenu
.Append(mID
, childItem
)
116 EVT_MENU(self
, mID
, self
.OnDemoMenu
)
117 menu
.AppendMenu(wxNewId(), item
[0], submenu
)
118 self
.mainmenu
.Append(menu
, '&Demo')
124 menu
.Append(helpID
, '&About\tCtrl-H', 'wxPython RULES!!!')
125 EVT_MENU(self
, helpID
, self
.OnHelpAbout
)
126 self
.mainmenu
.Append(menu
, '&Help')
127 self
.SetMenuBar(self
.mainmenu
)
129 # set the menu accellerator table...
130 aTable
= wxAcceleratorTable([(wxACCEL_ALT
, ord('X'), exitID
),
131 (wxACCEL_CTRL
, ord('H'), helpID
)])
132 self
.SetAcceleratorTable(aTable
)
139 self
.tree
= wxTreeCtrl(splitter
, tID
)
140 root
= self
.tree
.AddRoot("Overview")
142 for item
in _treeList
:
143 child
= self
.tree
.AppendItem(root
, item
[0])
144 if not firstChild
: firstChild
= child
145 for childItem
in item
[1]:
146 theDemo
= self
.tree
.AppendItem(child
, childItem
)
147 self
.treeMap
[childItem
] = theDemo
149 self
.tree
.Expand(root
)
150 self
.tree
.Expand(firstChild
)
151 EVT_TREE_ITEM_EXPANDED (self
.tree
, tID
, self
.OnItemExpanded
)
152 EVT_TREE_ITEM_COLLAPSED (self
.tree
, tID
, self
.OnItemCollapsed
)
153 EVT_TREE_SEL_CHANGED (self
.tree
, tID
, self
.OnSelChanged
)
156 self
.nb
= wxNotebook(nbParent
, -1)
158 # Set up a TextCtrl on the Overview Notebook page
159 self
.ovr
= wxTextCtrl(self
.nb
, -1, style
= wxTE_MULTILINE|wxTE_READONLY
)
160 self
.nb
.AddPage(self
.ovr
, "Overview")
163 # Set up a TextCtrl on the Demo Code Notebook page
164 self
.txt
= wxTextCtrl(self
.nb
, -1,
165 style
= wxTE_MULTILINE|wxTE_READONLY|wxHSCROLL
)
166 self
.txt
.SetFont(wxFont(9, wxMODERN
, wxNORMAL
, wxNORMAL
, false
))
167 self
.nb
.AddPage(self
.txt
, "Demo Code")
170 # Set up a log on the View Log Notebook page
171 self
.log
= wxTextCtrl(logParent
, -1,
172 style
= wxTE_MULTILINE|wxTE_READONLY|wxHSCROLL
)
173 (w
, self
.charHeight
) = self
.log
.GetTextExtent('X')
174 self
.WriteText('wxPython Demo Log:\n')
178 # add the windows to the splitter and split it.
180 if _useNestedSplitter
:
181 splitter2
.SplitHorizontally(self
.nb
, self
.log
)
182 splitter2
.SetSashPosition(360, true
)
183 splitter2
.SetMinimumPaneSize(20)
185 splitter
.SplitVertically(self
.tree
, splitter2
)
187 splitter
.SplitVertically(self
.tree
, self
.nb
)
189 splitter
.SetSashPosition(180, true
)
190 splitter
.SetMinimumPaneSize(20)
193 # make our log window be stdout
196 # select initial items
197 self
.nb
.SetSelection(0)
199 self
.tree
.SelectItem(root
)
201 if len(sys
.argv
) == 2:
203 selectedDemo
= self
.treeMap
[sys
.argv
[1]]
206 if selectedDemo
and _useSplitter
:
207 self
.tree
.SelectItem(selectedDemo
)
208 self
.tree
.EnsureVisible(selectedDemo
)
211 self
.WriteText('window handle: %s\n' % self
.GetHandle())
214 #---------------------------------------------
215 def WriteText(self
, text
):
216 self
.log
.WriteText(text
)
217 w
, h
= self
.log
.GetClientSizeTuple()
218 numLines
= h
/self
.charHeight
219 x
, y
= self
.log
.PositionToXY(self
.log
.GetLastPosition())
221 self
.log
.ShowPosition(self
.log
.XYToPosition(x
, y
-numLines
))
222 ##self.log.ShowPosition(self.log.GetLastPosition())
223 self
.log
.SetInsertionPointEnd()
225 def write(self
, txt
):
228 #---------------------------------------------
229 def OnItemExpanded(self
, event
):
230 item
= event
.GetItem()
231 self
.log
.WriteText("OnItemExpanded: %s\n" % self
.tree
.GetItemText(item
))
233 #---------------------------------------------
234 def OnItemCollapsed(self
, event
):
235 item
= event
.GetItem()
236 self
.log
.WriteText("OnItemCollapsed: %s\n" % self
.tree
.GetItemText(item
))
238 #---------------------------------------------
239 def OnSelChanged(self
, event
):
243 item
= event
.GetItem()
244 itemText
= self
.tree
.GetItemText(item
)
245 self
.RunDemo(itemText
)
248 #---------------------------------------------
249 def RunDemo(self
, itemText
):
251 if self
.nb
.GetPageCount() == 3:
252 if self
.nb
.GetSelection() == 2:
253 self
.nb
.SetSelection(0)
254 self
.nb
.DeletePage(2)
256 if itemText
== 'Overview':
257 self
.GetDemoFile('Main.py')
258 self
.SetOverview('Overview', overview
)
263 if os
.path
.exists(itemText
+ '.py'):
265 self
.GetDemoFile(itemText
+ '.py')
266 module
= __import__(itemText
, globals())
267 self
.SetOverview(itemText
, module
.overview
)
270 # in case runTest is modal, make sure things look right...
274 self
.window
= module
.runTest(self
, self
.nb
, self
)
276 self
.nb
.AddPage(self
.window
, 'Demo')
277 #self.nb.ResizeChildren()
278 self
.nb
.SetSelection(2)
279 #self.nb.ResizeChildren()
280 #if self.window.GetAutoLayout():
281 # self.window.Layout()
290 #---------------------------------------------
292 def GetDemoFile(self
, filename
):
294 #if not self.txt.LoadFile(filename):
295 # self.txt.WriteText("Cannot open %s file." % filename)
297 self
.txt
.SetValue(open(filename
).read())
299 self
.txt
.WriteText("Cannot open %s file." % filename
)
302 self
.txt
.SetInsertionPoint(0)
303 self
.txt
.ShowPosition(0)
305 #---------------------------------------------
306 def SetOverview(self
, name
, text
):
308 self
.ovr
.WriteText(text
)
309 self
.nb
.SetPageText(0, name
)
310 self
.ovr
.SetInsertionPoint(0)
311 self
.ovr
.ShowPosition(0)
313 #---------------------------------------------
315 def OnFileExit(self
, event
):
319 def OnHelpAbout(self
, event
):
320 #about = wxMessageDialog(self,
321 # "wxPython is a Python extension module that\n"
322 # "encapsulates the wxWindows GUI classes.\n\n"
323 # "This demo shows off some of the capabilities\n"
325 # " Developed by Robin Dunn",
326 # "About wxPython", wxOK)
327 from About
import MyAboutBox
328 about
= MyAboutBox(self
)
333 #---------------------------------------------
334 def OnCloseWindow(self
, event
):
340 #---------------------------------------------
341 def OnIdle(self
, event
):
343 self
.otherWin
.Raise()
344 self
.window
= self
.otherWin
347 #---------------------------------------------
348 def OnDemoMenu(self
, event
):
351 selectedDemo
= self
.treeMap
[self
.mainmenu
.GetLabel(event
.GetId())]
355 self
.tree
.SelectItem(selectedDemo
)
356 self
.tree
.EnsureVisible(selectedDemo
)
358 self
.RunDemo(self
.mainmenu
.GetLabel(event
.GetId()))
360 #---------------------------------------------------------------------------
361 #---------------------------------------------------------------------------
365 wxImage_AddHandler(wxJPEGHandler())
366 wxImage_AddHandler(wxPNGHandler())
367 wxImage_AddHandler(wxGIFHandler())
369 self
.splash
= SplashScreen(None, bitmapfile
='bitmaps/splash.gif',
370 duration
=4000, callback
=self
.AfterSplash
)
371 self
.splash
.Show(true
)
375 def AfterSplash(self
):
376 self
.splash
.Close(true
)
377 frame
= wxPythonDemo(None, -1, "wxPython: (A Demonstration)")
379 self
.SetTopWindow(frame
)
382 #---------------------------------------------------------------------------
389 #---------------------------------------------------------------------------
397 Python is an interpreted, interactive, object-oriented programming language often compared to Tcl, Perl, Scheme, or Java.
399 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.
404 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.
406 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.
411 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.
413 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.
415 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.
417 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.
426 #----------------------------------------------------------------------------
427 #----------------------------------------------------------------------------
429 if __name__
== '__main__':
432 #----------------------------------------------------------------------------