Ejemplo n.º 1
0
    def __init__(self,
                 parent=None,
                 size: QSize = QSize(10, 10),
                 lang: LangEnum = LangEnum.ENG,
                 log_handlers: [StreamHandler] = None):
        self.logger = getLogger(__name__)
        if log_handlers:
            for h in log_handlers:
                self.logger.addHandler(h)
        self.logger.debug("Initializing")
        super().__init__(parent)
        self.setLayout(QVBoxLayout())
        self.setMaximumSize(size)
        self._button_layout = QHBoxLayout()

        self._create_button = ClickAnimationButton()
        self._create_button.setFixedSize(60, 40)
        self._start_button = ClickAnimationButton()
        self._start_button.setFixedSize(120, 40)
        self._button_layout.addWidget(self._create_button)
        self._button_layout.addWidget(self._start_button)
        self._text_entry = QLineEdit()
        self.layout().addLayout(self._button_layout)
        self.layout().addWidget(self._text_entry)

        self._play_icon = QIcon(button_box_start_image_filepath)
        self._pause_icon = QIcon(button_box_pause_image_filepath)

        self._start_button_state = 0
        self._create_button_state = 0
        self._set_button_states()
        self._strings = dict()
        self.set_lang(lang)
        self.logger.debug("Initialized")
Ejemplo n.º 2
0
    def button_test_1(self):
        print("button 1 pressed")
        msg_box = QDialog()
        # msg_box.setModal(True)
        msg_box.setWindowTitle("Test message box")
        # msg_box.setText("This is a message")
        test_frame = EasyFrame()
        test_layout = QVBoxLayout(test_frame)

        test_button = ClickAnimationButton(test_frame)
        test_button.setText("test button")
        test_button.clicked.connect(self.button_test_2)

        test_layout.addWidget(test_button)

        # msg_box.layout().addWidget(test_layout)
        # msg_box.setStandardButtons(QMessageBox.Ok)
        msg_box.setLayout(test_layout)

        # msg_box.exec_()
        msg_box.exec()
Ejemplo n.º 3
0
    def __init__(self):
        QMainWindow.__init__(self)
        self.setFixedSize(300, 200)
        self.setCentralWidget(CentralWidget(self))
        self.myLayout = QHBoxLayout(self)

        # set this to desired file location and name
        self.file = "W:\\stuff\\file.wav"

        self.rec_button = ClickAnimationButton()
        self.rec_button.setText("record")
        self.rec_button.clicked.connect(self.record_audio)

        self.devs_button = ClickAnimationButton()
        self.devs_button.setText("input devices")
        self.devs_button.clicked.connect(self.input_devices)

        self.play_button = ClickAnimationButton()
        self.play_button.setText("play")
        self.play_button.clicked.connect(self.play_audio)

        self.myLayout.addWidget(self.rec_button)
        self.myLayout.addWidget(self.devs_button)
        self.myLayout.addWidget(self.play_button)

        self.centralWidget().layout().addLayout(self.myLayout)
Ejemplo n.º 4
0
    def __init__(self,
                 parent=None,
                 size: QSize = QSize(10, 10),
                 lang: LangEnum = LangEnum.ENG,
                 log_handlers: [StreamHandler] = None):
        self.logger = getLogger(__name__)
        if log_handlers:
            for h in log_handlers:
                self.logger.addHandler(h)
        self.logger.debug("Initializing")
        super().__init__(parent)
        self.setLayout(QGridLayout())
        self.setMaximumSize(size)
        self._text_edit = QTextEdit()
        self.layout().addWidget(self._text_edit, 0, 1, 1, 1)
        self._post_button = ClickAnimationButton()
        self.layout().addWidget(self._post_button, 1, 1, 1, 1)

        self._strings = dict()
        self.set_lang(lang)
        self._set_button_state()
        self.logger.debug("Initialized")
Ejemplo n.º 5
0
    def __init__(self,
                 name: str = "VOG_NONE",
                 log_handlers: [StreamHandler] = None):
        self._logger = getLogger(__name__)
        if log_handlers:
            for h in log_handlers:
                self._logger.addHandler(h)
        self._logger.debug("Initializing")
        super().__init__(name)
        """ Min size for the VOG window """
        self._subwindow_height = 222
        self._subwindow_width = 518
        """ min and max sizes for the configuration popup (width, height) """
        self._popup_min = (229, 409)
        self._popup_max = (300, 409)
        """ Set configuration value display area"""
        self._config_frame = EasyFrame()
        self._config_vertical_layout = QVBoxLayout(self._config_frame)
        self._config_label = QLabel(self._config_frame)
        self._config_label.setAlignment(Qt.AlignCenter)
        self._config_val_line_edit = QLineEdit(self._config_frame)
        self._config_val_line_edit.setAlignment(Qt.AlignCenter)

        self._config_vertical_layout.addWidget(self._config_label)
        self._config_vertical_layout.addWidget(self._config_val_line_edit)
        """ Set preset button selection area. """
        self._nhtsa_button = ClickAnimationButton()
        self._eblindfold_button = ClickAnimationButton()
        self._direct_control_button = ClickAnimationButton()
        """ Set open duration, close duration, and debounce time settings display area. """
        self._input_box_frame = EasyFrame()
        self._input_box_grid_layout = QGridLayout(self._input_box_frame)
        self._input_box_grid_layout.setContentsMargins(0, 6, 0, 6)

        self._open_dur_label = QLabel(self._input_box_frame)
        self._open_dur_line_edit = QLineEdit(self._input_box_frame)
        self._open_dur_line_edit.setFixedWidth(80)
        self._open_inf_check_box = QCheckBox(self._input_box_frame)

        self._close_dur_label = QLabel(self._input_box_frame)
        self._close_dur_line_edit = QLineEdit(self._input_box_frame)
        self._close_dur_line_edit.setFixedWidth(80)
        self._close_inf_check_box = QCheckBox(self._input_box_frame)

        self._debounce_label = QLabel(self._input_box_frame)
        self._debounce_time_line_edit = QLineEdit(self._input_box_frame)
        self._debounce_time_line_edit.setFixedWidth(80)

        self._input_box_grid_layout.addWidget(self._open_dur_label, 0, 0, 1, 1)
        self._input_box_grid_layout.addWidget(self._open_dur_line_edit, 0, 1,
                                              1, 1)
        self._input_box_grid_layout.addWidget(self._open_inf_check_box, 0, 2,
                                              1, 1)
        self._input_box_grid_layout.addWidget(self._close_dur_label, 1, 0, 1,
                                              1)
        self._input_box_grid_layout.addWidget(self._close_dur_line_edit, 1, 1,
                                              1, 1)
        self._input_box_grid_layout.addWidget(self._close_inf_check_box, 1, 2,
                                              1, 1)
        self._input_box_grid_layout.addWidget(self._debounce_label, 2, 0, 1, 1)
        self._input_box_grid_layout.addWidget(self._debounce_time_line_edit, 2,
                                              1, 1, 1)
        """ Set button mode setting display area. """
        self._button_mode_frame = EasyFrame()
        self._button_mode_horiz_layout = QGridLayout(self._button_mode_frame)
        self._button_mode_horiz_layout.setContentsMargins(0, 6, 0, 6)
        self._button_mode_label = QLabel(self._button_mode_frame)
        self._button_mode_selector = QComboBox(self._button_mode_frame)

        self._button_mode_selector.addItem("")
        self._button_mode_selector.addItem("")

        self._button_mode_horiz_layout.addWidget(self._button_mode_label, 0, 0,
                                                 1, 1)
        self._button_mode_horiz_layout.addWidget(self._button_mode_selector, 0,
                                                 1, 1, 1)
        """ Set control mode setting display area. """
        self._control_mode_label = QLabel(self._button_mode_frame)
        self._control_mode_selector = QComboBox(self._button_mode_frame)

        self._control_mode_selector.addItem("")
        self._control_mode_selector.addItem("")

        self._button_mode_horiz_layout.addWidget(self._control_mode_label, 1,
                                                 0, 1, 1)
        self._button_mode_horiz_layout.addWidget(self._control_mode_selector,
                                                 1, 1, 1, 1)
        """ Set upload button selection area. """
        self._upload_settings_button = ClickAnimationButton()
        """ Set manual control selection area. """
        self._manual_control_button_frame = EasyFrame()
        self._manual_control_button_layout = QHBoxLayout(
            self._manual_control_button_frame)

        self._manual_control_open_button = ClickAnimationButton()
        self._manual_control_close_button = ClickAnimationButton()

        self._manual_control_button_layout.addWidget(
            self._manual_control_open_button)
        self._manual_control_button_layout.addWidget(
            self._manual_control_close_button)
        self._manual_control_button_layout.setMargin(0)
        """ device settings display """
        self._dev_sets_frame = EasyFrame()

        self._dev_sets_layout = QVBoxLayout(self._dev_sets_frame)

        self.config_button = ClickAnimationButton()
        self.config_button.clicked.connect(self._config_button_handler)

        self._config_win = ConfigPopUp()
        self._config_win.setMinimumSize(self._popup_min[0], self._popup_min[1])
        self._config_win.setMaximumSize(self._popup_max[0], self._popup_max[1])
        self._config_win.setLayout(self._dev_sets_layout)
        """ Add widgets to layout. """
        self._dev_sets_layout.addWidget(self._config_frame)
        self._dev_sets_layout.addWidget(self._input_box_frame)
        self._dev_sets_layout.addWidget(self._button_mode_frame)
        self._dev_sets_layout.addWidget(self._nhtsa_button)
        self._dev_sets_layout.addWidget(self._eblindfold_button)
        self._dev_sets_layout.addWidget(self._direct_control_button)
        self._dev_sets_layout.addWidget(self._upload_settings_button)

        self.layout().addWidget(self.config_button, 0, 0,
                                Qt.AlignTop | Qt.AlignRight)
        self.config_button.setFixedSize(30, 25)

        self.layout().addWidget(self._manual_control_button_frame, 0, 0,
                                Qt.AlignBottom | Qt.AlignLeft)
        self._manual_control_open_button.setFixedSize(70, 25)
        self._manual_control_close_button.setFixedSize(70, 25)

        self.layout().setMargin(0)

        self._strings = dict()
        self._lang_enum = LangEnum.ENG
        self.setMinimumSize(self._subwindow_width, self._subwindow_height)
        self.resize(self._subwindow_width, self._subwindow_height)
        self._logger.debug("Initialized")
