class UIMainDialog():
    """UI dialog + widgets definition"""
    def setup_ui(self, main_dialog):
        """Initializes the UI"""

        main_dialog.setObjectName("main_dialog")
        main_dialog.resize(395, 284)
        main_dialog.setStyleSheet(STYLE)

        self.target_path_line_edit = QLineEdit(main_dialog)
        self.target_path_line_edit.setGeometry(QRect(10, 10, 291, 20))
        self.target_path_line_edit.setObjectName("target_path_line_edit")

        self.browse_path_btn = QPushButton(main_dialog)
        self.browse_path_btn.setGeometry(QRect(310, 9, 75, 23))
        self.browse_path_btn.setFocusPolicy(Qt.NoFocus)
        self.browse_path_btn.setObjectName("browse_path_btn")

        self.prefix_chk = QCheckBox(main_dialog)
        self.prefix_chk.setGeometry(QRect(10, 43, 70, 17))
        self.prefix_chk.setFocusPolicy(Qt.NoFocus)
        self.prefix_chk.setObjectName("prefix_chk")

        self.prefix_line_edit = QLineEdit(main_dialog)
        self.prefix_line_edit.setEnabled(False)
        self.prefix_line_edit.setGeometry(QRect(90, 42, 294, 20))
        self.prefix_line_edit.setObjectName("prefix_line_edit")

        self.suff_chk = QCheckBox(main_dialog)
        self.suff_chk.setGeometry(QRect(10, 71, 70, 17))
        self.suff_chk.setFocusPolicy(Qt.NoFocus)
        self.suff_chk.setObjectName("suff_chk")

        self.suff_line_edit = QLineEdit(main_dialog)
        self.suff_line_edit.setEnabled(False)
        self.suff_line_edit.setGeometry(QRect(90, 70, 294, 20))
        self.suff_line_edit.setObjectName("suff_line_edit")

        self.rename_chk = QCheckBox(main_dialog)
        self.rename_chk.setGeometry(QRect(10, 101, 70, 17))
        self.rename_chk.setFocusPolicy(Qt.NoFocus)
        self.rename_chk.setChecked(True)
        self.rename_chk.setObjectName("rename_chk")

        self.rename_old_line_edit = QLineEdit(main_dialog)
        self.rename_old_line_edit.setEnabled(True)
        self.rename_old_line_edit.setGeometry(QRect(90, 100, 140, 20))
        self.rename_old_line_edit.setObjectName("rename_old_line_edit")

        self.rename_new_line_edit = QLineEdit(main_dialog)
        self.rename_new_line_edit.setEnabled(True)
        self.rename_new_line_edit.setGeometry(QRect(242, 100, 141, 20))
        self.rename_new_line_edit.setObjectName("rename_new_line_edit")

        self.ext_chk = QCheckBox(main_dialog)
        self.ext_chk.setGeometry(QRect(10, 131, 110, 17))
        self.ext_chk.setFocusPolicy(Qt.NoFocus)
        self.ext_chk.setObjectName("ext_chk")

        self.ext_line_edit = QLineEdit(main_dialog)
        self.ext_line_edit.setEnabled(False)
        self.ext_line_edit.setGeometry(QRect(133, 130, 251, 20))
        self.ext_line_edit.setObjectName("ext_line_edit")

        self.include_subdir_chk = QCheckBox(main_dialog)
        self.include_subdir_chk.setGeometry(QRect(134, 170, 128, 17))
        self.include_subdir_chk.setFocusPolicy(Qt.NoFocus)
        self.include_subdir_chk.setObjectName("include_subdir_chk")

        self.prev_file_name_title_label = QLabel(main_dialog)
        self.prev_file_name_title_label.setGeometry(QRect(20, 201, 90, 13))
        self.prev_file_name_title_label.setObjectName(
            "prev_file_name_title_label")

        self.prev_file_name_label = QLabel(main_dialog)
        self.prev_file_name_label.setGeometry(QRect(124, 201, 260, 13))
        self.prev_file_name_label.setObjectName("prev_file_name_label")

        self.rename_files_btn = QPushButton(main_dialog)
        self.rename_files_btn.setGeometry(QRect(156, 230, 91, 41))
        self.rename_files_btn.setFocusPolicy(Qt.NoFocus)
        self.rename_files_btn.setObjectName("rename_files_btn")

        self.view_log_btn = QPushButton(main_dialog)
        self.view_log_btn.setGeometry(QRect(310, 255, 75, 23))
        self.view_log_btn.setFocusPolicy(Qt.NoFocus)
        self.view_log_btn.setObjectName("view_log_btn")

        self.retranslate_ui(main_dialog)
        QMetaObject.connectSlotsByName(main_dialog)

    def retranslate_ui(self, main_dialog):
        """Initializes widget texts"""

        main_dialog.setWindowTitle(
            QApplication.translate("main_dialog", "Easy File Renamer", None,
                                   -1))

        self.target_path_line_edit.setToolTip(
            QApplication.translate("main_dialog",
                                   "Target directory containing the files",
                                   None, -1))
        self.target_path_line_edit.setPlaceholderText(
            QApplication.translate("main_dialog", "Target directory", None,
                                   -1))

        self.browse_path_btn.setToolTip(
            QApplication.translate("main_dialog", "Browse target directory",
                                   None, -1))
        self.browse_path_btn.setText(
            QApplication.translate("main_dialog", "Browse", None, -1))

        self.prefix_chk.setToolTip(
            QApplication.translate("main_dialog",
                                   "If checked, adds a prefix to file names",
                                   None, -1))
        self.prefix_chk.setText(
            QApplication.translate("main_dialog", "Add Prefix", None, -1))

        self.prefix_line_edit.setToolTip(
            QApplication.translate("main_dialog", "Desired prefix", None, -1))
        self.prefix_line_edit.setPlaceholderText(
            QApplication.translate("main_dialog", "PREF_", None, -1))

        self.suff_chk.setToolTip(
            QApplication.translate("main_dialog",
                                   "If checked, adds a suffix to file names",
                                   None, -1))
        self.suff_chk.setText(
            QApplication.translate("main_dialog", "Add Suffix", None, -1))

        self.suff_line_edit.setToolTip(
            QApplication.translate("main_dialog", "Desired suffix", None, -1))
        self.suff_line_edit.setPlaceholderText(
            QApplication.translate("main_dialog", "_SUFF", None, -1))

        self.rename_chk.setToolTip(
            QApplication.translate(
                "main_dialog",
                "If checked, it replaces the provided old name with the new name on file names",
                None, -1))
        self.rename_chk.setText(
            QApplication.translate("main_dialog", "Rename", None, -1))

        self.rename_old_line_edit.setToolTip(
            QApplication.translate("main_dialog",
                                   "Old name to replace on file names", None,
                                   -1))
        self.rename_old_line_edit.setPlaceholderText(
            QApplication.translate("main_dialog", "Old name", None, -1))

        self.rename_new_line_edit.setToolTip(
            QApplication.translate("main_dialog",
                                   "New name to replace on file names", None,
                                   -1))
        self.rename_new_line_edit.setPlaceholderText(
            QApplication.translate("main_dialog", "New name", None, -1))

        self.ext_chk.setToolTip(
            QApplication.translate("main_dialog",
                                   "If checked, changes file extension", None,
                                   -1))
        self.ext_chk.setText(
            QApplication.translate("main_dialog", "Change extension", None,
                                   -1))

        self.ext_line_edit.setToolTip(
            QApplication.translate("main_dialog",
                                   "New file extension (without dot)", None,
                                   -1))
        self.ext_line_edit.setPlaceholderText(
            QApplication.translate("main_dialog", "ext (No dot)", None, -1))

        self.include_subdir_chk.setToolTip(
            QApplication.translate(
                "main_dialog", "If checked, it includes files in sub-folders",
                None, -1))
        self.include_subdir_chk.setText(
            QApplication.translate("main_dialog", "Include subdirectories",
                                   None, -1))

        self.prev_file_name_title_label.setText(
            QApplication.translate("main_dialog", "File name preview:", None,
                                   -1))
        self.prev_file_name_label.setText(
            QApplication.translate("main_dialog", "Please input a directory",
                                   None, -1))

        self.rename_files_btn.setText(
            QApplication.translate("main_dialog", "Rename Files", None, -1))

        self.view_log_btn.setToolTip(
            QApplication.translate("main_dialog", "View application's log",
                                   None, -1))
        self.view_log_btn.setText(
            QApplication.translate("main_dialog", "View log", None, -1))
