demoutils.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Utilities for the demos
  2. import sys, win32api, win32con, win32ui
  3. NotScriptMsg = """\
  4. This demo program is not designed to be run as a Script, but is
  5. probably used by some other test program. Please try another demo.
  6. """
  7. NeedGUIMsg = """\
  8. This demo program can only be run from inside of Pythonwin
  9. You must start Pythonwin, and select 'Run' from the toolbar or File menu
  10. """
  11. NeedAppMsg = """\
  12. This demo program is a 'Pythonwin Application'.
  13. It is more demo code than an example of Pythonwin's capabilities.
  14. To run it, you must execute the command:
  15. pythonwin.exe /app "%s"
  16. Would you like to execute it now?
  17. """
  18. def NotAScript():
  19. import win32ui
  20. win32ui.MessageBox(NotScriptMsg, "Demos")
  21. def NeedGoodGUI():
  22. from pywin.framework.app import HaveGoodGUI
  23. rc = HaveGoodGUI()
  24. if not rc:
  25. win32ui.MessageBox(NeedGUIMsg, "Demos")
  26. return rc
  27. def NeedApp():
  28. import win32ui
  29. rc = win32ui.MessageBox(NeedAppMsg % sys.argv[0], "Demos", win32con.MB_YESNO)
  30. if rc==win32con.IDYES:
  31. try:
  32. parent = win32ui.GetMainFrame().GetSafeHwnd()
  33. win32api.ShellExecute(parent, None, 'pythonwin.exe', '/app "%s"' % sys.argv[0], None, 1)
  34. except win32api.error as details:
  35. win32ui.MessageBox("Error executing command - %s" % (details), "Demos")
  36. if __name__=='__main__':
  37. import demoutils
  38. demoutils.NotAScript()