Exemplo n.º 1
0
    def createNotificationPopup(self):
        popup = QDialog(self)
        popup.setFixedSize(popup.sizeHint().height(), popup.sizeHint().width())
        popup.setWindowTitle("Évènements")
        innerLayout = QVBoxLayout()

        GroupBox = QGroupBox("Activer les notifications")
        GroupBox.setCheckable(True)
        GroupBox.setChecked(self.notification)

        checkBox_popup = QCheckBox("Afficher une popup")
        checkBox_notification = QCheckBox("Afficher une notification")
        checkBox_sound = QCheckBox("Jouer un son")

        if self.notification_popup:
            checkBox_popup.setCheckState(Qt.Checked)
        if self.notification_tray:
            checkBox_notification.setCheckState(Qt.Checked)
        if self.notification_sound:
            checkBox_sound.setCheckState(Qt.Checked)

        innerLayout.addWidget(checkBox_popup)
        innerLayout.addWidget(checkBox_notification)
        innerLayout.addWidget(checkBox_sound)
        innerLayout.addStretch(1)
        GroupBox.setLayout(innerLayout)

        button = QPushButton("Ok")
        button.clicked.connect(lambda: self.changeNotificationSettings(
            popup, GroupBox, checkBox_popup, checkBox_notification,
            checkBox_sound))

        outerLayout = QVBoxLayout()
        outerLayout.addWidget(GroupBox)
        outerLayout.addWidget(button)
        popup.setLayout(outerLayout)

        popup.exec_()
Exemplo n.º 2
0
class WidgetGallery(QDialog):
    def __init__(self, parent=None):
        super(WidgetGallery, self).__init__(parent)

        self.originalPalette = QApplication.palette()

        styleComboBox = QComboBox()
        styleComboBox.addItems(QStyleFactory.keys())

        styleLabel = QLabel("&Style:")
        styleLabel.setBuddy(styleComboBox)

        self.useStylePaletteCheckBox = QCheckBox(
            "&Use style's standard palette")
        self.useStylePaletteCheckBox.setChecked(True)

        disableWidgetsCheckBox = QCheckBox("&Disable widgets")

        self.createTopLeftGroupBox()
        self.createTopRightGroupBox()
        self.createBottomLeftTabWidget()
        self.createBottomRightGroupBox()
        self.createProgressBar()

        styleComboBox.activated[str].connect(self.changeStyle)
        self.useStylePaletteCheckBox.toggled.connect(self.changePalette)
        disableWidgetsCheckBox.toggled.connect(
            self.topLeftGroupBox.setDisabled)
        disableWidgetsCheckBox.toggled.connect(
            self.topRightGroupBox.setDisabled)
        disableWidgetsCheckBox.toggled.connect(
            self.bottomLeftTabWidget.setDisabled)
        disableWidgetsCheckBox.toggled.connect(
            self.bottomRightGroupBox.setDisabled)

        topLayout = QHBoxLayout()
        topLayout.addWidget(styleLabel)
        topLayout.addWidget(styleComboBox)
        topLayout.addStretch(1)
        topLayout.addWidget(self.useStylePaletteCheckBox)
        topLayout.addWidget(disableWidgetsCheckBox)

        mainLayout = QGridLayout()
        mainLayout.addLayout(topLayout, 0, 0, 1, 2)
        mainLayout.addWidget(self.topLeftGroupBox, 1, 0)
        mainLayout.addWidget(self.topRightGroupBox, 1, 1)
        mainLayout.addWidget(self.bottomLeftTabWidget, 2, 0)
        mainLayout.addWidget(self.bottomRightGroupBox, 2, 1)
        mainLayout.addWidget(self.progressBar, 3, 0, 1, 2)
        mainLayout.setRowStretch(1, 1)
        mainLayout.setRowStretch(2, 1)
        mainLayout.setColumnStretch(0, 1)
        mainLayout.setColumnStretch(1, 1)
        self.setLayout(mainLayout)

        self.setWindowTitle("Common Qt Widgets")
        self.changeStyle('Fusion')

    def changeStyle(self, styleName):
        QApplication.setStyle(styleName)
        self.changePalette()

    def changePalette(self):
        if (self.useStylePaletteCheckBox.isChecked()):
            QApplication.setPalette(QApplication.style().standardPalette())
        else:
            QApplication.setPalette(self.originalPalette)

    def advanceProgressBar(self):
        curVal = self.progressBar.value()
        maxVal = self.progressBar.maximum()
        self.progressBar.setValue(curVal + (maxVal - curVal) / 100)

    def createTopLeftGroupBox(self):
        self.topLeftGroupBox = QGroupBox("Group 1")

        radioButton1 = QRadioButton("Radio button 1")
        radioButton2 = QRadioButton("Radio button 2")
        radioButton3 = QRadioButton("Radio button 3")
        radioButton1.setChecked(True)

        checkBox = QCheckBox("Tri-state check box")
        checkBox.setTristate(True)
        checkBox.setCheckState(Qt.PartiallyChecked)

        layout = QVBoxLayout()
        layout.addWidget(radioButton1)
        layout.addWidget(radioButton2)
        layout.addWidget(radioButton3)
        layout.addWidget(checkBox)
        layout.addStretch(1)
        self.topLeftGroupBox.setLayout(layout)

    def createTopRightGroupBox(self):
        self.topRightGroupBox = QGroupBox("Group 2")

        defaultPushButton = QPushButton("Default Push Button")
        defaultPushButton.setDefault(True)

        togglePushButton = QPushButton("Toggle Push Button")
        togglePushButton.setCheckable(True)
        togglePushButton.setChecked(True)

        flatPushButton = QPushButton("Flat Push Button")
        flatPushButton.setFlat(True)

        layout = QVBoxLayout()
        layout.addWidget(defaultPushButton)
        layout.addWidget(togglePushButton)
        layout.addWidget(flatPushButton)
        layout.addStretch(1)
        self.topRightGroupBox.setLayout(layout)

    def createBottomLeftTabWidget(self):
        self.bottomLeftTabWidget = QTabWidget()
        self.bottomLeftTabWidget.setSizePolicy(QSizePolicy.Preferred,
                                               QSizePolicy.Ignored)

        tab1 = QWidget()
        tableWidget = QTableWidget(10, 10)

        tab1hbox = QHBoxLayout()
        tab1hbox.setContentsMargins(5, 5, 5, 5)
        tab1hbox.addWidget(tableWidget)
        tab1.setLayout(tab1hbox)

        tab2 = QWidget()
        textEdit = QTextEdit()

        textEdit.setPlainText("Twinkle, twinkle, little star,\n"
                              "How I wonder what you are.\n"
                              "Up above the world so high,\n"
                              "Like a diamond in the sky.\n"
                              "Twinkle, twinkle, little star,\n"
                              "How I wonder what you are!\n")

        tab2hbox = QHBoxLayout()
        tab2hbox.setContentsMargins(5, 5, 5, 5)
        tab2hbox.addWidget(textEdit)
        tab2.setLayout(tab2hbox)

        self.bottomLeftTabWidget.addTab(tab1, "&Table")
        self.bottomLeftTabWidget.addTab(tab2, "Text &Edit")

    def createBottomRightGroupBox(self):
        self.bottomRightGroupBox = QGroupBox("Group 3")
        self.bottomRightGroupBox.setCheckable(True)
        self.bottomRightGroupBox.setChecked(True)

        lineEdit = QLineEdit('s3cRe7')
        lineEdit.setEchoMode(QLineEdit.Password)

        spinBox = QSpinBox(self.bottomRightGroupBox)
        spinBox.setValue(50)

        dateTimeEdit = QDateTimeEdit(self.bottomRightGroupBox)
        dateTimeEdit.setDateTime(QDateTime.currentDateTime())

        slider = QSlider(Qt.Horizontal, self.bottomRightGroupBox)
        slider.setValue(40)

        scrollBar = QScrollBar(Qt.Horizontal, self.bottomRightGroupBox)
        scrollBar.setValue(60)

        dial = QDial(self.bottomRightGroupBox)
        dial.setValue(30)
        dial.setNotchesVisible(True)

        layout = QGridLayout()
        layout.addWidget(lineEdit, 0, 0, 1, 2)
        layout.addWidget(spinBox, 1, 0, 1, 2)
        layout.addWidget(dateTimeEdit, 2, 0, 1, 2)
        layout.addWidget(slider, 3, 0)
        layout.addWidget(scrollBar, 4, 0)
        layout.addWidget(dial, 3, 1, 2, 1)
        layout.setRowStretch(5, 1)
        self.bottomRightGroupBox.setLayout(layout)

    def createProgressBar(self):
        self.progressBar = QProgressBar()
        self.progressBar.setRange(0, 10000)
        self.progressBar.setValue(0)

        timer = QTimer(self)
        timer.timeout.connect(self.advanceProgressBar)
        timer.start(1000)