Exemple #2
0
class Prescreen(QWidget):
    REASONS = ('Inattentive', 'Child Talking', 'Parent Talking',
               'Parent Interference', 'Child Not Looking Before Sound',
               'Equipment Malfunction', 'Experiment Ended Early', 'Other')

    def __init__(self, callback):
        super().__init__()
        self.callback = callback

        trial_label = QLabel('Trial:')
        self.trial_box = QSpinBox()
        self.trial_box.setFixedWidth(64)
        self.trial_box.setValue(1)
        # self.trial_box.setFocusPolicy(Qt.NoFocus)

        reason_label = QLabel('Reason:')
        self.reason_box = QComboBox()
        self.reason_box.addItems(self.REASONS)
        self.reason_box.setFocusPolicy(Qt.NoFocus)

        self.code_radio = QRadioButton('Code')
        self.nocode_radio = QRadioButton('Do Not Code')
        self.code_radio.setChecked(True)
        self.code_radio.setFocusPolicy(Qt.NoFocus)
        self.nocode_radio.setFocusPolicy(Qt.NoFocus)

        radio_layout = QVBoxLayout()
        radio_layout.addStretch()
        radio_layout.addWidget(self.code_radio)
        radio_layout.addWidget(self.nocode_radio)
        radio_layout.addStretch()
        self.group_code = QButtonGroup()
        self.group_code.addButton(self.code_radio)
        self.group_code.addButton(self.nocode_radio)

        self.record_button = QPushButton('Record Reason')
        self.record_button.clicked.connect(self.record_reason)
        self.record_button.setEnabled(False)
        self.record_button.setFocusPolicy(Qt.NoFocus)

        self.both_checkbox = QCheckBox('Display both coders')
        self.both_checkbox.setFocusPolicy(Qt.NoFocus)
        self.radio_primary = QRadioButton('Primary')
        self.radio_secondary = QRadioButton('Secondary')
        self.radio_primary.setChecked(True)
        self.radio_primary.setFocusPolicy(Qt.NoFocus)
        self.radio_secondary.setFocusPolicy(Qt.NoFocus)
        who_layout = QVBoxLayout()
        who_layout.addWidget(self.both_checkbox)
        who_layout.addWidget(self.radio_primary)
        who_layout.addWidget(self.radio_secondary)
        self.group_who = QButtonGroup()
        self.group_who.addButton(self.radio_primary, id=1)
        self.group_who.addButton(self.radio_secondary, id=2)

        layout = QHBoxLayout()
        layout.addWidget(trial_label)
        layout.addWidget(self.trial_box)
        layout.addWidget(reason_label)
        layout.addWidget(self.reason_box)
        layout.addLayout(radio_layout)

        layout.addWidget(self.record_button)
        layout.addStretch()
        layout.addLayout(who_layout)

        self.setLayout(layout)

    def record_reason(self):
        reason = Reason(trial=self.trial_box.value(),
                        include=self.code_radio.isChecked(),
                        reason=self.reason_box.currentText())
        self.callback(reason)

    def prescreener(self):
        if self.both_checkbox.isChecked():
            return 0
        else:
            return self.group_who.checkedId()