Ejemplo n.º 6
0
class VOGView(AbstractView):
    def __init__(self,
                 name: str = "VOG_NONE",
                 log_handlers: [StreamHandler] = None):
        self._logger = getLogger(__name__)
        if log_handlers:
            for h in log_handlers:
                self._logger.addHandler(h)
        self._logger.debug("Initializing")
        super().__init__(name)
        """ Min size for the VOG window """
        self._subwindow_height = 222
        self._subwindow_width = 518
        """ min and max sizes for the configuration popup (width, height) """
        self._popup_min = (229, 409)
        self._popup_max = (300, 409)
        """ Set configuration value display area"""
        self._config_frame = EasyFrame()
        self._config_vertical_layout = QVBoxLayout(self._config_frame)
        self._config_label = QLabel(self._config_frame)
        self._config_label.setAlignment(Qt.AlignCenter)
        self._config_val_line_edit = QLineEdit(self._config_frame)
        self._config_val_line_edit.setAlignment(Qt.AlignCenter)

        self._config_vertical_layout.addWidget(self._config_label)
        self._config_vertical_layout.addWidget(self._config_val_line_edit)
        """ Set preset button selection area. """
        self._nhtsa_button = ClickAnimationButton()
        self._eblindfold_button = ClickAnimationButton()
        self._direct_control_button = ClickAnimationButton()
        """ Set open duration, close duration, and debounce time settings display area. """
        self._input_box_frame = EasyFrame()
        self._input_box_grid_layout = QGridLayout(self._input_box_frame)
        self._input_box_grid_layout.setContentsMargins(0, 6, 0, 6)

        self._open_dur_label = QLabel(self._input_box_frame)
        self._open_dur_line_edit = QLineEdit(self._input_box_frame)
        self._open_dur_line_edit.setFixedWidth(80)
        self._open_inf_check_box = QCheckBox(self._input_box_frame)

        self._close_dur_label = QLabel(self._input_box_frame)
        self._close_dur_line_edit = QLineEdit(self._input_box_frame)
        self._close_dur_line_edit.setFixedWidth(80)
        self._close_inf_check_box = QCheckBox(self._input_box_frame)

        self._debounce_label = QLabel(self._input_box_frame)
        self._debounce_time_line_edit = QLineEdit(self._input_box_frame)
        self._debounce_time_line_edit.setFixedWidth(80)

        self._input_box_grid_layout.addWidget(self._open_dur_label, 0, 0, 1, 1)
        self._input_box_grid_layout.addWidget(self._open_dur_line_edit, 0, 1,
                                              1, 1)
        self._input_box_grid_layout.addWidget(self._open_inf_check_box, 0, 2,
                                              1, 1)
        self._input_box_grid_layout.addWidget(self._close_dur_label, 1, 0, 1,
                                              1)
        self._input_box_grid_layout.addWidget(self._close_dur_line_edit, 1, 1,
                                              1, 1)
        self._input_box_grid_layout.addWidget(self._close_inf_check_box, 1, 2,
                                              1, 1)
        self._input_box_grid_layout.addWidget(self._debounce_label, 2, 0, 1, 1)
        self._input_box_grid_layout.addWidget(self._debounce_time_line_edit, 2,
                                              1, 1, 1)
        """ Set button mode setting display area. """
        self._button_mode_frame = EasyFrame()
        self._button_mode_horiz_layout = QGridLayout(self._button_mode_frame)
        self._button_mode_horiz_layout.setContentsMargins(0, 6, 0, 6)
        self._button_mode_label = QLabel(self._button_mode_frame)
        self._button_mode_selector = QComboBox(self._button_mode_frame)

        self._button_mode_selector.addItem("")
        self._button_mode_selector.addItem("")

        self._button_mode_horiz_layout.addWidget(self._button_mode_label, 0, 0,
                                                 1, 1)
        self._button_mode_horiz_layout.addWidget(self._button_mode_selector, 0,
                                                 1, 1, 1)
        """ Set control mode setting display area. """
        self._control_mode_label = QLabel(self._button_mode_frame)
        self._control_mode_selector = QComboBox(self._button_mode_frame)

        self._control_mode_selector.addItem("")
        self._control_mode_selector.addItem("")

        self._button_mode_horiz_layout.addWidget(self._control_mode_label, 1,
                                                 0, 1, 1)
        self._button_mode_horiz_layout.addWidget(self._control_mode_selector,
                                                 1, 1, 1, 1)
        """ Set upload button selection area. """
        self._upload_settings_button = ClickAnimationButton()
        """ Set manual control selection area. """
        self._manual_control_button_frame = EasyFrame()
        self._manual_control_button_layout = QHBoxLayout(
            self._manual_control_button_frame)

        self._manual_control_open_button = ClickAnimationButton()
        self._manual_control_close_button = ClickAnimationButton()

        self._manual_control_button_layout.addWidget(
            self._manual_control_open_button)
        self._manual_control_button_layout.addWidget(
            self._manual_control_close_button)
        self._manual_control_button_layout.setMargin(0)
        """ device settings display """
        self._dev_sets_frame = EasyFrame()

        self._dev_sets_layout = QVBoxLayout(self._dev_sets_frame)

        self.config_button = ClickAnimationButton()
        self.config_button.clicked.connect(self._config_button_handler)

        self._config_win = ConfigPopUp()
        self._config_win.setMinimumSize(self._popup_min[0], self._popup_min[1])
        self._config_win.setMaximumSize(self._popup_max[0], self._popup_max[1])
        self._config_win.setLayout(self._dev_sets_layout)
        """ Add widgets to layout. """
        self._dev_sets_layout.addWidget(self._config_frame)
        self._dev_sets_layout.addWidget(self._input_box_frame)
        self._dev_sets_layout.addWidget(self._button_mode_frame)
        self._dev_sets_layout.addWidget(self._nhtsa_button)
        self._dev_sets_layout.addWidget(self._eblindfold_button)
        self._dev_sets_layout.addWidget(self._direct_control_button)
        self._dev_sets_layout.addWidget(self._upload_settings_button)

        self.layout().addWidget(self.config_button, 0, 0,
                                Qt.AlignTop | Qt.AlignRight)
        self.config_button.setFixedSize(30, 25)

        self.layout().addWidget(self._manual_control_button_frame, 0, 0,
                                Qt.AlignBottom | Qt.AlignLeft)
        self._manual_control_open_button.setFixedSize(70, 25)
        self._manual_control_close_button.setFixedSize(70, 25)

        self.layout().setMargin(0)

        self._strings = dict()
        self._lang_enum = LangEnum.ENG
        self.setMinimumSize(self._subwindow_width, self._subwindow_height)
        self.resize(self._subwindow_width, self._subwindow_height)
        self._logger.debug("Initialized")

    def add_graph(self, graph) -> None:
        """
        Add Graph to view.
        :return None:
        """
        self._logger.debug("running")
        self.layout().addWidget(graph, 0, 0)
        self.config_button.raise_()
        self._manual_control_button_frame.raise_()
        self._logger.debug("done")

    def _config_button_handler(self) -> None:
        """
        handles the config button
        :return None:
        """
        self._logger.debug("running")
        self._config_win.exec_()
        self._logger.debug("done")

    def set_config_val_line_edit_handler(self, func: classmethod) -> None:
        """
        Sets the config val line handler.
        :param func: classmethod that handles the config val line.
        :return None:
        """
        self._logger.debug("running")
        self._config_val_line_edit.textChanged.connect(func)
        self._logger.debug("done")

    def set_nhtsa_button_handler(self, func: classmethod) -> None:
        """
        Sets NHTSA button press handler.
        :param func: classmethod that handles the NHTSA button.
        :return None:
        """
        self._logger.debug("running")
        self._nhtsa_button.clicked.connect(func)
        self._logger.debug("done")

    def set_eblindfold_button_handler(self, func: classmethod) -> None:
        """
        Sets eBlindfold button press handler.
        :param func: classmethod that handles the eBlindfold button.
        :return None:
        """
        self._logger.debug("running")
        self._eblindfold_button.clicked.connect(func)
        self._logger.debug("done")

    def set_direct_control_button_handler(self, func: classmethod) -> None:
        """
        Sets Direct Control button press handler.
        :param func: classmethod that handles the Direct Control button.
        :return None:
        """
        self._logger.debug("running")
        self._direct_control_button.clicked.connect(func)
        self._logger.debug("done")

    def set_open_dur_line_edit_handler(self, func: classmethod) -> None:
        """
        Sets open duration line edit handler.
        :param func: classmethod that handles the line edit.
        :return None:
        """
        self._logger.debug("running")
        self._open_dur_line_edit.textChanged.connect(func)
        self._logger.debug("done")

    def set_close_dur_line_edit_handler(self, func: classmethod) -> None:
        """
        Sets close duration line edit handler.
        :param func: classmethod that handles the line edit.
        :return None:
        """
        self._logger.debug("running")
        self._close_dur_line_edit.textChanged.connect(func)
        self._logger.debug("done")

    def set_open_inf_check_box_handler(self, func: classmethod) -> None:
        """
        Sets open INF checkbox handler.
        :param func: classmethod that handles the checkbox, requires bool param.
        :return None:
        """
        self._logger.debug("running")
        self._open_inf_check_box.stateChanged.connect(func)
        self._logger.debug("done")

    def set_close_inf_check_box_handler(self, func: classmethod) -> None:
        """
        Sets close INF checkbox handler.
        :param func: classmethod that handles the checkbox, requires bool param.
        :return None:
        """
        self._logger.debug("running")
        self._close_inf_check_box.stateChanged.connect(func)
        self._logger.debug("done")

    def set_debounce_time_line_edit_handler(self, func: classmethod) -> None:
        """
        Sets debounce time line edit handler.
        :param func: classmethod that handles the line edit.
        :return None:
        """
        self._logger.debug("running")
        self._debounce_time_line_edit.textChanged.connect(func)
        self._logger.debug("done")

    def set_button_mode_selector_handler(self, func: classmethod) -> None:
        """
        Sets button mode combo box handler.
        :param func: classmethod that handles the combo.
        :return None:
        """
        self._logger.debug("running")
        self._button_mode_selector.currentIndexChanged.connect(func)
        self._logger.debug("done")

    def set_control_mode_selector_handler(self, func: classmethod) -> None:
        """
        Sets button mode combo box handler.
        :param func: classmethod that handles the combo.
        :return None:
        """
        self._logger.debug("running")
        self._control_mode_selector.currentIndexChanged.connect(func)
        self._logger.debug("done")

    def set_upload_settings_button_handler(self, func: classmethod) -> None:
        """
        Sets upload settings button handler.
        :param func: classmethod that handles the button.
        :return None:
        """
        self._logger.debug("running")
        self._upload_settings_button.clicked.connect(func)
        self._logger.debug("done")

    def set_manual_control_open_button_handler(self,
                                               func: classmethod) -> None:
        """
        Sets manual open button handler.
        :param func: classmethod that handles the button.
        :return None:
        """
        self._logger.debug("running")
        self._manual_control_open_button.clicked.connect(func)
        self._logger.debug("done")

    def set_manual_control_close_button_handler(self,
                                                func: classmethod) -> None:
        """
        Sets manual close button handler.
        :param func: classmethod that handles the button.
        :return None:
        """
        self._logger.debug("running")
        self._manual_control_close_button.clicked.connect(func)
        self._logger.debug("done")

    @property
    def config_text(self) -> str:
        """
        Get the string value found in the config text box.
        :return str: string value in the text box.
        """
        return self._config_val_line_edit.text()

    @config_text.setter
    def config_text(self, val: str) -> None:
        """
        Set the string value found in the config text box.
        :param val: string value to set the config text box.
        :return None:
        """
        self._logger.debug("running")
        self._config_val_line_edit.setText(val)
        self._logger.debug("done")

    @property
    def open_duration(self) -> str:
        """
        Get the string value found in the open duration text box.
        :return str: string value in the text box.
        """
        return self._open_dur_line_edit.text()

    @open_duration.setter
    def open_duration(self, val: str) -> None:
        """
        Set the string value found in the open duration text box.
        :param val: string value to set the open duration text box.
        :return None:
        """
        self._logger.debug("running")
        self._open_dur_line_edit.setText(val)
        self._logger.debug("done")

    @property
    def close_duration(self) -> str:
        """
        Get the string value found in the close duration text box.
        :return str: string value in the text box.
        """
        return self._close_dur_line_edit.text()

    @close_duration.setter
    def close_duration(self, val: str) -> None:
        """
        Set the string value found in the close duration text box.
        :param val: string value to set the close duration text box.
        :return None:
        """
        self._logger.debug("running")
        self._close_dur_line_edit.setText(val)
        self._logger.debug("done")

    @property
    def debounce_val(self) -> str:
        """
        Get the string value found in the debounce time text box.
        :return str: string value in the text box.
        """
        return self._debounce_time_line_edit.text()

    @debounce_val.setter
    def debounce_val(self, val: str) -> None:
        """
        Set the string value found in the debounce time text box.
        :param val: string value to set the debounce text box.
        :return None:
        """
        self._logger.debug("running")
        self._debounce_time_line_edit.setText(val)
        self._logger.debug("done")

    @property
    def open_inf_check_box(self) -> bool:
        """
        Get the check box state.
        :return bool: returns true if the box is checked.
        """
        return self._open_inf_check_box.isChecked()

    @open_inf_check_box.setter
    def open_inf_check_box(self, val: bool) -> None:
        """
        Set the check box state.
        :param val: bool value to set the check box.
        :return None:
        """
        self._logger.debug("running")
        self._open_inf_check_box.setChecked(val)
        self._logger.debug("done")

    @property
    def close_inf_check_box(self) -> bool:
        """
        Get the check box state.
        :return bool: returns true if the box is checked.
        """
        return self._close_inf_check_box.isChecked()

    @close_inf_check_box.setter
    def close_inf_check_box(self, val: bool) -> None:
        """
        Set the check box state.
        :param val: bool value to set the check box.
        :return None:
        """
        self._logger.debug("running")
        self._close_inf_check_box.setChecked(val)
        self._logger.debug("done")

    @property
    def button_mode(self) -> int:
        """
        Get index of button mode.
        :return int: index of current button mode.
        """
        return self._button_mode_selector.currentIndex()

    @button_mode.setter
    def button_mode(self, val: int) -> None:
        """
        Set index of button mode.
        :return None:
        """
        self._logger.debug("running")
        self._button_mode_selector.setCurrentIndex(val)
        self._logger.debug("done")

    @property
    def control_mode(self) -> int:
        """
        Get index of button mode.
        :return int: index of current button mode.
        """
        return self._control_mode_selector.currentIndex()

    @control_mode.setter
    def control_mode(self, val: int) -> None:
        """
        Set index of button mode.
        :return None:
        """
        self._logger.debug("running")
        self._control_mode_selector.setCurrentIndex(val)
        self._logger.debug("done")

    def set_open_dur_err(self, err: bool) -> None:
        """
        Set this text entry to error style depending on err.
        :param err: If this text entry needs to be error styel
        :return None:
        """
        self._logger.debug("running")
        if err:
            self._open_dur_line_edit.setStyleSheet(tab_line_edit_error_style)
        else:
            self._open_dur_line_edit.setStyleSheet(
                tab_line_edit_compliant_style)
        self._logger.debug("done")

    def set_close_dur_err(self, err: bool) -> None:
        """
        Set this text entry to error style depending on err.
        :param err: If this text entry needs to be error styel
        :return None:
        """
        self._logger.debug("running")
        if err:
            self._close_dur_line_edit.setStyleSheet(tab_line_edit_error_style)
        else:
            self._close_dur_line_edit.setStyleSheet(
                tab_line_edit_compliant_style)
        self._logger.debug("done")

    def set_debounce_err(self, err: bool) -> None:
        """
        Set this text entry to error style depending on err.
        :param err: If this text entry needs to be error styel
        :return None:
        """
        self._logger.debug("running")
        if err:
            self._debounce_time_line_edit.setStyleSheet(
                tab_line_edit_error_style)
        else:
            self._debounce_time_line_edit.setStyleSheet(
                tab_line_edit_compliant_style)
        self._logger.debug("done")

    @property
    def language(self) -> LangEnum:
        """
        Get the current language setting
        :return LangEnum: The current language enumerator being used
        """
        return self._lang_enum

    @language.setter
    def language(self, lang: LangEnum) -> None:
        """
        Set the language for this view object and reload the text and tooltips.
        :param lang: the language to use.
        :return None:
        """
        self._logger.debug("running")
        self._strings = strings[lang]
        self._set_texts()
        self._set_tooltips()
        self._logger.debug("done")

    def set_upload_button(self, is_active: bool) -> None:
        """
        Set upload button activity to is_active.
        :param is_active: Whether this button should be active.
        :return None:
        """
        self._logger.debug("running")
        self._upload_settings_button.setEnabled(is_active)
        self._logger.debug("done")

    def _set_texts(self) -> None:
        """
        Set text fields of view object.
        :return None:
        """
        self._logger.debug("running")
        self._config_label.setText(self._strings[StringsEnum.CONFIG_LABEL])
        self._config_val_line_edit.setText(
            self._strings[StringsEnum.CONFIG_LABEL])
        self._nhtsa_button.setText(self._strings[StringsEnum.NHTSA_LABEL])
        self._eblindfold_button.setText(
            self._strings[StringsEnum.EBLIND_LABEL])
        self._direct_control_button.setText(
            self._strings[StringsEnum.DCON_LABEL])
        self._open_dur_label.setText(
            self._strings[StringsEnum.OPEN_DURATION_LABEL])
        self._open_inf_check_box.setText(self._strings[StringsEnum.INF_LABEL])
        self._close_dur_label.setText(
            self._strings[StringsEnum.CLOSE_DURATION_LABEL])
        self._close_inf_check_box.setText(self._strings[StringsEnum.INF_LABEL])
        self._debounce_label.setText(self._strings[StringsEnum.DEBOUNCE_LABEL])
        self._button_mode_label.setText(
            self._strings[StringsEnum.BUTTON_MODE_LABEL])
        self._button_mode_selector.setItemText(
            0, self._strings[StringsEnum.HOLD_VAL_LABEL])
        self._button_mode_selector.setItemText(
            1, self._strings[StringsEnum.CLICK_VAL_LABEL])
        self._control_mode_label.setText(
            self._strings[StringsEnum.CONTROL_MODE_LABEL])
        self._control_mode_selector.setItemText(
            0, self._strings[StringsEnum.LENS_VAL_LABEL])
        self._control_mode_selector.setItemText(
            1, self._strings[StringsEnum.TRIAL_VAL_LABEL])
        self._upload_settings_button.setText(
            self._strings[StringsEnum.UPLOAD_BUTTON_LABEL])
        self._manual_control_open_button.setText(
            self._strings[StringsEnum.MANUAL_OPEN_LABEL])
        self._manual_control_close_button.setText(
            self._strings[StringsEnum.MANUAL_CLOSE_LABEL])
        self.config_button.setText(self._strings[StringsEnum.CONFIG_TAB_LABEL])
        self.config_button.setText("...")
        self._config_win.setWindowTitle(
            self.get_name() + " " +
            self._strings[StringsEnum.CONFIG_TAB_LABEL])
        self._logger.debug("done")

    def _set_tooltips(self) -> None:
        """
        Set tooltip text fields of view object.
        :return None:
        """
        self._logger.debug("running")
        self._config_label.setToolTip(
            self._strings[StringsEnum.CONFIG_LABEL_TOOLTIP])
        self._config_val_line_edit.setToolTip(
            self._strings[StringsEnum.CONFIG_LABEL_TOOLTIP])
        self._open_dur_label.setToolTip(
            self._strings[StringsEnum.OPEN_DURATION_TOOLTIP])
        self._close_dur_label.setToolTip(
            self._strings[StringsEnum.CLOSE_DURATION_TOOLTIP])
        self._debounce_label.setToolTip(
            self._strings[StringsEnum.DEBOUNCE_TOOLTIP])
        self._button_mode_label.setToolTip(
            self._strings[StringsEnum.BUTTON_MODE_TOOLTIP])
        self._control_mode_label.setToolTip(
            self._strings[StringsEnum.CONTROL_MODE_TOOLTIP])
        self._upload_settings_button.setToolTip(
            self._strings[StringsEnum.UPLOAD_BUTTON_TOOLTIP])
        self._manual_control_open_button.setToolTip(
            self._strings[StringsEnum.MANUAL_OPEN_TOOLTIP])
        self._manual_control_close_button.setToolTip(
            self._strings[StringsEnum.MANUAL_CLOSE_TOOLTIP])
        self.config_button.setToolTip(
            self._strings[StringsEnum.CONFIG_TAB_TOOLTIP])
        self._logger.debug("done")
