Lamonte
2008-07-04 15:53:32 UTC
I'm having issues with my application and binding events. Robin Dunn
told me the following:
-------
Catch the EVT_CHAR event and if the keycode is wx.WXK_RETURN do nothing,
and call event.Skip() for everything else.
-------
I tried the following in the attachment also here:
import wx
class TwitterWidget(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id)
self.SetTitle("Twitter")
self.SetSize((219,240))
self.panel = TwitterWidgetPanel(self,wx.ID_ANY)
self.Show()
class TwitterWidgetPanel(wx.Panel):
def __init__(self,parent,id):
wx.Panel.__init__(self,parent,id)
self.addStaticBox()
def addStaticBox(self):
self.sb = wx.StaticBox(self, -1, "Twitter Status")
self.sbsizer = wx.StaticBoxSizer(self.sb, wx.VERTICAL)
table = self.addTextBoxes()
self.sbsizer.Add(table,1,wx.EXPAND,25)
a = wx.BoxSizer()
a.Add(self.sbsizer, 1, wx.EXPAND, 25)
self.SetSizer(a)
def addTextBoxes(self):
#twitter status box
self.tb1_text = wx.StaticText(self, -1, "Add a new twitter status:")
self.tb1 = wx.TextCtrl(self, -1, "",size=(200, 100),
style=wx.TE_MULTILINE)
self.tb1.Bind(wx.EVT_CHAR,self.onKeyDown)
#twitter state box
state = ['Reading','Looking at','Listening
To','Watching','Pissed at','Chilling at','Coding']
x = 0
while x < len(state):
state[x] = state[x] + ':'
x = x + 1
self.tb2_text = wx.StaticText(self, -1, "Twitter State:")
self.tb2 = wx.Choice(self, -1, (100, 50), choices = state)
#twitter submit button
self.tb3 = wx.Button(self, -1, "Add New Status")
self.Bind(wx.EVT_BUTTON,self.onSubmitTwit,self.tb3) #gets our
values for each required input
#
table = wx.FlexGridSizer(cols=1, hgap=4, vgap=4)
table.AddMany([ self.tb2_text, self.tb2, self.tb1_text,
self.tb1,self.tb3 ])
return table
def onSubmitTwit(self, event):
print self.tb1.GetValue()
def onKeyDown(self,event):
keycode = event.GetKeyCode()
if keycode == wx.WXK_RETURN:
event.Skip()
app = wx.App()
twit = TwitterWidget(None,wx.ID_ANY)
app.MainLoop()
It catches my event, but it doesn't do anything. Please help.
told me the following:
-------
Catch the EVT_CHAR event and if the keycode is wx.WXK_RETURN do nothing,
and call event.Skip() for everything else.
-------
I tried the following in the attachment also here:
import wx
class TwitterWidget(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id)
self.SetTitle("Twitter")
self.SetSize((219,240))
self.panel = TwitterWidgetPanel(self,wx.ID_ANY)
self.Show()
class TwitterWidgetPanel(wx.Panel):
def __init__(self,parent,id):
wx.Panel.__init__(self,parent,id)
self.addStaticBox()
def addStaticBox(self):
self.sb = wx.StaticBox(self, -1, "Twitter Status")
self.sbsizer = wx.StaticBoxSizer(self.sb, wx.VERTICAL)
table = self.addTextBoxes()
self.sbsizer.Add(table,1,wx.EXPAND,25)
a = wx.BoxSizer()
a.Add(self.sbsizer, 1, wx.EXPAND, 25)
self.SetSizer(a)
def addTextBoxes(self):
#twitter status box
self.tb1_text = wx.StaticText(self, -1, "Add a new twitter status:")
self.tb1 = wx.TextCtrl(self, -1, "",size=(200, 100),
style=wx.TE_MULTILINE)
self.tb1.Bind(wx.EVT_CHAR,self.onKeyDown)
#twitter state box
state = ['Reading','Looking at','Listening
To','Watching','Pissed at','Chilling at','Coding']
x = 0
while x < len(state):
state[x] = state[x] + ':'
x = x + 1
self.tb2_text = wx.StaticText(self, -1, "Twitter State:")
self.tb2 = wx.Choice(self, -1, (100, 50), choices = state)
#twitter submit button
self.tb3 = wx.Button(self, -1, "Add New Status")
self.Bind(wx.EVT_BUTTON,self.onSubmitTwit,self.tb3) #gets our
values for each required input
#
table = wx.FlexGridSizer(cols=1, hgap=4, vgap=4)
table.AddMany([ self.tb2_text, self.tb2, self.tb1_text,
self.tb1,self.tb3 ])
return table
def onSubmitTwit(self, event):
print self.tb1.GetValue()
def onKeyDown(self,event):
keycode = event.GetKeyCode()
if keycode == wx.WXK_RETURN:
event.Skip()
app = wx.App()
twit = TwitterWidget(None,wx.ID_ANY)
app.MainLoop()
It catches my event, but it doesn't do anything. Please help.