def __init__(self, parent, *args, **kwargs): super().__init__(parent) self.SetName(kwargs.get('name', 'SelectionBox')) cols = kwargs.pop('cols', 100) title = kwargs.pop('title', '') sizer = wx.StaticBoxSizer(wx.VERTICAL, self, title) item_sizer = wx.FlexGridSizer(rows=100, cols=cols, hgap=10, vgap=5) self.lookup = kwargs.pop('choices', []) self.index = kwargs.pop('index', 0) kwargs['choices'] = {f'{key}: {value[0]}': key for key, value in self.lookup.items()} self.ctrl = CustomRadioBox(self, *args, **kwargs) item_sizer.Add(self.ctrl, 0, wx.EXPAND) self.text_value = wx.StaticText(self, -1, '') self.hex_ctrl = HexCtrl(self, max=0xFFFF) self.hex_ctrl.Disable() sizer.Add(item_sizer, 0, wx.LEFT | wx.RIGHT, 10) sizer.Add(self.text_value, 0, wx.ALL | wx.EXPAND, 10) sizer.Add(self.hex_ctrl, 0, wx.ALL, 10) self.Bind(wx.EVT_TEXT, self.on_text) self.Bind(wx.EVT_RADIOBOX, self.on_select) self.Bind(wx.EVT_CHECKBOX, self.on_select) self.SetSizer(sizer) self.SetAutoLayout(1)
def __init__(self, parent, *args, **kwargs): super().__init__(parent) self.SetName(kwargs.get('name', 'SelectionBox')) cols = kwargs.pop('cols', 100) title = kwargs.pop('title', '') bytes = kwargs.pop('bytes', 1) sizer = wx.StaticBoxSizer(wx.VERTICAL, self, title) item_sizer = wx.FlexGridSizer(rows=100, cols=cols, hgap=10, vgap=5) self.selections = [] for i in range(bytes * 2): label = wx.StaticText(self, -1, chr(65 + i)) item_sizer.Add(label, 0, wx.EXPAND) ctrl = wx.SpinCtrl(self, *args, **kwargs, min=0, max=15) self.selections.append(ctrl) item_sizer.Add(ctrl, 0, wx.EXPAND) self.hex_ctrl = HexCtrl(self, max=0xFF * bytes) self.hex_ctrl.Disable() sizer.Add(item_sizer, 0, wx.LEFT | wx.RIGHT, 10) sizer.Add(self.hex_ctrl, 0, wx.ALL, 10) self.Bind(wx.EVT_TEXT, self.on_text) self.SetSizer(sizer) self.SetAutoLayout(1)
def __init__(self, parent, *args, **kwargs): super().__init__(parent) self.SetName(kwargs.get('name', 'SelectionBox')) cols = kwargs.pop('cols', 100) title = kwargs.pop('title', '') sizer = wx.StaticBoxSizer(wx.VERTICAL, self, title) item_sizer = wx.FlexGridSizer(rows=100, cols=cols, hgap=10, vgap=5) self.selections = [] choices = kwargs.pop('choices', []) for name, items, multiple in choices: if not items and not multiple: self.selections.insert(0, DummyCtrl()) continue kwargs['label'] = name or '' kwargs['choices'] = items or [] if multiple: ctrl = CustomCheckBox(self, *args, **kwargs) else: ctrl = CustomRadioBox(self, *args, **kwargs) self.selections.insert(0, ctrl) item_sizer.Add(ctrl, 0, wx.EXPAND) self.hex_ctrl = HexCtrl(self, max=0xFFFF) self.hex_ctrl.Disable() sizer.Add(item_sizer, 0, wx.LEFT | wx.RIGHT, 10) sizer.Add(self.hex_ctrl, 0, wx.ALL, 10) self.Bind(wx.EVT_TEXT, self.on_text) self.Bind(wx.EVT_RADIOBOX, self.on_select) self.Bind(wx.EVT_CHECKBOX, self.on_select) self.SetSizer(sizer) self.SetAutoLayout(1)
class SingleSelectionInfoBox(wx.Panel): def __init__(self, parent, *args, **kwargs): super().__init__(parent) self.SetName(kwargs.get('name', 'SelectionBox')) cols = kwargs.pop('cols', 100) title = kwargs.pop('title', '') sizer = wx.StaticBoxSizer(wx.VERTICAL, self, title) item_sizer = wx.FlexGridSizer(rows=100, cols=cols, hgap=10, vgap=5) self.lookup = kwargs.pop('choices', []) self.index = kwargs.pop('index', 0) kwargs['choices'] = {f'{key}: {value[0]}': key for key, value in self.lookup.items()} self.ctrl = CustomRadioBox(self, *args, **kwargs) item_sizer.Add(self.ctrl, 0, wx.EXPAND) self.text_value = wx.StaticText(self, -1, '') self.hex_ctrl = HexCtrl(self, max=0xFFFF) self.hex_ctrl.Disable() sizer.Add(item_sizer, 0, wx.LEFT | wx.RIGHT, 10) sizer.Add(self.text_value, 0, wx.ALL | wx.EXPAND, 10) sizer.Add(self.hex_ctrl, 0, wx.ALL, 10) self.Bind(wx.EVT_TEXT, self.on_text) self.Bind(wx.EVT_RADIOBOX, self.on_select) self.Bind(wx.EVT_CHECKBOX, self.on_select) self.SetSizer(sizer) self.SetAutoLayout(1) def GetValue(self): return self.hex_ctrl.GetValue() def SetValue(self, value): self.hex_ctrl.SetValue(value) self.on_text(None) def set_text(self, value): lookup = self.lookup[value] if len(lookup) > 1: self.text_value.SetLabelText(lookup[1].get(self.index, '')) else: self.text_value.SetLabelText('') def on_select(self, e): value = self.ctrl.GetValue() self.hex_ctrl.SetValue(value) self.set_text(value) e.Skip() def on_text(self, e): value = self.hex_ctrl.GetValue() self.ctrl.SetValue(value) self.set_text(value) if e: e.Skip()
class MultipleSelectionBox(wx.Panel): def __init__(self, parent, *args, **kwargs): super().__init__(parent) self.SetName(kwargs.get('name', 'SelectionBox')) cols = kwargs.pop('cols', 100) title = kwargs.pop('title', '') sizer = wx.StaticBoxSizer(wx.VERTICAL, self, title) item_sizer = wx.FlexGridSizer(rows=100, cols=cols, hgap=10, vgap=5) self.selections = [] choices = kwargs.pop('choices', []) for name, items, multiple in choices: if not items and not multiple: self.selections.insert(0, DummyCtrl()) continue kwargs['label'] = name or '' kwargs['choices'] = items or [] if multiple: ctrl = CustomCheckBox(self, *args, **kwargs) else: ctrl = CustomRadioBox(self, *args, **kwargs) self.selections.insert(0, ctrl) item_sizer.Add(ctrl, 0, wx.EXPAND) self.hex_ctrl = HexCtrl(self, max=0xFFFF) self.hex_ctrl.Disable() sizer.Add(item_sizer, 0, wx.LEFT | wx.RIGHT, 10) sizer.Add(self.hex_ctrl, 0, wx.ALL, 10) self.Bind(wx.EVT_TEXT, self.on_text) self.Bind(wx.EVT_RADIOBOX, self.on_select) self.Bind(wx.EVT_CHECKBOX, self.on_select) self.SetSizer(sizer) self.SetAutoLayout(1) def GetValue(self): return self.hex_ctrl.GetValue() def SetValue(self, value): self.hex_ctrl.SetValue(value) self.on_text(None) def on_select(self, e): value = sum(ctrl.GetValue() << (4 * i) for i, ctrl in enumerate(self.selections)) self.hex_ctrl.SetValue(value) e.Skip() def on_text(self, e): value = self.hex_ctrl.GetValue() for i, ctrl in enumerate(self.selections): ctrl.SetValue((value >> (4 * i)) & sum(1 << n for n in range(ctrl.GetLength()))) if e: e.Skip()
class SplitHexCtrl(wx.Panel): def __init__(self, parent, *args, **kwargs): super().__init__(parent) self.SetName(kwargs.get('name', 'SelectionBox')) cols = kwargs.pop('cols', 100) title = kwargs.pop('title', '') bytes = kwargs.pop('bytes', 1) sizer = wx.StaticBoxSizer(wx.VERTICAL, self, title) item_sizer = wx.FlexGridSizer(rows=100, cols=cols, hgap=10, vgap=5) self.selections = [] for i in range(bytes * 2): label = wx.StaticText(self, -1, chr(65 + i)) item_sizer.Add(label, 0, wx.EXPAND) ctrl = wx.SpinCtrl(self, *args, **kwargs, min=0, max=15) self.selections.append(ctrl) item_sizer.Add(ctrl, 0, wx.EXPAND) self.hex_ctrl = HexCtrl(self, max=0xFF * bytes) self.hex_ctrl.Disable() sizer.Add(item_sizer, 0, wx.LEFT | wx.RIGHT, 10) sizer.Add(self.hex_ctrl, 0, wx.ALL, 10) self.Bind(wx.EVT_TEXT, self.on_text) self.SetSizer(sizer) self.SetAutoLayout(1) def GetValue(self): return self.hex_ctrl.GetValue() def SetValue(self, value): self.hex_ctrl.SetValue(value) value = self.hex_ctrl.GetValue() for i, ctrl in enumerate(self.selections): ctrl.SetValue(value >> (4 * i) & 0xf) def on_text(self, e): value = sum(ctrl.GetValue() << (4 * i) for i, ctrl in enumerate(self.selections)) self.hex_ctrl.SetValue(value) e.Skip()
def add_hex_entry(self, parent, _, *args, **kwargs): return HexCtrl(parent, *args, **kwargs)
def add_hex_entry(self, parent, _, *args, **kwargs): if 'size' not in kwargs: kwargs['size'] = (150, -1) return HexCtrl(parent, *args, **kwargs)