Ejemplo n.º 7
0
    def __init__(self,
                 name: str = "CAM_NONE",
                 log_handlers: [StreamHandler] = None):
        self._logger = getLogger(__name__)
        if log_handlers:
            for h in log_handlers:
                self._logger.addHandler(h)
        self._logger.debug("Initializing")
        super().__init__(name)
        """ Min size for cam window """
        self._subwindow_height = 222
        self._subwindow_width = 518

        self._initialization_bar_frame = EasyFrame()
        self._initialization_bar_frame.setMouseTracking(True)
        self._initialization_bar_frame.setMaximumHeight(70)
        self._initialization_bar_layout = QVBoxLayout(
            self._initialization_bar_frame)

        self._initialization_bar_label = QLabel(self._initialization_bar_frame)
        self._initialization_bar_label.setMouseTracking(True)
        self._initialization_bar = QProgressBar(self._initialization_bar_frame)
        self._initialization_bar.setMouseTracking(True)
        self._initialization_bar.setMaximumHeight(15)
        self._initialization_bar.setTextVisible(True)
        self._initialization_bar.setAlignment(Qt.AlignHCenter)

        self._initialization_bar_layout.addWidget(
            self._initialization_bar_label)
        self._initialization_bar_layout.addWidget(self._initialization_bar)

        self._cam_settings_frame = EasyFrame()
        self._cam_settings_layout = QGridLayout(self._cam_settings_frame)

        self._resolution_selector_label = QLabel(self._cam_settings_frame)
        self._resolution_selector_label.setAlignment(Qt.AlignLeft)

        self._resolution_selector = QComboBox(self._cam_settings_frame)
        self._resolution_selector.setMaximumHeight(22)

        self._cam_settings_layout.addWidget(self._resolution_selector_label, 0,
                                            0)
        self._cam_settings_layout.addWidget(self._resolution_selector, 0, 1)

        self._fps_selector_label = QLabel(self._cam_settings_frame)
        self._fps_selector_label.setAlignment(Qt.AlignLeft)

        self._fps_selector = QComboBox(self._cam_settings_frame)
        self._fps_selector.setMaximumHeight(22)

        self._cam_settings_layout.addWidget(self._fps_selector_label, 1, 0)
        self._cam_settings_layout.addWidget(self._fps_selector, 1, 1)

        self._show_feed_checkbox_label = QLabel(self._cam_settings_frame)
        self._show_feed_checkbox_label.setAlignment(Qt.AlignLeft)

        self._show_feed_checkbox = QCheckBox()
        self._show_feed_checkbox.setChecked(True)
        self._show_feed_checkbox.setLayoutDirection(Qt.RightToLeft)

        self._cam_settings_layout.addWidget(self._show_feed_checkbox_label, 2,
                                            0)
        self._cam_settings_layout.addWidget(self._show_feed_checkbox, 2, 1)

        self._use_cam_checkbox_label = QLabel(self._cam_settings_frame)
        self._use_cam_checkbox_label.setAlignment(Qt.AlignLeft)

        self._use_cam_checkbox = QCheckBox()
        self._use_cam_checkbox.setChecked(True)
        self._use_cam_checkbox.setLayoutDirection(Qt.RightToLeft)

        self._cam_settings_layout.addWidget(self._use_cam_checkbox_label, 3, 0)
        self._cam_settings_layout.addWidget(self._use_cam_checkbox, 3, 1)

        self._use_overlay_checkbox_label = QLabel(self._cam_settings_frame)
        self._use_overlay_checkbox_label.setAlignment(Qt.AlignLeft)

        self._use_overlay_checkbox = QCheckBox()
        self._use_overlay_checkbox.setChecked(True)
        self._use_overlay_checkbox.setLayoutDirection(Qt.RightToLeft)

        self._cam_settings_layout.addWidget(self._use_overlay_checkbox_label,
                                            4, 0)
        self._cam_settings_layout.addWidget(self._use_overlay_checkbox, 4, 1)

        self._image_display_frame = EasyFrame()
        self._image_display_layout = QVBoxLayout(self._image_display_frame)

        self._image_display_label = QLabel(self._image_display_frame)
        self._image_display_label.setAlignment(Qt.AlignHCenter)
        self._image_display = QLabel(self._image_display_frame)
        self._image_display.setAlignment(Qt.AlignCenter)
        self._image_display.setMouseTracking(True)
        self._image_display_layout.addWidget(self._image_display_label)
        self._image_display_layout.addWidget(self._image_display)

        spacer = QSpacerItem(1, 1, vData=QSizePolicy.Expanding)

        self._dev_sets_frame = EasyFrame()
        self._dev_sets_layout = QVBoxLayout(self._dev_sets_frame)

        self.config_button = ClickAnimationButton()
        self.config_button.clicked.connect(self._config_button_handler)

        self.layout().addWidget(self.config_button, 0, 0,
                                Qt.AlignTop | Qt.AlignRight)
        self.config_button.setFixedSize(30, 25)
        self.config_button.setStyleSheet(
            "background-color: rgba(200, 200, 200, 50%)")

        self._dev_sets_layout.addWidget(self._cam_settings_frame)
        self._dev_sets_layout.addItem(spacer)
        self.layout().addWidget(self._image_display, 0, 0)
        self.layout().addWidget(self._initialization_bar_frame, 0, 0)

        self._config_items = [
            self._resolution_selector,
            self._fps_selector,
            self._use_cam_checkbox,
            self._show_feed_checkbox,
            self._use_overlay_checkbox,
        ]

        config_win_w = 350
        config_win_h = len(self._config_items) * 30

        self.config_button.raise_()

        self._config_win = ConfigPopUp()
        self._config_win.setLayout(self._dev_sets_layout)
        self._config_win.setFixedSize(config_win_w, config_win_h)

        self._rec_label = QLabel()
        self._rec_label.setStyleSheet(
            "background-color: rgba(0, 0, 0, 0%); color: red; font: 20px")
        self._rec_label.hide()

        self.layout().addWidget(self._rec_label, 0, 0,
                                Qt.AlignBottom | Qt.AlignRight)

        self.layout().setMargin(0)

        self._window_changing = False
        self._showing_images = False
        self._hidden = False
        w = 320
        self._aspect_ratio = 9 / 16
        self.resize(w, self.heightForWidth(w))
        self._strings = dict()
        self._lang_enum = LangEnum.ENG
        self.setMinimumSize(self._subwindow_width, self._subwindow_height)
        self.old_size = QSize(self.width(), self.height())

        self._logger.debug("Initialized")
