def on_select_area(self): for node in self.radio_button_to_node.keys(): node.deleteLater() self.radio_button_to_node.clear() current_area = self.current_area if not current_area: self.new_node_button.setEnabled(False) self.delete_node_button.setEnabled(False) return is_first = True for node in sorted(current_area.nodes, key=lambda x: x.name): button = QRadioButton(self.points_of_interest_group) button.setText(node.name) self.radio_button_to_node[button] = node if is_first: self.selected_node_button = button button.setChecked(is_first) button.toggled.connect(self.on_select_node) is_first = False self.verticalLayout.addWidget(button) self.new_node_button.setEnabled(True) self.delete_node_button.setEnabled(len(current_area.nodes) > 1) self.update_selected_node()
def create_history_item(self, node): button = QRadioButton(self.layout_history_content) button.toggled.connect(self.on_select_node) button.setText(node) self.layout_history_content_layout.addWidget(button) self._history_items.append(button) return button
class LayoutBox(QGroupBox): def __init__(self, parent=None, size: QSize = QSize(10, 10), lang: LangEnum = LangEnum.ENG, log_handlers: [StreamHandler] = None): self.logger = getLogger(__name__) if log_handlers: for h in log_handlers: self.logger.addHandler(h) self.logger.debug("Initializing") super().__init__(parent) self.setLayout(QVBoxLayout()) self.setMaximumSize(size) self._horizontal_button = QRadioButton(self) self._horizontal_button.clicked.connect(self._horizontal_toggled) self._vertical_button = QRadioButton(self) self._vertical_button.clicked.connect(self._vertical_toggled) self._tiled_button = QRadioButton(self) self._tiled_button.clicked.connect(self._tiled_toggled) self._cascade_button = QRadioButton(self) self._cascade_button.clicked.connect(self._cascade_toggled) self.layout().addWidget(self._horizontal_button) self.layout().addWidget(self._vertical_button) self.layout().addWidget(self._tiled_button) self.layout().addWidget(self._cascade_button) self._layout_callback = None self._strings = dict() self.set_lang(lang) self.logger.debug("Initialized") def set_lang(self, lang: LangEnum) -> None: """ Set the language for this view object. :param lang: The enum for the language. :return None: """ self._strings = strings[lang] self._set_texts() def add_window_layout_handler(self, func: classmethod) -> None: """ Add handler for window layout. :param func: The handler function :return None: """ self._layout_callback = func def _horizontal_toggled(self): self.logger.debug("running") if self._horizontal_button.isChecked(): self._layout_callback("horizontal") self.logger.debug("done") def _vertical_toggled(self): self.logger.debug("running") if self._vertical_button.isChecked(): self._layout_callback("vertical") self.logger.debug("done") def _tiled_toggled(self): self.logger.debug("running") if self._tiled_button.isChecked(): self._layout_callback("tiled") self.logger.debug("done") def _cascade_toggled(self): self.logger.debug("running") if self._cascade_button.isChecked(): self._layout_callback("cascade") self.logger.debug("done") def _set_texts(self) -> None: """ Set the texts of this view item :return None: """ self.logger.debug("running") self.setTitle(self._strings[StringsEnum.LAYOUT]) self._horizontal_button.setText(self._strings[StringsEnum.HORIZONTAL]) self._vertical_button.setText(self._strings[StringsEnum.VERTICAL]) self._tiled_button.setText(self._strings[StringsEnum.TILED]) self._cascade_button.setText(self._strings[StringsEnum.CASCADE]) self.logger.debug("done")
def _init_widgets(self): layout = QGridLayout() row = 0 header_label = QLabel(self) header_label.setText("Exploration strategy:") layout.addWidget(header_label, row, 0) row += 1 options_container = QGroupBox(self) options = QVBoxLayout() for strategy, cls in sorted( angr.exploration_techniques.__dict__.items()): if hasattr( cls, "mro" ) and angr.exploration_techniques.ExplorationTechnique in type.mro( cls): child = QRadioButton() child.setText(strategy) child.strategy = strategy child.toggled.connect(self.selected) options.addWidget(child) self.strategies[strategy] = cls scroll_area = QScrollArea(self) scroll_area.setWidgetResizable(True) widget = QWidget() scroll_area.setWidget(widget) layout_scroll = QVBoxLayout(widget) layout_scroll.addWidget(options_container) options_container.setLayout(options) layout.addWidget(scroll_area, row, 0) row += 1 constructor_box = QPlainTextEdit(self) highlight = PythonHighlighter(constructor_box.document()) constructor_box.setWordWrapMode(QTextOption.WordWrap) self._constructor_box = constructor_box layout.addWidget(constructor_box, row, 0) row += 1 # buttons ok_button = QPushButton(self) ok_button.setText('OK') def do_ok(): constructor_txt = constructor_box.toPlainText() try: strategy = eval(constructor_txt) strategy.project = self.instance.project self.simgr.strategies[strategy.__class__.__name__] = strategy self.close() except NameError as e: # error QMessageBox.about( self, 'Error', f"{str(e)}, \nMake sure to fill in all positional arguments." ) ok_button.clicked.connect(do_ok) cancel_button = QPushButton(self) cancel_button.setText('Cancel') def do_cancel(): self.close() cancel_button.clicked.connect(do_cancel) buttons_layout = QHBoxLayout() buttons_layout.addWidget(ok_button) buttons_layout.addWidget(cancel_button) self.main_layout.addLayout(layout) self.main_layout.addLayout(buttons_layout)
def _init_widgets(self): if len(self.strategies) == 0: QMessageBox.about( self, 'Error', "No strategies available\nCreate a strategy in Symbolic Execution -> Settings -> Add Strategy" ) return layout = QGridLayout() row = 0 addr = self.instance.project.entry if self._addr is None else self._addr function = self.instance.project.kb.functions.floor_func(addr) fn_name = function.name fn_addr = function.addr header_label = QLabel(self) header_label.setText( f"Exploration strategy for function {fn_name} @ address {hex(fn_addr)}:" ) layout.addWidget(header_label, row, 0) row += 1 options_container = QGroupBox(self) options = QVBoxLayout() for strategy, cls in self.strategies.items(): child = QRadioButton() child.setText(strategy) child.strategy = strategy child.toggled.connect(self.selected) options.addWidget(child) scroll_area = QScrollArea(self) scroll_area.setWidgetResizable(True) widget = QWidget() scroll_area.setWidget(widget) layout_scroll = QVBoxLayout(widget) layout_scroll.addWidget(options_container) options_container.setLayout(options) layout.addWidget(scroll_area, row, 0) row += 1 # buttons ok_button = QPushButton(self) ok_button.setText('OK') def do_ok( ): # TODO: parse call insn for this function and set end of explore at that addr if self._selected is not None: self.simgr.fn_strategy[ fn_addr] = self._selected # TODO: select from options self.close() ok_button.clicked.connect(do_ok) # TODO: add validation for OK button enable/disable def validation_update(): ok_button.setDisabled(bool(validation_failures)) cancel_button = QPushButton(self) cancel_button.setText('Cancel') def do_cancel(): self.close() cancel_button.clicked.connect(do_cancel) buttons_layout = QHBoxLayout() buttons_layout.addWidget(ok_button) buttons_layout.addWidget(cancel_button) self.main_layout.addLayout(layout) self.main_layout.addLayout(buttons_layout)
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))
def _init_widgets(self): layout = QGridLayout() row = 0 # validation_failures = set() addr = hex(self._addr) address_label = QLabel(self) address_label.setText(f"Hook at address {addr}:") layout.addWidget(address_label, row, 0) row += 1 options_container = QGroupBox(self) options = QVBoxLayout() for name, template in sorted(self.templates.items()): child = QRadioButton() child.setText(name) child.template = template child.toggled.connect(self.selected) options.addWidget(child) scroll_area = QScrollArea(self) scroll_area.setWidgetResizable(True) widget = QWidget() scroll_area.setWidget(widget) layout_scroll = QVBoxLayout(widget) header_label = QLabel(self) header_label.setText("Presets:") layout_scroll.addWidget(header_label) layout_scroll.addWidget(options_container) options_container.setLayout(options) layout.addWidget(scroll_area, row, 0) row += 1 function_box = QPlainTextEdit(self) if addr in self.hooks.keys(): function_box.insertPlainText(self.hooks[addr]) highlight = PythonHighlighter(function_box.document()) function_box.setWordWrapMode(QTextOption.WordWrap) self._function_box = function_box layout.addWidget(function_box, row, 0) row += 1 # def add_indent(): # txt = function_box.toPlainText() # if txt.endswith('\n'): # embed() # indent = txt.search() # if txt.endswith(':\n'): # function_box.insertPlainText(' ') # function_box.textChanged.connect(add_indent) # TODO: add python autoindent # buttons ok_button = QPushButton(self) ok_button.setText('OK') def do_ok(): hook_code_string = function_box.toPlainText() self.instance.apply_hook(self._addr, hook_code_string) self.hooks[hex(self._addr)] = hook_code_string disasm_view = self.instance.workspace.view_manager.first_view_in_category( "disassembly") # So the hook icon shows up in the disasm view disasm_view.refresh() self.close() ok_button.clicked.connect(do_ok) cancel_button = QPushButton(self) cancel_button.setText('Cancel') def do_cancel(): self.close() cancel_button.clicked.connect(do_cancel) buttons_layout = QHBoxLayout() buttons_layout.addWidget(ok_button) buttons_layout.addWidget(cancel_button) self.main_layout.addLayout(layout) self.main_layout.addLayout(buttons_layout)
def setupUi(self, MainWindow): def fun(spoiler): if spoiler.isOpened(): spoiler.close() else: spoiler.open() # app = QApplication(sys.argv) w = QMainWindow() cw = QWidget() mainLayout = QHBoxLayout() cw.setLayout(mainLayout) gridLayout = QGridLayout() spacerItem1 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) gridLayout.addItem(spacerItem1, 0, 0, 1, 1) pushButton1 = QPushButton() pushButton1.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Preferred) pushButton1.setText("") # gridLayout.addWidget(pushButton1, 0, 1, 1, 1) self.label1 = QLabel() self.label1.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum) self.label1.setObjectName("") gridLayout.addWidget(self.label1, 0, 2, 1, 1) datePicker1 = DatePicker() gridLayout.addWidget(datePicker1, 0, 1, 1, 1) datePicker1.selectionChanged.connect(lambda: self.__setLableDate__( self.label1, datePicker1.selectedDate())) spacerItem2 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) gridLayout.addItem(spacerItem2, 0, 3, 1, 1) self.label2 = QLabel() self.label2.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum) self.label2.setObjectName("") gridLayout.addWidget(self.label2, 0, 4, 1, 1) datePicker2 = DatePicker() gridLayout.addWidget(datePicker2, 0, 5, 1, 1) datePicker2.selectionChanged.connect(lambda: self.__setLableDate__( self.label2, datePicker2.selectedDate())) pushButton2 = QPushButton() pushButton2.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Preferred) pushButton2.setText("") #gridLayout.addWidget(pushButton2, 0, 5, 1, 1) spacerItem3 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) gridLayout.addItem(spacerItem3, 0, 6, 1, 1) groupBox = QGroupBox() groupBox.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Maximum) verticalLayout = QVBoxLayout(groupBox) radioButton1 = QRadioButton(groupBox) radioButton1.setText("Subscribers") verticalLayout.addWidget(radioButton1) radioButton2 = QRadioButton(groupBox) radioButton1.setText("PatientsServices") verticalLayout.addWidget(radioButton2) export_btn = QPushButton() export_btn.setText("export") gridLayout.addWidget(export_btn) export_btn.clicked.connect(lambda: self.onExport_btn()) gridLayout.addWidget(groupBox, 1, 1, 1, 2, Qt.AlignTop) self.comboBox = QComboBox() self.h_values = [ "all", "مستشفي الصفوة الدولي", "مختبر مصراتة المركزي", "مستشفى الحكمه الحديث" ] self.comboBox.addItems(self.h_values) if self.comboBox.currentIndex() == 1: print("kln") self.comboBox.activated.connect(self.oncomboBoxChanged) gridLayout.addWidget(self.comboBox, 1, 4, 1, 2, Qt.AlignTop) btn = QPushButton("Click me") btn.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum) spoiler = Spoiler(Spoiler.Orientation.VERTICAL) spoiler.setContentLayout(gridLayout) mainLayout.addWidget(btn) #self.searchGridLayout.addWidget(spoiler) # mainLayout.setAlignment(Qt.AlignRight) MainWindow.setObjectName(_fromUtf8("MainWindow")) MainWindow.resize(716, 392) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName(_fromUtf8("centralwidget")) self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget) self.verticalLayout.setObjectName(_fromUtf8("verticalLayout")) self.tabWidget = QtWidgets.QTabWidget(self.centralwidget) self.tabWidget.setTabsClosable(False) self.tabWidget.setObjectName(_fromUtf8("tabWidget")) self.InsertTab = QtWidgets.QWidget() self.InsertTab.setObjectName(_fromUtf8("InsertTab")) self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.InsertTab) self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2")) spacerItem = QtWidgets.QSpacerItem(20, 109, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) self.verticalLayout_2.addItem(spacerItem) self.insertGridLayout = QtWidgets.QGridLayout() self.insertGridLayout.setObjectName(_fromUtf8("insertGridLayout")) self.runBtn = QtWidgets.QPushButton(self.InsertTab) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.runBtn.sizePolicy().hasHeightForWidth()) self.runBtn.setSizePolicy(sizePolicy) self.runBtn.setMouseTracking(False) self.runBtn.setAutoFillBackground(False) self.runBtn.setStyleSheet(_fromUtf8("border: none")) self.runBtn.setText(_fromUtf8("")) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(_fromUtf8("icons/run.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.runBtn.setIcon(icon) self.runBtn.setIconSize(QtCore.QSize(64, 64)) self.runBtn.setObjectName(_fromUtf8("runBtn")) self.insertGridLayout.addWidget(self.runBtn, 0, 3, 2, 1) spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self.combo = QComboBox() self.values = [ "مستشفي الصفوة الدولي", "مختبر مصراتة المركزي", "مستشفى الحكمه الحديث", "مستشفى المدينه السكنيه" ] self.combo.addItems(self.values) if self.combo.currentIndex() == 1: print("kln") self.combo.activated.connect(self.oncomboChanged) self.insertGridLayout.addWidget(self.combo, 1, 4, 1, 2, Qt.AlignTop) self.insertGridLayout.addItem(spacerItem1, 0, 5, 1, 1) self.excelLabel = QtWidgets.QLabel(self.InsertTab) self.excelLabel.setText(_fromUtf8("")) self.excelLabel.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter) self.excelLabel.setObjectName(_fromUtf8("excelLabel")) self.insertGridLayout.addWidget(self.excelLabel, 1, 0, 1, 3) self.sqlBtn = QtWidgets.QPushButton(self.InsertTab) self.sqlBtn.setMinimumSize(QtCore.QSize(200, 0)) self.sqlBtn.setObjectName(_fromUtf8("sqlBtn")) self.insertGridLayout.addWidget(self.sqlBtn, 0, 4, 1, 1) self.excelBtn = QtWidgets.QPushButton(self.InsertTab) self.excelBtn.setMinimumSize(QtCore.QSize(200, 0)) self.excelBtn.setObjectName(_fromUtf8("excelBtn")) self.insertGridLayout.addWidget(self.excelBtn, 0, 2, 1, 1) spacerItem2 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self.insertGridLayout.addItem(spacerItem2, 0, 1, 1, 1) self.sqlLabel = QtWidgets.QLabel(self.InsertTab) self.sqlLabel.setText(_fromUtf8("")) self.sqlLabel.setObjectName(_fromUtf8("sqlLabel")) self.insertGridLayout.addWidget(self.sqlLabel, 1, 4, 1, 2) self.verticalLayout_2.addLayout(self.insertGridLayout) spacerItem3 = QtWidgets.QSpacerItem(20, 108, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) self.verticalLayout_2.addItem(spacerItem3) self.tabWidget.addTab(self.InsertTab, _fromUtf8("")) # self.filterBtn = QtWidgets.QPushButton(self.searchTab) # self.filterBtn.setStyleSheet(_fromUtf8("border: none")) # icon2 = QtGui.QIcon() # icon2.addPixmap(QtGui.QPixmap(_fromUtf8("icons/filter_icon.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) # self.filterBtn.setIcon(icon2) # self.filterBtn.setObjectName(_fromUtf8("filterBtn")) # self.searchGridLayout.addWidget(self.filterBtn, 0, 3, 1, 1) # self.searchGridLayout.addWidget(spoiler) self.export_btn = QPushButton() self.export_btn.setText("export") #self.gridLayout.addWidget(export_btn) self.export_btn.clicked.connect(lambda: self.onExport_btnSubscribers()) #self.exprt_btn = QtWidgets.QPushButton() #self.exprt_btn.setText("export") #self.exprt_btn.setObjectName(_fromUtf8("exprt_btn")) #self.searchGridLayout1.addWidget(self.exprt_btn, 0, 0, 2, 1) self.verticalLayout.addWidget(self.tabWidget) MainWindow.setCentralWidget(self.centralwidget) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName(_fromUtf8("statusbar")) MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) self.tabWidget.setCurrentIndex(1) QtCore.QMetaObject.connectSlotsByName(MainWindow) self.excelBtn.clicked.connect(MainWindow, QtCore.SLOT("onExcelBtnClick()")) self.sqlBtn.clicked.connect(MainWindow, QtCore.SLOT("onSqlBtnClick()")) self.runBtn.clicked.connect(MainWindow, QtCore.SLOT("onRunBtnClick()")) self.excelFileName = None self.sqlFileName = "/home/eamon/Desktop/test.sqlite" self.sqlLabel.setText(self.sqlFileName) conn = sqlite3.connect("C:\\Users\\PC WORLD\\Downloads\\test.sqlite") result = conn.execute("SELECT * FROM Subscribers") conn.close()
class App(QWidget): def __init__(self, bk, prefs): super().__init__() self.bk = bk self.prefs = prefs self.update = False # Install translator for the DOCXImport plugin dialog. # Use the Sigil language setting unless manually overridden. plugin_translator = QTranslator() if prefs['language_override'] is not None: print('Plugin preferences language override in effect') qmf = '{}_{}'.format(bk._w.plugin_name.lower(), prefs['language_override']) else: qmf = '{}_{}'.format(bk._w.plugin_name.lower(), bk.sigil_ui_lang) print( qmf, os.path.join(bk._w.plugin_dir, bk._w.plugin_name, 'translations')) plugin_translator.load( qmf, os.path.join(bk._w.plugin_dir, bk._w.plugin_name, 'translations')) print(QCoreApplication.instance().installTranslator(plugin_translator)) self._ok_to_close = False self.FTYPE_MAP = { 'smap': { 'title': _translate('App', 'Select custom style-map file'), 'defaultextension': '.txt', 'filetypes': 'Text Files (*.txt);;All files (*.*)', }, 'css': { 'title': _translate('App', 'Select custom CSS file'), 'defaultextension': '.css', 'filetypes': 'CSS Files (*.css)', }, 'docx': { 'title': _translate('App', 'Select DOCX file'), 'defaultextension': '.docx', 'filetypes': 'DOCX Files (*.docx)', }, } # Check online github files for newer version if self.prefs['check_for_updates']: self.update, self.newversion = self.check_for_update() self.initUI() def initUI(self): main_layout = QVBoxLayout(self) self.setWindowTitle('DOCXImport') self.upd_layout = QVBoxLayout() self.update_label = QLabel() self.update_label.setAlignment(Qt.AlignCenter) self.upd_layout.addWidget(self.update_label) self.get_update_button = QPushButton() self.get_update_button.clicked.connect(self.get_update) self.upd_layout.addWidget(self.get_update_button) main_layout.addLayout(self.upd_layout) if not self.update: self.update_label.hide() self.get_update_button.hide() self.details_grid = QGridLayout() self.epub2_select = QRadioButton() self.epub2_select.setText('EPUB2') self.epubType = QButtonGroup() self.epubType.addButton(self.epub2_select) self.details_grid.addWidget(self.epub2_select, 0, 0, 1, 1) self.checkbox_get_updates = QCheckBox() self.details_grid.addWidget(self.checkbox_get_updates, 0, 1, 1, 1) self.epub3_select = QRadioButton() self.epub3_select.setText('EPUB3') self.epubType.addButton(self.epub3_select) self.details_grid.addWidget(self.epub3_select, 1, 0, 1, 1) main_layout.addLayout(self.details_grid) self.checkbox_get_updates.setChecked(self.prefs['check_for_updates']) if self.prefs['epub_version'] == '2.0': self.epub2_select.setChecked(True) elif self.prefs['epub_version'] == '3.0': self.epub3_select.setChecked(True) else: self.epub2_select.setChecked(True) self.groupBox = QGroupBox() self.groupBox.setTitle('') self.verticalLayout_2 = QVBoxLayout(self.groupBox) self.docx_grid = QGridLayout() self.docx_label = QLabel() self.docx_grid.addWidget(self.docx_label, 0, 0, 1, 1) self.docx_path = QLineEdit() self.docx_grid.addWidget(self.docx_path, 1, 0, 1, 1) self.choose_docx_button = QPushButton() self.choose_docx_button.setText('...') self.docx_grid.addWidget(self.choose_docx_button, 1, 1, 1, 1) self.verticalLayout_2.addLayout(self.docx_grid) self.choose_docx_button.clicked.connect( lambda: self.fileChooser('docx', self.docx_path)) if len(self.prefs['lastDocxPath']): self.docx_path.setText(self.prefs['lastDocxPath']) self.docx_path.setEnabled(False) self.smap_grid = QGridLayout() self.checkbox_smap = QCheckBox(self.groupBox) self.smap_grid.addWidget(self.checkbox_smap, 0, 0, 1, 1) self.cust_smap_path = QLineEdit(self.groupBox) self.smap_grid.addWidget(self.cust_smap_path, 1, 0, 1, 1) self.choose_smap_button = QPushButton(self.groupBox) self.choose_smap_button.setText('...') self.smap_grid.addWidget(self.choose_smap_button, 1, 1, 1, 1) self.verticalLayout_2.addLayout(self.smap_grid) self.checkbox_smap.setChecked(self.prefs['useSmap']) self.checkbox_smap.stateChanged.connect(lambda: self.chkBoxActions( self.checkbox_smap, self.choose_smap_button)) self.choose_smap_button.clicked.connect( lambda: self.fileChooser('smap', self.cust_smap_path, self. checkbox_smap, self.choose_smap_button)) if len(self.prefs['useSmapPath']): self.cust_smap_path.setText(self.prefs['useSmapPath']) self.cust_smap_path.setEnabled(False) self.chkBoxActions(self.checkbox_smap, self.choose_smap_button) self.css_grid = QGridLayout() self.checkbox_css = QCheckBox(self.groupBox) self.css_grid.addWidget(self.checkbox_css, 0, 0, 1, 1) self.cust_css_path = QLineEdit(self.groupBox) self.css_grid.addWidget(self.cust_css_path, 1, 0, 1, 1) self.choose_css_button = QPushButton(self.groupBox) self.choose_css_button.setText('...') self.css_grid.addWidget(self.choose_css_button, 1, 1, 1, 1) self.verticalLayout_2.addLayout(self.css_grid) self.checkbox_css.setChecked(self.prefs['useCss']) self.checkbox_css.stateChanged.connect(lambda: self.chkBoxActions( self.checkbox_css, self.choose_css_button)) self.choose_css_button.clicked.connect( lambda: self.fileChooser('css', self.cust_css_path, self. checkbox_css, self.choose_css_button)) if len(self.prefs['useCssPath']): self.cust_css_path.setText(self.prefs['useCssPath']) self.cust_css_path.setEnabled(False) self.chkBoxActions(self.checkbox_css, self.choose_css_button) main_layout.addWidget(self.groupBox) self.checkbox_debug = QCheckBox() main_layout.addWidget(self.checkbox_debug) self.checkbox_debug.setChecked(self.prefs['debug']) spacerItem = QSpacerItem(20, 15, QSizePolicy.Minimum, QSizePolicy.Expanding) main_layout.addItem(spacerItem) button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) button_box.accepted.connect(self._ok_clicked) button_box.rejected.connect(self._cancel_clicked) main_layout.addWidget(button_box) self.retranslateUi(self) if self.prefs['qt_geometry'] is not None: try: self.restoreGeometry( QByteArray.fromHex( self.prefs['qt_geometry'].encode('ascii'))) except: pass self.show() def retranslateUi(self, App): self.update_label.setText(_translate('App', 'Plugin Update Available')) self.get_update_button.setText(_translate('App', 'Go to download page')) self.checkbox_get_updates.setText( _translate('App', 'Check for plugin updates')) self.docx_label.setText(_translate('App', 'DOCX File to import')) self.checkbox_smap.setText(_translate('App', 'Use Custom Style Map')) self.checkbox_css.setText(_translate('App', 'Use Custom CSS')) self.checkbox_debug.setText( _translate('App', 'Debug Mode (change takes effect next plugin run)')) def fileChooser(self, ftype, qlineedit, qcheck=None, qbutton=None): options = QFileDialog.Options() options |= QFileDialog.DontUseNativeDialog title = self.FTYPE_MAP[ftype]['title'] startfolder = self.prefs['lastDir'][ftype] ffilter = self.FTYPE_MAP[ftype]['filetypes'] inpath, _ = QFileDialog.getOpenFileName(self, title, startfolder, ffilter, options=options) if len(inpath): qlineedit.setEnabled(True) qlineedit.setText(os.path.normpath(inpath)) self.prefs['lastDir'][ftype] = os.path.dirname(inpath) qlineedit.setEnabled(False) else: if qcheck is not None: qcheck.setChecked(False) if qbutton is not None: qbutton.setEnabled(False) def chkBoxActions(self, chk, btn): btn.setEnabled(chk.isChecked()) def cmdDo(self): global _DETAILS self.prefs['qt_geometry'] = self.saveGeometry().toHex().data().decode( 'ascii') self.prefs['check_for_updates'] = self.checkbox_get_updates.isChecked() self.prefs['epub_version'] = self.epubType.checkedButton().text( )[-1] + '.0' self.prefs['debug'] = self.checkbox_debug.isChecked() _DETAILS['vers'] = self.epubType.checkedButton().text()[-1] + '.0' self.prefs['useSmap'] = self.checkbox_smap.isChecked() if self.checkbox_smap.isChecked(): if len(self.cust_smap_path.text()): self.prefs['useSmapPath'] = self.cust_smap_path.text() _DETAILS['smap'] = (self.checkbox_smap.isChecked(), self.cust_smap_path.text()) else: # Message box that no file is selected return self.prefs['useCss'] = self.checkbox_css.isChecked() if self.checkbox_css.isChecked(): if len(self.cust_css_path.text()): self.prefs['useCssPath'] = self.cust_css_path.text() _DETAILS['css'] = (self.checkbox_css.isChecked(), self.cust_css_path.text()) else: # Message box that no file is selected return if len(self.docx_path.text()): self.prefs['lastDocxPath'] = self.docx_path.text() _DETAILS['docx'] = self.docx_path.text() else: # Message box that no file is selected return def check_for_update(self): '''Use updatecheck.py to check for newer versions of the plugin''' chk = UpdateChecker(self.prefs['last_time_checked'], self.bk._w) update_available, online_version, time = chk.update_info() # update preferences with latest date/time/version self.prefs['last_time_checked'] = time if online_version is not None: self.prefs['last_online_version'] = online_version if update_available: return (True, online_version) return (False, online_version) def get_update(self): url = DOWNLOAD_PAGE if self.update: latest = '/tag/v{}'.format(self.newversion) url = url + latest webbrowser.open_new_tab(url) def _ok_clicked(self): self._ok_to_close = True self.cmdDo() self.bk.savePrefs(self.prefs) QCoreApplication.instance().quit() def _cancel_clicked(self): self._ok_to_close = True '''Close aborting any changes''' self.prefs['qt_geometry'] = self.saveGeometry().toHex().data().decode( 'ascii') self.prefs['check_for_updates'] = self.checkbox_get_updates.isChecked() self.prefs['debug'] = self.checkbox_debug.isChecked() self.bk.savePrefs(self.prefs) QCoreApplication.instance().quit() def closeEvent(self, event): if self._ok_to_close: event.accept() # let the window close else: self._cancel_clicked()
class NumberConversion(QWidget): def __init__(self): super(NumberConversion, self).__init__() # App attributes self.bin_format_base = None self.bin_format_base_byte = None # Use language settings self.ml = ManageLng() main_layout = QGridLayout() self.setLayout(main_layout) # Input self.inputbox = QGroupBox( self.ml.get_tr_text("tab_num_conv_inputbox_gbox_name")) self.inputbox.setMaximumWidth(400) main_layout.addWidget(self.inputbox, 0, 0) inputbox_layout = QGridLayout() inputbox_layout.setHorizontalSpacing(25) inputbox_layout.setVerticalSpacing(35) inputbox_layout.setAlignment(Qt.AlignCenter) self.inputbox.setLayout(inputbox_layout) self.input_number_label = QLabel( self.ml.get_tr_text("tab_num_conv_inputbox_in_number_lab")) self.input_number_textfield = QLineEdit() self.input_number_textfield.setPlaceholderText("192") self.input_number_textfield.setAlignment(Qt.AlignCenter) self.input_number_textfield.returnPressed.connect(self.convert_action) inputbox_layout.addWidget(self.input_number_label, 0, 0, alignment=Qt.AlignCenter) inputbox_layout.addWidget(self.input_number_textfield, 0, 1) button_layout = QVBoxLayout() self.bin_button = QRadioButton( self.ml.get_tr_text("tab_num_conv_inputbox_bin_chkbox")) self.bin_button.clicked.connect( lambda: self.input_number_textfield.setPlaceholderText("11100010")) self.dec_button = QRadioButton( self.ml.get_tr_text("tab_num_conv_inputbox_dec_chkbox")) self.dec_button.clicked.connect( lambda: self.input_number_textfield.setPlaceholderText("192")) self.hex_button = QRadioButton( self.ml.get_tr_text("tab_num_conv_inputbox_hex_chkbox")) self.hex_button.clicked.connect( lambda: self.input_number_textfield.setPlaceholderText("FF")) self.dec_button.setChecked(True) button_layout.addWidget(self.bin_button) button_layout.addWidget(self.dec_button) button_layout.addWidget(self.hex_button) inputbox_layout.addLayout(button_layout, 0, 3, 1, 2) self.convert_button = QPushButton( self.ml.get_tr_text("tab_num_conv_inputbox_conv_btn")) self.convert_button.clicked.connect(self.convert_action) self.convert_button.setIcon(QIcon("static/images/exchange.png")) inputbox_layout.addWidget(self.convert_button, 1, 1, alignment=Qt.AlignCenter) # Output self.outputbox = QGroupBox( self.ml.get_tr_text("tab_num_conv_outputbox_gbox_name")) main_layout.addWidget(self.outputbox, 0, 1) outputbox_layout = QGridLayout() outputbox_layout.setHorizontalSpacing(25) self.outputbox.setLayout(outputbox_layout) self.bin_label = QLabel( self.ml.get_tr_text("tab_num_conv_outputbox_bin_lab")) self.bin_label.setAlignment(Qt.AlignCenter) self.dec_label = QLabel( self.ml.get_tr_text("tab_num_conv_outputbox_dec_lab")) self.dec_label.setAlignment(Qt.AlignCenter) self.hex_label = QLabel( self.ml.get_tr_text("tab_num_conv_outputbox_hex_lab")) self.hex_label.setAlignment(Qt.AlignCenter) self.bin_output = QLineEdit() self.bin_output.setReadOnly(True) self.bin_output.setAlignment(Qt.AlignCenter) self.dec_output = QLineEdit() self.dec_output.setReadOnly(True) self.dec_output.setAlignment(Qt.AlignCenter) self.hex_output = QLineEdit() self.hex_output.setReadOnly(True) self.hex_output.setAlignment(Qt.AlignCenter) self.bin_output_copy_button = QPushButton( self.ml.get_tr_text("tab_num_conv_outputbox_copy_btn")) self.bin_output_copy_button.setIcon( QIcon("static/images/copy_clipboard.png")) self.bin_output_copy_button.clicked.connect( lambda: copy_action(self.bin_output.text())) self.dec_output_copy_button = QPushButton( self.ml.get_tr_text("tab_num_conv_outputbox_copy_btn")) self.dec_output_copy_button.setIcon( QIcon("static/images/copy_clipboard.png")) self.dec_output_copy_button.clicked.connect( lambda: copy_action(self.dec_output.text())) self.hex_output_copy_button = QPushButton( self.ml.get_tr_text("tab_num_conv_outputbox_copy_btn")) self.hex_output_copy_button.setIcon( QIcon("static/images/copy_clipboard.png")) self.hex_output_copy_button.clicked.connect( lambda: copy_action(self.hex_output.text())) outputbox_layout.addWidget(self.bin_label, 0, 0) outputbox_layout.addWidget(self.bin_output, 0, 1) outputbox_layout.addWidget(self.bin_output_copy_button, 0, 2) outputbox_layout.addWidget(self.dec_label, 1, 0) outputbox_layout.addWidget(self.dec_output, 1, 1) outputbox_layout.addWidget(self.dec_output_copy_button, 1, 2) outputbox_layout.addWidget(self.hex_label, 2, 0) outputbox_layout.addWidget(self.hex_output, 2, 1) outputbox_layout.addWidget(self.hex_output_copy_button, 2, 2) # IP address/mask number conversion self.ip_address_number_conversion_box = QGroupBox( self.ml.get_tr_text("tab_num_conv_ip_mask_conv_gbox_name")) main_layout.addWidget(self.ip_address_number_conversion_box, 1, 0, 1, 2) ip_address_number_conversion_layout = QGridLayout() ip_address_number_conversion_layout.setAlignment(Qt.AlignCenter) ip_address_number_conversion_layout.setHorizontalSpacing(25) ip_address_number_conversion_layout.setVerticalSpacing(24) self.ip_address_number_conversion_box.setLayout( ip_address_number_conversion_layout) self.input_label = QLabel( self.ml.get_tr_text("tab_num_conv_ip_mask_conv_in_lab")) self.input_label.setAlignment(Qt.AlignCenter) self.input_label.setMaximumWidth(150) self.input_textfield = QLineEdit() self.input_textfield.setPlaceholderText("192.168.1.1") self.input_textfield.setAlignment(Qt.AlignLeft) self.input_textfield.setMaximumWidth(300) self.input_textfield.setAlignment(Qt.AlignCenter) self.input_textfield.returnPressed.connect(self.convert_action_2) ip_address_number_conversion_layout.addWidget(self.input_label, 0, 0) ip_address_number_conversion_layout.addWidget(self.input_textfield, 0, 1) button_layout_2 = QVBoxLayout() self.dec_to_bin_button = QRadioButton( self.ml.get_tr_text("tab_num_conv_ip_mask_conv_dectobin")) self.dec_to_bin_button.clicked.connect( lambda: self.input_textfield.setPlaceholderText("192.168.1.1")) self.dec_to_bin_button.setMaximumWidth(150) self.bin_to_dec_button = QRadioButton( self.ml.get_tr_text("tab_num_conv_ip_mask_conv_bintodec")) self.bin_to_dec_button.clicked.connect( lambda: self.input_textfield.setPlaceholderText( "11000000.10101000.00000001.00000001")) self.bin_to_dec_button.setMaximumWidth(150) self.dec_to_bin_button.setChecked(True) button_layout_2.addWidget(self.dec_to_bin_button) button_layout_2.addWidget(self.bin_to_dec_button) ip_address_number_conversion_layout.addLayout(button_layout_2, 0, 2) self.output_label = QLabel( self.ml.get_tr_text("tab_num_conv_ip_mask_conv_out_lab")) self.output_label.setAlignment(Qt.AlignCenter) self.output_textfield = QLineEdit() self.output_textfield.setMaximumWidth(300) self.output_textfield.setReadOnly(True) self.output_textfield.setAlignment(Qt.AlignCenter) ip_address_number_conversion_layout.addWidget(self.output_label, 1, 0) ip_address_number_conversion_layout.addWidget(self.output_textfield, 1, 1) self.output_textfield_copy_button = QPushButton( self.ml.get_tr_text("tab_num_conv_ip_mask_conv_copy_btn")) self.output_textfield_copy_button.setIcon( QIcon("static/images/copy_clipboard.png")) self.output_textfield_copy_button.clicked.connect( lambda: copy_action(self.output_textfield.text())) ip_address_number_conversion_layout.addWidget( self.output_textfield_copy_button, 1, 2, alignment=Qt.AlignLeft) self.convert_button_2 = QPushButton( self.ml.get_tr_text("tab_num_conv_ip_mask_conv_convert_btn")) self.convert_button_2.clicked.connect(self.convert_action_2) self.convert_button_2.setIcon(QIcon("static/images/exchange.png")) ip_address_number_conversion_layout.addWidget( self.convert_button_2, 2, 0, 1, 3, alignment=Qt.AlignHCenter) def convert_action(self): if is_empty(self.input_number_textfield.text()): PopupWindow("warning", self.ml.get_tr_text("tab_num_conv_warning01"), self.input_number_textfield) else: if self.bin_button.isChecked(): self.source_bin(self.input_number_textfield.text()) elif self.dec_button.isChecked(): self.source_dec(self.input_number_textfield.text()) else: self.source_hex(self.input_number_textfield.text()) def source_bin(self, bin_number): bin_number_corrected = get_corrected_number(bin_number) bin_number_corrected_byte = bin_number_corrected.rjust(8, "0") if not is_correct_binary(bin_number_corrected): PopupWindow("warning", self.ml.get_tr_text("tab_num_conv_warning02"), self.input_number_textfield) else: if 0 <= int(bin_number_corrected, 2) <= 255: if bin_number_corrected != bin_number_corrected_byte: self.bin_format_base = bin_number_corrected self.bin_format_base_byte = bin_number_corrected_byte bin_format = get_bin_format( self.bin_format_base, self.ml.get_tr_text("byte_format_str"), self.bin_format_base_byte) else: bin_format = self.bin_format_base else: bin_format = bin_number_corrected dec_format = str(int(bin_number_corrected, 2)) hex_format = hex(int(bin_number_corrected, 2)).replace("0x", "").upper() self.bin_output.setText(bin_format) self.dec_output.setText(dec_format) self.hex_output.setText(hex_format) def source_dec(self, dec_number): dec_number_corrected = get_corrected_number(dec_number) if not is_correct_decimal(dec_number_corrected): PopupWindow("warning", self.ml.get_tr_text("tab_num_conv_warning03"), self.input_number_textfield) else: if 0 <= int(dec_number_corrected) <= 255: self.bin_format_base = bin(int(dec_number_corrected)).replace( "0b", "") self.bin_format_base_byte = self.bin_format_base.rjust(8, "0") if self.bin_format_base != self.bin_format_base_byte: bin_format = get_bin_format( self.bin_format_base, self.ml.get_tr_text("byte_format_str"), self.bin_format_base_byte) else: bin_format = self.bin_format_base else: bin_format = bin(int(dec_number_corrected)).replace("0b", "") dec_format = dec_number_corrected hex_format = hex(int(dec_number_corrected)).replace("0x", "").upper() self.bin_output.setText(bin_format) self.dec_output.setText(dec_format) self.hex_output.setText(hex_format) def source_hex(self, hex_number): hex_number_corrected = get_corrected_number(hex_number).upper() if not is_correct_hexadecimal(hex_number_corrected): PopupWindow("warning", self.ml.get_tr_text("tab_num_conv_warning04"), self.input_number_textfield) else: if 0 <= int(hex_number_corrected, 16) <= 255: self.bin_format_base = bin(int(hex_number_corrected, 16)).replace("0b", "") self.bin_format_base_byte = self.bin_format_base.rjust(8, "0") if self.bin_format_base != self.bin_format_base_byte: bin_format = get_bin_format( self.bin_format_base, self.ml.get_tr_text("byte_format_str"), self.bin_format_base_byte) else: bin_format = self.bin_format_base else: bin_format = bin(int(hex_number_corrected, 16)).replace("0b", "") dec_format = str(int(hex_number_corrected, 16)) hex_format = hex_number_corrected self.bin_output.setText(bin_format) self.dec_output.setText(dec_format) self.hex_output.setText(hex_format) def convert_action_2(self): if is_empty(self.input_textfield.text()): PopupWindow("warning", self.ml.get_tr_text("tab_num_conv_warning05"), self.input_textfield) elif self.dec_to_bin_button.isChecked(): if is_correct_any_ip_dec(self.input_textfield.text()): self.output_textfield.setText( dec_to_bin(self.input_textfield.text())) else: PopupWindow("warning", self.ml.get_tr_text("tab_num_conv_warning06"), self.input_textfield) else: if is_correct_any_ip_bin(self.input_textfield.text()): self.output_textfield.setText( bin_to_dec(self.input_textfield.text())) else: PopupWindow("warning", self.ml.get_tr_text("tab_num_conv_warning07"), self.input_textfield) def re_translate_ui(self, lang): self.ml = ManageLng(lang) self.inputbox.setTitle( self.ml.get_tr_text("tab_num_conv_inputbox_gbox_name")) self.input_number_label.setText( self.ml.get_tr_text("tab_num_conv_inputbox_in_number_lab")) self.bin_button.setText( self.ml.get_tr_text("tab_num_conv_inputbox_bin_chkbox")) self.dec_button.setText( self.ml.get_tr_text("tab_num_conv_inputbox_dec_chkbox")) self.hex_button.setText( self.ml.get_tr_text("tab_num_conv_inputbox_hex_chkbox")) self.convert_button.setText( self.ml.get_tr_text("tab_num_conv_inputbox_conv_btn")) self.outputbox.setTitle( self.ml.get_tr_text("tab_num_conv_outputbox_gbox_name")) self.bin_label.setText( self.ml.get_tr_text("tab_num_conv_outputbox_bin_lab")) self.dec_label.setText( self.ml.get_tr_text("tab_num_conv_outputbox_dec_lab")) self.hex_label.setText( self.ml.get_tr_text("tab_num_conv_outputbox_hex_lab")) self.bin_output_copy_button.setText( self.ml.get_tr_text("tab_num_conv_outputbox_copy_btn")) self.dec_output_copy_button.setText( self.ml.get_tr_text("tab_num_conv_outputbox_copy_btn")) self.hex_output_copy_button.setText( self.ml.get_tr_text("tab_num_conv_outputbox_copy_btn")) self.ip_address_number_conversion_box.setTitle( self.ml.get_tr_text("tab_num_conv_ip_mask_conv_gbox_name")) self.input_label.setText( self.ml.get_tr_text("tab_num_conv_ip_mask_conv_in_lab")) self.dec_to_bin_button.setText( self.ml.get_tr_text("tab_num_conv_ip_mask_conv_dectobin")) self.bin_to_dec_button.setText( self.ml.get_tr_text("tab_num_conv_ip_mask_conv_bintodec")) self.output_label.setText( self.ml.get_tr_text("tab_num_conv_ip_mask_conv_out_lab")) self.output_textfield_copy_button.setText( self.ml.get_tr_text("tab_num_conv_ip_mask_conv_copy_btn")) self.convert_button_2.setText( self.ml.get_tr_text("tab_num_conv_ip_mask_conv_convert_btn")) if self.bin_output.text(): self.bin_output.setText( get_bin_format(self.bin_format_base, self.ml.get_tr_text("byte_format_str"), self.bin_format_base_byte))
def _init_widgets(self): layout = QGridLayout() row = 0 # validation_failures = set() addr = hex(self._addr) address_label = QLabel(self) address_label.setText(f"Hook at address {addr}:") layout.addWidget(address_label, row, 0) row += 1 options_container = QGroupBox(self) options = QVBoxLayout() for name, template in sorted(self.templates.items()): child = QRadioButton() child.setText(name) child.template = template child.toggled.connect(self.selected) options.addWidget(child) scroll_area = QScrollArea(self) scroll_area.setWidgetResizable(True) widget = QWidget() scroll_area.setWidget(widget) layout_scroll = QVBoxLayout(widget) header_label = QLabel(self) header_label.setText("Presets:") layout_scroll.addWidget(header_label) layout_scroll.addWidget(options_container) options_container.setLayout(options) layout.addWidget(scroll_area, row, 0) row += 1 function_box = CodeEdit(self) function_box.use_spaces_instead_of_tabs = True function_box.tab_length = 4 function_box.modes.append(CaretLineHighlighterMode()) function_box.modes.append( PygmentsSyntaxHighlighter(function_box.document())) function_box.modes.append(AutoIndentMode()) function_box.setWordWrapMode(QTextOption.WordWrap) self._function_box = function_box layout.addWidget(function_box, row, 0) row += 1 self.main_layout.addLayout(layout) buttons = QDialogButtonBox(parent=self) buttons.setStandardButtons(QDialogButtonBox.StandardButton.Cancel | QDialogButtonBox.StandardButton.Ok) buttons.button(QDialogButtonBox.Ok).setText('Append to Console') def do_ok(): code = function_box.toPlainText() self.instance.append_code_to_console(code) self.close() buttons.accepted.connect(do_ok) buttons.rejected.connect(self.close) self.main_layout.addWidget(buttons)
class NodeAddDialog(QDialog): def __init__(self, parent=None, text='',): super(NodeAddDialog, self).__init__(parent) self._node = 0 self._text = text self._answer = [] self._answer.append(0) self._answer.append(0) self.ln_question = QLineEdit() self.ln_question.setText(self._text) self.ln_question.editingFinished.connect(self.setText) self.layoutH1 = QHBoxLayout() self.btn_add = QPushButton() self.btn_add.setText('Add') self.btn_cansel = QPushButton() self.btn_cansel.setText('Cansel') self.btn_add.clicked.connect(self.addNode) self.btn_cansel.clicked.connect(self.decline) self.layoutH1.addWidget(self.btn_add) self.layoutH1.addWidget(self.btn_cansel) self.layoutH2 = QHBoxLayout() self.rb_node1 = QRadioButton() self.rb_node1.setText('Node1') self.rb_answer1 = QRadioButton() self.rb_answer1.setText('Answer1') self.rb_answer1.setChecked(True) self.layoutH2.addWidget(self.rb_node1) self.layoutH2.addWidget(self.rb_answer1) self.layoutH3 = QHBoxLayout() self.rb_node2 = QRadioButton() self.rb_node2.setText('Node2') self.rb_answer2 = QRadioButton() self.rb_answer2.setText('Answer2') self.rb_answer2.setChecked(True) self.layoutH3.addWidget(self.rb_node2) self.layoutH3.addWidget(self.rb_answer2) self.layoutV = QVBoxLayout() self.layoutV.addWidget(self.ln_question) self.layoutV.addLayout(self.layoutH2) self.layoutV.addLayout(self.layoutH3) self.layoutV.addLayout(self.layoutH1) self.setLayout(self.layoutV) def addNode(self): self._node.setText(self.ln_question.text()) if self.rb_node1.isChecked() and self._node.getFirstChild().who() == 'Answer': self._node.setFirstChild(Node()) if self.rb_answer1.isChecked() and self._node.getFirstChild().who() == 'Node': self._node.setFirstChild(Answer()) if self.rb_node2.isChecked() and self._node.getSecoundChild().who() == 'Answer': self._node.setSecoundChild(Node()) if self.rb_answer2.isChecked() and self._node.getSecoundChild().who() == 'Node': self._node.setSecoundChild(Answer()) self.close() def decline(self): self.close() def setText(self): self._node.setText(self.ln_question.text()) def setNode(self, node): if node: self._node = node if self._node.getFirstChild().who() == 'Answer': self.rb_answer1.setChecked(True) self.rb_node1.setChecked(False) else: self.rb_answer1.setChecked(False) self.rb_node1.setChecked(True) if self._node.getSecoundChild().who() == 'Answer': self.rb_answer2.setChecked(True) self.rb_node2.setChecked(False) else: self.rb_answer2.setChecked(False) self.rb_node2.setChecked(True) return True else: return False
class mainWindow(QObject): signalRun = Signal(SpiderThread) signalRunApi = Signal(apiTester) def __init__(self): QObject.__init__(self) # must init parent QObject,if you want to use signal self.widget = QWidget() self.ipLabel = QLabel(self.widget) self.thread = QThread() self.worker = Worker() self.worker.moveToThread(self.thread) self.man = SpiderThread() self.api = apiTester() # 1 2:loop 3: time self.testStatus = [False,1,0,"ip","mac"] # advance config self.findCoreStop = True self.cleanCacheSet = False self.useApiTest = False self.showTestProgress = True self.saveTestLog = False self.saveLogPath = "" self.chromePath = "" self.showChrome = False self.coreDumpPath = "" # ui form self.passwordLabel = QLabel(self.widget) self.ipLineEdit = QLineEdit(self.widget) self.passwordLineEdit = QLineEdit(self.widget) self.startBtn = QPushButton(self.widget) self.stopBtn = QPushButton(self.widget) self.messageBox = QTextEdit(self.widget) self.messageBox.setReadOnly(True) self.userLabel = QLabel(self.widget) self.userLineEdit = QLineEdit(self.widget) self.intervalLabel = QLabel(self.widget) self.intervalSpinBox = QSpinBox(self.widget) self.loopLabel = QLabel(self.widget) self.loopSpinBox = QSpinBox(self.widget) self.intervalSpinBox.setRange(0,9999) self.loopSpinBox.setRange(1,9999) self.radioReboot = QRadioButton(self.widget) self.radioProvision = QRadioButton(self.widget) self.radioFactory = QRadioButton(self.widget) # self.apiCheckBox = QCheckBox(self.widget) self.menu = QMenu() self.gxpAction = QAction("Classic UI") self.grp2602Action = QAction("Ant Design UI") self.gxpAction.setCheckable(True) self.grp2602Action.setCheckable(True) self.menu.addAction(self.gxpAction) self.menu.addAction(self.grp2602Action) self.webLabel = QLabel(self.widget) self.webBtn = QPushButton(self.widget) self.webBtn.setMenu(self.menu) self.clearBtn = QPushButton(self.widget) self.messageList = deque() self.timer = QTimer() self.advanceBtn = QPushButton(self.widget) self.infoLabel = QLabel(self.widget) # provision widget self.provWidget = QWidget(self.widget) self.ver1Label = QLabel(self.provWidget) self.ver2Label = QLabel(self.provWidget) self.ver3Label = QLabel(self.provWidget) self.ver1LineEdit = QLineEdit(self.provWidget) self.ver2LineEdit = QLineEdit(self.provWidget) self.ver3LineEdit = QLineEdit(self.provWidget) self.dir1Label = QLabel(self.provWidget) self.dir2Label = QLabel(self.provWidget) self.dir3Label = QLabel(self.provWidget) self.dir1LineEdit = QLineEdit(self.provWidget) self.dir2LineEdit = QLineEdit(self.provWidget) self.dir3LineEdit = QLineEdit(self.provWidget) self.radioHttp = QRadioButton(self.provWidget) self.radioHttps = QRadioButton(self.provWidget) self.radioTftp = QRadioButton(self.provWidget) self.radioFtp = QRadioButton(self.provWidget) self.radioFtps = QRadioButton(self.provWidget) self.radioWindow = QRadioButton(self.provWidget) # advance widget self.advanceWidget = QWidget() self.checkCoreBox = QCheckBox(self.advanceWidget) self.cleanCache = QCheckBox(self.advanceWidget) self.checkSaveLogBox = QCheckBox(self.advanceWidget) self.selectDirBtn = QPushButton(self.advanceWidget) self.saveDirLabel = QLabel(self.advanceWidget) self.saveDirLabel.setStyleSheet("background:white") self.checkProgressBox = QCheckBox(self.advanceWidget) self.advanceOkBtn = QPushButton(self.advanceWidget) self.selectChromeBtn = QPushButton(self.advanceWidget) self.chromePathLabel = QLabel(self.advanceWidget) self.chromePathLabel.setStyleSheet("background:white") self.checkShowChromeBox = QCheckBox(self.advanceWidget) self.chromeLabel = QLabel(self.advanceWidget) self.pcapLabel = QLabel(self.advanceWidget) self.apiCheckBox = QCheckBox(self.advanceWidget) self.corePathLabel = QLabel(self.advanceWidget) self.corePathLabel.setStyleSheet("background:white") self.corePathBtn = QPushButton(self.advanceWidget) self.interfaceMenu = QComboBox(self.advanceWidget) self.interfaceMenu.addItem('Default') self.aiOptionBox= QCheckBox(self.advanceWidget) a = IFACES print(a) for i in a.keys(): print(a[i].description) self.interfaceMenu.addItem(a[i].description) # connect singal and slot self.startBtn.clicked.connect(self.clickedStarBtn) self.radioProvision.clicked.connect(self.clickedProvision) self.radioReboot.clicked.connect(self.clickedOthers) self.radioFactory.clicked.connect(self.clickedOthers) self.stopBtn.clicked.connect(self.clickedStopBtn) self.grp2602Action.triggered.connect(self.clickedGrp2602) self.gxpAction.triggered.connect(self.clickedGxpType) self.timer.timeout.connect(self.updateMessage) self.apiCheckBox.stateChanged.connect(self.apiTestBoxCheck) self.clearBtn.clicked.connect(self.clickedClearBtn) self.advanceBtn.clicked.connect(self.clickedAdvanceBtn) self.advanceOkBtn.clicked.connect(self.clickedAdvanceOkBtn) self.checkSaveLogBox.stateChanged.connect(self.saveLogBoxCheck) self.selectChromeBtn.clicked.connect(self.clickedSelectChromeBtn) self.selectDirBtn.clicked.connect(self.clickedSelectDirBtn) self.corePathBtn.clicked.connect(self.clickedCorePathBtn) self.worker.signalJobEnd.connect(self.slotTestStoped) self.worker.apiTestFinished.connect(self.slotTestStoped) self.signalRun.connect(self.worker.dowork) self.signalRunApi.connect(self.worker.doworkApi) # self.man.signalUpdateMessage.connect(self.pushMessage) def setupUI(self): # set text content /value self.widget.setWindowTitle("自动重启升降级测试工具") self.ipLabel.setText("初始IP:") self.passwordLabel.setText("密码:") self.startBtn.setText("开始测试") self.stopBtn.setText("停止测试") self.userLabel.setText("用户名:") self.intervalLabel.setText("间隔时间:") self.loopLabel.setText("测试次数:") self.intervalSpinBox.setValue(130) self.radioFactory.setText("恢复出厂") self.radioProvision.setText("升降级") self.radioReboot.setText("重启") self.ver1Label.setText("版本 1:") self.ver2Label.setText("版本 2:") self.ver3Label.setText("版本 3:") self.dir1Label.setText("路径 1:") self.dir2Label.setText("路径 2:") self.dir3Label.setText("路径 3:") self.radioHttp.setText("Http") self.radioHttps.setText("Https") self.radioTftp.setText("Tftp") self.radioFtp.setText("Ftp") self.radioFtps.setText("Ftps") self.apiCheckBox.setText("使用API测试,配置CoreDump下载路径") self.webLabel.setText("网页类型:") self.webBtn.setText("请选择UI类型") self.clearBtn.setText("清空输入") self.advanceWidget.setWindowTitle("高级设置") self.advanceBtn.setText("高级设置") self.checkCoreBox.setText("发现Core Dump时停止测试") self.cleanCache.setText("清除页面cache") self.checkSaveLogBox.setText("保存测试日志") self.selectDirBtn.setText("浏览") self.checkProgressBox.setText("显示底部状态条") self.advanceOkBtn.setText("OK") self.checkShowChromeBox.setText("测试时显示Chrome浏览器") self.selectChromeBtn.setText("浏览") self.chromeLabel.setText("Chrome浏览器路径") self.infoLabel.setText("未开始测试") self.pcapLabel.setText("Net Interface") self.corePathBtn.setText("浏览") self.radioWindow.setText("网页拖拽文件") # self.aiOptionBox.setText("AI") #init value self.saveDirLabel.hide() self.selectDirBtn.hide() self.gxpAction.setChecked(True) self.radioReboot.click() self.radioHttp.click() self.stopBtn.setEnabled(False) self.passwordLineEdit.setEchoMode(QLineEdit.PasswordEchoOnEdit) # set position------------------------------- xPos = 20 yPos = 30 colum2 = xPos +200 # line 1 self.ipLabel.move(xPos,yPos) self.intervalLabel.move(colum2,yPos) self.intervalSpinBox.move(colum2+60,yPos-2) self.ipLineEdit.move(xPos+50,yPos-2) # line 2 line2 = yPos +40 self.passwordLabel.move(xPos,line2) self.passwordLineEdit.move(xPos+50,line2-2) self.loopLabel.move(colum2,line2) self.loopSpinBox.move(colum2+60,line2-2) # line3 line3 = yPos +80 self.userLabel.move(xPos,line3) self.userLineEdit.move(xPos+50,line3-2) self.radioReboot.move(colum2,line3) self.radioFactory.move(colum2+60,line3) self.radioProvision.move(colum2,line3+30) self.webLabel.move(xPos,line3+40) self.webBtn.move(xPos+60,line3+35) # provWidget self.provWidget.resize(400,130) self.provWidget.move(xPos,line3+70) spaceY = 30 x = 0 y = 0 cl = 200 self.ver1Label.move(x,y) self.ver1LineEdit.move(x+50,y) self.ver2Label.move(x,y+spaceY) self.ver2LineEdit.move(x+50,y+spaceY) self.ver3Label.move(x,y+spaceY*2) self.ver3LineEdit.move(x+50,y+spaceY*2) self.dir1Label.move(cl,y) self.dir1LineEdit.move(cl+50,y) self.dir2Label.move(cl,y+spaceY) self.dir2LineEdit.move(cl+50,y+spaceY) self.dir3Label.move(cl,y+spaceY*2) self.dir3LineEdit.move(cl+50,y+spaceY*2) self.radioHttp.move(x,y+spaceY*3) self.radioHttps.move(x+50,y+spaceY*3) self.radioTftp.move(x+110,y+spaceY*3) self.radioFtp.move(x+160,y+spaceY*3) self.radioFtps.move(x+210,y+spaceY*3) self.radioWindow.move(x+265,y+spaceY*3) # advance widget self.advanceWidget.resize(300,400) x = 20 y = 20 space = 30 self.checkCoreBox.move(x,y) self.cleanCache.move(x,y+space) self.checkProgressBox.move(x,y+space*2) self.checkShowChromeBox.move(x,y+space*3) self.apiCheckBox.move(x,y+space*4) self.corePathBtn.move(x-2,y+space*5-8) self.corePathLabel.move(x+35,y+space*5-8) y += 40 self.chromeLabel.move(x,y+space*4+10) self.selectChromeBtn.move(x-2,y+space*5) self.chromePathLabel.move(x+35,y+space*5+2) self.checkSaveLogBox.move(x,y+space*6+10) self.selectDirBtn.move(x-2,y+space*7) self.saveDirLabel.move(x+35,y+space*7+2) self.advanceOkBtn.move(x+170,y+space*10+10) self.interfaceMenu.move(x-5,y+space*8+10) self.pcapLabel.move(x,y+space*8-2) # self.aiOptionBox.move(x, y+space*9+8) # set size self.messageBox.resize(373,155) # self.widget.resize(410,400) self.loopSpinBox.resize(60,25) self.intervalSpinBox.resize(60,25) self.webBtn.resize(100,25) self.saveDirLabel.resize(185,22) self.selectDirBtn.resize(32,24) self.selectChromeBtn.resize(32,24) self.chromePathLabel.resize(185,22) self.infoLabel.resize(400, 25) self.corePathBtn.resize(32,24) self.corePathLabel.resize(185,22) # self.provWidget.hide() self.changePosition(True) self.widget.show() self.loadCache() # ----------------end of setupUI --------------------- def changePosition(self,hide): xPos = 20 if hide: buttonLine = 200 self.widget.resize(420,415) else: buttonLine = 310 self.widget.resize(420,524) self.startBtn.move(xPos,buttonLine) self.stopBtn.move(xPos+90,buttonLine) self.clearBtn.move(xPos+180,buttonLine) self.advanceBtn.move(xPos+270,buttonLine) self.messageBox.move(xPos,buttonLine+30) boxH = self.messageBox.height() self.infoLabel.move(xPos,buttonLine+boxH+35) def setItemEnable(self,enable): self.provWidget.setEnabled(enable) self.ipLineEdit.setEnabled(enable) self.passwordLineEdit.setEnabled(enable) self.userLineEdit.setEnabled(enable) self.intervalSpinBox.setEnabled(enable) self.loopSpinBox.setEnabled(enable) self.radioFactory.setEnabled(enable) self.radioReboot.setEnabled(enable) self.radioProvision.setEnabled(enable) self.advanceBtn.setEnabled(enable) self.startBtn.setEnabled(enable) self.clearBtn.setEnabled(enable) if self.useApiTest: self.webBtn.setEnabled(False) else: self.webBtn.setEnabled(enable) self.stopBtn.setEnabled(not enable) def outputError(self,str): appstr = "<span style=\"color:red\">" appstr += str + "</span>" self.messageBox.append(appstr) def outputWarning(self,str): appstr = "<span style=\"color:orange\">" appstr += str + "</span>" self.messageBox.append(appstr) def loadCache(self): file = QFile("cache") if not file.open(QIODevice.ReadOnly | QIODevice.Text): return inStream = QTextStream(file) # ip self.ipLineEdit.setText(inStream.readLine()) # passwordLabel self.passwordLineEdit.setText(inStream.readLine()) # user self.userLineEdit.setText(inStream.readLine()) # ver1 self.ver1LineEdit.setText(inStream.readLine()) self.dir1LineEdit.setText(inStream.readLine()) # ver2 self.ver2LineEdit.setText(inStream.readLine()) self.dir2LineEdit.setText(inStream.readLine()) # ver3 self.ver3LineEdit.setText(inStream.readLine()) self.dir3LineEdit.setText(inStream.readLine()) self.intervalSpinBox.setValue(int(inStream.readLine())) self.loopSpinBox.setValue(int(inStream.readLine())) # web type button webType = inStream.readLine() if webType == "gxpAction": self.grp2602Action.setChecked(False) self.gxpAction.setChecked(True) self.webBtn.setText(self.gxpAction.text()) else: self.grp2602Action.setChecked(True) self.gxpAction.setChecked(False) self.webBtn.setText(self.grp2602Action.text()) testType = inStream.readLine() if testType == "reboot": self.radioReboot.setChecked(True) elif testType == "provision": self.radioProvision.setChecked(True) self.changePosition(False) self.provWidget.show() else: self.radioFactory.setChecked(True) serverType = inStream.readLine() if serverType == "Http": self.radioHttp.setChecked(True) elif serverType == "Https": self.radioHttps.setChecked(True) elif serverType == "Tftp": self.radioTftp.setChecked(True) elif serverType == "Ftp": self.radioFtp.setChecked(True) elif serverType == "Ftps": self.radioFtps.setChecked(True) else: self.radioWindow.setChecked(True) if inStream.readLine() == "True": self.findCoreStop = True else: self.findCoreStop = False if inStream.readLine() == "True": self.cleanCacheSet = True else: self.cleanCacheSet = False if inStream.readLine() == "True": self.useApiTest = True self.webBtn.setEnabled(False) else: self.useApiTest = False self.corePathBtn.hide() self.corePathLabel.hide() if inStream.readLine() == "True": self.showTestProgress = True else: self.showTestProgress = False self.infoLabel.hide() if inStream.readLine() == "True": self.showChrome = True else: self.showChrome = False self.chromePath = inStream.readLine() if inStream.readLine() == "True": self.saveTestLog = True else: self.saveTestLog = False self.saveLogPath = inStream.readLine() self.coreDumpPath = inStream.readLine() file.close() def saveCache(self): file = QFile("cache") if not file.open(QIODevice.WriteOnly): return content = self.ipLineEdit.text() + "\n" content += self.passwordLineEdit.text() + "\n" content += self.userLineEdit.text() + "\n" content += self.ver1LineEdit.text() + "\n" content += self.dir1LineEdit.text() + "\n" content += self.ver2LineEdit.text() + "\n" content += self.dir2LineEdit.text() + "\n" content += self.ver3LineEdit.text() + "\n" content += self.dir3LineEdit.text() + "\n" content += str(self.intervalSpinBox.value()) + "\n" content += str(self.loopSpinBox.value()) + "\n" if self.gxpAction.isChecked(): content += "gxpAction\n" else: content += "grp2602Action\n" if self.radioReboot.isChecked(): content += "reboot\n" elif self.radioProvision.isChecked(): content += "provision\n" else: content += "factory\n" if self.radioHttp.isChecked(): content += "Http\n" elif self.radioHttps.isChecked(): content += "Https\n" elif self.radioTftp.isChecked(): content += "Tftp\n" elif self.radioFtp.isChecked(): content += "Ftp\n" elif self.radioFtps.isChecked(): content += "Ftps\n" else : content += "Window\n" content += str(self.findCoreStop) + "\n" content += str(self.cleanCacheSet) + "\n" content += str(self.useApiTest) + "\n" content += str(self.showTestProgress) + "\n" content += str(self.showChrome) + "\n" content += self.chromePath +"\n" content += str(self.saveTestLog) +"\n" content += self.saveLogPath +"\n" content += self.coreDumpPath +"\n" byteArr = bytes(content,"utf-8") file.write(QByteArray(byteArr)) file.close() def checkBeforeRun(self): containError = False #---------check Ip address-------------- if self.ipLineEdit.text() == "": containError = True self.outputError("IP地址不能为空!") else: pattern = re.compile("^((1[0-9][0-9]\.)|(2[0-4][0-9]\.)|(25[0-5]\.)|([1-9][0-9]\.)|([0-9]\.)){3}((1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])|([1-9][0-9])|([0-9]))$") if not pattern.search(self.ipLineEdit.text()): containError = True self.outputError("IP地址格式错误,检查是否含有多余空格!(仅支持IPV4)") #------------------------ if self.passwordLineEdit.text() == "": containError = True self.outputError("密码不能为空!") if self.userLineEdit.text() == "": containError = True self.outputError("用户名不能为空!") if self.intervalSpinBox.value() <= 40: self.outputWarning("间隔时间过短,可能对测试造成影响") if not self.radioProvision.isChecked() and not self.radioReboot.isChecked() and \ not self.radioFactory.isChecked(): containError = True self.outputError("必须选择测试方式(重启,升降级,恢复出厂)") # check provision ---------- if self.radioProvision.isChecked(): if self.ver1LineEdit.text() == "" or self.ver2LineEdit.text() == "" or \ self.dir1LineEdit.text() == "" or self.dir2LineEdit.text() == "": containError = True self.outputError("升降级测试至少填上前两个版本及其路径") bin_name = "" if os.path.exists(os.path.abspath("config.ini") ): f = open(os.path.abspath("config.ini") , "r") line = f.readline() while line: option = line.split("=") if option[0] == "firmbinname": if option[1].strip('"') != "": filenamebin = option[1].strip() bin_name = filenamebin.strip('"') pass line = f.readline() f.close() filename = os.path.join(self.dir1LineEdit.text(), bin_name) if not os.path.exists(filename) and self.radioWindow.isChecked(): containError = True self.outputError("firmware1 文件不存在!" + filename) filename = os.path.join(self.dir2LineEdit.text(), bin_name) if not os.path.exists(filename) and self.radioWindow.isChecked(): containError = True self.outputError("firmware2 文件不存在!" + filename) filename = os.path.join(self.dir3LineEdit.text(), bin_name) if self.ver3LineEdit.text() != "" and self.dir3LineEdit.text() == "": containError = True self.outputError("填写了版本3,但对应路径为空!") if self.dir3LineEdit.text() != "" and self.ver3LineEdit.text() == "": containError = True self.outputError("填写了路径3,但对应版本为空!") elif self.dir3LineEdit.text() != "" and self.radioWindow.isChecked() and not os.path.exists(filename): containError = True self.outputError("firmware3 文件不存在!" + filename) if not self.radioFtp.isChecked() and not self.radioFtps.isChecked() and \ not self.radioHttp.isChecked() and not self.radioHttps.isChecked() and \ not self.radioTftp.isChecked() and not self.radioWindow.isChecked(): containError = True self.outputError("升降级测试必须选择服务器类型(Tftp,Ftp,Ftps,Http,Https)") return containError def startTest(self): ip = self.ipLineEdit.text() passwd = self.passwordLineEdit.text() username = self.userLineEdit.text() ptime = self.intervalSpinBox.value() loop = self.loopSpinBox.value() modelType = self.webBtn.text() if self.gxpAction.isChecked(): device_type = "GXP21XX" elif self.grp2602Action.isChecked(): device_type = "GRP260X" if self.radioReboot.isChecked(): task_type = "reboot" elif self.radioProvision.isChecked(): task_type = "provision" text_ver1 = self.ver1LineEdit.text() text_ver2 = self.ver2LineEdit.text() text_ver3 = self.ver3LineEdit.text() text_dir1 = self.dir1LineEdit.text() text_dir2 = self.dir2LineEdit.text() text_dir3 = self.dir3LineEdit.text() prov_dict = {"ver1": text_ver1.strip(), "dir1": text_dir1.strip(), "ver2": text_ver2.strip(), "dir2": text_dir2.strip(), "ver3": text_ver3.strip(), "dir3": text_dir3.strip()} if self.radioHttp.isChecked(): self.man.update_prov_setting("HTTP", prov_dict) elif self.radioHttps.isChecked(): self.man.update_prov_setting("HTTPS", prov_dict) elif self.radioTftp.isChecked(): self.man.update_prov_setting("TFTP", prov_dict) elif self.radioFtp.isChecked(): self.man.update_prov_setting("FTP", prov_dict) elif self.radioFtps.isChecked(): self.man.update_prov_setting("FTPS", prov_dict) elif self.radioWindow.isChecked(): self.man.update_prov_setting("browser", prov_dict) else: task_type = "reset" coredump_stop = True headless_flag = False clean_cache = False if self.checkCoreBox.isChecked() == False: self.messageBox.append("Find core dump will not stop") coredump_stop = False if self.cleanCache.isChecked() == True: clean_cache = True if self.checkShowChromeBox.isChecked() == True or self.radioWindow.isChecked() == True: headless_flag = False else: headless_flag = True # ai_mode = False # if self.aiOptionBox.isChecked() == True: # ai_mode = True browser_path = "" if self.chromePathLabel.text() != "": browser_path = self.chromePathLabel.text() self.testStatus = [True,1,0,"ip",""] print(self.interfaceMenu.currentText()) self.man.setStatus(self.testStatus) self.man.setMessageList(self.messageList) self.man.update_setting(ip.strip(), username.strip(), passwd.strip(), device_type, \ task_type, loop, ptime, coredump_stop, headless_flag, browser_path, \ clean_cache, self.interfaceMenu.currentText(), False) def startApiTest(self): ip = self.ipLineEdit.text() passwd = self.passwordLineEdit.text() username = self.userLineEdit.text() ptime = self.intervalSpinBox.value() loop = self.loopSpinBox.value() testType = "Reboot" if self.radioProvision.isChecked(): testType = "Provision" self.api.setValue(ip,username,passwd,ptime,loop,testType) v1 = self.ver1LineEdit.text() v2 = self.ver2LineEdit.text() v3 = self.ver3LineEdit.text() d1 = self.dir1LineEdit.text() d2 = self.dir2LineEdit.text() d3 = self.dir3LineEdit.text() self.api.setVersion(v1,v2,v3,d1,d2,d3) self.api.setTestStatus(self.testStatus,self.messageList,self.coreDumpPath) if self.radioHttp.isChecked(): self.api.setServerType("http") elif self.radioHttps.isChecked(): self.api.setServerType("https") elif self.radioTftp.isChecked(): self.api.setServerType("tftp") elif self.radioFtp.isChecked(): self.api.setServerType("ftp") else: #self.radioFtps.isChecked() self.api.setServerType("ftps") self.api.setFoundCoreStop(self.findCoreStop) # slot --------------------------------- def apiTestBoxCheck(self,state): if state == 2: self.corePathBtn.show() self.corePathLabel.show() else: self.corePathBtn.hide() self.corePathLabel.hide() def clickedCorePathBtn(self): dir = QFileDialog.getExistingDirectory(self.advanceWidget,"选择Core Dump存放路径","/home") if dir != "": self.corePathLabel.setText(dir) self.coreDumpPath = dir def clickedSelectDirBtn(self): dir = QFileDialog.getExistingDirectory(self.advanceWidget,"选择日志存放路径","/home") if dir != "": self.saveDirLabel.setText(dir) self.saveLogPath = dir def clickedSelectChromeBtn(self): fileName = QFileDialog.getOpenFileName(self.advanceWidget,"选择谷歌浏览器","/home","Chrome (*.exe)") if fileName != "": self.chromePathLabel.setText(fileName[0]) self.chromePath = fileName[0] def saveLogBoxCheck(self,state): if state == 2: # checked self.selectDirBtn.show() self.saveDirLabel.show() else: self.selectDirBtn.hide() self.saveDirLabel.hide() def clickedAdvanceOkBtn(self): self.findCoreStop = self.checkCoreBox.isChecked() self.cleanCacheSet = self.cleanCache.isChecked() self.useApiTest = self.apiCheckBox.isChecked() self.showTestProgress = self.checkProgressBox.isChecked() self.saveTestLog = self.checkSaveLogBox.isChecked() self.saveLogPath = self.saveDirLabel.text() self.showChrome = self.checkShowChromeBox.isChecked() self.chromePath = self.chromePathLabel.text() self.coreDumpPath = self.corePathLabel.text() if self.useApiTest: self.webBtn.setEnabled(False) self.corePathBtn.show() self.corePathLabel.show() else: self.webBtn.setEnabled(True) self.corePathBtn.hide() self.corePathLabel.hide() if self.showTestProgress: self.infoLabel.show() else: self.infoLabel.hide() self.saveCache() self.advanceWidget.hide() def clickedAdvanceBtn(self): self.advanceWidget.hide() self.checkCoreBox.setChecked(self.findCoreStop) self.cleanCache.setChecked(self.cleanCacheSet) self.apiCheckBox.setChecked(self.useApiTest) self.checkProgressBox.setChecked(self.showTestProgress) self.checkSaveLogBox.setChecked(self.saveTestLog) self.saveDirLabel.setText(self.saveLogPath) self.checkShowChromeBox.setChecked(self.showChrome) self.chromePathLabel.setText(self.chromePath) self.corePathLabel.setText(self.coreDumpPath) self.advanceWidget.show() def slotTestStoped(self): self.testStatus[0] = False self.setItemEnable(True) self.timer.stop() self.updateMessage() self.thread.quit() # save Test log if self.saveTestLog: fileName = time.strftime("%Y_%m_%d.%H_%M_%S.",time.localtime()) if self.radioReboot.isChecked(): fileName += "reboot" elif self.radioProvision: fileName += "provision" else: fileName += "factoryReset" fileName += ".htm" if self.saveLogPath == "": self.outputWarning("日志地址没有设置,无法保存") else: fileName = self.saveLogPath + "\\" + fileName print(fileName) file = QFile(fileName) if not file.open(QIODevice.WriteOnly): self.outputError("打开文件错误,保存日志失败") return byteArr = bytes(self.messageBox.toHtml(),"utf-8") file.write(QByteArray(byteArr)) file.close() def clickedClearBtn(self): self.ipLineEdit.setText("") self.passwordLineEdit.setText("") self.userLineEdit.setText("") self.ver1LineEdit.setText("") self.dir1LineEdit.setText("") self.ver2LineEdit.setText("") self.dir2LineEdit.setText("") self.ver3LineEdit.setText("") self.dir3LineEdit.setText("") def clickedStarBtn(self): if self.checkBeforeRun(): return self.messageBox.clear() self.saveCache() self.messageBox.append("Init Setting...") self.setItemEnable(False) self.timer.start(500) self.thread.start() # deside use what to test if self.useApiTest: if self.radioFactory.isChecked(): self.outputWarning("Api not support Factory Reset, will test as Gxp type web driver") self.clickedGxpType() self.startTest() self.signalRun.emit(self.man) else: self.startApiTest() self.signalRunApi.emit(self.api) else: self.startTest() self.signalRun.emit(self.man) def clickedStopBtn(self): self.stopBtn.setEnabled(False) self.testStatus[0] = False self.man.quit() self.outputWarning("正在停止...") def clickedProvision(self): self.provWidget.show() self.changePosition(False) def clickedOthers(self): self.provWidget.hide() self.changePosition(True) def clickedGxpType(self): self.gxpAction.setChecked(True) self.grp2602Action.setChecked(False) self.webBtn.setText(self.gxpAction.text()) def clickedGrp2602(self): self.gxpAction.setChecked(False) self.grp2602Action.setChecked(True) self.webBtn.setText(self.grp2602Action.text()) def updateMessage(self): while len(self.messageList) >0: info = self.messageList.popleft() self.messageBox.append(info) if self.testStatus[0] == False: self.infoLabel.setText("未开始测试") else: info = "第" + str(self.testStatus[1]) + "次测试 " if self.testStatus[2] > 0: info += "等待:{} 秒".format( self.testStatus[2] ) else: info += "运行中" info += " " + self.testStatus[3] info += " " + self.testStatus[4] self.infoLabel.setText(info)
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 Ui_GroupBox(object): def setupUi(self, GroupBox): if not GroupBox.objectName(): GroupBox.setObjectName(u"GroupBox") GroupBox.resize(535, 520) 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_occupancy_histogram = QGroupBox(GroupBox) self.groupBox_occupancy_histogram.setObjectName( u"groupBox_occupancy_histogram") self.verticalLayout = QVBoxLayout(self.groupBox_occupancy_histogram) self.verticalLayout.setObjectName(u"verticalLayout") self.horizontalLayout = QHBoxLayout() self.horizontalLayout.setObjectName(u"horizontalLayout") self.label_56 = QLabel(self.groupBox_occupancy_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.addWidget(self.label_56) self.lineEdit_bins = QLineEdit(self.groupBox_occupancy_histogram) self.lineEdit_bins.setObjectName(u"lineEdit_bins") self.lineEdit_bins.setMinimumSize(QSize(50, 0)) self.lineEdit_bins.setMaximumSize(QSize(50, 16777215)) self.horizontalLayout.addWidget(self.lineEdit_bins) self.horizontalSpacer_3 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout.addItem(self.horizontalSpacer_3) self.label_55 = QLabel(self.groupBox_occupancy_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.addWidget(self.label_55) self.lineEdit_minimum = QLineEdit(self.groupBox_occupancy_histogram) self.lineEdit_minimum.setObjectName(u"lineEdit_minimum") self.lineEdit_minimum.setMinimumSize(QSize(50, 0)) self.lineEdit_minimum.setMaximumSize(QSize(50, 16777215)) self.horizontalLayout.addWidget(self.lineEdit_minimum) self.horizontalSpacer_2 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout.addItem(self.horizontalSpacer_2) self.label_17 = QLabel(self.groupBox_occupancy_histogram) self.label_17.setObjectName(u"label_17") self.label_17.setAlignment(Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter) self.horizontalLayout.addWidget(self.label_17) self.lineEdit_maximum = QLineEdit(self.groupBox_occupancy_histogram) self.lineEdit_maximum.setObjectName(u"lineEdit_maximum") self.lineEdit_maximum.setMinimumSize(QSize(50, 0)) self.lineEdit_maximum.setMaximumSize(QSize(50, 16777215)) self.horizontalLayout.addWidget(self.lineEdit_maximum) self.verticalLayout.addLayout(self.horizontalLayout) self.horizontalLayout_7 = QHBoxLayout() self.horizontalLayout_7.setObjectName(u"horizontalLayout_7") self.checkBox_cumulative_histogram = QCheckBox( self.groupBox_occupancy_histogram) self.checkBox_cumulative_histogram.setObjectName( u"checkBox_cumulative_histogram") self.horizontalLayout_7.addWidget(self.checkBox_cumulative_histogram) self.horizontalSpacer_12 = QSpacerItem(40, 20, QSizePolicy.Fixed, QSizePolicy.Minimum) self.horizontalLayout_7.addItem(self.horizontalSpacer_12) self.checkBox_stacked_histogram = QCheckBox( self.groupBox_occupancy_histogram) self.checkBox_stacked_histogram.setObjectName( u"checkBox_stacked_histogram") self.horizontalLayout_7.addWidget(self.checkBox_stacked_histogram) self.horizontalSpacer_11 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout_7.addItem(self.horizontalSpacer_11) self.verticalLayout.addLayout(self.horizontalLayout_7) self.horizontalLayout_6 = QHBoxLayout() self.horizontalLayout_6.setObjectName(u"horizontalLayout_6") self.checkBox_color_segments_occupancy = QCheckBox( self.groupBox_occupancy_histogram) self.checkBox_color_segments_occupancy.setObjectName( u"checkBox_color_segments_occupancy") self.checkBox_color_segments_occupancy.setChecked(True) self.horizontalLayout_6.addWidget( self.checkBox_color_segments_occupancy) self.horizontalSpacer_9 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout_6.addItem(self.horizontalSpacer_9) self.verticalLayout.addLayout(self.horizontalLayout_6) self.horizontalLayout_2 = QHBoxLayout() self.horizontalLayout_2.setObjectName(u"horizontalLayout_2") self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout_2.addItem(self.horizontalSpacer) self.pushButton_save_occupancy = QPushButton( self.groupBox_occupancy_histogram) self.pushButton_save_occupancy.setObjectName( u"pushButton_save_occupancy") self.horizontalLayout_2.addWidget(self.pushButton_save_occupancy) self.pushButton_plot_occupancy = QPushButton( self.groupBox_occupancy_histogram) self.pushButton_plot_occupancy.setObjectName( u"pushButton_plot_occupancy") self.pushButton_plot_occupancy.setAutoDefault(False) self.horizontalLayout_2.addWidget(self.pushButton_plot_occupancy) self.verticalLayout.addLayout(self.horizontalLayout_2) self.verticalLayout_2.addWidget(self.groupBox_occupancy_histogram) self.verticalSpacer_2 = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding) self.verticalLayout_2.addItem(self.verticalSpacer_2) self.groupBox_nb_connections = QGroupBox(GroupBox) self.groupBox_nb_connections.setObjectName(u"groupBox_nb_connections") self.verticalLayout_3 = QVBoxLayout(self.groupBox_nb_connections) self.verticalLayout_3.setObjectName(u"verticalLayout_3") self.horizontalLayout_5 = QHBoxLayout() self.horizontalLayout_5.setObjectName(u"horizontalLayout_5") self.checkBox_color_segments_timeseries = QCheckBox( self.groupBox_nb_connections) self.checkBox_color_segments_timeseries.setObjectName( u"checkBox_color_segments_timeseries") self.checkBox_color_segments_timeseries.setChecked(True) self.horizontalLayout_5.addWidget( self.checkBox_color_segments_timeseries) self.horizontalSpacer_7 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout_5.addItem(self.horizontalSpacer_7) self.verticalLayout_3.addLayout(self.horizontalLayout_5) self.horizontalLayout_4 = QHBoxLayout() self.horizontalLayout_4.setObjectName(u"horizontalLayout_4") self.horizontalSpacer_5 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout_4.addItem(self.horizontalSpacer_5) self.pushButton_save_timeseries = QPushButton( self.groupBox_nb_connections) self.pushButton_save_timeseries.setObjectName( u"pushButton_save_timeseries") self.horizontalLayout_4.addWidget(self.pushButton_save_timeseries) self.pushButton_plot_timeseries = QPushButton( self.groupBox_nb_connections) self.pushButton_plot_timeseries.setObjectName( u"pushButton_plot_timeseries") self.pushButton_plot_timeseries.setAutoDefault(False) self.horizontalLayout_4.addWidget(self.pushButton_plot_timeseries) self.verticalLayout_3.addLayout(self.horizontalLayout_4) self.verticalLayout_2.addWidget(self.groupBox_nb_connections) self.verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding) self.verticalLayout_2.addItem(self.verticalSpacer) self.groupBox_joint_occupancy = QGroupBox(GroupBox) self.groupBox_joint_occupancy.setObjectName( u"groupBox_joint_occupancy") self.verticalLayout_4 = QVBoxLayout(self.groupBox_joint_occupancy) self.verticalLayout_4.setObjectName(u"verticalLayout_4") self.horizontalLayout_10 = QHBoxLayout() self.horizontalLayout_10.setObjectName(u"horizontalLayout_10") self.radioButton_scatter = QRadioButton(self.groupBox_joint_occupancy) self.radioButton_scatter.setObjectName(u"radioButton_scatter") self.radioButton_scatter.setChecked(True) self.horizontalLayout_10.addWidget(self.radioButton_scatter) self.label_3 = QLabel(self.groupBox_joint_occupancy) self.label_3.setObjectName(u"label_3") self.horizontalLayout_10.addWidget(self.label_3) self.lineEdit_scatter_size = QLineEdit(self.groupBox_joint_occupancy) self.lineEdit_scatter_size.setObjectName(u"lineEdit_scatter_size") self.lineEdit_scatter_size.setMaximumSize(QSize(50, 16777215)) self.horizontalLayout_10.addWidget(self.lineEdit_scatter_size) self.horizontalSpacer_10 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout_10.addItem(self.horizontalSpacer_10) self.verticalLayout_4.addLayout(self.horizontalLayout_10) self.horizontalLayout_3 = QHBoxLayout() self.horizontalLayout_3.setObjectName(u"horizontalLayout_3") self.radioButton_heatmap = QRadioButton(self.groupBox_joint_occupancy) self.radioButton_heatmap.setObjectName(u"radioButton_heatmap") self.horizontalLayout_3.addWidget(self.radioButton_heatmap) self.horizontalSpacer_4 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout_3.addItem(self.horizontalSpacer_4) self.pushButton_save_jo = QPushButton(self.groupBox_joint_occupancy) self.pushButton_save_jo.setObjectName(u"pushButton_save_jo") self.horizontalLayout_3.addWidget(self.pushButton_save_jo) self.pushButton_plot_jo = QPushButton(self.groupBox_joint_occupancy) self.pushButton_plot_jo.setObjectName(u"pushButton_plot_jo") self.pushButton_plot_jo.setAutoDefault(False) self.horizontalLayout_3.addWidget(self.pushButton_plot_jo) self.verticalLayout_4.addLayout(self.horizontalLayout_3) self.verticalLayout_2.addWidget(self.groupBox_joint_occupancy) self.retranslateUi(GroupBox) QMetaObject.connectSlotsByName(GroupBox) # setupUi def retranslateUi(self, GroupBox): GroupBox.setWindowTitle( QCoreApplication.translate("GroupBox", u"GroupBox", None)) self.groupBox_occupancy_histogram.setTitle( QCoreApplication.translate("GroupBox", u"Occupancy 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. occupancy", None)) self.lineEdit_minimum.setText( QCoreApplication.translate("GroupBox", u"0.0", None)) self.label_17.setText( QCoreApplication.translate("GroupBox", u"max. occupancy", 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)) self.pushButton_save_occupancy.setText( QCoreApplication.translate("GroupBox", u"Data", None)) #if QT_CONFIG(tooltip) self.pushButton_plot_occupancy.setToolTip( QCoreApplication.translate( "GroupBox", u"<html><head/><body><p>Compute histogram of H bond occupancies. Counts the number of H bonds with an occupancy equal or greater than the respective value.</p></body></html>", None)) #endif // QT_CONFIG(tooltip) self.pushButton_plot_occupancy.setText( QCoreApplication.translate("GroupBox", u"Plot", None)) self.groupBox_nb_connections.setTitle( QCoreApplication.translate("GroupBox", u"Number of connections time series", None)) #if QT_CONFIG(tooltip) self.checkBox_color_segments_timeseries.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_timeseries.setText( QCoreApplication.translate("GroupBox", u"color by segment", None)) self.pushButton_save_timeseries.setText( QCoreApplication.translate("GroupBox", u"Data", None)) #if QT_CONFIG(tooltip) self.pushButton_plot_timeseries.setToolTip( QCoreApplication.translate( "GroupBox", u"<html><head/><body><p align=\"justify\">Compute the number of H bonds per frame.</p></body></html>", None)) #endif // QT_CONFIG(tooltip) self.pushButton_plot_timeseries.setText( QCoreApplication.translate("GroupBox", u"Plot", None)) self.groupBox_joint_occupancy.setTitle( QCoreApplication.translate("GroupBox", u"Joint Occupancy", None)) self.radioButton_scatter.setText( QCoreApplication.translate("GroupBox", u"scatter plot", None)) self.label_3.setText( QCoreApplication.translate("GroupBox", u"with dot size", None)) self.lineEdit_scatter_size.setText( QCoreApplication.translate("GroupBox", u"1", None)) self.lineEdit_scatter_size.setPlaceholderText( QCoreApplication.translate("GroupBox", u"0 - 100", None)) self.radioButton_heatmap.setText( QCoreApplication.translate("GroupBox", u"heatmap", None)) self.pushButton_save_jo.setText( QCoreApplication.translate("GroupBox", u"Data", None)) #if QT_CONFIG(tooltip) self.pushButton_plot_jo.setToolTip( QCoreApplication.translate( "GroupBox", u"<html><head/><body><p align=\"justify\">Compute the joint occupancy of the H bond network. The joint occupancy is true, if all H bonds of the network are present in a frame and false otherwise.</p></body></html>", None)) #endif // QT_CONFIG(tooltip) self.pushButton_plot_jo.setText( QCoreApplication.translate("GroupBox", u"Plot", None))
class SCOUTS(QMainWindow): """Main Window Widget for SCOUTS.""" style = { 'title': 'QLabel {font-size: 18pt; font-weight: 600}', 'header': 'QLabel {font-size: 12pt; font-weight: 520}', 'label': 'QLabel {font-size: 10pt}', 'button': 'QPushButton {font-size: 10pt}', 'md button': 'QPushButton {font-size: 12pt}', 'run button': 'QPushButton {font-size: 18pt; font-weight: 600}', 'line edit': 'QLineEdit {font-size: 10pt}', 'checkbox': 'QCheckBox {font-size: 10pt}', 'radio button': 'QRadioButton {font-size: 10pt}' } def __init__(self) -> None: """SCOUTS Constructor. Defines all aspects of the GUI.""" # ### # ### Main Window setup # ### # Inherits from QMainWindow super().__init__() self.rootdir = get_project_root() self.threadpool = QThreadPool() # Sets values for QMainWindow self.setWindowTitle("SCOUTS") self.setWindowIcon( QIcon( os.path.abspath(os.path.join(self.rootdir, 'src', 'scouts.ico')))) # Creates StackedWidget as QMainWindow's central widget self.stacked_pages = QStackedWidget(self) self.setCentralWidget(self.stacked_pages) # Creates Widgets for individual "pages" and adds them to the StackedWidget self.main_page = QWidget() self.samples_page = QWidget() self.gating_page = QWidget() self.pages = (self.main_page, self.samples_page, self.gating_page) for page in self.pages: self.stacked_pages.addWidget(page) # ## Sets widget at program startup self.stacked_pages.setCurrentWidget(self.main_page) # ### # ### MAIN PAGE # ### # Main page layout self.main_layout = QVBoxLayout(self.main_page) # Title section # Title self.title = QLabel(self.main_page) self.title.setText('SCOUTS - Single Cell Outlier Selector') self.title.setStyleSheet(self.style['title']) self.title.adjustSize() self.main_layout.addWidget(self.title) # ## Input section # Input header self.input_header = QLabel(self.main_page) self.input_header.setText('Input settings') self.input_header.setStyleSheet(self.style['header']) self.main_layout.addChildWidget(self.input_header) self.input_header.adjustSize() self.main_layout.addWidget(self.input_header) # Input frame self.input_frame = QFrame(self.main_page) self.input_frame.setFrameShape(QFrame.StyledPanel) self.input_frame.setLayout(QFormLayout()) self.main_layout.addWidget(self.input_frame) # Input button self.input_button = QPushButton(self.main_page) self.input_button.setStyleSheet(self.style['button']) self.set_icon(self.input_button, 'x-office-spreadsheet') self.input_button.setObjectName('input') self.input_button.setText(' Select input file (.xlsx or .csv)') self.input_button.clicked.connect(self.get_path) # Input path box self.input_path = QLineEdit(self.main_page) self.input_path.setObjectName('input_path') self.input_path.setStyleSheet(self.style['line edit']) # Go to sample naming page self.samples_button = QPushButton(self.main_page) self.samples_button.setStyleSheet(self.style['button']) self.set_icon(self.samples_button, 'preferences-other') self.samples_button.setText(' Name samples...') self.samples_button.clicked.connect(self.goto_samples_page) # Go to gating page self.gates_button = QPushButton(self.main_page) self.gates_button.setStyleSheet(self.style['button']) self.set_icon(self.gates_button, 'preferences-other') self.gates_button.setText(' Gating && outlier options...') self.gates_button.clicked.connect(self.goto_gates_page) # Add widgets above to input frame Layout self.input_frame.layout().addRow(self.input_button, self.input_path) self.input_frame.layout().addRow(self.samples_button) self.input_frame.layout().addRow(self.gates_button) # ## Analysis section # Analysis header self.analysis_header = QLabel(self.main_page) self.analysis_header.setText('Analysis settings') self.analysis_header.setStyleSheet(self.style['header']) self.analysis_header.adjustSize() self.main_layout.addWidget(self.analysis_header) # Analysis frame self.analysis_frame = QFrame(self.main_page) self.analysis_frame.setFrameShape(QFrame.StyledPanel) self.analysis_frame.setLayout(QVBoxLayout()) self.main_layout.addWidget(self.analysis_frame) # Cutoff text self.cutoff_text = QLabel(self.main_page) self.cutoff_text.setText('Type of outlier to select:') self.cutoff_text.setToolTip( 'Choose whether to select outliers using the cutoff value from a reference\n' 'sample (OutR) or by using the cutoff value calculated for each sample\n' 'individually (OutS)') self.cutoff_text.setStyleSheet(self.style['label']) # Cutoff button group self.cutoff_group = QButtonGroup(self) # Cutoff by sample self.cutoff_sample = QRadioButton(self.main_page) self.cutoff_sample.setText('OutS') self.cutoff_sample.setObjectName('sample') self.cutoff_sample.setStyleSheet(self.style['radio button']) self.cutoff_sample.setChecked(True) self.cutoff_group.addButton(self.cutoff_sample) # Cutoff by reference self.cutoff_reference = QRadioButton(self.main_page) self.cutoff_reference.setText('OutR') self.cutoff_reference.setObjectName('ref') self.cutoff_reference.setStyleSheet(self.style['radio button']) self.cutoff_group.addButton(self.cutoff_reference) # Both cutoffs self.cutoff_both = QRadioButton(self.main_page) self.cutoff_both.setText('both') self.cutoff_both.setObjectName('sample ref') self.cutoff_both.setStyleSheet(self.style['radio button']) self.cutoff_group.addButton(self.cutoff_both) # Markers text self.markers_text = QLabel(self.main_page) self.markers_text.setStyleSheet(self.style['label']) self.markers_text.setText('Show results for:') self.markers_text.setToolTip( 'Individual markers: for each marker, select outliers\n' 'Any marker: select cells that are outliers for AT LEAST one marker' ) # Markers button group self.markers_group = QButtonGroup(self) # Single marker self.single_marker = QRadioButton(self.main_page) self.single_marker.setText('individual markers') self.single_marker.setObjectName('single') self.single_marker.setStyleSheet(self.style['radio button']) self.single_marker.setChecked(True) self.markers_group.addButton(self.single_marker) # Any marker self.any_marker = QRadioButton(self.main_page) self.any_marker.setText('any marker') self.any_marker.setObjectName('any') self.any_marker.setStyleSheet(self.style['radio button']) self.markers_group.addButton(self.any_marker) # Both methods self.both_methods = QRadioButton(self.main_page) self.both_methods.setText('both') self.both_methods.setObjectName('single any') self.both_methods.setStyleSheet(self.style['radio button']) self.markers_group.addButton(self.both_methods) # Tukey text self.tukey_text = QLabel(self.main_page) self.tukey_text.setStyleSheet(self.style['label']) # Tukey button group self.tukey_text.setText('Tukey factor:') self.tukey_group = QButtonGroup(self) # Low Tukey value self.tukey_low = QRadioButton(self.main_page) self.tukey_low.setText('1.5') self.tukey_low.setStyleSheet(self.style['radio button']) self.tukey_low.setChecked(True) self.tukey_group.addButton(self.tukey_low) # High Tukey value self.tukey_high = QRadioButton(self.main_page) self.tukey_high.setText('3.0') self.tukey_high.setStyleSheet(self.style['radio button']) self.tukey_group.addButton(self.tukey_high) # Add widgets above to analysis frame layout self.analysis_frame.layout().addWidget(self.cutoff_text) self.cutoff_buttons = QHBoxLayout() for button in self.cutoff_group.buttons(): self.cutoff_buttons.addWidget(button) self.analysis_frame.layout().addLayout(self.cutoff_buttons) self.analysis_frame.layout().addWidget(self.markers_text) self.markers_buttons = QHBoxLayout() for button in self.markers_group.buttons(): self.markers_buttons.addWidget(button) self.analysis_frame.layout().addLayout(self.markers_buttons) self.analysis_frame.layout().addWidget(self.tukey_text) self.tukey_buttons = QHBoxLayout() for button in self.tukey_group.buttons(): self.tukey_buttons.addWidget(button) self.tukey_buttons.addWidget(QLabel()) # aligns row with 2 buttons self.analysis_frame.layout().addLayout(self.tukey_buttons) # ## Output section # Output header self.output_header = QLabel(self.main_page) self.output_header.setText('Output settings') self.output_header.setStyleSheet(self.style['header']) self.output_header.adjustSize() self.main_layout.addWidget(self.output_header) # Output frame self.output_frame = QFrame(self.main_page) self.output_frame.setFrameShape(QFrame.StyledPanel) self.output_frame.setLayout(QFormLayout()) self.main_layout.addWidget(self.output_frame) # Output button self.output_button = QPushButton(self.main_page) self.output_button.setStyleSheet(self.style['button']) self.set_icon(self.output_button, 'folder') self.output_button.setObjectName('output') self.output_button.setText(' Select output folder') self.output_button.clicked.connect(self.get_path) # Output path box self.output_path = QLineEdit(self.main_page) self.output_path.setStyleSheet(self.style['line edit']) # Generate CSV checkbox self.output_csv = QCheckBox(self.main_page) self.output_csv.setText('Export multiple text files (.csv)') self.output_csv.setStyleSheet(self.style['checkbox']) self.output_csv.setChecked(True) # Generate XLSX checkbox self.output_excel = QCheckBox(self.main_page) self.output_excel.setText('Export multiple Excel spreadsheets (.xlsx)') self.output_excel.setStyleSheet(self.style['checkbox']) self.output_excel.clicked.connect(self.enable_single_excel) # Generate single, large XLSX checkbox self.single_excel = QCheckBox(self.main_page) self.single_excel.setText( 'Also save one multi-sheet Excel spreadsheet') self.single_excel.setToolTip( 'After generating all Excel spreadsheets, SCOUTS combines them into ' 'a single\nExcel spreadsheet where each sheet corresponds to an output' 'file from SCOUTS') self.single_excel.setStyleSheet(self.style['checkbox']) self.single_excel.setEnabled(False) self.single_excel.clicked.connect(self.memory_warning) # Add widgets above to output frame layout self.output_frame.layout().addRow(self.output_button, self.output_path) self.output_frame.layout().addRow(self.output_csv) self.output_frame.layout().addRow(self.output_excel) self.output_frame.layout().addRow(self.single_excel) # ## Run & help-quit section # Run button (stand-alone) self.run_button = QPushButton(self.main_page) self.set_icon(self.run_button, 'system-run') self.run_button.setText(' Run!') self.run_button.setStyleSheet(self.style['run button']) self.main_layout.addWidget(self.run_button) self.run_button.clicked.connect(self.run) # Help-quit frame (invisible) self.helpquit_frame = QFrame(self.main_page) self.helpquit_frame.setLayout(QHBoxLayout()) self.helpquit_frame.layout().setMargin(0) self.main_layout.addWidget(self.helpquit_frame) # Help button self.help_button = QPushButton(self.main_page) self.set_icon(self.help_button, 'help-about') self.help_button.setText(' Help') self.help_button.setStyleSheet(self.style['md button']) self.help_button.clicked.connect(self.get_help) # Quit button self.quit_button = QPushButton(self.main_page) self.set_icon(self.quit_button, 'process-stop') self.quit_button.setText(' Quit') self.quit_button.setStyleSheet(self.style['md button']) self.quit_button.clicked.connect(self.close) # Add widgets above to help-quit layout self.helpquit_frame.layout().addWidget(self.help_button) self.helpquit_frame.layout().addWidget(self.quit_button) # ### # ### SAMPLES PAGE # ### # Samples page layout self.samples_layout = QVBoxLayout(self.samples_page) # ## Title section # Title self.samples_title = QLabel(self.samples_page) self.samples_title.setText('Name your samples') self.samples_title.setStyleSheet(self.style['title']) self.samples_title.adjustSize() self.samples_layout.addWidget(self.samples_title) # Subtitle self.samples_subtitle = QLabel(self.samples_page) string = ( 'Please name the samples to be analysed by SCOUTS.\n\nSCOUTS searches the first ' 'column of your data\nand locates the exact string as part of the sample name.' ) self.samples_subtitle.setText(string) self.samples_subtitle.setStyleSheet(self.style['label']) self.samples_subtitle.adjustSize() self.samples_layout.addWidget(self.samples_subtitle) # ## Sample addition section # Sample addition frame self.samples_frame = QFrame(self.samples_page) self.samples_frame.setFrameShape(QFrame.StyledPanel) self.samples_frame.setLayout(QGridLayout()) self.samples_layout.addWidget(self.samples_frame) # Sample name box self.sample_name = QLineEdit(self.samples_page) self.sample_name.setStyleSheet(self.style['line edit']) self.sample_name.setPlaceholderText('Sample name ...') # Reference check self.is_reference = QCheckBox(self.samples_page) self.is_reference.setText('Reference?') self.is_reference.setStyleSheet(self.style['checkbox']) # Add sample to table self.add_sample_button = QPushButton(self.samples_page) QShortcut(QKeySequence("Return"), self.add_sample_button, self.write_to_sample_table) self.set_icon(self.add_sample_button, 'list-add') self.add_sample_button.setText(' Add sample (Enter)') self.add_sample_button.setStyleSheet(self.style['button']) self.add_sample_button.clicked.connect(self.write_to_sample_table) # Remove sample from table self.remove_sample_button = QPushButton(self.samples_page) QShortcut(QKeySequence("Delete"), self.remove_sample_button, self.remove_from_sample_table) self.set_icon(self.remove_sample_button, 'list-remove') self.remove_sample_button.setText(' Remove sample (Del)') self.remove_sample_button.setStyleSheet(self.style['button']) self.remove_sample_button.clicked.connect( self.remove_from_sample_table) # Add widgets above to sample addition layout self.samples_frame.layout().addWidget(self.sample_name, 0, 0) self.samples_frame.layout().addWidget(self.is_reference, 1, 0) self.samples_frame.layout().addWidget(self.add_sample_button, 0, 1) self.samples_frame.layout().addWidget(self.remove_sample_button, 1, 1) # ## Sample table self.sample_table = QTableWidget(self.samples_page) self.sample_table.setColumnCount(2) self.sample_table.setHorizontalHeaderItem(0, QTableWidgetItem('Sample')) self.sample_table.setHorizontalHeaderItem( 1, QTableWidgetItem('Reference?')) self.sample_table.horizontalHeader().setSectionResizeMode( 0, QHeaderView.Stretch) self.sample_table.horizontalHeader().setSectionResizeMode( 1, QHeaderView.ResizeToContents) self.samples_layout.addWidget(self.sample_table) # ## Save & clear buttons # Save & clear frame (invisible) self.saveclear_frame = QFrame(self.samples_page) self.saveclear_frame.setLayout(QHBoxLayout()) self.saveclear_frame.layout().setMargin(0) self.samples_layout.addWidget(self.saveclear_frame) # Clear samples button self.clear_samples = QPushButton(self.samples_page) self.set_icon(self.clear_samples, 'edit-delete') self.clear_samples.setText(' Clear table') self.clear_samples.setStyleSheet(self.style['md button']) self.clear_samples.clicked.connect(self.prompt_clear_data) # Save samples button self.save_samples = QPushButton(self.samples_page) self.set_icon(self.save_samples, 'document-save') self.save_samples.setText(' Save samples') self.save_samples.setStyleSheet(self.style['md button']) self.save_samples.clicked.connect(self.goto_main_page) # Add widgets above to save & clear layout self.saveclear_frame.layout().addWidget(self.clear_samples) self.saveclear_frame.layout().addWidget(self.save_samples) # ### # ### GATING PAGE # ### # Gating page layout self.gating_layout = QVBoxLayout(self.gating_page) # ## Title section # Title self.gates_title = QLabel(self.gating_page) self.gates_title.setText('Gating & outlier options') self.gates_title.setStyleSheet(self.style['title']) self.gates_title.adjustSize() self.gating_layout.addWidget(self.gates_title) # ## Gating options section # Gating header self.gate_header = QLabel(self.gating_page) self.gate_header.setText('Gating') self.gate_header.setStyleSheet(self.style['header']) self.gate_header.adjustSize() self.gating_layout.addWidget(self.gate_header) # Gating frame self.gate_frame = QFrame(self.gating_page) self.gate_frame.setFrameShape(QFrame.StyledPanel) self.gate_frame.setLayout(QFormLayout()) self.gating_layout.addWidget(self.gate_frame) # Gating button group self.gating_group = QButtonGroup(self) # Do not gate samples self.no_gates = QRadioButton(self.gating_page) self.no_gates.setObjectName('no_gate') self.no_gates.setText("Don't gate samples") self.no_gates.setStyleSheet(self.style['radio button']) self.no_gates.setChecked(True) self.gating_group.addButton(self.no_gates) self.no_gates.clicked.connect(self.activate_gate) # CyToF gating self.cytof_gates = QRadioButton(self.gating_page) self.cytof_gates.setObjectName('cytof') self.cytof_gates.setText('Mass Cytometry gating') self.cytof_gates.setStyleSheet(self.style['radio button']) self.cytof_gates.setToolTip( 'Exclude cells for which the average expression of all\n' 'markers is below the selected value') self.gating_group.addButton(self.cytof_gates) self.cytof_gates.clicked.connect(self.activate_gate) # CyToF gating spinbox self.cytof_gates_value = QDoubleSpinBox(self.gating_page) self.cytof_gates_value.setMinimum(0) self.cytof_gates_value.setMaximum(1) self.cytof_gates_value.setValue(0.1) self.cytof_gates_value.setSingleStep(0.05) self.cytof_gates_value.setEnabled(False) # scRNA-Seq gating self.rnaseq_gates = QRadioButton(self.gating_page) self.rnaseq_gates.setText('scRNA-Seq gating') self.rnaseq_gates.setStyleSheet(self.style['radio button']) self.rnaseq_gates.setToolTip( 'When calculating cutoff, ignore reads below the selected value') self.rnaseq_gates.setObjectName('rnaseq') self.gating_group.addButton(self.rnaseq_gates) self.rnaseq_gates.clicked.connect(self.activate_gate) # scRNA-Seq gating spinbox self.rnaseq_gates_value = QDoubleSpinBox(self.gating_page) self.rnaseq_gates_value.setMinimum(0) self.rnaseq_gates_value.setMaximum(10) self.rnaseq_gates_value.setValue(0) self.rnaseq_gates_value.setSingleStep(1) self.rnaseq_gates_value.setEnabled(False) # export gated population checkbox self.export_gated = QCheckBox(self.gating_page) self.export_gated.setText('Export gated cells as an output file') self.export_gated.setStyleSheet(self.style['checkbox']) self.export_gated.setEnabled(False) # Add widgets above to Gate frame layout self.gate_frame.layout().addRow(self.no_gates, QLabel()) self.gate_frame.layout().addRow(self.cytof_gates, self.cytof_gates_value) self.gate_frame.layout().addRow(self.rnaseq_gates, self.rnaseq_gates_value) self.gate_frame.layout().addRow(self.export_gated, QLabel()) # ## Outlier options section # Outlier header self.outlier_header = QLabel(self.gating_page) self.outlier_header.setText('Outliers') self.outlier_header.setStyleSheet(self.style['header']) self.outlier_header.adjustSize() self.gating_layout.addWidget(self.outlier_header) # Outlier frame self.outlier_frame = QFrame(self.gating_page) self.outlier_frame.setFrameShape(QFrame.StyledPanel) self.outlier_frame.setLayout(QVBoxLayout()) self.gating_layout.addWidget(self.outlier_frame) # Top outliers information self.top_outliers = QLabel(self.gating_page) self.top_outliers.setStyleSheet(self.style['label']) self.top_outliers.setText( 'By default, SCOUTS selects the top outliers from the population') self.top_outliers.setStyleSheet(self.style['label']) # Bottom outliers data self.bottom_outliers = QCheckBox(self.gating_page) self.bottom_outliers.setText('Include results for low outliers') self.bottom_outliers.setStyleSheet(self.style['checkbox']) # Non-outliers data self.not_outliers = QCheckBox(self.gating_page) self.not_outliers.setText('Include results for non-outliers') self.not_outliers.setStyleSheet(self.style['checkbox']) # Add widgets above to Gate frame layout self.outlier_frame.layout().addWidget(self.top_outliers) self.outlier_frame.layout().addWidget(self.bottom_outliers) self.outlier_frame.layout().addWidget(self.not_outliers) # ## Save/back button self.save_gates = QPushButton(self.gating_page) self.set_icon(self.save_gates, 'go-next') self.save_gates.setText(' Back to main menu') self.save_gates.setStyleSheet(self.style['md button']) self.gating_layout.addWidget(self.save_gates) self.save_gates.clicked.connect(self.goto_main_page) # ## Add empty label to take vertical space self.empty_label = QLabel(self.gating_page) self.empty_label.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.gating_layout.addWidget(self.empty_label) # ### # ### ICON SETTING # ### def set_icon(self, widget: QWidget, icon: str) -> None: """Associates an icon to a widget.""" i = QIcon() i.addPixmap( QPixmap( os.path.abspath( os.path.join(self.rootdir, 'src', 'default_icons', f'{icon}.svg')))) widget.setIcon(QIcon.fromTheme(icon, i)) # ### # ### STACKED WIDGET PAGE SWITCHING # ### def goto_main_page(self) -> None: """Switches stacked widget pages to the main page.""" self.stacked_pages.setCurrentWidget(self.main_page) def goto_samples_page(self) -> None: """Switches stacked widget pages to the samples table page.""" self.stacked_pages.setCurrentWidget(self.samples_page) def goto_gates_page(self) -> None: """Switches stacked widget pages to the gating & other options page.""" self.stacked_pages.setCurrentWidget(self.gating_page) # ### # ### MAIN PAGE GUI LOGIC # ### def get_path(self) -> None: """Opens a dialog box and sets the chosen file/folder path, depending on the caller widget.""" options = QFileDialog.Options() options |= QFileDialog.DontUseNativeDialog sender_name = self.sender().objectName() if sender_name == 'input': query, _ = QFileDialog.getOpenFileName(self, "Select file", "", "All Files (*)", options=options) elif sender_name == 'output': query = QFileDialog.getExistingDirectory(self, "Select Directory", options=options) else: return if query: getattr(self, f'{sender_name}_path').setText(query) def enable_single_excel(self) -> None: """Enables checkbox for generating a single Excel output.""" if self.output_excel.isChecked(): self.single_excel.setEnabled(True) else: self.single_excel.setEnabled(False) self.single_excel.setChecked(False) # ### # ### SAMPLE NAME/SAMPLE TABLE GUI LOGIC # ### def write_to_sample_table(self) -> None: """Writes data to sample table.""" table = self.sample_table ref = 'no' sample = self.sample_name.text() if sample: for cell in range(table.rowCount()): item = table.item(cell, 0) if item.text() == sample: self.same_sample() return if self.is_reference.isChecked(): for cell in range(table.rowCount()): item = table.item(cell, 1) if item.text() == 'yes': self.more_than_one_reference() return ref = 'yes' sample = QTableWidgetItem(sample) is_reference = QTableWidgetItem(ref) is_reference.setFlags(Qt.ItemIsEnabled) row_position = table.rowCount() table.insertRow(row_position) table.setItem(row_position, 0, sample) table.setItem(row_position, 1, is_reference) self.is_reference.setChecked(False) self.sample_name.setText('') def remove_from_sample_table(self) -> None: """Removes data from sample table.""" table = self.sample_table rows = set(index.row() for index in table.selectedIndexes()) for index in sorted(rows, reverse=True): self.sample_table.removeRow(index) def prompt_clear_data(self) -> None: """Prompts option to clear all data in the sample table.""" if self.confirm_clear_data(): table = self.sample_table while table.rowCount(): self.sample_table.removeRow(0) # ### # ### GATING GUI LOGIC # ### def activate_gate(self) -> None: """Activates/deactivates buttons related to gating.""" if self.sender().objectName() == 'no_gate': self.cytof_gates_value.setEnabled(False) self.rnaseq_gates_value.setEnabled(False) self.export_gated.setEnabled(False) self.export_gated.setChecked(False) elif self.sender().objectName() == 'cytof': self.cytof_gates_value.setEnabled(True) self.rnaseq_gates_value.setEnabled(False) self.export_gated.setEnabled(True) elif self.sender().objectName() == 'rnaseq': self.cytof_gates_value.setEnabled(False) self.rnaseq_gates_value.setEnabled(True) self.export_gated.setEnabled(True) # ### # ### CONNECT SCOUTS TO ANALYTICAL MODULES # ### def run(self) -> None: """Runs SCOUTS as a Worker, based on user input in the GUI.""" try: data = self.parse_input() except Exception as error: trace = traceback.format_exc() self.propagate_error((error, trace)) else: data['widget'] = self worker = Worker(func=start_scouts, **data) worker.signals.started.connect(self.analysis_has_started) worker.signals.finished.connect(self.analysis_has_finished) worker.signals.success.connect(self.success_message) worker.signals.error.connect(self.propagate_error) self.threadpool.start(worker) def parse_input(self) -> Dict: """Returns user input on the GUI as a dictionary.""" # Input and output input_dict = { 'input_file': str(self.input_path.text()), 'output_folder': str(self.output_path.text()) } if not input_dict['input_file'] or not input_dict['output_folder']: raise NoIOPathError # Set cutoff by reference or by sample rule input_dict['cutoff_rule'] = self.cutoff_group.checkedButton( ).objectName() # 'sample', 'ref', 'sample ref' # Outliers for each individual marker or any marker in row input_dict['marker_rule'] = self.markers_group.checkedButton( ).objectName() # 'single', 'any', 'single any' # Tukey factor used for calculating cutoff input_dict['tukey_factor'] = float( self.tukey_group.checkedButton().text()) # '1.5', '3.0' # Output settings input_dict['export_csv'] = True if self.output_csv.isChecked( ) else False input_dict['export_excel'] = True if self.output_excel.isChecked( ) else False input_dict['single_excel'] = True if self.single_excel.isChecked( ) else False # Retrieve samples from sample table input_dict['sample_list'] = [] for tuples in self.yield_samples_from_table(): input_dict['sample_list'].append(tuples) if not input_dict['sample_list']: raise NoSampleError # Set gate cutoff (if any) input_dict['gating'] = self.gating_group.checkedButton().objectName( ) # 'no_gate', 'cytof', 'rnaseq' input_dict['gate_cutoff_value'] = None if input_dict['gating'] != 'no_gate': input_dict['gate_cutoff_value'] = getattr( self, f'{input_dict["gating"]}_gates_value').value() input_dict['export_gated'] = True if self.export_gated.isChecked( ) else False # Generate results for non-outliers input_dict['non_outliers'] = False if self.not_outliers.isChecked(): input_dict['non_outliers'] = True # Generate results for bottom outliers input_dict['bottom_outliers'] = False if self.bottom_outliers.isChecked(): input_dict['bottom_outliers'] = True # return dictionary with all gathered inputs return input_dict def yield_samples_from_table( self) -> Generator[Tuple[str, str], None, None]: """Yields sample names from the sample table.""" table = self.sample_table for cell in range(table.rowCount()): sample_name = table.item(cell, 0).text() sample_type = table.item(cell, 1).text() yield sample_name, sample_type # ### # ### MESSAGE BOXES # ### def analysis_has_started(self) -> None: """Disables run button while SCOUTS analysis is underway.""" self.run_button.setText(' Working...') self.run_button.setEnabled(False) def analysis_has_finished(self) -> None: """Enables run button after SCOUTS analysis has finished.""" self.run_button.setEnabled(True) self.run_button.setText(' Run!') def success_message(self) -> None: """Info message box used when SCOUTS finished without errors.""" title = "Analysis finished!" mes = "Your analysis has finished. No errors were reported." if self.stacked_pages.isEnabled() is True: QMessageBox.information(self, title, mes) def memory_warning(self) -> None: """Warning message box used when user wants to generate a single excel file.""" if self.sender().isChecked(): title = 'Memory warning!' mes = ( "Depending on your dataset, this option can consume a LOT of memory and take" " a long time to process. Please make sure that your computer can handle it!" ) QMessageBox.information(self, title, mes) def same_sample(self) -> None: """Error message box used when the user tries to input the same sample twice in the sample table.""" title = 'Error: sample name already in table' mes = ( "Sorry, you can't do this because this sample name is already in the table. " "Please select a different name.") QMessageBox.critical(self, title, mes) def more_than_one_reference(self) -> None: """Error message box used when the user tries to input two reference samples in the sample table.""" title = "Error: more than one reference selected" mes = ( "Sorry, you can't do this because there is already a reference column in the table. " "Please remove it before adding a reference.") QMessageBox.critical(self, title, mes) def confirm_clear_data(self) -> bool: """Question message box used to confirm user action of clearing sample table.""" title = 'Confirm Action' mes = "Table will be cleared. Are you sure?" reply = QMessageBox.question(self, title, mes, QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if reply == QMessageBox.Yes: return True return False # ### # ### EXCEPTIONS & ERRORS # ### def propagate_error(self, error: Tuple[Exception, str]) -> None: """Calls the appropriate error message box based on type of Exception raised.""" if isinstance(error[0], NoIOPathError): self.no_io_path_error_message() elif isinstance(error[0], NoReferenceError): self.no_reference_error_message() elif isinstance(error[0], NoSampleError): self.no_sample_error_message() elif isinstance(error[0], PandasInputError): self.pandas_input_error_message() elif isinstance(error[0], SampleNamingError): self.sample_naming_error_message() else: self.generic_error_message(error) def no_io_path_error_message(self) -> None: """Message displayed when the user did not include an input file path, or an output folder path.""" title = 'Error: no file/folder' message = ("Sorry, no input file and/or output folder was provided. " "Please add the path to the necessary file/folder.") QMessageBox.critical(self, title, message) def no_reference_error_message(self) -> None: """Message displayed when the user wants to analyse cutoff based on a reference, but did not specify what sample corresponds to the reference.""" title = "Error: No reference selected" message = ( "Sorry, no reference sample was found on the sample list, but analysis was set to " "reference. Please add a reference sample, or change the rule for cutoff calculation." ) QMessageBox.critical(self, title, message) def no_sample_error_message(self) -> None: """Message displayed when the user did not add any samples to the sample table.""" title = "Error: No samples selected" message = ( "Sorry, the analysis cannot be performed because no sample names were input. " "Please add your sample names.") QMessageBox.critical(self, title, message) def pandas_input_error_message(self) -> None: """Message displayed when the input file cannot be read (likely because it is not a Excel or csv file).""" title = 'Error: unexpected input file' message = ( "Sorry, the input file could not be read. Please make sure that " "the data is save in a valid format (supported formats are: " ".csv, .xlsx).") QMessageBox.critical(self, title, message) def sample_naming_error_message(self) -> None: """Message displayed when none of the sample names passed by the user are found in the input DataFrame.""" title = 'Error: sample names not in input file' message = ( "Sorry, your sample names were not found in the input file. Please " "make sure that the names were typed correctly (case-sensitive).") QMessageBox.critical(self, title, message) def generic_error_message(self, error: Tuple[Exception, str]) -> None: """Error message box used to display any error message (including traceback) for any uncaught errors.""" title = 'An error occurred!' name, trace = error QMessageBox.critical(self, title, f"{str(name)}\n\nfull traceback:\n{trace}") def not_implemented_error_message(self) -> None: """Error message box used when the user accesses a functionality that hasn't been implemented yet.""" title = "Not yet implemented" mes = "Sorry, this functionality has not been implemented yet." QMessageBox.critical(self, title, mes) # ### # ### HELP & QUIT # ### @staticmethod def get_help() -> None: """Opens SCOUTS documentation on the browser. Called when the user clicks the "help" button""" webbrowser.open('https://scouts.readthedocs.io/en/master/') def closeEvent(self, event: QEvent) -> None: """Defines the message box for when the user wants to quit SCOUTS.""" title = 'Quit SCOUTS' mes = "Are you sure you want to quit?" reply = QMessageBox.question(self, title, mes, QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if reply == QMessageBox.Yes: self.stacked_pages.setEnabled(False) message = self.quit_message() waiter = Waiter(waiter_func=self.threadpool.activeThreadCount) waiter.signals.started.connect(message.show) waiter.signals.finished.connect(message.destroy) waiter.signals.finished.connect(sys.exit) self.threadpool.start(waiter) event.ignore() def quit_message(self) -> QDialog: """Displays a window while SCOUTS is exiting""" message = QDialog(self) message.setWindowTitle('Exiting SCOUTS') message.resize(300, 50) label = QLabel('SCOUTS is exiting, please wait...', message) label.setStyleSheet(self.style['label']) label.adjustSize() label.setAlignment(Qt.AlignCenter) label.move(int((message.width() - label.width()) / 2), int((message.height() - label.height()) / 2)) return message
class QCartConnectDialog(QDialog): def __init__(self): super(QCartConnectDialog, self).__init__() self.accepted = False self._init_widgets() def accept(self): self.accepted = True super().accept() def reject(self): self.accepted = False super().reject() def handleRadioButtons(self): if self.connectRad.isChecked(): self.hostText.setEnabled(True) self.portText.setEnabled(True) self.hostText.setText("") self.portText.setText("") else: self.hostText.setEnabled(False) self.portText.setEnabled(False) self.hostText.setText("NEW") self.portText.setText("NEW") def _init_widgets(self): self.resize(530, 180) main_layout = QVBoxLayout() frame = QFrame() frame.setFrameShape(QFrame.NoFrame) frame.setFrameShadow(QFrame.Plain) frameLayout = QVBoxLayout() self.connectRad = QRadioButton(frame) self.createRad = QRadioButton(frame) self.connectRad.setChecked(True) self.connectRad.toggled.connect(self.handleRadioButtons) self.createRad.toggled.connect(self.handleRadioButtons) frameLayout.addWidget(self.connectRad) internalFrame = QFrame() internalFrameLayout = QHBoxLayout(internalFrame) hostLabel = QLabel() portLabel = QLabel() self.hostText = QLineEdit() self.portText = QLineEdit() internalFrameLayout.addWidget(hostLabel) internalFrameLayout.addWidget(self.hostText) internalFrameLayout.addWidget(portLabel) internalFrameLayout.addWidget(self.portText) self.portText.setMaximumSize(QSize(80, 200)) internalFrame.setLayout(internalFrameLayout) frameLayout.addWidget(internalFrame) frameLayout.addWidget(self.createRad) frame.setLayout(frameLayout) self.buttonBox = QDialogButtonBox(self) self.buttonBox.setOrientation(QtCore.Qt.Horizontal) self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) main_layout.addWidget(frame) main_layout.addWidget(self.buttonBox) self.setLayout(main_layout) self.setWindowTitle("Cartprograph Connect") self.connectRad.setText("Connect to Existing Cartprograph Server") self.createRad.setText("Create New Cartprograph Server") hostLabel.setText("Host") portLabel.setText("Port") @classmethod def launch(cls): dialog = cls() dialog.exec_() if dialog.accepted: return True, dialog.hostText.text(), dialog.portText.text() return False, None, None
class Music(QMainWindow): def __init__(self): super(Music, self).__init__() self.setGeometry(20, 50, 522, 175) self.setMinimumSize(522, 175) self.setMaximumSize(522, 175) self.setWindowTitle('Muse') self.setWindowIcon(QIcon('arti.PNG')) self.setFont(QFont('Roboto', 12)) palette = QPalette() palette.setColor(palette.Window, QColor('#000000')) palette.setColor(palette.WindowText, QColor('#FFFFFF')) self.setPalette(palette) self.menubar = QMenuBar(self) self.menubar.setGeometry(0, 0, 682, 21) self.menubar.setFont(QFont('Roboto', 10)) self.date_menu = QMenu(self.menubar) self.date_menu.setTitle(str(datetime.now().strftime('%d-%m-%Y'))) self.setMenuBar(self.menubar) self.menubar.addAction(self.date_menu.menuAction()) self.song = QLineEdit(self) self.song.setPlaceholderText( 'Enter the name of song you want to search for:') self.song.setGeometry(10, 30, 501, 31) self.spotify = QRadioButton(self) self.spotify.setText('Spotify') self.spotify.setGeometry(120, 80, 101, 21) self.gaana = QRadioButton(self) self.gaana.setText('Gaana') self.gaana.setGeometry(330, 80, 91, 21) self.search = QPushButton(self) self.search.setText('Search') self.search.setGeometry(380, 130, 121, 31) self.search.clicked.connect(lambda: self.on_click()) self.search.setCursor(QCursor(Qt.PointingHandCursor)) self.label = QLabel(self) self.label.setGeometry(10, 130, 341, 31) def on_click(self): self.song_search = self.song.text() if self.song.text(): if self.spotify.isChecked(): self.speak('Searching your song on Spotify.') spotify_url = 'https://open.spotify.com/search/' webbrowser.open(spotify_url + self.song_search) elif self.gaana.isChecked(): self.speak('Searching your song on Gaana.') gaana_url = 'https://gaana.com/search/' webbrowser.open(gaana_url + self.song_search) else: self.speak('Please choose either Spotify or Gaana.') else: self.speak('Please type a song name first') self.song.clear() def speak(self, audio): self.engine = pyttsx3.init('sapi5') self.voices = self.engine.getProperty('voices') self.engine.setProperty('voice', self.voices[1].id) self.engine.setProperty('rate', 165) self.engine.say(audio) self.label.setText(audio) self.engine.runAndWait()
class PetrophysicsOptions(QWidget): polymorphic_states = { 'DParsons': {'param1': 'Coeficiente de Dykstra-Parsons', 'param2': 'Grau de heterogenêidade', 'param3': '', 'param4': '', 'prop1': ['Permeabilidade (mD)'], 'prop2': ['Permeabilidade (mD)'], 'prop3': '', 'prop4': ''}, 'Winland': {'param1': 'Garganta de Poro (Winland R35)', 'param2': '', 'param3': '', 'param4': '', 'prop1': ['Permeabilidade (mD)', 'Porosidade (%)'], 'prop2': 'Porosidade (%)', 'prop3': '', 'prop4': ''}, 'Lucia': {'param1': 'Classificação de Lucia (Gráfico de classes carbonáticas)', 'param2': '', 'param3': '', 'param4': '', 'prop1': ['Permeabilidade (mD)', 'Porosidade Interpartícula (%)'], 'prop2': '', 'prop3': '', 'prop4': ''}, 'RQIFZI': {'param1': 'RQI (μm)', 'param2': 'FZI (gráfico)', 'param3': '', 'param4': '', 'prop1': ['Permeabilidade', 'Porosidade (%)'], 'prop2': ['Permeabilidade', 'Porosidade (%)'], 'prop3': [], 'prop4': []}, 'TCoates': {'param1': 'FFI', 'param2': 'BVI', 'param3': 'Permeabilidade (mD)', 'param4': 'Swir (%)', 'prop1': ['Swir (%)', 'Porosidade (%)'], 'prop2': ['Swir (%)', 'Porosidade (%)'], 'prop3': ['Swir (%)', 'Porosidade (%)'], 'prop4': ['Permeabilidade (mD)', 'Porosidade (%)']}, 'KCarman': {'param1': 'Permeabilidade (mD)', 'param2': 'SVgr (cm-1)', 'param3': '', 'param4': '', 'prop1': ['Porosidade (%)', 'SVgr (cm-1)'], 'prop2': ['Permeabilidade (mD)', 'Porosidade (%)'], 'prop3': ['Permeabilidade (cm²)', 'Porosidade (decimal)'], 'prop4': []} } ready2calculate = Signal(bool) def __init__(self, _mode='KCarman'): super().__init__() self.mode = _mode self.subtitle = QLabel('Calcular:') self.label1 = QLabel() self.label2 = QLabel() self.label3 = QLabel() self.label4 = QLabel() self.labels = [self.label1, self.label2, self.label3, self.label4] for l in self.labels: l.setWordWrap(True) self.param1 = QRadioButton() self.param2 = QRadioButton() self.param3 = QRadioButton() self.param4 = QRadioButton() self.x_column = QLineEdit() self.y_column = QLineEdit() self.z_column = QLineEdit() self.destination_column = QLineEdit() self.results_l = QLabel('Resultados da análise: ') self.results = QTextEdit() self.unit_selector = Dropdown.Dropdown(['Darcy', 'SI']) self.run = QPushButton('Começar Análise') self.connections() self.changeMode(_mode) self.buildLayout() self.property_to_calculate = self.property_to_calculate = self.polymorphic_states[self.mode]['param1'] self.payload = {} stly_sheet = "QRadioButton::indicator {width: 13px; height: 13px;} QRadioButton::indicator::unchecked {image: url(:/images/radiobutton_unchecked.png)} QRadioButton::indicator:unchecked:hover {image: url(:/images/radiobutton_unchecked_hover.png);}" self.subtitle.setStyleSheet('color: white') self.label1.setStyleSheet('color: white') self.label2.setStyleSheet('color: white') self.label3.setStyleSheet('color: white') self.label4.setStyleSheet('color: white') self.param1.setStyleSheet('color: white') self.param2.setStyleSheet('color: white') self.param3.setStyleSheet('color: white') self.param4.setStyleSheet('color: white') self.x_column.setStyleSheet('background-color: white; color: black') self.y_column.setStyleSheet('background-color: white; color: black') self.z_column.setStyleSheet('background-color: white; color: black') self.results.setStyleSheet('background-color: white; color: black') self.setStyleSheet('color:white; font-family: Bahnschrift SemiLight Condensed; font-size: 14px;') def buildLayout(self): layout = QFormLayout() a = self.polymorphic_states[self.mode]['prop1'] b = self.polymorphic_states[self.mode]['prop2'] c = self.polymorphic_states[self.mode]['prop3'] d = self.polymorphic_states[self.mode]['prop4'] layout.addWidget(self.subtitle) if len(self.param1.text()) != 0: layout.addWidget(self.param1) if len(self.param2.text()) != 0: layout.addWidget(self.param2) if len(self.param3.text()) != 0: layout.addWidget(self.param3) if len(self.param4.text()) != 0: layout.addWidget(self.param4) if len(self.label1.text()) != 0: layout.addWidget(self.label1) layout.addWidget(self.x_column) if len(self.label2.text()) != 0: layout.addWidget(self.label2) layout.addWidget(self.y_column) if len(self.label3.text()) != 0: layout.addWidget(self.label3) layout.addWidget(self.z_column) #if len(self.label4.text()) != 0: #layout.addWidget(self.label4) #layout.addWidget(self.destination_column) if self.mode == 'RQIFZI': layout.addWidget(QLabel('Sistema de Unidades: ')) layout.addWidget(self.unit_selector) layout.addWidget(self.run) if self.mode == 'DParsons': layout.addWidget(self.results_l) layout.addWidget(self.results) if self.mode == 'Lucia': layout.addWidget(self.results_l) layout.addWidget(self.results) self.setLayout(layout) def connections(self): self.param1.clicked.connect(self.param1Active) self.param2.clicked.connect(self.param2Active) self.param3.clicked.connect(self.param3Active) self.param4.clicked.connect(self.param4Active) self.run.clicked.connect(self.collectPayload) def changeMode(self, _mode): self.mode = _mode self.param1.setText(self.polymorphic_states[self.mode]['param1']) self.param1.click() self.param2.setText(self.polymorphic_states[self.mode]['param2']) self.param3.setText(self.polymorphic_states[self.mode]['param3']) self.param4.setText(self.polymorphic_states[self.mode]['param4']) def param1Active(self): self.label1.setText('Selecione a coluna com os valores de ' + self.polymorphic_states[self.mode]['prop1'][0]) try: self.label2.setText('Selecione a coluna com os valores de ' + self.polymorphic_states[self.mode]['prop1'][1]) except IndexError: self.label2.setText('') try: self.label3.setText('Selecione a coluna com os valores de ' + self.polymorphic_states[self.mode]['prop1'][2]) except IndexError: self.label3.setText('') self.label4.setText('Selecione a coluna para os valores de ' + self.polymorphic_states[self.mode]['param1']) self.property_to_calculate = self.polymorphic_states[self.mode]['param1'] def param2Active(self): self.label1.setText('Selecione a coluna com os valores de ' + self.polymorphic_states[self.mode]['prop2'][0]) try: self.label2.setText('Selecione a coluna com os valores de ' + self.polymorphic_states[self.mode]['prop2'][1]) except IndexError: self.label2.setText('') try: self.label3.setText('Selecione a coluna com os valores de ' + self.polymorphic_states[self.mode]['prop2'][2]) except IndexError: self.label3.setText('') self.label4.setText('Selecione a coluna para os valores de ' + self.polymorphic_states[self.mode]['param2']) self.property_to_calculate = self.polymorphic_states[self.mode]['param2'] def param3Active(self): self.label1.setText('Selecione a coluna com os valores de ' + self.polymorphic_states[self.mode]['prop3'][0]) try: self.label2.setText('Selecione a coluna com os valores de ' + self.polymorphic_states[self.mode]['prop3'][1]) except IndexError: self.label2.setText('') try: self.label3.setText('Selecione a coluna com os valores de ' + self.polymorphic_states[self.mode]['prop3'][2]) except IndexError: self.label3.setText('') self.label4.setText('Selecione a coluna para os valores de ' + self.polymorphic_states[self.mode]['param3']) self.property_to_calculate = self.polymorphic_states[self.mode]['param3'] def param4Active(self): self.label1.setText('Selecione a coluna com os valores de ' + self.polymorphic_states[self.mode]['prop4'][0]) try: self.label2.setText('Selecione a coluna com os valores de ' + self.polymorphic_states[self.mode]['prop4'][1]) except IndexError: self.label2.setText('') try: self.label3.setText('Selecione a coluna com os valores de ' + self.polymorphic_states[self.mode]['prop4'][2]) except IndexError: self.label3.setText('') self.label4.setText('Selecione a coluna para os valores de ' + self.polymorphic_states[self.mode]['param4']) self.property_to_calculate = self.polymorphic_states[self.mode]['param4'] def collectPayload(self): payload = { 'calculate': self.property_to_calculate, 'x_column': self.x_column.text(), 'y_column': self.y_column.text(), 'z_column': self.z_column.text(), 'column_range': self.unit_selector.currentText(), 'output_selection': None, 'output_column': self.destination_column.text() } self.payload = payload print(payload) self.ready2calculate.emit(True)