Reputation: 141
I have this bind "self.Bind(wx.EVT_LISTBOX, self.selLoadFile, listbox)". How would I add another function, I guess thats what youd call it. Like the self.selLoadFile, how would I add another function to the same event? I am making a music player and want the file to automatically play after it is selected. The self.selLoadFile function loads the file, how would I add the "self.Play" function to the same evt?
Thanks in advance!!
I'm sorry, I am new to programming. Could you help me out alittle? So if my functions where:
def selLoadFile(self, event):
my_selection = self.myListBox.GetStringSelection()
file_path = os.path.join(os.getcwd(),"songs",my_selection)
self.doLoadFile2(file_path)
def doLoadFile2(self, file_path):
if not self.mc.Load(file_path):
wx.MessageBox("Unable to load %s: Unsupported format?" % file_path, "ERROR", wx.ICON_ERROR | wx.OK)
else:
folder, filename = os.path.split(file_path)
self.st_file.SetLabel('%s' % filename)
self.mc.SetBestFittingSize()
self.mc.Play()
def Play(self, event):
self.mc.Play()
self.playbackSlider.SetRange(0,self.mc.Length())
How would I include all 3 of the above functions in one function?
Upvotes: 3
Views: 2970
Reputation: 33111
If you want to bind a widget to two event handlers, then just do it. That will work as long as you call event.Skip() at the end of the handler code. Without this line the event will be consumed by the first handler and will not be caught by any additional handlers. Here's a silly example:
import wx
########################################################################
class MyPanel(wx.Panel):
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent)
btn = wx.Button(self, label="Press Me")
btn.Bind(wx.EVT_BUTTON, self.HandlerOne)
btn.Bind(wx.EVT_BUTTON, self.HandlerTwo)
def HandlerOne(self, event):
print "handler one fired!"
event.Skip()
def HandlerTwo(self, event):
print "handler two fired!"
event.Skip()
########################################################################
class MyFrame(wx.Frame):
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, title="Test")
panel = MyPanel(self)
self.Show()
if __name__ == "__main__":
app = wx.App(False)
frame = MyFrame()
app.MainLoop()
Upvotes: 6