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
 
  19 #--------------------------------------------------------------------------- 
  23     ('New since last release', ['PyShellWindow', 
  26     ('Managed Windows', ['wxFrame', 'wxDialog', 'wxMiniFrame']), 
  28     ('Non-Managed Windows', ['wxGrid', 'wxSashWindow', 
  29                              'wxScrolledWindow', 'wxSplitterWindow', 
  30                              'wxStatusBar', 'wxNotebook', 
  32                              'wxStyledTextCtrl_1', 'wxStyledTextCtrl_2',]), 
  34     ('Common Dialogs', ['wxColourDialog', 'wxDirDialog', 'wxFileDialog', 
  35                         'wxSingleChoiceDialog', 'wxTextEntryDialog', 
  36                         'wxFontDialog', 'wxPageSetupDialog', 'wxPrintDialog', 
  37                         'wxMessageDialog', 'wxProgressDialog']), 
  39     ('Controls', ['wxButton', 'wxCheckBox', 'wxCheckListBox', 'wxChoice', 
  40                   'wxComboBox', 'wxGauge', 'wxListBox', 'wxListCtrl', 'wxTextCtrl', 
  41                   'wxTreeCtrl', 'wxSpinButton', 'wxSpinCtrl', 'wxStaticText', 
  42                   'wxStaticBitmap', 'wxRadioBox', 'wxSlider', 'wxToolBar', 
  46     ('Window Layout', ['wxLayoutConstraints', 'Sizers', 'OldSizers']), 
  48     ('Miscellaneous', [ 'DragAndDrop', 'CustomDragAndDrop', 'FontEnumerator', 
  49                         'wxTimer', 'wxValidator', 'wxGLCanvas', 'DialogUnits', 
  50                         'wxImage', 'wxMask', 'PrintFramework', 'wxOGL', 
  51                         'PythonEvents', 'Threads', 
  52                         'ActiveXWrapper_Acrobat', 'ActiveXWrapper_IE', 
  53                         'wxDragImage', 'PyShellWindow', 
  56     ('wxPython Library', ['Layoutf', 'wxScrolledMessageDialog', 
  57                           'wxMultipleChoiceDialog', 'wxPlotCanvas', 'wxFloatBar', 
  58                           'PyShell', 'wxCalendar', 'wxMVCTree', 'wxVTKRenderWindow', 
  59                           'FileBrowseButton', 'GenericButtons', 'wxEditor']), 
  61     ('Cool Contribs', ['pyTree', 'hangman', 'SlashDot', 'XMLtreeview']), 
  65 #--------------------------------------------------------------------------- 
  67 class wxPythonDemo(wxFrame
): 
  68     def __init__(self
, parent
, id, title
): 
  69         wxFrame
.__init
__(self
, parent
, -1, title
, size 
= (800, 600), 
  70                          style
=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE
) 
  72         self
.cwd 
= os
.getcwd() 
  74         if wxPlatform 
== '__WXMSW__': 
  75             self
.icon 
= wxIcon('bitmaps/mondrian.ico', wxBITMAP_TYPE_ICO
) 
  76             self
.SetIcon(self
.icon
) 
  79         EVT_IDLE(self
, self
.OnIdle
) 
  80         EVT_CLOSE(self
, self
.OnCloseWindow
) 
  83         self
.CreateStatusBar(1, wxST_SIZEGRIP
) 
  85         splitter 
= wxSplitterWindow(self
, -1, style
=wxNO_3D|wxSP_3D
) 
  86         splitter2 
= wxSplitterWindow(splitter
, -1, style
=wxNO_3D|wxSP_3D
) 
  89         # Prevent TreeCtrl from displaying all items after destruction 
  93         self
.mainmenu 
= wxMenuBar() 
  96         menu
.Append(exitID
, 'E&xit\tAlt-X', 'Get the heck outta here!') 
  97         EVT_MENU(self
, exitID
, self
.OnFileExit
) 
  98         self
.mainmenu
.Append(menu
, '&File') 
 102         for item 
in _treeList
: 
 104             for childItem 
in item
[1]: 
 106                 submenu
.Append(mID
, childItem
) 
 107                 EVT_MENU(self
, mID
, self
.OnDemoMenu
) 
 108             menu
.AppendMenu(wxNewId(), item
[0], submenu
) 
 109         self
.mainmenu
.Append(menu
, '&Demo') 
 115         menu
.Append(helpID
, '&About\tCtrl-H', 'wxPython RULES!!!') 
 116         EVT_MENU(self
, helpID
, self
.OnHelpAbout
) 
 117         self
.mainmenu
.Append(menu
, '&Help') 
 118         self
.SetMenuBar(self
.mainmenu
) 
 120         # set the menu accellerator table... 
 121         aTable 
= wxAcceleratorTable([(wxACCEL_ALT
,  ord('X'), exitID
), 
 122                                      (wxACCEL_CTRL
, ord('H'), helpID
)]) 
 123         self
.SetAcceleratorTable(aTable
) 
 129         self
.tree 
= wxTreeCtrl(splitter
, tID
, 
 130                                style
=wxTR_HAS_BUTTONS |
 
 132                                wxTR_HAS_VARIABLE_ROW_HEIGHT |
 
 134         #self.tree.SetBackgroundColour(wxNamedColour("Pink")) 
 135         root 
= self
.tree
.AddRoot("Overview") 
 137         for item 
in _treeList
: 
 138             child 
= self
.tree
.AppendItem(root
, item
[0]) 
 139             if not firstChild
: firstChild 
= child
 
 140             for childItem 
in item
[1]: 
 141                 theDemo 
= self
.tree
.AppendItem(child
, childItem
) 
 142                 self
.treeMap
[childItem
] = theDemo
 
 144         self
.tree
.Expand(root
) 
 145         self
.tree
.Expand(firstChild
) 
 146         EVT_TREE_ITEM_EXPANDED   (self
.tree
, tID
, self
.OnItemExpanded
) 
 147         EVT_TREE_ITEM_COLLAPSED  (self
.tree
, tID
, self
.OnItemCollapsed
) 
 148         EVT_TREE_SEL_CHANGED     (self
.tree
, tID
, self
.OnSelChanged
) 
 149         EVT_LEFT_DOWN            (self
.tree
,      self
.OnTreeLeftDown
) 
 152         self
.nb 
= wxNotebook(splitter2
, -1) 
 154         # Set up a TextCtrl on the Overview Notebook page 
 155         self
.ovr 
= wxHtmlWindow(self
.nb
, -1) 
 156         self
.nb
.AddPage(self
.ovr
, "Overview") 
 159         # Set up a TextCtrl on the Demo Code Notebook page 
 160         self
.txt 
= wxTextCtrl(self
.nb
, -1, 
 161                               style 
= wxTE_MULTILINE|wxTE_READONLY|wxHSCROLL
) 
 162         self
.txt
.SetFont(wxFont(9, wxMODERN
, wxNORMAL
, wxNORMAL
, false
)) 
 163         self
.nb
.AddPage(self
.txt
, "Demo Code") 
 166         # Set up a log on the View Log Notebook page 
 167         self
.log 
= wxTextCtrl(splitter2
, -1, 
 168                               style 
= wxTE_MULTILINE|wxTE_READONLY|wxHSCROLL
) 
 169         # Set the wxWindows log target to be this textctrl 
 170         wxLog_SetActiveTarget(wxLogTextCtrl(self
.log
)) 
 176         # add the windows to the splitter and split it. 
 177         splitter2
.SplitHorizontally(self
.nb
, self
.log
) 
 178         splitter2
.SetSashPosition(450, true
) 
 179         splitter2
.SetMinimumPaneSize(20) 
 181         splitter
.SplitVertically(self
.tree
, splitter2
) 
 182         splitter
.SetSashPosition(180, true
) 
 183         splitter
.SetMinimumPaneSize(20) 
 186         # select initial items 
 187         self
.nb
.SetSelection(0) 
 188         self
.tree
.SelectItem(root
) 
 190         if len(sys
.argv
) == 2: 
 192                 selectedDemo 
= self
.treeMap
[sys
.argv
[1]] 
 196                 self
.tree
.SelectItem(selectedDemo
) 
 197                 self
.tree
.EnsureVisible(selectedDemo
) 
 200         wxLogMessage('window handle: %s' % self
.GetHandle()) 
 203     #--------------------------------------------- 
 204     def WriteText(self
, text
): 
 205         if text
[-1:] == '\n': 
 210     def write(self
, txt
): 
 213     #--------------------------------------------- 
 214     def OnItemExpanded(self
, event
): 
 215         item 
= event
.GetItem() 
 216         wxLogMessage("OnItemExpanded: %s" % self
.tree
.GetItemText(item
)) 
 218     #--------------------------------------------- 
 219     def OnItemCollapsed(self
, event
): 
 220         item 
= event
.GetItem() 
 221         wxLogMessage("OnItemCollapsed: %s" % self
.tree
.GetItemText(item
)) 
 224     #--------------------------------------------- 
 225     def OnTreeLeftDown(self
, event
): 
 226         pt 
= event
.GetPosition(); 
 227         item
, flags 
= self
.tree
.HitTest(pt
) 
 228         if item 
== self
.tree
.GetSelection(): 
 229             self
.SetOverview(self
.tree
.GetItemText(item
), self
.curOverview
) 
 233     #--------------------------------------------- 
 234     def OnSelChanged(self
, event
): 
 238         item 
= event
.GetItem() 
 239         itemText 
= self
.tree
.GetItemText(item
) 
 240         self
.RunDemo(itemText
) 
 243     #--------------------------------------------- 
 244     def RunDemo(self
, itemText
): 
 246         if self
.nb
.GetPageCount() == 3: 
 247             if self
.nb
.GetSelection() == 2: 
 248                 self
.nb
.SetSelection(0) 
 249             self
.nb
.DeletePage(2) 
 251         if itemText 
== 'Overview': 
 252             self
.GetDemoFile('Main.py') 
 253             self
.SetOverview('Overview', overview
) 
 258             if os
.path
.exists(itemText 
+ '.py'): 
 260                 wxLogMessage("Running demo %s.py..." % itemText
) 
 262                     self
.GetDemoFile(itemText 
+ '.py') 
 263                     module 
= __import__(itemText
, globals()) 
 264                     self
.SetOverview(itemText
, module
.overview
) 
 268                 # in case runTest is modal, make sure things look right... 
 272                 self
.window 
= module
.runTest(self
, self
.nb
, self
) ### 
 274                     self
.nb
.AddPage(self
.window
, 'Demo') 
 276                     self
.nb
.SetSelection(2) 
 285     #--------------------------------------------- 
 287     def GetDemoFile(self
, filename
): 
 290             self
.txt
.SetValue(open(filename
).read()) 
 292             self
.txt
.WriteText("Cannot open %s file." % filename
) 
 294         self
.txt
.SetInsertionPoint(0) 
 295         self
.txt
.ShowPosition(0) 
 297     #--------------------------------------------- 
 298     def SetOverview(self
, name
, text
): 
 299         self
.curOverview 
= text
 
 301         if lead 
!= '<html>' and lead 
!= '<HTML>': 
 302             text 
= string
.join(string
.split(text
, '\n'), '<br>') 
 303             #text = '<font size="-1"><pre>' + text + '</pre></font>' 
 304         self
.ovr
.SetPage(text
) 
 305         self
.nb
.SetPageText(0, name
) 
 307     #--------------------------------------------- 
 309     def OnFileExit(self
, event
): 
 313     def OnHelpAbout(self
, event
): 
 314         from About 
import MyAboutBox
 
 315         about 
= MyAboutBox(self
) 
 320     #--------------------------------------------- 
 321     def OnCloseWindow(self
, event
): 
 327     #--------------------------------------------- 
 328     def OnIdle(self
, event
): 
 330             self
.otherWin
.Raise() 
 331             self
.window 
= self
.otherWin
 
 334     #--------------------------------------------- 
 335     def OnDemoMenu(self
, event
): 
 337             selectedDemo 
= self
.treeMap
[self
.mainmenu
.GetLabel(event
.GetId())] 
 341             self
.tree
.SelectItem(selectedDemo
) 
 342             self
.tree
.EnsureVisible(selectedDemo
) 
 344 #--------------------------------------------------------------------------- 
 345 #--------------------------------------------------------------------------- 
 349         wxInitAllImageHandlers() 
 351         self
.splash 
= SplashScreen(None, bitmapfile
='bitmaps/splash.gif', 
 352                               duration
=4000, callback
=self
.AfterSplash
) 
 353         self
.splash
.Show(true
) 
 358     def AfterSplash(self
): 
 359         self
.splash
.Close(true
) 
 360         frame 
= wxPythonDemo(None, -1, "wxPython: (A Demonstration)") 
 362         self
.SetTopWindow(frame
) 
 366     def ShowTip(self
, frame
): 
 368             showTipText 
= open("data/showTips").read() 
 369             showTip
, index 
= eval(showTipText
) 
 371             showTip
, index 
= (1, 0) 
 374             tp 
= wxCreateFileTipProvider("data/tips.txt", index
) 
 375             showTip 
= wxShowTip(frame
, tp
) 
 376             index 
= tp
.GetCurrentTip() 
 377             open("data/showTips", "w").write(str( (showTip
, index
) )) 
 380 #--------------------------------------------------------------------------- 
 384         demoPath 
= os
.path
.split(__file__
)[0] 
 392 #--------------------------------------------------------------------------- 
 396 overview 
= """<html><body> 
 399  Python is an interpreted, interactive, object-oriented programming 
 400  language often compared to Tcl, Perl, Scheme, or Java. 
 402  <p> Python combines remarkable power with very clear syntax. It has 
 403  modules, classes, exceptions, very high level dynamic data types, and 
 404  dynamic typing.  There are interfaces to many system calls and 
 405  libraries, and new built-in modules are easily written in C or 
 406  C++. Python is also usable as an extension language for applications 
 407  that need a programmable interface.  <p> 
 411  wxWindows is a free C++ framework designed to make cross-platform 
 412  programming child's play. Well, almost. wxWindows 2 supports Windows 
 413  3.1/95/98/NT, Unix with GTK/Motif/Lesstif, with a Mac version 
 414  underway. Other ports are under consideration.  <p> 
 416  wxWindows is a set of libraries that allows C++ applications to 
 417  compile and run on several different types of computers, with minimal 
 418  source code changes.  There is one library per supported GUI (such as 
 419  Motif, or Windows). As well as providing a common API (Application 
 420  Programming Interface) for GUI functionality, it provides 
 421  functionality for accessing some commonly-used operating system 
 422  facilities, such as copying or deleting files. wxWindows is a 
 423  'framework' in the sense that it provides a lot of built-in 
 424  functionality, which the application can use or replace as required, 
 425  thus saving a great deal of coding effort. Basic data structures such 
 426  as strings, linked lists and hash tables are also supported. 
 431  wxPython is a Python extension module that encapsulates the wxWindows 
 432  GUI classes. Currently it is only available for the Win32 and GTK 
 433  ports of wxWindows, but as soon as the other ports are brought up to 
 434  the same level as Win32 and GTK, it should be fairly trivial to 
 435  enable wxPython to be used with the new GUI. 
 439  The wxPython extension module attempts to mirror the class heiarchy 
 440  of wxWindows as closely as possible. This means that there is a 
 441  wxFrame class in wxPython that looks, smells, tastes and acts almost 
 442  the same as the wxFrame class in the C++ version. Unfortunately, 
 443  because of differences in the languages, wxPython doesn't match 
 444  wxWindows exactly, but the differences should be easy to absorb 
 445  because they are natural to Python. For example, some methods that 
 446  return multiple values via argument pointers in C++ will return a 
 447  tuple of values in Python. 
 451  There is still much to be done for wxPython, many classes still need 
 452  to be mirrored. Also, wxWindows is still somewhat of a moving target 
 453  so it is a bit of an effort just keeping wxPython up to date. On the 
 454  other hand, there are enough of the core classes completed that 
 455  useful applications can be written. 
 459  wxPython is close enough to the C++ version that the majority of 
 460  the wxPython documentation is actually just notes attached to the C++ 
 461  documents that describe the places where wxPython is different. There 
 462  is also a series of sample programs included, and a series of 
 463  documentation pages that assist the programmer in getting started 
 469 #---------------------------------------------------------------------------- 
 470 #---------------------------------------------------------------------------- 
 472 if __name__ 
== '__main__': 
 475 #----------------------------------------------------------------------------