Robin,
Thanks for your reply.
I'm attaching a small working example. Actually yesterday I discovered
that Windows behavior (that is weird scrolling) is similar to Linux, the
only difference I cannot get segfault there.
Use File Menu to open a file (try to open something not too small).
Scroll somewhere in the middle of the text (otherwise you will not see
the bug), then select Mark Words from the menu.
On my computer I see how the text scrolls several times back and forth.
When I try Mark Words the third time I get segfault. I can avoid this if
I uncomment the line self.SetInsertionPoint(0).
Additionally sometimes updates of the marked text is not accurate....
Another problem is that the text reacts on mouse wheel only if the
pointer is over the scrollbar.
Looking forward to hearing from you,
~Serge
#------------------demo starts here------------------------
from wxPython.wx import *
import os
ID_1=101
ID_2=110
class rText(wxTextCtrl):
def __init__(self, *args, **kwds):
wxTextCtrl.__init__(self, *args, **kwds)
def markWords(self, event):
# Uncomment the next line to avoid segfault!
#self.SetInsertionPoint(0)
pos_lst=[(0, 5), (10, 20), (25, 40), (345, 355), (423, 440)]
font=self.GetFont()
for pos in pos_lst:
self.SetStyle(pos[0],
pos[1],
wxTextAttr(wxNullColour,
wxColour(168, 225, 248), font))
···
#---------------------------------------------------------------------
class MainWindow(wxFrame):
def __init__(self, *args, **kwds):
wxFrame.__init__(self, *args, **kwds)
self.text=rText(self, 1, style=wxTE_MULTILINE
>wxHSCROLL>wxTE_RICH2|wxTE_NOHIDESEL)
self.dirname=""
self.Show(True)
self.setMenu()
def onOpen(self,e):
""" Open a file"""
dlg = wxFileDialog(self, "Choose a file",
self.dirname, "", "*.*", wxOPEN)
if dlg.ShowModal() == wxID_OK:
self.filename=dlg.GetFilename()
self.dirname=dlg.GetDirectory()
f=open(os.path.join(self.dirname,self.filename),'r')
self.text.SetValue(f.read())
f.close()
dlg.Destroy()
def setMenu(self):
menu=wxMenu()
menu.Append(ID_1, "Open...")
menu.Append(ID_2, "Mark Words")
EVT_MENU(self, ID_1, self.onOpen)
EVT_MENU(self, ID_2, self.text.markWords)
menuBar=wxMenuBar()
menuBar.Append(menu, "File")
self.SetMenuBar(menuBar)
#----------------------------------------------------------------------
def main():
app=wxPySimpleApp()
frame=MainWindow(None, -1, size=(400, 200), title="SetStyle Demo")
app.MainLoop()
if __name__=="__main__":
main()
#-------------------------demo ends here--------------------------------
+++++
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.