Ejemplo n.º 8
0
class CamView(AbstractView):
    def __init__(self,
                 name: str = "CAM_NONE",
                 log_handlers: [StreamHandler] = None):
        self._logger = getLogger(__name__)
        if log_handlers:
            for h in log_handlers:
                self._logger.addHandler(h)
        self._logger.debug("Initializing")
        super().__init__(name)
        """ Min size for cam window """
        self._subwindow_height = 222
        self._subwindow_width = 518

        self._initialization_bar_frame = EasyFrame()
        self._initialization_bar_frame.setMouseTracking(True)
        self._initialization_bar_frame.setMaximumHeight(70)
        self._initialization_bar_layout = QVBoxLayout(
            self._initialization_bar_frame)

        self._initialization_bar_label = QLabel(self._initialization_bar_frame)
        self._initialization_bar_label.setMouseTracking(True)
        self._initialization_bar = QProgressBar(self._initialization_bar_frame)
        self._initialization_bar.setMouseTracking(True)
        self._initialization_bar.setMaximumHeight(15)
        self._initialization_bar.setTextVisible(True)
        self._initialization_bar.setAlignment(Qt.AlignHCenter)

        self._initialization_bar_layout.addWidget(
            self._initialization_bar_label)
        self._initialization_bar_layout.addWidget(self._initialization_bar)

        self._cam_settings_frame = EasyFrame()
        self._cam_settings_layout = QGridLayout(self._cam_settings_frame)

        self._resolution_selector_label = QLabel(self._cam_settings_frame)
        self._resolution_selector_label.setAlignment(Qt.AlignLeft)

        self._resolution_selector = QComboBox(self._cam_settings_frame)
        self._resolution_selector.setMaximumHeight(22)

        self._cam_settings_layout.addWidget(self._resolution_selector_label, 0,
                                            0)
        self._cam_settings_layout.addWidget(self._resolution_selector, 0, 1)

        self._fps_selector_label = QLabel(self._cam_settings_frame)
        self._fps_selector_label.setAlignment(Qt.AlignLeft)

        self._fps_selector = QComboBox(self._cam_settings_frame)
        self._fps_selector.setMaximumHeight(22)

        self._cam_settings_layout.addWidget(self._fps_selector_label, 1, 0)
        self._cam_settings_layout.addWidget(self._fps_selector, 1, 1)

        self._show_feed_checkbox_label = QLabel(self._cam_settings_frame)
        self._show_feed_checkbox_label.setAlignment(Qt.AlignLeft)

        self._show_feed_checkbox = QCheckBox()
        self._show_feed_checkbox.setChecked(True)
        self._show_feed_checkbox.setLayoutDirection(Qt.RightToLeft)

        self._cam_settings_layout.addWidget(self._show_feed_checkbox_label, 2,
                                            0)
        self._cam_settings_layout.addWidget(self._show_feed_checkbox, 2, 1)

        self._use_cam_checkbox_label = QLabel(self._cam_settings_frame)
        self._use_cam_checkbox_label.setAlignment(Qt.AlignLeft)

        self._use_cam_checkbox = QCheckBox()
        self._use_cam_checkbox.setChecked(True)
        self._use_cam_checkbox.setLayoutDirection(Qt.RightToLeft)

        self._cam_settings_layout.addWidget(self._use_cam_checkbox_label, 3, 0)
        self._cam_settings_layout.addWidget(self._use_cam_checkbox, 3, 1)

        self._use_overlay_checkbox_label = QLabel(self._cam_settings_frame)
        self._use_overlay_checkbox_label.setAlignment(Qt.AlignLeft)

        self._use_overlay_checkbox = QCheckBox()
        self._use_overlay_checkbox.setChecked(True)
        self._use_overlay_checkbox.setLayoutDirection(Qt.RightToLeft)

        self._cam_settings_layout.addWidget(self._use_overlay_checkbox_label,
                                            4, 0)
        self._cam_settings_layout.addWidget(self._use_overlay_checkbox, 4, 1)

        self._image_display_frame = EasyFrame()
        self._image_display_layout = QVBoxLayout(self._image_display_frame)

        self._image_display_label = QLabel(self._image_display_frame)
        self._image_display_label.setAlignment(Qt.AlignHCenter)
        self._image_display = QLabel(self._image_display_frame)
        self._image_display.setAlignment(Qt.AlignCenter)
        self._image_display.setMouseTracking(True)
        self._image_display_layout.addWidget(self._image_display_label)
        self._image_display_layout.addWidget(self._image_display)

        spacer = QSpacerItem(1, 1, vData=QSizePolicy.Expanding)

        self._dev_sets_frame = EasyFrame()
        self._dev_sets_layout = QVBoxLayout(self._dev_sets_frame)

        self.config_button = ClickAnimationButton()
        self.config_button.clicked.connect(self._config_button_handler)

        self.layout().addWidget(self.config_button, 0, 0,
                                Qt.AlignTop | Qt.AlignRight)
        self.config_button.setFixedSize(30, 25)
        self.config_button.setStyleSheet(
            "background-color: rgba(200, 200, 200, 50%)")

        self._dev_sets_layout.addWidget(self._cam_settings_frame)
        self._dev_sets_layout.addItem(spacer)
        self.layout().addWidget(self._image_display, 0, 0)
        self.layout().addWidget(self._initialization_bar_frame, 0, 0)

        self._config_items = [
            self._resolution_selector,
            self._fps_selector,
            self._use_cam_checkbox,
            self._show_feed_checkbox,
            self._use_overlay_checkbox,
        ]

        config_win_w = 350
        config_win_h = len(self._config_items) * 30

        self.config_button.raise_()

        self._config_win = ConfigPopUp()
        self._config_win.setLayout(self._dev_sets_layout)
        self._config_win.setFixedSize(config_win_w, config_win_h)

        self._rec_label = QLabel()
        self._rec_label.setStyleSheet(
            "background-color: rgba(0, 0, 0, 0%); color: red; font: 20px")
        self._rec_label.hide()

        self.layout().addWidget(self._rec_label, 0, 0,
                                Qt.AlignBottom | Qt.AlignRight)

        self.layout().setMargin(0)

        self._window_changing = False
        self._showing_images = False
        self._hidden = False
        w = 320
        self._aspect_ratio = 9 / 16
        self.resize(w, self.heightForWidth(w))
        self._strings = dict()
        self._lang_enum = LangEnum.ENG
        self.setMinimumSize(self._subwindow_width, self._subwindow_height)
        self.old_size = QSize(self.width(), self.height())

        self._logger.debug("Initialized")

    def set_show_feed_button_handler(self, func) -> None:
        """
        Add handler for show camera selector.
        :param func: The handler.
        :return None:
        """
        self._logger.debug("running")
        self._show_feed_checkbox.toggled.connect(func)
        self._logger.debug("done")

    def set_resolution_selector_handler(self, func) -> None:
        """
        Add handler for resolution selector.
        :param func: The handler.
        :return None:
        """
        self._logger.debug("running")
        self._resolution_selector.activated.connect(func)
        self._logger.debug("done")

    def set_fps_selector_handler(self, func) -> None:
        """
        Add handler for resolution selector.
        :param func: The handler.
        :return None:
        """
        self._logger.debug("running")
        self._fps_selector.activated.connect(func)
        self._logger.debug("done")

    def set_use_cam_button_handler(self, func) -> None:
        """
        Add handler for use camera selector.
        :param func: The handler.
        :return None:
        """
        self._logger.debug("running")
        self._use_cam_checkbox.toggled.connect(func)
        self._logger.debug("done")

    def set_use_overlay_button_handler(self, func) -> None:
        """
        Add handler for use camera selector.
        :param func: The handler.
        :return None:
        """
        self._logger.debug("running")
        self._use_overlay_checkbox.toggled.connect(func)
        self._logger.debug("done")

    def _config_button_handler(self) -> None:
        """
        Show config pop up.
        :return None:
        """
        self._logger.debug("running")
        self.config_button.setStyleSheet(
            "background-color: rgba(200, 200, 200, 50%)")
        self._config_win.exec_()
        self._logger.debug("done")

    @property
    def language(self) -> LangEnum:
        """
        :return: The current lang enum being used.
        """
        return self._lang_enum

    @language.setter
    def language(self, lang: LangEnum) -> None:
        """
        Set the language for this view object.
        :param lang: The language to use.
        :return None:
        """
        self._logger.debug("running")
        self._lang_enum = lang
        self._strings = strings[lang]
        self._set_texts()
        self._set_tooltips()
        self._logger.debug("done")

    @property
    def resolution_list(self) -> list:
        """
        Get list of resolutions.
        :return list: The list of resolutions.
        """
        ret = list()
        return ret

    @resolution_list.setter
    def resolution_list(self, res_list: list) -> None:
        """
        Set list of resolutions available to res_list.
        :param res_list: The list of available resolutions.
        :return None:
        """
        self._logger.debug("running")
        self._resolution_selector.clear()
        for item in res_list:
            self._resolution_selector.addItem(str(item))
        self._logger.debug("done")

    @property
    def resolution(self) -> str:
        """
        Get the current resolution selection.
        :return str: The current resolution.
        """
        return self._resolution_selector.currentText()

    @resolution.setter
    def resolution(self, res: str) -> None:
        """
        Set the current resolution selection.
        :param res: The resolution to set to.
        :return None:
        """
        self._resolution_selector.setCurrentIndex(
            self._resolution_selector.findText(res))

    @property
    def fps_list(self) -> list:
        """
        Get list of fps options.
        :return list: The list of fps options.
        """
        ret = list()
        return ret

    @fps_list.setter
    def fps_list(self, fps_list: list) -> None:
        """
        Set list of available fps to fps_list.
        :param fps_list:
        :return None:
        """
        self._logger.debug("running")
        self._fps_selector.clear()
        for item in fps_list:
            self._fps_selector.addItem(str(item))
        self._logger.debug("done")

    @property
    def fps(self) -> str:
        """
        Get the current fps selection.
        :return str: The current fps selection.
        """
        return self._fps_selector.currentText()

    @fps.setter
    def fps(self, fps: str) -> None:
        """
        Set the current fps selection.
        :param fps: The fps to set to.
        :return None:
        """
        self._logger.debug("running")
        self._fps_selector.setCurrentIndex(self._fps_selector.findText(fps))
        self._logger.debug("done")

    @property
    def use_feed(self) -> bool:
        """
        Get the current use_cam setting.
        :return bool: User selection for using cam.
        """
        return self._show_feed_checkbox.isChecked()

    @use_feed.setter
    def use_feed(self, useable: bool) -> None:
        """
        Set use_cam setting.
        :param useable: The setting to set to.
        :return None:
        """
        self._logger.debug("running")
        self._show_feed_checkbox.setChecked(useable)
        self._logger.debug("Done")

    @property
    def use_cam(self) -> bool:
        """
        Get the current use_cam setting.
        :return bool: User selection for using cam.
        """
        return self._use_cam_checkbox.isChecked()

    @use_cam.setter
    def use_cam(self, useable: bool) -> None:
        """
        Set use_cam setting.
        :param useable: The setting to set to.
        :return None:
        """
        self._logger.debug("running")
        self._use_cam_checkbox.setChecked(useable)
        self._logger.debug("Done")

    @property
    def use_overlay(self) -> bool:
        """
        Get the current use_overlay setting.
        :return bool: User selection for using overlay.
        """
        return self._use_overlay_checkbox.isChecked()

    @use_overlay.setter
    def use_overlay(self, useable: bool) -> None:
        """
        Set use_overlay setting.
        :param useable: The setting to set to.
        :return None:
        """
        self._logger.debug("running")
        self._use_overlay_checkbox.setChecked(useable)
        self._logger.debug("Done")

    def heightForWidth(self, w: int) -> int:
        return int(w * self._aspect_ratio)

    def widthForHeight(self, h: int) -> int:
        return int(h / self._aspect_ratio)

    def hideEvent(self, hideEvent: QHideEvent):
        """
        Track minimize event.
        :param hideEvent:
        :return None:
        """
        self._hidden = True

    def showEvent(self, showEvent: QShowEvent):
        """
        Track restore event.
        :param showEvent:
        :return None:
        """
        self._hidden = False

    def update_image(self, image: QPixmap = None, msg: str = None) -> None:
        """
        Update image viewer with new image.
        :param image: The new image to show.
        :param msg: The text to show if no image.
        :return None:
        """
        self._logger.debug("running")
        if not self._window_changing:
            if image is not None:
                temp_image_w = image.scaledToWidth(self.width() - 15)
                temp_image_h = image.scaledToHeight(self.height() - 35)
                if temp_image_w.height() > self.height() - 35:
                    self._image_display.setPixmap(temp_image_h)
                else:
                    self._image_display.setPixmap(temp_image_w)
            elif msg is not None:
                self._image_display.setText(msg)
        self._logger.debug("done")

    def show_images(self) -> None:
        """
        Show image display and hide initialization bar.
        :return None:
        """
        self._logger.debug("running")
        geo = self.geometry()
        self._showing_images = True
        self._initialization_bar_frame.hide()
        self._image_display.show()
        self.config_button.show()
        self.setStyleSheet("background-color: black")
        self.setGeometry(geo)
        self._logger.debug("done")

    def show_initialization(self) -> None:
        """
        Show initialization bar and hide image display.
        :return None:
        """
        self._logger.debug("running")
        self._showing_images = False
        self._image_display.hide()
        self.config_button.hide()
        self._initialization_bar_frame.show()
        self._logger.debug("done")

    def update_init_bar(self, progress: int) -> None:
        """
        set progress bar value to progress.
        :param progress: The value to set progress bar to.
        :return None:
        """
        self._logger.debug("running")
        if progress > 100:
            progress = 100
        elif progress < 0:
            progress = 0
        self._initialization_bar.setValue(progress)
        self._logger.debug("done")

    def set_config_active(self, is_active: bool) -> None:
        """
        Set whether this camera config options are usable.
        :param is_active: Usable.
        :return None:
        """
        self._logger.debug("running")
        if self._showing_images:
            if is_active:
                self._rec_label.hide()
            elif self.use_cam:
                self._rec_label.show()
        for item in self._config_items:
            item.setEnabled(is_active)
        self._logger.debug("done")

    def _set_texts(self) -> None:
        """
        Set the texts in this view object.
        :return None:
        """
        self._logger.debug("running")
        self._initialization_bar_label.setText(
            self._strings[StringsEnum.INITIALIZATION_BAR_LABEL])
        self._initialization_bar.setValue(0)
        self._image_display_label.setText(
            self._strings[StringsEnum.IMAGE_DISPLAY_LABEL])
        self._image_display.setText(self._strings[StringsEnum.IMAGE_DISPLAY])
        self._show_feed_checkbox_label.setText(
            self._strings[StringsEnum.SHOW_FEED_CHECKBOX_LABEL])
        self._use_cam_checkbox_label.setText(
            self._strings[StringsEnum.USE_CAM_CHECKBOX_LABEL])
        self._use_overlay_checkbox_label.setText(
            self._strings[StringsEnum.USE_OVERLAY_CHECKBOX_LABEL])
        self._resolution_selector_label.setText(
            self._strings[StringsEnum.RESOLUTION_SELECTOR_LABEL])
        self._fps_selector_label.setText(
            self._strings[StringsEnum.FPS_SELECTOR_LABEL])
        self._config_win.setWindowTitle(
            self.get_name() + " " +
            self._strings[StringsEnum.CONFIG_TAB_LABEL])
        self.config_button.setText("...")
        self._rec_label.setText("rec ●")
        self._logger.debug("done")

    def _set_tooltips(self) -> None:
        """
        Set the tooltips in this view object.
        :return None:
        """
        self._logger.debug("running")
        self._resolution_selector_label.setToolTip(
            self._strings[StringsEnum.RESOLUTION_SELECTOR_TOOLTIP])
        self._resolution_selector.setToolTip(
            self._strings[StringsEnum.RESOLUTION_SELECTOR_TOOLTIP])
        self._fps_selector_label.setToolTip(
            self._strings[StringsEnum.FPS_SELECTOR_TOOLTIP])
        self._fps_selector.setToolTip(
            self._strings[StringsEnum.FPS_SELECTOR_TOOLTIP])
        self._show_feed_checkbox_label.setToolTip(
            self._strings[StringsEnum.SHOW_FEED_CHECKBOX_TOOLTIP])
        self._show_feed_checkbox.setToolTip(
            self._strings[StringsEnum.SHOW_FEED_CHECKBOX_TOOLTIP])
        self._use_cam_checkbox_label.setToolTip(
            self._strings[StringsEnum.USE_CAM_CHECKBOX_TOOLTIP])
        self._use_cam_checkbox.setToolTip(
            self._strings[StringsEnum.USE_CAM_CHECKBOX_TOOLTIP])
        self._use_overlay_checkbox_label.setToolTip(
            self._strings[StringsEnum.USE_OVERLAY_TOOLTIP])
        self._use_overlay_checkbox.setToolTip(
            self._strings[StringsEnum.USE_OVERLAY_TOOLTIP])
        self._image_display.setToolTip(
            self._strings[StringsEnum.IMAGE_DISPLAY_TOOLTIP])
        self._logger.debug("done")
