guidemo.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # GUI Demo - just a worker script to invoke all the other demo/test scripts.
  2. import win32ui
  3. import __main__
  4. import sys
  5. import regutil
  6. import win32api
  7. demos = [ \
  8. # ('Font', 'import fontdemo;fontdemo.FontDemo()'),
  9. ('Open GL Demo', 'import openGLDemo;openGLDemo.test()'),
  10. ('Threaded GUI', 'import threadedgui;threadedgui.ThreadedDemo()'),
  11. ('Tree View Demo', 'import hiertest;hiertest.demoboth()'),
  12. ('3-Way Splitter Window', 'import splittst;splittst.demo()'),
  13. ('Custom Toolbars and Tooltips', 'import toolbar;toolbar.test()'),
  14. ('Progress Bar', 'import progressbar;progressbar.demo()'),
  15. ('Slider Control', 'import sliderdemo;sliderdemo.demo()'),
  16. ('Dynamic window creation', 'import createwin;createwin.demo()'),
  17. ('Various Dialog demos', 'import dlgtest;dlgtest.demo()'),
  18. ('OCX Control Demo', 'from ocx import ocxtest;ocxtest.demo()'),
  19. ('OCX Serial Port Demo', 'from ocx import ocxserialtest; ocxserialtest.test()'),
  20. ('IE4 Control Demo', 'from ocx import webbrowser; webbrowser.Demo("http://www.python.org")'),
  21. ]
  22. def demo():
  23. try:
  24. # seeif I can locate the demo files.
  25. import fontdemo
  26. except ImportError:
  27. # else put the demos direectory on the path (if not already)
  28. try:
  29. instPath = regutil.GetRegistryDefaultValue(regutil.BuildDefaultPythonKey() + "\\InstallPath")
  30. except win32api.error:
  31. print("The InstallPath can not be located, and the Demos directory is not on the path")
  32. instPath="."
  33. demosDir = win32ui.FullPath(instPath + "\\Demos")
  34. for path in sys.path:
  35. if win32ui.FullPath(path)==demosDir:
  36. break
  37. else:
  38. sys.path.append(demosDir)
  39. import fontdemo
  40. import sys
  41. if "/go" in sys.argv:
  42. for name, cmd in demos:
  43. try:
  44. exec(cmd)
  45. except:
  46. print("Demo of %s failed - %s:%s" % (cmd,sys.exc_info()[0], sys.exc_info()[1]))
  47. return
  48. # Otherwise allow the user to select the demo to run
  49. import pywin.dialogs.list
  50. while 1:
  51. rc = pywin.dialogs.list.SelectFromLists( "Select a Demo", demos, ['Demo Title'] )
  52. if rc is None:
  53. break
  54. title, cmd = demos[rc]
  55. try:
  56. exec(cmd)
  57. except:
  58. print("Demo of %s failed - %s:%s" % (title,sys.exc_info()[0], sys.exc_info()[1]))
  59. if __name__==__main__.__name__:
  60. import demoutils
  61. if demoutils.NeedGoodGUI():
  62. demo()