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))
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), ]