]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/demo/run.py
support Show() in wxFlexGridSizer (patch 737850)
[wxWidgets.git] / wxPython / demo / run.py
index c58a9a86f084439632bbaf9dc38caee47b968c1d..fcf5bd902992fc9e2af202921870ef4492fbae11 100755 (executable)
@@ -18,14 +18,16 @@ on the command line.
 """
 
 
-import sys
+import sys, os
 from wxPython.wx import *
 
 #----------------------------------------------------------------------------
 
 class Log:
     def WriteText(self, text):
-        sys.stdout.write(text)
+        if text[-1:] == '\n':
+            text = text[:-1]
+        wxLogMessage(text)
     write = WriteText
 
 
@@ -33,14 +35,25 @@ class RunDemoApp(wxApp):
     def __init__(self, name, module):
         self.name = name
         self.demoModule = module
-        wxApp.__init__(self, 0)
+        wxApp.__init__(self, 0) ##wxPlatform == "__WXMAC__")
+
 
     def OnInit(self):
         wxInitAllImageHandlers()
-        frame = wxFrame(None, -1, "RunDemo: " + self.name, size=(0,0),
+        wxLog_SetActiveTarget(wxLogStderr())
+
+        frame = wxFrame(None, -1, "RunDemo: " + self.name, pos=(50,50), size=(0,0),
                         style=wxNO_FULL_REPAINT_ON_RESIZE|wxDEFAULT_FRAME_STYLE)
         frame.CreateStatusBar()
-        frame.Show(true)
+        menuBar = wxMenuBar()
+        menu = wxMenu()
+        menu.Append(101, "E&xit\tAlt-X", "Exit demo")
+        EVT_MENU(self, 101, self.OnButton)
+        menuBar.Append(menu, "&File")
+        frame.SetMenuBar(menuBar)
+        frame.Show(True)
+        EVT_CLOSE(frame, self.OnCloseFrame)
+
         win = self.demoModule.runTest(frame, frame, Log())
 
         # a window will be returned if the demo does not create
@@ -49,33 +62,43 @@ class RunDemoApp(wxApp):
             # so set the frame to a good size for showing stuff
             frame.SetSize((640, 480))
             win.SetFocus()
+            self.window = win
 
         else:
             # otherwise the demo made its own frame, so just put a
             # button in this one
             if hasattr(frame, 'otherWin'):
-                wxButton(frame, 1101, " Exit ")
+                b = wxButton(frame, -1, " Exit ")
                 frame.SetSize((200, 100))
-                EVT_BUTTON(frame, 1101, self.OnButton)
+                EVT_BUTTON(frame, b.GetId(), self.OnButton)
             else:
                 # It was probably a dialog or something that is already
                 # gone, so we're done.
                 frame.Destroy()
-                return true
+                return True
 
         self.SetTopWindow(frame)
         self.frame = frame
-        return true
+        #wxLog_SetActiveTarget(wxLogStderr())
+        #wxLog_SetTraceMask(wxTraceMessages)
+        return True
 
 
     def OnButton(self, evt):
-        self.frame.Close(true)
+        self.frame.Close(True)
+
+
+    def OnCloseFrame(self, evt):
+        if hasattr(self, "window") and hasattr(self.window, "ShutdownDemo"):
+            self.window.ShutdownDemo()
+        evt.Skip()
+
 
 #----------------------------------------------------------------------------
 
 
 def main(argv):
-    if len(argv) != 2:
+    if len(argv) < 2:
         print "Please specify a demo module name on the command-line"
         raise SystemExit