Example #1
0
    def __init__(self, tool):
        QWidget.__init__(self)
        self.tool = tool

        self.layout = QBoxLayout(QBoxLayout.TopToBottom)

        self.sliders = [
            slider.Slider(self.tool, "Short term TDP",
                          "Maximal TDP in the short term", 1, 1, 150, 5),
            slider.Slider(self.tool, "Long term TDP",
                          "Maximal TDP in the long term", 1, 1, 150, 5)
        ]

        self.slider_grid = slider.SliderGrid(self.tool, self.sliders)
        self.layout.addWidget(self.slider_grid)

        self.duration_controls = PowerDurationControls(self.tool)
        duration_group = QGroupBox("Override power limit durations")
        duration_group.setCheckable(True)
        duration_group.setToolTip(
            """If checked, allows you to alter short term and long term package power limit durations.
This is used for Turbo Boost.""")
        duration_group.setLayout(self.duration_controls.layout())
        self.layout.addWidget(duration_group)

        self.setLayout(self.layout)
Example #2
0
    def __init__(self, tool):
        QWidget.__init__(self)
        self.tool = tool

        self.layout = QBoxLayout(QBoxLayout.TopToBottom)

        self.tjunction_offset = slider.SliderGrid(self.tool, [
            slider.Slider(
                self.tool, "TJunction offset",
                "Offsets the temperature from which the CPU throttles", 1,
                -120, 0, 5)
        ])
        self.layout.addWidget(self.tjunction_offset)

        self.power_controls = PowerControls(self.tool)
        power_group = QGroupBox("Override power limits")
        power_group.setCheckable(True)
        power_group.setLayout(self.power_controls.layout)
        self.layout.addWidget(power_group)

        self.setLayout(self.layout)
