Hi. i know that the wxHtmlWindow is built to handle things like this, but
I need the GetStringSelection method that comes with wxTextCtrl (not
using it in this boiled down example). What im doing is simply
highlighting a
string with red wherever it appears in a file, theres a lot of very weird
behaviour and its very innefficient and hindering me.
Heres how the program below is used: enter a filename in the smaller
textctrl on the top (in the same dir as you ran the program from) , press
the "make" button, watch the slowness.
specifically, it is hardcoded to highlight the string "wx" so try to pick
a good sized (few hundred lines) file with a few instances of this
string. ive found that its quite
slow even for 5 setstyles....
import string,os,re
from wxPython.wx import *
from wxPython.lib.scrolledpanel import wxScrolledPanel
class MainWindow(wxFrame):
""" We simply derive a new class of Frame. """
def __init__(self,parent,id,title):
wxFrame.__init__(self,parent,-4, title, size = ( 200,100),
style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
self.filetable={}
self.control = wxSplitterWindow(self,1)
p1 = wxScrolledPanel(self.control,1)
ppu=200
p1.SetScrollbars(ppu, ppu, 200/ppu, 200*100/ppu)
self.varPanel = p1
p1.sizer = wxBoxSizer(wxVERTICAL)
p1.sizer.Add(wxTextCtrl(p1,1,"yaya"*1000,style=wxTE_MULTILINE|wxHSCROLL),
1, wxEXPAND)
p1.SetSizer(p1.sizer)
p1.SetAutoLayout(1)
p1.sizer.Fit(p1)
p2 = wxPanel(self.control,1)
p2.sizer = wxBoxSizer(wxVERTICAL)
self.qtext = wxTextCtrl(p2,1,"")
p2.sizer.Add(self.qtext)
p2.sizer.Add(wxButton(p2,10,"Make"))
self.ftext = wxTextCtrl(p2,1,"File goes
here",size=(800,400),style=wxTE_MULTILINE)
p2.sizer.Add(self.ftext,wxEXPAND)
EVT_BUTTON(p2,10,self.filedo)
p2.SetSizer(p2.sizer)
p2.SetAutoLayout(1)
p2.sizer.Fit(p2)
self.control.SplitVertically(p1,p2,300)
self.sizer = wxBoxSizer(wxVERTICAL)
self.sizer.Add(self.control,1, wxEXPAND)
self.SetSizer(self.sizer)
self.Show(true)
def filedo(self,event):
f = open(self.qtext.GetValue()).read()
self.ftext.SetValue(f)
serstr = "wx"
l = findall(serstr,f)
for n,each in enumerate(l):
self.ftext.SetStyle(each,each+len(serstr),wxTextAttr("RED"))
def findall(sub,s):
if s =='' or sub =='':
return []
ret=[]
findval=0
pos=0
while findval != -1:
findval = s.find(sub,pos)
if findval != -1:
ret.append(findval)
pos = findval + len(sub)
return ret
app = wxPySimpleApp()
frame = MainWindow(None, -1, "Small editor")
app.MainLoop()