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
_______________________________________________
QScintilla mailing list
[email protected]
https://www.riverbankcomputing.com/mailman/listinfo/qscintilla

Reply via email to