kommander0000 kommander0000 - 3 months ago 19
Python Question

wxPython : Creating a soundboard with panels

I am making a quick and dirty soundboard using the wxPython package and was wondering how to go by implementing a scroll-list of sounds to play.

Here is a picture of what I am trying to convey:
http://i.imgur.com/av0E5jC.png

and here is my code so far:

import wx

class windowClass(wx.Frame):
def __init__(self, *args, **kwargs):
super(windowClass,self).__init__(*args,**kwargs)
self.basicGUI()
def basicGUI(self):
panel = wx.Panel(self)
menuBar = wx.MenuBar()
fileButton = wx.Menu()
editButton = wx.Menu()
exitItem = fileButton.Append(wx.ID_EXIT, 'Exit','status msg...')

menuBar.Append(fileButton, 'File')
menuBar.Append(editButton, 'Edit')

self.SetMenuBar(menuBar)
self.Bind(wx.EVT_MENU, self.Quit, exitItem)

wx.TextCtrl(panel,pos=(10,10), size=(250,150))

self.SetTitle("Soundboard")
self.Show(True)
def Quit(self, e):
self.Close()
def main():
app = wx.App()
windowClass(None)
app.MainLoop()


main()


My question remains, how does one load a list of sounds on that panel and click a certain button to play that sound. I don't really care about implementing pause and fast forward features since this is only going to play really quick sound files.

Thanks in advance.

Answer

Just removed the text widget, replaced by a listbox, and hooked a callback on item click:

import wx

class windowClass(wx.Frame):
    def __init__(self, *args, **kwargs):
        super(windowClass,self).__init__(*args,**kwargs)
        self.basicGUI()
    def basicGUI(self):
        panel = wx.Panel(self)
        menuBar = wx.MenuBar()
        fileButton = wx.Menu()
        editButton = wx.Menu()
        exitItem = fileButton.Append(wx.ID_EXIT, 'Exit','status msg...')

        menuBar.Append(fileButton, 'File')
        menuBar.Append(editButton, 'Edit')

        self.SetMenuBar(menuBar)
        self.Bind(wx.EVT_MENU, self.Quit, exitItem)

        self.__sound_list = ["a","b","c"]
        self.__list = wx.ListBox(panel,pos=(20,20), size=(250,150))
        for i in self.__sound_list: self.__list.Append(i)
        self.__list.Bind(wx.EVT_LISTBOX,self.__on_click)

        #wx.TextCtrl(panel,pos=(10,10), size=(250,150))

        self.SetTitle("Soundboard")
        self.Show(True)
    def __on_click(self,event):
        event.Skip()
        print("clicked on %s" % self.__sound_list[self.__list.GetSelection()])

    def Quit(self, e):
        self.Close()
def main():
    app = wx.App()
    windowClass(None)
    app.MainLoop()


main()
Comments