Ejemplo n.º 9
0
    def __init__(self,
                 name: str = "DRT_NONE",
                 log_handlers: [StreamHandler] = None):
        self._logger = getLogger(__name__)
        if log_handlers:
            for h in log_handlers:
                self._logger.addHandler(h)
        self._logger.debug("Initializing")
        super().__init__(name)
        """ Min size for the DRT window """
        self._subwindow_height = 222
        self._subwindow_width = 518
        """ min and max sizes for the configuration popup """
        self._popup_min = (168, 313)
        self._popup_max = (300, 313)
        """ Set configuration value display area """
        self._config_frame = EasyFrame()
        self._config_layout = QVBoxLayout(self._config_frame)

        self._config_label = QLabel(self._config_frame)
        self._config_label.setAlignment(Qt.AlignCenter)

        self._config_val = QLabel(self._config_frame)
        self._config_val.setAlignment(Qt.AlignCenter)

        self._config_layout.addWidget(self._config_label)
        self._config_layout.addWidget(self._config_val)
        """ Set preset button selection area. """
        self._iso_button = ClickAnimationButton()
        """ Set stim intensity settings display area. """
        self._slider_frame = EasyFrame()
        self._slider_layout = QVBoxLayout(self._slider_frame)
        self._slider_label_layout = QHBoxLayout(self._slider_frame)

        self._stim_intens_label = QLabel(self._slider_frame)
        self._stim_intens_label.setAlignment(Qt.AlignLeft)
        self._stim_intens_val = QLabel(self._slider_frame)
        self._stim_intens_val.setAlignment(Qt.AlignRight | Qt.AlignTrailing
                                           | Qt.AlignVCenter)

        self._slider_layout.addLayout(self._slider_label_layout)

        self._stim_intens_slider = QSlider(self._slider_frame)
        self._stim_intens_slider.setMinimum(1)
        self._stim_intens_slider.setMaximum(100)
        self._stim_intens_slider.setSliderPosition(100)
        self._stim_intens_slider.setOrientation(Qt.Horizontal)
        self._stim_intens_slider.setTickPosition(QSlider.TicksBelow)
        self._stim_intens_slider.setTickInterval(10)

        self._slider_label_layout.addWidget(self._stim_intens_label)
        self._slider_label_layout.addWidget(self._stim_intens_val)
        self._slider_layout.addWidget(self._stim_intens_slider)
        """ Set stim duration, upper isi and lower isi settings display area. """
        self._input_box_frame = EasyFrame()
        self._input_box_layout = QGridLayout(self._input_box_frame)

        self._stim_dur_line_edit = QLineEdit(self._input_box_frame)
        self._stim_dur_line_edit.setMaximumSize(QSize(100, 16777215))
        self._stim_dur_label = QLabel(self._input_box_frame)

        self._upper_isi_label = QLabel(self._input_box_frame)
        self._upper_isi_line_edit = QLineEdit(self._input_box_frame)
        self._upper_isi_line_edit.setMaximumSize(QSize(100, 16777215))

        self._lower_isi_line_edit = QLineEdit(self._input_box_frame)
        self._lower_isi_line_edit.setMaximumSize(QSize(100, 16777215))
        self._lower_isi_label = QLabel(self._input_box_frame)

        self._input_box_layout.addWidget(self._stim_dur_line_edit, 0, 1, 1, 1)
        self._input_box_layout.addWidget(self._upper_isi_label, 1, 0, 1, 1)
        self._input_box_layout.addWidget(self._upper_isi_line_edit, 1, 1, 1, 1)
        self._input_box_layout.addWidget(self._stim_dur_label, 0, 0, 1, 1)
        self._input_box_layout.addWidget(self._lower_isi_line_edit, 2, 1, 1, 1)
        self._input_box_layout.addWidget(self._lower_isi_label, 2, 0, 1, 1)
        """ Set upload button selection area. """
        self._upload_settings_button = ClickAnimationButton()
        self._upload_settings_button.setEnabled(False)
        """ device settings display """
        self._dev_sets_frame = EasyFrame()
        self._dev_sets_layout = QVBoxLayout(self._dev_sets_frame)
        self._config_horizontal_layout = QHBoxLayout()

        self.config_button = ClickAnimationButton()
        self.config_button.clicked.connect(self._config_button_handler)

        self.layout().addWidget(self.config_button, 0, 0,
                                Qt.AlignTop | Qt.AlignRight)
        self.config_button.setFixedSize(30, 25)

        self._config_win = ConfigPopUp()
        self._config_win.setMinimumSize(self._popup_min[0], self._popup_min[1])
        self._config_win.setMaximumSize(self._popup_max[0], self._popup_max[1])
        self._config_win.setLayout(self._dev_sets_layout)
        """ Add all of the widgets to the layout. """
        self._dev_sets_layout.addWidget(self._config_frame)
        self._dev_sets_layout.addWidget(self._input_box_frame)
        self._dev_sets_layout.addWidget(self._slider_frame)
        self._dev_sets_layout.addWidget(EasyFrame(line=True))
        self._dev_sets_layout.addWidget(self._iso_button)
        self._dev_sets_layout.addWidget(self._upload_settings_button)

        self.layout().setMargin(0)

        self._strings = dict()
        self._lang_enum = LangEnum.ENG
        self.setMinimumSize(self._subwindow_width, self._subwindow_height)
        self.resize(self._subwindow_width, self._subwindow_height)
        self._logger.debug("Initialized")
