Reputation: 2579
I have code as follows
log = wx.TextCtrl(panel, wx.ID_ANY, size=(300,100), style = wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL|wx.TE_DONTWRAP)
I'm writing logs into this box by redirecting stdout. How do I make the cursor dissappear for the TextCtrl because it appends logs based on the position of the cursor right now. I dont want to give the user the privilage to place the cursor at a particular spot in the box basically
Upvotes: 1
Views: 3963
Reputation: 11
This worked for me.
self.log.Bind(wx.EVT_MOUSE_EVENTS,self.onfocus)
def onfocus(self,e):
self.log.SetInsertionPointEnd()
Upvotes: 1
Reputation: 3217
For windows users you can call
wx.CallAfter(self.your_text_ctrl.HideNativeCaret)
You'll have to call it anytime you update the text
Upvotes: 0
Reputation: 347
I just ran into this myself. I resolved it while retaining the ability to highlight entries and use the scrollbar by defining an internal print function in my UI subclass.
import wx,sys
class RedirectText(object):
def __init__(self,wxTextCtrl):
self.out=wxTextCtrl
def write(self,string):
self.out.WriteText(string)
class SomeGUI(wx.Frame):
def __init__(self,parent,title):
super(SomeGUI,self).__init__(parent,title=title)
self.mainsizer=wx.GridBagSizer(2,2)
self.textout=wx.TextCtrl(self,size=(-1,80), style=wx.TE_MULTILINE|wx.TE_READONLY)
self.mainsizer.Add(self.textout,(0,0),span=wx.GBSpan(1,3),flag=wx.EXPAND)
self.redir=RedirectText(self.textout)
sys.stdout=self.redir
self.buttons=[wx.Button(self, label=val) for val in ['Bob Dole', 'Batman', 'Pet Rock']]
for i,v in enumerate(self.buttons):
self.mainsizer.Add(v,(1,i),flag=wx.EXPAND)
self.Bind(wx.EVT_BUTTON,self.BobDole,self.buttons[0])
self.Bind(wx.EVT_BUTTON,self.Batman,self.buttons[1])
self.Bind(wx.EVT_BUTTON,self.Rock,self.buttons[2])
self.SetSizerAndFit(self.mainsizer)
self.Show()
def iprint(self,string): #iprint because "internal print", not because Apple
self.textout.SetInsertionPointEnd()
print(string)
def BobDole(self,e):
self.iprint('Bob Dole!')
def Batman(self,e):
self.iprint('The hero we deserve.')
def Rock(self,e):
self.iprint('It looks happy...')
def main():
app=wx.App()
app.locale=wx.Locale(wx.LANGUAGE_ENGLISH)
somegui=SomeGUI(None, title='It prints text and stuff')
app.MainLoop()
if __name__=='__main__':
main()
Technically speaking, I'd imagine the running time is marginally slower than just disabling the wx.TextCtrl, but I can't see that realistically becoming an issue.
Upvotes: 2
Reputation: 113948
ummmm
log.Enable(False)
?
I think ...
or if you feel awesome you could also do
log.Disable()
Upvotes: 2