]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/demo/infoframe.py
Applied [ 828322 ] Use gdk_draw_polygon for the outline in DoDrawPolygon
[wxWidgets.git] / wxPython / demo / infoframe.py
index 99507a654725318a571c4d1e8ca9353570f494bf..a9d71f950bd0cdf6d1ed91b633afa28984233052 100644 (file)
@@ -1,48 +1,87 @@
-
-from wxPython.wx import *
-from wxPython.lib.infoframe import *
+# 11/12/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Updated for wx namespace
+# o wx module doesn't like the doc string.
+#
+# 11/25/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o Library didn't get hit by the wx renamer.
+# o Docstring issues resolved.
+#
+
+import  sys
+
+import  wx
+import  wx.lib.infoframe as infoframe
 
 #----------------------------------------------------------------------
 
 
 #----------------------------------------------------------------------
 
-class MyFrame(wxFrame):
-    def __init__(self,output):
-        wxFrame.__init__(self,None,-1,"Close me...",size=(300,100))
-        menubar = wxMenuBar()
-        menu = wxMenu()
-        mID = NewId()
-        menu.Append(mID,"&Enable output","Display output frame")
-        EVT_MENU(self,mID,output.EnableOutput)
-        mID = NewId()
-        menu.Append(mID,"&Disable output","Close output frame")
-        EVT_MENU(self,mID,output.DisableOutput)
-        menubar.Append(menu,"&Output")
+class MyFrame(wx.Frame):
+    def __init__(self, output):
+        wx.Frame.__init__(self, None, -1, "Close me...", size=(300,100))
+
+        menubar = wx.MenuBar()
+
+        # Output menu
+        menu = wx.Menu()
+
+        # Enable output menu item
+        mID = wx.NewId()
+        menu.Append(mID, "&Enable output", "Display output frame")
+        self.Bind(wx.EVT_MENU, output.EnableOutput, id=mID)
+
+        # Disable output menu item
+        mID = wx.NewId()
+        menu.Append(mID, "&Disable output", "Close output frame")
+        self.Bind(wx.EVT_MENU, output.DisableOutput, id=mID)
+
+        # Attach the menu to our menu bar
+        menubar.Append(menu, "&Output")
+        
+        # Attach menu bar to frame
         self.SetMenuBar(menubar)
         self.SetMenuBar(menubar)
+        
+        # Point to ourselves as the output object's parent.
         output.SetParent(self)
         output.SetParent(self)
-        output.SetOtherMenuBar(menubar,menuname="Output")
-        EVT_CLOSE(self,self.OnClose)
-        EVT_TIMER(self, -1, self.OnTimer)
+        
+        # Associate menu bar with output object
+        output.SetOtherMenuBar(menubar, menuname="Output")
 
 
-        self.timer = wxTimer(self, -1)
+        self.Bind(wx.EVT_CLOSE, self.OnClose)
+        # We're going to set up a timer; set up an event handler for it.
+        self.Bind(wx.EVT_TIMER, self.OnTimer)
+
+        # Set up a timer for demo purposes
+        self.timer = wx.Timer(self, -1)
         self.timer.Start(1000)
 
         self.timer.Start(1000)
 
+        # Get a copy of stdout and set it aside. We'll use it later.
         self.save_stdout = sys.stdout
         self.save_stdout = sys.stdout
+        
+        # Now point to the output object for stdout
         sys.stdout = self.output = output
         sys.stdout = self.output = output
+        # ... and use it.
         print "Hello!"
 
     def OnClose(self,event):
         print "Hello!"
 
     def OnClose(self,event):
+        # We stored a pointer to the original stdout above in .__init__(), and
+        # here we restore it before closing the window.
         sys.stdout = self.save_stdout
         sys.stdout = self.save_stdout
+
+        # Clean up
         self.output.close()
         self.timer.Stop()
         self.timer = None
         self.output.close()
         self.timer.Stop()
         self.timer = None
+
         self.Destroy()
 
         self.Destroy()
 
+    # Event handler for timer events.
     def OnTimer(self, evt):
         print "This was printed with \"print\""
 
 
 #----------------------------------------------------------------------
 
     def OnTimer(self, evt):
         print "This was printed with \"print\""
 
 
 #----------------------------------------------------------------------
 
