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 #---------------------------------------------------------------------------
22 ('Managed Windows', ['wxFrame', 'wxDialog', 'wxMiniFrame']),
24 ('Miscellaneous Windows', ['wxGrid', 'wxSashWindow',
25 'wxScrolledWindow', 'wxSplitterWindow',
26 'wxStatusBar', 'wxToolBar', 'wxNotebook',
29 ('Common Dialogs', ['wxColourDialog', 'wxDirDialog', 'wxFileDialog',
30 'wxSingleChoiceDialog', 'wxTextEntryDialog',
31 'wxFontDialog', 'wxPageSetupDialog', 'wxPrintDialog',
32 'wxMessageDialog', 'wxProgressDialog']),
34 ('Controls', ['wxButton', 'wxCheckBox', 'wxCheckListBox', 'wxChoice',
35 'wxComboBox', 'wxGauge', 'wxListBox', 'wxListCtrl', 'wxTextCtrl',
36 'wxTreeCtrl', 'wxSpinButton', 'wxStaticText', 'wxStaticBitmap',
37 'wxRadioBox', 'wxSlider']),
39 ('Window Layout', ['wxLayoutConstraints', 'Sizers']),
41 ('Miscellaneous', ['wxTimer', 'wxGLCanvas', 'DialogUnits', 'wxImage',
42 'PrintFramework', 'wxOGL']),
44 ('wxPython Library', ['Sizers', 'Layoutf', 'wxScrolledMessageDialog',
45 'wxMultipleChoiceDialog', 'wxPlotCanvas']),
47 ('Cool Contribs', ['pyTree', 'hangman', 'SlashDot', 'XMLtreeview']),
51 #---------------------------------------------------------------------------
53 class wxPythonDemo(wxFrame
):
54 def __init__(self
, parent
, id, title
):
55 wxFrame
.__init
__(self
, parent
, -1, title
,
56 wxDefaultPosition
, wxSize(700, 550))
57 if wxPlatform
== '__WXMSW__':
58 self
.icon
= wxIcon('bitmaps/mondrian.ico', wxBITMAP_TYPE_ICO
)
59 self
.SetIcon(self
.icon
)
62 EVT_IDLE(self
, self
.OnIdle
)
65 self
.CreateStatusBar(1, wxST_SIZEGRIP
)
66 splitter
= wxSplitterWindow(self
, -1)
67 splitter2
= wxSplitterWindow(splitter
, -1)
69 # Prevent TreeCtrl from displaying all items after destruction
73 self
.mainmenu
= wxMenuBar()
76 menu
.Append(mID
, 'E&xit', 'Get the heck outta here!')
77 EVT_MENU(self
, mID
, self
.OnFileExit
)
78 self
.mainmenu
.Append(menu
, '&File')
82 for item
in _treeList
:
84 for childItem
in item
[1]:
86 submenu
.Append(mID
, childItem
)
87 EVT_MENU(self
, mID
, self
.OnDemoMenu
)
88 menu
.AppendMenu(wxNewId(), item
[0], submenu
)
89 self
.mainmenu
.Append(menu
, '&Demo')
95 menu
.Append(mID
, '&About', 'wxPython RULES!!!')
96 EVT_MENU(self
, mID
, self
.OnHelpAbout
)
97 self
.mainmenu
.Append(menu
, '&Help')
98 self
.SetMenuBar(self
.mainmenu
)
104 self
.tree
= wxTreeCtrl(splitter
, tID
)
105 root
= self
.tree
.AddRoot("Overview")
106 for item
in _treeList
:
107 child
= self
.tree
.AppendItem(root
, item
[0])
108 for childItem
in item
[1]:
109 theDemo
= self
.tree
.AppendItem(child
, childItem
)
110 self
.treeMap
[childItem
] = theDemo
112 self
.tree
.Expand(root
)
113 EVT_TREE_ITEM_EXPANDED (self
.tree
, tID
, self
.OnItemExpanded
)
114 EVT_TREE_ITEM_COLLAPSED (self
.tree
, tID
, self
.OnItemCollapsed
)
115 EVT_TREE_SEL_CHANGED (self
.tree
, tID
, self
.OnSelChanged
)
118 self
.nb
= wxNotebook(splitter2
, -1)
120 # Set up a TextCtrl on the Overview Notebook page
121 self
.ovr
= wxTextCtrl(self
.nb
, -1, style
= wxTE_MULTILINE|wxTE_READONLY
)
122 self
.nb
.AddPage(self
.ovr
, "Overview")
125 # Set up a TextCtrl on the Demo Code Notebook page
126 self
.txt
= wxTextCtrl(self
.nb
, -1,
127 style
= wxTE_MULTILINE|wxTE_READONLY|wxHSCROLL
)
128 self
.txt
.SetFont(wxFont(9, wxMODERN
, wxNORMAL
, wxNORMAL
, false
))
129 self
.nb
.AddPage(self
.txt
, "Demo Code")
132 # Set up a log on the View Log Notebook page
133 self
.log
= wxTextCtrl(splitter2
, -1,
134 style
= wxTE_MULTILINE|wxTE_READONLY|wxHSCROLL
)
135 (w
, self
.charHeight
) = self
.log
.GetTextExtent('X')
136 #self.WriteText('wxPython Demo Log:\n')
139 # add the windows to the splitter and split it.
140 splitter
.SplitVertically(self
.tree
, splitter2
)
141 splitter
.SetSashPosition(180, true
)
142 splitter
.SetMinimumPaneSize(20)
144 splitter2
.SplitHorizontally(self
.nb
, self
.log
)
145 splitter2
.SetSashPosition(360, true
)
146 splitter2
.SetMinimumPaneSize(20)
148 # make our log window be stdout
151 # select initial items
152 self
.nb
.SetSelection(0)
153 self
.tree
.SelectItem(root
)
155 if len(sys
.argv
) == 2:
157 selectedDemo
= self
.treeMap
[sys
.argv
[1]]
161 self
.tree
.SelectItem(selectedDemo
)
162 self
.tree
.EnsureVisible(selectedDemo
)
165 #---------------------------------------------
166 def WriteText(self
, text
):
167 self
.log
.WriteText(text
)
168 w
, h
= self
.log
.GetClientSizeTuple()
169 numLines
= h
/self
.charHeight
170 x
, y
= self
.log
.PositionToXY(self
.log
.GetLastPosition())
171 self
.log
.ShowPosition(self
.log
.XYToPosition(x
, y
-numLines
))
172 ##self.log.ShowPosition(self.log.GetLastPosition())
173 self
.log
.SetInsertionPointEnd()
175 def write(self
, txt
):
178 #---------------------------------------------
179 def OnItemExpanded(self
, event
):
180 item
= event
.GetItem()
181 self
.log
.WriteText("OnItemExpanded: %s\n" % self
.tree
.GetItemText(item
))
183 #---------------------------------------------
184 def OnItemCollapsed(self
, event
):
185 item
= event
.GetItem()
186 self
.log
.WriteText("OnItemCollapsed: %s\n" % self
.tree
.GetItemText(item
))
188 #---------------------------------------------
189 def OnSelChanged(self
, event
):
193 if self
.nb
.GetPageCount() == 3:
194 if self
.nb
.GetSelection() == 2:
195 self
.nb
.SetSelection(0)
196 self
.nb
.DeletePage(2)
198 item
= event
.GetItem()
199 itemText
= self
.tree
.GetItemText(item
)
201 if itemText
== 'Overview':
202 self
.GetDemoFile('Main.py')
203 self
.SetOverview('Overview', overview
)
204 #self.nb.ResizeChildren();
210 if os
.path
.exists(itemText
+ '.py'):
211 self
.GetDemoFile(itemText
+ '.py')
212 module
= __import__(itemText
, globals())
213 self
.SetOverview(itemText
, module
.overview
)
215 # in case runTest is modal, make sure things look right...
219 self
.window
= module
.runTest(self
, self
.nb
, self
)
221 self
.nb
.AddPage(self
.window
, 'Demo')
222 self
.nb
.SetSelection(2)
223 self
.nb
.ResizeChildren();
231 #---------------------------------------------
233 def GetDemoFile(self
, filename
):
235 #if not self.txt.LoadFile(filename):
236 # self.txt.WriteText("Cannot open %s file." % filename)
238 self
.txt
.SetValue(open(filename
).read())
240 self
.txt
.WriteText("Cannot open %s file." % filename
)
243 self
.txt
.SetInsertionPoint(0)
244 self
.txt
.ShowPosition(0)
246 #---------------------------------------------
247 def SetOverview(self
, name
, text
):
249 self
.ovr
.WriteText(text
)
250 self
.nb
.SetPageText(0, name
)
251 self
.ovr
.SetInsertionPoint(0)
252 self
.ovr
.ShowPosition(0)
254 #---------------------------------------------
256 def OnFileExit(self
, event
):
260 def OnHelpAbout(self
, event
):
261 #about = wxMessageDialog(self,
262 # "wxPython is a Python extension module that\n"
263 # "encapsulates the wxWindows GUI classes.\n\n"
264 # "This demo shows off some of the capabilities\n"
266 # " Developed by Robin Dunn",
267 # "About wxPython", wxOK)
268 about
= MyAboutBox(self
)
273 #---------------------------------------------
274 def OnCloseWindow(self
, event
):
279 #---------------------------------------------
280 def OnIdle(self
, event
):
282 self
.otherWin
.Raise()
283 self
.window
= self
.otherWin
286 #---------------------------------------------
287 def OnDemoMenu(self
, event
):
288 print event
.GetId(), self
.mainmenu
.GetLabel(event
.GetId())
290 selectedDemo
= self
.treeMap
[self
.mainmenu
.GetLabel(event
.GetId())]
294 self
.tree
.SelectItem(selectedDemo
)
295 self
.tree
.EnsureVisible(selectedDemo
)
299 #---------------------------------------------------------------------------
300 #---------------------------------------------------------------------------
302 class MyAboutBox(wxDialog
):
305 <body bgcolor="#AC76DE">
306 <center><table bgcolor="#458154" width="100%%" cellspacing="0" cellpadding="0" border="1">
308 <td align="center"><h1>wxPython %s</h1></td>
312 <p><b>wxPython</b> is a Python extension module that
313 encapsulates the wxWindows GUI classes.</p>
315 <p>This demo shows off some of the capabilities
316 of <b>wxPython</b>. Select items from the menu or tree control,
317 sit back and enjoy. Be sure to take a peek at the source code for each
318 demo item so you can learn how to use the classes yourself.</p>
320 <p><b>wxPython</b> is brought to you by <b>Robin Dunn</b> and<br>
321 <b>Total Control Software</b>, copyright 1999.</p>
323 <p><font size="-1">Please see <i>license.txt</i> for licensing information.</font></p>
328 def __init__(self
, parent
):
329 from wxPython
.html
import *
330 wxDialog
.__init
__(self
, parent
, -1, 'About wxPython')
331 self
.html
= wxHtmlWindow(self
, -1, wxPoint(5,5), wxSize(400, 350))
332 self
.html
.SetPage(self
.text
% wx
.__version
__)
333 wxButton(self
, wxID_OK
, 'OK', wxPoint(5, 365)).SetDefault()
337 #---------------------------------------------------------------------------
338 #---------------------------------------------------------------------------
342 wxImage_AddHandler(wxJPEGHandler())
343 wxImage_AddHandler(wxPNGHandler())
344 wxImage_AddHandler(wxGIFHandler())
345 frame
= wxPythonDemo(NULL
, -1, "wxPython: (A Demonstration)")
347 self
.SetTopWindow(frame
)
350 #---------------------------------------------------------------------------
357 #---------------------------------------------------------------------------
365 Python is an interpreted, interactive, object-oriented programming language often compared to Tcl, Perl, Scheme, or Java.
367 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.
372 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.
374 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.
379 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.
381 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.
383 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.
385 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.
394 #----------------------------------------------------------------------------
395 #----------------------------------------------------------------------------
397 if __name__
== '__main__':
400 #----------------------------------------------------------------------------