[pywin32-checkins] pywin32/Pythonwin/pywin/scintilla control.py, 1.17.2.3, 1.17.2.4
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2009-01-03 04:45:28
|
Update of /cvsroot/pywin32/pywin32/Pythonwin/pywin/scintilla In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv7676/pywin/scintilla Modified Files: Tag: py3k control.py Log Message: merge various fixes and cleanups from bzr integration branch Index: control.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/Pythonwin/pywin/scintilla/control.py,v retrieving revision 1.17.2.3 retrieving revision 1.17.2.4 diff -C2 -d -r1.17.2.3 -r1.17.2.4 *** control.py 3 Sep 2008 03:05:57 -0000 1.17.2.3 --- control.py 3 Jan 2009 04:45:17 -0000 1.17.2.4 *************** *** 33,36 **** --- 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 *************** *** 70,75 **** self.SendMessage(scintillacon.SCI_ADDSTYLEDTEXT, text.encode(default_scintilla_encoding)) def SCIInsertText(self, text, pos=-1): - ## sma = array.array('u', text+"\0") - ## (a,l) = sma.buffer_info() buff=(text+'\0').encode(default_scintilla_encoding) self.SendScintilla(scintillacon.SCI_INSERTTEXT, pos, buff) --- 73,76 ---- *************** *** 111,115 **** def SCIStyleSetFont(self, num, name, characterset=0): buff = (name + "\0").encode(default_scintilla_encoding) - ## addressBuffer = buff.buffer_info()[0] self.SendScintilla(scintillacon.SCI_STYLESETFONT, num, buff) self.SendScintilla(scintillacon.SCI_STYLESETCHARACTERSET, num, characterset) --- 112,115 ---- *************** *** 301,308 **** def GetSelText(self): start, end = self.GetSel() ! txtBuf = array.array('u', " " * ((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): --- 301,316 ---- 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): *************** *** 348,353 **** 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) ! buff = array.array('u', initer) addressBuffer = buff.buffer_info()[0] tr = struct.pack('llP', start, end, addressBuffer) --- 356,361 ---- 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) *************** *** 355,359 **** addressTrBuff = trBuff.buffer_info()[0] numChars = self.SendScintilla(EM_GETTEXTRANGE, 0, addressTrBuff) - ## return buff.tounicode()[:numChars] return buff.tostring()[:numChars].decode(default_scintilla_encoding) --- 363,366 ---- |