CVS: anygui/lib/anygui/backends dwgui.py,1.7,1.8
Robin Becker <[email protected]> Fri, 15 Nov 2002 06:12:03 -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-serv12262
Modified Files:
dwgui.py
Log Message:
Fixes learned from ctmswgui
Index: dwgui.py
===================================================================
RCS file: /cvsroot/anygui/anygui/lib/anygui/backends/dwgui.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** dwgui.py 7 Nov 2002 17:53:37 -0000 1.7
--- dwgui.py 15 Nov 2002 14:12:00 -0000 1.8
***************
*** 31,34 ****
--- 31,40 ----
kernel32 = windll.module('kernel32')
+ def _to_native(text):
+ return text.replace('\n', '\r\n')
+
+ def _from_native(text):
+ return text.replace('\r\n', '\n')
+
ANSI_VAR_FONT=12
BM_GETSTATE=0xf2
***************
*** 93,97 ****
GetLastError = kernel32.GetLastError
! _verbose=1
if _verbose:
setLogFile('/tmp/dbg.txt')
--- 99,103 ----
GetLastError = kernel32.GetLastError
! _verbose=0
if _verbose:
setLogFile('/tmp/dbg.txt')
***************
*** 150,154 ****
def widgetFactory(self,*args,**kws):
app = application()
! if hasattr(self.proxy.container,'wrapper'):
parent = self.proxy.container.wrapper.widget
else:
--- 156,160 ----
def widgetFactory(self,*args,**kws):
app = application()
! if self.proxy.container and hasattr(self.proxy.container,'wrapper'):
parent = self.proxy.container.wrapper.widget
else:
***************
*** 190,193 ****
--- 196,200 ----
def getGeometry(self):
+ if not self.widget: return 0,0,0,0
r = t_rect()
user32.GetWindowRect(self.widget,r)
***************
*** 255,259 ****
def destroy(self):
! if self.proxy.container:
try:
del self.proxy.container.wrapper.widget_map[self.widget]
--- 262,266 ----
def destroy(self):
! if getattr(self.proxy,'container',None):
try:
del self.proxy.container.wrapper.widget_map[self.widget]
***************
*** 270,285 ****
if not self.widget: return
if _verbose: log("%s.SetWindowText('%s'(%s)) hwnd=%s(%s) self=%s" % (self.__class__.__name__,text,type(text),self.widget,type(self.widget),self))
! self._i_text = windll.cstring(text)
! user32.SetWindowTextA(self.widget,self._i_text)
! def getText(self):
! if not self.widget: return
n = user32.GetWindowTextLength(self.widget)
- if _verbose: log('GetWindowText n=',n)
t = windll.cstring('',n+1)
r = user32.GetWindowText(self.widget,t.address(),n+1)
- if _verbose: log('GetWindowText n=%d r=%d s=%s'%(n,r,t.trunc()))
return t.trunc()
def setContainer(self, container):
if container is None:
--- 277,292 ----
if not self.widget: return
if _verbose: log("%s.SetWindowText('%s'(%s)) hwnd=%s(%s) self=%s" % (self.__class__.__name__,text,type(text),self.widget,type(self.widget),self))
! user32.SetWindowTextA(self.widget,windll.cstring(_to_native(text)))
! def _getText(self):
! 'return native text'
n = user32.GetWindowTextLength(self.widget)
t = windll.cstring('',n+1)
r = user32.GetWindowText(self.widget,t.address(),n+1)
return t.trunc()
+ def getText(self):
+ if self.widget: return _from_native(self._getText())
+
def setContainer(self, container):
if container is None:
***************
*** 326,332 ****
# HIWORD(wParam): notification code
# LOWORD(wParam): id of menu item, control, or accelerator
! if (wParam >> 16) == BN_CLICKED:
! #self.do_action()
! return send(self.proxy, 'click')
##################################################################
--- 333,337 ----
# HIWORD(wParam): notification code
# LOWORD(wParam): id of menu item, control, or accelerator
! return (wParam >> 16)!=BN_CLICKED and -1 or send(self.proxy, 'click')
##################################################################
***************
*** 337,357 ****
def getSelection(self):
! if not self.widget: return
! return user32.SendMessage(self.widget,
! LB_GETCURSEL,
! 0,
! 0)
def setItems(self,items):
if not self.widget: return
! user32.SendMessage(self.widget,
! LB_RESETCONTENT, 0, 0)
for item in map(str, list(items)):
# FIXME: This doesn't work! Items get jumbled...
! user32.SendMessage(self.widget,
! LB_ADDSTRING,
! 0,
! windll.cstring(item))
!
def setSelection(self,selection):
--- 342,353 ----
def getSelection(self):
! if self.widget: return user32.SendMessage(self.widget, LB_GETCURSEL, 0, 0)
def setItems(self,items):
if not self.widget: return
! user32.SendMessage(self.widget, LB_RESETCONTENT, 0, 0)
for item in map(str, list(items)):
# FIXME: This doesn't work! Items get jumbled...
! user32.SendMessage(self.widget, LB_ADDSTRING, 0, windll.cstring(item))
def setSelection(self,selection):
***************
*** 365,371 ****
# HIWORD(wParam): notification code
# LOWORD(wParam): id of menu item, control, or accelerator
! if wParam >> 16 == LBN_SELCHANGE:
! #self.do_action()
! return send(self.proxy, 'select')
##################################################################
--- 361,365 ----
# HIWORD(wParam): notification code
# LOWORD(wParam): id of menu item, control, or accelerator
! return (wParam>>16)!=LBN_SELCHANGE and -1 or send(self.proxy, 'select')
##################################################################
***************
*** 412,422 ****
group._items.append(self.proxy)
- def _WM_COMMAND(self, hwnd, msg, wParam, lParam):
- # lParam: handle of control (or NULL, if not from a control)
- # HIWORD(wParam): notification code
- # LOWORD(wParam): id of menu item, control, or accelerator
- if (wParam >> 16) != BN_CLICKED: return -1
- return send(self.proxy, 'click')
-
##################################################################
--- 406,409 ----
***************
*** 431,464 ****
class TextFieldWrapper(ComponentWrapper):
_wndclass = "EDIT"
! _win_style = ES_NOHIDESEL | ES_AUTOHSCROLL | \
! WS_CHILD | WS_BORDER
_win_style_ex = WS_EX_CLIENTEDGE
- def _to_native(self, text):
- return text.replace('\n', '\r\n')
-
- def _from_native(self, text):
- return text.replace('\r\n', '\n')
-
- def getText(self):
- if not self.widget: return
- return self._from_native(ComponentWrapper.getText(self))
-
def setText(self, text):
! if not self.widget: return
! if text==self.getText(): return
! ComponentWrapper.setText(self, self._to_native(text))
def getSelection(self):
#log("TextField._backend_selection")
if not self.widget: return
! result = user32.SendMessage(self.widget,
! EM_GETSEL,
! 0, 0)
start, end = result & 0xFFFF, result >> 16
! #log(" start,end=%s,%s"%(start,end))
! # under windows, the natice widget contains
# CRLF line separators
! text = self.getText()
start -= text[:start].count('\n')
end -= text[:end].count('\n')
--- 418,437 ----
class TextFieldWrapper(ComponentWrapper):
_wndclass = "EDIT"
! _win_style = ES_NOHIDESEL | ES_AUTOHSCROLL | WS_CHILD | WS_BORDER
_win_style_ex = WS_EX_CLIENTEDGE
def setText(self, text):
! if self.widget and text!=self.getText():
! ComponentWrapper.setText(self,text)
def getSelection(self):
#log("TextField._backend_selection")
if not self.widget: return
! result = user32.SendMessage(self.widget, EM_GETSEL, 0, 0)
start, end = result & 0xFFFF, result >> 16
! #log("TextField.getSelection: start,end=%s,%s"%(start,end))
! # under windows, the native widget contains
# CRLF line separators
! text = self._getText()
start -= text[:start].count('\n')
end -= text[:end].count('\n')
***************
*** 508,512 ****
# EN_CHANGE (0x300) and EN_UPDATE (0x400) notifications
# here even before the call to CreateWindow returns.
! return None
except:
logTraceback(None)
--- 481,485 ----
# EN_CHANGE (0x300) and EN_UPDATE (0x400) notifications
# here even before the call to CreateWindow returns.
! return -1
except:
logTraceback(None)
***************
*** 588,595 ****
class ImageWrapper(ComponentWrapper):
_win_style = WS_CHILD | WS_VISIBLE
! _wndclass = "dw.anygui.Image"
def _WM_PAINT(self, hwnd, msg, wParam, lParam):
! if not self.widget: return
if _verbose: log('Image _WM_PAINT self.__dict__',self.__dict__)
r = ComponentWrapper._WM_PAINT(self, hwnd, msg, wParam, lParam)
--- 561,568 ----
class ImageWrapper(ComponentWrapper):
_win_style = WS_CHILD | WS_VISIBLE
! _wndclass = "dw.anygui.PythonWindow"
def _WM_PAINT(self, hwnd, msg, wParam, lParam):
! if not self.widget: return -1
if _verbose: log('Image _WM_PAINT self.__dict__',self.__dict__)
r = ComponentWrapper._WM_PAINT(self, hwnd, msg, wParam, lParam)
***************
*** 614,617 ****
--- 587,593 ----
return self._image
+ def _WM_SIZE(self, hwnd, msg, wParam, lParam):
+ w, h = lParam & 0xFFFF, lParam >> 16
+
class WindowWrapper(ContainerMixin,ComponentWrapper):
_win_style = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN
***************
*** 636,640 ****
def setGeometry(self,x,y,width,height):
if not self.widget: return
! if _verbose: log('WindowWrapper: setGeometry',x,y,width,height)
# take account for title bar and borders
user32.SetWindowPos(self.widget,
--- 612,616 ----
def setGeometry(self,x,y,width,height):
if not self.widget: return
! if _verbose: log('WindowWrapper: setGeometry',str(self),self.widget,x,y,width,height,self._extraWidth,self._extraHeight)
# take account for title bar and borders
user32.SetWindowPos(self.widget,
***************
*** 659,666 ****
def setTitle(self,title):
! if not self.widget: return
! if title:
! self._i_text = windll.cstring(title)
! user32.SetWindowTextA(self.widget, self._i_text)
def getTitle(self):
--- 635,640 ----
def setTitle(self,title):
! if self.widget and title:
! user32.SetWindowTextA(self.widget, windll.cstring(title))
def getTitle(self):
***************
*** 694,699 ****
self._width = w
self._height = h
! if (dw,dh) == (0,0): return
! self.proxy.resized(dw,dh)
return 0
--- 668,672 ----
self._width = w
self._height = h
! if (dw,dh)!=(0,0): self.proxy.resized(dw,dh)
return 0
***************
*** 701,709 ****
self.destroy()
application().remove(self.proxy)
! return 1
def _WM_COMMAND(self, hwnd, msg, wParam, lParam):
! if _verbose: log('WindowWrapper: _WM_COMMAND',self,hwnd,msg,wParam,lParam)
! ContainerMixin._WM_COMMAND(self, hwnd, msg, wParam, lParam)
################################################################
--- 674,682 ----
self.destroy()
application().remove(self.proxy)
! return 0
def _WM_COMMAND(self, hwnd, msg, wParam, lParam):
! if _verbose: log('WindowWrapper: _WM_COMMAND',str(self),hwnd,msg,wParam,lParam)
! return ContainerMixin._WM_COMMAND(self, hwnd, msg, wParam, lParam)
################################################################
***************
*** 729,732 ****
--- 702,706 ----
return user32.DefWindowProc(hwnd, msg, wParam, lParam)
+ _app=None
class Application(AbstractApplication):
widget_map = {} # maps top level window handles to window instances
***************
*** 741,755 ****
def __init__(self):
- if _verbose: log('Application.__init__:start',self)
- AbstractApplication.__init__(self)
- if not self._wndclass: self._register_class()
- WindowWrapper._wndclass = self._wndclass
- FrameWrapper._wndclass = self._wndclass
global _app
! _app = self
! if _verbose: log('Application.__init__:end',self)
def _register_class(self):
! if _verbose: log('Application._register_class:start',self)
class WNDCLASS(structob.struct_object):
oracle = structob.Oracle (
--- 715,736 ----
def __init__(self):
global _app
! if not _app:
! if _verbose: log('Application.__init__:start',str(self))
! AbstractApplication.__init__(self)
! if not self._wndclass: self._register_class()
! WindowWrapper._wndclass = self._wndclass
! FrameWrapper._wndclass = self._wndclass
! _app = self
! if _verbose: log('Application.__init__:end',self)
!
! def __str__(self):
! return '<%s.Application 0x%s>' % (__file__,id(self))
!
! def __nonzero__(self):
! return _app is not None
def _register_class(self):
! if _verbose: log('Application._register_class:start',str(self))
class WNDCLASS(structob.struct_object):
oracle = structob.Oracle (
***************
*** 770,774 ****
self._class_name = windll.cstring("dw.anygui.PythonWindow")
self.__wndproc = gencb.generated_callback('llll',self._wndproc)
! # register a window class for toplevel windows.
wc = WNDCLASS()
wc.hbrBackground = COLOR_BTNFACE + 1
--- 751,755 ----
self._class_name = windll.cstring("dw.anygui.PythonWindow")
self.__wndproc = gencb.generated_callback('llll',self._wndproc)
! # register a window class for our windows.
wc = WNDCLASS()
wc.hbrBackground = COLOR_BTNFACE + 1
***************
*** 782,786 ****
self.__class__._wndclass = user32.RegisterClass(wc)
assert self.__class__._wndclass, "RegisterClass --> %d=%s ie\n%s" % (GetLastError(), hex(GetLastError()), _lastErrorMessage())
! if _verbose: log('Application._register_class:end',self)
def _wndproc(self, hwnd, msg, wParam, lParam):
--- 763,767 ----
self.__class__._wndclass = user32.RegisterClass(wc)
assert self.__class__._wndclass, "RegisterClass --> %d=%s ie\n%s" % (GetLastError(), hex(GetLastError()), _lastErrorMessage())
! if _verbose: log('Application._register_class:end',str(self))
def _wndproc(self, hwnd, msg, wParam, lParam):
***************
*** 791,796 ****
if _verbose: log("\tNO WINDOW TO DISPATCH???")
return user32.DefWindowProc(hwnd, msg, wParam, lParam)
! _dispatch = self._dispatch.get(msg,_dispatch_DEFAULT)
! x = _dispatch(window,hwnd,msg,wParam,lParam)
if _verbose: log("\tdispatch %s to %s %s\n" % (_dispatch.__name__[9:],window.__class__.__name__,window),"\t ==>",x)
return x
--- 772,780 ----
if _verbose: log("\tNO WINDOW TO DISPATCH???")
return user32.DefWindowProc(hwnd, msg, wParam, lParam)
! try:
! _dispatch = self._dispatch.get(msg,_dispatch_DEFAULT)
! x = _dispatch(window,hwnd,msg,wParam,lParam)
! except:
! logTraceback(None,'_wndproc.1')
if _verbose: log("\tdispatch %s to %s %s\n" % (_dispatch.__name__[9:],window.__class__.__name__,window),"\t ==>",x)
return x
***************
*** 817,824 ****
user32.TranslateMessage(msg)
user32.DispatchMessage(msg)
! log('internalRun: loopend')
except:
! logTraceback(None)
! log('internalRun: finish')
def internalRemove(self):
--- 801,808 ----
user32.TranslateMessage(msg)
user32.DispatchMessage(msg)
! if _verbose: log('internalRun: loopend')
except:
! if _verbose: logTraceback(None)
! if _verbose: log('internalRun: finish')
def internalRemove(self):
***************
*** 826,829 ****
--- 810,846 ----
if _verbose: log('PostQuitMessage(0)')
user32.PostQuitMessage(0)
+ global _app
+ _app = None
+
+ if 1 and _verbose:
+ n = 0
+ from inspect import isclass, ismethod, getmembers
+ def makeTBWrap(C,methodname):
+ import new
+ global n
+ oldmethodname = '_%d_tbWrap_%s' % (n,methodname)
+ oldmethod = getattr(C,methodname)
+ S = []
+ s = S.append
+ s('def %s(self,*A,**K):' % methodname)
+ s('\ttry:')
+ s('\t\treturn self.%s(*A,**K)' % oldmethodname)
+ s('\texcept:')
+ s('\t\tfrom anygui.Utils import logTraceback')
+ s('\t\tlogTraceback(None,\'[%s.%s]\')' % (C.__name__,methodname))
+ s('\t\traise')
+ s('setattr(C,oldmethodname,oldmethod)')
+ s('setattr(C,methodname,new.instancemethod(%s,None,C))' % methodname)
+ exec '\n'.join(S) + '\n' in locals()
+ n += 1
+
+ for a in __all__:
+ C = globals()[a]
+ if isclass(C):
+ M = []
+ m = M.append
+ for methodname,method in getmembers(C):
+ if ismethod(method): m(methodname)
+ for methodname in M: makeTBWrap(C,methodname)
################################################################
-------------------------------------------------------
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