Exemplo n.º 3
0
class Ui_GroupBox(object):
    def setupUi(self, GroupBox):
        if not GroupBox.objectName():
            GroupBox.setObjectName(u"GroupBox")
        GroupBox.resize(528, 576)
        sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Minimum)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(GroupBox.sizePolicy().hasHeightForWidth())
        GroupBox.setSizePolicy(sizePolicy)
        self.verticalLayout_2 = QVBoxLayout(GroupBox)
        self.verticalLayout_2.setObjectName(u"verticalLayout_2")
        self.groupBox = QGroupBox(GroupBox)
        self.groupBox.setObjectName(u"groupBox")
        self.verticalLayout_4 = QVBoxLayout(self.groupBox)
        self.verticalLayout_4.setObjectName(u"verticalLayout_4")
        self.horizontalLayout_7 = QHBoxLayout()
        self.horizontalLayout_7.setObjectName(u"horizontalLayout_7")
        self.horizontalSpacer_7 = QSpacerItem(40, 20, QSizePolicy.Expanding,
                                              QSizePolicy.Minimum)

        self.horizontalLayout_7.addItem(self.horizontalSpacer_7)

        self.pushButton_degree_save = QPushButton(self.groupBox)
        self.pushButton_degree_save.setObjectName(u"pushButton_degree_save")

        self.horizontalLayout_7.addWidget(self.pushButton_degree_save)

        self.verticalLayout_4.addLayout(self.horizontalLayout_7)

        self.verticalLayout_2.addWidget(self.groupBox)

        self.verticalSpacer_2 = QSpacerItem(20, 40, QSizePolicy.Minimum,
                                            QSizePolicy.Expanding)

        self.verticalLayout_2.addItem(self.verticalSpacer_2)

        self.groupBox_degree = QGroupBox(GroupBox)
        self.groupBox_degree.setObjectName(u"groupBox_degree")
        self.verticalLayout_3 = QVBoxLayout(self.groupBox_degree)
        self.verticalLayout_3.setObjectName(u"verticalLayout_3")
        self.horizontalLayout_2 = QHBoxLayout()
        self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
        self.radioButton_betweenness = QRadioButton(self.groupBox_degree)
        self.radioButton_betweenness.setObjectName(u"radioButton_betweenness")

        self.horizontalLayout_2.addWidget(self.radioButton_betweenness)

        self.radioButton_degree = QRadioButton(self.groupBox_degree)
        self.radioButton_degree.setObjectName(u"radioButton_degree")
        self.radioButton_degree.setChecked(True)

        self.horizontalLayout_2.addWidget(self.radioButton_degree)

        self.horizontalSpacer_5 = QSpacerItem(40, 20, QSizePolicy.Expanding,
                                              QSizePolicy.Minimum)

        self.horizontalLayout_2.addItem(self.horizontalSpacer_5)

        self.verticalLayout_3.addLayout(self.horizontalLayout_2)

        self.checkBox_averaged_frames = QCheckBox(self.groupBox_degree)
        self.checkBox_averaged_frames.setObjectName(
            u"checkBox_averaged_frames")
        self.checkBox_averaged_frames.setChecked(True)

        self.verticalLayout_3.addWidget(self.checkBox_averaged_frames)

        self.checkBox_normalized = QCheckBox(self.groupBox_degree)
        self.checkBox_normalized.setObjectName(u"checkBox_normalized")

        self.verticalLayout_3.addWidget(self.checkBox_normalized)

        self.groupBox_per_residue = QGroupBox(self.groupBox_degree)
        self.groupBox_per_residue.setObjectName(u"groupBox_per_residue")
        self.groupBox_per_residue.setCheckable(True)
        self.verticalLayout = QVBoxLayout(self.groupBox_per_residue)
        self.verticalLayout.setObjectName(u"verticalLayout")
        self.horizontalLayout_6 = QHBoxLayout()
        self.horizontalLayout_6.setObjectName(u"horizontalLayout_6")
        self.label_2 = QLabel(self.groupBox_per_residue)
        self.label_2.setObjectName(u"label_2")

        self.horizontalLayout_6.addWidget(self.label_2)

        self.comboBox = QComboBox(self.groupBox_per_residue)
        self.comboBox.setObjectName(u"comboBox")

        self.horizontalLayout_6.addWidget(self.comboBox)

        self.horizontalSpacer_2 = QSpacerItem(40, 20, QSizePolicy.Expanding,
                                              QSizePolicy.Minimum)

        self.horizontalLayout_6.addItem(self.horizontalSpacer_2)

        self.verticalLayout.addLayout(self.horizontalLayout_6)

        self.horizontalLayout = QHBoxLayout()
        self.horizontalLayout.setObjectName(u"horizontalLayout")
        self.label_10 = QLabel(self.groupBox_per_residue)
        self.label_10.setObjectName(u"label_10")
        self.label_10.setAlignment(Qt.AlignRight | Qt.AlignTrailing
                                   | Qt.AlignVCenter)

        self.horizontalLayout.addWidget(self.label_10)

        self.lineEdit_degree_residue_ids = QLineEdit(self.groupBox_per_residue)
        self.lineEdit_degree_residue_ids.setObjectName(
            u"lineEdit_degree_residue_ids")

        self.horizontalLayout.addWidget(self.lineEdit_degree_residue_ids)

        self.horizontalSpacer_6 = QSpacerItem(40, 20, QSizePolicy.Expanding,
                                              QSizePolicy.Minimum)

        self.horizontalLayout.addItem(self.horizontalSpacer_6)

        self.verticalLayout.addLayout(self.horizontalLayout)

        self.verticalLayout_3.addWidget(self.groupBox_per_residue)

        self.groupBox_histogram = QGroupBox(self.groupBox_degree)
        self.groupBox_histogram.setObjectName(u"groupBox_histogram")
        self.groupBox_histogram.setCheckable(True)
        self.groupBox_histogram.setChecked(False)
        self.verticalLayout_5 = QVBoxLayout(self.groupBox_histogram)
        self.verticalLayout_5.setObjectName(u"verticalLayout_5")
        self.horizontalLayout_3 = QHBoxLayout()
        self.horizontalLayout_3.setObjectName(u"horizontalLayout_3")
        self.label_56 = QLabel(self.groupBox_histogram)
        self.label_56.setObjectName(u"label_56")
        self.label_56.setMaximumSize(QSize(16777215, 16777215))
        self.label_56.setAlignment(Qt.AlignRight | Qt.AlignTrailing
                                   | Qt.AlignVCenter)

        self.horizontalLayout_3.addWidget(self.label_56)

        self.lineEdit_bins = QLineEdit(self.groupBox_histogram)
        self.lineEdit_bins.setObjectName(u"lineEdit_bins")
        self.lineEdit_bins.setMinimumSize(QSize(50, 0))
        self.lineEdit_bins.setMaximumSize(QSize(50, 16777215))

        self.horizontalLayout_3.addWidget(self.lineEdit_bins)

        self.label_55 = QLabel(self.groupBox_histogram)
        self.label_55.setObjectName(u"label_55")
        self.label_55.setMaximumSize(QSize(16777215, 16777215))
        self.label_55.setAlignment(Qt.AlignRight | Qt.AlignTrailing
                                   | Qt.AlignVCenter)

        self.horizontalLayout_3.addWidget(self.label_55)

        self.lineEdit_minimum = QLineEdit(self.groupBox_histogram)
        self.lineEdit_minimum.setObjectName(u"lineEdit_minimum")
        self.lineEdit_minimum.setMinimumSize(QSize(50, 0))
        self.lineEdit_minimum.setMaximumSize(QSize(50, 16777215))

        self.horizontalLayout_3.addWidget(self.lineEdit_minimum)

        self.label_17 = QLabel(self.groupBox_histogram)
        self.label_17.setObjectName(u"label_17")
        self.label_17.setAlignment(Qt.AlignRight | Qt.AlignTrailing
                                   | Qt.AlignVCenter)

        self.horizontalLayout_3.addWidget(self.label_17)

        self.lineEdit_maximum = QLineEdit(self.groupBox_histogram)
        self.lineEdit_maximum.setObjectName(u"lineEdit_maximum")
        self.lineEdit_maximum.setMinimumSize(QSize(50, 0))
        self.lineEdit_maximum.setMaximumSize(QSize(50, 16777215))

        self.horizontalLayout_3.addWidget(self.lineEdit_maximum)

        self.horizontalSpacer_3 = QSpacerItem(40, 20, QSizePolicy.Expanding,
                                              QSizePolicy.Minimum)

        self.horizontalLayout_3.addItem(self.horizontalSpacer_3)

        self.verticalLayout_5.addLayout(self.horizontalLayout_3)

        self.horizontalLayout_8 = QHBoxLayout()
        self.horizontalLayout_8.setObjectName(u"horizontalLayout_8")
        self.checkBox_cumulative_histogram = QCheckBox(self.groupBox_histogram)
        self.checkBox_cumulative_histogram.setObjectName(
            u"checkBox_cumulative_histogram")

        self.horizontalLayout_8.addWidget(self.checkBox_cumulative_histogram)

        self.horizontalSpacer_12 = QSpacerItem(40, 20, QSizePolicy.Fixed,
                                               QSizePolicy.Minimum)

        self.horizontalLayout_8.addItem(self.horizontalSpacer_12)

        self.checkBox_stacked_histogram = QCheckBox(self.groupBox_histogram)
        self.checkBox_stacked_histogram.setObjectName(
            u"checkBox_stacked_histogram")

        self.horizontalLayout_8.addWidget(self.checkBox_stacked_histogram)

        self.horizontalSpacer_11 = QSpacerItem(40, 20, QSizePolicy.Expanding,
                                               QSizePolicy.Minimum)

        self.horizontalLayout_8.addItem(self.horizontalSpacer_11)

        self.verticalLayout_5.addLayout(self.horizontalLayout_8)

        self.horizontalLayout_9 = QHBoxLayout()
        self.horizontalLayout_9.setObjectName(u"horizontalLayout_9")
        self.checkBox_color_segments_occupancy = QCheckBox(
            self.groupBox_histogram)
        self.checkBox_color_segments_occupancy.setObjectName(
            u"checkBox_color_segments_occupancy")
        self.checkBox_color_segments_occupancy.setChecked(True)

        self.horizontalLayout_9.addWidget(
            self.checkBox_color_segments_occupancy)

        self.horizontalSpacer_9 = QSpacerItem(40, 20, QSizePolicy.Expanding,
                                              QSizePolicy.Minimum)

        self.horizontalLayout_9.addItem(self.horizontalSpacer_9)

        self.verticalLayout_5.addLayout(self.horizontalLayout_9)

        self.verticalLayout_3.addWidget(self.groupBox_histogram)

        self.horizontalLayout_5 = QHBoxLayout()
        self.horizontalLayout_5.setObjectName(u"horizontalLayout_5")
        self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding,
                                            QSizePolicy.Minimum)

        self.horizontalLayout_5.addItem(self.horizontalSpacer)

        self.pushButton_degree_plot = QPushButton(self.groupBox_degree)
        self.pushButton_degree_plot.setObjectName(u"pushButton_degree_plot")
        self.pushButton_degree_plot.setAutoDefault(False)

        self.horizontalLayout_5.addWidget(self.pushButton_degree_plot)

        self.verticalLayout_3.addLayout(self.horizontalLayout_5)

        self.verticalLayout_2.addWidget(self.groupBox_degree)

        self.retranslateUi(GroupBox)

        QMetaObject.connectSlotsByName(GroupBox)

    # setupUi

    def retranslateUi(self, GroupBox):
        GroupBox.setWindowTitle(
            QCoreApplication.translate("GroupBox", u"GroupBox", None))
        self.groupBox.setTitle(
            QCoreApplication.translate("GroupBox", u"All centrality measures",
                                       None))
        self.pushButton_degree_save.setText(
            QCoreApplication.translate("GroupBox", u"Data", None))
        self.groupBox_degree.setTitle(
            QCoreApplication.translate("GroupBox", u"Plots", None))
        self.radioButton_betweenness.setText(
            QCoreApplication.translate("GroupBox", u"betweenness centrality",
                                       None))
        self.radioButton_degree.setText(
            QCoreApplication.translate("GroupBox", u"degree centrality", None))
        #if QT_CONFIG(tooltip)
        self.checkBox_averaged_frames.setToolTip(
            QCoreApplication.translate(
                "GroupBox",
                u"<html><head/><body><p align=\"justify\">Toggle, if absolute number of connections or time averaged number of connections are used.</p></body></html>",
                None))
        #endif // QT_CONFIG(tooltip)
        self.checkBox_averaged_frames.setText(
            QCoreApplication.translate("GroupBox", u"average across frames",
                                       None))
        self.checkBox_normalized.setText(
            QCoreApplication.translate("GroupBox", u"normalized", None))
        self.groupBox_per_residue.setTitle(
            QCoreApplication.translate("GroupBox", u"Per Residue", None))
        self.label_2.setText(
            QCoreApplication.translate("GroupBox", u"segment: ", None))
        self.label_10.setText(
            QCoreApplication.translate("GroupBox", u"residue ids: ", None))
        self.lineEdit_degree_residue_ids.setPlaceholderText(
            QCoreApplication.translate("GroupBox", u"e.g. 0-12, 20, 70-90",
                                       None))
        self.groupBox_histogram.setTitle(
            QCoreApplication.translate("GroupBox", u"Histogram", None))
        self.label_56.setText(
            QCoreApplication.translate("GroupBox", u"# of bins", None))
        self.lineEdit_bins.setText(
            QCoreApplication.translate("GroupBox", u"10", None))
        self.label_55.setText(
            QCoreApplication.translate("GroupBox", u"min. value", None))
        self.lineEdit_minimum.setText(
            QCoreApplication.translate("GroupBox", u"0.0", None))
        self.label_17.setText(
            QCoreApplication.translate("GroupBox", u"max. value", None))
        self.lineEdit_maximum.setText(
            QCoreApplication.translate("GroupBox", u"1.0", None))
        self.checkBox_cumulative_histogram.setText(
            QCoreApplication.translate("GroupBox", u"cumulative", None))
        self.checkBox_stacked_histogram.setText(
            QCoreApplication.translate("GroupBox", u"stacked", None))
        #if QT_CONFIG(tooltip)
        self.checkBox_color_segments_occupancy.setToolTip(
            QCoreApplication.translate(
                "GroupBox",
                u"<html><head/><body><p align=\"justify\">Toggle if histogram bars are colored by segment or molecule. With colors turned on, comparing to other analyses is not possible.</p></body></html>",
                None))
        #endif // QT_CONFIG(tooltip)
        self.checkBox_color_segments_occupancy.setText(
            QCoreApplication.translate("GroupBox", u"color by segment", None))
        #if QT_CONFIG(tooltip)
        self.pushButton_degree_plot.setToolTip(
            QCoreApplication.translate(
                "GroupBox",
                u"<html><head/><body><p align=\"justify\">Compute the number of H bonds per residue. Results are colored by segment.</p></body></html>",
                None))
        #endif // QT_CONFIG(tooltip)
        self.pushButton_degree_plot.setText(
            QCoreApplication.translate("GroupBox", u"Plot", None))