Ejemplo n.º 10
0
class DRTView(AbstractView):
    def __init__(self,
                 name: str = "DRT_NONE",
                 log_handlers: [StreamHandler] = None):
        self._logger = getLogger(__name__)
        if log_handlers:
            for h in log_handlers:
                self._logger.addHandler(h)
        self._logger.debug("Initializing")
        super().__init__(name)
        """ Min size for the DRT window """
        self._subwindow_height = 222
        self._subwindow_width = 518
        """ min and max sizes for the configuration popup """
        self._popup_min = (168, 313)
        self._popup_max = (300, 313)
        """ Set configuration value display area """
        self._config_frame = EasyFrame()
        self._config_layout = QVBoxLayout(self._config_frame)

        self._config_label = QLabel(self._config_frame)
        self._config_label.setAlignment(Qt.AlignCenter)

        self._config_val = QLabel(self._config_frame)
        self._config_val.setAlignment(Qt.AlignCenter)

        self._config_layout.addWidget(self._config_label)
        self._config_layout.addWidget(self._config_val)
        """ Set preset button selection area. """
        self._iso_button = ClickAnimationButton()
        """ Set stim intensity settings display area. """
        self._slider_frame = EasyFrame()
        self._slider_layout = QVBoxLayout(self._slider_frame)
        self._slider_label_layout = QHBoxLayout(self._slider_frame)

        self._stim_intens_label = QLabel(self._slider_frame)
        self._stim_intens_label.setAlignment(Qt.AlignLeft)
        self._stim_intens_val = QLabel(self._slider_frame)
        self._stim_intens_val.setAlignment(Qt.AlignRight | Qt.AlignTrailing
                                           | Qt.AlignVCenter)

        self._slider_layout.addLayout(self._slider_label_layout)

        self._stim_intens_slider = QSlider(self._slider_frame)
        self._stim_intens_slider.setMinimum(1)
        self._stim_intens_slider.setMaximum(100)
        self._stim_intens_slider.setSliderPosition(100)
        self._stim_intens_slider.setOrientation(Qt.Horizontal)
        self._stim_intens_slider.setTickPosition(QSlider.TicksBelow)
        self._stim_intens_slider.setTickInterval(10)

        self._slider_label_layout.addWidget(self._stim_intens_label)
        self._slider_label_layout.addWidget(self._stim_intens_val)
        self._slider_layout.addWidget(self._stim_intens_slider)
        """ Set stim duration, upper isi and lower isi settings display area. """
        self._input_box_frame = EasyFrame()
        self._input_box_layout = QGridLayout(self._input_box_frame)

        self._stim_dur_line_edit = QLineEdit(self._input_box_frame)
        self._stim_dur_line_edit.setMaximumSize(QSize(100, 16777215))
        self._stim_dur_label = QLabel(self._input_box_frame)

        self._upper_isi_label = QLabel(self._input_box_frame)
        self._upper_isi_line_edit = QLineEdit(self._input_box_frame)
        self._upper_isi_line_edit.setMaximumSize(QSize(100, 16777215))

        self._lower_isi_line_edit = QLineEdit(self._input_box_frame)
        self._lower_isi_line_edit.setMaximumSize(QSize(100, 16777215))
        self._lower_isi_label = QLabel(self._input_box_frame)

        self._input_box_layout.addWidget(self._stim_dur_line_edit, 0, 1, 1, 1)
        self._input_box_layout.addWidget(self._upper_isi_label, 1, 0, 1, 1)
        self._input_box_layout.addWidget(self._upper_isi_line_edit, 1, 1, 1, 1)
        self._input_box_layout.addWidget(self._stim_dur_label, 0, 0, 1, 1)
        self._input_box_layout.addWidget(self._lower_isi_line_edit, 2, 1, 1, 1)
        self._input_box_layout.addWidget(self._lower_isi_label, 2, 0, 1, 1)
        """ Set upload button selection area. """
        self._upload_settings_button = ClickAnimationButton()
        self._upload_settings_button.setEnabled(False)
        """ device settings display """
        self._dev_sets_frame = EasyFrame()
        self._dev_sets_layout = QVBoxLayout(self._dev_sets_frame)
        self._config_horizontal_layout = QHBoxLayout()

        self.config_button = ClickAnimationButton()
        self.config_button.clicked.connect(self._config_button_handler)

        self.layout().addWidget(self.config_button, 0, 0,
                                Qt.AlignTop | Qt.AlignRight)
        self.config_button.setFixedSize(30, 25)

        self._config_win = ConfigPopUp()
        self._config_win.setMinimumSize(self._popup_min[0], self._popup_min[1])
        self._config_win.setMaximumSize(self._popup_max[0], self._popup_max[1])
        self._config_win.setLayout(self._dev_sets_layout)
        """ Add all of the widgets to the layout. """
        self._dev_sets_layout.addWidget(self._config_frame)
        self._dev_sets_layout.addWidget(self._input_box_frame)
        self._dev_sets_layout.addWidget(self._slider_frame)
        self._dev_sets_layout.addWidget(EasyFrame(line=True))
        self._dev_sets_layout.addWidget(self._iso_button)
        self._dev_sets_layout.addWidget(self._upload_settings_button)

        self.layout().setMargin(0)

        self._strings = dict()
        self._lang_enum = LangEnum.ENG
        self.setMinimumSize(self._subwindow_width, self._subwindow_height)
        self.resize(self._subwindow_width, self._subwindow_height)
        self._logger.debug("Initialized")

    def add_graph(self, graph) -> None:
        """
        Add graph to view
        :return None:
        """
        self._logger.debug("running")
        self.layout().addWidget(graph, 0, 0)
        self.config_button.raise_()
        self._logger.debug("done")

    def _config_button_handler(self) -> None:
        """
        handles the config button
        :return None:
        """
        self._logger.debug("running")
        self._config_win.exec_()
        self._logger.debug("done")

    def set_stim_dur_entry_changed_handler(self, func: classmethod) -> None:
        """
        Add handler for when user changes input value in this field.
        :param func: The handler.
        :return: None.
        """
        self._logger.debug("running")
        self._stim_dur_line_edit.textChanged.connect(func)
        self._logger.debug("done")

    def set_stim_intens_entry_changed_handler(self, func: classmethod) -> None:
        """
        Add handler for when user changes input value in this field.
        :param func: The handler.
        :return: None.
        """
        self._logger.debug("running")
        self._stim_intens_slider.valueChanged.connect(func)
        self._logger.debug("done")

    def set_upper_isi_entry_changed_handler(self, func: classmethod) -> None:
        """
        Add handler for when user changes input value in this field.
        :param func: The handler.
        :return: None.
        """
        self._logger.debug("running")
        self._upper_isi_line_edit.textChanged.connect(func)
        self._logger.debug("done")

    def set_lower_isi_entry_changed_handler(self, func: classmethod) -> None:
        """
        Add handler for when user changes input value in this field.
        :param func: The handler.
        :return: None.
        """
        self._logger.debug("running")
        self._lower_isi_line_edit.textChanged.connect(func)
        self._logger.debug("done")

    def set_iso_button_handler(self, func: classmethod) -> None:
        """
        Add handler for when user clicks this button.
        :param func: The handler.
        :return: None.
        """
        self._logger.debug("running")
        self._iso_button.clicked.connect(func)
        self._logger.debug("done")

    def set_upload_button_handler(self, func: classmethod) -> None:
        """
        Add handler for when user clicks this button.
        :param func: The handler.
        :return: None.
        """
        self._logger.debug("running")
        self._upload_settings_button.clicked.connect(func)
        self._logger.debug("done")

    @property
    def config_text(self) -> str:
        """
        Get configuration text value
        :return str: text value
        """
        return self._config_val.text()

    @config_text.setter
    def config_text(self, val: str) -> None:
        """
        Set configuration text value
        :param val: text to set
        :return None:
        """
        self._logger.debug("running")
        self._config_val.setText(val)
        self._logger.debug("done")

    @property
    def stim_duration(self) -> str:
        """
        Get the display value of stim duration
        :return str: the display value
        """
        return self._stim_dur_line_edit.text()

    @stim_duration.setter
    def stim_duration(self, val: str) -> None:
        """
        Set display value of stim duration
        :param val:
        :return:
        """
        self._logger.debug("running")
        self._stim_dur_line_edit.setText(str(val))
        self._logger.debug("done")

    def set_stim_dur_err(self, is_error: bool) -> None:
        """
        Set display of error in stim duration
        :param is_error: Whether this line edit should display error.
        :return None:
        """
        self._logger.debug("running")
        if is_error:
            self._stim_dur_line_edit.setStyleSheet(tab_line_edit_error_style)
        else:
            self._stim_dur_line_edit.setStyleSheet(
                tab_line_edit_compliant_style)
        self._logger.debug("done")

    @property
    def stim_intensity(self) -> int:
        """
        Get the integer value for the stim intensity
        :return int: stim intensity
        """
        return self._stim_intens_slider.value()

    @stim_intensity.setter
    def stim_intensity(self, val: str) -> None:
        """
        Set display value of stim intensity
        :param val:
        :return:
        """
        self._logger.debug("running")
        self._stim_intens_slider.setValue(int(val))
        self.update_stim_intens_val_tooltip()
        self._logger.debug("done")

    def update_stim_intens_val_tooltip(self) -> None:
        """
        Update slider tooltip.
        :return: None.
        """
        self._logger.debug("running")
        self._stim_intens_slider.setToolTip(
            str(self._stim_intens_slider.value()) + "%")
        self._logger.debug("done")

    @property
    def upper_isi(self) -> str:
        """

        :return str:
        """
        return self._upper_isi_line_edit.text()

    @upper_isi.setter
    def upper_isi(self, val: str) -> None:
        """
        Set display value of upper isi
        :param val:
        :return:
        """
        self._logger.debug("running")
        self._upper_isi_line_edit.setText(str(val))
        self._logger.debug("done")

    def set_upper_isi_err(self, is_error: bool) -> None:
        """
        Set display of error in upper isi line edit
        :param is_error: Whether this line edit should display error.
        :return None:
        """
        self._logger.debug("running")
        if is_error:
            self._upper_isi_line_edit.setStyleSheet(tab_line_edit_error_style)
        else:
            self._upper_isi_line_edit.setStyleSheet(
                tab_line_edit_compliant_style)
        self._logger.debug("done")

    @property
    def lower_isi(self) -> str:
        """

        :return str:
        """
        return self._lower_isi_line_edit.text()

    @lower_isi.setter
    def lower_isi(self, val: str) -> None:
        """
        Set display value of lower isi
        :param val: string value the display will be set to
        :return None:
        """
        self._logger.debug("running")
        self._lower_isi_line_edit.setText(str(val))
        self._logger.debug("done")

    def set_lower_isi_err(self, is_error: bool) -> None:
        """
        Set display of error in lower isi line edit
        :param is_error: Whether this line edit should display error.
        :return None:
        """
        self._logger.debug("running")
        if is_error:
            self._lower_isi_line_edit.setStyleSheet(tab_line_edit_error_style)
        else:
            self._lower_isi_line_edit.setStyleSheet(
                tab_line_edit_compliant_style)
        self._logger.debug("done")

    def set_upload_button(self, is_active) -> None:
        """

        :return:
        """
        self._logger.debug("running")
        self._upload_settings_button.setEnabled(is_active)
        self._logger.debug("done")

    @property
    def language(self) -> LangEnum:
        """
        Get the current language setting
        :return LangEnum: The current language enumerator being used
        """
        return self._lang_enum

    @language.setter
    def language(self, lang: LangEnum) -> None:
        """
        Set the language for this view object and reload the text and tooltips.
        :param lang: the language to use.
        :return None:
        """
        self._logger.debug("running")
        self._strings = strings[lang]
        self._set_texts()
        self._set_tooltips()
        self._logger.debug("done")

    def _set_texts(self):
        self._logger.debug("running")
        self._config_label.setText(self._strings[StringsEnum.CONFIG_LABEL])
        self._config_val.setText(self._strings[StringsEnum.ISO_LABEL])
        self._iso_button.setText(self._strings[StringsEnum.ISO_BUTTON_LABEL])
        self._stim_dur_label.setText(self._strings[StringsEnum.DURATION_LABEL])
        self._stim_intens_label.setText(
            self._strings[StringsEnum.INTENSITY_LABEL])
        self._upper_isi_label.setText(
            self._strings[StringsEnum.UPPER_ISI_LABEL])
        self._lower_isi_label.setText(
            self._strings[StringsEnum.LOWER_ISI_LABEL])
        self._upload_settings_button.setText(
            self._strings[StringsEnum.UPLOAD_BUTTON_LABEL])
        self.config_button.setText("...")
        self._config_win.setWindowTitle(
            self.get_name() + " " +
            self._strings[StringsEnum.CONFIG_TAB_LABEL])
        self._logger.debug("done")

    def _set_tooltips(self):
        self._logger.debug("running")
        self._config_label.setToolTip(
            self._strings[StringsEnum.CONFIG_LABEL_TOOLTIP])
        self._iso_button.setToolTip(
            self._strings[StringsEnum.ISO_BUTTON_TOOLTIP])
        self._upper_isi_label.setToolTip(
            self._strings[StringsEnum.UPPER_ISI_TOOLTIP])
        self._lower_isi_label.setToolTip(
            self._strings[StringsEnum.LOWER_ISI_TOOLTIP])
        self._stim_dur_label.setToolTip(
            self._strings[StringsEnum.DURATION_TOOLTIP])
        self._stim_intens_label.setToolTip(
            self._strings[StringsEnum.INTENSITY_TOOLTIP])
        self._upload_settings_button.setToolTip(
            self._strings[StringsEnum.UPLOAD_BUTTON_TOOLTIP])
        self._stim_intens_slider.setToolTip(
            str(self._stim_intens_slider.value()) + "%")
        self.config_button.setToolTip(
            self._strings[StringsEnum.CONFIG_TAB_TOOLTIP])
        self._logger.debug("done")
