Hi,
I am trying to implement a small shell-like command window for my application
that looks like PyShell using stc. I'd like to know how I can set text not to
be deleted or cut. I want to allow the user to copy only.
Also, for some reason, AddText() does not work when I put it within an event
handler.
Also, I have not been successful in setting autocomplete. I've tried:
self.AutoCompShow(1,"condor_status condor_q condor_master condor_submit")
I thought once I have that line, there will be autocomplete for all words
beginning with "condor". Is that correct? If you have stc sample code that uses
autocomplete, or if you can help me understand how to use autocomplete I will
be very grateful.
I am using wx 2.8 and Python 2.4 on Windows XP. Here's my code:
import wx
import wx.stc as stc
intro = """\
This is the C-GET command window.
This offers an interactive shell-like window to enter parameters for QAPs and
TSPs, as well as Condor commands.
···
--------------------------------------------------------------------------------
-----------------------------------
"""
fonts = ['Lucida Sans Typewriter','Georgia']
buffersize = 0
class CommandWindow(stc.StyledTextCtrl):
def __init__(self, parent, style=wx.SIMPLE_BORDER):
stc.StyledTextCtrl.__init__(self, parent, style=wx.SIMPLE_BORDER)
self.StartShell()
self.flows = self.distances = 0
#self.AutoCompShow(1,"condor_status condor_q condor_master
condor_submit")
self.StyleSetSpec(stc.STC_STYLE_DEFAULT, "size:%d,face:%s" % (8,
fonts[0]))
self.StyleClearAll()
self.StyleSetSpec(1, "size:%d,fore:#FF0000,bold,face:%s" % (8,
fonts[0]))
self.StyleSetSpec(2, "fore:#00007F,bold,size:%d,face:%s" % (8,
fonts[0]))
self.StyleSetSpec(3, "size:%d,fore:#00FF00,bold,face:%s" % (8,
fonts[0]))
self.SetMarginType(0, stc.STC_MARGIN_SYMBOL)
self.MarkerDefine(0, stc.STC_MARK_ARROWS, "black")
self.MarkerDefine(1, stc.STC_MARK_DOTDOTDOT, "black")
self.MarkerAdd(self.GetCurrentLine(), 0)
self.Bind(stc.EVT_STC_MODIFIED, self.TextEntered)
self._styles = [None]*32
self._free = 1
def StartShell(self):
#--- beginning of the command window. shows small intro. ---#
self.SetText(intro)
self.StartStyling(0, 0xff) # from position 0, mask for style bytes 0xff
self.SetStyling(self.GetLength(),1) # length to be style is length of
intro, style using style 1
self.start_write = self.GetLength() # position where one can start
entering text. will be useful cor a 'cls' command
self.GotoPos(self.start_write)
self.last_enter = 0
self.AddText("added text")#this works!!
def TextEntered(self, evt):
if evt.GetText() == '\r\n':# check if user has pressed 'enter'
pos = evt.GetPosition()
if self.last_enter:
text = self.GetTextRange(self.last_enter, pos)
else:
text = self.GetTextRange(self.start_write, pos)
self.last_enter = pos+2
print "you hit enter!!!"
print text
self.MarkerAdd(self.GetCurrentLine()+1, 0)
self.AddText("maakla maakla maakla maakla")#this doen't work!!
app = wx.PySimpleApp()
frame = wx.Frame(None)
CommandWindow(frame)
frame.Show()
app.MainLoop()