[QScintilla] Python SendScintilla with a pointer

Baz Walter bazwal at ftml.net
Sat Jun 4 19:37:44 BST 2016


On 04/06/16 17:35, VA wrote:
> Hello,
>
> I'm not sure this is the right mailing list, so direct me if I'm not on
> the right one.
>
> I'm using Python 2, PyQt 5.6 and the Python bindings of QScintilla.
> I need to get the styled text of an annotation, but unfortunately,
> QScintilla (and moreover the Python bindings) does not have a wrapper
> for SCI_ANNOTATIONGETSTYLES, so I'm trying to wrap it myself in Python.
>
> For easier testing purpose, I first tried to wrap myself
> SCI_ANNOTATIONGETTEXT, which is wrapped by annotation(), so I can adapt
> the QScintilla C++ code to Python:
>
> bufsize = self.SendScintilla(self.SCI_ANNOTATIONGETTEXT, line, 0L) + 1
> buf = ctypes.create_string_buffer(bufsize)
> addr = ctypes.addressof(buf)
> self.SendScintilla(self.SCI_ANNOTATIONGETTEXT, line, ptr)
> return buf.value
>
> But the second SendScintilla call segfaults on my machine. I delved and
> found that on my machine (32 bits OS), for small bufsize (if <= 16),
> addr is a Python 'long', as it is between 1<<31 and 1<<32.

Just use normal python types:

     >>> text = b'hello world'
     >>> self.SendScintilla(self.SCI_ANNOTATIONSETTEXT, 1, text)
     >>> size = self.SendScintilla(QSB.SCI_ANNOTATIONGETTEXT, 1, 0)
     >>> print len(text), repr(size)
     11 11L
     >>> buf = bytearray(size)
     >>> self.SendScintilla(self.SCI_ANNOTATIONGETTEXT, 1, buf)
     print len(buf), repr(buf)
     11 bytearray(b'hello world')

And note that you don't need to allow for the terminating null (in python).

-- 
Regards
Baz Walter


More information about the QScintilla mailing list