Ejemplo n.º 11
0
    def __init__(self):
        QMainWindow.__init__(self)
        self.setFixedSize(300, 200)
        self.setCentralWidget(CentralWidget(self))
        self.myLayout = QHBoxLayout(self)

        self.tab1 = QTabWidget(self)
        self.tab3 = QTabWidget(self)
        self.tab3.setTabPosition(QTabWidget.East)
        self.tab3.tabBarClicked.connect(self.tab_pressed_3)
        self.tab3_minimized = False
        self.tab1.setTabPosition(QTabWidget.East)
        self.tab1.tabBarClicked.connect(self.tab_pressed_1)
        self.tab1_minimized = False

        self.widget1 = EasyFrame()

        self.button1 = ClickAnimationButton()
        self.button1.setText("button 1")
        self.button1.clicked.connect(self.button_test_1)

        self.widget2 = EasyFrame()

        self.button2 = ClickAnimationButton()
        self.button2.setText("button 2")
        self.button2.clicked.connect(self.button_test_2)

        self.widget3 = EasyFrame()

        self.button3 = ClickAnimationButton()
        self.button3.setText("button 3")
        self.button3.clicked.connect(self.button_test_3)

        self.radio_test1 = QRadioButton(self)
        self.radio_test1.setText("radio 1")
        self.radio_test1.toggled.connect(self.radio_toggled_1)

        self.radio_test2 = QRadioButton(self)
        self.radio_test2.setText("radio 2")
        self.radio_test2.toggled.connect(self.radio_toggled_2)

        self.radio_test3 = QRadioButton(self)
        self.radio_test3.setText("radio 3")
        self.radio_test3.toggled.connect(self.radio_toggled_3)

        self.tab1_layout = QVBoxLayout(self.widget1)
        self.tab1_layout.addWidget(self.button1)
        self.tab1_layout.addWidget(self.radio_test1)
        self.tab1_layout.addWidget(self.radio_test2)
        self.tab1_layout.addWidget(self.radio_test3)

        self.tab2_layout = QVBoxLayout(self.widget2)
        self.tab2_layout.addWidget(self.button2)

        self.tab3_layout = QVBoxLayout(self.widget3)
        self.tab3_layout.addWidget(self.button3)

        self.tab1.addTab(self.widget1, "tab 1")
        self.tab1.addTab(self.widget2, "tab 2")
        self.tab3.addTab(self.widget3, "tab 3")

        self.myLayout.addWidget(self.tab1)
        self.myLayout.addWidget(self.tab3)
        # self.myLayout.addWidget(self.button1)
        # self.myLayout.addWidget(self.button2)
        # self.myLayout.addWidget(self.button3)

        self.centralWidget().layout().addLayout(self.myLayout)
Ejemplo n.º 12
0
class MainWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        self.setFixedSize(300, 200)
        self.setCentralWidget(CentralWidget(self))
        self.myLayout = QHBoxLayout(self)

        self.tab1 = QTabWidget(self)
        self.tab3 = QTabWidget(self)
        self.tab3.setTabPosition(QTabWidget.East)
        self.tab3.tabBarClicked.connect(self.tab_pressed_3)
        self.tab3_minimized = False
        self.tab1.setTabPosition(QTabWidget.East)
        self.tab1.tabBarClicked.connect(self.tab_pressed_1)
        self.tab1_minimized = False

        self.widget1 = EasyFrame()

        self.button1 = ClickAnimationButton()
        self.button1.setText("button 1")
        self.button1.clicked.connect(self.button_test_1)

        self.widget2 = EasyFrame()

        self.button2 = ClickAnimationButton()
        self.button2.setText("button 2")
        self.button2.clicked.connect(self.button_test_2)

        self.widget3 = EasyFrame()

        self.button3 = ClickAnimationButton()
        self.button3.setText("button 3")
        self.button3.clicked.connect(self.button_test_3)

        self.radio_test1 = QRadioButton(self)
        self.radio_test1.setText("radio 1")
        self.radio_test1.toggled.connect(self.radio_toggled_1)

        self.radio_test2 = QRadioButton(self)
        self.radio_test2.setText("radio 2")
        self.radio_test2.toggled.connect(self.radio_toggled_2)

        self.radio_test3 = QRadioButton(self)
        self.radio_test3.setText("radio 3")
        self.radio_test3.toggled.connect(self.radio_toggled_3)

        self.tab1_layout = QVBoxLayout(self.widget1)
        self.tab1_layout.addWidget(self.button1)
        self.tab1_layout.addWidget(self.radio_test1)
        self.tab1_layout.addWidget(self.radio_test2)
        self.tab1_layout.addWidget(self.radio_test3)

        self.tab2_layout = QVBoxLayout(self.widget2)
        self.tab2_layout.addWidget(self.button2)

        self.tab3_layout = QVBoxLayout(self.widget3)
        self.tab3_layout.addWidget(self.button3)

        self.tab1.addTab(self.widget1, "tab 1")
        self.tab1.addTab(self.widget2, "tab 2")
        self.tab3.addTab(self.widget3, "tab 3")

        self.myLayout.addWidget(self.tab1)
        self.myLayout.addWidget(self.tab3)
        # self.myLayout.addWidget(self.button1)
        # self.myLayout.addWidget(self.button2)
        # self.myLayout.addWidget(self.button3)

        self.centralWidget().layout().addLayout(self.myLayout)

    def button_test_1(self):
        print("button 1 pressed")
        msg_box = QDialog()
        # msg_box.setModal(True)
        msg_box.setWindowTitle("Test message box")
        # msg_box.setText("This is a message")
        test_frame = EasyFrame()
        test_layout = QVBoxLayout(test_frame)

        test_button = ClickAnimationButton(test_frame)
        test_button.setText("test button")
        test_button.clicked.connect(self.button_test_2)

        test_layout.addWidget(test_button)

        # msg_box.layout().addWidget(test_layout)
        # msg_box.setStandardButtons(QMessageBox.Ok)
        msg_box.setLayout(test_layout)

        # msg_box.exec_()
        msg_box.exec()

    def button_test_2(self):
        print("button 2 pressed")

    def button_test_3(self):
        print("button 3 pressed")

    def tab_pressed_1(self):
        print("tab 1 pressed")

    def tab_pressed_2(self):
        print("tab 2 pressed")

    def tab_pressed_3(self):
        print("tab 3 pressed")
        if not self.tab3_minimized:
            self.tab3_minimized = True
            self.tab3.setMaximumWidth(18)
        else:
            self.tab3_minimized = False
            self.tab3.setMaximumWidth(200)

    def tab_pressed_1(self):
        print("tab 3 pressed")
        if not self.tab1_minimized:
            self.tab1_minimized = True
            self.tab1.setMaximumWidth(18)
        else:
            self.tab1_minimized = False
            self.tab1.setMaximumWidth(200)

    def radio_toggled_1(self):
        if self.radio_test1.isChecked():
            print("radio button 1 on")
        else:
            print("radio button 1 off")

    def radio_toggled_2(self):
        if self.radio_test2.isChecked():
            print("radio button 2 on")
        else:
            print("radio button 2 off")

    def radio_toggled_3(self):
        if self.radio_test3.isChecked():
            print("radio button 3 on")
        else:
            print("radio button 3 off")