Example #3
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_()
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)
Example #5
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))
Example #6
0
class MainWidget(QWidget):

    format_dict = {
        "JPEG(jpg)": "jpeg",
        "WebP": "webp",
        "Gif": "gif",
        "PNG": "png"
    }

    def __init__(self, parent):
        super().__init__()
        self.par = parent
        self.InitUI()

    def InitUI(self):
        self.selected_dir = str()
        self.option_array = [1, 0, 0, 0]
        self.main_layout = QVBoxLayout()
        self.make_dir_groupbox()
        self.make_func_groupbox()
        self.make_sys_layout()
        self.status_bar = QStatusBar()
        self.setEnabled(True)

        self.setLayout(self.main_layout)

    def make_dir_groupbox(self):
        dir_groupbox = QGroupBox("Select Directory")
        dir_layout = QVBoxLayout()
        self.loaded_dir_label = QLabel(self.selected_dir)
        self.loaded_dir_label.setStyleSheet("max-height: 24px;"
                                            "background-color: #FFFFFF;"
                                            "border-style: solid;"
                                            "border-width: 1px;"
                                            "border-color: #000000")
        dir_layout.addWidget(self.loaded_dir_label)
        self.load_dir_button = QPushButton("Load Directory", self)
        self.load_dir_button.clicked.connect(self.load_dir)
        dir_layout.addWidget(self.load_dir_button)
        dir_groupbox.setLayout(dir_layout)
        self.main_layout.addWidget(dir_groupbox)

    def make_func_groupbox(self):
        func_layout = QHBoxLayout()

        self.encode_widget = RadioBox(encode_dict)
        encode_layout = self.encode_widget.make_radio_box("UTF-8 with BOM")
        self.encode_groupbox = QGroupBox("Encode to: ")
        self.encode_groupbox.setLayout(encode_layout)
        self.encode_groupbox.setCheckable(True)
        self.encode_groupbox.clicked.connect(self.option_set)
        func_layout.addWidget(self.encode_groupbox)

        self.fmt_groupbox = QGroupBox("Convert image format")
        fmt_hbox = QHBoxLayout()
        self.format_widget_from = RadioBox(self.format_dict)
        format_layout_from = self.format_widget_from.make_radio_box("WebP")
        fmt_from_groupbox = QGroupBox("Convert image from: ")
        fmt_from_groupbox.setLayout(format_layout_from)
        fmt_hbox.addWidget(fmt_from_groupbox)

        self.format_widget_to = RadioBox(self.format_dict)
        format_layout_to = self.format_widget_to.make_radio_box("PNG")
        fmt_to_groupbox = QGroupBox("Convert image to: ")
        fmt_to_groupbox.setLayout(format_layout_to)
        fmt_hbox.addWidget(fmt_to_groupbox)
        self.fmt_groupbox.setLayout(fmt_hbox)
        self.fmt_groupbox.setCheckable(True)
        func_layout.addWidget(self.fmt_groupbox)

        option_groupbox = QGroupBox("OPTION: ")
        option_layout = QVBoxLayout()
        self.change_txt_yn = QCheckBox("Change image ext in CSV/ERB", self)
        self.change_txt_yn.toggle()
        self.change_txt_yn.clicked.connect(self.option_set)
        self.backup_yn = QCheckBox("Place files in Result directory", self)
        self.backup_yn.clicked.connect(self.option_set)

        option_layout.addWidget(self.change_txt_yn)
        option_layout.addWidget(self.backup_yn)
        option_groupbox.setLayout(option_layout)
        func_layout.addWidget(option_groupbox)

        self.main_layout.addLayout(func_layout)

    def make_sys_layout(self):
        sys_layout = QHBoxLayout()
        self.run_button = QPushButton("RUN", self)
        self.run_button.setEnabled(False)
        self.run_button.clicked.connect(self.run_process)
        self.prog_bar = QProgressBar()
        self.prog_bar.setMinimum(0)
        sys_layout.addWidget(self.prog_bar)
        sys_layout.stretch(1)
        sys_layout.addWidget(self.run_button)
        self.main_layout.addLayout(sys_layout)

    def load_dir(self):
        f_dialog = QFileDialog(self, "불러올 폴더를 선택하세요.", os.path.curdir)
        f_dialog.setFileMode(QFileDialog.DirectoryOnly)
        self.selected_dir = f_dialog.getExistingDirectory(
            self, "불러올 폴더를 선택하세요.")
        if not self.selected_dir:
            self.selected_dir = str()
            self.run_button.setEnabled(False)
        else:
            self.run_button.setEnabled(True)
        self.loaded_dir_label.setText(self.selected_dir)
        return self.selected_dir

    def option_set(self):
        if not self.encode_groupbox.isChecked():
            self.change_txt_yn.setEnabled(False)
        else:
            self.change_txt_yn.setEnabled(True)
        self.option_array[0] = self.change_txt_yn.checkState()
        self.option_array[1] = self.backup_yn.checkState()
        self.option_array[2] = self.encode_groupbox.isChecked()
        self.option_array[3] = self.fmt_groupbox.isChecked()
        return self.option_array

    def run_process(self):
        self.option_set()
        self.setEnabled(False)
        target_array = (
            self.encode_widget.result,
            self.format_widget_from.result,
            self.format_widget_to.result,
            self.selected_dir,
        )
        bar_array = (self.prog_bar, self.status_bar)
        self.threadclass = MyThread(target_array, bar_array, self.option_array,
                                    self)
        self.work_started = 0
        self.threadclass.processed.connect(self.progbar_set)
        self.threadclass.finished.connect(self.donebox)
        self.threadclass.start()

    def open_result(self):
        if self.option_array[1]:
            result_path = "Result\\"
        else:
            result_path = self.selected_dir
        os.startfile(result_path)

    @Slot(int)
    def progbar_set(self, progress_stat):
        if not self.work_started:
            self.prog_bar.setMaximum(progress_stat)
            self.work_started += 1
        else:
            self.prog_bar.setValue(progress_stat)

    @Slot(bool)
    def donebox(self):
        msgbox = QMessageBox(
            QMessageBox.Warning,
            "Done!",
            "Do you want to quit?",
            buttons=QMessageBox.Yes | QMessageBox.No,
            parent=self,
        )
        open_result = msgbox.addButton("Open Result Folder",
                                       QMessageBox.AcceptRole)
        msgbox.setDefaultButton(QMessageBox.Yes)
        close_yn = msgbox.exec_()
        if close_yn == QMessageBox.No:
            self.threadclass.wait()
            # debugpy.debug_this_thread()
            self.close()
            self.par.intiGUI()
        else:
            if close_yn == QMessageBox.AcceptRole:
                self.open_result()
            QCoreApplication.instance().quit()
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
Example #9
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()
Example #10
0
class Ui_dlg_new_tool(object):
    def setupUi(self, dlg_new_tool):
        if not dlg_new_tool.objectName():
            dlg_new_tool.setObjectName(u"dlg_new_tool")
        dlg_new_tool.resize(570, 463)
        dlg_new_tool.setModal(True)
        self.gridLayout_2 = QGridLayout(dlg_new_tool)
        self.gridLayout_2.setObjectName(u"gridLayout_2")
        self.gridLayout = QGridLayout()
        self.gridLayout.setObjectName(u"gridLayout")
        self.te_description = QTextEdit(dlg_new_tool)
        self.te_description.setObjectName(u"te_description")

        self.gridLayout.addWidget(self.te_description, 3, 0, 1, 6)

        self.label = QLabel(dlg_new_tool)
        self.label.setObjectName(u"label")

        self.gridLayout.addWidget(self.label, 0, 0, 1, 1)

        self.lbl_file_exists = QLabel(dlg_new_tool)
        self.lbl_file_exists.setObjectName(u"lbl_file_exists")
        self.lbl_file_exists.setPixmap(QPixmap(u"../resources/OK.png"))

        self.gridLayout.addWidget(self.lbl_file_exists, 0, 5, 1, 1)

        self.label_5 = QLabel(dlg_new_tool)
        self.label_5.setObjectName(u"label_5")

        self.gridLayout.addWidget(self.label_5, 0, 3, 1, 1)

        self.chk_mask_required = QCheckBox(dlg_new_tool)
        self.chk_mask_required.setObjectName(u"chk_mask_required")

        self.gridLayout.addWidget(self.chk_mask_required, 5, 0, 1, 6)

        self.label_4 = QLabel(dlg_new_tool)
        self.label_4.setObjectName(u"label_4")

        self.gridLayout.addWidget(self.label_4, 0, 2, 1, 1)

        self.le_tool_name = QLineEdit(dlg_new_tool)
        self.le_tool_name.setObjectName(u"le_tool_name")

        self.gridLayout.addWidget(self.le_tool_name, 0, 1, 1, 1)

        self.label_3 = QLabel(dlg_new_tool)
        self.label_3.setObjectName(u"label_3")

        self.gridLayout.addWidget(self.label_3, 1, 3, 1, 1)

        self.le_file_name = QLineEdit(dlg_new_tool)
        self.le_file_name.setObjectName(u"le_file_name")
        self.le_file_name.setReadOnly(True)

        self.gridLayout.addWidget(self.le_file_name, 0, 4, 1, 1)

        self.label_6 = QLabel(dlg_new_tool)
        self.label_6.setObjectName(u"label_6")
        font = QFont()
        font.setPointSize(8)
        self.label_6.setFont(font)

        self.gridLayout.addWidget(self.label_6, 1, 2, 1, 1)

        self.le_class_name = QLineEdit(dlg_new_tool)
        self.le_class_name.setObjectName(u"le_class_name")
        self.le_class_name.setReadOnly(True)

        self.gridLayout.addWidget(self.le_class_name, 1, 4, 1, 1)

        self.label_2 = QLabel(dlg_new_tool)
        self.label_2.setObjectName(u"label_2")

        self.gridLayout.addWidget(self.label_2, 2, 0, 1, 6)

        self.label_7 = QLabel(dlg_new_tool)
        self.label_7.setObjectName(u"label_7")

        self.gridLayout.addWidget(self.label_7, 4, 0, 1, 1)

        self.le_package_name = QLineEdit(dlg_new_tool)
        self.le_package_name.setObjectName(u"le_package_name")

        self.gridLayout.addWidget(self.le_package_name, 4, 1, 1, 5)

        self.gridLayout_2.addLayout(self.gridLayout, 0, 0, 1, 2)

        self.verticalLayout_4 = QVBoxLayout()
        self.verticalLayout_4.setObjectName(u"verticalLayout_4")
        self.groupBox = QGroupBox(dlg_new_tool)
        self.groupBox.setObjectName(u"groupBox")
        self.groupBox.setCheckable(False)
        self.verticalLayout = QVBoxLayout(self.groupBox)
        self.verticalLayout.setObjectName(u"verticalLayout")
        self.rb_output_image = QRadioButton(self.groupBox)
        self.rb_output_image.setObjectName(u"rb_output_image")
        self.rb_output_image.setChecked(True)

        self.verticalLayout.addWidget(self.rb_output_image)

        self.rb_output_mask = QRadioButton(self.groupBox)
        self.rb_output_mask.setObjectName(u"rb_output_mask")

        self.verticalLayout.addWidget(self.rb_output_mask)

        self.rb_output_data = QRadioButton(self.groupBox)
        self.rb_output_data.setObjectName(u"rb_output_data")

        self.verticalLayout.addWidget(self.rb_output_data)

        self.rb_output_none = QRadioButton(self.groupBox)
        self.rb_output_none.setObjectName(u"rb_output_none")

        self.verticalLayout.addWidget(self.rb_output_none)

        self.verticalLayout_4.addWidget(self.groupBox)

        self.gb_pipeline_tool_groups = QGroupBox(dlg_new_tool)
        self.gb_pipeline_tool_groups.setObjectName(u"gb_pipeline_tool_groups")

        self.verticalLayout_4.addWidget(self.gb_pipeline_tool_groups)

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

        self.verticalLayout_4.addItem(self.verticalSpacer)

        self.gridLayout_2.addLayout(self.verticalLayout_4, 1, 0, 1, 1)

        self.verticalLayout_3 = QVBoxLayout()
        self.verticalLayout_3.setObjectName(u"verticalLayout_3")
        self.groupBox_2 = QGroupBox(dlg_new_tool)
        self.groupBox_2.setObjectName(u"groupBox_2")
        self.verticalLayout_2 = QVBoxLayout(self.groupBox_2)
        self.verticalLayout_2.setObjectName(u"verticalLayout_2")
        self.rb_rt_yes = QRadioButton(self.groupBox_2)
        self.rb_rt_yes.setObjectName(u"rb_rt_yes")

        self.verticalLayout_2.addWidget(self.rb_rt_yes)

        self.rb_rt_no = QRadioButton(self.groupBox_2)
        self.rb_rt_no.setObjectName(u"rb_rt_no")
        self.rb_rt_no.setChecked(True)

        self.verticalLayout_2.addWidget(self.rb_rt_no)

        self.rb_rt_widget = QRadioButton(self.groupBox_2)
        self.rb_rt_widget.setObjectName(u"rb_rt_widget")

        self.verticalLayout_2.addWidget(self.rb_rt_widget)

        self.rb_rt_property = QRadioButton(self.groupBox_2)
        self.rb_rt_property.setObjectName(u"rb_rt_property")

        self.verticalLayout_2.addWidget(self.rb_rt_property)

        self.verticalLayout_3.addWidget(self.groupBox_2)

        self.gb_no_pipeline_tool_groups = QGroupBox(dlg_new_tool)
        self.gb_no_pipeline_tool_groups.setObjectName(u"gb_no_pipeline_tool_groups")

        self.verticalLayout_3.addWidget(self.gb_no_pipeline_tool_groups)

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

        self.verticalLayout_3.addItem(self.verticalSpacer_2)

        self.gridLayout_2.addLayout(self.verticalLayout_3, 1, 1, 1, 1)

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

        self.horizontalLayout.addItem(self.horizontalSpacer)

        self.bt_save = QPushButton(dlg_new_tool)
        self.bt_save.setObjectName(u"bt_save")

        self.horizontalLayout.addWidget(self.bt_save)

        self.bt_cancel = QPushButton(dlg_new_tool)
        self.bt_cancel.setObjectName(u"bt_cancel")

        self.horizontalLayout.addWidget(self.bt_cancel)

        self.gridLayout_2.addLayout(self.horizontalLayout, 2, 1, 1, 1)

        self.gridLayout_2.setColumnStretch(0, 1)
        self.gridLayout_2.setColumnStretch(1, 1)

        self.retranslateUi(dlg_new_tool)

        QMetaObject.connectSlotsByName(dlg_new_tool)

    # setupUi

    def retranslateUi(self, dlg_new_tool):
        dlg_new_tool.setWindowTitle(
            QCoreApplication.translate("dlg_new_tool", u"New tool wizard", None)
        )
        self.te_description.setPlaceholderText(
            QCoreApplication.translate(
                "dlg_new_tool",
                u"Write your tool's description here.\\nYou can use HTML tags",
                None,
            )
        )
        self.label.setText(
            QCoreApplication.translate("dlg_new_tool", u"Tool name:", None)
        )
        self.lbl_file_exists.setText("")
        self.label_5.setText(
            QCoreApplication.translate("dlg_new_tool", u"File name:", None)
        )
        self.chk_mask_required.setText(
            QCoreApplication.translate("dlg_new_tool", u"Requires mask in input", None)
        )
        self.label_4.setText(u"\ud83e\udc62")
        self.label_6.setText(u"\ud83e\udc62")
        self.label_3.setText(
            QCoreApplication.translate("dlg_new_tool", u"Class name", None)
        )
        self.label_2.setText(
            QCoreApplication.translate("dlg_new_tool", u"Description:", None)
        )
        self.label_7.setText(
            QCoreApplication.translate("dlg_new_tool", u"Package:", None)
        )
        self.groupBox.setTitle(
            QCoreApplication.translate("dlg_new_tool", u"Output:", None)
        )
        self.rb_output_image.setText(
            QCoreApplication.translate("dlg_new_tool", u"Image", None)
        )
        self.rb_output_mask.setText(
            QCoreApplication.translate("dlg_new_tool", u"Mask", None)
        )
        self.rb_output_data.setText(
            QCoreApplication.translate("dlg_new_tool", u"Data", None)
        )
        self.rb_output_none.setText(
            QCoreApplication.translate("dlg_new_tool", u"None", None)
        )
        self.gb_pipeline_tool_groups.setTitle(
            QCoreApplication.translate(
                "dlg_new_tool", u"Groups that can be added to pipelines", None
            )
        )
        self.groupBox_2.setTitle(
            QCoreApplication.translate("dlg_new_tool", u"Real time:", None)
        )
        self.rb_rt_yes.setText(QCoreApplication.translate("dlg_new_tool", u"Yes", None))
        self.rb_rt_no.setText(QCoreApplication.translate("dlg_new_tool", u"No", None))
        self.rb_rt_widget.setText(
            QCoreApplication.translate("dlg_new_tool", u"Widget", None)
        )
        self.rb_rt_property.setText(
            QCoreApplication.translate("dlg_new_tool", u"Property", None)
        )
        self.gb_no_pipeline_tool_groups.setTitle(
            QCoreApplication.translate(
                "dlg_new_tool", u"Groups forbiden in pipelines", None
            )
        )
        self.bt_save.setText(QCoreApplication.translate("dlg_new_tool", u"Save", None))
        self.bt_cancel.setText(
            QCoreApplication.translate("dlg_new_tool", u"Close", None)
        )
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()