CVS: anygui/lib/anygui/backends ctmswgui.py,1.4,1.5
Robin Becker <[email protected]> Fri, 15 Nov 2002 10:50:12 -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-serv18670
Modified Files:
ctmswgui.py
Log Message:
Checked in Thomas' result test changes after checking
Index: ctmswgui.py
===================================================================
RCS file: /cvsroot/anygui/anygui/lib/anygui/backends/ctmswgui.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** ctmswgui.py 15 Nov 2002 14:12:39 -0000 1.4
--- ctmswgui.py 15 Nov 2002 18:50:08 -0000 1.5
***************
*** 26,30 ****
################################################################
! from ctypes import CDLL, _DLLS, _DynFunction, CFunction, c_string, Structure, WinError, byref
_apiMode = 'A'
--- 26,30 ----
################################################################
! from ctypes import CDLL, _DLLS, _DynFunction, CFunction, c_string, Structure, WinError, byref, GetLastError
_apiMode = 'A'
***************
*** 45,52 ****
--- 45,150 ----
return func
windll = _DLLS(WinDLL)
+
user32 = windll.user32
gdi32 = windll.gdi32
kernel32 = windll.kernel32
+ def not_null(value):
+ if value == 0: raise WinError()
+ return value
+
+ CreateWindowEx = user32.CreateWindowEx
+ CreateWindowEx.restype = not_null
+
+ DefWindowProc = user32.DefWindowProc
+
+ DestroyWindow = user32.DestroyWindow
+ DestroyWindow.restype = not_null
+
+ DispatchMessage = user32.DispatchMessage
+
+ # Error checking code for win32 api functions
+ # select one and assign to restype
+
+ def check_error(value):
+ """Some functions return 0 which may be an error or not, depending
+ on the outcome of GetLastError()"""
+ if value == 0:
+ code = GetLastError()
+ if code: raise WinError(code)
+ return value
+
+ def not_minus_one(value):
+ if value == -1: raise WinError()
+ return value
+
+ def not_null_noinfo(value):
+ "Check return code of functions returning 0 on error, but do not set an error code"
+ if value == 0: raise WindowsError, "function failed"
+ return value
+
+ def ret_atom(value):
+ "n atom is 16 bit."
+ value = value & 0xFFFF
+ if not value: raise WinError
+ return value
+
+ EnableWindow = user32.EnableWindow
+ ##EnableWindow.restype = check_error # hm, this one doesn't work.
+
+ GetDC = user32.GetDC
+ GetDC.restype = not_null # stricly, only on NT/2000/XP the error code is set
+
+ GetMessage = user32.GetMessage
+ GetMessage.restype = not_minus_one
+
+ GetSystemMetrics = user32.GetSystemMetrics
+ GetSystemMetrics.restype = not_null_noinfo
+
+ GetWindowRect = user32.GetWindowRect
+ GetWindowRect.restype = not_null
+
+ GetWindowText = user32.GetWindowText
+ ##GetWindowText.restype = not_null # but it will also fail if the title bar is empty
+
+ GetWindowTextLength = user32.GetWindowTextLength
+ ##GetWindowTextLength.restype = not_null # but it will also fail if the text length is zero
+
+ LoadCursor = user32.LoadCursor
+ LoadCursor.restype = not_null
+
+ LoadIcon = user32.LoadIcon
+ LoadIcon.restype = not_null
+
+ LoadImage = user32.LoadImage
+ LoadImage.restype = not_null
+
+ PostQuitMessage = user32.PostQuitMessage
+
+ RegisterClass = user32.RegisterClass
+ RegisterClass.restype = ret_atom
+
+ ScreenToClient = user32.ScreenToClient
+ ScreenToClient.restype = not_null_noinfo
+
+ SendMessage = user32.SendMessage
+ SetWindowPos = user32.SetWindowPos
+ SetWindowPos.restype = not_null
+
+ SetWindowText = user32.SetWindowText
+ SetWindowText.restype = not_null
+
+ ShowWindow = user32.ShowWindow
+
+ TranslateMessage = user32.TranslateMessage
+
+ UnregisterClass = user32.UnregisterClass
+ UnregisterClass.restype = not_null
+
+ UpdateWindow = user32.UpdateWindow
+ UpdateWindow.restype = not_null # only on NT/2000/XP the error code is set
+
+ ################################################################
+
ANSI_VAR_FONT=12
BM_GETSTATE=0xf2
***************
*** 150,165 ****
else:
parent = 0
! widget = user32.CreateWindowEx(self._win_style_ex,
! self._wndclass,
! 0,
! self._win_style,
! 0,
! 0,
! 10,
! 10,
! parent,
! 0, # hMenu
! 0, # hInstance
! 0)
app.widget_map[widget] = self
return widget
--- 248,263 ----
else:
parent = 0
! widget = CreateWindowEx(self._win_style_ex,
! self._wndclass,
! 0,
! self._win_style,
! 0,
! 0,
! 10,
! 10,
! parent,
! 0, # hMenu
! 0, # hInstance
! 0)
app.widget_map[widget] = self
return widget
***************
*** 168,175 ****
if _verbose: log('widgetSetup',str(self))
self.proxy.container.wrapper.widget_map[self.widget] = self
! user32.SendMessage(self.widget,
! WM_SETFONT,
! self._hfont,
! 0)
self.setVisible(1)
--- 266,273 ----
if _verbose: log('widgetSetup',str(self))
self.proxy.container.wrapper.widget_map[self.widget] = self
! SendMessage(self.widget,
! WM_SETFONT,
! self._hfont,
! 0)
self.setVisible(1)
***************
*** 181,185 ****
if not self.widget: return 0,0,0,0
r = t_rect()
! user32.GetWindowRect(self.widget,byref(r))
l,t,r,b = r.left, r.top, r.right, r.bottom
w = r-l
--- 279,283 ----
if not self.widget: return 0,0,0,0
r = t_rect()
! GetWindowRect(self.widget,byref(r))
l,t,r,b = r.left, r.top, r.right, r.bottom
w = r-l
***************
*** 190,194 ****
p = t_point()
p.x, p.y = l,t
! user32.ScreenToClient(self.proxy.container.wrapper.widget,byref(p))
l,t = p.x, p.y
if _verbose: log(' -->', l,t,w,h)
--- 288,292 ----
p = t_point()
p.x, p.y = l,t
! ScreenToClient(self.proxy.container.wrapper.widget,byref(p))
l,t = p.x, p.y
if _verbose: log(' -->', l,t,w,h)
***************
*** 232,246 ****
if self.widget:
if _verbose: log(str(self),'setGeometry', x,y,width,height)
! user32.SetWindowPos(self.widget, 0, x, y, width, height, SWP_NOACTIVATE | SWP_NOZORDER)
! user32.UpdateWindow(self.widget)
def setVisible(self,visible):
if self.widget:
if _verbose: log(str(self),'setVisible', visible, self.widget)
! user32.ShowWindow(self.widget, visible and SW_SHOWNORMAL or SW_HIDE)
def setEnabled(self,enabled):
if self.widget:
! user32.EnableWindow(self.widget, enabled and 1 or 0)
def destroy(self):
--- 330,344 ----
if self.widget:
if _verbose: log(str(self),'setGeometry', x,y,width,height)
! SetWindowPos(self.widget, 0, x, y, width, height, SWP_NOACTIVATE | SWP_NOZORDER)
! UpdateWindow(self.widget)
def setVisible(self,visible):
if self.widget:
if _verbose: log(str(self),'setVisible', visible, self.widget)
! ShowWindow(self.widget, visible and SW_SHOWNORMAL or SW_HIDE)
def setEnabled(self,enabled):
if self.widget:
! EnableWindow(self.widget, enabled and 1 or 0)
def destroy(self):
***************
*** 252,256 ****
if self.widget:
try:
! user32.DestroyWindow(self.widget)
except:
pass
--- 350,354 ----
if self.widget:
try:
! DestroyWindow(self.widget)
except:
pass
***************
*** 260,270 ****
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),str(self)))
! user32.SetWindowText(self.widget,c_string(_to_native(text)))
def _getText(self):
'return native text'
! n = user32.GetWindowTextLength(self.widget)
t = c_string('\000'*(n+1))
! user32.GetWindowText(self.widget,t,n+1)
return t.value
--- 358,368 ----
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),str(self)))
! SetWindowText(self.widget,c_string(_to_native(text)))
def _getText(self):
'return native text'
! n = GetWindowTextLength(self.widget)
t = c_string('\000'*(n+1))
! GetWindowText(self.widget,t,n+1)
return t.value
***************
*** 289,293 ****
def _WM_PAINT(self, hwnd, msg, wParam, lParam):
! return user32.DefWindowProc(hwnd, msg, wParam, lParam)
##################################################################
--- 387,391 ----
def _WM_PAINT(self, hwnd, msg, wParam, lParam):
! return DefWindowProc(hwnd, msg, wParam, lParam)
##################################################################
***************
*** 303,308 ****
def setPos(self,pos):
if not self.widget: return
! user32.SendMessage(self.widget, PBM_SETRANGE, 0, 0xffff0000)
! return user32.SendMessage(self.widget, PBM_SETPOS, int(pos*0xffff), 0)
##################################################################
--- 401,406 ----
def setPos(self,pos):
if not self.widget: return
! SendMessage(self.widget, PBM_SETRANGE, 0, 0xffff0000)
! return SendMessage(self.widget, PBM_SETPOS, int(pos*0xffff), 0)
##################################################################
***************
*** 325,343 ****
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, c_string(item))
def setSelection(self,selection):
if not self.widget: return
! user32.SendMessage(self.widget,
! LB_SETCURSEL,
! selection, 0)
def _WM_COMMAND(self, hwnd, msg, wParam, lParam):
--- 423,441 ----
def getSelection(self):
! if self.widget: return SendMessage(self.widget, LB_GETCURSEL, 0, 0)
def setItems(self,items):
if not self.widget: return
! SendMessage(self.widget, LB_RESETCONTENT, 0, 0)
for item in map(str, list(items)):
# FIXME: This doesn't work! Items get jumbled...
! SendMessage(self.widget, LB_ADDSTRING, 0, c_string(item))
def setSelection(self,selection):
if not self.widget: return
! SendMessage(self.widget,
! LB_SETCURSEL,
! selection, 0)
def _WM_COMMAND(self, hwnd, msg, wParam, lParam):
***************
*** 357,365 ****
else:
val = BST_UNCHECKED
! user32.SendMessage(self.widget, BM_SETCHECK, val, 0)
self._on = on
def getOn(self):
! val = user32.SendMessage(self.widget, BM_GETSTATE, 0, 0)
val = val & BST_CHECKED
if val: return 1
--- 455,463 ----
else:
val = BST_UNCHECKED
! SendMessage(self.widget, BM_SETCHECK, val, 0)
self._on = on
def getOn(self):
! val = SendMessage(self.widget, BM_GETSTATE, 0, 0)
val = val & BST_CHECKED
if val: return 1
***************
*** 412,416 ****
#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))
--- 510,514 ----
#log("TextField._backend_selection")
if not self.widget: return
! result = SendMessage(self.widget, EM_GETSEL, 0, 0)
start, end = result & 0xFFFF, result >> 16
#log("TextField.getSelection: start,end=%s,%s"%(start,end))
***************
*** 430,440 ****
end += text[:end].count('\n')
#log(" start,end=%s,%s"%(start,end))
! user32.SendMessage(self.widget,
! EM_SETSEL,
! start, end)
def setEditable(self,editable):
if self.widget:
! user32.SendMessage(self.widget, EM_SETREADONLY, not editable and 1 or 0, 0)
def _WM_COMMAND(self, hwnd, msg, wParam, lParam):
--- 528,538 ----
end += text[:end].count('\n')
#log(" start,end=%s,%s"%(start,end))
! SendMessage(self.widget,
! EM_SETSEL,
! start, end)
def setEditable(self,editable):
if self.widget:
! SendMessage(self.widget, EM_SETREADONLY, not editable and 1 or 0, 0)
def _WM_COMMAND(self, hwnd, msg, wParam, lParam):
***************
*** 512,516 ****
if self.kind=='bitmap':
try:
! self._handle = user32.LoadImage(0,c_string(fn),
IMAGE_BITMAP,0,0,LR_DEFAULTSIZE|LR_LOADFROMFILE)
except:
--- 610,614 ----
if self.kind=='bitmap':
try:
! self._handle = LoadImage(0,c_string(fn),
IMAGE_BITMAP,0,0,LR_DEFAULTSIZE|LR_LOADFROMFILE)
except:
***************
*** 557,561 ****
if _verbose: log('Image.draw',self.widget,self._image)
if not self.widget or not self._image: return
! dc = user32.GetDC(self.widget)
memdc = gdi32.CreateCompatibleDC(dc)
if _verbose: log('Image.draw dc, memdc',dc,memdc)
--- 655,659 ----
if _verbose: log('Image.draw',self.widget,self._image)
if not self.widget or not self._image: return
! dc = GetDC(self.widget)
memdc = gdi32.CreateCompatibleDC(dc)
if _verbose: log('Image.draw dc, memdc',dc,memdc)
***************
*** 576,581 ****
class WindowWrapper(ContainerMixin,ComponentWrapper):
_win_style = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN
! _extraWidth = 2*user32.GetSystemMetrics(SM_CXFRAME)
! _extraHeight = user32.GetSystemMetrics(SM_CYCAPTION) + 2*user32.GetSystemMetrics(SM_CYFRAME)
def __init__(self,*args,**kws):
--- 674,679 ----
class WindowWrapper(ContainerMixin,ComponentWrapper):
_win_style = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN
! _extraWidth = 2*GetSystemMetrics(SM_CXFRAME)
! _extraHeight = GetSystemMetrics(SM_CYCAPTION) + 2*GetSystemMetrics(SM_CYFRAME)
def __init__(self,*args,**kws):
***************
*** 587,591 ****
if not self.widget: return 0,0,0,0
r = t_rect()
! user32.GetWindowRect(self.widget,byref(r))
l,t,r,b = r.left, r.top, r.right, r.bottom
w = r-l-self._extraWidth
--- 685,689 ----
if not self.widget: return 0,0,0,0
r = t_rect()
! GetWindowRect(self.widget,byref(r))
l,t,r,b = r.left, r.top, r.right, r.bottom
w = r-l-self._extraWidth
***************
*** 598,608 ****
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,
! 0,
! x, y,
! width + self._extraWidth,
! height + self._extraHeight,
! SWP_NOACTIVATE | SWP_NOZORDER)
! user32.UpdateWindow(self.widget)
def setContainer(self,container):
--- 696,706 ----
if _verbose: log('WindowWrapper: setGeometry',str(self),self.widget,x,y,width,height,self._extraWidth,self._extraHeight)
# take account for title bar and borders
! SetWindowPos(self.widget,
! 0,
! x, y,
! width + self._extraWidth,
! height + self._extraHeight,
! SWP_NOACTIVATE | SWP_NOZORDER)
! UpdateWindow(self.widget)
def setContainer(self,container):
***************
*** 611,616 ****
if not self.widget:
self.create()
! user32.ShowWindow(self.widget, SW_HIDE)
! user32.UpdateWindow(self.widget)
self.proxy.push(blocked=['container'])
# Ensure contents are properly created.
--- 709,714 ----
if not self.widget:
self.create()
! ShowWindow(self.widget, SW_HIDE)
! UpdateWindow(self.widget)
self.proxy.push(blocked=['container'])
# Ensure contents are properly created.
***************
*** 620,624 ****
def setTitle(self,title):
if self.widget and title:
! user32.SetWindowText(self.widget, c_string(title))
def getTitle(self):
--- 718,722 ----
def setTitle(self,title):
if self.widget and title:
! SetWindowText(self.widget, c_string(title))
def getTitle(self):
***************
*** 629,633 ****
if _verbose: log('Windowwrapper widgetSetup',str(self),'application()',application(),'isRunning()',application().isRunning(),'widget',getattr(self,'widget',None))
application().widget_map[self.widget] = self
! user32.SendMessage(self.widget, WM_SETFONT, self._hfont, 0)
def internalProd(self):
--- 727,731 ----
if _verbose: log('Windowwrapper widgetSetup',str(self),'application()',application(),'isRunning()',application().isRunning(),'widget',getattr(self,'widget',None))
application().widget_map[self.widget] = self
! SendMessage(self.widget, WM_SETFONT, self._hfont, 0)
def internalProd(self):
***************
*** 684,688 ****
def _dispatch_DEFAULT(window,hwnd,msg,wParam,lParam):
! return user32.DefWindowProc(hwnd, msg, wParam, lParam)
_app=None
--- 782,786 ----
def _dispatch_DEFAULT(window,hwnd,msg,wParam,lParam):
! return DefWindowProc(hwnd, msg, wParam, lParam)
_app=None
***************
*** 737,749 ****
wc = WNDCLASS()
wc.hbrBackground = COLOR_BTNFACE + 1
! wc.hCursor = user32.LoadCursor(0, IDC_ARROW)
! wc.hIcon = user32.LoadIcon(0, IDI_APPLICATION)
wc.lpzClassName = "dw.anygui.PythonWindow"
wc.lpfnWndProc = WINDOWPROC(self._wndproc)
! wc.hInst = kernel32.GetModuleHandle(None)
self._wc = wc
! user32.UnregisterClass(wc.lpzClassName,0)
! self.__class__._wndclass = user32.RegisterClass(byref(wc)) & 0xFFFF
! assert self.__class__._wndclass, "RegisterClass --> %s" % WinError()
if _verbose: log('Application._register_class:end',str(self))
--- 835,850 ----
wc = WNDCLASS()
wc.hbrBackground = COLOR_BTNFACE + 1
! wc.hCursor = LoadCursor(0, IDC_ARROW)
! wc.hIcon = LoadIcon(0, IDI_APPLICATION)
wc.lpzClassName = "dw.anygui.PythonWindow"
wc.lpfnWndProc = WINDOWPROC(self._wndproc)
! wc.hInst = kernel32.GetModuleHandleA(None)
self._wc = wc
! try:
! UnregisterClass(wc.lpzClassName,0)
! except WindowsError:
! pass # class does not exist
! self.__class__._wndclass = RegisterClass(byref(wc))
! ## assert self.__class__._wndclass, "RegisterClass --> %s" % WinError()
if _verbose: log('Application._register_class:end',str(self))
***************
*** 754,758 ****
except:
if _verbose: log("\tNO WINDOW TO DISPATCH???")
! return user32.DefWindowProc(hwnd, msg, wParam, lParam)
try:
_dispatch = self._dispatch.get(msg,_dispatch_DEFAULT)
--- 855,859 ----
except:
if _verbose: log("\tNO WINDOW TO DISPATCH???")
! return DefWindowProc(hwnd, msg, wParam, lParam)
try:
_dispatch = self._dispatch.get(msg,_dispatch_DEFAULT)
***************
*** 779,787 ****
msg = MSG()
! while user32.GetMessage(byref(msg), 0, 0, 0):
try:
if _verbose: log('internalRun: loopstart',msg)
! user32.TranslateMessage(byref(msg))
! user32.DispatchMessage(byref(msg))
if _verbose: log('internalRun: loopend')
except:
--- 880,888 ----
msg = MSG()
! while GetMessage(byref(msg), 0, 0, 0):
try:
if _verbose: log('internalRun: loopstart',msg)
! TranslateMessage(byref(msg))
! DispatchMessage(byref(msg))
if _verbose: log('internalRun: loopend')
except:
***************
*** 792,796 ****
if not self._windows:
if _verbose: log('PostQuitMessage(0)')
! user32.PostQuitMessage(0)
global _app
_app = None
--- 893,897 ----
if not self._windows:
if _verbose: log('PostQuitMessage(0)')
! PostQuitMessage(0)
global _app
_app = None
-------------------------------------------------------
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