def __init__(self, parent): # Basic Construction stuff super().__init__(parent) self.app_data = AppData() self._output_garbage_collector = 0 self._input_matrix_enabled = False # Create modbus instance, to have access to its props instance = ModbusConnectionThreadSingleton() self.modbus = instance.thread_instance_get() # Create content for self.input_matrix = InputArray(parent=self, title='Associated inputs:', dimension=(3, 5), col_titles=['1', '2', '3', '4', '5'], row_titles=['X1', 'X2', 'X3']) self.inner_panel_sizer = wx.BoxSizer(wx.VERTICAL) self.inner_panel_sizer.Add(self.input_matrix, 0, wx.ALL | wx.ALIGN_CENTER, 10) self.SetSizer(self.inner_panel_sizer) self.input_matrix.disable() self.app_data.iface_output_handler_register(self._matrix_visibility_update) for instance in self.input_matrix.instance_array: self.Bind(wx.EVT_CHECKBOX, self._checkbox_pressed_handle, instance.cell_instance.checkbox)
def __init__(self, parent=None): super().__init__(parent) self.app_data = AppData() self._input_matrix_enabled = False self._in_matrix_update_stage = 0 self.modbus = ModbusConnectionThreadSingleton() self.modbus = self.modbus.thread_instance_get() self.input_matrix = InputArray(parent=self, title='Inputs mode toggle:', interface=INPUT_INTERFACE, dimension=(3, 5), col_titles=['1', '2', '3', '4', '5'], row_titles=['X1', 'X2', 'X3']) inner_panel_sizer = wx.BoxSizer(wx.VERTICAL) inner_panel_sizer.Add(self.input_matrix, 0, wx.ALL | wx.CENTER, 15) self.input_matrix.disable() self.app_data.iface_conn_handler_register( self._matrix_initial_data_setup) self.app_data.iface_output_handler_register( self._matrix_visibility_update) self.app_data.iface_input_handler_register(self._in_matrix_data_gather) self.SetSizer(inner_panel_sizer) for instance in self.input_matrix.instance_array: self.Bind(wx.EVT_CHECKBOX, self._checkbox_pressed_handle, instance.cell_instance.checkbox)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.main_sizer = wx.BoxSizer(wx.VERTICAL) inner_sizer = wx.BoxSizer(wx.HORIZONTAL) self.modbus_label = ' ' self.conn_static_text = wx.StaticText(parent=self, label='Connection status') self.modbus_status_text = wx.StaticText(parent=self, label='') inner_sizer.Add(self.conn_static_text, 2, wx.LEFT | wx.ALIGN_LEFT, 10) inner_sizer.Add(self.modbus_status_text, 4, wx.LEFT | wx.ALIGN_LEFT, 120) self.main_sizer.Add(inner_sizer, 1, wx.ALL | wx.EXPAND, 2) self.appdata = AppData() self.modbus = ModbusConnectionThreadSingleton().modbus_comm_instance self.SetSizer(self.main_sizer) self.appdata.iface_output_handler_register(self._conn_status_update) self.appdata.iface_output_handler_register(self._modbus_data_update) self.status = 1 self.conn_static_text.SetLabel(self.STATUSES[self.status])
def __init__(self, parent=None): super().__init__(parent=parent) self.app_data = AppData() self.modbus = ModbusConnectionThreadSingleton() self.modbus = self.modbus.thread_instance_get() self.btm_page_sizer = wx.BoxSizer(wx.HORIZONTAL) self.notebook_sizer = wx.BoxSizer(wx.HORIZONTAL) self.notebook = wx.Notebook(self) self.sub_canvases = list() for i in range(8): self.sub_canvases.append(_BtmSubPanel(parent=self.notebook)) self.notebook.AddPage(self.sub_canvases[i], "Relay " + str(1 + i)) ''' Here goes a very important line of a code, setting notebook item's color to default window color instead of white color, chosen by default, when creating widget ''' self.notebook.SetOwnBackgroundColour(self.GetBackgroundColour()) self.notebook_sizer.Add(self.notebook, 0, wx.EXPAND) self.btm_page_sizer.Add(self.notebook_sizer, 0, wx.EXPAND) self.SetSizer(self.btm_page_sizer) # Apply data on connection self.app_data.iface_conn_handler_register( self._input_left_matrix_update_on_conn) self.app_data.iface_conn_handler_register( self._input_radio_data_set_on_conn) # Interface handlers, always called to update data on screen self.app_data.iface_output_handler_register(self._out_led_update) self.app_data.iface_output_handler_register( self._matrix_visibility_update) self.app_data.iface_output_handler_register( self._input_right_matrix_update) # Gather input data handlers self.app_data.iface_input_handler_register( self._input_left_matrix_data_gather) self.app_data.iface_input_handler_register( self._input_radio_data_gather) self._input_matrix_enabled = 0 self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.on_page_change)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # Define two singletones, containing data to share across application self.app_settings = Settings() self.app_settings.settings_load() self.app_data = AppData() self.modbus_singleton = None # Create a gui application with main frame self.gui = GuiApp(size=(439, 550), title="Light Controller") # Create threads self.modbus_singleton = ModbusConnectionThreadSingleton() self.modbus_connection = self.modbus_singleton.modbus_comm_instance self.modbus_connection.daemon = True self.poll_thread = threading.Thread(target=self._app_settings_poll) self.poll_thread.daemon = True self.main_logic_thread = threading.Thread( target=self._main_logic_handler) self.main_logic_thread.daemon = True self.data_thread = threading.Thread(target=self._modbus_data_handler) self.data_thread.daemon = True self.conn_state_prev = None self.app_stage = 0
class TopRightPanel(wx.Panel): def __init__(self, parent=None): super().__init__(parent) self.app_data = AppData() self.modbus = ModbusConnectionThreadSingleton() self.modbus = self.modbus.thread_instance_get() self.input_matrix = InputArray(parent=self, title='Inputs state:', interface=DISPLAY_INTERFACE, dimension=(3, 5), col_titles=['1', '2', '3', '4', '5'], row_titles=['X1', 'X2', 'X3']) inner_panel_sizer = wx.BoxSizer(wx.VERTICAL) inner_panel_sizer.Add(self.input_matrix, 0, wx.ALL | wx.CENTER, 15) self.app_data.iface_output_handler_register(self._inputs_state_update) self.SetSizer(inner_panel_sizer) def _inputs_state_update(self): for i in range(15): self.input_matrix.value_set_by_index( i, self.app_data.input_state_get(i))
def __init__(self, parent=None): # Basic construction stuff super().__init__() self.parent = parent self.settings = Settings() self._garbage_event_collector = 0 instance = ModbusConnectionThreadSingleton() self.modbus = instance.thread_instance_get() # Start with connect menu self.conn_submenu = wx.Menu() self.conn_submenu_item_connect = self.conn_submenu.Append( -1, 'Connect...', 'Connect...') self.conn_submenu_item_disconnect = self.conn_submenu.Append( -1, 'Disconnect', 'Disconnect') self.conn_submenu.AppendSeparator() self.conn_submenu_item_quick_conn = self.conn_submenu.Append( -1, 'Quick Connect', 'Quick Connect') # TODO: Decide if this one is needed # self.help_menu = wx.Menu() # self.about = self.help_menu.Append(-1, 'About', 'About') self.Append(self.conn_submenu, 'Connection') # self.Append(self.help_menu, 'Help') self.dialog_window = None parent.Bind(wx.EVT_MENU, self.on_click_conn, self.conn_submenu_item_connect) parent.Bind(wx.EVT_MENU, self.on_clock_dc, self.conn_submenu_item_disconnect) parent.Bind(wx.EVT_MENU, self.on_click_quick_conn, self.conn_submenu_item_quick_conn) # Insert a certain delay for refresh button self.timer = wx.Timer() self.timer_evt_handler = wx.EvtHandler() self.timer.SetOwner(self.timer_evt_handler, id=228) self.timer_evt_handler.Bind(wx.EVT_TIMER, self._refresh, self.timer, id=228) self._refresh(wx.EVT_TIMER)
class TopLeftPanel(wx.Panel): def __init__(self, parent=None): super().__init__(parent) self.app_data = AppData() self._input_matrix_enabled = False self._in_matrix_update_stage = 0 self.modbus = ModbusConnectionThreadSingleton() self.modbus = self.modbus.thread_instance_get() self.input_matrix = InputArray(parent=self, title='Inputs mode toggle:', interface=INPUT_INTERFACE, dimension=(3, 5), col_titles=['1', '2', '3', '4', '5'], row_titles=['X1', 'X2', 'X3']) inner_panel_sizer = wx.BoxSizer(wx.VERTICAL) inner_panel_sizer.Add(self.input_matrix, 0, wx.ALL | wx.CENTER, 15) self.input_matrix.disable() self.app_data.iface_conn_handler_register( self._matrix_initial_data_setup) self.app_data.iface_output_handler_register( self._matrix_visibility_update) self.app_data.iface_input_handler_register(self._in_matrix_data_gather) self.SetSizer(inner_panel_sizer) for instance in self.input_matrix.instance_array: self.Bind(wx.EVT_CHECKBOX, self._checkbox_pressed_handle, instance.cell_instance.checkbox) def _checkbox_pressed_handle(self, event): self.app_data.user_interaction = True def _matrix_initial_data_setup(self): for i in range(15): toggle = self.app_data.input_trigger_type_is_toggle_get(i) self.input_matrix.value_set_by_index(i, toggle) def _matrix_visibility_update(self): if self.modbus.is_connected: if self._input_matrix_enabled is False: self.input_matrix.enable() self._input_matrix_enabled = True else: if self._input_matrix_enabled is True: self.input_matrix.disable() self._input_matrix_enabled = False def _in_matrix_data_gather(self): val_list = [] for in_id in range(15): value = self.input_matrix.value_get_by_index(in_id) val_list.append(value) self.app_data.input_trigger_type_is_toggle_set_mask(val_list)
def __init__(self, *args, parent=None, title=None, settings=None, **kwargs): super().__init__(parent=parent) self.settings = None self.SetSize((300, 180)) self.SetTitle(title) self.CenterOnParent() self.settings = Settings() self._pending_dev_port = None self.panel = wx.Panel(self) self.panel_sizer = wx.BoxSizer(wx.VERTICAL) self.relay_cfg_byte = 0 self.radio_boxes_list = list() self.box_style = wx.VERTICAL self.radio_boxes_sizer = wx.BoxSizer(self.box_style) rows_or_cols = wx.RA_SPECIFY_COLS if self.box_style == wx.VERTICAL else wx.RA_SPECIFY_ROWS for i in range(4): self.radio_boxes_list.append( RadioBoxWrapper(parent=self.panel, id=wx.ID_ANY, label="Relay " + str(i + 1), choices=['Auto', 'On', 'Off'], majorDimension=3, style=rows_or_cols, name=str(i + 1), secret_id=i)) self.radio_boxes_list[i].Bind(wx.EVT_RADIOBOX, self.radio_box_handler) self.radio_boxes_sizer.Add(self.radio_boxes_list[i], 0, wx.ALL, 5) self.button_accept = wx.Button(parent=self.panel, label='Accept') modbus_singleton = ModbusConnectionThreadSingleton() self.modbus = modbus_singleton.modbus_comm_instance self.panel.Bind(wx.EVT_BUTTON, self.on_accept, self.button_accept) self.panel_sizer.Add( self.radio_boxes_sizer, 0, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL, ) self.panel_sizer.Add(self.button_accept, 0, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL, 3) self.panel.SetSizer(self.panel_sizer)
class StatusPanel(wx.Panel): STATUSES = {0: 'Connected', 1: 'Disconnected', 2: 'Connection timeout'} def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.main_sizer = wx.BoxSizer(wx.VERTICAL) inner_sizer = wx.BoxSizer(wx.HORIZONTAL) self.modbus_label = ' ' self.conn_static_text = wx.StaticText(parent=self, label='Connection status') self.modbus_status_text = wx.StaticText(parent=self, label='') inner_sizer.Add(self.conn_static_text, 2, wx.LEFT | wx.ALIGN_LEFT, 10) inner_sizer.Add(self.modbus_status_text, 4, wx.LEFT | wx.ALIGN_LEFT, 120) self.main_sizer.Add(inner_sizer, 1, wx.ALL | wx.EXPAND, 2) self.appdata = AppData() self.modbus = ModbusConnectionThreadSingleton().modbus_comm_instance self.SetSizer(self.main_sizer) self.appdata.iface_output_handler_register(self._conn_status_update) self.appdata.iface_output_handler_register(self._modbus_data_update) self.status = 1 self.conn_static_text.SetLabel(self.STATUSES[self.status]) def _conn_status_update(self): if self.modbus.is_connected: status = 0 if self.modbus.exception_state_get(): status = 2 else: status = 1 if status != self.status: self.status = status try: self.conn_static_text.SetLabel(self.STATUSES[self.status]) except RuntimeError: pass def _modbus_data_update(self): label = 'Port: ' + str(self.modbus.port) + '; ' + str(self.modbus.baudrate) + '-' + \ str(self.modbus.bytesize) + '-' + str(self.modbus.parity) + '-' + \ str(self.modbus.stopbits) if label != self.modbus_label: self.modbus_label = label try: self.modbus_status_text.SetLabel(self.modbus_label) except RuntimeError: pass
def __init__(self, parent): super().__init__(parent) self.app_data = AppData() self._output_garbage_collector = 0 # Create modbus instance, to have access to its props instance = ModbusConnectionThreadSingleton() self.modbus = instance.thread_instance_get() # Create content for self.input_matrix = InputArray(parent=self, title='Corresponding inputs state:', dimension=(3, 5), interface=DISPLAY_INTERFACE, col_titles=['1', '2', '3', '4', '5'], row_titles=['X1', 'X2', 'X3']) self.inner_panel_sizer = wx.BoxSizer(wx.VERTICAL) self.inner_panel_sizer.Add(self.input_matrix, 0, wx.ALL | wx.ALIGN_CENTER, 10) self.SetSizer(self.inner_panel_sizer)
def __init__(self, parent=None, title=None, **kwargs): # Initial construction procedure super().__init__(parent=parent) self.SetSize((250, 250)) self.SetTitle(title) self.CenterOnParent() self.settings = Settings() self._garbage_evt_collector = 0 instance = ModbusConnectionThreadSingleton() self.modbus = instance.thread_instance_get() # Create Background Panel and its sizer self.panel = wx.Panel(self) self.panel_sizer = wx.BoxSizer(wx.VERTICAL) # Create Settings Outline self.static_box = wx.StaticBox(self.panel, wx.ID_ANY, 'Settings') self.static_box_sizer = wx.StaticBoxSizer(self.static_box, wx.VERTICAL) # Create top row self.port_setup = ComPortSelector( parent=self.panel, label_caption='Device port', ) # self.panel.Bind(self.port_setup.item.event, self.on_choice, self.port_setup.item.choicer) # Create bottom row self.slave_address = LabelValueSequence( parent=self.panel, label='Slave ID', interface=LABELED_SPIN_CONTROL, button_required=False, initial_value=self.settings.slave_id, ) # Create Control Buttons self.button_accept = wx.Button(parent=self.panel, label='Accept') self.button_refresh = wx.Button(parent=self.panel, label='Refresh') self.button_connect = wx.Button(parent=self.panel, label='Connect') # Bind callbacks to newly created buttons self.panel.Bind(wx.EVT_BUTTON, self.port_setup.item.update_cb, self.button_refresh) self.panel.Bind(wx.EVT_BUTTON, self.on_accept, self.button_accept) self.panel.Bind(wx.EVT_BUTTON, self.on_connect, self.button_connect) # Wrap controls self.static_box_sizer.Add(self.port_setup) self.static_box_sizer.Add(self.slave_address) # Wrap buttons into sizer self.button_sizer = wx.BoxSizer(wx.HORIZONTAL) self.button_sizer.Add(self.button_accept, 1, wx.ALL | wx.ALIGN_LEFT, 8) self.button_sizer.Add(self.button_refresh, 1, wx.ALL | wx.ALIGN_RIGHT, 8) self.button_conn_sizer = wx.BoxSizer(wx.HORIZONTAL) self.button_conn_sizer.Add(self.button_connect, 1, wx.ALL | wx.ALIGN_CENTER, 8) # Wrap window items into window wrapper self.panel_sizer.Add(self.static_box_sizer, 5, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL, 15) self.panel_sizer.Add(self.button_sizer, 2, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL, 3) self.panel_sizer.Add(self.button_conn_sizer, 2, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL, 3) # Set panel sizer self.panel.SetSizer(self.panel_sizer)
def __init__(self, parent, *args, aydi=None, with_size=True, with_indicator=False, with_radio_panel=False, **kwargs): self.id = aydi style = None if 'style' in kwargs: style = kwargs['style'] if style is not None: super().__init__(parent, style=style) else: super().__init__(parent) self.inner_title = None self.setup_button = None self._configuration = None self.inner_title = wx.StaticText(parent=self, label=kwargs['inner_title']) modbus_singleton = ModbusConnectionThreadSingleton() self.modbus = modbus_singleton.modbus_comm_instance self.app_data = AppData() intermediate_sizer = wx.BoxSizer(wx.HORIZONTAL) self.inter_title = wx.StaticText(parent=self, label='Output State') self.inter_instance = InputArray(parent=self, dimension=(1, 1), outlined=False, interface=DISPLAY_INTERFACE) intermediate_sizer.Add(self.inter_title, 0, wx.LEFT, 15) intermediate_sizer.Add(self.inter_instance, 0, wx.LEFT, 30) if 'interface' in kwargs: if kwargs['interface'] == DISPLAY_INTERFACE: self.interface = DISPLAY_INTERFACE else: self.interface = INPUT_INTERFACE title = 'Inputs state:' self.inner_matrix = InputArray(parent=self, title=title, dimension=(3, 5), col_titles=['1', '2', '3', '4', '5'], row_titles=['X1', 'X2', 'X3']) self.inner_panel_sizer = wx.BoxSizer(wx.VERTICAL) self.inner_panel_sizer.Add(self.inner_title, 0, wx.ALL, 5) if with_indicator or with_radio_panel: self.inner_panel_sizer.Add(intermediate_sizer, 0, wx.RIGHT | wx.ALIGN_RIGHT, 18) self.inner_panel_sizer.Add(self.inner_matrix, 0, wx.ALL | wx.CENTER, 10) if with_size: self.SetSizer(self.inner_panel_sizer)
class _BtmPanel(wx.Panel): def __init__(self, parent=None): super().__init__(parent=parent) self.app_data = AppData() self.modbus = ModbusConnectionThreadSingleton() self.modbus = self.modbus.thread_instance_get() self.btm_page_sizer = wx.BoxSizer(wx.HORIZONTAL) self.notebook_sizer = wx.BoxSizer(wx.HORIZONTAL) self.notebook = wx.Notebook(self) self.sub_canvases = list() for i in range(8): self.sub_canvases.append(_BtmSubPanel(parent=self.notebook)) self.notebook.AddPage(self.sub_canvases[i], "Relay " + str(1 + i)) ''' Here goes a very important line of a code, setting notebook item's color to default window color instead of white color, chosen by default, when creating widget ''' self.notebook.SetOwnBackgroundColour(self.GetBackgroundColour()) self.notebook_sizer.Add(self.notebook, 0, wx.EXPAND) self.btm_page_sizer.Add(self.notebook_sizer, 0, wx.EXPAND) self.SetSizer(self.btm_page_sizer) # Apply data on connection self.app_data.iface_conn_handler_register( self._input_left_matrix_update_on_conn) self.app_data.iface_conn_handler_register( self._input_radio_data_set_on_conn) # Interface handlers, always called to update data on screen self.app_data.iface_output_handler_register(self._out_led_update) self.app_data.iface_output_handler_register( self._matrix_visibility_update) self.app_data.iface_output_handler_register( self._input_right_matrix_update) # Gather input data handlers self.app_data.iface_input_handler_register( self._input_left_matrix_data_gather) self.app_data.iface_input_handler_register( self._input_radio_data_gather) self._input_matrix_enabled = 0 self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.on_page_change) def on_page_change(self, event): page = event.GetSelection() if self.modbus.is_connected: self.sub_canvases[page].rb_value = self.app_data.output_mode_get( page) self.sub_canvases[page].rb_layout() def _input_left_matrix_data_gather(self): for out_id in range(8): val_list = [] left_panel = self.sub_canvases[out_id].left_panel for in_id in range(15): value = left_panel.input_matrix.value_get_by_index(in_id) val_list.append(value) self.app_data.output_associated_input_set_mask(out_id, val_list) def _input_left_matrix_update_on_conn(self): # Update left matrix when we acquire connection for out_id in range(8): left_panel = self.sub_canvases[out_id].left_panel for in_id in range(15): value = self.app_data.output_associated_input_get( out_id, in_id) left_panel.input_matrix.value_set_by_index(in_id, value) def _input_right_matrix_update(self): # Update right matrix when we acquire connection for out_id in range(8): right_panel = self.sub_canvases[out_id].right_panel for in_id in range(15): is_visible = self.app_data.output_associated_input_get( out_id, in_id) right_panel.input_matrix.visibility_set_by_index( in_id, is_visible) value = self.app_data.input_state_get(in_id) right_panel.input_matrix.value_set_by_index(in_id, value) def _input_radio_data_set_on_conn(self): val_list = list() for out_id, sub_cvs in enumerate(self.sub_canvases): sub_cvs.rb_value = self.app_data.output_mode_get(out_id) val_list.append(sub_cvs.rb_value) sub_cvs.rb_layout() def _input_radio_data_gather(self): val_list = list() for out_id, sub_cvs in enumerate(self.sub_canvases): val_list.append(sub_cvs.rb_value) self.app_data.output_mode_set(out_id, sub_cvs.rb_value) def _matrix_visibility_update(self): if self.modbus.is_connected: for out_id in range(8): left_panel = self.sub_canvases[out_id].left_panel if self._input_matrix_enabled is False: left_panel.input_matrix.enable() self._input_matrix_enabled = True else: for out_id in range(8): left_panel = self.sub_canvases[out_id].left_panel if self._input_matrix_enabled is True: left_panel.input_matrix.disable() self._input_matrix_enabled = False def _out_led_update(self): for i in range(8): self.sub_canvases[i].output_led.values = [ self.app_data.output_state_get(i), ]
def __init__(self, parent): # Basic Construction procedure super().__init__(parent) self.left_panel = None self.right_panel = None self.app_data = AppData() self.rb_value = 0 # Create modbus instance, to have access to its props instance = ModbusConnectionThreadSingleton() self.modbus = instance.thread_instance_get() # Create sizers self.panel_sizer = wx.BoxSizer(wx.VERTICAL) self.upper_sizer = wx.BoxSizer(wx.HORIZONTAL) self.bottom_sizer = wx.BoxSizer(wx.HORIZONTAL) # Create upper sequence items self.output_mode_label = wx.StaticText(parent=self, label='Mode:') self.output_mode_rb_auto = wx.RadioButton(parent=self, id=0, label='Auto', style=wx.RB_GROUP) self.output_mode_rb_off = wx.RadioButton(parent=self, id=1, label='Off') self.output_mode_rb_on = wx.RadioButton(parent=self, id=2, label='On') # self.output_mode_rb_change = wx.RadioButton(parent=self, id=3, label='Change') self.output_state_label = wx.StaticText(parent=self, label='State:') self.output_led = InputArray(parent=self, dimension=(1, 1), interface=DISPLAY_INTERFACE, outlined=False, is_input_indication=False) # Create both panels self._left_panel_create(self) self._right_panel_create(self) # Prepare led state sizer self.led_state_sizer = wx.BoxSizer(wx.HORIZONTAL) led_inter_sizer = wx.BoxSizer(wx.VERTICAL) led_inter_sizer.Add(self.output_led, 1, wx.RIGHT | wx.ALIGN_RIGHT, 20) label_inter_sizer = wx.BoxSizer(wx.VERTICAL) label_inter_sizer.Add(self.output_state_label, 1, wx.LEFT, 85) self.led_state_sizer.Add(label_inter_sizer, 1, wx.ALL) self.led_state_sizer.Add(led_inter_sizer, 1, wx.ALL) # Wrap data into upper sizer self.upper_radio_sizer = wx.BoxSizer(wx.HORIZONTAL) self.upper_radio_sizer.Add(self.output_mode_label, 0, wx.LEFT, 15) self.upper_radio_sizer.Add(self.output_mode_rb_auto, 0, wx.LEFT, 5) self.upper_radio_sizer.Add(self.output_mode_rb_off, 0, wx.LEFT, 5) self.upper_radio_sizer.Add(self.output_mode_rb_on, 0, wx.LEFT, 5) # self.upper_radio_sizer.Add(self.output_mode_rb_change, 0, wx.LEFT, 5) self.upper_sizer.Add(self.upper_radio_sizer, 1, wx.TOP | wx.BOTTOM, 15) self.upper_sizer.Add(self.led_state_sizer, 5, wx.ALL, 15) # Wrap data into bottom sizer self.bottom_sizer.Add(self.left_panel, 1, wx.EXPAND | wx.LEFT, 2) self.bottom_sizer.Add(self.right_panel, 1, wx.EXPAND | wx.RIGHT, 2) # Wrap data into self sizer self.panel_sizer.Add(self.upper_sizer, 1, wx.EXPAND | wx.TOP, 5) self.panel_sizer.Add(self.bottom_sizer, 3, wx.EXPAND) # Apply self sizer self.SetSizer(self.panel_sizer) # Beautify self.output_mode_rb_auto.Disable() self.output_mode_rb_off.Disable() self.output_mode_rb_on.Disable() # self.output_mode_rb_change.Disable() # Bind Callbacks self.Bind(wx.EVT_RADIOBUTTON, self._radio_button_callback, self.output_mode_rb_auto) self.Bind(wx.EVT_RADIOBUTTON, self._radio_button_callback, self.output_mode_rb_off) self.Bind(wx.EVT_RADIOBUTTON, self._radio_button_callback, self.output_mode_rb_on) # self.Bind(wx.EVT_RADIOBUTTON, self._radio_button_callback, self.output_mode_rb_change) self.app_data.iface_output_handler_register( self.radio_buttons_visibility_handler)
def __init__(self, parent=None): super().__init__(parent=parent) self.conn_blink_state = 0 self.settings = Settings() self.app_data = AppData() self.sizer = wx.BoxSizer(wx.HORIZONTAL) self._output_garbage_collector = 0 self.act_indicator_wrapper = wx.BoxSizer(wx.VERTICAL) self.slave_id_sequence_wrapper = wx.BoxSizer(wx.VERTICAL) # Create display matrix for Relays self.output_matrix = InputArray( parent=self, title='Outputs state:', dimension=(1, 8), col_titles=['K1', 'K2', 'K3', 'K4', 'K5', 'K6', 'K7', 'K8'], interface=DISPLAY_INTERFACE, secret_ids=[1, 2, 3, 4, 5, 6, 7, 8], is_input_indication=False) self.output_matrix_wrapper = wx.BoxSizer(wx.VERTICAL) self.output_matrix_wrapper.Add(self.output_matrix, 0, wx.RIGHT | wx.ALIGN_RIGHT, 18) # Assign instance of modbus singleton, to have access to its props instance = ModbusConnectionThreadSingleton() self.modbus = instance.thread_instance_get() # Create an activity Led self.act_label = wx.StaticText(parent=self, label='Activity') self.activity_led = InputArray(parent=self, dimension=(1, 1), is_conn=True, interface=DISPLAY_INTERFACE, outlined=False) # Create Slave id sequence self.slave_id_label = wx.StaticText(parent=self, label='Slave ID') self.slave_id_control = wx.SpinCtrl(parent=self, size=(60, -1), style=wx.TE_LEFT, max=999) # Wrap indicator act_label_wrapper = wx.BoxSizer(wx.HORIZONTAL) led_activity_wrapper = wx.BoxSizer(wx.HORIZONTAL) act_label_wrapper.Add(self.act_label, 1, wx.LEFT, 8) led_activity_wrapper.Add(self.activity_led, 1, wx.LEFT, 21) self.act_indicator_wrapper.Add(act_label_wrapper, 2, wx.TOP, 12) self.act_indicator_wrapper.Add(led_activity_wrapper, 2, wx.TOP, 14) # Wrap slave id slave_id_label_wrapper = wx.BoxSizer(wx.HORIZONTAL) slave_id_control_wrapper = wx.BoxSizer(wx.HORIZONTAL) slave_id_label_wrapper.Add(self.slave_id_label, 1, wx.LEFT, 3) slave_id_control_wrapper.Add(self.slave_id_control, 1, wx.LEFT, 8) self.slave_id_sequence_wrapper.Add(slave_id_label_wrapper, 3, wx.TOP, 18) self.slave_id_sequence_wrapper.Add(slave_id_control_wrapper, 2, wx.TOP, 4) # Bind events self.Bind(wx.EVT_SPINCTRL, self.slave_id_update, self.slave_id_control) self.app_data.iface_output_handler_register(self._slave_id_update) # Assemble panel sizer self.sizer.Add(self.act_indicator_wrapper, 1, wx.LEFT | wx.ALIGN_CENTER_VERTICAL, 20) self.sizer.Add(self.slave_id_sequence_wrapper, 1, wx.LEFT | wx.ALIGN_CENTER_VERTICAL, 20) self.sizer.Add(self.output_matrix_wrapper, 6, wx.EXPAND, 0) # Apply panel sizer self.SetSizer(self.sizer) # Register handler to update output state self.app_data.iface_output_handler_register( self._output_indication_update) # Insert a certain delay for refresh button self.timer = wx.Timer() self.timer_evt_handler = wx.EvtHandler() self.timer.SetOwner(self.timer_evt_handler, id=228) self.timer_evt_handler.Bind(wx.EVT_TIMER, self._refresh_conn_activity, self.timer, id=228) self.timer.Start(100, True)