Ver Mensaje Individual
  #3 (permalink)  
Antiguo 25/02/2009, 19:43
iozk
 
Fecha de Ingreso: mayo-2008
Mensajes: 499
Antigüedad: 16 años
Puntos: 1
Respuesta: ayuda!!! con codigo

run.py
Código pythom:
Ver original
  1. #!/usr/bin/env python
  2. #----------------------------------------------------------------------------
  3. # Name:         run.py
  4. # Purpose:      Simple framework for running individual demos
  5. #
  6. # Author:       Robin Dunn
  7. #
  8. # Created:      6-March-2000
  9. # RCS-ID:       $Id: run.py 53286 2008-04-21 15:33:51Z RD $
  10. # Copyright:    (c) 2000 by Total Control Software
  11. # Licence:      wxWindows license
  12. #----------------------------------------------------------------------------
  13.  
  14. """
  15. This program will load and run one of the individual demos in this
  16. directory within its own frame window.  Just specify the module name
  17. on the command line.
  18. """
  19.  
  20. import wx
  21. import wx.lib.inspection
  22. import wx.lib.mixins.inspection
  23. import sys, os
  24.  
  25. # stuff for debugging
  26. print "wx.version:", wx.version()
  27. print "pid:", os.getpid()
  28. ##raw_input("Press Enter...")
  29.  
  30. assertMode = wx.PYAPP_ASSERT_DIALOG
  31. ##assertMode = wx.PYAPP_ASSERT_EXCEPTION
  32.  
  33.  
  34. #----------------------------------------------------------------------------
  35.  
  36. class Log:
  37.     def WriteText(self, text):
  38.         if text[-1:] == '\n':
  39.             text = text[:-1]
  40.         wx.LogMessage(text)
  41.     write = WriteText
  42.  
  43.  
  44. class RunDemoApp(wx.App, wx.lib.mixins.inspection.InspectionMixin):
  45.     def __init__(self, name, module, useShell):
  46.         self.name = name
  47.         self.demoModule = module
  48.         self.useShell = useShell
  49.         wx.App.__init__(self, redirect=False)
  50.  
  51.  
  52.     def OnInit(self):
  53.         wx.Log_SetActiveTarget(wx.LogStderr())
  54.  
  55.         self.SetAssertMode(assertMode)
  56.         self.Init()  # InspectionMixin
  57.  
  58.         frame = wx.Frame(None, -1, "RunDemo: " + self.name, pos=(50,50), size=(200,100),
  59.                         style=wx.DEFAULT_FRAME_STYLE, name="run a sample")
  60.         frame.CreateStatusBar()
  61.  
  62.         menuBar = wx.MenuBar()
  63.         menu = wx.Menu()
  64.         item = menu.Append(-1, "&Widget Inspector\tF6", "Show the wxPython Widget Inspection Tool")
  65.         self.Bind(wx.EVT_MENU, self.OnWidgetInspector, item)
  66.         item = menu.Append(-1, "E&xit\tCtrl-Q", "Exit demo")
  67.         self.Bind(wx.EVT_MENU, self.OnExitApp, item)
  68.         menuBar.Append(menu, "&File")
  69.  
  70.         ns = {}
  71.         ns['wx'] = wx
  72.         ns['app'] = self
  73.         ns['module'] = self.demoModule
  74.         ns['frame'] = frame
  75.        
  76.         frame.SetMenuBar(menuBar)
  77.         frame.Show(True)
  78.         frame.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
  79.  
  80.         win = self.demoModule.runTest(frame, frame, Log())
  81.  
  82.         # a window will be returned if the demo does not create
  83.         # its own top-level window
  84.         if win:
  85.             # so set the frame to a good size for showing stuff
  86.             frame.SetSize((640, 480))
  87.             win.SetFocus()
  88.             self.window = win
  89.             ns['win'] = win
  90.             frect = frame.GetRect()
  91.  
  92.         else:
  93.             # It was probably a dialog or something that is already
  94.             # gone, so we're done.
  95.             frame.Destroy()
  96.             return True
  97.  
  98.         self.SetTopWindow(frame)
  99.         self.frame = frame
  100.         #wx.Log_SetActiveTarget(wx.LogStderr())
  101.         #wx.Log_SetTraceMask(wx.TraceMessages)
  102.  
  103.         if self.useShell:
  104.             # Make a PyShell window, and position it below our test window
  105.             from wx import py
  106.             shell = py.shell.ShellFrame(None, locals=ns)
  107.             frect.OffsetXY(0, frect.height)
  108.             frect.height = 400
  109.             shell.SetRect(frect)
  110.             shell.Show()
  111.  
  112.             # Hook the close event of the test window so that we close
  113.             # the shell at the same time
  114.             def CloseShell(evt):
  115.                 if shell:
  116.                     shell.Close()
  117.                 evt.Skip()
  118.             frame.Bind(wx.EVT_CLOSE, CloseShell)
  119.                    
  120.         return True
  121.  
  122.  
  123.     def OnExitApp(self, evt):
  124.         self.frame.Close(True)
  125.  
  126.  
  127.     def OnCloseFrame(self, evt):
  128.         if hasattr(self, "window") and hasattr(self.window, "ShutdownDemo"):
  129.             self.window.ShutdownDemo()
  130.         evt.Skip()
  131.  
  132.     def OnWidgetInspector(self, evt):
  133.         wx.lib.inspection.InspectionTool().Show()
  134.    
  135.  
  136. #----------------------------------------------------------------------------
  137.  
  138.  
  139. def main(argv):
  140.     useShell = False
  141.     for x in range(len(sys.argv)):
  142.         if sys.argv[x] in ['--shell', '-shell', '-s']:
  143.             useShell = True
  144.             del sys.argv[x]
  145.             break
  146.            
  147.     if len(argv) < 2:
  148.         print "Please specify a demo module name on the command-line"
  149.         raise SystemExit
  150.  
  151.     name, ext  = os.path.splitext(argv[1])
  152.     module = __import__(name)
  153.  
  154.  
  155.     app = RunDemoApp(name, module, useShell)
  156.     app.MainLoop()
  157.  
  158.  
  159.  
  160. if __name__ == "__main__":
  161.     main(sys.argv)