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)
Example #2
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))
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, 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)
    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)
Example #7
0
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),
            ]
Example #8
0
    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)
Example #9
0
    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)