[wxpython-users] TextCtrl wx.EVT_SET_FOCUS
Aigars Aigars
srad at inbox.lv
Wed May 14 10:46:41 PDT 2008
Good day all,
I have code as below, and want to find solution for two cases:
1st case - when wx.TextCtrl gots focus (with TAB or ALT+HotKey) - it
has all text selected.
I want the text not been selected and cursor stands at beginning of
text. I have cought wx.EVT_SET_FOCUS and set Selection = (0,0) and
InsertionPoint = 0, but appereantly there is another event, I can not
find, that resets Selection to full text. Which is that event, and
how to change selection OnGotFocus?
2nd case - when wx.TextCtrl gots focus, it has all text selected. If
the text entered in TextCtrl is longer than TextCtrl can display,
OnGotFocus it shows end of the entered text. I want the beginning to
be displayed. style=wx.TE_LEFT doesnot change that. Is there a
solution?
There is my code,
thanks in advance.
import wx
class Form_Main(wx.Frame):
def __init__(self, *args, **kwds):
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.SetSize((800, 450))
self.panel_1 = wx.Panel(self, -1)
self.panel_1.SetMinSize((300, 100))
self.label_1 = wx.StaticText(self.panel_1, -1, "Text &1")
self.text_1 = Ctrl_Char(self.panel_1, -1)
self.text_1.SetValue("1234567890ABCDEFGHIJKLMNOPRSTUVWXYZ")
self.sizer_1 = wx.BoxSizer(wx.HORIZONTAL)
self.sizer_1.Add(self.label_1, 0, wx.ALL, 5)
self.sizer_1.Add(self.text_1, 0, wx.ALL, 5)
self.label_2 = wx.StaticText(self.panel_1, -1, "Text &2")
self.text_2 = Ctrl_Char(self.panel_1, -1)
self.text_2.SetValue("1234567890ABCDEFGHIJKLMNOPRSTUVWXYZ")
self.sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
self.sizer_2.Add(self.label_2, 0, wx.ALL, 5)
self.sizer_2.Add(self.text_2, 0, wx.ALL, 5)
self.label_3 = wx.StaticText(self.panel_1, -1, "Text &3")
self.text_3 = Ctrl_Char(self.panel_1, -1)
self.text_3.SetValue("1234567890ABCDEFGHIJKLMNOPRSTUVWXYZ")
self.sizer_3 = wx.BoxSizer(wx.HORIZONTAL)
self.sizer_3.Add(self.label_3, 0, wx.ALL, 5)
self.sizer_3.Add(self.text_3, 0, wx.ALL, 5)
sizer_Main = wx.BoxSizer(wx.VERTICAL)
sizer_Main.Add(self.sizer_1, 0, wx.ALL, 5)
sizer_Main.Add(self.sizer_2, 0, wx.ALL, 5)
sizer_Main.Add(self.sizer_3, 0, wx.ALL, 5)
self.panel_1.SetSizer(sizer_Main)
class Ctrl_Char(wx.TextCtrl):
def __init__(self, Parent, ID):
wx.TextCtrl.__init__(self, Parent, ID,
style=wx.WANTS_CHARS|wx.TE_LEFT)
self.Bind(wx.EVT_SET_FOCUS, self.OnGotFocus)
self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
self.Bind(wx.EVT_KEY_UP, self.OnKeyUp)
self.Bind(wx.EVT_KILL_FOCUS, self.OnLostFocus)
self.Bind(wx.EVT_TEXT, self.OnEdit)
def OnGotFocus(self, event):
print "OnGotFocus"
self.SetInsertionPoint(0)
self.SetSelection(0,0)
event.Skip()
print "Insertion point = %s, Selection = (%s, %s)" %
(self.GetInsertionPoint(), self.GetSelection()[0],
self.GetSelection()[1])
def OnKeyDown(self, event):
print "OnKeyDown - " + str(event.GetKeyCode())
event.Skip()
def OnKeyUp(self, event):
print "OnKeyUp - " + str(event.GetKeyCode())
event.Skip()
def OnLostFocus(self, event):
print "OnLostFocus"
event.Skip()
def OnEdit(self, event):
print "OnEdit - "" + str(event.GetString()) + """
event.Skip()
class MyApp(wx.App):
def OnInit(self):
wx.InitAllImageHandlers()
GLapp = Form_Main(None, -1, "")
self.SetTopWindow(GLapp)
GLapp.Show()
return 1
if __name__ == "__main__":
app = MyApp(0)
app.MainLoop()
Advertisement:
prasi mammai!
www.mama.lv
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/20080514/956d2264/attachment-0001.htm
More information about the wxpython-users
mailing list