#!/usr/bin/env python import wx import dbg def wrap( lsts, border=4 ): vsz = wx.BoxSizer(wx.VERTICAL) for lst in lsts: hsz = wx.BoxSizer(wx.HORIZONTAL) for o in lst: flag = wx.LEFT | ( wx.RIGHT if o == lst[-1] else 0 ) hsz.Add(o, 0, flag, border) flag = wx.TOP | ( wx.BOTTOM if lst == lsts[-1] else 0 ) vsz.Add( hsz, 0, flag, border ) return vsz def init(app, title): frame = wx.Frame(None, wx.ID_ANY, title) play_lbs = ( ' Play |>', ' Play <|', 'Pause ||' ) btn_play = wx.ToggleButton( frame, wx.ID_ANY, play_lbs[0] ) lb_pause = play_lbs[-1] is_play = lambda : btn_play.GetValue() cbox_reverse = wx.CheckBox( frame, wx.ID_ANY, 'reverse' ) is_reverse = lambda : cbox_reverse.GetValue() speed_lbs = ('x4', 'x2', 'x1', 'x0.5') menu_speed = wx.Choice( frame, wx.ID_ANY, choices=speed_lbs ) #menu_speed.SetSelection(2) menu_speed.SetStringSelection('x1') shifts = (2, 1, 0, -1) get_shift = lambda : shifts[ menu_speed.GetSelection() ] def lb_update(): lb = lb_pause if is_play() else play_lbs[ 1 if is_reverse() else 0 ] btn_play.SetLabel(lb) def hdl(evt): o = evt.GetEventObject() if o in ( btn_play, cbox_reverse ): lb_update() s = '' if o == btn_play: s = 'snd.{}()'.format( 'start' if is_play() else 'stop' ) elif o == cbox_reverse: s = 'snd.reverse={}'.format( o.GetValue() ) elif o == menu_speed: s = 'snd.shift={}'.format( get_shift() ) if o in (cbox_reverse, menu_speed) and is_play(): s = '\n'.join( ( 'snd.stop()', s, 'snd.start()' ) ) if s: dbg.out(s) frame.Bind( wx.EVT_TOGGLEBUTTON, hdl, btn_play ) frame.Bind( wx.EVT_CHECKBOX, hdl, cbox_reverse ) frame.Bind( wx.EVT_CHOICE, hdl, menu_speed ) szr = wrap( [ (btn_play, cbox_reverse, menu_speed) ] ) frame.SetSizer(szr) frame.Layout() frame.Fit() app.SetTopWindow(frame) frame.Show() def wx_run(title=''): class MyApp(wx.App): def OnInit(self): init(self, title) return 1 MyApp(0).MainLoop() if __name__ == "__main__": wx_run('snd') # EOF