codekingpro/portable-devtools
114k
1# dlgappdemo - a demo of a dialog application.2# This is a demonstration of both a custom "application" module,3# and a Python program in a dialog box.4#5# NOTE: You CAN NOT import this module from either PythonWin or Python.6# This module must be specified on the commandline to PythonWin only.7# eg, PythonWin /app dlgappdemo.py8 9import sys10 11import win32ui12from pywin.framework import app, dlgappcore13 14 15class TestDialogApp(dlgappcore.DialogApp):16 def CreateDialog(self):17 return TestAppDialog()18 19 20class TestAppDialog(dlgappcore.AppDialog):21 def __init__(self):22 self.edit = None23 dlgappcore.AppDialog.__init__(self, win32ui.IDD_LARGE_EDIT)24 25 def OnInitDialog(self):26 self.SetWindowText("Test dialog application")27 self.edit = self.GetDlgItem(win32ui.IDC_EDIT1)28 print("Hello from Python")29 print("args are:", end=" ")30 for arg in sys.argv:31 print(arg)32 return 133 34 def PreDoModal(self):35 sys.stdout = sys.stderr = self36 37 def write(self, str):38 if self.edit:39 self.edit.SetSel(-2)40 # translate \n to \n\r41 self.edit.ReplaceSel(str.replace("\n", "\r\n"))42 else:43 win32ui.OutputDebug("dlgapp - no edit control! >>\n%s\n<<\n" % str)44 45 46app.AppBuilder = TestDialogApp47 48if __name__ == "__main__":49 import demoutils50 51 demoutils.NeedApp()52 