Update of /cvsroot/pywin32/pywin32/win32/Demos
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16706
Modified Files:
win32gui_dialog.py
Log Message:
Demonstrate the "correct" way to implement a message loop for an
application.
Index: win32gui_dialog.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/Demos/win32gui_dialog.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** win32gui_dialog.py 22 Jul 2004 08:31:23 -0000 1.4
--- win32gui_dialog.py 25 Jan 2005 13:41:47 -0000 1.5
***************
*** 120,124 ****
]
! class DemoWindow:
def __init__(self):
win32gui.InitCommonControls()
--- 120,124 ----
]
! class DemoWindowBase:
def __init__(self):
win32gui.InitCommonControls()
***************
*** 174,183 ****
return dlg
- def CreateWindow(self):
- self._DoCreate(win32gui.CreateDialogIndirect)
-
- def DoModal(self):
- return self._DoCreate(win32gui.DialogBoxIndirect)
-
def _DoCreate(self, fn):
message_map = {
--- 174,177 ----
***************
*** 263,273 ****
self._DoSize(r-l,b-t, 1)
- def OnClose(self, hwnd, msg, wparam, lparam):
- win32gui.EndDialog(hwnd, 0)
-
- def OnDestroy(self, hwnd, msg, wparam, lparam):
- print "OnDestroy"
- win32gui.PostQuitMessage(0) # Terminate the app.
-
def _DoSize(self, cx, cy, repaint = 1):
# right-justify the textbox.
--- 257,260 ----
***************
*** 340,350 ****
print "The selected item is", sel+1
def DemoModal():
! w=DemoWindow()
w.DoModal()
- ## w.CreateWindow()
- ## win32gui.PumpMessages()
- ## # Not sure how to kill this loop.
if __name__=='__main__':
DemoModal()
--- 327,372 ----
print "The selected item is", sel+1
+ # These function differ based on how the window is used, so may be overridden
+ def OnClose(self, hwnd, msg, wparam, lparam):
+ raise NotImplementedError
+
+ def OnDestroy(self, hwnd, msg, wparam, lparam):
+ pass
+
+ # An implementation suitable for use with the Win32 Window functions (ie, not
+ # a true dialog)
+ class DemoWindow(DemoWindowBase):
+ def CreateWindow(self):
+ # Create the window via CreateDialogBoxIndirect - it can then
+ # work as a "normal" window, once a message loop is established.
+ self._DoCreate(win32gui.CreateDialogIndirect)
+
+ def OnClose(self, hwnd, msg, wparam, lparam):
+ win32gui.DestroyWindow(hwnd)
+
+ # We need to arrange to a WM_QUIT message to be sent to our
+ # PumpMessages() loop.
+ def OnDestroy(self, hwnd, msg, wparam, lparam):
+ win32gui.PostQuitMessage(0) # Terminate the app.
+
+ # An implementation suitable for use with the Win32 Dialog functions.
+ class DemoDialog(DemoWindowBase):
+ def DoModal(self):
+ return self._DoCreate(win32gui.DialogBoxIndirect)
+
+ def OnClose(self, hwnd, msg, wparam, lparam):
+ win32gui.EndDialog(hwnd, 0)
+
def DemoModal():
! w=DemoDialog()
w.DoModal()
+ def DemoCreateWindow():
+ w=DemoWindow()
+ w.CreateWindow()
+ # PumpMessages runs until PostQuitMessage() is called by someone.
+ win32gui.PumpMessages()
+
if __name__=='__main__':
DemoModal()
+ DemoCreateWindow()
|