class ChapterSelectionSetting(GlobalSetting):
    tab_clicked_signal = Signal()
    activation_signal = Signal(bool)

    def __init__(self):
        super().__init__()
        self.create_properties()
        self.create_widgets()
        self.setup_widgets()
        self.connect_signals()

    def create_widgets(self):
        self.chapter_source_label = QLabel("Chapter Source Folder:")
        self.chapter_extension_label = QLabel("Chapter Extension:")
        self.chapter_source_lineEdit = ChapterSourceLineEdit()
        self.chapter_source_button = ChapterSourceButton()
        self.chapter_extensions_comboBox = ChapterExtensionsCheckableComboBox()
        self.chapter_match_layout = MatchChapterLayout(parent=self)
        self.chapter_options_layout = QHBoxLayout()
        self.MainLayout = QVBoxLayout()
        self.main_layout = QGridLayout()
        self.chapter_main_groupBox = QGroupBox()
        self.chapter_match_groupBox = QGroupBox("Chapter Matching")
        self.chapter_match_groupBox.setLayout(self.chapter_match_layout)

    def setup_widgets(self):
        self.setup_chapter_main_groupBox()
        self.setup_layouts()

    # noinspection PyUnresolvedReferences
    def connect_signals(self):
        self.chapter_main_groupBox.toggled.connect(self.activate_tab)
        self.chapter_source_button.clicked_signal.connect(
            self.update_folder_path)
        self.chapter_source_lineEdit.edit_finished_signal.connect(
            self.update_folder_path)
        self.chapter_extensions_comboBox.close_list.connect(
            self.check_extension_changes)
        self.chapter_match_layout.sync_chapter_files_with_global_files_after_swap_signal.connect(
            self.sync_chapter_files_with_global_files)
        self.tab_clicked_signal.connect(self.tab_clicked)

    def create_properties(self):
        self.folder_path = ""
        self.files_names_list = []
        self.files_names_absolute_list = []
        self.current_chapter_extensions = [Default_Chapter_Extension]

    def setup_layouts(self):
        self.setup_chapter_options_layout()
        self.setup_main_layout()
        self.setLayout(self.MainLayout)
        self.MainLayout.addWidget(self.chapter_main_groupBox)

    def setup_chapter_options_layout(self):
        self.chapter_options_layout.addWidget(self.chapter_extensions_comboBox)
        self.chapter_options_layout.addStretch()

    def setup_main_layout(self):
        self.main_layout.addWidget(self.chapter_source_label, 0, 0)
        self.main_layout.addWidget(self.chapter_source_lineEdit, 0, 1, 1, 1)
        self.main_layout.addWidget(self.chapter_source_button, 0, 2)
        self.main_layout.addWidget(self.chapter_extension_label, 1, 0)
        self.main_layout.addLayout(self.chapter_options_layout, 1, 1, 1, 2)
        self.main_layout.addWidget(self.chapter_match_groupBox, 2, 0, 1, -1)

    def setup_chapter_main_groupBox(self):
        self.chapter_main_groupBox.setParent(self)
        self.chapter_main_groupBox.setLayout(self.main_layout)
        self.chapter_main_groupBox.setTitle("Chapters")
        self.chapter_main_groupBox.setCheckable(True)
        self.chapter_main_groupBox.setChecked(True)

    def update_folder_path(self, new_path: str):
        if new_path != "":
            self.chapter_source_lineEdit.setText(new_path)
            self.update_files_lists(new_path)
            self.show_chapter_files_list()

    def update_files_lists(self, folder_path):
        if folder_path == "" or folder_path.isspace():
            self.folder_path = ""
            self.chapter_source_lineEdit.setText("")
            return
        try:
            self.folder_path = folder_path
            self.files_names_list = self.get_files_list(self.folder_path)
            self.files_names_absolute_list = get_files_names_absolute_list(
                self.files_names_list, self.folder_path)
        except Exception as e:
            invalid_path_dialog = InvalidPathDialog()
            invalid_path_dialog.execute()

    def check_extension_changes(self, new_extensions):
        if self.current_chapter_extensions != new_extensions:
            self.current_chapter_extensions = new_extensions
            self.update_files_lists(self.folder_path)
            self.show_chapter_files_list()

    def get_files_list(self, folder_path):
        temp_files_names = sort_names_like_windows(
            names_list=os.listdir(folder_path))
        temp_files_names_absolute = get_files_names_absolute_list(
            temp_files_names, folder_path)
        current_extensions = self.chapter_extensions_comboBox.currentData()
        result = []
        for i in range(len(temp_files_names)):
            if os.path.isdir(temp_files_names_absolute[i]):
                continue
            if os.path.getsize(temp_files_names_absolute[i]) == 0:
                continue
            for j in range(len(current_extensions)):
                temp_file_extension_start_index = temp_files_names[i].rfind(
                    ".")
                if temp_file_extension_start_index == -1:
                    continue
                temp_file_extension = temp_files_names[i][
                    temp_file_extension_start_index + 1:]
                if temp_file_extension.lower() == current_extensions[j].lower(
                ):
                    result.append(temp_files_names[i])
                    break
        return result

    def show_chapter_files_list(self):
        self.update_other_classes_variables()
        self.chapter_match_layout.show_chapter_files()

    def update_other_classes_variables(self):
        self.change_global_last_path_directory()
        self.change_global_chapter_list()
        self.chapter_source_button.set_is_there_old_file(
            len(self.files_names_list) > 0)
        self.chapter_source_lineEdit.set_is_there_old_file(
            len(self.files_names_list) > 0)
        self.chapter_extensions_comboBox.set_is_there_old_file(
            len(self.files_names_list) > 0)
        self.chapter_source_lineEdit.set_current_folder_path(self.folder_path)
        self.chapter_extensions_comboBox.set_current_folder_path(
            self.folder_path)
        self.chapter_extensions_comboBox.set_current_files_list(
            self.files_names_list)

    def change_global_chapter_list(self):
        GlobalSetting.CHAPTER_FILES_LIST = self.files_names_list
        GlobalSetting.CHAPTER_FILES_ABSOLUTE_PATH_LIST = self.files_names_absolute_list

    def show_video_files_list(self):
        if self.chapter_main_groupBox.isChecked():
            self.chapter_match_layout.show_video_files()

    def activate_tab(self, on):
        if on:
            self.show_video_files_list()
        else:
            self.chapter_source_lineEdit.setText("")
            self.chapter_match_layout.clear_tables()
            self.folder_path = ""
            self.files_names_list = []
            self.files_names_absolute_list = []
            self.current_chapter_extensions = [Default_Chapter_Extension]
            self.chapter_extensions_comboBox.setData(
                self.current_chapter_extensions)
            GlobalSetting.CHAPTER_FILES_LIST = []
            GlobalSetting.CHAPTER_FILES_ABSOLUTE_PATH_LIST = []
            GlobalSetting.CHAPTER_TRACK_NAME = ""
            GlobalSetting.CHAPTER_DELAY = 0.0
            GlobalSetting.CHAPTER_SET_DEFAULT = False
            GlobalSetting.CHAPTER_SET_FORCED = False
            GlobalSetting.CHAPTER_LANGUAGE = ""
        self.activation_signal.emit(on)
        GlobalSetting.CHAPTER_ENABLED = on

    def mousePressEvent(self, QMouseEvent):
        if QMouseEvent.buttons() == Qt.RightButton:
            self.chapter_match_layout.clear_chapter_selection()
        if (QMouseEvent.buttons() == Qt.RightButton or QMouseEvent.buttons()
                == Qt.LeftButton) and (self.chapter_source_lineEdit.text()
                                       == ""):
            self.chapter_source_lineEdit.setText(self.folder_path)
        return QWidget.mousePressEvent(self, QMouseEvent)

    def showEvent(self, a0: QtGui.QShowEvent) -> None:
        super().showEvent(a0)
        if self.chapter_main_groupBox.isChecked():
            self.show_video_files_list()

    def change_global_last_path_directory(self):
        if self.folder_path != "" and not self.folder_path.isspace():
            GlobalSetting.LAST_DIRECTORY_PATH = self.folder_path

    def tab_clicked(self):
        if self.chapter_main_groupBox.isChecked():
            self.show_chapter_files_list()
            self.show_video_files_list()
        if not GlobalSetting.JOB_QUEUE_EMPTY:
            self.disable_editable_widgets()
        else:
            self.enable_editable_widgets()

    def disable_editable_widgets(self):
        self.chapter_source_lineEdit.setEnabled(False)
        self.chapter_source_button.setEnabled(False)
        self.chapter_extensions_comboBox.setEnabled(False)
        self.chapter_main_groupBox.setCheckable(False)
        self.chapter_match_layout.disable_editable_widgets()

    def enable_editable_widgets(self):
        self.chapter_source_lineEdit.setEnabled(True)
        self.chapter_source_button.setEnabled(True)
        self.chapter_extensions_comboBox.setEnabled(True)
        if GlobalSetting.CHAPTER_ENABLED:
            self.chapter_main_groupBox.setCheckable(True)
        else:
            self.chapter_main_groupBox.setCheckable(True)
            GlobalSetting.CHAPTER_ENABLED = False
            self.chapter_main_groupBox.setChecked(
                GlobalSetting.CHAPTER_ENABLED)
        self.chapter_match_layout.enable_editable_widgets()

    def sync_chapter_files_with_global_files(self):
        self.files_names_list = GlobalSetting.CHAPTER_FILES_LIST
        GlobalSetting.CHAPTER_FILES_ABSOLUTE_PATH_LIST = get_files_names_absolute_list(
            self.files_names_list, self.folder_path)
        self.files_names_absolute_list = GlobalSetting.CHAPTER_FILES_ABSOLUTE_PATH_LIST
        self.update_other_classes_variables()
