2 #----------------------------------------------------------------------------
4 # Purpose: Testing lots of stuff, controls, window types, etc.
8 # Created: A long time ago, in a galaxy far, far away...
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
17 from wxPython
.html
import wxHtmlWindow
21 #---------------------------------------------------------------------------
25 ('New since last release', ['ContextHelp',
32 'wxFindReplaceDialog',
39 'wxDynamicSashWindow',
43 ('Windows', ['wxFrame', 'wxDialog', 'wxMiniFrame',
44 'wxGrid', 'wxSashWindow',
45 'wxScrolledWindow', 'wxSplitterWindow',
46 'wxStatusBar', 'wxNotebook',
48 'wxStyledTextCtrl_1', 'wxStyledTextCtrl_2',
50 'wxDynamicSashWindow',
53 ('Common Dialogs', ['wxColourDialog', 'wxDirDialog', 'wxFileDialog',
54 'wxSingleChoiceDialog', 'wxTextEntryDialog',
55 'wxFontDialog', 'wxPageSetupDialog', 'wxPrintDialog',
56 'wxMessageDialog', 'wxProgressDialog', 'wxFindReplaceDialog',
59 ('Controls', ['wxButton', 'wxCheckBox', 'wxCheckListBox', 'wxChoice',
60 'wxComboBox', 'wxGauge', 'wxListBox', 'wxListCtrl', 'wxTextCtrl',
61 'wxTreeCtrl', 'wxSpinButton', 'wxSpinCtrl', 'wxStaticText',
62 'wxStaticBitmap', 'wxRadioBox', 'wxSlider', 'wxToolBar',
63 'wxCalendarCtrl', 'wxToggleButton',
67 ('Window Layout', ['wxLayoutConstraints', 'LayoutAnchors', 'Sizers', 'XML_Resource']),
69 ('Miscellaneous', [ 'DragAndDrop', 'CustomDragAndDrop', 'URLDragAndDrop',
71 'wxTimer', 'wxValidator', 'wxGLCanvas', 'DialogUnits',
72 'wxImage', 'wxMask', 'PrintFramework', 'wxOGL',
73 'PythonEvents', 'Threads',
74 'ActiveXWrapper_Acrobat', 'ActiveXWrapper_IE',
75 'wxDragImage', "wxProcess", "FancyText", "OOR", "wxWave",
76 'wxJoystick', 'DrawXXXList', 'ErrorDialogs', 'wxMimeTypesManager',
79 ('wxPython Library', ['Layoutf', 'wxScrolledMessageDialog',
80 'wxMultipleChoiceDialog', 'wxPlotCanvas', 'wxFloatBar',
81 'wxCalendar', 'wxMVCTree', 'wxVTKRenderWindow',
82 'FileBrowseButton', 'GenericButtons', 'wxEditor',
83 'ColourSelect', 'ImageBrowser',
84 'infoframe', 'ColourDB', 'PyCrust', 'TablePrint',
88 ('Cool Contribs', ['pyTree', 'hangman', 'SlashDot', 'XMLtreeview']),
92 #---------------------------------------------------------------------------
95 def __init__(self
, textCtrl
, logTime
=0):
96 wxPyLog
.__init
__(self
)
98 self
.logTime
= logTime
100 def DoLogString(self
, message
, timeStamp
):
102 message
= time
.strftime("%X", time
.localtime(timeStamp
)) + \
104 self
.tc
.AppendText(message
+ '\n')
107 #---------------------------------------------------------------------------
109 class wxPythonDemo(wxFrame
):
111 def __init__(self
, parent
, id, title
):
112 wxFrame
.__init
__(self
, parent
, -1, title
, size
= (800, 600),
113 style
=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE
)
115 self
.cwd
= os
.getcwd()
116 self
.curOverview
= ""
119 icon
= wxIconFromXPMData(images
.getMondrianData())
121 # another way to do it
122 bmp
= images
.getMondrianBitmap()
124 icon
.CopyFromBitmap(bmp
)
128 if wxPlatform
== '__WXMSW__':
129 # setup a taskbar icon, and catch some events from it
130 self
.tbicon
= wxTaskBarIcon()
131 self
.tbicon
.SetIcon(icon
, "wxPython Demo")
132 EVT_TASKBAR_LEFT_DCLICK(self
.tbicon
, self
.OnTaskBarActivate
)
133 EVT_TASKBAR_RIGHT_UP(self
.tbicon
, self
.OnTaskBarMenu
)
134 EVT_MENU(self
.tbicon
, self
.TBMENU_RESTORE
, self
.OnTaskBarActivate
)
135 EVT_MENU(self
.tbicon
, self
.TBMENU_CLOSE
, self
.OnTaskBarClose
)
139 EVT_IDLE(self
, self
.OnIdle
)
140 EVT_CLOSE(self
, self
.OnCloseWindow
)
141 EVT_ICONIZE(self
, self
.OnIconfiy
)
142 EVT_MAXIMIZE(self
, self
.OnMaximize
)
145 self
.CreateStatusBar(1, wxST_SIZEGRIP
)
147 splitter
= wxSplitterWindow(self
, -1, style
=wxNO_3D|wxSP_3D
)
148 splitter2
= wxSplitterWindow(splitter
, -1, style
=wxNO_3D|wxSP_3D
)
150 def EmptyHandler(evt
): pass
151 EVT_ERASE_BACKGROUND(splitter
, EmptyHandler
)
152 EVT_ERASE_BACKGROUND(splitter2
, EmptyHandler
)
154 # Prevent TreeCtrl from displaying all items after destruction when true
158 self
.mainmenu
= wxMenuBar()
161 menu
.Append(exitID
, 'E&xit\tAlt-X', 'Get the heck outta here!')
162 EVT_MENU(self
, exitID
, self
.OnFileExit
)
163 self
.mainmenu
.Append(menu
, '&File')
167 for item
in _treeList
:
169 for childItem
in item
[1]:
171 submenu
.Append(mID
, childItem
)
172 EVT_MENU(self
, mID
, self
.OnDemoMenu
)
173 menu
.AppendMenu(wxNewId(), item
[0], submenu
)
174 self
.mainmenu
.Append(menu
, '&Demo')
180 menu
.Append(helpID
, '&About\tCtrl-H', 'wxPython RULES!!!')
181 EVT_MENU(self
, helpID
, self
.OnHelpAbout
)
182 self
.mainmenu
.Append(menu
, '&Help')
183 self
.SetMenuBar(self
.mainmenu
)
185 # set the menu accellerator table...
186 aTable
= wxAcceleratorTable([(wxACCEL_ALT
, ord('X'), exitID
),
187 (wxACCEL_CTRL
, ord('H'), helpID
)])
188 self
.SetAcceleratorTable(aTable
)
194 self
.tree
= wxTreeCtrl(splitter
, tID
,
195 style
=wxTR_HAS_BUTTONS |
197 wxTR_HAS_VARIABLE_ROW_HEIGHT |
199 #self.tree.SetBackgroundColour(wxNamedColour("Pink"))
200 root
= self
.tree
.AddRoot("Overview")
202 for item
in _treeList
:
203 child
= self
.tree
.AppendItem(root
, item
[0])
204 if not firstChild
: firstChild
= child
205 for childItem
in item
[1]:
206 theDemo
= self
.tree
.AppendItem(child
, childItem
)
207 self
.treeMap
[childItem
] = theDemo
209 self
.tree
.Expand(root
)
210 self
.tree
.Expand(firstChild
)
211 EVT_TREE_ITEM_EXPANDED (self
.tree
, tID
, self
.OnItemExpanded
)
212 EVT_TREE_ITEM_COLLAPSED (self
.tree
, tID
, self
.OnItemCollapsed
)
213 EVT_TREE_SEL_CHANGED (self
.tree
, tID
, self
.OnSelChanged
)
214 EVT_LEFT_DOWN (self
.tree
, self
.OnTreeLeftDown
)
217 self
.nb
= wxNotebook(splitter2
, -1, style
=wxCLIP_CHILDREN
)
219 # Set up a wxHtmlWindow on the Overview Notebook page
220 # we put it in a panel first because there seems to be a
221 # refresh bug of some sort (wxGTK) when it is directly in
224 self
.ovr
= wxHtmlWindow(self
.nb
, -1, size
=(400, 400))
225 self
.nb
.AddPage(self
.ovr
, "Overview")
227 else: # hopefully I can remove this hacky code soon, see bug #216861
228 panel
= wxPanel(self
.nb
, -1, style
=wxCLIP_CHILDREN
)
229 self
.ovr
= wxHtmlWindow(panel
, -1, size
=(400, 400))
230 self
.nb
.AddPage(panel
, "Overview")
232 def OnOvrSize(evt
, ovr
=self
.ovr
):
233 ovr
.SetSize(evt
.GetSize())
235 EVT_SIZE(panel
, OnOvrSize
)
236 EVT_ERASE_BACKGROUND(panel
, EmptyHandler
)
239 self
.SetOverview("Overview", overview
)
242 # Set up a TextCtrl on the Demo Code Notebook page
243 self
.txt
= wxTextCtrl(self
.nb
, -1,
244 style
= wxTE_MULTILINE|wxTE_READONLY|wxHSCROLL
)
245 self
.nb
.AddPage(self
.txt
, "Demo Code")
248 # Set up a log on the View Log Notebook page
249 self
.log
= wxTextCtrl(splitter2
, -1,
250 style
= wxTE_MULTILINE|wxTE_READONLY|wxHSCROLL
)
251 # Set the wxWindows log target to be this textctrl
252 #wxLog_SetActiveTarget(wxLogTextCtrl(self.log))
253 wxLog_SetActiveTarget(MyLog(self
.log
))
259 # add the windows to the splitter and split it.
260 splitter2
.SplitHorizontally(self
.nb
, self
.log
)
261 splitter2
.SetSashPosition(450, true
)
262 splitter2
.SetMinimumPaneSize(20)
264 splitter
.SplitVertically(self
.tree
, splitter2
)
265 splitter
.SetSashPosition(180, true
)
266 splitter
.SetMinimumPaneSize(20)
269 # select initial items
270 self
.nb
.SetSelection(0)
271 self
.tree
.SelectItem(root
)
273 if len(sys
.argv
) == 2:
275 selectedDemo
= self
.treeMap
[sys
.argv
[1]]
279 self
.tree
.SelectItem(selectedDemo
)
280 self
.tree
.EnsureVisible(selectedDemo
)
283 wxLogMessage('window handle: %s' % self
.GetHandle())
286 #---------------------------------------------
287 def WriteText(self
, text
):
288 if text
[-1:] == '\n':
293 def write(self
, txt
):
296 #---------------------------------------------
297 def OnItemExpanded(self
, event
):
298 item
= event
.GetItem()
299 wxLogMessage("OnItemExpanded: %s" % self
.tree
.GetItemText(item
))
302 #---------------------------------------------
303 def OnItemCollapsed(self
, event
):
304 item
= event
.GetItem()
305 wxLogMessage("OnItemCollapsed: %s" % self
.tree
.GetItemText(item
))
308 #---------------------------------------------
309 def OnTreeLeftDown(self
, event
):
310 pt
= event
.GetPosition();
311 item
, flags
= self
.tree
.HitTest(pt
)
312 if item
== self
.tree
.GetSelection():
313 self
.SetOverview(self
.tree
.GetItemText(item
), self
.curOverview
)
316 #---------------------------------------------
317 def OnSelChanged(self
, event
):
321 item
= event
.GetItem()
322 itemText
= self
.tree
.GetItemText(item
)
323 self
.RunDemo(itemText
)
326 #---------------------------------------------
327 def RunDemo(self
, itemText
):
329 if self
.nb
.GetPageCount() == 3:
330 if self
.nb
.GetSelection() == 2:
331 self
.nb
.SetSelection(0)
332 self
.nb
.DeletePage(2)
334 if itemText
== 'Overview':
335 self
.GetDemoFile('Main.py')
336 self
.SetOverview('Overview', overview
)
341 if os
.path
.exists(itemText
+ '.py'):
343 wxLogMessage("Running demo %s.py..." % itemText
)
345 self
.GetDemoFile(itemText
+ '.py')
346 module
= __import__(itemText
, globals())
347 self
.SetOverview(itemText
, module
.overview
)
351 # in case runTest is modal, make sure things look right...
355 self
.window
= module
.runTest(self
, self
.nb
, self
) ###
357 self
.nb
.AddPage(self
.window
, 'Demo')
359 self
.nb
.SetSelection(2)
368 #---------------------------------------------
370 def GetDemoFile(self
, filename
):
373 self
.txt
.SetValue(open(filename
).read())
375 self
.txt
.WriteText("Cannot open %s file." % filename
)
377 self
.txt
.SetInsertionPoint(0)
378 self
.txt
.ShowPosition(0)
380 #---------------------------------------------
381 def SetOverview(self
, name
, text
):
382 self
.curOverview
= text
384 if lead
!= '<html>' and lead
!= '<HTML>':
385 text
= string
.join(string
.split(text
, '\n'), '<br>')
386 #text = '<font size="-1"><pre>' + text + '</pre></font>'
387 self
.ovr
.SetPage(text
)
388 self
.nb
.SetPageText(0, name
)
390 #---------------------------------------------
392 def OnFileExit(self
, *event
):
396 def OnHelpAbout(self
, event
):
397 from About
import MyAboutBox
398 about
= MyAboutBox(self
)
403 #---------------------------------------------
404 def OnCloseWindow(self
, event
):
408 if hasattr(self
, "tbicon"):
413 #---------------------------------------------
414 def OnIdle(self
, event
):
416 self
.otherWin
.Raise()
417 self
.window
= self
.otherWin
420 #---------------------------------------------
421 def OnDemoMenu(self
, event
):
423 selectedDemo
= self
.treeMap
[self
.mainmenu
.GetLabel(event
.GetId())]
427 self
.tree
.SelectItem(selectedDemo
)
428 self
.tree
.EnsureVisible(selectedDemo
)
431 #---------------------------------------------
432 def OnTaskBarActivate(self
, evt
):
433 if self
.IsIconized():
435 if not self
.IsShown():
439 #---------------------------------------------
441 TBMENU_RESTORE
= 1000
444 def OnTaskBarMenu(self
, evt
):
446 menu
.Append(self
.TBMENU_RESTORE
, "Restore wxPython Demo")
447 menu
.Append(self
.TBMENU_CLOSE
, "Close")
448 self
.tbicon
.PopupMenu(menu
)
451 #---------------------------------------------
452 def OnTaskBarClose(self
, evt
):
455 # because of the way wxTaskBarIcon.PopupMenu is implemented we have to
456 # prod the main idle handler a bit to get the window to actually close
457 wxGetApp().ProcessIdle()
460 #---------------------------------------------
461 def OnIconfiy(self
, evt
):
462 wxLogMessage("OnIconfiy")
465 #---------------------------------------------
466 def OnMaximize(self
, evt
):
467 wxLogMessage("OnMaximize")
473 #---------------------------------------------------------------------------
474 #---------------------------------------------------------------------------
478 wxInitAllImageHandlers()
480 self
.splash
= SplashScreen(None, bitmapfile
='bitmaps/splash.gif',
481 duration
=4000, callback
=self
.AfterSplash
)
482 self
.splash
.Show(true
)
487 def AfterSplash(self
):
488 self
.splash
.Close(true
)
489 frame
= wxPythonDemo(None, -1, "wxPython: (A Demonstration)")
491 self
.SetTopWindow(frame
)
495 def ShowTip(self
, frame
):
497 showTipText
= open("data/showTips").read()
498 showTip
, index
= eval(showTipText
)
500 showTip
, index
= (1, 0)
501 #print showTip, index
503 tp
= wxCreateFileTipProvider("data/tips.txt", index
)
504 showTip
= wxShowTip(frame
, tp
)
505 index
= tp
.GetCurrentTip()
506 open("data/showTips", "w").write(str( (showTip
, index
) ))
509 #---------------------------------------------------------------------------
513 demoPath
= os
.path
.dirname(__file__
)
521 #---------------------------------------------------------------------------
525 overview
= """<html><body>
528 Python is an interpreted, interactive, object-oriented programming
529 language often compared to Tcl, Perl, Scheme, or Java.
531 <p> Python combines remarkable power with very clear syntax. It has
532 modules, classes, exceptions, very high level dynamic data types, and
533 dynamic typing. There are interfaces to many system calls and
534 libraries, and new built-in modules are easily written in C or
535 C++. Python is also usable as an extension language for applications
536 that need a programmable interface. <p>
540 wxWindows is a free C++ framework designed to make cross-platform
541 programming child's play. Well, almost. wxWindows 2 supports Windows
542 3.1/95/98/NT, Unix with GTK/Motif/Lesstif, with a Mac version
543 underway. Other ports are under consideration. <p>
545 wxWindows is a set of libraries that allows C++ applications to
546 compile and run on several different types of computers, with minimal
547 source code changes. There is one library per supported GUI (such as
548 Motif, or Windows). As well as providing a common API (Application
549 Programming Interface) for GUI functionality, it provides
550 functionality for accessing some commonly-used operating system
551 facilities, such as copying or deleting files. wxWindows is a
552 'framework' in the sense that it provides a lot of built-in
553 functionality, which the application can use or replace as required,
554 thus saving a great deal of coding effort. Basic data structures such
555 as strings, linked lists and hash tables are also supported.
560 wxPython is a Python extension module that encapsulates the wxWindows
561 GUI classes. Currently it is only available for the Win32 and GTK
562 ports of wxWindows, but as soon as the other ports are brought up to
563 the same level as Win32 and GTK, it should be fairly trivial to
564 enable wxPython to be used with the new GUI.
568 The wxPython extension module attempts to mirror the class heiarchy
569 of wxWindows as closely as possible. This means that there is a
570 wxFrame class in wxPython that looks, smells, tastes and acts almost
571 the same as the wxFrame class in the C++ version. Unfortunately,
572 because of differences in the languages, wxPython doesn't match
573 wxWindows exactly, but the differences should be easy to absorb
574 because they are natural to Python. For example, some methods that
575 return multiple values via argument pointers in C++ will return a
576 tuple of values in Python.
580 There is still much to be done for wxPython, many classes still need
581 to be mirrored. Also, wxWindows is still somewhat of a moving target
582 so it is a bit of an effort just keeping wxPython up to date. On the
583 other hand, there are enough of the core classes completed that
584 useful applications can be written.
588 wxPython is close enough to the C++ version that the majority of
589 the wxPython documentation is actually just notes attached to the C++
590 documents that describe the places where wxPython is different. There
591 is also a series of sample programs included, and a series of
592 documentation pages that assist the programmer in getting started
598 #----------------------------------------------------------------------------
599 #----------------------------------------------------------------------------
601 if __name__
== '__main__':
604 #----------------------------------------------------------------------------