Hi, there,
···
________________________________________________________________________
Mandrake 9.1, wxPython 2.4.1.2, python 2.2.2
I noticed a weird behaviour of wxTextCtrl when I try to SetStyle of some
parts of the text.
Here is my class:
class rBasicText(wxTextCtrl):
def __init__(self, *args, **kwds):
wxTextCtrl.__init__(self, *args, **kwds)
<...>
def _beautify(self):
val=self.GetValue()
ind=string.find(val, "\n")
# THE NEXT LINE IS VERY IMPORTANT WITHOUT THIS LINE
# I WILL GET SEGMENTATION FAULT TRYING TO SET A STYLE!!!
self.SetInsertionPoint(0)
points = self.GetFont().GetPointSize() # get the current size
f = wxFont(points+5, wxNORMAL, wxNORMAL, wxNORMAL)
self.SetStyle(0, ind, wxTextAttr(wxRED, wxNullColour , f))
<...>
I initialize rBasicText as follows:
self.txt=rTextText(splitter2, -1,
style = wxTE_MULTILINE|wxTE_READONLY|
wxHSCROLL>wxTE_RICH2|wxTE_NOHIDESEL)
My first question is:
I always get a segfault without
self.SetInsertionPoint(some_value) in _beautify(). Why? Is there another
way to avoid it?
The second question is: when I do this the very first time, the
selection to which SetStyle is applied appears at the end of the text,
i.e. SetStyle modifies the text in control, self.txt.GetValue() shows
that. Why?
I tested this under Python 2.3 and wxPython 2.4.2 compiled with gtk2
support. It works as expected. However here comes my third question:
ShowPosition() doesn't work, is that a bug?
Finally, another code snippet:
I want to mark a bunch of words in the instance of rBasicText, I do:
def markText(self):
self.SetInsertionPoint(self.last_point) #stay where we are
font=self.GetFont()
# self.pos_lst holds positions of words to be marked:
for pos in self.pos_lst:
self.SetStyle(pos[0],
pos[1],
wxTextAttr(wxNullColour,
wxRED, font))
Instead of changing attributes of some words in the text it makes
instance of rBasicText scrolls several times back and forth. Just after
that scrolling (which takes forever if text is long enough) I see the
words marked as expected.
Nothing strange happens under Python 2.3 and wxPython compiled with
experimental gtk2 support (perhaps because ShowPosition is not
working).
It seems on Windows it works normally. I also noticed another thing. If
I modify an element of wxTextAttributes the rest stay unchanged on
Windows, meanwhile under Linux all other styles are reset to defaults.
All that makes me sick. What do I do wrong? This is my first experience
with wxPython (after a couple of happy years with PyQt) and it is
frustrating. This is not to say I don't like wxPython, it's nice, clear,
feature rich, and liberally licensed. And I believe it's going to be
even better.
Help me!
Many thanks,
~Serge
+++++
This mail has been sent through the MPI for Demographic Research. Should you receive a mail that is apparently from a MPI user without this text displayed, then the address has most likely been faked. If you are uncertain about the validity of this message, please check the mail header or ask your system administrator for assistance.