]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/Main.py
Fixed cursor resource names to actually match what's in the resource file.
[wxWidgets.git] / wxPython / demo / Main.py
1 #!/bin/env python
2 #----------------------------------------------------------------------------
3 # Name: Main.py
4 # Purpose: Testing lots of stuff, controls, window types, etc.
5 #
6 # Author: Robin Dunn
7 #
8 # Created: A long time ago, in a galaxy far, far away...
9 # RCS-ID: $Id$
10 # Copyright: (c) 1999 by Total Control Software
11 # Licence: wxWindows license
12 #----------------------------------------------------------------------------
13
14 import sys, os, time
15
16 import wx # This module uses the new wx namespace
17 import wx.html
18
19 import images
20
21 # For debugging
22 ##wx.Trap();
23 ##print os.getpid(); raw_input("Press a key...")
24
25
26 #---------------------------------------------------------------------------
27
28
29 _treeList = [
30 # new stuff
31 ('Recent Additions', [
32 'wxVListBox',
33 'wxListbook',
34 'wxMaskedNumCtrl',
35 'FloatCanvas',
36 'wxXmlResourceSubclass',
37 'wxGridBagSizer',
38 ]),
39
40 # managed windows == things with a (optional) caption you can close
41 ('Base Frames and Dialogs', [
42 'wxDialog',
43 'wxFrame',
44 'wxMDIWindows',
45 'wxMiniFrame',
46 'wxWizard',
47 ]),
48
49 # the common dialogs
50 ('Common Dialogs', [
51 'wxColourDialog',
52 'wxDirDialog',
53 'wxFileDialog',
54 'wxFileDialog_Save',
55 'wxFindReplaceDialog',
56 'wxFontDialog',
57 'wxMessageDialog',
58 'wxPageSetupDialog',
59 'wxPrintDialog',
60 'wxProgressDialog',
61 'wxSingleChoiceDialog',
62 'wxTextEntryDialog',
63 ]),
64
65 # dialogs from libraries
66 ('More Dialogs', [
67 'ErrorDialogs',
68 'ImageBrowser',
69 'wxMultipleChoiceDialog',
70 'wxScrolledMessageDialog',
71 ]),
72
73 # core controls
74 ('Core Windows/Controls', [
75 'PopupMenu',
76 'wxButton',
77 'wxCheckBox',
78 'wxCheckListBox',
79 'wxChoice',
80 'wxComboBox',
81 'wxGauge',
82 'wxGrid',
83 'wxGrid_MegaExample',
84 'wxListbook',
85 'wxListBox',
86 'wxListCtrl',
87 'wxListCtrl_virtual',
88 'wxMenu',
89 'wxNotebook',
90 'wxPopupWindow',
91 'wxRadioBox',
92 'wxRadioButton',
93 'wxSashWindow',
94 'wxScrolledWindow',
95 'wxSlider',
96 'wxSpinButton',
97 'wxSpinCtrl',
98 'wxSplitterWindow',
99 'wxStaticBitmap',
100 'wxStaticText',
101 'wxStatusBar',
102 'wxTextCtrl',
103 'wxToggleButton',
104 'wxToolBar',
105 'wxTreeCtrl',
106 'wxValidator',
107 ]),
108
109 ('Custom Controls', [
110 'AnalogClockWindow',
111 'ColourSelect',
112 'GenericButtons',
113 'wxEditor',
114 'wxGenericDirCtrl',
115 'wxLEDNumberCtrl',
116 'wxMultiSash',
117 'wxPopupControl',
118 'wxPyColourChooser',
119 'wxTreeListCtrl',
120 ]),
121
122 # controls coming from other libraries
123 ('More Windows/Controls', [
124 #'wxFloatBar', deprecated
125 #'wxMVCTree', deprecated
126 #'wxRightTextCtrl', deprecated as we have wxTE_RIGHT now.
127 'ContextHelp',
128 'FancyText',
129 'FloatCanvas',
130 'FileBrowseButton',
131 'MaskedEditControls',
132 'PyShell',
133 'PyCrust',
134 'SplitTree',
135 'TablePrint',
136 'Throbber',
137 'wxCalendar',
138 'wxCalendarCtrl',
139 'wxDynamicSashWindow',
140 'wxEditableListBox',
141 'wxHtmlWindow',
142 'wxIEHtmlWin',
143 'wxIntCtrl',
144 'wxMimeTypesManager',
145 'wxMaskedNumCtrl',
146 'wxScrolledPanel',
147 'wxStyledTextCtrl_1',
148 'wxStyledTextCtrl_2',
149 'wxTimeCtrl',
150 'wxVListBox',
151 ]),
152
153 # How to lay out the controls in a frame/dialog
154 ('Window Layout', [
155 'LayoutAnchors',
156 'Layoutf',
157 'RowColSizer',
158 'Sizers',
159 'wxGridBagSizer',
160 'wxLayoutConstraints',
161 'wxScrolledPanel',
162 'wxXmlResource',
163 'wxXmlResourceHandler',
164 'wxXmlResourceSubclass',
165 ]),
166
167 # ditto
168 ('Process and Events', [
169 'EventManager',
170 'infoframe',
171 'OOR',
172 'PythonEvents',
173 'Threads',
174 'wxKeyEvents',
175 'wxProcess',
176 'wxTimer',
177 ]),
178
179 # Clipboard and DnD
180 ('Clipboard and DnD', [
181 'CustomDragAndDrop',
182 'DragAndDrop',
183 'URLDragAndDrop',
184 ]),
185
186 # Images
187 ('Using Images', [
188 'Throbber',
189 'wxArtProvider',
190 'wxDragImage',
191 'wxImage',
192 'wxImageFromStream',
193 'wxMask',
194 ]),
195
196 # Other stuff
197 ('Miscellaneous', [
198 'ColourDB',
199 'DialogUnits',
200 'DrawXXXList',
201 'FontEnumerator',
202 'NewNamespace',
203 'PrintFramework',
204 'ShapedWindow',
205 'Throbber',
206 'Unicode',
207 'wxFileHistory',
208 'wxJoystick',
209 'wxOGL',
210 'wxWave',
211 ]),
212
213 # need libs not coming with the demo
214 ('Objects using an external library', [
215 'ActiveXWrapper_Acrobat',
216 'ActiveXWrapper_IE',
217 'wxGLCanvas',
218 'wxPlotCanvas',
219 ]),
220
221
222 ('Check out the samples dir too', [
223 ]),
224
225 ]
226
227
228
229 #---------------------------------------------------------------------------
230 # Show how to derive a custom wxLog class
231
232 class MyLog(wx.PyLog):
233 def __init__(self, textCtrl, logTime=0):
234 wx.PyLog.__init__(self)
235 self.tc = textCtrl
236 self.logTime = logTime
237
238 def DoLogString(self, message, timeStamp):
239 if self.logTime:
240 message = time.strftime("%X", time.localtime(timeStamp)) + \
241 ": " + message
242 if self.tc:
243 self.tc.AppendText(message + '\n')
244
245
246 class MyTP(wx.PyTipProvider):
247 def GetTip(self):
248 return "This is my tip"
249
250 #---------------------------------------------------------------------------
251 # A class to be used to display source code in the demo. Try using the
252 # wxSTC in the wxStyledTextCtrl_2 sample first, fall back to wxTextCtrl
253 # if there is an error, such as the stc module not being present.
254 #
255
256 try:
257 ##raise ImportError
258 from wx import stc
259 from wxStyledTextCtrl_2 import PythonSTC
260 class DemoCodeViewer(PythonSTC):
261 def __init__(self, parent, ID):
262 PythonSTC.__init__(self, parent, ID)
263 self.SetEdgeMode(stc.STC_EDGE_NONE)
264 self.SetSelBackground(True, wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHT))
265 self.SetSelForeground(True, wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHTTEXT))
266
267 # Some methods to make it compatible with how the wxTextCtrl is used
268 def SetValue(self, value):
269 self.SetReadOnly(False)
270 self.SetText(value)
271 self.SetReadOnly(True)
272
273 def Clear(self):
274 self.ClearAll()
275
276 def SetInsertionPoint(self, pos):
277 self.SetCurrentPos(pos)
278
279 def ShowPosition(self, pos):
280 self.GotoPos(pos)
281
282 def GetLastPosition(self):
283 return self.GetLength()
284
285 def GetRange(self, start, end):
286 return self.GetTextRange(start, end)
287
288 def GetSelection(self):
289 return self.GetAnchor(), self.GetCurrentPos()
290
291 def SetSelection(self, start, end):
292 self.SetSelectionStart(start)
293 self.SetSelectionEnd(end)
294
295
296 except ImportError:
297 class DemoCodeViewer(wx.TextCtrl):
298 def __init__(self, parent, ID):
299 wx.TextCtrl.__init__(self, parent, ID, style =
300 wx.TE_MULTILINE | wx.TE_READONLY |
301 wx.HSCROLL | wx.TE_RICH2 | wx.TE_NOHIDESEL)
302
303
304 #---------------------------------------------------------------------------
305
306 def opj(path):
307 """Convert paths to the platform-specific separator"""
308 return apply(os.path.join, tuple(path.split('/')))
309
310
311 #---------------------------------------------------------------------------
312
313 class wxPythonDemo(wx.Frame):
314 overviewText = "wxPython Overview"
315
316 def __init__(self, parent, id, title):
317 wx.Frame.__init__(self, parent, -1, title, size = (800, 600),
318 style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
319
320 self.cwd = os.getcwd()
321 self.curOverview = ""
322 self.window = None
323
324 icon = images.getMondrianIcon()
325 self.SetIcon(icon)
326
327 if wx.Platform == '__WXMSW__':
328 # setup a taskbar icon, and catch some events from it
329 self.tbicon = wx.TaskBarIcon()
330 self.tbicon.SetIcon(icon, "wxPython Demo")
331 wx.EVT_TASKBAR_LEFT_DCLICK(self.tbicon, self.OnTaskBarActivate)
332 wx.EVT_TASKBAR_RIGHT_UP(self.tbicon, self.OnTaskBarMenu)
333 wx.EVT_MENU(self.tbicon, self.TBMENU_RESTORE, self.OnTaskBarActivate)
334 wx.EVT_MENU(self.tbicon, self.TBMENU_CLOSE, self.OnTaskBarClose)
335
336 wx.CallAfter(self.ShowTip)
337
338 self.otherWin = None
339 wx.EVT_IDLE(self, self.OnIdle)
340 wx.EVT_CLOSE(self, self.OnCloseWindow)
341 wx.EVT_ICONIZE(self, self.OnIconfiy)
342 wx.EVT_MAXIMIZE(self, self.OnMaximize)
343
344 self.Centre(wx.BOTH)
345 self.CreateStatusBar(1, wx.ST_SIZEGRIP)
346
347 splitter = wx.SplitterWindow(self, -1)
348 splitter2 = wx.SplitterWindow(splitter, -1)
349
350 def EmptyHandler(evt): pass
351 #wx.EVT_ERASE_BACKGROUND(splitter, EmptyHandler)
352 #wx.EVT_ERASE_BACKGROUND(splitter2, EmptyHandler)
353
354 # Prevent TreeCtrl from displaying all items after destruction when True
355 self.dying = False
356
357 # Make a File menu
358 self.mainmenu = wx.MenuBar()
359 menu = wx.Menu()
360 exitID = wx.NewId()
361 menu.Append(exitID, 'E&xit\tAlt-X', 'Get the heck outta here!')
362 wx.EVT_MENU(self, exitID, self.OnFileExit)
363 wx.App_SetMacExitMenuItemId(exitID)
364 self.mainmenu.Append(menu, '&File')
365
366 # Make a Demo menu
367 menu = wx.Menu()
368 for item in _treeList:
369 submenu = wx.Menu()
370 for childItem in item[1]:
371 mID = wx.NewId()
372 submenu.Append(mID, childItem)
373 wx.EVT_MENU(self, mID, self.OnDemoMenu)
374 menu.AppendMenu(wx.NewId(), item[0], submenu)
375 self.mainmenu.Append(menu, '&Demo')
376
377
378 # Make a Help menu
379 helpID = wx.NewId()
380 findID = wx.NewId()
381 findnextID = wx.NewId()
382 menu = wx.Menu()
383 menu.Append(findID, '&Find\tCtrl-F', 'Find in the Demo Code')
384 menu.Append(findnextID, 'Find &Next\tF3', 'Find Next')
385 menu.AppendSeparator()
386 menu.Append(helpID, '&About\tCtrl-H', 'wxPython RULES!!!')
387 wx.App_SetMacAboutMenuItemId(helpID)
388 wx.EVT_MENU(self, helpID, self.OnHelpAbout)
389 wx.EVT_MENU(self, findID, self.OnHelpFind)
390 wx.EVT_MENU(self, findnextID, self.OnFindNext)
391 wx.EVT_COMMAND_FIND(self, -1, self.OnFind)
392 wx.EVT_COMMAND_FIND_NEXT(self, -1, self.OnFind)
393 wx.EVT_COMMAND_FIND_CLOSE(self, -1 , self.OnFindClose)
394 self.mainmenu.Append(menu, '&Help')
395 self.SetMenuBar(self.mainmenu)
396
397 self.finddata = wx.FindReplaceData()
398
399 if 0:
400 # This is another way to set Accelerators, in addition to
401 # using the '\t<key>' syntax in the menu items.
402 aTable = wx.AcceleratorTable([(wx.ACCEL_ALT, ord('X'), exitID),
403 (wx.ACCEL_CTRL, ord('H'), helpID),
404 (wx.ACCEL_CTRL, ord('F'), findID),
405 (wx.ACCEL_NORMAL, WXK_F3, findnextID)
406 ])
407 self.SetAcceleratorTable(aTable)
408
409
410 # Create a TreeCtrl
411 tID = wx.NewId()
412 self.treeMap = {}
413 self.tree = wx.TreeCtrl(splitter, tID, style =
414 wx.TR_DEFAULT_STYLE #| wx.TR_HAS_VARIABLE_ROW_HEIGHT
415 )
416
417 root = self.tree.AddRoot("wxPython Overview")
418 firstChild = None
419 for item in _treeList:
420 child = self.tree.AppendItem(root, item[0])
421 if not firstChild: firstChild = child
422 for childItem in item[1]:
423 theDemo = self.tree.AppendItem(child, childItem)
424 self.treeMap[childItem] = theDemo
425
426 self.tree.Expand(root)
427 self.tree.Expand(firstChild)
428 wx.EVT_TREE_ITEM_EXPANDED (self.tree, tID, self.OnItemExpanded)
429 wx.EVT_TREE_ITEM_COLLAPSED (self.tree, tID, self.OnItemCollapsed)
430 wx.EVT_TREE_SEL_CHANGED (self.tree, tID, self.OnSelChanged)
431 wx.EVT_LEFT_DOWN (self.tree, self.OnTreeLeftDown)
432
433 # Create a Notebook
434 self.nb = wx.Notebook(splitter2, -1, style=wx.CLIP_CHILDREN)
435
436 # Set up a wx.html.HtmlWindow on the Overview Notebook page
437 # we put it in a panel first because there seems to be a
438 # refresh bug of some sort (wxGTK) when it is directly in
439 # the notebook...
440 if 0: # the old way
441 self.ovr = wx.html.HtmlWindow(self.nb, -1, size=(400, 400))
442 self.nb.AddPage(self.ovr, self.overviewText)
443
444 else: # hopefully I can remove this hacky code soon, see SF bug #216861
445 panel = wx.Panel(self.nb, -1, style=wx.CLIP_CHILDREN)
446 self.ovr = wx.html.HtmlWindow(panel, -1, size=(400, 400))
447 self.nb.AddPage(panel, self.overviewText)
448
449 def OnOvrSize(evt, ovr=self.ovr):
450 ovr.SetSize(evt.GetSize())
451
452 wx.EVT_SIZE(panel, OnOvrSize)
453 wx.EVT_ERASE_BACKGROUND(panel, EmptyHandler)
454
455
456 self.SetOverview(self.overviewText, overview)
457
458
459 # Set up a notebook page for viewing the source code of each sample
460 self.txt = DemoCodeViewer(self.nb, -1)
461 self.nb.AddPage(self.txt, "Demo Code")
462 self.GetDemoFile('Main.py')
463
464
465 # Set up a log on the View Log Notebook page
466 self.log = wx.TextCtrl(splitter2, -1,
467 style = wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)
468
469 # Set the wxWindows log target to be this textctrl
470 #wx.Log_SetActiveTarget(wx.LogTextCtrl(self.log))
471
472 # But instead of the above we want to show how to use our own wx.Log class
473 wx.Log_SetActiveTarget(MyLog(self.log))
474
475 # for serious debugging
476 #wx.Log_SetActiveTarget(wx.LogStderr())
477 #wx.Log_SetTraceMask(wx.TraceMessages)
478
479 self.Show(True)
480
481
482 # add the windows to the splitter and split it.
483 splitter2.SplitHorizontally(self.nb, self.log, -120)
484 splitter.SplitVertically(self.tree, splitter2, 180)
485
486 splitter.SetMinimumPaneSize(20)
487 splitter2.SetMinimumPaneSize(20)
488
489
490 # Make the splitter on the right expand the top wind when resized
491 def SplitterOnSize(evt):
492 splitter = evt.GetEventObject()
493 sz = splitter.GetSize()
494 splitter.SetSashPosition(sz.height - 120, False)
495 evt.Skip()
496 wx.EVT_SIZE(splitter2, SplitterOnSize)
497
498
499 # select initial items
500 self.nb.SetSelection(0)
501 self.tree.SelectItem(root)
502
503 if len(sys.argv) == 2:
504 try:
505 selectedDemo = self.treeMap[sys.argv[1]]
506 except:
507 selectedDemo = None
508 if selectedDemo:
509 self.tree.SelectItem(selectedDemo)
510 self.tree.EnsureVisible(selectedDemo)
511
512
513 wx.LogMessage('window handle: %s' % self.GetHandle())
514
515
516 #---------------------------------------------
517 def WriteText(self, text):
518 if text[-1:] == '\n':
519 text = text[:-1]
520 wx.LogMessage(text)
521
522
523 def write(self, txt):
524 self.WriteText(txt)
525
526 #---------------------------------------------
527 def OnItemExpanded(self, event):
528 item = event.GetItem()
529 wx.LogMessage("OnItemExpanded: %s" % self.tree.GetItemText(item))
530 event.Skip()
531
532 #---------------------------------------------
533 def OnItemCollapsed(self, event):
534 item = event.GetItem()
535 wx.LogMessage("OnItemCollapsed: %s" % self.tree.GetItemText(item))
536 event.Skip()
537
538 #---------------------------------------------
539 def OnTreeLeftDown(self, event):
540 pt = event.GetPosition();
541 item, flags = self.tree.HitTest(pt)
542 if item == self.tree.GetSelection():
543 self.SetOverview(self.tree.GetItemText(item)+" Overview", self.curOverview)
544 event.Skip()
545
546 #---------------------------------------------
547 def OnSelChanged(self, event):
548 if self.dying:
549 return
550
551 item = event.GetItem()
552 itemText = self.tree.GetItemText(item)
553 self.RunDemo(itemText)
554
555
556 #---------------------------------------------
557 def RunDemo(self, itemText):
558 os.chdir(self.cwd)
559 if self.nb.GetPageCount() == 3:
560 if self.nb.GetSelection() == 2:
561 self.nb.SetSelection(0)
562 # inform the window that it's time to quit if it cares
563 if self.window is not None:
564 if hasattr(self.window, "ShutdownDemo"):
565 self.window.ShutdownDemo()
566 wx.SafeYield() # in case the page has pending events
567 self.nb.DeletePage(2)
568
569 if itemText == self.overviewText:
570 self.GetDemoFile('Main.py')
571 self.SetOverview(self.overviewText, overview)
572 self.nb.Refresh();
573 self.window = None
574
575 else:
576 if os.path.exists(itemText + '.py'):
577 wx.BeginBusyCursor()
578 wx.LogMessage("Running demo %s.py..." % itemText)
579 try:
580 self.GetDemoFile(itemText + '.py')
581 module = __import__(itemText, globals())
582 self.SetOverview(itemText + " Overview", module.overview)
583 finally:
584 wx.EndBusyCursor()
585 self.tree.Refresh()
586
587 # in case runTest is modal, make sure things look right...
588 self.nb.Refresh();
589 wx.SafeYield()
590
591 self.window = module.runTest(self, self.nb, self) ###
592 if self.window is not None:
593 self.nb.AddPage(self.window, 'Demo')
594 self.nb.SetSelection(2)
595 self.nb.Refresh() # without this wxMac has troubles showing the just added page
596
597 else:
598 self.ovr.SetPage("")
599 self.txt.Clear()
600 self.window = None
601
602
603
604 #---------------------------------------------
605 # Get the Demo files
606 def GetDemoFile(self, filename):
607 self.txt.Clear()
608 try:
609 self.txt.SetValue(open(filename).read())
610 except IOError:
611 self.txt.SetValue("Cannot open %s file." % filename)
612
613 self.txt.SetInsertionPoint(0)
614 self.txt.ShowPosition(0)
615
616 #---------------------------------------------
617 def SetOverview(self, name, text):
618 self.curOverview = text
619 lead = text[:6]
620 if lead != '<html>' and lead != '<HTML>':
621 text = '<br>'.join(text.split('\n'))
622 self.ovr.SetPage(text)
623 self.nb.SetPageText(0, name)
624
625 #---------------------------------------------
626 # Menu methods
627 def OnFileExit(self, *event):
628 self.Close()
629
630 def OnHelpAbout(self, event):
631 from About import MyAboutBox
632 about = MyAboutBox(self)
633 about.ShowModal()
634 about.Destroy()
635
636 def OnHelpFind(self, event):
637 self.nb.SetSelection(1)
638 self.finddlg = wx.FindReplaceDialog(self, self.finddata, "Find",
639 wx.FR_NOUPDOWN |
640 wx.FR_NOMATCHCASE |
641 wx.FR_NOWHOLEWORD)
642 self.finddlg.Show(True)
643
644 def OnFind(self, event):
645 self.nb.SetSelection(1)
646 end = self.txt.GetLastPosition()
647 textstring = self.txt.GetRange(0, end).lower()
648 start = self.txt.GetSelection()[1]
649 findstring = self.finddata.GetFindString().lower()
650 loc = textstring.find(findstring, start)
651 if loc == -1 and start != 0:
652 # string not found, start at beginning
653 start = 0
654 loc = textstring.find(findstring, start)
655 if loc == -1:
656 dlg = wx.MessageDialog(self, 'Find String Not Found',
657 'Find String Not Found in Demo File',
658 wx.OK | wx.ICON_INFORMATION)
659 dlg.ShowModal()
660 dlg.Destroy()
661 if self.finddlg:
662 if loc == -1:
663 self.finddlg.SetFocus()
664 return
665 else:
666 self.finddlg.Destroy()
667 self.txt.ShowPosition(loc)
668 self.txt.SetSelection(loc, loc + len(findstring))
669
670
671
672 def OnFindNext(self, event):
673 if self.finddata.GetFindString():
674 self.OnFind(event)
675 else:
676 self.OnHelpFind(event)
677
678 def OnFindClose(self, event):
679 event.GetDialog().Destroy()
680
681
682 #---------------------------------------------
683 def OnCloseWindow(self, event):
684 self.dying = True
685 self.window = None
686 self.mainmenu = None
687 if hasattr(self, "tbicon"):
688 del self.tbicon
689 self.Destroy()
690
691
692 #---------------------------------------------
693 def OnIdle(self, event):
694 if self.otherWin:
695 self.otherWin.Raise()
696 self.window = self.otherWin
697 self.otherWin = None
698
699
700 #---------------------------------------------
701 def ShowTip(self):
702 try:
703 showTipText = open(opj("data/showTips")).read()
704 showTip, index = eval(showTipText)
705 except IOError:
706 showTip, index = (1, 0)
707 if showTip:
708 tp = wx.CreateFileTipProvider(opj("data/tips.txt"), index)
709 ##tp = MyTP(0)
710 showTip = wx.ShowTip(self, tp)
711 index = tp.GetCurrentTip()
712 open(opj("data/showTips"), "w").write(str( (showTip, index) ))
713
714
715 #---------------------------------------------
716 def OnDemoMenu(self, event):
717 try:
718 selectedDemo = self.treeMap[self.mainmenu.GetLabel(event.GetId())]
719 except:
720 selectedDemo = None
721 if selectedDemo:
722 self.tree.SelectItem(selectedDemo)
723 self.tree.EnsureVisible(selectedDemo)
724
725
726 #---------------------------------------------
727 def OnTaskBarActivate(self, evt):
728 if self.IsIconized():
729 self.Iconize(False)
730 if not self.IsShown():
731 self.Show(True)
732 self.Raise()
733
734 #---------------------------------------------
735
736 TBMENU_RESTORE = 1000
737 TBMENU_CLOSE = 1001
738
739 def OnTaskBarMenu(self, evt):
740 menu = wx.Menu()
741 menu.Append(self.TBMENU_RESTORE, "Restore wxPython Demo")
742 menu.Append(self.TBMENU_CLOSE, "Close")
743 self.tbicon.PopupMenu(menu)
744 menu.Destroy()
745
746 #---------------------------------------------
747 def OnTaskBarClose(self, evt):
748 self.Close()
749
750 # because of the way wx.TaskBarIcon.PopupMenu is implemented we have to
751 # prod the main idle handler a bit to get the window to actually close
752 wx.GetApp().ProcessIdle()
753
754
755 #---------------------------------------------
756 def OnIconfiy(self, evt):
757 wx.LogMessage("OnIconfiy")
758 evt.Skip()
759
760 #---------------------------------------------
761 def OnMaximize(self, evt):
762 wx.LogMessage("OnMaximize")
763 evt.Skip()
764
765
766
767
768 #---------------------------------------------------------------------------
769 #---------------------------------------------------------------------------
770
771 class MySplashScreen(wx.SplashScreen):
772 def __init__(self):
773 bmp = wx.Image(opj("bitmaps/splash.gif")).ConvertToBitmap()
774 wx.SplashScreen.__init__(self, bmp,
775 wx.SPLASH_CENTRE_ON_SCREEN|wx.SPLASH_TIMEOUT,
776 4000, None, -1,
777 style = wx.SIMPLE_BORDER|wx.FRAME_NO_TASKBAR|wx.STAY_ON_TOP)
778 wx.EVT_CLOSE(self, self.OnClose)
779
780 def OnClose(self, evt):
781 frame = wxPythonDemo(None, -1, "wxPython: (A Demonstration)")
782 frame.Show()
783 evt.Skip() # Make sure the default handler runs too...
784
785
786 class MyApp(wx.App):
787 def OnInit(self):
788 """
789 Create and show the splash screen. It will then create and show
790 the main frame when it is time to do so.
791 """
792
793 #import locale
794 #self.locale = wx.Locale(wx.LANGUAGE_FRENCH)
795 #locale.setlocale(locale.LC_ALL, 'fr')
796
797 wx.InitAllImageHandlers()
798 splash = MySplashScreen()
799 splash.Show()
800 return True
801
802
803
804 #---------------------------------------------------------------------------
805
806 def main():
807 try:
808 demoPath = os.path.dirname(__file__)
809 os.chdir(demoPath)
810 except:
811 pass
812 app = MyApp(0) #wx.Platform == "__WXMAC__")
813 app.MainLoop()
814
815
816 #---------------------------------------------------------------------------
817
818
819
820 overview = """<html><body>
821 <h2>wxPython</h2>
822
823 <p> wxPython is a <b>GUI toolkit</b> for the <a
824 href="http://www.python.org/">Python</a> programming language. It
825 allows Python programmers to create programs with a robust, highly
826 functional graphical user interface, simply and easily. It is
827 implemented as a Python extension module (native code) that wraps the
828 popular <a href="http://wxwindows.org/front.htm">wxWindows</a> cross
829 platform GUI library, which is written in C++.
830
831 <p> Like Python and wxWindows, wxPython is <b>Open Source</b> which
832 means that it is free for anyone to use and the source code is
833 available for anyone to look at and modify. Or anyone can contribute
834 fixes or enhancements to the project.
835
836 <p> wxPython is a <b>cross-platform</b> toolkit. This means that the
837 same program will run on multiple platforms without modification.
838 Currently supported platforms are 32-bit Microsoft Windows, most Unix
839 or unix-like systems, and Macintosh OS X. Since the language is
840 Python, wxPython programs are <b>simple, easy</b> to write and easy to
841 understand.
842
843 <p> <b>This demo</b> is not only a collection of test cases for
844 wxPython, but is also designed to help you learn about and how to use
845 wxPython. Each sample is listed in the tree control on the left.
846 When a sample is selected in the tree then a module is loaded and run
847 (usually in a tab of this notebook,) and the source code of the module
848 is loaded in another tab for you to browse and learn from.
849
850 """
851
852
853 #----------------------------------------------------------------------------
854 #----------------------------------------------------------------------------
855
856 if __name__ == '__main__':
857 main()
858
859 #----------------------------------------------------------------------------
860
861
862
863
864
865
866