示例#1
0
    def __init__(self, parent, dev):
        wx.Panel.__init__(self, parent, -1)

        device_st = wx.StaticText(self, -1, Text.device_lbl)
        device_ctrl = eg.Choice(self, 0, choices=[])
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(device_st, 0, wx.EXPAND | wx.ALL, 5)
        sizer.Add(device_ctrl, 0, wx.EXPAND | wx.ALL, 5)

        def on_choice(evt):
            global dev
            dev = device_ctrl.GetStringSelection()
            evt.Skip()

        device_ctrl.Bind(wx.EVT_CHOICE, on_choice)

        def update_devices(adapter):
            choices = list(d.name for d in adapter.devices)
            device_ctrl.SetItems(choices)

            if dev in choices:
                device_ctrl.SetStringSelection(dev)
            else:
                device_ctrl.SetSelection(0)

        def get_value():
            return dev

        self.GetValue = get_value
        self.UpdateDevices = update_devices
        self.SetSizer(sizer)
示例#2
0
    def __init__(self, parent, com_port, adapter_name, adapters):
        wx.Panel.__init__(self, parent, -1)

        choices = list(adapter.name + ' : ' + adapter.com_port
                       for adapter in adapters)

        adapters_st = wx.StaticText(self, -1, Text.adapter_lbl)
        adapters_ctrl = eg.Choice(self, 0, choices=sorted(choices))

        adapters_ctrl.SetStringSelection(
            str(adapter_name) + ' : ' + str(com_port))

        def get_value():
            value = adapters_ctrl.GetStringSelection()
            a_name, c_port = value.split(' : ')
            return c_port, a_name

        adapters_sizer = wx.BoxSizer(wx.HORIZONTAL)
        adapters_sizer.Add(adapters_st, 0, wx.EXPAND | wx.ALL, 5)
        adapters_sizer.Add(adapters_ctrl, 0, wx.EXPAND | wx.ALL, 5)

        self.GetValue = get_value
        self.SetSizer(adapters_sizer)
 def Choice(self, value, choices, *args, **kwargs):
     return eg.Choice(self, value, choices, *args, **kwargs)