-from wxPython.lib import infoframe
 overview = infoframe.__doc__
 
 def runTest(frame, nb, log):
 overview = infoframe.__doc__
 
 def runTest(frame, nb, log):
@@ -50,7 +89,7 @@ def runTest(frame, nb, log):
     This method is used by the wxPython Demo Framework for integrating
     this demo with the rest.
     """
     This method is used by the wxPython Demo Framework for integrating
     this demo with the rest.
     """
-    win = MyFrame(wxPyInformationalMessagesFrame())
+    win = MyFrame(infoframe.wxPyInformationalMessagesFrame())
     frame.otherWin = win
     win.Show(1)
 
     frame.otherWin = win
     win.Show(1)
 
@@ -63,10 +102,10 @@ if __name__ == "__main__":
 ##             EVT_CLOSE(self,self.OnClose)
 ##             menubar = wxMenuBar()
 ##             menu = wxMenu()
 ##             EVT_CLOSE(self,self.OnClose)
 ##             menubar = wxMenuBar()
 ##             menu = wxMenu()
-##             mID = NewId()
+##             mID = wxNewId()
 ##             menu.Append(mID,"&Enable output","Display output frame")
 ##             EVT_MENU(self,mID,output.EnableOutput)
 ##             menu.Append(mID,"&Enable output","Display output frame")
 ##             EVT_MENU(self,mID,output.EnableOutput)
-##             mID = NewId()
+##             mID = wxNewId()
 ##             menu.Append(mID,"&Disable output","Close output frame")
 ##             EVT_MENU(self,mID,output.DisableOutput)
 ##             menubar.Append(menu,"&Output")
 ##             menu.Append(mID,"&Disable output","Close output frame")
 ##             EVT_MENU(self,mID,output.DisableOutput)
 ##             menubar.Append(menu,"&Output")
@@ -78,18 +117,42 @@ if __name__ == "__main__":
 ##                 sys.stdout.close()
 ##             self.Destroy()
 
 ##                 sys.stdout.close()
 ##             self.Destroy()
 
-    class MyApp(wxApp):
-        outputWindowClass = wxPyInformationalMessagesFrame
+        # Override the default output window and point it to the
+        # custom class.
+        #>>Todo: wx renamer didn't get this
+        outputWindowClass = infoframe.wxPyInformationalMessagesFrame
+        
         def OnInit(self):
         def OnInit(self):
+            
+            # At this point, we should probably check to see if self.stdioWin
+            # is actually pointed to something. By default, wx.App() sets this
+            # attribute to None. This causes problems when setting up the menus
+            # in MyFrame() above. On the other hand, since there's little that
+            # can be done at this point, you might be better served putting
+            # an error handler directly into MyFrame().
+            #
+            # That's in practice. In the case of this demo, the whole point
+            # of the exercise is to demonstrate the window, so we're being 
+            # just a little lazy for clarity's sake. But do be careful in
+            # a 'real world' implementation :-)
+            
             frame = MyFrame(self.stdioWin)
             frame = MyFrame(self.stdioWin)
-            frame.Show(TRUE)
+            frame.Show(True)
             self.SetTopWindow(frame)
             self.SetTopWindow(frame)
-            if isinstance(sys.stdout,wxPyInformationalMessagesFrame):
+            
+            # Associate the frame with stdout.
+            #>>Todo: wx renamer didn't get this
+            if isinstance(sys.stdout, infoframe.wxPyInformationalMessagesFrame):
                 sys.stdout.SetParent(frame)
                 sys.stdout.SetParent(frame)
-                #self.redirectStdio(None)# this is done automatically
-                # by the MyApp(1) call below
-            print "Starting.\n",
-            return true
 
 
-    app = MyApp(1)
+            print "Starting.\n",
+            return True
+
+    # *extremely important*
+    # 
+    # In this demo, if the redirect flag is set to False, the infoframe will not
+    # be created or used. All output will go to the default stdout, which in this
+    # case will cause the app to throw an exception. In a real app, you should
+    # probably plan ahead and add a check before forging ahead. See suggestion above.
+    app = MyApp(True)
     app.MainLoop()
     app.MainLoop()