diff -urN v1/wx_smp2.py v2/wx_smp2.py --- v1/wx_smp2.py 1970-01-01 09:00:00.000000000 +0900 +++ v2/wx_smp2.py 2020-05-30 01:04:29.000000000 +0900 @@ -0,0 +1,46 @@ +#!/usr/bin/env python + +import wx + +import empty +import wx_ut +import dbg + +def tbtn_1_hdl(inf): + tc = inf.wxo.L.tc + tc.SetValue( 'tbtn_1={}'.format( inf.v ) ) + +def menu_hdl(inf): + tc = inf.wxo.L.tc + tc.SetValue( '{} {} {} Hz'.format( inf.menu.i, inf.menu.lbl, inf.menu.v ) ) + +def init(wxo): + tc = wxo.wx_new( wx.TextCtrl, '', min_h=80 ) + + tbtn_1 = wxo.toggle_new( 'ON', tbtn_1_hdl ) + + tbtn_2 = wxo.toggle_new( [ 'ON', 'OFF' ] ) + + def tbtn_2_hdl(inf): + tc.SetValue( 'tbtn_2={} lbl={}'.format( inf.v, inf.label ) ) + + wxo.toggle_bind( tbtn_2, tbtn_2_hdl ) + + lb = wxo.label_new( 'radio' ) + menu = wxo.menu_new( [ 'MBS', 'ABC', 'OBC' ], menu_hdl, 'ABC', [ 1179, 1008, 1314 ] ) + + wp = wxo.wp + lsts = [ + wp( [ wp( tc, prop=1, flag=wx.EXPAND ) ], prop=1, flag=wx.EXPAND ), + wp( [ wp( tbtn_1 ), wp( tbtn_2, prop=1 ), wp( lb ), wp( menu ) ], flag=wx.EXPAND ), + ] + wxo.wrap( wxo.frame, lsts ) + wxo.L = empty.new( locals() ) + +def run(): + wxo = wx_ut.new( 'wx sample 2', init ) + wxo.main_loop() + +if __name__ == "__main__": + run() +# EOF diff -urN v1/wx_ut.py v2/wx_ut.py --- v1/wx_ut.py 2020-05-25 00:37:33.000000000 +0900 +++ v2/wx_ut.py 2020-05-30 01:03:28.000000000 +0900 @@ -192,44 +192,85 @@ return wx_new( wx.StaticText, s, style=wx.ALIGN_CENTER, parent=parent ) - drags = {} + obj_dic = {} + + def bind_obj_dic_hdl(o, hdl): + p = obj_dic.get( o ) + if p: + p.hdl = hdl + + def drag_hdl(inf): - (drag, cb) = drags.get( inf.o ) + p = obj_dic.get( inf.o ) + (drag, hdl) = ( p.drag, p.hdl ) dr = drag.update( inf ) - if dr and cb: - cb( dr ) + if dr and hdl: + inf.dr = dr + hdl( inf ) - def set_drag_cb(o, cb): + def set_drag_hdl(o, hdl): if type( o ) == list: f = lambda o: set_drag_cb( o, cb ) return list( map( f, o ) ) - drags[ o ] = ( drag_new( o ), cb ) + obj_dic[ o ] = empty.new( drag=draw_new( o ), hdl=hdl ) bind( o, drag_hdl, mouse_evts ) - menus = {} def menu_hdl(inf): menu = inf.o - (lbls, cb, vs) = menus.get( menu ) - if cb: + p = obj_dic.get( menu ) + (lbls, hdl, vs) = ( p.lbls, p.hdl, p.vs ) + if hdl: i = menu.GetSelection() lbl = lbls[ i ] v = vs[ i ] if vs and i < len( vs ) else None inf.menu = empty.new( i=i, lbl=lbl, v=v ) - cb( inf ) + hdl( inf ) - def menu_new(lbls, cb=None, init_str='', vs=None, parent=None): + def menu_new(lbls, hdl=None, init_str='', vs=None, parent=None): menu = wx_new( wx.Choice, choices=lbls, parent=parent ) if not init_str: init_str = lbls[ 0 ] menu.SetStringSelection( init_str ) - menus[ menu ] = ( lbls, cb, vs ) + obj_dic[ menu ] = empty.new( lbls=lbls, hdl=hdl, vs=vs ) bind( menu, menu_hdl ) return menu + def menu_bind(menu, hdl): + bind_obj_dic_hdl( menu, hdl ) + + + + def toggle_lbl(lbls, v): + if type( lbls ) == list: + i = 1 if len( lbls ) >= 2 and v else 0 + return lbls[ i ] + return lbls # str + + def toggle_hdl(inf): + tbtn = inf.o + p = obj_dic.get( tbtn ) + lbl = toggle_lbl( p.lbls, inf.v ) + tbtn.SetLabel( lbl ) + inf.label = lbl + if p.hdl: + p.hdl( inf ) + + def toggle_new(lbls, hdl=None, init_stat=False, parent=None): + tbtn = wx_new( wx.ToggleButton, toggle_lbl( lbls, init_stat ) ) + if init_stat: + tbln.SetValue( init_state ) + obj_dic[ tbtn ] = empty.new( lbls=lbls, hdl=hdl ) + bind( tbtn, toggle_hdl ) + return tbtn + + def toggle_bind(tbtn, hdl): + bind_obj_dic_hdl( tbtn, hdl ) + + class MyApp(wx.App): def OnInit(self):