[pywin32-checkins] pywin32/Pythonwin/pywin/scintilla control.py, 1.19, 1.20
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2009-01-05 11:07:30
|
Update of /cvsroot/pywin32/pywin32/Pythonwin/pywin/scintilla In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv30686/Pythonwin/pywin/scintilla Modified Files: control.py Log Message: better py3k-friendly use of array module, more comments and cleanups Index: control.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/Pythonwin/pywin/scintilla/control.py,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** control.py 14 Nov 2008 00:22:25 -0000 1.19 --- control.py 5 Jan 2009 11:07:24 -0000 1.20 *************** *** 14,18 **** import string import os - import sys import scintillacon --- 14,17 ---- *************** *** 34,37 **** --- 33,39 ---- dllid = win32api.LoadLibrary("Scintilla.DLL") + # null_byte is str in py2k, bytes on py3k + null_byte = "\0".encode('ascii') + ## These are from Richedit.h - need to add to win32con or commctrl EM_GETTEXTRANGE = 1099 *************** *** 199,210 **** def SCICallTipShow(self, text, pos=-1): if pos==-1: pos = self.GetSel()[0] ! if isinstance(text, unicode): ! # I'm really not sure what the correct encoding ! # to use is - but it has gotta be better than total ! # failure due to the array module ! text = text.encode("mbcs") ! buff = array.array('c', text + "\0") ! addressBuffer = buff.buffer_info()[0] ! self.SendScintilla(scintillacon.SCI_CALLTIPSHOW, pos, addressBuffer) def SCICallTipCancel(self): self.SendScintilla(scintillacon.SCI_CALLTIPCANCEL) --- 201,206 ---- def SCICallTipShow(self, text, pos=-1): if pos==-1: pos = self.GetSel()[0] ! buff = (text + "\0").encode(default_scintilla_encoding) ! self.SendScintilla(scintillacon.SCI_CALLTIPSHOW, pos, buff) def SCICallTipCancel(self): self.SendScintilla(scintillacon.SCI_CALLTIPCANCEL) *************** *** 220,225 **** self.SendScintilla(scintillacon.SCI_SETKEYWORDS, kw_list_no, buff) def SCISetProperty(self, name, value): ! name_buff = array.array('c', name + "\0") ! val_buff = array.array("c", str(value) + "\0") address_name_buffer = name_buff.buffer_info()[0] address_val_buffer = val_buff.buffer_info()[0] --- 216,221 ---- self.SendScintilla(scintillacon.SCI_SETKEYWORDS, kw_list_no, buff) def SCISetProperty(self, name, value): ! name_buff = array.array('b', (name + '\0').encode(default_scintilla_encoding)) ! val_buff = array.array("b", (str(value)+'\0').encode(default_scintilla_encoding)) address_name_buffer = name_buff.buffer_info()[0] address_val_buffer = val_buff.buffer_info()[0] *************** *** 297,304 **** def GetSelText(self): start, end = self.GetSel() ! txtBuf = array.array('c', " " * ((end-start)+1)) addressTxtBuf = txtBuf.buffer_info()[0] self.SendScintilla(EM_GETSELTEXT, 0, addressTxtBuf) ! return txtBuf.tostring().decode(default_scintilla_encoding) def SetSel(self, start=0, end=None): --- 293,308 ---- def GetSelText(self): start, end = self.GetSel() ! txtBuf = array.array('b', null_byte * (end-start+1)) addressTxtBuf = txtBuf.buffer_info()[0] + # EM_GETSELTEXT is documented as returning the number of chars + # not including the NULL, but scintilla includes the NULL. A + # quick glance at the scintilla impl doesn't make this + # obvious - the NULL is included in the 'selection' object + # and reflected in the length of that 'selection' object. + # I expect that is a bug in scintilla and may be fixed by now, + # but we just blindly assume that the last char is \0 and + # strip it. self.SendScintilla(EM_GETSELTEXT, 0, addressTxtBuf) ! return txtBuf.tostring()[:-1].decode(default_scintilla_encoding) def SetSel(self, start=0, end=None): *************** *** 313,317 **** assert end <= self.GetTextLength(), "The end postion is invalid (%d/%d)" % (end, self.GetTextLength()) cr = struct.pack('ll', start, end) ! crBuff = array.array('c', cr) addressCrBuff = crBuff.buffer_info()[0] rc = self.SendScintilla(EM_EXSETSEL, 0, addressCrBuff) --- 317,321 ---- assert end <= self.GetTextLength(), "The end postion is invalid (%d/%d)" % (end, self.GetTextLength()) cr = struct.pack('ll', start, end) ! crBuff = array.array('b', cr) addressCrBuff = crBuff.buffer_info()[0] rc = self.SendScintilla(EM_EXSETSEL, 0, addressCrBuff) *************** *** 344,356 **** assert start >= 0 and start <= self.GetTextLength(), "The start postion is invalid" assert end >= 0 and end <= self.GetTextLength(), "The end postion is invalid" ! initer = ("=" * (end - start + 1)).encode("ascii") # ensure bytes in both 2x and 3k ! if sys.version_info >= (3,): ! byte_format = 'b' ! else: ! byte_format = 'c' ! buff = array.array(byte_format, initer) addressBuffer = buff.buffer_info()[0] tr = struct.pack('llP', start, end, addressBuffer) ! trBuff = array.array(byte_format, tr) addressTrBuff = trBuff.buffer_info()[0] numChars = self.SendScintilla(EM_GETTEXTRANGE, 0, addressTrBuff) --- 348,356 ---- assert start >= 0 and start <= self.GetTextLength(), "The start postion is invalid" assert end >= 0 and end <= self.GetTextLength(), "The end postion is invalid" ! initer = null_byte * (end - start + 1) ! buff = array.array('b', initer) addressBuffer = buff.buffer_info()[0] tr = struct.pack('llP', start, end, addressBuffer) ! trBuff = array.array('b', tr) addressTrBuff = trBuff.buffer_info()[0] numChars = self.SendScintilla(EM_GETTEXTRANGE, 0, addressTrBuff) |