Question

I have created a simple music player using wxPython which has a Frame and a Panel and plays music using the tutorial given here.

Furthermore I also added a playlist functionality to this which uses ObjectListView and shows all tracks from a .m3u file. This playList is a separate python module which

class MainPanel(wx.Panel):

def __init__(self, parent, playListSelected):
    //stuff

def GetOLVColClicked(self, event):
    item = event.GetEventObject().GetSelectedObjects()
    print item[0]['path']

class MainFrame(wx.Frame):
    def __init__(self, playList):
        wx.Frame.__init__(self, parent=None, id=wx.ID_ANY, 
                      title="ObjectListView Demo", size=(800,600))
        panel = MainPanel(self, playList)

class GenApp(wx.App):
    def __init__(self, playList, redirect=False, filename=None):
        self.playList = playList
        wx.App.__init__(self, redirect, filename)

    def OnInit(self):
        frame = MainFrame(self.playList)
        frame.Show()
        return True

On clicking on any track in the playlist I can get the entire path of the song. I was wondering how to send this song to the existing music player and play it. Or is this approach wrong and is there a better approach to accomodate the playlist?

Was it helpful?

Solution

This approach is pretty close to the way I was thinking of doing it back when I was pondering how to enhance my own mp3 player. To pass information between classes, I think that pubsub is by far the most elegant solution, even if it is a little magical. You can read my tutorial on the subject or you can read about it on the wxPython wiki:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top