I have a simple text editor with a autocomplete of some words. I am having problems getting it to open with a one line command from anoter file, like VisualWX. I have worked on this problem for a week now. there is some lesson I need to learn better.
I have a sample file. it will not start though.
import wx
import wx.stc as stc
import re
AutoFillStartLen=2
AutoFillMinWordLen=4
choices=
class MySTC(stc.StyledTextCtrl):
def init(self, parent, size=wx.DefaultSize, style=0,menu=None):
text=stc.StyledTextCtrl.init(self, parent, size=size, style=style)
self.SetMarginWidth(1,0)
choices.sort()
self.MyChoices=’ '.join(choices)
self.Bind(stc.EVT_STC_CHARADDED , self.OnAutoFill)
self.Bind( wx.EVT_KEY_DOWN , self.OnKeyDown, self )
self.Bind(wx.EVT_CONTEXT_MENU,self.MainPopUp)
def PopUpSwitch(self,event):
menu=wx.Menu()
print menu.IsEnabled(event)
def MainPopUp(self,event):
menu = wx.Menu()
menu.Append(wx.ID_UNDO,“&Undo”)
menu.Append(wx.ID_REDO,‘Redo’)
menu.AppendSeparator()
menu.Append(wx.ID_CUT,“Cu&t” )
menu.Append(wx.ID_COPY, “Copy”)
menu.Append(wx.ID_PASTE,“&Paste”)
menu.Append(wx.ID_DELETE,“&Delete”)
menu.AppendSeparator()
menu.Append(wx.ID_SELECTALL,‘Select All’)
menu.AppendSeparator()
menu.Append(4,
“RemoveWord”)
self.Bind(wx.EVT_MENU, self.OnUndo,id=wx.ID_UNDO)
self.Bind(wx.EVT_MENU, self.OnRedo,id=wx.ID_REDO)
self.Bind(wx.EVT_MENU, self.OnCut,id=wx.ID_CUT)
self.Bind(wx.EVT_MENU, self.OnCopy,id=wx.ID_COPY)
self.Bind(wx.EVT_MENU, self.OnPaste, id=wx.ID_PASTE)
self.Bind(wx.EVT_MENU, self.OnDelete, id=wx.ID_DELETE)
self.Bind(wx.EVT_MENU, self.OnSelectAll, id=wx.ID_SELECTALL)
self.Bind(wx.EVT_MENU, self.OnRemoveWord,id=4)
self.PopupMenu(menu)
def
OnUndo(self,event):self.Undo()
def OnRedo(self,event):self.Redo()
def OnCut(self,event):self.Cut()
def OnCopy(self,event):self.Copy()
def OnPaste(self,event):self.Paste()
def OnDelete(self,event):self.Clear()
def OnSelectAll(self,event):self.SelectAll()
def OnRemoveWord(self,event):
WordToRemove=self.GetSelectedText()
WordInList=False
for num, colVal in enumerate(choices):
choice=re.match(WordToRemove,choices[num])
if choice:
WordInList=True
try:
choices.remove(WordToRemove)
except:
event.Skip()
choices.sort()
self.MyChoices=’ '.join(choices)
break
#else:
#event.Skip()
def OnAutoFill(self,event):
p = self.GetCurrentPos()
st = self.WordStartPosition(p, 1)
en = self.WordEndPosition(p, 1)
self.CurentWord=self.GetTextRange(st,en)
if p-st>AutoFillStartLen:
stc.StyledTextCtrl.AutoCompShow(self,(p-st),self.MyChoices)
def AddWord(self,WordToAdd):
if len(WordToAdd)
AutoFillMinWordLen:
WordInList=False
for num, colVal in enumerate(choices):
choice=re.match(WordToAdd,choices[num])
if choice:
WordInList=True
break
else:
choices.append(WordToAdd)
choices.sort()
self.MyChoices=’ '.join(choices)
def OnKeyDown(self,event):
if event.GetKeyCode() == wx.WXK_SPACE:
self.AddWord(self.CurentWord)
event.Skip()
class TestFrame(wx.Frame):
def init(self):
global MainEditor
wx.Frame.init(self, None, -1, ‘Walts Program’)
MainEditor = MySTC(self)
app = wx.App(0)
if name==“main”:
#app = wx.App(0)
win = TestFrame()
win.Show(True)
app.MainLoop()
stcEditor.py (3.67 KB)