class AttachmentSelectionSetting(GlobalSetting):
    tab_clicked_signal = Signal()
    activation_signal = Signal(bool)

    def __init__(self):
        super().__init__()
        self.attachment_source_label = QLabel("Attachment Source Folder:")
        self.attachment_total_size_label = QLabel("Total Attachment Size:")
        self.attachment_total_size_value_label = AttachmentsTotalSizeValueLabel(
        )
        self.attachment_source_lineEdit = AttachmentSourceLineEdit()
        self.attachment_source_button = AttachmentSourceButton()
        self.discard_old_attachments_checkBox = DiscardOldAttachmentsCheckBox()
        self.table = AttachmentTable()
        self.MainLayout = QVBoxLayout()
        self.attachment_main_groupBox = QGroupBox(self)
        self.attachment_main_layout = QGridLayout()
        self.folder_path = ""
        self.files_names_list = []
        self.files_checked_list = []
        self.files_names_absolute_list = []
        self.files_size_list = []
        self.setup_layouts()
        self.connect_signals()

    def setup_layouts(self):
        self.setup_main_layout()
        self.setup_attachment_main_groupBox()
        self.MainLayout.addWidget(self.attachment_main_groupBox)
        self.setLayout(self.MainLayout)

    def setup_attachment_main_groupBox(self):
        self.attachment_main_groupBox.setTitle("Attachments")
        self.attachment_main_groupBox.setCheckable(True)
        self.attachment_main_groupBox.setChecked(False)
        self.attachment_main_groupBox.setLayout(self.attachment_main_layout)

    def update_folder_path(self, new_path: str):
        if new_path != "":
            self.attachment_source_lineEdit.setText(new_path)
            self.update_files_lists(new_path)

            self.update_total_size()
            self.show_files_list()

    def update_total_size(self):
        self.attachment_total_size_value_label.update_total_size(
            self.files_names_absolute_list)

    def update_files_lists(self, folder_path):
        if folder_path == "" or folder_path.isspace():
            self.folder_path = ""
            self.attachment_source_lineEdit.setText("")
            return
        try:
            self.folder_path = folder_path
            self.files_names_list = self.get_files_list(self.folder_path)
            self.files_names_absolute_list = get_files_names_absolute_list(
                self.files_names_list, self.folder_path)
            self.files_size_list = get_files_size_list(
                files_list=self.files_names_list, folder_path=self.folder_path)
        except Exception as e:
            invalid_path_dialog = InvalidPathDialog()
            invalid_path_dialog.execute()

    def get_files_list(self, folder_path):
        temp_files_names = sort_names_like_windows(
            names_list=os.listdir(folder_path))
        temp_files_names_absolute = get_files_names_absolute_list(
            temp_files_names, folder_path)
        result = []
        for i in range(len(temp_files_names)):
            if os.path.isdir(temp_files_names_absolute[i]):
                continue
            if os.path.getsize(temp_files_names_absolute[i]) == 0:
                continue
            result.append(temp_files_names[i])
        return result

    def show_files_list(self):
        self.table.show_files_list(files_names_list=self.files_names_list,
                                   files_size_list=self.files_size_list)
        self.update_other_classes_variables()

    def update_other_classes_variables(self):
        self.change_global_last_path_directory()
        self.change_global_attachment_list()
        self.attachment_source_lineEdit.set_current_folder_path(
            self.folder_path)

    def setup_main_layout(self):
        self.attachment_main_layout.addWidget(self.attachment_source_label, 0,
                                              0)
        self.attachment_main_layout.addWidget(self.attachment_source_lineEdit,
                                              0, 1, 1, 80)
        self.attachment_main_layout.addWidget(self.attachment_source_button, 0,
                                              81, 1, 1)
        self.attachment_main_layout.addWidget(self.attachment_total_size_label,
                                              1, 0)
        self.attachment_main_layout.addWidget(
            self.attachment_total_size_value_label, 1, 1)
        self.attachment_main_layout.addWidget(
            self.discard_old_attachments_checkBox,
            1,
            40,
            1,
            -1,
            alignment=Qt.AlignRight)
        self.attachment_main_layout.addWidget(self.table, 2, 0, 1, -1)

    def change_global_last_path_directory(self):
        if self.folder_path != "" and not self.folder_path.isspace():
            GlobalSetting.LAST_DIRECTORY_PATH = self.folder_path

    def change_global_attachment_list(self):
        GlobalSetting.ATTACHMENT_FILES_LIST = self.files_names_list
        GlobalSetting.ATTACHMENT_FILES_ABSOLUTE_PATH_LIST = self.files_names_absolute_list
        GlobalSetting.ATTACHMENT_FILES_CHECKING_LIST = [True] * len(
            self.files_names_list)

    def connect_signals(self):
        self.attachment_source_button.clicked_signal.connect(
            self.update_folder_path)
        self.attachment_source_lineEdit.edit_finished_signal.connect(
            self.update_folder_path)
        self.attachment_main_groupBox.toggled.connect(self.activate_tab)
        self.tab_clicked_signal.connect(self.tab_clicked)
        self.table.update_checked_attachment_signal.connect(
            self.attachment_total_size_value_label.attachment_checked)
        self.table.update_unchecked_attachment_signal.connect(
            self.attachment_total_size_value_label.attachment_unchecked)

    def tab_clicked(self):
        if not GlobalSetting.JOB_QUEUE_EMPTY:
            self.disable_editable_widgets()
        else:
            self.enable_editable_widgets()

    def disable_editable_widgets(self):
        self.attachment_source_lineEdit.setEnabled(False)
        self.attachment_source_button.setEnabled(False)
        self.discard_old_attachments_checkBox.setEnabled(False)
        self.attachment_main_groupBox.setCheckable(False)

    def enable_editable_widgets(self):
        self.attachment_source_lineEdit.setEnabled(True)
        self.attachment_source_button.setEnabled(True)
        self.discard_old_attachments_checkBox.setEnabled(True)
        if GlobalSetting.ATTACHMENT_ENABLED:
            self.attachment_main_groupBox.setCheckable(True)
        else:
            self.attachment_main_groupBox.setCheckable(True)
            GlobalSetting.ATTACHMENT_ENABLED = False
            self.attachment_main_groupBox.setChecked(
                GlobalSetting.ATTACHMENT_ENABLED)

    def activate_tab(self, on):
        if not on:
            self.table.clear_table()
            self.attachment_source_lineEdit.setText("")
            self.attachment_total_size_value_label.set_total_size_zero()
            self.discard_old_attachments_checkBox.setChecked(False)
            self.folder_path = ""
            self.files_names_list = []
            self.files_names_absolute_list = []
            self.files_size_list = []
            GlobalSetting.ATTACHMENT_FILES_LIST = []
            GlobalSetting.ATTACHMENT_FILES_ABSOLUTE_PATH_LIST = []
            GlobalSetting.ATTACHMENT_FILES_CHECKING_LIST = []
            GlobalSetting.ATTACHMENT_DISCARD_OLD = False
        self.activation_signal.emit(on)
        GlobalSetting.ATTACHMENT_ENABLED = on
