CVS: anygui/lib/anygui/backends ctmswgui.py,1.1,1.2
Robin Becker <[email protected]> Fri, 15 Nov 2002 05:33:33 -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-serv30866
Modified Files:
ctmswgui.py
Log Message:
Better text handling and use Thomas' better windproc
Index: ctmswgui.py
===================================================================
RCS file: /cvsroot/anygui/anygui/lib/anygui/backends/ctmswgui.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** ctmswgui.py 14 Nov 2002 16:19:23 -0000 1.1
--- ctmswgui.py 15 Nov 2002 13:33:31 -0000 1.2
***************
*** 28,40 ****
from ctypes import CDLL, _DLLS, _DynFunction, CFunction, c_string, Structure, WinError, byref
! class WinDLLA(CDLL):
def __getattr__(self, name):
try:
func = _DynFunction(name, self)
except:
! func = _DynFunction(name+'A', self)
setattr(self, name, func)
return func
! windll = _DLLS(WinDLLA)
user32 = windll.user32
gdi32 = windll.gdi32
--- 28,48 ----
from ctypes import CDLL, _DLLS, _DynFunction, CFunction, c_string, Structure, WinError, byref
! _apiMode = 'A'
! def _to_native(text):
! return text.replace('\n', '\r\n')
!
! def _from_native(text):
! return text.replace('\r\n', '\n')
!
! class WinDLL(CDLL):
!
def __getattr__(self, name):
try:
func = _DynFunction(name, self)
except:
! func = _DynFunction(name+_apiMode, self)
setattr(self, name, func)
return func
! windll = _DLLS(WinDLL)
user32 = windll.user32
gdi32 = windll.gdi32
***************
*** 259,272 ****
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(text))
! def getText(self):
! if not self.widget: return
n = user32.GetWindowTextLength(self.widget)
- if _verbose: log('GetWindowText n=',n)
t = c_string('\000'*(n+1))
! r = user32.GetWindowText(self.widget,t,n+1)
! if _verbose: log('GetWindowText n=%d r=%d s=%s'%(n,r,repr(t.value)))
! return repr(t.value)
def setContainer(self, container):
--- 267,281 ----
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
!
! def getText(self):
! if self.widget: return _from_native(self._getText())
def setContainer(self, container):
***************
*** 323,342 ****
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,
! c_string(item))
--- 332,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))
***************
*** 408,441 ****
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')
--- 409,428 ----
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')
***************
*** 639,644 ****
def setTitle(self,title):
! if not self.widget: return
! if title:
user32.SetWindowText(self.widget, c_string(title))
--- 626,630 ----
def setTitle(self,title):
! if self.widget and title:
user32.SetWindowText(self.widget, c_string(title))
***************
*** 738,745 ****
def _register_class(self):
if _verbose: log('Application._register_class:start',str(self))
class WNDCLASS(Structure):
_fields_= (
('style','i'),
! ('lpfnWndProc','i'),
('cls_extra','i'),
('wnd_extra','i'),
--- 724,734 ----
def _register_class(self):
if _verbose: log('Application._register_class:start',str(self))
+ class WINDOWPROC(CFunction):
+ _types_ = "iiii"
+ _stdcall_ = 1
class WNDCLASS(Structure):
_fields_= (
('style','i'),
! ('lpfnWndProc',WINDOWPROC),
('cls_extra','i'),
('wnd_extra','i'),
***************
*** 748,770 ****
('hCursor','i'),
('hbrBackground','i'),
! ('menu_name','i'),
! ('lpzClassName','i'),
)
! class WINDOWPROC(CFunction):
! _types_ = "iiii"
! _stdcall_ = 1
! self.__wndproc = WINDOWPROC(self._wndproc)
! self._class_name = c_string("dw.anygui.PythonWindow")
! # register a window class for toplevel windows.
wc = WNDCLASS()
wc.hbrBackground = COLOR_BTNFACE + 1
wc.hCursor = user32.LoadCursor(0, IDC_ARROW)
wc.hIcon = user32.LoadIcon(0, IDI_APPLICATION)
! wc.lpzClassName = self._class_name._as_parameter_
! wc.lpfnWndProc = self.__wndproc._as_parameter_
! wc.hInst = kernel32.GetModuleHandle(0)
self._wc = wc
user32.UnregisterClass(wc.lpzClassName,0)
! self.__class__._wndclass = user32.RegisterClass(byref(wc))
assert self.__class__._wndclass, "RegisterClass --> %s" % WinError()
if _verbose: log('Application._register_class:end',str(self))
--- 737,755 ----
('hCursor','i'),
('hbrBackground','i'),
! ('menu_name','z'),
! ('lpzClassName','z'),
)
!
! # register a window class for our windows.
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))
***************
*** 781,785 ****
x = _dispatch(window,hwnd,msg,wParam,lParam)
except:
! logTraceback(None,'_wndproc.1')
x = -1
if _verbose: log("\tdispatch %s to %s %s\n" % (_dispatch.__name__[9:],window.__class__.__name__,window),"\t ==>",x)
--- 766,770 ----
x = _dispatch(window,hwnd,msg,wParam,lParam)
except:
! if _verbose: logTraceback(None,'_wndproc.1')
x = -1
if _verbose: log("\tdispatch %s to %s %s\n" % (_dispatch.__name__[9:],window.__class__.__name__,window),"\t ==>",x)
-------------------------------------------------------
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