codekingpro/portable-devtools
114k
1# Utilities for the demos2 3import sys4 5import win32api6import win32con7import win32ui8 9NotScriptMsg = """\10This demo program is not designed to be run as a Script, but is11probably used by some other test program. Please try another demo.12"""13 14NeedGUIMsg = """\15This demo program can only be run from inside of Pythonwin16 17You must start Pythonwin, and select 'Run' from the toolbar or File menu18"""19 20 21NeedAppMsg = """\22This demo program is a 'Pythonwin Application'.23 24It is more demo code than an example of Pythonwin's capabilities.25 26To run it, you must execute the command:27pythonwin.exe /app "%s"28 29Would you like to execute it now?30"""31 32 33def NotAScript():34 import win32ui35 36 win32ui.MessageBox(NotScriptMsg, "Demos")37 38 39def NeedGoodGUI():40 from pywin.framework.app import HaveGoodGUI41 42 rc = HaveGoodGUI()43 if not rc:44 win32ui.MessageBox(NeedGUIMsg, "Demos")45 return rc46 47 48def NeedApp():49 import win32ui50 51 rc = win32ui.MessageBox(NeedAppMsg % sys.argv[0], "Demos", win32con.MB_YESNO)52 if rc == win32con.IDYES:53 try:54 parent = win32ui.GetMainFrame().GetSafeHwnd()55 win32api.ShellExecute(56 parent, None, "pythonwin.exe", '/app "%s"' % sys.argv[0], None, 157 )58 except win32api.error as details:59 win32ui.MessageBox("Error executing command - %s" % (details), "Demos")60 61 62from pywin.framework.app import HaveGoodGUI63 64if __name__ == "__main__":65 import demoutils66 67 demoutils.NotAScript()68 