Exemplo n.º 6
0
class ChapterSelectionSetting(GlobalSetting):
    tab_clicked_signal = Signal()
    activation_signal = Signal(bool)

    def __init__(self):
        super().__init__()
        self.create_properties()
        self.create_widgets()
        self.setup_widgets()
        self.connect_signals()

    def create_widgets(self):
        self.chapter_source_label = QLabel("Chapter Source Folder:")
        self.chapter_extension_label = QLabel("Chapter Extension:")
        self.chapter_source_lineEdit = ChapterSourceLineEdit()
        self.chapter_source_button = ChapterSourceButton()
        self.chapter_clear_button = ChapterClearButton()
        self.chapter_extensions_comboBox = ChapterExtensionsCheckableComboBox()
        self.chapter_match_layout = MatchChapterLayout(parent=self)
        self.chapter_options_layout = QHBoxLayout()
        self.MainLayout = QVBoxLayout()
        self.main_layout = QGridLayout()
        self.chapter_main_groupBox = QGroupBox()
        self.chapter_match_groupBox = QGroupBox("Chapter Matching")
        self.chapter_match_groupBox.setLayout(self.chapter_match_layout)

    def setup_widgets(self):
        self.setup_chapter_main_groupBox()
        self.setup_layouts()

    # noinspection PyUnresolvedReferences
    def connect_signals(self):
        self.chapter_main_groupBox.toggled.connect(self.activate_tab)
        self.chapter_source_button.clicked_signal.connect(
            self.update_folder_path)
        self.chapter_source_lineEdit.edit_finished_signal.connect(
            self.update_folder_path)
        self.chapter_source_lineEdit.set_is_drag_and_drop_signal.connect(
            self.update_is_drag_and_drop)
        self.chapter_extensions_comboBox.close_list.connect(
            self.check_extension_changes)
        self.chapter_match_layout.sync_chapter_files_with_global_files_after_swap_signal.connect(
            self.sync_chapter_files_with_global_files)
        self.tab_clicked_signal.connect(self.tab_clicked)
        self.chapter_match_layout.chapter_table.drop_folder_and_files_signal.connect(
            self.update_files_with_drag_and_drop)
        self.chapter_clear_button.clear_files_signal.connect(self.clear_files)

    def create_properties(self):
        self.folder_path = ""
        self.drag_and_dropped_text = "[Drag & Drop Files]"
        self.files_names_list = []
        self.files_names_absolute_list = []
        self.files_names_absolute_list_with_dropped_files = []
        self.current_chapter_extensions = DefaultOptions.Default_Chapter_Extensions
        self.is_drag_and_drop = False

    def setup_layouts(self):
        self.setup_chapter_options_layout()
        self.setup_main_layout()
        self.setLayout(self.MainLayout)
        self.MainLayout.addWidget(self.chapter_main_groupBox)

    def setup_chapter_options_layout(self):
        self.chapter_options_layout.addWidget(self.chapter_extensions_comboBox)
        self.chapter_options_layout.addStretch()

    def setup_main_layout(self):
        self.main_layout.addWidget(self.chapter_source_label, 0, 0)
        self.main_layout.addWidget(self.chapter_source_lineEdit, 0, 1, 1, 1)
        self.main_layout.addWidget(self.chapter_clear_button, 0, 2, 1, 1)
        self.main_layout.addWidget(self.chapter_source_button, 0, 3)
        self.main_layout.addWidget(self.chapter_extension_label, 1, 0)
        self.main_layout.addLayout(self.chapter_options_layout, 1, 1, 1, 3)
        self.main_layout.addWidget(self.chapter_match_groupBox, 2, 0, 1, -1)

    def setup_chapter_main_groupBox(self):
        self.chapter_main_groupBox.setParent(self)
        self.chapter_main_groupBox.setLayout(self.main_layout)
        self.chapter_main_groupBox.setTitle("Chapters")
        self.chapter_main_groupBox.setCheckable(True)
        self.chapter_main_groupBox.setChecked(True)

    def update_folder_path(self, new_path: str):
        if new_path != "":
            self.chapter_source_lineEdit.setText(new_path)
            self.update_files_lists(new_path)
            self.show_chapter_files_list()
        else:
            if self.is_drag_and_drop:
                self.chapter_source_lineEdit.stop_check_path = True
                self.chapter_source_lineEdit.setText(
                    self.drag_and_dropped_text)
                self.chapter_source_lineEdit.stop_check_path = False

    def update_files_lists(self, folder_path):
        if folder_path == "" or folder_path.isspace():
            self.folder_path = ""
            if self.is_drag_and_drop:
                new_files_absolute_path_list = []
                self.files_names_list = []
                current_extensions = self.chapter_extensions_comboBox.currentData(
                )
                for file_absolute_path in self.files_names_absolute_list_with_dropped_files:
                    if os.path.isdir(file_absolute_path):
                        continue
                    if os.path.getsize(file_absolute_path) == 0:
                        continue
                    temp_file_name = os.path.basename(file_absolute_path)
                    for j in range(len(current_extensions)):
                        temp_file_extension_start_index = temp_file_name.rfind(
                            ".")
                        if temp_file_extension_start_index == -1:
                            continue
                        temp_file_extension = temp_file_name[
                            temp_file_extension_start_index + 1:]
                        if temp_file_extension.lower(
                        ) == current_extensions[j].lower():
                            new_files_absolute_path_list.append(
                                file_absolute_path)
                            self.files_names_list.append(
                                os.path.basename(file_absolute_path))
                            break
                self.chapter_source_lineEdit.stop_check_path = True
                self.chapter_source_lineEdit.setText(
                    self.drag_and_dropped_text)
                self.is_drag_and_drop = True
                self.folder_path = ""
                self.files_names_absolute_list = new_files_absolute_path_list.copy(
                )
                self.files_names_absolute_list_with_dropped_files = new_files_absolute_path_list.copy(
                )
                self.chapter_source_lineEdit.stop_check_path = False
            else:
                self.chapter_source_lineEdit.setText("")
            return
        try:
            self.is_drag_and_drop = False
            self.folder_path = folder_path
            self.files_names_list = self.get_files_list(self.folder_path)
            self.files_names_absolute_list = get_files_names_absolute_list(
                self.files_names_list, self.folder_path)
            self.files_names_absolute_list_with_dropped_files = self.files_names_absolute_list.copy(
            )
        except Exception as e:
            invalid_path_dialog = InvalidPathDialog()
            invalid_path_dialog.execute()

    def check_extension_changes(self, new_extensions):
        if self.current_chapter_extensions != new_extensions:
            self.current_chapter_extensions = new_extensions
            self.update_files_lists(self.folder_path)
            self.show_chapter_files_list()

    def get_files_list(self, folder_path):
        temp_files_names = sort_names_like_windows(
            names_list=os.listdir(folder_path))
        temp_files_names_absolute = get_files_names_absolute_list(
            temp_files_names, folder_path)
        current_extensions = self.chapter_extensions_comboBox.currentData()
        result = []
        for i in range(len(temp_files_names)):
            if os.path.isdir(temp_files_names_absolute[i]):
                continue
            if os.path.getsize(temp_files_names_absolute[i]) == 0:
                continue
            for j in range(len(current_extensions)):
                temp_file_extension_start_index = temp_files_names[i].rfind(
                    ".")
                if temp_file_extension_start_index == -1:
                    continue
                temp_file_extension = temp_files_names[i][
                    temp_file_extension_start_index + 1:]
                if temp_file_extension.lower() == current_extensions[j].lower(
                ):
                    result.append(temp_files_names[i])
                    break
        return result

    def show_chapter_files_list(self):
        self.update_other_classes_variables()
        self.chapter_match_layout.show_chapter_files()

    def update_other_classes_variables(self):
        self.change_global_last_path_directory()
        self.change_global_chapter_list()
        self.chapter_source_button.set_is_there_old_file(
            len(self.files_names_list) > 0)
        self.chapter_source_lineEdit.set_is_there_old_file(
            len(self.files_names_list) > 0)
        self.chapter_extensions_comboBox.set_is_there_old_file(
            len(self.files_names_list) > 0)
        self.chapter_clear_button.set_is_there_old_file(
            len(self.files_names_list) > 0)
        self.chapter_source_lineEdit.set_current_folder_path(self.folder_path)
        self.chapter_source_lineEdit.set_is_drag_and_drop(
            self.is_drag_and_drop)
        self.chapter_extensions_comboBox.set_current_folder_path(
            self.folder_path)
        self.chapter_extensions_comboBox.set_current_files_list(
            self.files_names_list)

    def clear_files(self):
        self.folder_path = ""
        self.files_names_list = []
        self.files_names_absolute_list = []
        self.files_names_absolute_list_with_dropped_files = []
        self.chapter_source_lineEdit.setText("")
        self.is_drag_and_drop = False
        self.show_chapter_files_list()

    def change_global_chapter_list(self):
        GlobalSetting.CHAPTER_FILES_LIST = self.files_names_list
        GlobalSetting.CHAPTER_FILES_ABSOLUTE_PATH_LIST = self.files_names_absolute_list

    def show_video_files_list(self):
        if self.chapter_main_groupBox.isChecked():
            self.chapter_match_layout.show_video_files()

    def activate_tab(self, on):
        if on:
            self.show_video_files_list()
        else:
            self.chapter_source_lineEdit.setText("")
            self.chapter_match_layout.clear_tables()
            self.folder_path = ""
            self.files_names_list = []
            self.files_names_absolute_list = []
            self.current_chapter_extensions = DefaultOptions.Default_Chapter_Extensions
            self.chapter_extensions_comboBox.setData(
                self.current_chapter_extensions)
            self.is_drag_and_drop = False
            self.chapter_source_lineEdit.set_is_drag_and_drop(False)
            GlobalSetting.CHAPTER_FILES_LIST = []
            GlobalSetting.CHAPTER_FILES_ABSOLUTE_PATH_LIST = []
            GlobalSetting.CHAPTER_TRACK_NAME = ""
            GlobalSetting.CHAPTER_DELAY = 0.0
            GlobalSetting.CHAPTER_SET_DEFAULT = False
            GlobalSetting.CHAPTER_SET_FORCED = False
            GlobalSetting.CHAPTER_LANGUAGE = ""
        self.activation_signal.emit(on)
        GlobalSetting.CHAPTER_ENABLED = on

    def mousePressEvent(self, QMouseEvent):
        if QMouseEvent.buttons() == Qt.RightButton:
            self.chapter_match_layout.clear_chapter_selection()
        if (QMouseEvent.buttons() == Qt.RightButton or QMouseEvent.buttons()
                == Qt.LeftButton) and (self.chapter_source_lineEdit.text()
                                       == ""):
            self.chapter_source_lineEdit.setText(self.folder_path)
        return QWidget.mousePressEvent(self, QMouseEvent)

    def showEvent(self, a0: QtGui.QShowEvent) -> None:
        super().showEvent(a0)
        if self.chapter_main_groupBox.isChecked():
            self.show_video_files_list()

    def change_global_last_path_directory(self):
        if self.folder_path != "" and not self.folder_path.isspace(
        ) and not self.is_drag_and_drop:
            GlobalSetting.LAST_DIRECTORY_PATH = self.folder_path

    def tab_clicked(self):
        if self.chapter_main_groupBox.isChecked():
            self.show_chapter_files_list()
            self.show_video_files_list()
        if not GlobalSetting.JOB_QUEUE_EMPTY:
            self.disable_editable_widgets()
        else:
            self.enable_editable_widgets()

    def disable_editable_widgets(self):
        self.chapter_source_lineEdit.setEnabled(False)
        self.chapter_source_button.setEnabled(False)
        self.chapter_extensions_comboBox.setEnabled(False)
        self.chapter_clear_button.setEnabled(False)
        self.chapter_main_groupBox.setCheckable(False)
        self.chapter_match_layout.disable_editable_widgets()

    def enable_editable_widgets(self):
        self.chapter_source_lineEdit.setEnabled(True)
        self.chapter_source_button.setEnabled(True)
        self.chapter_extensions_comboBox.setEnabled(True)
        self.chapter_clear_button.setEnabled(True)
        if GlobalSetting.CHAPTER_ENABLED:
            self.chapter_main_groupBox.setCheckable(True)
        else:
            self.chapter_main_groupBox.setCheckable(True)
            GlobalSetting.CHAPTER_ENABLED = False
            self.chapter_main_groupBox.setChecked(
                GlobalSetting.CHAPTER_ENABLED)
        self.chapter_match_layout.enable_editable_widgets()

    def sync_chapter_files_with_global_files(self):
        self.files_names_list = GlobalSetting.CHAPTER_FILES_LIST
        self.files_names_absolute_list = GlobalSetting.CHAPTER_FILES_ABSOLUTE_PATH_LIST
        self.update_other_classes_variables()

    def update_files_with_drag_and_drop(self, paths_list):
        duplicate_flag = False
        not_duplicate_files_absolute_path_list = []
        not_duplicate_files_list = []
        duplicate_files_list = []
        new_files_absolute_path_list = []
        current_extensions = self.chapter_extensions_comboBox.currentData()
        for path in paths_list:
            if os.path.isfile(path):
                if os.path.getsize(path) == 0:
                    continue
                temp_file_name = os.path.basename(path)
                for j in range(len(current_extensions)):
                    temp_file_extension_start_index = temp_file_name.rfind(".")
                    if temp_file_extension_start_index == -1:
                        continue
                    temp_file_extension = temp_file_name[
                        temp_file_extension_start_index + 1:]
                    if temp_file_extension.lower(
                    ) == current_extensions[j].lower():
                        new_files_absolute_path_list.append(path)
                        break
            else:
                new_files_absolute_path_list.extend(
                    sort_names_like_windows(
                        get_files_names_absolute_list(
                            self.get_files_list(path), path)))

        for new_file_name in new_files_absolute_path_list:
            if os.path.basename(new_file_name).lower() in map(
                    str.lower, self.files_names_list):
                duplicate_flag = True
                duplicate_files_list.append(os.path.basename(new_file_name))
            else:
                not_duplicate_files_absolute_path_list.append(new_file_name)
                not_duplicate_files_list.append(
                    os.path.basename(new_file_name))
                self.files_names_list.append(os.path.basename(new_file_name))
        self.chapter_source_lineEdit.stop_check_path = True
        self.chapter_source_lineEdit.setText(self.drag_and_dropped_text)
        self.is_drag_and_drop = True
        self.folder_path = ""
        self.files_names_absolute_list_with_dropped_files.extend(
            not_duplicate_files_absolute_path_list)
        self.files_names_absolute_list.extend(
            not_duplicate_files_absolute_path_list)
        self.show_chapter_files_list()
        self.chapter_source_lineEdit.stop_check_path = False
        if duplicate_flag:
            info_message = "One or more files have the same name with the old files will be " \
                           "skipped:"
            for file_name in duplicate_files_list:
                info_message += "\n" + file_name
            warning_dialog = WarningDialog(
                window_title="Duplicate files names",
                info_message=info_message,
                parent=self.window())
            warning_dialog.execute_wth_no_block()

    def update_is_drag_and_drop(self, new_state):
        self.is_drag_and_drop = new_state

    def set_default_directory(self):
        self.chapter_source_lineEdit.setText(
            DefaultOptions.Default_Chapter_Directory)
        self.chapter_source_lineEdit.check_new_path()
