diff -urN v2/wx_smp3.py v3/wx_smp3.py --- v2/wx_smp3.py 1970-01-01 09:00:00.000000000 +0900 +++ v3/wx_smp3.py 2020-05-30 19:58:52.000000000 +0900 @@ -0,0 +1,58 @@ +#!/usr/bin/env python + +import wx + +import empty +import wx_ut +import dbg + +def btn_hdl(inf): + tc = inf.wxo.L.tc + tc.SetValue( inf.label ) + +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 ) + + (btn_ok, btn_cancel, btn_go) = wxo.button_new( [ 'OK', 'Cancel', 'Go' ], btn_hdl ) + + def ckb_hdl(inf): + btn_go.Enable( inf.v ) + + ckb = wxo.checkbox_new( 'enable', ckb_hdl, init_stat=True ) + + 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 ), + wp( [ wp( btn_ok ), wp( btn_cancel ), wp( ckb ), wp( btn_go, prop=1 ) ], flag=wx.EXPAND ), + ] + wxo.wrap_frame( lsts ) + wxo.L = empty.new( locals() ) + +def run(): + wxo = wx_ut.new( 'wx sample 3', init ) + wxo.main_loop() + +if __name__ == "__main__": + run() +# EOF diff -urN v2/wx_ut.py v3/wx_ut.py --- v2/wx_ut.py 2020-05-30 01:03:28.000000000 +0900 +++ v3/wx_ut.py 2020-05-30 19:58:22.000000000 +0900 @@ -133,6 +133,9 @@ win.SetSizer( vsz ) + def wrap_frame(lsts): + wrap( e.frame, lsts ) + obj_cls_dic = {} @@ -184,13 +187,6 @@ return o.Bind( evt, bind_hdl ) - def label_new(s, parent=None): - if type( s ) == list: - f = lambda s: label_new( s, parent ) - return list( map( f, s ) ) - - return wx_new( wx.StaticText, s, style=wx.ALIGN_CENTER, parent=parent ) - obj_dic = {} @@ -219,19 +215,59 @@ + def label_new(s, **kwds): + if type( s ) == list: + f = lambda s: label_new( s, **kwds ) + return list( map( f, s ) ) + + return wx_new( wx.StaticText, s, style=wx.ALIGN_CENTER, **kwds ) + + + + def button_new(lbl, hdl=None, **kwds): + if type( lbl ) == list: + f = lambda lbl: button_new( lbl, hdl, **kwds ) + return list( map( f, lbl ) ) + + btn = wx_new( wx.Button, lbl, **kwds ) + if hdl: + bind( btn, hdl ) + return btn + + + + def checkbox_new(lbl, hdl=None, init_stat=False, **kwds): + if type( lbl ) == list: + f = lambda lbl: checkbox_new( lbl, hdl, init_stat, **kwds ) + return list( map( f, lbl ) ) + + ckb = wx_new( wx.CheckBox, lbl, **kwds ) + if init_stat: + ckb.SetValue( init_stat ) + if hdl: + bind( ckb, hdl ) + return ckb + + + + def menu_get(menu): + p = obj_dic.get( menu ) + (lbls, hdl, vs) = ( p.lbls, p.hdl, p.vs ) + + i = menu.GetSelection() + lbl = p.lbls[ i ] + v = vs[ i ] if vs and i < len( vs ) else None + return empty.new( i=i, lbl=lbl, v=v ) + def menu_hdl(inf): menu = inf.o 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 ) - hdl( inf ) + if p.hdl: + inf.menu = menu_get( menu ) + p.hdl( inf ) - def menu_new(lbls, hdl=None, init_str='', vs=None, parent=None): - menu = wx_new( wx.Choice, choices=lbls, parent=parent ) + def menu_new(lbls, hdl=None, init_str='', vs=None, **kwds): + menu = wx_new( wx.Choice, choices=lbls, **kwds ) if not init_str: init_str = lbls[ 0 ] menu.SetStringSelection( init_str ) @@ -259,8 +295,8 @@ 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 ) ) + def toggle_new(lbls, hdl=None, init_stat=False, **kwds): + tbtn = wx_new( wx.ToggleButton, toggle_lbl( lbls, init_stat ), **kwds ) if init_stat: tbln.SetValue( init_state ) obj_dic[ tbtn ] = empty.new( lbls=lbls, hdl=hdl )