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())
172 self
.log
.ShowPosition(self
.log
.XYToPosition(x
, y
-numLines
))
173 ##self.log.ShowPosition(self.log.GetLastPosition())
174 self
.log
.SetInsertionPointEnd()
176 def write(self
, txt
):
179 #---------------------------------------------
180 def OnItemExpanded(self
, event
):
181 item
= event
.GetItem()
182 self
.log
.WriteText("OnItemExpanded: %s\n" % self
.tree
.GetItemText(item
))
184 #---------------------------------------------
185 def OnItemCollapsed(self
, event
):
186 item
= event
.GetItem()
187 self
.log
.WriteText("OnItemCollapsed: %s\n" % self
.tree
.GetItemText(item
))
189 #---------------------------------------------
190 def OnSelChanged(self
, event
):
194 if self
.nb
.GetPageCount() == 3:
195 if self
.nb
.GetSelection() == 2:
196 self
.nb
.SetSelection(0)
197 self
.nb
.DeletePage(2)
199 item
= event
.GetItem()
200 itemText
= self
.tree
.GetItemText(item
)
202 if itemText
== 'Overview':
203 self
.GetDemoFile('Main.py')
204 self
.SetOverview('Overview', overview
)
205 #self.nb.ResizeChildren();
211 if os
.path
.exists(itemText
+ '.py'):
212 self
.GetDemoFile(itemText
+ '.py')
213 module
= __import__(itemText
, globals())
214 self
.SetOverview(itemText
, module
.overview
)
216 # in case runTest is modal, make sure things look right...
220 self
.window
= module
.runTest(self
, self
.nb
, self
)
222 self
.nb
.AddPage(self
.window
, 'Demo')
223 self
.nb
.SetSelection(2)
224 self
.nb
.ResizeChildren();
232 #---------------------------------------------
234 def GetDemoFile(self
, filename
):
236 #if not self.txt.LoadFile(filename):
237 # self.txt.WriteText("Cannot open %s file." % filename)
239 self
.txt
.SetValue(open(filename
).read())
241 self
.txt
.WriteText("Cannot open %s file." % filename
)
244 self
.txt
.SetInsertionPoint(0)
245 self
.txt
.ShowPosition(0)
247 #---------------------------------------------
248 def SetOverview(self
, name
, text
):
250 self
.ovr
.WriteText(text
)
251 self
.nb
.SetPageText(0, name
)
252 self
.ovr
.SetInsertionPoint(0)
253 self
.ovr
.ShowPosition(0)
255 #---------------------------------------------
257 def OnFileExit(self
, event
):
261 def OnHelpAbout(self
, event
):
262 #about = wxMessageDialog(self,
263 # "wxPython is a Python extension module that\n"
264 # "encapsulates the wxWindows GUI classes.\n\n"
265 # "This demo shows off some of the capabilities\n"
267 # " Developed by Robin Dunn",
268 # "About wxPython", wxOK)
269 from About
import MyAboutBox
270 about
= MyAboutBox(self
)
275 #---------------------------------------------
276 def OnCloseWindow(self
, event
):
281 #---------------------------------------------
282 def OnIdle(self
, event
):
284 self
.otherWin
.Raise()
285 self
.window
= self
.otherWin
288 #---------------------------------------------
289 def OnDemoMenu(self
, event
):
290 print event
.GetId(), self
.mainmenu
.GetLabel(event
.GetId())
292 selectedDemo
= self
.treeMap
[self
.mainmenu
.GetLabel(event
.GetId())]
296 self
.tree
.SelectItem(selectedDemo
)
297 self
.tree
.EnsureVisible(selectedDemo
)
301 #---------------------------------------------------------------------------
302 #---------------------------------------------------------------------------
306 wxImage_AddHandler(wxJPEGHandler())
307 wxImage_AddHandler(wxPNGHandler())
308 wxImage_AddHandler(wxGIFHandler())
309 frame
= wxPythonDemo(NULL
, -1, "wxPython: (A Demonstration)")
311 self
.SetTopWindow(frame
)
314 #---------------------------------------------------------------------------
321 #---------------------------------------------------------------------------
329 Python is an interpreted, interactive, object-oriented programming language often compared to Tcl, Perl, Scheme, or Java.
331 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.
336 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.
338 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.
343 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.
345 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.
347 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.
349 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.
358 #----------------------------------------------------------------------------
359 #----------------------------------------------------------------------------
361 if __name__
== '__main__':
364 #----------------------------------------------------------------------------