class AttachmentSelectionSetting(GlobalSetting):
    tab_clicked_signal = Signal()
    activation_signal = Signal(bool)

    def __init__(self):
        super().__init__()
        self.attachment_source_label = QLabel("Attachment Source Folder:")
        self.attachment_total_size_label = QLabel("Total Attachment Size:")
        self.attachment_total_size_value_label = AttachmentsTotalSizeValueLabel(
        )
        self.attachment_source_lineEdit = AttachmentSourceLineEdit()
        self.attachment_clear_button = AttachmentClearButton()
        self.attachment_source_button = AttachmentSourceButton()
        self.discard_old_attachments_checkBox = DiscardOldAttachmentsCheckBox()
        self.table = AttachmentTable()
        self.MainLayout = QVBoxLayout()
        self.attachment_main_groupBox = QGroupBox(self)
        self.attachment_main_layout = QGridLayout()
        self.folder_path = ""
        self.drag_and_dropped_text = "[Drag & Drop Files]"
        self.is_drag_and_drop = False
        self.files_names_list = []
        self.files_checked_list = []
        self.files_names_absolute_list = []
        self.files_size_list = []
        self.setup_layouts()
        self.connect_signals()

    def setup_layouts(self):
        self.setup_main_layout()
        self.setup_attachment_main_groupBox()
        self.MainLayout.addWidget(self.attachment_main_groupBox)
        self.setLayout(self.MainLayout)

    def setup_attachment_main_groupBox(self):
        self.attachment_main_groupBox.setTitle("Attachments")
        self.attachment_main_groupBox.setCheckable(True)
        self.attachment_main_groupBox.setChecked(False)
        self.attachment_main_groupBox.setLayout(self.attachment_main_layout)

    def update_folder_path(self, new_path: str):
        if new_path != "":
            self.attachment_source_lineEdit.setText(new_path)
            self.update_files_lists(new_path)

            self.update_total_size()
            self.show_files_list()
        else:
            if self.is_drag_and_drop:
                self.attachment_source_lineEdit.stop_check_path = True
                self.attachment_source_lineEdit.setText(
                    self.drag_and_dropped_text)
                self.attachment_source_lineEdit.stop_check_path = False

    def update_total_size(self):
        self.attachment_total_size_value_label.update_total_size(
            self.files_names_absolute_list, self.files_checked_list)

    def update_files_lists(self, folder_path):
        if folder_path == "" or folder_path.isspace():
            self.folder_path = ""
            if self.is_drag_and_drop:
                new_files_absolute_path_list = []
                self.files_names_list = []
                for file_absolute_path in self.files_names_absolute_list_with_dropped_files:
                    if os.path.isdir(file_absolute_path):
                        continue
                    if os.path.getsize(file_absolute_path) == 0:
                        continue
                    new_files_absolute_path_list.append(file_absolute_path)
                    self.files_names_list.append(
                        os.path.basename(file_absolute_path))
                self.attachment_source_lineEdit.stop_check_path = True
                self.attachment_source_lineEdit.setText(
                    self.drag_and_dropped_text)
                self.is_drag_and_drop = True
                self.folder_path = ""
                self.files_names_absolute_list = new_files_absolute_path_list.copy(
                )
                self.files_size_list = get_files_size_with_absolute_path_list(
                    new_files_absolute_path_list)
                self.files_checked_list = ([True] *
                                           len(new_files_absolute_path_list))
                self.attachment_source_lineEdit.stop_check_path = False
                self.update_total_size()
            else:
                self.attachment_source_lineEdit.setText("")
            return
        try:
            self.is_drag_and_drop = False
            self.folder_path = folder_path
            self.files_names_list = self.get_files_list(self.folder_path)
            self.files_names_absolute_list = get_files_names_absolute_list(
                self.files_names_list, self.folder_path)
            self.files_size_list = get_files_size_list(
                files_list=self.files_names_list, folder_path=self.folder_path)
            self.files_checked_list = ([True] *
                                       len(self.files_names_absolute_list))
        except Exception as e:
            invalid_path_dialog = InvalidPathDialog()
            invalid_path_dialog.execute()

    def get_files_list(self, folder_path):
        temp_files_names = sort_names_like_windows(
            names_list=os.listdir(folder_path))
        temp_files_names_absolute = get_files_names_absolute_list(
            temp_files_names, folder_path)
        result = []
        for i in range(len(temp_files_names)):
            if os.path.isdir(temp_files_names_absolute[i]):
                continue
            if os.path.getsize(temp_files_names_absolute[i]) == 0:
                continue
            result.append(temp_files_names[i])
        return result

    def show_files_list(self):
        self.table.show_files_list(
            files_names_list=self.files_names_list,
            files_names_checked_list=self.files_checked_list,
            files_size_list=self.files_size_list)
        self.update_other_classes_variables()

    def update_other_classes_variables(self):
        self.change_global_last_path_directory()
        self.change_global_attachment_list()
        self.attachment_source_lineEdit.set_current_folder_path(
            self.folder_path)
        self.attachment_source_lineEdit.set_is_drag_and_drop(
            self.is_drag_and_drop)
        self.attachment_clear_button.set_is_there_old_file(
            len(self.files_names_list) > 0)

    def setup_main_layout(self):
        self.attachment_main_layout.addWidget(self.attachment_source_label, 0,
                                              0)
        self.attachment_main_layout.addWidget(self.attachment_source_lineEdit,
                                              0, 1, 1, 80)
        self.attachment_main_layout.addWidget(self.attachment_clear_button, 0,
                                              81, 1, 1)
        self.attachment_main_layout.addWidget(self.attachment_source_button, 0,
                                              82, 1, 1)
        self.attachment_main_layout.addWidget(self.attachment_total_size_label,
                                              1, 0)
        self.attachment_main_layout.addWidget(
            self.attachment_total_size_value_label, 1, 1)
        self.attachment_main_layout.addWidget(
            self.discard_old_attachments_checkBox,
            1,
            40,
            1,
            -1,
            alignment=Qt.AlignRight)
        self.attachment_main_layout.addWidget(self.table, 2, 0, 1, -1)

    def clear_files(self):
        self.folder_path = ""
        self.files_names_list = []
        self.files_names_absolute_list = []
        self.files_size_list = []
        self.attachment_source_lineEdit.setText("")
        self.is_drag_and_drop = False
        self.files_checked_list = []
        self.update_total_size()
        self.show_files_list()

    def change_global_last_path_directory(self):
        if self.folder_path != "" and not self.folder_path.isspace(
        ) and not self.is_drag_and_drop:
            GlobalSetting.LAST_DIRECTORY_PATH = self.folder_path

    def change_global_attachment_list(self):
        GlobalSetting.ATTACHMENT_FILES_LIST = self.files_names_list
        GlobalSetting.ATTACHMENT_FILES_ABSOLUTE_PATH_LIST = self.files_names_absolute_list
        GlobalSetting.ATTACHMENT_FILES_CHECKING_LIST = []
        for i in range(len(self.files_names_list)):
            if self.files_checked_list[i]:
                GlobalSetting.ATTACHMENT_FILES_CHECKING_LIST.append(True)
            else:
                GlobalSetting.ATTACHMENT_FILES_CHECKING_LIST.append(False)

    def connect_signals(self):
        self.attachment_source_button.clicked_signal.connect(
            self.update_folder_path)
        self.attachment_source_lineEdit.edit_finished_signal.connect(
            self.update_folder_path)
        self.attachment_source_lineEdit.set_is_drag_and_drop_signal.connect(
            self.update_is_drag_and_drop)
        self.attachment_main_groupBox.toggled.connect(self.activate_tab)
        self.tab_clicked_signal.connect(self.tab_clicked)
        self.table.update_checked_attachment_signal.connect(
            self.update_checked_attachment)
        self.table.update_unchecked_attachment_signal.connect(
            self.update_unchecked_attachment)
        self.table.drop_folder_and_files_signal.connect(
            self.update_files_with_drag_and_drop)
        self.attachment_clear_button.clear_files_signal.connect(
            self.clear_files)

    def update_checked_attachment(self, attachment_file_name_absolute):
        index = GlobalSetting.ATTACHMENT_FILES_ABSOLUTE_PATH_LIST.index(
            attachment_file_name_absolute)
        self.files_checked_list[index] = True
        self.attachment_total_size_value_label.attachment_checked(
            attachment_file_name_absolute)

    def update_unchecked_attachment(self, attachment_file_name_absolute):
        index = GlobalSetting.ATTACHMENT_FILES_ABSOLUTE_PATH_LIST.index(
            attachment_file_name_absolute)
        self.files_checked_list[index] = False
        self.attachment_total_size_value_label.attachment_unchecked(
            attachment_file_name_absolute)

    def tab_clicked(self):
        if not GlobalSetting.JOB_QUEUE_EMPTY:
            self.disable_editable_widgets()
        else:
            self.enable_editable_widgets()

    def disable_editable_widgets(self):
        self.attachment_source_lineEdit.setEnabled(False)
        self.attachment_source_button.setEnabled(False)
        self.discard_old_attachments_checkBox.setEnabled(False)
        self.attachment_main_groupBox.setCheckable(False)
        self.attachment_clear_button.setEnabled(False)
        self.table.setAcceptDrops(False)

    def enable_editable_widgets(self):
        self.attachment_source_lineEdit.setEnabled(True)
        self.attachment_source_button.setEnabled(True)
        self.discard_old_attachments_checkBox.setEnabled(True)
        self.attachment_clear_button.setEnabled(True)
        self.table.setAcceptDrops(True)
        if GlobalSetting.ATTACHMENT_ENABLED:
            self.attachment_main_groupBox.setCheckable(True)
        else:
            self.attachment_main_groupBox.setCheckable(True)
            GlobalSetting.ATTACHMENT_ENABLED = False
            self.attachment_main_groupBox.setChecked(
                GlobalSetting.ATTACHMENT_ENABLED)

    def activate_tab(self, on):
        if not on:
            self.table.clear_table()
            self.attachment_source_lineEdit.setText("")
            self.attachment_total_size_value_label.set_total_size_zero()
            self.discard_old_attachments_checkBox.setChecked(False)
            self.folder_path = ""
            self.files_names_list = []
            self.files_names_absolute_list = []
            self.files_size_list = []
            self.files_checked_list = []
            self.is_drag_and_drop = False
            self.attachment_source_lineEdit.set_is_drag_and_drop(False)
            GlobalSetting.ATTACHMENT_FILES_LIST = []
            GlobalSetting.ATTACHMENT_FILES_ABSOLUTE_PATH_LIST = []
            GlobalSetting.ATTACHMENT_FILES_CHECKING_LIST = []
            GlobalSetting.ATTACHMENT_DISCARD_OLD = False
        self.activation_signal.emit(on)
        GlobalSetting.ATTACHMENT_ENABLED = on

    def update_files_with_drag_and_drop(self, paths_list):
        duplicate_flag = False
        not_duplicate_files_absolute_path_list = []
        not_duplicate_files_list = []
        duplicate_files_list = []
        new_files_absolute_path_list = []
        for path in paths_list:
            if os.path.isfile(path):
                if os.path.getsize(path) == 0:
                    continue
                new_files_absolute_path_list.append(path)
            else:
                new_files_absolute_path_list.extend(
                    sort_names_like_windows(
                        get_files_names_absolute_list(
                            self.get_files_list(path), path)))

        for new_file_name in new_files_absolute_path_list:
            if os.path.basename(new_file_name).lower() in map(
                    str.lower, self.files_names_list):
                duplicate_flag = True
                duplicate_files_list.append(os.path.basename(new_file_name))
            else:
                not_duplicate_files_absolute_path_list.append(new_file_name)
                not_duplicate_files_list.append(
                    os.path.basename(new_file_name))
                self.files_names_list.append(os.path.basename(new_file_name))
        self.attachment_source_lineEdit.stop_check_path = True
        self.attachment_source_lineEdit.setText(self.drag_and_dropped_text)
        self.is_drag_and_drop = True
        self.folder_path = ""
        self.files_names_absolute_list.extend(
            not_duplicate_files_absolute_path_list)
        self.files_size_list.extend(
            get_files_size_with_absolute_path_list(
                not_duplicate_files_absolute_path_list))
        self.files_checked_list.extend(
            [True] * len(not_duplicate_files_absolute_path_list))
        self.update_total_size()
        self.show_files_list()
        self.attachment_source_lineEdit.stop_check_path = False
        if duplicate_flag:
            info_message = "One or more files have the same name with the old files will be " \
                           "skipped:"
            for file_name in duplicate_files_list:
                info_message += "\n" + file_name
            warning_dialog = WarningDialog(
                window_title="Duplicate files names",
                info_message=info_message,
                parent=self.window())
            warning_dialog.execute_wth_no_block()

    def update_is_drag_and_drop(self, new_state):
        self.is_drag_and_drop = new_state

    def set_default_directory(self):
        self.attachment_source_lineEdit.setText(
            DefaultOptions.Default_Attachment_Directory)
        self.attachment_source_lineEdit.check_new_path()