]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/Main.py
added visual c++ makefiles
[wxWidgets.git] / wxPython / demo / Main.py
CommitLineData
cf694132
RD
1#!/bin/env python
2#----------------------------------------------------------------------------
3# Name: Main.py
4# Purpose: Testing lots of stuff, controls, window types, etc.
5#
f6bcfd97 6# Author: Robin Dunn
cf694132 7#
f6bcfd97 8# Created: A long time ago, in a galaxy far, far away...
cf694132
RD
9# RCS-ID: $Id$
10# Copyright: (c) 1999 by Total Control Software
11# Licence: wxWindows license
12#----------------------------------------------------------------------------
13
1e4a197e 14import sys, os, time
cf694132 15from wxPython.wx import *
f6bcfd97 16from wxPython.html import wxHtmlWindow
cf694132 17
774e63ef 18##from wxPython.stc import *
606d919c 19
96bfd053
RD
20import images
21
1e4a197e 22
cf694132
RD
23#---------------------------------------------------------------------------
24
25
26_treeList = [
9c67cbec 27 # new stuff
1e4a197e
RD
28 ('Recent Additions', [
29 'wxIntCtrl',
30 'wxPyColourChooser',
31 'wxScrolledPanel',
9c67cbec
RD
32 ]),
33
1e4a197e 34 # managed windows == things with a (optional) caption you can close
9c67cbec
RD
35 ('Base Frames and Dialogs', [
36 'wxDialog',
37 'wxFrame',
38 'wxMDIWindows',
39 'wxMiniFrame',
af83019e 40 'wxWizard',
9c67cbec
RD
41 ]),
42
43 # the common dialogs
44 ('Common Dialogs', [
45 'wxColourDialog',
46 'wxDirDialog',
47 'wxFileDialog',
48 'wxFindReplaceDialog',
49 'wxFontDialog',
50 'wxMessageDialog',
51 'wxPageSetupDialog',
52 'wxPrintDialog',
53 'wxProgressDialog',
54 'wxSingleChoiceDialog',
55 'wxTextEntryDialog',
56 ]),
57
af83019e 58 # dialogs from libraries
9c67cbec
RD
59 ('More Dialogs', [
60 'ErrorDialogs',
61 'ImageBrowser',
62 'wxMultipleChoiceDialog',
63 'wxScrolledMessageDialog',
64 ]),
65
66 # core controls
67 ('Core Windows/Controls', [
9c67cbec
RD
68 'wxButton',
69 'wxCheckBox',
70 'wxCheckListBox',
71 'wxChoice',
72 'wxComboBox',
73 'wxGauge',
74 'wxGenericDirCtrl',
75 'wxGrid',
76 'wxListBox',
77 'wxListCtrl',
6f48b1b5 78 'wxListCtrl_virtual',
3115ef3e 79 'wxMenu',
9c67cbec
RD
80 'wxNotebook',
81 'wxPopupWindow',
82 'wxRadioBox',
1e4a197e 83 'wxRadioButton',
9c67cbec 84 'wxSashWindow',
9c67cbec 85 'wxScrolledWindow',
1e4a197e 86 'wxSlider',
9c67cbec
RD
87 'wxSpinButton',
88 'wxSpinCtrl',
1e4a197e 89 'wxSplitterWindow',
9c67cbec 90 'wxStaticBitmap',
1e4a197e 91 'wxStaticText',
9c67cbec
RD
92 'wxStatusBar',
93 'wxTextCtrl',
9c67cbec
RD
94 'wxToggleButton',
95 'wxToolBar',
96 'wxTreeCtrl',
97 'wxValidator',
98 ]),
99
100 # controls coming from other librairies
101 ('More Windows/Controls', [
1e4a197e
RD
102 #'wxFloatBar', deprecated
103 #'wxMVCTree', deprecated
104 #'wxRightTextCtrl', deprecated as we have wxTE_RIGHT now.
9c67cbec
RD
105 'ColourSelect',
106 'ContextHelp',
107 'FancyText',
108 'FileBrowseButton',
109 'GenericButtons',
110 'PyCrust',
111 'PyCrustWithFilling',
112 'SplitTree',
113 'TablePrint',
1e4a197e 114 'Throbber',
9c67cbec
RD
115 'wxCalendar',
116 'wxCalendarCtrl',
1e4a197e 117 'wxPyColourChooser',
9c67cbec
RD
118 'wxDynamicSashWindow',
119 'wxEditableListBox',
120 'wxEditor',
9c67cbec 121 'wxHtmlWindow',
c731eb47 122 'wxIEHtmlWin',
1e4a197e 123 'wxIntCtrl',
9c67cbec
RD
124 'wxLEDNumberCtrl',
125 'wxMimeTypesManager',
1e4a197e
RD
126 'wxMultiSash',
127 'wxPopupControl',
9c67cbec
RD
128 'wxStyledTextCtrl_1',
129 'wxStyledTextCtrl_2',
1e4a197e 130 'wxTimeCtrl',
9c67cbec
RD
131 ]),
132
133 # How to lay out the controls in a frame/dialog
134 ('Window Layout', [
135 'LayoutAnchors',
136 'Layoutf',
137 'RowColSizer',
138 'Sizers',
139 'wxLayoutConstraints',
1e4a197e 140 'wxScrolledPanel',
628c7f79
RD
141 'wxXmlResource',
142 'wxXmlResourceHandler',
9c67cbec
RD
143 ]),
144
145 # ditto
146 ('Process and Events', [
1e4a197e 147 'EventManager',
9c67cbec
RD
148 'infoframe',
149 'OOR',
150 'PythonEvents',
151 'Threads',
1e4a197e 152 'wxKeyEvents',
9c67cbec
RD
153 'wxProcess',
154 'wxTimer',
155 ]),
156
157 # Clipboard and DnD
158 ('Clipboard and DnD', [
159 'CustomDragAndDrop',
160 'DragAndDrop',
161 'URLDragAndDrop',
162 ]),
163
164 # Images
1e4a197e
RD
165 ('Using Images', [
166 'Throbber',
167 'wxArtProvider',
9c67cbec
RD
168 'wxDragImage',
169 'wxImage',
170 'wxImageFromStream',
171 'wxMask',
172 ]),
173
174 # Other stuff
175 ('Miscellaneous', [
176 'ColourDB',
177 'DialogUnits',
178 'DrawXXXList',
179 'FontEnumerator',
180 'PrintFramework',
1e4a197e 181 'Throbber',
9c67cbec
RD
182 'Unicode',
183 'wxFileHistory',
184 'wxJoystick',
185 'wxOGL',
186 'wxWave',
187 ]),
188
189 # need libs not coming with the demo
190 ('Objects using an external library', [
191 'ActiveXWrapper_Acrobat',
192 'ActiveXWrapper_IE',
193 'wxGLCanvas',
194 'wxPlotCanvas',
9c67cbec
RD
195 ]),
196
70a357c2 197
9c67cbec
RD
198 ('Check out the samples dir too', [
199 ]),
200
9c67cbec
RD
201]
202
203
cf694132
RD
204
205#---------------------------------------------------------------------------
206
76bfdc78
RD
207class MyLog(wxPyLog):
208 def __init__(self, textCtrl, logTime=0):
209 wxPyLog.__init__(self)
210 self.tc = textCtrl
211 self.logTime = logTime
212
213 def DoLogString(self, message, timeStamp):
214 if self.logTime:
215 message = time.strftime("%X", time.localtime(timeStamp)) + \
216 ": " + message
1e4a197e
RD
217 if self.tc:
218 self.tc.AppendText(message + '\n')
76bfdc78
RD
219
220
861a0196
RD
221class MyTP(wxPyTipProvider):
222 def GetTip(self):
223 return "This is my tip"
224
6c5ae2d2
RD
225#---------------------------------------------------------------------------
226
227def opj(path):
228 """Convert paths to the platform-specific separator"""
1e4a197e 229 return apply(os.path.join, tuple(path.split('/')))
6c5ae2d2
RD
230
231
76bfdc78
RD
232#---------------------------------------------------------------------------
233
cf694132 234class wxPythonDemo(wxFrame):
e9159fe8 235 overviewText = "wxPython Overview"
c368d904 236
cf694132 237 def __init__(self, parent, id, title):
f6bcfd97
BP
238 wxFrame.__init__(self, parent, -1, title, size = (800, 600),
239 style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
2f90df85 240
694759cf 241 self.cwd = os.getcwd()
3ca6a5f0 242 self.curOverview = ""
1e4a197e 243 self.window = None
694759cf 244
afb810d9 245 icon = images.getMondrianIcon()
96bfd053 246 self.SetIcon(icon)
c368d904 247
96bfd053 248 if wxPlatform == '__WXMSW__':
c368d904
RD
249 # setup a taskbar icon, and catch some events from it
250 self.tbicon = wxTaskBarIcon()
251 self.tbicon.SetIcon(icon, "wxPython Demo")
252 EVT_TASKBAR_LEFT_DCLICK(self.tbicon, self.OnTaskBarActivate)
253 EVT_TASKBAR_RIGHT_UP(self.tbicon, self.OnTaskBarMenu)
254 EVT_MENU(self.tbicon, self.TBMENU_RESTORE, self.OnTaskBarActivate)
255 EVT_MENU(self.tbicon, self.TBMENU_CLOSE, self.OnTaskBarClose)
256
1e4a197e 257 wxCallAfter(self.ShowTip)
cf694132
RD
258
259 self.otherWin = None
260 EVT_IDLE(self, self.OnIdle)
f6bcfd97 261 EVT_CLOSE(self, self.OnCloseWindow)
f3d9dc1d
RD
262 EVT_ICONIZE(self, self.OnIconfiy)
263 EVT_MAXIMIZE(self, self.OnMaximize)
cf694132
RD
264
265 self.Centre(wxBOTH)
266 self.CreateStatusBar(1, wxST_SIZEGRIP)
5a7823f5 267
f6bcfd97
BP
268 splitter = wxSplitterWindow(self, -1, style=wxNO_3D|wxSP_3D)
269 splitter2 = wxSplitterWindow(splitter, -1, style=wxNO_3D|wxSP_3D)
5a7823f5 270
d56cebe7
RD
271 def EmptyHandler(evt): pass
272 EVT_ERASE_BACKGROUND(splitter, EmptyHandler)
273 EVT_ERASE_BACKGROUND(splitter2, EmptyHandler)
cf694132 274
1e4a197e
RD
275 # Prevent TreeCtrl from displaying all items after destruction when True
276 self.dying = False
cf694132
RD
277
278 # Make a File menu
279 self.mainmenu = wxMenuBar()
280 menu = wxMenu()
2f90df85 281 exitID = wxNewId()
f0261a72 282 menu.Append(exitID, 'E&xit\tAlt-X', 'Get the heck outta here!')
2f90df85 283 EVT_MENU(self, exitID, self.OnFileExit)
1e4a197e 284 wxApp_SetMacExitMenuItemId(exitID)
cf694132
RD
285 self.mainmenu.Append(menu, '&File')
286
ec3e670f
RD
287 # Make a Demo menu
288 menu = wxMenu()
289 for item in _treeList:
290 submenu = wxMenu()
291 for childItem in item[1]:
292 mID = wxNewId()
293 submenu.Append(mID, childItem)
294 EVT_MENU(self, mID, self.OnDemoMenu)
295 menu.AppendMenu(wxNewId(), item[0], submenu)
296 self.mainmenu.Append(menu, '&Demo')
297
298
cf694132 299 # Make a Help menu
2f90df85 300 helpID = wxNewId()
1e4a197e
RD
301 findID = wxNewId()
302 findnextID = wxNewId()
cf694132 303 menu = wxMenu()
1e4a197e
RD
304 menu.Append(findID, '&Find\tCtrl-F', 'Find in the Demo Code')
305 menu.Append(findnextID, 'Find &Next\tF3', 'Find Next')
306 menu.AppendSeparator()
2f90df85 307 menu.Append(helpID, '&About\tCtrl-H', 'wxPython RULES!!!')
1e4a197e 308 wxApp_SetMacAboutMenuItemId(helpID)
2f90df85 309 EVT_MENU(self, helpID, self.OnHelpAbout)
1e4a197e
RD
310 EVT_MENU(self, findID, self.OnHelpFind)
311 EVT_MENU(self, findnextID, self.OnFindNext)
312 EVT_COMMAND_FIND(self, -1, self.OnFind)
313 EVT_COMMAND_FIND_NEXT(self, -1, self.OnFind)
314 EVT_COMMAND_FIND_CLOSE(self, -1 , self.OnFindClose)
cf694132
RD
315 self.mainmenu.Append(menu, '&Help')
316 self.SetMenuBar(self.mainmenu)
317
1e4a197e
RD
318 self.finddata = wxFindReplaceData()
319
320 if 0:
321 # This is another way to set Accelerators, in addition to
322 # using the '\t<key>' syntax in the menu items.
323 aTable = wxAcceleratorTable([(wxACCEL_ALT, ord('X'), exitID),
324 (wxACCEL_CTRL, ord('H'), helpID),
325 (wxACCEL_CTRL, ord('F'), findID),
326 (wxACCEL_NORMAL, WXK_F3, findnextID)])
327 self.SetAcceleratorTable(aTable)
2f90df85 328
bb0054cd 329
cf694132 330 # Create a TreeCtrl
f6bcfd97
BP
331 tID = wxNewId()
332 self.treeMap = {}
333 self.tree = wxTreeCtrl(splitter, tID,
334 style=wxTR_HAS_BUTTONS |
eb0f373c
RD
335 wxTR_HAS_VARIABLE_ROW_HEIGHT
336 )
afb810d9 337
f6bcfd97 338 #self.tree.SetBackgroundColour(wxNamedColour("Pink"))
e9159fe8 339 root = self.tree.AddRoot("wxPython Overview")
f6bcfd97
BP
340 firstChild = None
341 for item in _treeList:
342 child = self.tree.AppendItem(root, item[0])
343 if not firstChild: firstChild = child
344 for childItem in item[1]:
345 theDemo = self.tree.AppendItem(child, childItem)
346 self.treeMap[childItem] = theDemo
347
348 self.tree.Expand(root)
349 self.tree.Expand(firstChild)
350 EVT_TREE_ITEM_EXPANDED (self.tree, tID, self.OnItemExpanded)
351 EVT_TREE_ITEM_COLLAPSED (self.tree, tID, self.OnItemCollapsed)
352 EVT_TREE_SEL_CHANGED (self.tree, tID, self.OnSelChanged)
353 EVT_LEFT_DOWN (self.tree, self.OnTreeLeftDown)
cf694132 354
cf694132 355 # Create a Notebook
d56cebe7 356 self.nb = wxNotebook(splitter2, -1, style=wxCLIP_CHILDREN)
cf694132 357
c368d904 358 # Set up a wxHtmlWindow on the Overview Notebook page
0bdca46d
RD
359 # we put it in a panel first because there seems to be a
360 # refresh bug of some sort (wxGTK) when it is directly in
361 # the notebook...
362 if 0: # the old way
363 self.ovr = wxHtmlWindow(self.nb, -1, size=(400, 400))
364 self.nb.AddPage(self.ovr, self.overviewText)
365
366 else: # hopefully I can remove this hacky code soon, see bug #216861
367 panel = wxPanel(self.nb, -1, style=wxCLIP_CHILDREN)
368 self.ovr = wxHtmlWindow(panel, -1, size=(400, 400))
369 self.nb.AddPage(panel, self.overviewText)
370
371 def OnOvrSize(evt, ovr=self.ovr):
372 ovr.SetSize(evt.GetSize())
373
374 EVT_SIZE(panel, OnOvrSize)
375 EVT_ERASE_BACKGROUND(panel, EmptyHandler)
376
c368d904 377
e9159fe8 378 self.SetOverview(self.overviewText, overview)
cf694132
RD
379
380
381 # Set up a TextCtrl on the Demo Code Notebook page
efc5f224 382 self.txt = wxTextCtrl(self.nb, -1,
1e4a197e
RD
383 style = wxTE_MULTILINE|wxTE_READONLY|
384 wxHSCROLL|wxTE_RICH2|wxTE_NOHIDESEL)
cf694132
RD
385 self.nb.AddPage(self.txt, "Demo Code")
386
387
cf694132 388 # Set up a log on the View Log Notebook page
f6bcfd97 389 self.log = wxTextCtrl(splitter2, -1,
efc5f224 390 style = wxTE_MULTILINE|wxTE_READONLY|wxHSCROLL)
342639eb 391
f6bcfd97 392 # Set the wxWindows log target to be this textctrl
76bfdc78 393 #wxLog_SetActiveTarget(wxLogTextCtrl(self.log))
342639eb
RD
394
395 # But instead of the above we want to show how to use our own wxLog class
76bfdc78 396 wxLog_SetActiveTarget(MyLog(self.log))
cf694132 397
f9b24f07
RD
398 # for serious debugging
399 #wxLog_SetActiveTarget(wxLogStderr())
400 #wxLog_SetTraceMask(wxTraceMessages)
5a7823f5 401
1e4a197e 402 self.Show(True)
5a7823f5 403
f9b24f07 404
f6bcfd97 405 # add the windows to the splitter and split it.
1e4a197e
RD
406 splitter2.SplitHorizontally(self.nb, self.log, 450)
407 splitter.SplitVertically(self.tree, splitter2, 180)
afb810d9 408
f6bcfd97 409 splitter.SetMinimumPaneSize(20)
afb810d9
RD
410 splitter2.SetMinimumPaneSize(20)
411
cf694132 412
cf694132 413
bb0054cd
RD
414 # select initial items
415 self.nb.SetSelection(0)
f6bcfd97 416 self.tree.SelectItem(root)
ec3e670f
RD
417
418 if len(sys.argv) == 2:
419 try:
420 selectedDemo = self.treeMap[sys.argv[1]]
421 except:
422 selectedDemo = None
f6bcfd97 423 if selectedDemo:
ec3e670f
RD
424 self.tree.SelectItem(selectedDemo)
425 self.tree.EnsureVisible(selectedDemo)
426
bb0054cd 427
f6bcfd97 428 wxLogMessage('window handle: %s' % self.GetHandle())
2abc0a0f
RD
429
430
cf694132
RD
431 #---------------------------------------------
432 def WriteText(self, text):
f6bcfd97
BP
433 if text[-1:] == '\n':
434 text = text[:-1]
435 wxLogMessage(text)
436
cf694132
RD
437
438 def write(self, txt):
439 self.WriteText(txt)
440
441 #---------------------------------------------
442 def OnItemExpanded(self, event):
443 item = event.GetItem()
f6bcfd97 444 wxLogMessage("OnItemExpanded: %s" % self.tree.GetItemText(item))
c368d904 445 event.Skip()
cf694132
RD
446
447 #---------------------------------------------
448 def OnItemCollapsed(self, event):
449 item = event.GetItem()
f6bcfd97 450 wxLogMessage("OnItemCollapsed: %s" % self.tree.GetItemText(item))
c368d904 451 event.Skip()
f6bcfd97
BP
452
453 #---------------------------------------------
454 def OnTreeLeftDown(self, event):
455 pt = event.GetPosition();
456 item, flags = self.tree.HitTest(pt)
457 if item == self.tree.GetSelection():
d975da9b 458 self.SetOverview(self.tree.GetItemText(item)+" Overview", self.curOverview)
185d7c3e 459 event.Skip()
cf694132
RD
460
461 #---------------------------------------------
462 def OnSelChanged(self, event):
463 if self.dying:
464 return
465
5a7823f5
RD
466 item = event.GetItem()
467 itemText = self.tree.GetItemText(item)
468 self.RunDemo(itemText)
469
470
471 #---------------------------------------------
472 def RunDemo(self, itemText):
694759cf 473 os.chdir(self.cwd)
cf694132
RD
474 if self.nb.GetPageCount() == 3:
475 if self.nb.GetSelection() == 2:
476 self.nb.SetSelection(0)
1e4a197e
RD
477 # inform the window that it's time to quit if it cares
478 if self.window is not None:
479 if hasattr(self.window, "ShutdownDemo"):
480 self.window.ShutdownDemo()
481 wxSafeYield() # in case the page has pending events
cf694132
RD
482 self.nb.DeletePage(2)
483
e9159fe8 484 if itemText == self.overviewText:
cf694132 485 self.GetDemoFile('Main.py')
e9159fe8 486 self.SetOverview(self.overviewText, overview)
cf694132 487 self.nb.Refresh();
e91a9dfc 488 self.window = None
cf694132
RD
489
490 else:
491 if os.path.exists(itemText + '.py'):
9d8bd15f 492 wxBeginBusyCursor()
f6bcfd97
BP
493 wxLogMessage("Running demo %s.py..." % itemText)
494 try:
495 self.GetDemoFile(itemText + '.py')
496 module = __import__(itemText, globals())
e9159fe8 497 self.SetOverview(itemText + " Overview", module.overview)
f6bcfd97
BP
498 finally:
499 wxEndBusyCursor()
5a1eefc7 500 self.tree.Refresh()
cf694132
RD
501
502 # in case runTest is modal, make sure things look right...
503 self.nb.Refresh();
5a1eefc7 504 wxSafeYield()
cf694132 505
f6bcfd97 506 self.window = module.runTest(self, self.nb, self) ###
1e4a197e 507 if self.window is not None:
e91a9dfc 508 self.nb.AddPage(self.window, 'Demo')
cf694132 509 self.nb.SetSelection(2)
eb28fd47 510 self.nb.Refresh() # without this wxMac has troubles showing the just added page
cf694132
RD
511
512 else:
f6bcfd97 513 self.ovr.SetPage("")
cf694132 514 self.txt.Clear()
e91a9dfc 515 self.window = None
cf694132 516
2f90df85 517
cf694132
RD
518
519 #---------------------------------------------
520 # Get the Demo files
521 def GetDemoFile(self, filename):
522 self.txt.Clear()
bb0054cd
RD
523 try:
524 self.txt.SetValue(open(filename).read())
8bf5d46e 525 except IOError:
cf694132
RD
526 self.txt.WriteText("Cannot open %s file." % filename)
527
528 self.txt.SetInsertionPoint(0)
529 self.txt.ShowPosition(0)
530
531 #---------------------------------------------
532 def SetOverview(self, name, text):
f6bcfd97
BP
533 self.curOverview = text
534 lead = text[:6]
535 if lead != '<html>' and lead != '<HTML>':
1e4a197e 536 text = '<br>'.join(text.split('\n'))
f6bcfd97 537 self.ovr.SetPage(text)
cf694132 538 self.nb.SetPageText(0, name)
cf694132
RD
539
540 #---------------------------------------------
541 # Menu methods
c368d904 542 def OnFileExit(self, *event):
cf694132
RD
543 self.Close()
544
cf694132 545 def OnHelpAbout(self, event):
e166644c 546 from About import MyAboutBox
ec3e670f 547 about = MyAboutBox(self)
cf694132
RD
548 about.ShowModal()
549 about.Destroy()
550
1e4a197e
RD
551 def OnHelpFind(self, event):
552 self.nb.SetSelection(1)
553 self.finddlg = wxFindReplaceDialog(self, self.finddata, "Find",
554 wxFR_NOUPDOWN |
555 wxFR_NOMATCHCASE |
556 wxFR_NOWHOLEWORD)
557 self.finddlg.Show(True)
558
559 def OnFind(self, event):
560 self.nb.SetSelection(1)
561 end = self.txt.GetLastPosition()
562 textstring = self.txt.GetRange(0, end).lower()
563 start = self.txt.GetSelection()[1]
564 findstring = self.finddata.GetFindString().lower()
565 loc = textstring.find(findstring, start)
566 if loc == -1 and start != 0:
567 # string not found, start at beginning
568 start = 0
569 loc = textstring.find(findstring, start)
570 if loc == -1:
571 dlg = wxMessageDialog(self, 'Find String Not Found',
572 'Find String Not Found in Demo File',
573 wxOK | wxICON_INFORMATION)
574 dlg.ShowModal()
575 dlg.Destroy()
576 if self.finddlg:
577 if loc == -1:
578 self.finddlg.SetFocus()
579 return
580 else:
581 self.finddlg.Destroy()
582 self.txt.SetSelection(loc, loc + len(findstring))
583 self.txt.ShowPosition(loc)
584
585
586
587 def OnFindNext(self, event):
588 if self.finddata.GetFindString():
589 self.OnFind(event)
590 else:
591 self.OnHelpFind(event)
592
593 def OnFindClose(self, event):
594 event.GetDialog().Destroy()
595
cf694132
RD
596
597 #---------------------------------------------
598 def OnCloseWindow(self, event):
1e4a197e 599 self.dying = True
e91a9dfc 600 self.window = None
26197023 601 self.mainmenu = None
c368d904
RD
602 if hasattr(self, "tbicon"):
603 del self.tbicon
cf694132
RD
604 self.Destroy()
605
c368d904 606
cf694132
RD
607 #---------------------------------------------
608 def OnIdle(self, event):
609 if self.otherWin:
610 self.otherWin.Raise()
e91a9dfc 611 self.window = self.otherWin
cf694132
RD
612 self.otherWin = None
613
ccf691a4
RD
614
615 #---------------------------------------------
616 def ShowTip(self):
617 try:
618 showTipText = open(opj("data/showTips")).read()
619 showTip, index = eval(showTipText)
620 except IOError:
621 showTip, index = (1, 0)
622 if showTip:
623 tp = wxCreateFileTipProvider(opj("data/tips.txt"), index)
861a0196 624 ##tp = MyTP(0)
ccf691a4
RD
625 showTip = wxShowTip(self, tp)
626 index = tp.GetCurrentTip()
627 open(opj("data/showTips"), "w").write(str( (showTip, index) ))
628
629
ec3e670f
RD
630 #---------------------------------------------
631 def OnDemoMenu(self, event):
f6bcfd97
BP
632 try:
633 selectedDemo = self.treeMap[self.mainmenu.GetLabel(event.GetId())]
634 except:
635 selectedDemo = None
636 if selectedDemo:
637 self.tree.SelectItem(selectedDemo)
638 self.tree.EnsureVisible(selectedDemo)
ec3e670f 639
c368d904
RD
640
641 #---------------------------------------------
642 def OnTaskBarActivate(self, evt):
643 if self.IsIconized():
1e4a197e 644 self.Iconize(False)
c368d904 645 if not self.IsShown():
1e4a197e 646 self.Show(True)
c368d904
RD
647 self.Raise()
648
649 #---------------------------------------------
650
651 TBMENU_RESTORE = 1000
652 TBMENU_CLOSE = 1001
653
654 def OnTaskBarMenu(self, evt):
655 menu = wxMenu()
656 menu.Append(self.TBMENU_RESTORE, "Restore wxPython Demo")
657 menu.Append(self.TBMENU_CLOSE, "Close")
658 self.tbicon.PopupMenu(menu)
659 menu.Destroy()
660
661 #---------------------------------------------
662 def OnTaskBarClose(self, evt):
663 self.Close()
664
665 # because of the way wxTaskBarIcon.PopupMenu is implemented we have to
666 # prod the main idle handler a bit to get the window to actually close
667 wxGetApp().ProcessIdle()
668
669
f3d9dc1d
RD
670 #---------------------------------------------
671 def OnIconfiy(self, evt):
672 wxLogMessage("OnIconfiy")
673 evt.Skip()
674
675 #---------------------------------------------
676 def OnMaximize(self, evt):
677 wxLogMessage("OnMaximize")
678 evt.Skip()
679
680
681
682
cf694132
RD
683#---------------------------------------------------------------------------
684#---------------------------------------------------------------------------
685
b5a5d647
RD
686class MySplashScreen(wxSplashScreen):
687 def __init__(self):
6c5ae2d2 688 bmp = wxImage(opj("bitmaps/splash.gif")).ConvertToBitmap()
b5a5d647
RD
689 wxSplashScreen.__init__(self, bmp,
690 wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT,
40c4c5a3
RD
691 4000, None, -1,
692 style = wxSIMPLE_BORDER|wxFRAME_NO_TASKBAR|wxSTAY_ON_TOP)
b5a5d647
RD
693 EVT_CLOSE(self, self.OnClose)
694
695 def OnClose(self, evt):
9fb56e0c 696 frame = wxPythonDemo(None, -1, "wxPython: (A Demonstration)")
1e4a197e 697 frame.Show()
ccf691a4 698 evt.Skip() # Make sure the default handler runs too...
cf694132 699
b5a5d647
RD
700
701class MyApp(wxApp):
702 def OnInit(self):
703 """
68320e40 704 Create and show the splash screen. It will then create and show
b5a5d647
RD
705 the main frame when it is time to do so.
706 """
1e4a197e
RD
707
708 #import locale
709 #self.locale = wxLocale(wxLANGUAGE_FRENCH)
710 #locale.setlocale(locale.LC_ALL, 'fr')
711
b5a5d647
RD
712 wxInitAllImageHandlers()
713 splash = MySplashScreen()
714 splash.Show()
1e4a197e 715 return True
b5a5d647
RD
716
717
718
cf694132
RD
719#---------------------------------------------------------------------------
720
721def main():
e02c03a4 722 try:
d56cebe7 723 demoPath = os.path.dirname(__file__)
e02c03a4
RD
724 os.chdir(demoPath)
725 except:
726 pass
606d919c 727 app = MyApp(wxPlatform == "__WXMAC__")
cf694132
RD
728 app.MainLoop()
729
730
731#---------------------------------------------------------------------------
732
733
734
f6bcfd97
BP
735overview = """<html><body>
736 <h2>Python</h2>
737
738 Python is an interpreted, interactive, object-oriented programming
739 language often compared to Tcl, Perl, Scheme, or Java.
740
741 <p> Python combines remarkable power with very clear syntax. It has
742 modules, classes, exceptions, very high level dynamic data types, and
743 dynamic typing. There are interfaces to many system calls and
744 libraries, and new built-in modules are easily written in C or
745 C++. Python is also usable as an extension language for applications
746 that need a programmable interface. <p>
747
748 <h2>wxWindows</h2>
749
750 wxWindows is a free C++ framework designed to make cross-platform
751 programming child's play. Well, almost. wxWindows 2 supports Windows
752 3.1/95/98/NT, Unix with GTK/Motif/Lesstif, with a Mac version
753 underway. Other ports are under consideration. <p>
754
755 wxWindows is a set of libraries that allows C++ applications to
756 compile and run on several different types of computers, with minimal
757 source code changes. There is one library per supported GUI (such as
758 Motif, or Windows). As well as providing a common API (Application
759 Programming Interface) for GUI functionality, it provides
760 functionality for accessing some commonly-used operating system
761 facilities, such as copying or deleting files. wxWindows is a
762 'framework' in the sense that it provides a lot of built-in
763 functionality, which the application can use or replace as required,
764 thus saving a great deal of coding effort. Basic data structures such
765 as strings, linked lists and hash tables are also supported.
766
767 <p>
768 <h2>wxPython</h2>
769
770 wxPython is a Python extension module that encapsulates the wxWindows
771 GUI classes. Currently it is only available for the Win32 and GTK
772 ports of wxWindows, but as soon as the other ports are brought up to
773 the same level as Win32 and GTK, it should be fairly trivial to
774 enable wxPython to be used with the new GUI.
775
776 <p>
777
778 The wxPython extension module attempts to mirror the class heiarchy
779 of wxWindows as closely as possible. This means that there is a
780 wxFrame class in wxPython that looks, smells, tastes and acts almost
781 the same as the wxFrame class in the C++ version. Unfortunately,
782 because of differences in the languages, wxPython doesn't match
783 wxWindows exactly, but the differences should be easy to absorb
784 because they are natural to Python. For example, some methods that
785 return multiple values via argument pointers in C++ will return a
786 tuple of values in Python.
787
788 <p>
789
790 There is still much to be done for wxPython, many classes still need
791 to be mirrored. Also, wxWindows is still somewhat of a moving target
792 so it is a bit of an effort just keeping wxPython up to date. On the
793 other hand, there are enough of the core classes completed that
794 useful applications can be written.
795
796 <p>
797
798 wxPython is close enough to the C++ version that the majority of
799 the wxPython documentation is actually just notes attached to the C++
800 documents that describe the places where wxPython is different. There
801 is also a series of sample programs included, and a series of
802 documentation pages that assist the programmer in getting started
803 with wxPython.
804
805 """
cf694132
RD
806
807
808#----------------------------------------------------------------------------
809#----------------------------------------------------------------------------
810
811if __name__ == '__main__':
812 main()
813
814#----------------------------------------------------------------------------
815
816
817
818
819
820
821