CVS: anygui/lib/anygui/backends mswgui.py,1.41,1.42

Robin Becker <[email protected]> Fri, 15 Nov 2002 05:28:27 -0800
Newsgroups gmane.comp.python.anygui.cvs
Message-ID <[email protected]>
Update of /cvsroot/anygui/anygui/lib/anygui/backends
In directory usw-pr-cvs1:/tmp/cvs-serv29131

Modified Files:
	mswgui.py 
Log Message:
Add base progress bar and move to faster dispatch

Index: mswgui.py
===================================================================
RCS file: /cvsroot/anygui/anygui/lib/anygui/backends/mswgui.py,v
retrieving revision 1.41
retrieving revision 1.42
diff -C2 -r1.41 -r1.42
*** mswgui.py	3 Nov 2002 19:03:08 -0000	1.41
--- mswgui.py	15 Nov 2002 13:28:24 -0000	1.42
***************
*** 14,21 ****
    RadioButtonWrapper
    CheckBoxWrapper
  
  '''.split()
  
! from anygui.Utils import log
  from anygui.Applications import AbstractApplication
  from anygui.Wrappers import AbstractWrapper
--- 14,22 ----
    RadioButtonWrapper
    CheckBoxWrapper
+   ProgressBarWrapper
  
  '''.split()
  
! from anygui.Utils import log, logTraceback, setLogFile
  from anygui.Applications import AbstractApplication
  from anygui.Wrappers import AbstractWrapper
***************
*** 23,26 ****
--- 24,31 ----
  from anygui import application
  
+ #_verbose=1
+ #if _verbose:
+ #   setLogFile('/tmp/dbg.txt')
+ 
  ################################################################
  import win32gui, win32con, win32api
***************
*** 187,193 ****
          self.proxy.push()
  
  
  ##################################################################
- 
  class LabelWrapper(ComponentWrapper):
      _wndclass = "STATIC"
--- 192,199 ----
          self.proxy.push()
  
+     def _WM_PAINT(self, hwnd, msg, wParam, lParam):
+         return win32gui.DefWindowProc(hwnd, msg, wParam, lParam)
  
  ##################################################################
  class LabelWrapper(ComponentWrapper):
      _wndclass = "STATIC"
***************
*** 195,198 ****
--- 201,214 ----
  
  ##################################################################
+ class ProgressBarWrapper(ComponentWrapper):
+     _wndclass = "msctls_progress32"
+     _win_style = win32con.WS_VISIBLE | win32con.WS_CHILD | 1 #PBS_SMOOTH
+ 
+     def setPos(self,pos):
+         if not self.widget: return
+         win32gui.SendMessage(self.widget, PBM_SETRANGE, 0, 0xffff0000)
+         return win32gui.SendMessage(self.widget, PBM_SETPOS, int(pos*0xffff), 0)
+ 
+ ##################################################################
  
  class ButtonWrapper(ComponentWrapper):
***************
*** 378,390 ****
  
      def setEditable(self,editable):
!         if not self.widget: return
!         if editable:
!             win32gui.SendMessage(self.widget,
!                                  win32con.EM_SETREADONLY,
!                                  0, 0)
!         else:
!             win32gui.SendMessage(self.widget,
!                                  win32con.EM_SETREADONLY,
!                                  1, 0)
  
  ##    def _ensure_events(self):
--- 394,399 ----
  
      def setEditable(self,editable):
!         if self.widget:
!             win32gui.SendMessage(self.widget, win32con.EM_SETREADONLY, not editable and 1 or 0, 0)
  
  ##    def _ensure_events(self):
***************
*** 396,400 ****
  
      def _WM_COMMAND(self, hwnd, msg, wParam, lParam):
!         pass
  
  # FIXME: Inheriting TextField overrides TextArea defaults.
--- 405,409 ----
  
      def _WM_COMMAND(self, hwnd, msg, wParam, lParam):
!         return 0
  
  # FIXME: Inheriting TextField overrides TextArea defaults.
***************
*** 531,538 ****
--- 540,575 ----
  
  ################################################################
+ def _dispatch_WM_DESTROY(window,hwnd,msg,wParam,lParam):
+     app = application()
+     app.remove(window)
+     app.internalRemove()
+     return 0
+ 
+ def _dispatch_WM_CLOSE(window,hwnd,msg,wParam,lParam):
+     return window._WM_CLOSE(hwnd, msg, wParam, lParam)
+ 
+ def _dispatch_WM_SIZE(window,hwnd,msg,wParam,lParam):
+     return window._WM_SIZE(hwnd, msg, wParam, lParam)
+ 
+ def _dispatch_WM_COMMAND(window,hwnd,msg,wParam,lParam):
+     return window._WM_COMMAND(hwnd, msg, wParam, lParam)
  
+ def _dispatch_WM_PAINT(window,hwnd,msg,wParam,lParam):
+     return window._WM_PAINT(hwnd, msg, wParam, lParam)
+ 
+ def _dispatch_DEFAULT(window,hwnd,msg,wParam,lParam):
+     return win32gui.DefWindowProc(hwnd, msg, wParam, lParam)
+ 
+ _app=None
  class Application(AbstractApplication):
      widget_map = {} # maps top level window handles to window instances
      _wndclass = None
+     _dispatch = {
+                 win32con.WM_DESTROY: _dispatch_WM_DESTROY,
+                 win32con.WM_CLOSE: _dispatch_WM_CLOSE,
+                 win32con.WM_SIZE: _dispatch_WM_SIZE,
+                 win32con.WM_COMMAND: _dispatch_WM_COMMAND,
+                 win32con.WM_PAINT: _dispatch_WM_PAINT,
+                 }
  
      def __init__(self):
***************
*** 562,579 ****
              #log("NO WINDOW TO DISPATCH???")
              return win32gui.DefWindowProc(hwnd, msg, wParam, lParam)
!         # there should probably be a better way to dispatch messages
!         if msg == win32con.WM_DESTROY:
!             app = application()
!             app.remove(window)
!             if not app._windows:
!                 win32gui.PostQuitMessage(0)
!         if msg == win32con.WM_CLOSE:
!             return window._WM_CLOSE(hwnd, msg, wParam, lParam)
!         if msg == win32con.WM_SIZE:
!             return window._WM_SIZE(hwnd, msg, wParam, lParam)
!         if msg == win32con.WM_COMMAND:
!             #log("Dispatching command to %s"%window)
!             return window._WM_COMMAND(hwnd, msg, wParam, lParam)
!         return win32gui.DefWindowProc(hwnd, msg, wParam, lParam)
          
      def internalRun(self):
--- 599,608 ----
              #log("NO WINDOW TO DISPATCH???")
              return win32gui.DefWindowProc(hwnd, msg, wParam, lParam)
!         try:
!             _dispatch = self._dispatch.get(msg,_dispatch_DEFAULT)
!             x = _dispatch(window,hwnd,msg,wParam,lParam)
!         except:
!             x = -1
!         return x
          
      def internalRun(self):



-------------------------------------------------------
This sf.net email is sponsored by: To learn the basics of securing 
your web site with SSL, click here to get a FREE TRIAL of a Thawte 
Server Certificate: http://www.gothawte.com/rd524.html