Ejemplo n.º 13
0
class NoteBox(QGroupBox):
    """ This code is for the user to input notes as desired. """
    def __init__(self,
                 parent=None,
                 size: QSize = QSize(10, 10),
                 lang: LangEnum = LangEnum.ENG,
                 log_handlers: [StreamHandler] = None):
        self.logger = getLogger(__name__)
        if log_handlers:
            for h in log_handlers:
                self.logger.addHandler(h)
        self.logger.debug("Initializing")
        super().__init__(parent)
        self.setLayout(QGridLayout())
        self.setMaximumSize(size)
        self._text_edit = QTextEdit()
        self.layout().addWidget(self._text_edit, 0, 1, 1, 1)
        self._post_button = ClickAnimationButton()
        self.layout().addWidget(self._post_button, 1, 1, 1, 1)

        self._strings = dict()
        self.set_lang(lang)
        self._set_button_state()
        self.logger.debug("Initialized")

    def set_lang(self, lang: LangEnum) -> None:
        """
        Set the language of this view item.
        :param lang: The language enum to use.
        :return None:
        """
        self._strings = strings[lang]
        self._set_texts()
        self._set_tooltips()

    def get_note(self):
        return self._text_edit.toPlainText()

    def clear_note(self):
        self.logger.debug("running")
        self._text_edit.clear()
        self.logger.debug("done")

    def set_post_button_enabled(self, is_active):
        self.logger.debug("running")
        self._post_button.setEnabled(is_active)
        self.logger.debug("done")

    def add_post_handler(self, func):
        self.logger.debug("running")
        self._post_button.clicked.connect(func)
        self.logger.debug("done")

    def add_note_box_changed_handler(self, func):
        self.logger.debug("running")
        self._text_edit.textChanged.connect(func)
        self.logger.debug("done")

    def _set_texts(self):
        self.logger.debug("running")
        self.setTitle(self._strings[StringsEnum.TITLE])
        self._post_button.setText(self._strings[StringsEnum.POST])
        self._text_edit.setPlaceholderText(self._strings[StringsEnum.SHADOW])
        self.logger.debug("done")

    def _set_button_state(self):
        self.logger.debug("running")
        self._post_button.setEnabled(False)
        self.logger.debug("done")

    def _set_tooltips(self):
        self.logger.debug("running")
        self._post_button.setToolTip(self._strings[StringsEnum.POST_TT])
        self.logger.debug("done")
Ejemplo n.º 14
0
class ButtonBox(QGroupBox):
    """ This code is to contain the overall controls which govern running experiments. """
    def __init__(self,
                 parent=None,
                 size: QSize = QSize(10, 10),
                 lang: LangEnum = LangEnum.ENG,
                 log_handlers: [StreamHandler] = None):
        self.logger = getLogger(__name__)
        if log_handlers:
            for h in log_handlers:
                self.logger.addHandler(h)
        self.logger.debug("Initializing")
        super().__init__(parent)
        self.setLayout(QVBoxLayout())
        self.setMaximumSize(size)
        self._button_layout = QHBoxLayout()

        self._create_button = ClickAnimationButton()
        self._create_button.setFixedSize(60, 40)
        self._start_button = ClickAnimationButton()
        self._start_button.setFixedSize(120, 40)
        self._button_layout.addWidget(self._create_button)
        self._button_layout.addWidget(self._start_button)
        self._text_entry = QLineEdit()
        self.layout().addLayout(self._button_layout)
        self.layout().addWidget(self._text_entry)

        self._play_icon = QIcon(button_box_start_image_filepath)
        self._pause_icon = QIcon(button_box_pause_image_filepath)

        self._start_button_state = 0
        self._create_button_state = 0
        self._set_button_states()
        self._strings = dict()
        self.set_lang(lang)
        self.logger.debug("Initialized")

    def set_lang(self, lang: LangEnum) -> None:
        """
        Set the language for this view object.
        :param lang: The enum for the language.
        :return None:
        """
        self._strings = strings[lang]
        self._set_texts()
        self._set_tooltips()

    def get_condition_name(self) -> str:
        """
        Return the text from the condition name text entry
        :return: The text from the text entry.
        """
        return self._text_entry.text()

    def add_create_button_handler(self, func: classmethod) -> None:
        """
        Add handler for the create button click event.
        :param func: The handler.
        :return: None.
        """
        self.logger.debug("running")
        self._create_button.clicked.connect(func)
        self.logger.debug("done")

    def add_start_button_handler(self, func: classmethod) -> None:
        """
        Add handler for the start button click event.
        :param func: The handler.
        :return: None.
        """
        self.logger.debug("running")
        self._start_button.clicked.connect(func)
        self.logger.debug("done")

    def add_cond_name_changed_handler(self, func: classmethod) -> None:
        """
        Add handler for when the condition name box text is edited.
        :param func: The handler.
        :return None:
        """
        self.logger.debug("running")
        self._text_entry.textChanged.connect(func)
        self.logger.debug("done")

    def set_condition_name_box_enabled(self, is_active: bool) -> None:
        """
        Set whether this text entry is enabled.
        :param is_active: Whether this button is active.
        :return: None
        """
        self.logger.debug("running")
        self._text_entry.setEnabled(is_active)
        self.logger.debug("done")

    def set_create_button_enabled(self, is_active: bool) -> None:
        """
        Toggle whether this button is active.
        :param is_active: Whether this button is active.
        :return None:
        """
        self._create_button.setEnabled(is_active)

    def set_create_button_state(self, button_state: int) -> None:
        """
        Set create button state to given state. 0: Create. 1: End.
        :param button_state: The state to show on this button.
        :return: None.
        """
        self.logger.debug("running")
        self._create_button_state = button_state
        if button_state == 0:
            self._create_button.setText(self._strings[StringsEnum.CREATE])
            self._create_button.setToolTip(
                self._strings[StringsEnum.CREATE_TT])
        elif button_state == 1:
            self._create_button.setText(self._strings[StringsEnum.END])
            self._create_button.setToolTip(self._strings[StringsEnum.END_TT])
        self.logger.debug("done")

    def set_start_button_enabled(self, is_active: bool) -> None:
        """
        Toggle whether this button is active.
        :param is_active: Whether this button is active.
        :return None:
        """
        self._start_button.setEnabled(is_active)

    def set_start_button_state(self, button_state: int = 0) -> None:
        """
        Set start button state to given state. 0: Start. 1: Pause. 2: Resume.
        :param button_state: The state to show on this button.
        :return: None.
        """
        self.logger.debug("running")
        self._start_button_state = button_state
        if button_state == 0:
            self._start_button.setIcon(self._play_icon)
            self._start_button.setIconSize(QSize(26, 26))
            self._start_button.setToolTip(self._strings[StringsEnum.START_TT])
        elif button_state == 1:
            self._start_button.setIcon(self._pause_icon)
            self._start_button.setIconSize(QSize(36, 36))
            self._start_button.setToolTip(self._strings[StringsEnum.PAUSE_TT])
        elif button_state == 2:
            self._start_button.setIcon(self._play_icon)
            self._start_button.setIconSize(QSize(26, 26))
            self._start_button.setToolTip(self._strings[StringsEnum.RESUME_TT])
        self.logger.debug("done")

    def _set_texts(self) -> None:
        """
        Set the texts of this view item.
        :return: None.
        """
        self.logger.debug("running")
        self.setTitle(self._strings[StringsEnum.TITLE])
        self._text_entry.setPlaceholderText(
            self._strings[StringsEnum.COND_NAME_SHADOW])
        if self._create_button_state == 0:
            self._create_button.setText(self._strings[StringsEnum.CREATE])
        elif self._create_button_state == 1:
            self._create_button.setText(self._strings[StringsEnum.END])
        if self._start_button_state == 0 or self._start_button_state == 2:
            self._start_button.setIcon(self._play_icon)
            self._start_button.setIconSize(QSize(32, 32))
        elif self._start_button_state == 1:
            self._start_button.setIcon(self._pause_icon)
            self._start_button.setIconSize(QSize(36, 36))
        self.logger.debug("done")

    def _set_button_states(self) -> None:
        """
        Set default button states.
        :return: None.
        """
        self.logger.debug("running")
        self._start_button.setEnabled(False)
        self.logger.debug("done")

    def _set_tooltips(self) -> None:
        """
        Set the text for the tooltips in this view item.
        :return: None.
        """
        self.logger.debug("running")
        if self._create_button_state == 0:
            self._create_button.setToolTip(
                self._strings[StringsEnum.CREATE_TT])
        if self._create_button_state == 1:
            self._create_button.setToolTip(self._strings[StringsEnum.END_TT])
        if self._start_button_state == 0:
            self._start_button.setToolTip(self._strings[StringsEnum.START_TT])
        elif self._start_button_state == 1:
            self._start_button.setToolTip(self._strings[StringsEnum.PAUSE_TT])
        elif self._start_button_state == 2:
            self._start_button.setToolTip(self._strings[StringsEnum.RESUME_TT])
        self.logger.debug("done")
Ejemplo n.º 15
0
class MainWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        self.setFixedSize(300, 200)
        self.setCentralWidget(CentralWidget(self))
        self.myLayout = QHBoxLayout(self)

        # set this to desired file location and name
        self.file = "W:\\stuff\\file.wav"

        self.rec_button = ClickAnimationButton()
        self.rec_button.setText("record")
        self.rec_button.clicked.connect(self.record_audio)

        self.devs_button = ClickAnimationButton()
        self.devs_button.setText("input devices")
        self.devs_button.clicked.connect(self.input_devices)

        self.play_button = ClickAnimationButton()
        self.play_button.setText("play")
        self.play_button.clicked.connect(self.play_audio)

        self.myLayout.addWidget(self.rec_button)
        self.myLayout.addWidget(self.devs_button)
        self.myLayout.addWidget(self.play_button)

        self.centralWidget().layout().addLayout(self.myLayout)

    def play_file(self, file):
        # plays a file given from the command line
        print("Plays a wave file from: %s" % file)

        wf = wave.open(file, 'rb')

        # instantiate PyAudio (1)
        p = pyaudio.PyAudio()

        print("done with 1")

        # define callback (2)
        def callback(in_data, frame_count, time_info, status):
            data = wf.readframes(frame_count)
            return (data, pyaudio.paContinue)

        print("done with 2")

        # open stream using callback (3)
        stream = p.open(format=p.get_format_from_width(wf.getsampwidth()),
                        channels=wf.getnchannels(),
                        rate=wf.getframerate(),
                        output=True,
                        stream_callback=callback)

        print("done with 3")

        # start the stream (4)
        stream.start_stream()

        print("done with 4")

        # wait for stream to finish (5)
        while stream.is_active():
            time.sleep(0.1)

        print("done with 5")

        # stop stream (6)
        stream.stop_stream()
        stream.close()
        wf.close()

        print("done with 6")

        # close PyAudio (7)
        p.terminate()

        print("done with 7")

    def record_file(self, file):
        # records audio, and saves it to FILENAME
        FORMAT = pyaudio.paInt16
        CHANNELS = 2
        RATE = 44100
        CHUNK = 1024
        RECORD_SECONDS = 10
        # this is a specific path.
        # change if running on a different machine.
        FILENAME = file

        print("recording to:", FILENAME)

        p = pyaudio.PyAudio()

        # start recording
        stream = p.open(format=FORMAT,
                        channels=CHANNELS,
                        rate=RATE,
                        input=True,
                        frames_per_buffer=CHUNK)

        frames = []

        print(p.get_default_input_device_info())

        print("\nrecording\n")

        # saves audio to frames
        for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
            data = stream.read(CHUNK)
            frames.append(data)

        print("finished recording")

        # stop recording
        stream.stop_stream()
        stream.close()
        p.terminate()

        waveFile = wave.open(FILENAME, 'wb')
        waveFile.setnchannels(CHANNELS)
        waveFile.setsampwidth(p.get_sample_size(FORMAT))
        waveFile.setframerate(RATE)
        waveFile.writeframes(b''.join(frames))
        waveFile.close()

    def input_devices(self):
        retVals = []
        p = pyaudio.PyAudio()

        # print out available mic devices
        for i in range(p.get_device_count()):
            device = p.get_device_info_by_index(i)
            input_ch = device.get('maxInputChannels', 0)
            if input_ch > 0:
                name = device.get('name')
                rate = device.get('defaultSampleRate')
                val = "index {i}: {name} (max channels {input_ch}, Default @ {rate} Hz)".format(
                    i=i, name=name, input_ch=input_ch, rate=int(rate))
                print(val)
                retVals.append(val)
        return retVals

    def record_audio(self):
        self.record_file(self.file)

    def play_audio(self):
        self.play_file(self.file)