wxPython:创建带有面板的音板

wxPython : Creating a soundboard with panels

我正在使用 wxPython 包制作一个快速而肮脏的音板,并且想知道如何通过实现要播放的声音滚动列表来实现。

这是我要传达的内容的图片: http://i.imgur.com/av0E5jC.png

到目前为止,这是我的代码:

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()

我的问题仍然存在,如何在该面板上加载声音列表并单击某个按钮来播放该声音。我真的不关心实现暂停和快进功能,因为这只会播放非常快的声音文件。

提前致谢。

刚刚删除了文本小部件,取而代之的是一个列表框,并在项目点击时挂钩回调,稍微详细一点:点击时,它找到项目的位置,检索标签名称并在字典中获取文件名 (我们想播放带路径的.wav文件,但不一定要显示完整的文件名)

我重构了代码,因此回调和其他属性是私有的,有助于提高易感性。

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_dict = { "a" : "a.wav","b" : "b.wav","c" : "c2.wav"}
        self.__sound_list = sorted(self.__sound_dict.keys())

        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()
        name = self.__sound_list[self.__list.GetSelection()]
        filename = self.__sound_dict[name]
        print("now playing %s" % filename)

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

main()