def _add_box_with_requirements(self, alternative: RequirementList): group_box = self._create_box_in_grid() group_box.rows = [] vertical_layout = QVBoxLayout(group_box) vertical_layout.setObjectName(f"Layout with index {self._current_last_index - 1}") vertical_layout.setAlignment(Qt.AlignTop) empty = True trick_level = LayoutTrickLevel.NO_TRICKS for item in sorted(alternative.items): if self.edit_mode: ItemRow(group_box, vertical_layout, self.resource_database, item, group_box.rows) else: if item.resource.resource_type == ResourceType.DIFFICULTY: trick_level = LayoutTrickLevel.from_number(item.amount) else: empty = False label = QLabel(group_box) if item.resource.resource_type == ResourceType.TRICK: label.setText(f"{item.resource} ({LayoutTrickLevel.from_number(item.amount).long_name})") else: label.setText(item.pretty_text) vertical_layout.addWidget(label) if self.edit_mode: tools_layout = QHBoxLayout(group_box) tools_layout.setObjectName(f"Tools layout with index {self._current_last_index - 1}") vertical_layout.addLayout(tools_layout) add_new_button = QPushButton(group_box) add_new_button.setText("New Requirement") tools_layout.addWidget(add_new_button) delete_button = QPushButton(group_box) delete_button.setText("Delete") delete_button.clicked.connect(partial(self._delete_alternative, group_box)) tools_layout.addWidget(delete_button) def _new_row(): empty_item = IndividualRequirement( self.resource_database.get_by_type(ResourceType.ITEM)[0], 1, False ) ItemRow(group_box, vertical_layout, self.resource_database, empty_item, group_box.rows) vertical_layout.removeItem(tools_layout) vertical_layout.addLayout(tools_layout) add_new_button.clicked.connect(_new_row) else: group_box.setTitle(f"Difficulty: {trick_level.long_name}") if empty: label = QLabel(group_box) label.setText("No requirements.") vertical_layout.addWidget(label) return group_box
class Ui_PDFViewer(object): def setupUi(self, PDFViewer): if not PDFViewer.objectName(): PDFViewer.setObjectName(u"PDFViewer") PDFViewer.resize(820, 652) icon = QIcon() icon.addFile(u":/icons/icon.ico", QSize(), QIcon.Normal, QIcon.Off) PDFViewer.setWindowIcon(icon) self.centralwidget = QWidget(PDFViewer) self.centralwidget.setObjectName(u"centralwidget") self.verticalLayout = QVBoxLayout(self.centralwidget) self.verticalLayout.setObjectName(u"verticalLayout") self.webView = QWebView(self.centralwidget) self.webView.setObjectName(u"webView") sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.webView.sizePolicy().hasHeightForWidth()) self.webView.setSizePolicy(sizePolicy) self.webView.setProperty("url", QUrl(u"")) self.verticalLayout.addWidget(self.webView) PDFViewer.setCentralWidget(self.centralwidget) self.retranslateUi(PDFViewer) QMetaObject.connectSlotsByName(PDFViewer) # setupUi def retranslateUi(self, PDFViewer): PDFViewer.setWindowTitle( QCoreApplication.translate("PDFViewer", u"MainWindow", None))
def __init__(self, item, parent): super(Override, self).__init__(parent=parent) self.path = None self.attributeUI = None self.item = weakref.ref(item) layout = QVBoxLayout() layout.setObjectName('override_vertical_box_layout') layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(utils.dpiScale(2)) self._setupMainOverrideGroupBox(layout) self.setLayout(layout) # Unwrap the layout into a pointer to be able to get the UI name. # We use fullName() to ensure a unique name is used layoutName = mui.MQtUtil.fullName(long(getCppPointer(layout)[0])) cmds.setParent(layoutName) self._uiLayout = cmds.columnLayout(adjustableColumn=True) self._dropBoxInit() if item.isUniqueOverride(): self.target = QLabel(kAppliedToUnique % item.targetNodeName()) self.target.setAlignment(Qt.AlignBottom | Qt.AlignCenter) layout.addWidget(self.target)
class Ui_dlgAddUser(QDialog): def __init__(self): super().__init__() self.setupUi() def setupUi(self): self.setObjectName("dlgAddUser") self.resize(335, 154) self.setWindowFlags(Qt.MSWindowsFixedSizeDialogHint) self.gridLayout = QGridLayout(self) self.gridLayout.setObjectName("gridLayout") self.groupBox = QGroupBox(self) self.groupBox.setObjectName("groupBox") self.verticalLayout = QVBoxLayout(self.groupBox) self.verticalLayout.setObjectName("verticalLayout") self.leFullName = QLineEdit(self.groupBox) self.leFullName.setObjectName("leFullName") self.verticalLayout.addWidget(self.leFullName) self.leUsuario = QLineEdit(self.groupBox) self.leUsuario.setObjectName("leUsuario") self.verticalLayout.addWidget(self.leUsuario) self.lePassword = QLineEdit(self.groupBox) self.lePassword.setObjectName("lePassword") self.lePassword.setEchoMode(QLineEdit.Password) self.verticalLayout.addWidget(self.lePassword) self.gridLayout.addWidget(self.groupBox, 0, 0, 1, 1) self.horizontalLayout = QHBoxLayout() self.horizontalLayout.setObjectName("horizontalLayout") spacerItem = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout.addItem(spacerItem) self.pbAddUser = QPushButton(self) self.pbAddUser.setObjectName("pbAddUser") self.horizontalLayout.addWidget(self.pbAddUser) self.pbCancel = QPushButton(self) self.pbCancel.setObjectName("pbCancel") self.horizontalLayout.addWidget(self.pbCancel) self.gridLayout.addLayout(self.horizontalLayout, 1, 0, 1, 1) self.retranslateUi() QMetaObject.connectSlotsByName(self) def retranslateUi(self): self.setWindowTitle( QApplication.translate("dlgAddUser", "Dialog", None, -1)) self.groupBox.setTitle( QApplication.translate("dlgAddUser", "GroupBox", None, -1)) self.leFullName.setPlaceholderText( QApplication.translate("dlgAddUser", "Ingresar nombre completo", None, -1)) self.leUsuario.setPlaceholderText( QApplication.translate("dlgAddUser", "Ingrese nombre de usuario", None, -1)) self.lePassword.setPlaceholderText( QApplication.translate("dlgAddUser", "Ingrese su clave", None, -1)) self.pbAddUser.setText( QApplication.translate("dlgAddUser", "Add user", None, -1)) self.pbCancel.setText( QApplication.translate("dlgAddUser", "Cancel", None, -1))
class Ui_Form(object): def setupUi(self, Form): if not Form.objectName(): Form.setObjectName(u"Form") Form.resize(400, 300) self.horizontalLayoutWidget = QWidget(Form) self.horizontalLayoutWidget.setObjectName(u"horizontalLayoutWidget") self.horizontalLayoutWidget.setGeometry(QRect(9, 10, 381, 271)) self.horizontalLayout = QHBoxLayout(self.horizontalLayoutWidget) self.horizontalLayout.setObjectName(u"horizontalLayout") self.horizontalLayout.setContentsMargins(0, 0, 0, 0) self.main_list = QListWidget(self.horizontalLayoutWidget) self.main_list.setObjectName(u"main_list") self.horizontalLayout.addWidget(self.main_list) self.verticalLayout = QVBoxLayout() self.verticalLayout.setObjectName(u"verticalLayout") self.button_add = QPushButton(self.horizontalLayoutWidget) self.button_add.setObjectName(u"button_add") self.verticalLayout.addWidget(self.button_add) self.button_remove = QPushButton(self.horizontalLayoutWidget) self.button_remove.setObjectName(u"button_remove") self.verticalLayout.addWidget(self.button_remove) self.verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding) self.verticalLayout.addItem(self.verticalSpacer) self.button_clear = QPushButton(self.horizontalLayoutWidget) self.button_clear.setObjectName(u"button_clear") self.verticalLayout.addWidget(self.button_clear) self.horizontalLayout.addLayout(self.verticalLayout) self.retranslateUi(Form) QMetaObject.connectSlotsByName(Form) # setupUi def retranslateUi(self, Form): Form.setWindowTitle(QCoreApplication.translate("Form", u"Form", None)) self.button_add.setText( QCoreApplication.translate("Form", u"Add", None)) self.button_remove.setText( QCoreApplication.translate("Form", u"Remove", None)) self.button_clear.setText( QCoreApplication.translate("Form", u"Clear", None))
class UiMainWindow: def setupUi(self, main_window): main_window.setObjectName('main_window') main_window.setWindowTitle('qt_mvc Demo') main_window.resize(800, 600) # pyqtgraph configuration setConfigOption('background', 'w') setConfigOption('foreground', 'k') # Divide window into left (toolbar) and right(main) vertical layouts self.central_widget = QWidget(main_window) self.central_widget.setObjectName('centralwidget') self.central_layout = QHBoxLayout(self.central_widget) self.central_layout.setObjectName('centrallayout') self.left_bar_layout = QVBoxLayout() self.left_bar_layout.setObjectName('left_bar_layout') self.main_layout = QVBoxLayout() self.main_layout.setObjectName('main_layout') self.central_layout.addLayout(self.left_bar_layout, 0) self.central_layout.addLayout(self.main_layout, 1) # Populate left toolbar self.calctype = CalcTypeButtonGroup('Calc Type') self.calctype.setObjectName('calctype_menu') self.stack_model_selections = QStackedWidget() self.stack_model_selections.setObjectName('model_selection_stack') self.multiplet_menu = MultipletButtonGroup('Multiplet') self.multiplet_menu.setObjectName('multiplet_menu') self.abc_menu = ABC_ButtonGroup('Number of Spins') self.abc_menu.setObjectName('abc_menu') self.dnmr_menu = DNMR_ButtonGroup('DNMR') self.dnmr_menu.setObjectName('dnmr_menu') for menu in [self.multiplet_menu, self.abc_menu, self.dnmr_menu]: self.stack_model_selections.addWidget(menu) self.stack_model_selections.setCurrentWidget(self.multiplet_menu) self.left_bar_layout.addWidget(self.calctype, 0) self.left_bar_layout.addWidget(self.stack_model_selections, 0) self.left_bar_layout.addWidget(QWidget(), 1) # Add toolbars and plot area to main layout self.toolbars = toolbar_stack(main_window, main_window.view_state) self.plot = PlotWidget() self.plot.getViewBox().invertX(True) # Reverse x axis "NMR style" self.main_layout.addWidget(self.toolbars, 0) self.main_layout.addWidget(self.plot, 1) main_window.setCentralWidget(self.central_widget)
def _add_box_with_labels(self, labels: Iterable[str]) -> QGroupBox: group_box = self._create_box_in_grid() vertical_layout = QVBoxLayout(group_box) vertical_layout.setObjectName(f"Layout with index {self._current_last_index - 1}") vertical_layout.setAlignment(Qt.AlignTop) vertical_layout.setContentsMargins(11, 11, 11, 11) vertical_layout.setSpacing(6) group_box.vertical_layout = vertical_layout for text in labels: label = QLabel(group_box) label.setText(text) vertical_layout.addWidget(label) return group_box
class Ui_StripDialog(object): def setupUi(self, StripDialog): if not StripDialog.objectName(): StripDialog.setObjectName(u"StripDialog") StripDialog.resize(342, 139) self.verticalLayoutWidget = QWidget(StripDialog) self.verticalLayoutWidget.setObjectName(u"verticalLayoutWidget") self.verticalLayoutWidget.setGeometry(QRect(40, 10, 266, 121)) self.verticalLayout = QVBoxLayout(self.verticalLayoutWidget) self.verticalLayout.setObjectName(u"verticalLayout") self.verticalLayout.setContentsMargins(0, 0, 0, 0) self.horizontalLayout = QHBoxLayout() self.horizontalLayout.setObjectName(u"horizontalLayout") self.StripChText = QLabel(self.verticalLayoutWidget) self.StripChText.setObjectName(u"StripChText") self.horizontalLayout.addWidget(self.StripChText) self.StripCh = QLineEdit(self.verticalLayoutWidget) self.StripCh.setObjectName(u"StripCh") self.horizontalLayout.addWidget(self.StripCh) self.verticalLayout.addLayout(self.horizontalLayout) self.OKButton = QPushButton(self.verticalLayoutWidget) self.OKButton.setObjectName(u"OKButton") self.verticalLayout.addWidget(self.OKButton) self.retranslateUi(StripDialog) QMetaObject.connectSlotsByName(StripDialog) # setupUi def retranslateUi(self, StripDialog): StripDialog.setWindowTitle( QCoreApplication.translate("StripDialog", u"\u53bb\u9664\u5b57\u7b26", None)) self.StripChText.setText( QCoreApplication.translate( "StripDialog", u"\u8981\u53bb\u9664\u7684\u5b57\u7b26\uff1a", None)) self.OKButton.setText( QCoreApplication.translate("StripDialog", u"\u786e\u8ba4", None))
def __init__(self, item, parent): super(BasicCollection, self).__init__(parent=parent) # item is a weakref. self.item = item self.path = None layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(utils.dpiScale(2)) layout.setObjectName('collection_vertical_box_layout') self._setupMainCollectionGroupBox(layout) self.setLayout(layout) # Unwrap the layout into a pointer to be able to get the UI name. # We use fullName() to ensure a unique name is used self._layoutName = mui.MQtUtil.fullName( long(getCppPointer(self.layout())[0])) self.preSelector() self.setupSelector(layout)
class Ui_MainWindow: """This class holds all the UI structral info: widgets and their organization. main_window is the parent app window, which handles hooking the GUI widgets up to the controller/model.""" def setupUi(self, main_window): main_window.setObjectName('main_window') main_window.setWindowTitle('qt_mvc Demo') main_window.resize(800, 600) self.central_widget = QWidget(main_window) self.central_widget.setObjectName('centralwidget') self.central_layout = QVBoxLayout(self.central_widget) self.central_layout.setObjectName('centrallayout') self.top_bar_layout = QHBoxLayout() self.top_bar_layout.setObjectName('top_barlayout') self.base_label = QLabel('Base: ') self.base_entry = QDoubleSpinBox() self.base_entry.setObjectName('base_entry') self.exp_label = QLabel('Exponent: ') self.exp_entry = QDoubleSpinBox() self.exp_entry.setObjectName('exp_entry') self.base_entry.setValue(1) self.base_entry.setMinimum(0.1) self.exp_entry = QDoubleSpinBox() self.exp_entry.setValue(2) for widget in [ self.base_label, self.base_entry, self.exp_label, self.exp_entry ]: self.top_bar_layout.addWidget(widget) self.central_layout.addLayout(self.top_bar_layout) self.plot = PlotWidget() self.central_layout.addWidget(self.plot) main_window.setCentralWidget(self.central_widget)
class WMagnetOut(QGroupBox): """Setup of QGroupBox for output for Magnet""" def __init__(self, parent=None): """Initialize the widget""" QGroupBox.__init__(self, parent) self.u = gui_option.unit # Setup main widget self.setTitle(self.tr("Output")) self.setMinimumSize(QSize(200, 0)) self.setObjectName("g_output") self.layout = QVBoxLayout(self) self.layout.setObjectName("layout") # The widget is composed of several QLabel in a vertical layout self.out_Smag = QLabel(self) self.out_Smag.setObjectName("out_Smag") self.layout.addWidget(self.out_Smag) self.out_gap = QLabel(self) self.out_gap.setObjectName("out_gap") self.layout.addWidget(self.out_gap) self.out_gap_min = QLabel(self) self.out_gap_min.setObjectName("out_gap_min") self.layout.addWidget(self.out_gap_min) self.out_taum = QLabel(self) self.out_taum.setObjectName("out_taum") self.layout.addWidget(self.out_taum) def comp_output(self): """Update the Output text with the computed values Parameters ---------- self : WMagnetOut A WMagnetOut object """ mach = self.parent().machine # Gap is set in SMachineDimension gap = format(self.u.get_m(mach.comp_width_airgap_mag()), ".4g") self.out_gap.setText( self.tr("gap: ") + gap + " " + self.u.get_m_name()) mag_txt = self.tr("Magnet surface: ") gm_txt = self.tr("gap_min: ") taum_txt = self.tr("taum: ") if self.parent().check() is None: # We compute the output only if the slot is correctly set Zs = mach.rotor.slot.Zs # Compute all the needed output as string (scientific notation with # 2 digits) Smag = format( self.u.get_m2(mach.rotor.slot.magnet[0].comp_surface()), ".4g") gap_min = format(self.u.get_m(mach.comp_width_airgap_mec()), ".4g") taum = 100 * mach.rotor.slot.magnet[0].comp_ratio_opening(Zs / 2.0) taum = "%.4g" % (taum) # Update the GUI to display the Output self.out_Smag.setText(mag_txt + Smag + " " + self.u.get_m2_name()) self.out_gap_min.setText(gm_txt + gap_min + " " + self.u.get_m_name()) self.out_taum.setText(taum_txt + taum + " %") else: # We can't compute the output => We erase the previous version # (that way the user know that something is wrong without # clicking next) self.out_Smag.setText(mag_txt + "?") self.out_gap_min.setText(gm_txt + "?") self.out_taum.setText(taum_txt + " ?")
class Ui_GroupBox(object): def setupUi(self, GroupBox): if not GroupBox.objectName(): GroupBox.setObjectName(u"GroupBox") GroupBox.resize(528, 576) sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Minimum) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(GroupBox.sizePolicy().hasHeightForWidth()) GroupBox.setSizePolicy(sizePolicy) self.verticalLayout_2 = QVBoxLayout(GroupBox) self.verticalLayout_2.setObjectName(u"verticalLayout_2") self.groupBox = QGroupBox(GroupBox) self.groupBox.setObjectName(u"groupBox") self.verticalLayout_4 = QVBoxLayout(self.groupBox) self.verticalLayout_4.setObjectName(u"verticalLayout_4") self.horizontalLayout_7 = QHBoxLayout() self.horizontalLayout_7.setObjectName(u"horizontalLayout_7") self.horizontalSpacer_7 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout_7.addItem(self.horizontalSpacer_7) self.pushButton_degree_save = QPushButton(self.groupBox) self.pushButton_degree_save.setObjectName(u"pushButton_degree_save") self.horizontalLayout_7.addWidget(self.pushButton_degree_save) self.verticalLayout_4.addLayout(self.horizontalLayout_7) self.verticalLayout_2.addWidget(self.groupBox) self.verticalSpacer_2 = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding) self.verticalLayout_2.addItem(self.verticalSpacer_2) self.groupBox_degree = QGroupBox(GroupBox) self.groupBox_degree.setObjectName(u"groupBox_degree") self.verticalLayout_3 = QVBoxLayout(self.groupBox_degree) self.verticalLayout_3.setObjectName(u"verticalLayout_3") self.horizontalLayout_2 = QHBoxLayout() self.horizontalLayout_2.setObjectName(u"horizontalLayout_2") self.radioButton_betweenness = QRadioButton(self.groupBox_degree) self.radioButton_betweenness.setObjectName(u"radioButton_betweenness") self.horizontalLayout_2.addWidget(self.radioButton_betweenness) self.radioButton_degree = QRadioButton(self.groupBox_degree) self.radioButton_degree.setObjectName(u"radioButton_degree") self.radioButton_degree.setChecked(True) self.horizontalLayout_2.addWidget(self.radioButton_degree) self.horizontalSpacer_5 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout_2.addItem(self.horizontalSpacer_5) self.verticalLayout_3.addLayout(self.horizontalLayout_2) self.checkBox_averaged_frames = QCheckBox(self.groupBox_degree) self.checkBox_averaged_frames.setObjectName( u"checkBox_averaged_frames") self.checkBox_averaged_frames.setChecked(True) self.verticalLayout_3.addWidget(self.checkBox_averaged_frames) self.checkBox_normalized = QCheckBox(self.groupBox_degree) self.checkBox_normalized.setObjectName(u"checkBox_normalized") self.verticalLayout_3.addWidget(self.checkBox_normalized) self.groupBox_per_residue = QGroupBox(self.groupBox_degree) self.groupBox_per_residue.setObjectName(u"groupBox_per_residue") self.groupBox_per_residue.setCheckable(True) self.verticalLayout = QVBoxLayout(self.groupBox_per_residue) self.verticalLayout.setObjectName(u"verticalLayout") self.horizontalLayout_6 = QHBoxLayout() self.horizontalLayout_6.setObjectName(u"horizontalLayout_6") self.label_2 = QLabel(self.groupBox_per_residue) self.label_2.setObjectName(u"label_2") self.horizontalLayout_6.addWidget(self.label_2) self.comboBox = QComboBox(self.groupBox_per_residue) self.comboBox.setObjectName(u"comboBox") self.horizontalLayout_6.addWidget(self.comboBox) self.horizontalSpacer_2 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout_6.addItem(self.horizontalSpacer_2) self.verticalLayout.addLayout(self.horizontalLayout_6) self.horizontalLayout = QHBoxLayout() self.horizontalLayout.setObjectName(u"horizontalLayout") self.label_10 = QLabel(self.groupBox_per_residue) self.label_10.setObjectName(u"label_10") self.label_10.setAlignment(Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter) self.horizontalLayout.addWidget(self.label_10) self.lineEdit_degree_residue_ids = QLineEdit(self.groupBox_per_residue) self.lineEdit_degree_residue_ids.setObjectName( u"lineEdit_degree_residue_ids") self.horizontalLayout.addWidget(self.lineEdit_degree_residue_ids) self.horizontalSpacer_6 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout.addItem(self.horizontalSpacer_6) self.verticalLayout.addLayout(self.horizontalLayout) self.verticalLayout_3.addWidget(self.groupBox_per_residue) self.groupBox_histogram = QGroupBox(self.groupBox_degree) self.groupBox_histogram.setObjectName(u"groupBox_histogram") self.groupBox_histogram.setCheckable(True) self.groupBox_histogram.setChecked(False) self.verticalLayout_5 = QVBoxLayout(self.groupBox_histogram) self.verticalLayout_5.setObjectName(u"verticalLayout_5") self.horizontalLayout_3 = QHBoxLayout() self.horizontalLayout_3.setObjectName(u"horizontalLayout_3") self.label_56 = QLabel(self.groupBox_histogram) self.label_56.setObjectName(u"label_56") self.label_56.setMaximumSize(QSize(16777215, 16777215)) self.label_56.setAlignment(Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter) self.horizontalLayout_3.addWidget(self.label_56) self.lineEdit_bins = QLineEdit(self.groupBox_histogram) self.lineEdit_bins.setObjectName(u"lineEdit_bins") self.lineEdit_bins.setMinimumSize(QSize(50, 0)) self.lineEdit_bins.setMaximumSize(QSize(50, 16777215)) self.horizontalLayout_3.addWidget(self.lineEdit_bins) self.label_55 = QLabel(self.groupBox_histogram) self.label_55.setObjectName(u"label_55") self.label_55.setMaximumSize(QSize(16777215, 16777215)) self.label_55.setAlignment(Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter) self.horizontalLayout_3.addWidget(self.label_55) self.lineEdit_minimum = QLineEdit(self.groupBox_histogram) self.lineEdit_minimum.setObjectName(u"lineEdit_minimum") self.lineEdit_minimum.setMinimumSize(QSize(50, 0)) self.lineEdit_minimum.setMaximumSize(QSize(50, 16777215)) self.horizontalLayout_3.addWidget(self.lineEdit_minimum) self.label_17 = QLabel(self.groupBox_histogram) self.label_17.setObjectName(u"label_17") self.label_17.setAlignment(Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter) self.horizontalLayout_3.addWidget(self.label_17) self.lineEdit_maximum = QLineEdit(self.groupBox_histogram) self.lineEdit_maximum.setObjectName(u"lineEdit_maximum") self.lineEdit_maximum.setMinimumSize(QSize(50, 0)) self.lineEdit_maximum.setMaximumSize(QSize(50, 16777215)) self.horizontalLayout_3.addWidget(self.lineEdit_maximum) self.horizontalSpacer_3 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout_3.addItem(self.horizontalSpacer_3) self.verticalLayout_5.addLayout(self.horizontalLayout_3) self.horizontalLayout_8 = QHBoxLayout() self.horizontalLayout_8.setObjectName(u"horizontalLayout_8") self.checkBox_cumulative_histogram = QCheckBox(self.groupBox_histogram) self.checkBox_cumulative_histogram.setObjectName( u"checkBox_cumulative_histogram") self.horizontalLayout_8.addWidget(self.checkBox_cumulative_histogram) self.horizontalSpacer_12 = QSpacerItem(40, 20, QSizePolicy.Fixed, QSizePolicy.Minimum) self.horizontalLayout_8.addItem(self.horizontalSpacer_12) self.checkBox_stacked_histogram = QCheckBox(self.groupBox_histogram) self.checkBox_stacked_histogram.setObjectName( u"checkBox_stacked_histogram") self.horizontalLayout_8.addWidget(self.checkBox_stacked_histogram) self.horizontalSpacer_11 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout_8.addItem(self.horizontalSpacer_11) self.verticalLayout_5.addLayout(self.horizontalLayout_8) self.horizontalLayout_9 = QHBoxLayout() self.horizontalLayout_9.setObjectName(u"horizontalLayout_9") self.checkBox_color_segments_occupancy = QCheckBox( self.groupBox_histogram) self.checkBox_color_segments_occupancy.setObjectName( u"checkBox_color_segments_occupancy") self.checkBox_color_segments_occupancy.setChecked(True) self.horizontalLayout_9.addWidget( self.checkBox_color_segments_occupancy) self.horizontalSpacer_9 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout_9.addItem(self.horizontalSpacer_9) self.verticalLayout_5.addLayout(self.horizontalLayout_9) self.verticalLayout_3.addWidget(self.groupBox_histogram) self.horizontalLayout_5 = QHBoxLayout() self.horizontalLayout_5.setObjectName(u"horizontalLayout_5") self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout_5.addItem(self.horizontalSpacer) self.pushButton_degree_plot = QPushButton(self.groupBox_degree) self.pushButton_degree_plot.setObjectName(u"pushButton_degree_plot") self.pushButton_degree_plot.setAutoDefault(False) self.horizontalLayout_5.addWidget(self.pushButton_degree_plot) self.verticalLayout_3.addLayout(self.horizontalLayout_5) self.verticalLayout_2.addWidget(self.groupBox_degree) self.retranslateUi(GroupBox) QMetaObject.connectSlotsByName(GroupBox) # setupUi def retranslateUi(self, GroupBox): GroupBox.setWindowTitle( QCoreApplication.translate("GroupBox", u"GroupBox", None)) self.groupBox.setTitle( QCoreApplication.translate("GroupBox", u"All centrality measures", None)) self.pushButton_degree_save.setText( QCoreApplication.translate("GroupBox", u"Data", None)) self.groupBox_degree.setTitle( QCoreApplication.translate("GroupBox", u"Plots", None)) self.radioButton_betweenness.setText( QCoreApplication.translate("GroupBox", u"betweenness centrality", None)) self.radioButton_degree.setText( QCoreApplication.translate("GroupBox", u"degree centrality", None)) #if QT_CONFIG(tooltip) self.checkBox_averaged_frames.setToolTip( QCoreApplication.translate( "GroupBox", u"<html><head/><body><p align=\"justify\">Toggle, if absolute number of connections or time averaged number of connections are used.</p></body></html>", None)) #endif // QT_CONFIG(tooltip) self.checkBox_averaged_frames.setText( QCoreApplication.translate("GroupBox", u"average across frames", None)) self.checkBox_normalized.setText( QCoreApplication.translate("GroupBox", u"normalized", None)) self.groupBox_per_residue.setTitle( QCoreApplication.translate("GroupBox", u"Per Residue", None)) self.label_2.setText( QCoreApplication.translate("GroupBox", u"segment: ", None)) self.label_10.setText( QCoreApplication.translate("GroupBox", u"residue ids: ", None)) self.lineEdit_degree_residue_ids.setPlaceholderText( QCoreApplication.translate("GroupBox", u"e.g. 0-12, 20, 70-90", None)) self.groupBox_histogram.setTitle( QCoreApplication.translate("GroupBox", u"Histogram", None)) self.label_56.setText( QCoreApplication.translate("GroupBox", u"# of bins", None)) self.lineEdit_bins.setText( QCoreApplication.translate("GroupBox", u"10", None)) self.label_55.setText( QCoreApplication.translate("GroupBox", u"min. value", None)) self.lineEdit_minimum.setText( QCoreApplication.translate("GroupBox", u"0.0", None)) self.label_17.setText( QCoreApplication.translate("GroupBox", u"max. value", None)) self.lineEdit_maximum.setText( QCoreApplication.translate("GroupBox", u"1.0", None)) self.checkBox_cumulative_histogram.setText( QCoreApplication.translate("GroupBox", u"cumulative", None)) self.checkBox_stacked_histogram.setText( QCoreApplication.translate("GroupBox", u"stacked", None)) #if QT_CONFIG(tooltip) self.checkBox_color_segments_occupancy.setToolTip( QCoreApplication.translate( "GroupBox", u"<html><head/><body><p align=\"justify\">Toggle if histogram bars are colored by segment or molecule. With colors turned on, comparing to other analyses is not possible.</p></body></html>", None)) #endif // QT_CONFIG(tooltip) self.checkBox_color_segments_occupancy.setText( QCoreApplication.translate("GroupBox", u"color by segment", None)) #if QT_CONFIG(tooltip) self.pushButton_degree_plot.setToolTip( QCoreApplication.translate( "GroupBox", u"<html><head/><body><p align=\"justify\">Compute the number of H bonds per residue. Results are colored by segment.</p></body></html>", None)) #endif // QT_CONFIG(tooltip) self.pushButton_degree_plot.setText( QCoreApplication.translate("GroupBox", u"Plot", None))
class Ui_Dialog(object): def setupUi(self, Dialog): if Dialog.objectName(): Dialog.setObjectName(u"Dialog") Dialog.resize(878, 528) icon = QIcon() icon.addFile("./icon.ico") Dialog.setWindowIcon(icon) self.verticalLayout = QVBoxLayout(Dialog) self.verticalLayout.setObjectName(u"verticalLayout") self.horizontalLayout = QHBoxLayout() self.horizontalLayout.setObjectName(u"horizontalLayout") self.questionLable = QLabel(Dialog) self.questionLable.setObjectName(u"questionLable") font = QFont() font.setFamily(u"\u5fae\u8f6f\u96c5\u9ed1") font.setPointSize(12) self.questionLable.setFont(font) self.questionLable.setWordWrap(True) self.questionLable.setMargin(0) self.questionLable.setIndent(0) self.horizontalLayout.addWidget(self.questionLable) self.lcd = QLCDNumber(Dialog) self.lcd.setObjectName(u"lcd") sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.lcd.sizePolicy().hasHeightForWidth()) self.lcd.setSizePolicy(sizePolicy) self.lcd.setMinimumSize(QSize(120, 60)) self.lcd.setSmallDecimalPoint(True) self.lcd.setDigitCount(4) self.lcd.setSegmentStyle(QLCDNumber.Flat) self.lcd.setProperty("value", 120.000000000000000) self.horizontalLayout.addWidget(self.lcd) self.verticalLayout.addLayout(self.horizontalLayout) self.line = QFrame(Dialog) self.line.setObjectName(u"line") self.line.setFrameShape(QFrame.HLine) self.line.setFrameShadow(QFrame.Sunken) self.verticalLayout.addWidget(self.line) self.answerLable = QLabel(Dialog) self.answerLable.setObjectName(u"answerLable") font1 = QFont() font1.setFamily(u"Yu Gothic UI") font1.setPointSize(14) self.answerLable.setFont(font1) self.answerLable.setWordWrap(True) self.verticalLayout.addWidget(self.answerLable) self.retranslateUi(Dialog) QMetaObject.connectSlotsByName(Dialog) # setupUi def retranslateUi(self, Dialog): Dialog.setWindowTitle( QCoreApplication.translate("Dialog", u"Dialog", None)) # retranslateUi def setupUi_(self, question, answer, time): self.questionLable.setText(question) self.answerLable.setText(answer) self.lcd.setDigitCount(3) # 设置lcd的显示位数 self.lcd.display(time) self.timer1 = QTimer() self.timer1.timeout.connect(self.setlcd1) self.timer1.start(1000) # self.timer2 = QTimer() # self.timer2.timeout.connect(self.setlcd2) def setlcd1(self): self.lcd.display(self.lcd.intValue() - 1) if self.lcd.intValue() == 0: self.timer1.stop() # self.lcd.setSegmentStyle(QLCDNumber.Flat) # self.lcd.setStyleSheet("color: red;") # self.timer2.start(1000) def setlcd2(self): self.lcd.display(self.lcd.intValue() + 1)
class MainWindow(QMainWindow): def __init__(self, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) self.setupUi(self) self.player = QMediaPlayer() self.player.error.connect(self.erroralert) self.player.play() # Setup the playlist. self.playlist = QMediaPlaylist() self.player.setPlaylist(self.playlist) # Add viewer for video playback, separate floating window. self.viewer = ViewerWindow(self) self.viewer.setWindowFlags(self.viewer.windowFlags() | Qt.WindowStaysOnTopHint) self.viewer.setMinimumSize(QSize(480, 360)) videoWidget = QVideoWidget() self.viewer.setCentralWidget(videoWidget) self.player.setVideoOutput(videoWidget) # Connect control buttons/slides for media player. self.playButton.pressed.connect(self.player.play) self.pauseButton.pressed.connect(self.player.pause) self.stopButton.pressed.connect(self.player.stop) self.volumeSlider.valueChanged.connect(self.player.setVolume) self.viewButton.toggled.connect(self.toggle_viewer) self.viewer.state.connect(self.viewButton.setChecked) self.previousButton.pressed.connect(self.playlist.previous) self.nextButton.pressed.connect(self.playlist.next) self.model = PlaylistModel(self.playlist) self.playlistView.setModel(self.model) self.playlist.currentIndexChanged.connect( self.playlist_position_changed) selection_model = self.playlistView.selectionModel() selection_model.selectionChanged.connect( self.playlist_selection_changed) self.player.durationChanged.connect(self.update_duration) self.player.positionChanged.connect(self.update_position) self.timeSlider.valueChanged.connect(self.player.setPosition) self.open_file_action.triggered.connect(self.open_file) self.setAcceptDrops(True) self.show() def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(484, 371) self.centralWidget = QWidget(MainWindow) sizePolicy = QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.centralWidget.sizePolicy().hasHeightForWidth()) self.centralWidget.setSizePolicy(sizePolicy) self.centralWidget.setObjectName("centralWidget") self.horizontalLayout = QHBoxLayout(self.centralWidget) self.horizontalLayout.setContentsMargins(11, 11, 11, 11) self.horizontalLayout.setSpacing(6) self.horizontalLayout.setObjectName("horizontalLayout") self.verticalLayout = QVBoxLayout() self.verticalLayout.setSpacing(6) self.verticalLayout.setObjectName("verticalLayout") self.playlistView = QListView(self.centralWidget) self.playlistView.setAcceptDrops(True) self.playlistView.setProperty("showDropIndicator", True) self.playlistView.setDragDropMode(QAbstractItemView.DropOnly) self.playlistView.setAlternatingRowColors(True) self.playlistView.setUniformItemSizes(True) self.playlistView.setObjectName("playlistView") self.verticalLayout.addWidget(self.playlistView) self.horizontalLayout_4 = QHBoxLayout() self.horizontalLayout_4.setSpacing(6) self.horizontalLayout_4.setObjectName("horizontalLayout_4") self.currentTimeLabel = QLabel(self.centralWidget) self.currentTimeLabel.setMinimumSize(QSize(80, 0)) self.currentTimeLabel.setAlignment(Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter) self.currentTimeLabel.setObjectName("currentTimeLabel") self.horizontalLayout_4.addWidget(self.currentTimeLabel) self.timeSlider = QSlider(self.centralWidget) self.timeSlider.setOrientation(Qt.Horizontal) self.timeSlider.setObjectName("timeSlider") self.horizontalLayout_4.addWidget(self.timeSlider) self.totalTimeLabel = QLabel(self.centralWidget) self.totalTimeLabel.setMinimumSize(QSize(80, 0)) self.totalTimeLabel.setAlignment(Qt.AlignLeading | Qt.AlignLeft | Qt.AlignVCenter) self.totalTimeLabel.setObjectName("totalTimeLabel") self.horizontalLayout_4.addWidget(self.totalTimeLabel) self.verticalLayout.addLayout(self.horizontalLayout_4) self.horizontalLayout_5 = QHBoxLayout() self.horizontalLayout_5.setSpacing(6) self.horizontalLayout_5.setObjectName("horizontalLayout_5") self.previousButton = QPushButton(self.centralWidget) self.previousButton.setText("") icon = QIcon() icon.addPixmap(QPixmap("images/control-skip-180.png"), QIcon.Normal, QIcon.Off) self.previousButton.setIcon(icon) self.previousButton.setObjectName("previousButton") self.horizontalLayout_5.addWidget(self.previousButton) self.playButton = QPushButton(self.centralWidget) self.playButton.setText("") icon1 = QIcon() icon1.addPixmap(QPixmap("images/control.png"), QIcon.Normal, QIcon.Off) self.playButton.setIcon(icon1) self.playButton.setObjectName("playButton") self.horizontalLayout_5.addWidget(self.playButton) self.pauseButton = QPushButton(self.centralWidget) self.pauseButton.setText("") icon2 = QIcon() icon2.addPixmap(QPixmap("images/control-pause.png"), QIcon.Normal, QIcon.Off) self.pauseButton.setIcon(icon2) self.pauseButton.setObjectName("pauseButton") self.horizontalLayout_5.addWidget(self.pauseButton) self.stopButton = QPushButton(self.centralWidget) self.stopButton.setText("") icon3 = QIcon() icon3.addPixmap(QPixmap("images/control-stop-square.png"), QIcon.Normal, QIcon.Off) self.stopButton.setIcon(icon3) self.stopButton.setObjectName("stopButton") self.horizontalLayout_5.addWidget(self.stopButton) self.nextButton = QPushButton(self.centralWidget) self.nextButton.setText("") icon4 = QIcon() icon4.addPixmap(QPixmap("images/control-skip.png"), QIcon.Normal, QIcon.Off) self.nextButton.setIcon(icon4) self.nextButton.setObjectName("nextButton") self.horizontalLayout_5.addWidget(self.nextButton) self.viewButton = QPushButton(self.centralWidget) self.viewButton.setText("") icon5 = QIcon() icon5.addPixmap(QPixmap("images/application-image.png"), QIcon.Normal, QIcon.Off) self.viewButton.setIcon(icon5) self.viewButton.setCheckable(True) self.viewButton.setObjectName("viewButton") self.horizontalLayout_5.addWidget(self.viewButton) spacerItem = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout_5.addItem(spacerItem) self.label = QLabel(self.centralWidget) self.label.setText("") self.label.setPixmap(QPixmap("images/speaker-volume.png")) self.label.setObjectName("label") self.horizontalLayout_5.addWidget(self.label) self.volumeSlider = QSlider(self.centralWidget) self.volumeSlider.setMaximum(100) self.volumeSlider.setProperty("value", 100) self.volumeSlider.setOrientation(Qt.Horizontal) self.volumeSlider.setObjectName("volumeSlider") self.horizontalLayout_5.addWidget(self.volumeSlider) self.verticalLayout.addLayout(self.horizontalLayout_5) self.horizontalLayout.addLayout(self.verticalLayout) MainWindow.setCentralWidget(self.centralWidget) self.menuBar = QMenuBar(MainWindow) self.menuBar.setGeometry(QRect(0, 0, 484, 22)) self.menuBar.setObjectName("menuBar") self.menuFIle = QMenu(self.menuBar) self.menuFIle.setObjectName("menuFIle") MainWindow.setMenuBar(self.menuBar) self.statusBar = QStatusBar(MainWindow) self.statusBar.setObjectName("statusBar") MainWindow.setStatusBar(self.statusBar) self.open_file_action = QAction(MainWindow) self.open_file_action.setObjectName("open_file_action") self.menuFIle.addAction(self.open_file_action) self.menuBar.addAction(self.menuFIle.menuAction()) self.retranslateUi(MainWindow) QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): _translate = QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "Failamp")) self.currentTimeLabel.setText(_translate("MainWindow", "0:00")) self.totalTimeLabel.setText(_translate("MainWindow", "0:00")) self.menuFIle.setTitle(_translate("MainWindow", "FIle")) self.open_file_action.setText(_translate("MainWindow", "Open file...")) def dragEnterEvent(self, e): if e.mimeData().hasUrls(): e.acceptProposedAction() def dropEvent(self, e): for url in e.mimeData().urls(): self.playlist.addMedia(QMediaContent(url)) self.model.layoutChanged.emit() # If not playing, seeking to first of newly added + play. if self.player.state() != QMediaPlayer.PlayingState: i = self.playlist.mediaCount() - len(e.mimeData().urls()) self.playlist.setCurrentIndex(i) self.player.play() def open_file(self): path, _ = QFileDialog.getOpenFileName( self, "Open file", "", "mp3 Audio (*.mp3);mp4 Video (*.mp4);Movie files (*.mov);All files (*.*)" ) if path: self.playlist.addMedia(QMediaContent(QUrl.fromLocalFile(path))) self.model.layoutChanged.emit() def update_duration(self, duration): print("!", duration) print("?", self.player.duration()) self.timeSlider.setMaximum(duration) if duration >= 0: self.totalTimeLabel.setText(hhmmss(duration)) def update_position(self, position): if position >= 0: self.currentTimeLabel.setText(hhmmss(position)) # Disable the events to prevent updating triggering a setPosition event (can cause stuttering). self.timeSlider.blockSignals(True) self.timeSlider.setValue(position) self.timeSlider.blockSignals(False) def playlist_selection_changed(self, ix): # We receive a QItemSelection from selectionChanged. i = ix.indexes()[0].row() self.playlist.setCurrentIndex(i) def playlist_position_changed(self, i): if i > -1: ix = self.model.index(i) self.playlistView.setCurrentIndex(ix) def toggle_viewer(self, state): if state: self.viewer.show() else: self.viewer.hide() def erroralert(self, *args): print(args)
class Ui_MainWindow(QMainWindow): def __init__(self, parent=None): QMainWindow.__init__(self, parent) self.setupUi() def setupUi(self): self.setObjectName(_fromUtf8("MainWindow")) self.resize(565, 358) self.centralwidget = QWidget(self) self.centralwidget.setObjectName(_fromUtf8("centralwidget")) self.verticalLayout = QVBoxLayout(self.centralwidget) self.verticalLayout.setObjectName(_fromUtf8("verticalLayout")) self.horizontalLayout = QHBoxLayout() self.horizontalLayout.setSizeConstraint(QLayout.SetDefaultConstraint) self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout")) spacerItem = QSpacerItem(40, 20, QSizePolicy.MinimumExpanding, QSizePolicy.Minimum) self.horizontalLayout.addItem(spacerItem) self.searchTE = QLineEdit(self.centralwidget) self.searchTE.setObjectName(_fromUtf8("searchTE")) self.horizontalLayout.addWidget(self.searchTE) self.searchBtn = QPushButton(self.centralwidget) sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.searchBtn.sizePolicy().hasHeightForWidth()) self.searchBtn.setSizePolicy(sizePolicy) self.searchBtn.setStyleSheet(_fromUtf8("border: none")) self.searchBtn.setText(_fromUtf8("")) icon = QIcon() icon.addPixmap( QPixmap( _fromUtf8( "../.designer/gitlab/ExcelToSql/icons/searchBtn.png")), QIcon.Normal, QIcon.Off) self.searchBtn.setIcon(icon) self.searchBtn.setIconSize(QtCore.QSize(48, 24)) self.searchBtn.setObjectName(_fromUtf8("searchBtn")) self.horizontalLayout.addWidget(self.searchBtn) self.pushButton_2 = QPushButton(self.centralwidget) sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.pushButton_2.sizePolicy().hasHeightForWidth()) self.pushButton_2.setSizePolicy(sizePolicy) self.pushButton_2.setMaximumSize(QtCore.QSize(32, 16777215)) self.pushButton_2.setStyleSheet(_fromUtf8("color: blue")) self.pushButton_2.setObjectName(_fromUtf8("pushButton_2")) self.horizontalLayout.addWidget(self.pushButton_2) # self.pushButton_2.clicked.connect(self.onRunBtnClick()) self.verticalLayout.addLayout(self.horizontalLayout) self.gridLayout = QGridLayout() self.gridLayout.setObjectName(_fromUtf8("gridLayout")) self.dateEdit = QDateEdit(self.centralwidget) self.dateEdit.setObjectName(_fromUtf8("dateEdit")) self.gridLayout.addWidget(self.dateEdit, 0, 0, 1, 1) self.dateEdit_2 = QDateEdit(self.centralwidget) self.dateEdit_2.setObjectName(_fromUtf8("dateEdit_2")) self.gridLayout.addWidget(self.dateEdit_2, 0, 1, 1, 1) self.verticalLayout.addLayout(self.gridLayout) self.tableWidget = QTableWidget(self.centralwidget) sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.tableWidget.sizePolicy().hasHeightForWidth()) self.tableWidget.setSizePolicy(sizePolicy) self.tableWidget.setObjectName(_fromUtf8("tableWidget")) self.tableWidget.setColumnCount(3) self.tableWidget.setRowCount(0) item = QTableWidgetItem() self.tableWidget.setHorizontalHeaderItem(0, item) item = QTableWidgetItem() self.tableWidget.setHorizontalHeaderItem(1, item) item = QTableWidgetItem() self.tableWidget.setHorizontalHeaderItem(2, item) self.verticalLayout.addWidget(self.tableWidget) self.setCentralWidget(self.centralwidget) self.statusbar = QStatusBar(self) self.statusbar.setObjectName(_fromUtf8("statusbar")) self.setStatusBar(self.statusbar) item = QTableWidgetItem() self.tableWidget.setHorizontalHeaderItem(0, item) item = QTableWidgetItem() self.tableWidget.setHorizontalHeaderItem(1, item) item = QTableWidgetItem() self.tableWidget.setHorizontalHeaderItem(2, item) self.retranslateUi() QtCore.QMetaObject.connectSlotsByName(self) print("A") self.pushButton_2.clicked.connect(self, QtCore.SLOT("onRunBtnClick()")) print("B") conn = sqlite3.connect("/home/eamon/Desktop/test.sqlite") result = conn.execute("SELECT * FROM Sheet1") for raw_number, raw_data in enumerate(result): self.tableWidget.insertRow(raw_number) # print(raw_number) for column_number, data in enumerate(raw_data): item = QTableWidgetItem(str(data)) self.tableWidget.setItem(raw_number, column_number, item) # print("\t", column_number) conn.close() def retranslateUi(self): self.setWindowTitle(_translate("MainWindow", "MainWindow", None)) item = self.tableWidget.horizontalHeaderItem(0) item.setText(_translate("MainWindow", "id", None)) item = self.tableWidget.horizontalHeaderItem(1) item.setText(_translate("MainWindow", "Name", None)) item = self.tableWidget.horizontalHeaderItem(2) item.setText(_translate("MainWindow", "Cost", None)) def onRunBtnClick(self): db = sqlite3.connect("/home/eamon/Desktop/test.sqlite") cur = db.cursor() q = "SELECT * FROM Sheet1 WHERE name='%s'" % (self.searchTE.text(), ) print(q) res = cur.execute(q) if res: self.tableWidget.clear() for raw_number, raw_data in enumerate(res): self.tableWidget.insertRow(raw_number) for column_number, data in enumerate(raw_data): item = QTableWidgetItem(str(data)) self.tableWidget.setItem(raw_number, column_number, item)
def _generate_sector(self, sector, band=None, gen_cloud=False): logging.debug( "Generation process launched for %s, generating cloud: %r", sector, gen_cloud) logging.info(f"Generating image for {sector['name']}") if self._data is None: logging.error( "No data loaded for sector! Should never have gotten here!") return self._proj_str = f'+proj=laea +lat_0={sector["centerLat"]} +lon_0={sector["centerLng"]} +x_0=0 +y_0=0 +ellps=WGS84 +units=m +no_defs' self._laea_transformer = pyproj.Transformer.from_proj( LAT_LON_PROJ, self._proj_str) lat_from, lat_to = (sector['latFrom'], sector['latTo']) lon_from, lon_to = (sector['longFrom'], sector['longTo']) # Make sure our longitude is in the "REAL" range if lon_from < -180: filt_lon_from = lon_from + 360 elif lon_from > 180: filt_lon_from = lon_from - 360 else: filt_lon_from = lon_from if lon_to > 180: filt_lon_to = lon_to - 360 elif lon_to < -180: filt_lon_to = lon_to + 360 else: filt_lon_to = lon_to # Just look at *this* sector # Start with a rough latitude/longitude filter # (with 1/2 degree latitude, 1 dgree longitude border) with numpy.errstate(invalid='ignore'): # Filter on density again so that any bins that wound up without data are removed. filter_items = [ ~numpy.isnan(self._data['SO2_column_number_density']) ] filter_items.append(self._data['latitude'] >= (lat_from - .5)) filter_items.append(self._data['latitude'] <= (lat_to + .5)) logging.debug("Generating latitude filters") lat_filter = numpy.logical_and.reduce(filter_items) # Figure out longitude filter if filt_lon_to > filt_lon_from: filt_lon_from = [filt_lon_from, 180] filt_lon_to = [-180, filt_lon_to] else: filt_lon_from = [filt_lon_from] filt_lon_to = [filt_lon_to] lon_filters = [] for start, stop in zip(filt_lon_from, filt_lon_to): lon_filters.append( numpy.logical_and(self._data['longitude'] <= (start + 1), self._data['longitude'] >= (stop - 1))) logging.debug("Generating longitude filters") if len(lon_filters) > 1: lon_filter = numpy.logical_or(*lon_filters) else: lon_filter = lon_filters[0] logging.debug("Combining filters") post_filter = numpy.logical_and(lat_filter, lon_filter) # short-circuit filtering if no records would be retained if not post_filter.any(): logging.info("No in-range data found for %s, %s", band or "cloud", sector['sector']) return sector_data = self._apply_filter(post_filter) logging.debug("Rough filters applied") if not sector_data['latitude'].any(): # No data for this set of parameters. Try the next logging.info("No data found for %s, %s", band or "cloud", sector['sector']) return # Figure out the bounds in laea projection pixel_bounds = numpy.stack( (sector_data['latitude_bounds'], sector_data['longitude_bounds']), axis=-1) x_lat_lon = pixel_bounds[:, :, 1].reshape(pixel_bounds[:, :, 1].size) y_lat_lon = pixel_bounds[:, :, 0].reshape(pixel_bounds[:, :, 0].size) x_laea, y_laea = self._laea_transformer.transform( y_lat_lon, x_lat_lon, ) x_laea = x_laea.reshape(int(x_laea.size / 4), 4) y_laea = y_laea.reshape(int(y_laea.size / 4), 4) # Add these to sector data so they get filtered along with # everything else sector_data['x_laea'] = (['time', 'corners'], x_laea) sector_data['y_laea'] = (['time', 'corners'], y_laea) # seperate the max/min x and y limits of each pixel so we can tell which # actually have area within the image x_max = numpy.nanmax(x_laea, axis=1) x_min = numpy.nanmin(x_laea, axis=1) y_max = numpy.nanmax(y_laea, axis=1) y_min = numpy.nanmin(y_laea, axis=1) meter_width = sector['pixelSize'] * 1000 * sector[ 'imageWidth'] # km-->meters meter_height = sector['pixelSize'] * 1000 * sector['imageHeight'] center_x, center_y = ( 0, 0 ) # Always centered at 0, because that's how we defined our projection # Yes, this could be simplified, since our center is 0, but this keeps # flexability should that change, and explicitly spells out exactly what # we are doing here. x_range = [center_x - (meter_width / 2), center_x + (meter_width / 2)] y_range = [ center_y - (meter_height / 2), center_y + (meter_height / 2) ] # Second filter - now that we have translated the cordinate system, # trim down to *only* the area to be displayed. filters = [ x_max > x_range[0], # Right edge of pixel inside left edge of image x_min < x_range[1], # Left edge of pixel inside right edge of image y_max > y_range[0], # well, you get the idea y_min < y_range[1] ] final_filter = numpy.logical_and.reduce(filters) # Short-circuit filtering in border cases if not final_filter.any(): logging.info("No in-range data found for %s, %s", band, sector['sector']) return # Only filter if we are actually getting rid of something if not final_filter.all(): sector_data = self._apply_filter(final_filter, sector_data) if not sector_data['latitude'].any(): # No data for this set of parameters. Try the next logging.debug("No data found for %s, %s", band, sector['sector']) return logging.debug("Data filtered for sector succesfully") # Center point of pixels data_x, data_y = self._laea_transformer.transform( sector_data['latitude'], sector_data['longitude']) laea_pixel_bounds = numpy.stack( [sector_data['x_laea'], sector_data['y_laea']], axis=2) areas = PolyArea(sector_data['x_laea'], sector_data['y_laea']) mass = areas * sector_data['SO2_column_number_density'] # in moles mass *= 64 # in grams total_mass = numpy.nansum(mass) * 1e-9 # Kilo Tonnes self._du_val = sector_data[ 'SO2_column_number_density'] * 2241.15 # Conversion Factor from manual self._normalized_du = self._du_val * (1 / 20) self._normalized_du[self._normalized_du > 1] = 1 self._normalized_du[self._normalized_du < 0] = 0 _percentile_levels = (90, 95, 97, 99, 100) _percentiles = numpy.nanpercentile(self._du_val, _percentile_levels) _percentiles[_percentiles < 0] = 0 _percentiles[_percentiles > 20] = 20 _percentColors = self._du_color_map.map(_percentiles * (1 / 20), mode='qcolor') # When rounded to 5 digits, the color results are identical. # Doing the rounding significanly reduces the number of unique values, # therby enabling significant speed up by using a lookup table rather # than having to check each value individually. self._normalized_du = numpy.round(self._normalized_du, 5) # show_volc_names = sector.get('showAllLabels', True) # hide_all_names = sector.get('hideAllLabels', False) # Generate path objects for each pixel for graphing purposes. # To get the shape of each pixel, shift each one to 0,0 lower left bounding box shifted_coords = laea_pixel_bounds - numpy.min(laea_pixel_bounds, axis=1)[:, None, :] # We have to do min twice to get the single min value for each group of corner points # If we only did it once, X and Y would be scaled seperately, distorting the shape. scale_factors = numpy.max(numpy.max(shifted_coords, axis=1), axis=1) # Scale each pixel to fit within -0.5 - +0.5 with warnings.catch_warnings(): warnings.simplefilter("ignore") scaled_coords = (shifted_coords * (1 / scale_factors[:, None, None])) - .5 # "Center" the scaled coordinates so the paths correctly represent the points scaled_coords -= (((numpy.max(scaled_coords, axis=1) - numpy.min(scaled_coords, axis=1)) - 1) / 2)[:, None, :] pixel_paths = [_generate_path(x) for x in scaled_coords] # Have to keep disp_widget, otherwise python deletes things too soon. (plot_item, scale_widget, disp_widget, date_label) = _initalize_image_widgets(self._file_date, band, self._data_type) # Add the total mass to the date label if sector['sector'] == '1kmHIKI': date_label.setText(date_label.text() + f" {total_mass:.2f}kt") date_label.adjustSize() # Make color blocks to display the percentiles if not gen_cloud: _percentContainer = QWidget() _percentContainer.setObjectName("Percent Container") _percentContainer.setAutoFillBackground(False) _percentContainer.setStyleSheet('background-color:transparent') main_layout = QVBoxLayout(_percentContainer) main_layout.setObjectName("Main Layout") main_layout.setContentsMargins(0, 0, 0, 0) title = QLabel(_percentContainer) title.setText("Percentiles:") title.setAlignment(Qt.AlignLeft) title_font = title.font() title_font.setPointSize(8) title.setFont(title_font) main_layout.addWidget(title) percentLayout = QHBoxLayout() percentLayout.setObjectName("Percent Bar Layout") percentLayout.setContentsMargins(0, 0, 0, 0) percentLayout.setSpacing(0) main_layout.addLayout(percentLayout) for idx, color in enumerate(_percentColors): val = _percentiles[idx] widg = QWidget() lay = QVBoxLayout() lay.setObjectName(f"Val {idx} layout") lay.setContentsMargins(0, 0, 0, 0) widg.setLayout(lay) label = QLabel() label.setText( f"{_percentile_levels[idx]}<sup>th</sup><br>{str(round(val, 2))} DU" ) labelFont = label.font() labelFont.setPointSize(8) label.setFont(labelFont) label.setAlignment(Qt.AlignCenter) lay.addWidget(label) ss = f'background-color:{color.name()};border:1px solid black;' if idx != 0: ss += "border-left:None;" widg.setStyleSheet(ss) percentLayout.addWidget(widg) _percentContainer.setGeometry(0, 0, 300, 18) _percentContainer.setLayout(main_layout) vbox = plot_item.getViewBox() vbox.disableAutoRange() vbox.setRange(xRange=x_range, yRange=y_range, padding=0) ############################################################### # Plot Generation Code ############################################################### def plot_dataset(dataset, color_map, scale_labels): # Only generate the brush once for each unique value lookup_table = { x: pg.mkBrush(color_map.map(x)) for x in numpy.unique(dataset) } brushes = [lookup_table[x] for x in dataset.data] scale_widget.setGradient(color_map.getGradient()) scale_widget.setLabels(scale_labels) # Generate Plot plot = plot_item.plot(data_x, data_y, pen=None, symbolPen=None, symbolBrush=brushes, pxMode=False, symbolSize=scale_factors, symbol=pixel_paths) plot_item.getViewWidget().parent().grab() volcview_img = plot_item.getViewWidget().parent().grab() self._view_extents = vbox.viewRange() file_bytes = QByteArray() file_buffer = QBuffer(file_bytes) file_buffer.open(QIODevice.WriteOnly) volcview_img.save(file_buffer, "PNG") file_buffer.close() file_stream = BytesIO(file_bytes) pil_img = Image.open(file_stream) # find coverage percent(ish) width, height = pil_img.size total_count = width * height # Should be 800,000, unless we changed the size of the images. # dump into a numpy array to count grey pixels as_array = numpy.array(pil_img) # the grey value we use is 238, so if all elements of axis 2 are 238, # then the pixel is grey. is_grey = numpy.all(as_array == 238, axis=2) # number that is False is non-grey, or covered, pixels # Not quite true due to scale bar, borders, etc. unique, counts = numpy.unique(is_grey, return_counts=True) non_grey = dict(zip(unique, counts))[False] covered_percent = non_grey / total_count # Don't send the image to volcview unless it has at least 15% coverage. # Allow 2% for the scale bar and other features. threshold = .17 if sector['pixelSize'] == 5: threshold = .06 if covered_percent > threshold: self._add_coastlines(pil_img) raw_data = QByteArray() buffer = QBuffer(raw_data) if not gen_cloud and not self._data_type in ('VIIRS'): # "Save" the percentile bar to a bytes buffer, in PNG format buffer.open(QIODevice.WriteOnly) _percentContainer.grab().save(buffer, "PNG") buffer.close() # Use a bytes IO object to "read" the image into a PIL object img_stream = BytesIO(raw_data) with Image.open(img_stream) as img: pil_img.paste(img, (5, 5), mask=img) # Add the scale bar and timestamp. scale_top = pil_img.height buffer.open(QIODevice.WriteOnly) scale_widget.grab() # why? WHYYYYYYYY???? scale_widget.grab().save(buffer, "PNG") buffer.close() img_stream = BytesIO(raw_data) with Image.open(img_stream) as img: scale_top = pil_img.height - img.height - 10 pil_img.paste(img, (25, scale_top), mask=img) # Add the timestamp buffer.open(QIODevice.WriteOnly) date_label.grab().save(buffer, "PNG") buffer.close() img_stream = BytesIO(raw_data) with Image.open(img_stream) as img: pil_img.paste(img, (pil_img.width - img.width - 51, scale_top - img.height - 5), mask=img) # Save an archive image logging.debug("Saving archive image for %s", band) filename = f"{self._file_date.strftime('%Y_%m_%d_%H%M%S')}-{band}-{self._data_type}.png" save_file = os.path.join(config.FILE_BASE, 'VolcView', sector['name'], filename) os.makedirs(os.path.dirname(save_file), exist_ok=True) pil_img.save(save_file, format='PNG') file_stream = BytesIO() # "Save" the image to memory in PNG format pil_img.save(file_stream, format='PNG') file_stream.seek(0) # Go back to the begining for reading out logging.debug("Uploading image for %s", band) if not DEBUG: self._volcview_upload(file_stream, sector, band) else: logging.debug("******Pretending to send to volc view") print("TEST UPLOAD", sector['name'], filename, "***200***") logging.debug("Image upload complete") if DEBUG: # This is just Debugging code to save the generated # image to disk for local analysis. # Feel free to change file paths to something more # appropriate if desired. print(f"^^^^SAVING IMAGE FOR FILE TO DISK^^^") dest_dir = f"/tmp/VolcViewImages/{sector['sector']}" os.makedirs(dest_dir, exist_ok=True) dest_file = f"{self._data_type}-{band}-{self._file_date.strftime('%Y_%m_%d_%H%M%S')}.png" dest_path = os.path.join(dest_dir, dest_file) file_stream.seek(0) with open(dest_path, 'wb') as f: f.write(file_stream.read()) ################### else: logging.info("Not enough coverage to bother with") plot_item.removeItem(plot) ############################################################### if gen_cloud: band = 'cloud' logging.debug("Plotting CLOUD dataset") plot_dataset(sector_data['cloud_fraction'], self._cloud_color_map, self._cloud_scale_labels) logging.debug("CLOUD dataset plotted. function ends.") elif self._data_type == 'VIIRS': labels = {0: "0", 0.5: "SO2 Index", 1: "100"} plot_dataset(self._normalized_du, self._du_color_map, labels) else: plot_dataset(self._normalized_du, self._du_color_map, self._du_scale_labels)
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 MainWindow(QMainWindow): def __init__(self, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) self.setupUi(self) self.pushButton.pressed.connect(self.update_weather) self.threadpool = QThreadPool() self.update_weather() self.show() def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(330, 417) self.centralwidget = QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.horizontalLayout = QHBoxLayout(self.centralwidget) self.horizontalLayout.setObjectName("horizontalLayout") self.verticalLayout = QVBoxLayout() self.verticalLayout.setObjectName("verticalLayout") self.horizontalLayout_3 = QHBoxLayout() self.horizontalLayout_3.setObjectName("horizontalLayout_3") self.lineEdit = QLineEdit(self.centralwidget) self.lineEdit.setObjectName("lineEdit") self.horizontalLayout_3.addWidget(self.lineEdit) self.pushButton = QPushButton(self.centralwidget) self.pushButton.setText("") icon = QIcon() icon.addPixmap(QPixmap("images/arrow-circle-225.png"), QIcon.Normal, QIcon.Off) self.pushButton.setIcon(icon) self.pushButton.setObjectName("pushButton") self.horizontalLayout_3.addWidget(self.pushButton) self.verticalLayout.addLayout(self.horizontalLayout_3) self.horizontalLayout_4 = QHBoxLayout() self.horizontalLayout_4.setObjectName("horizontalLayout_4") self.weatherIcon = QLabel(self.centralwidget) sizePolicy = QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.weatherIcon.sizePolicy().hasHeightForWidth()) self.weatherIcon.setSizePolicy(sizePolicy) self.weatherIcon.setMinimumSize(QSize(64, 64)) self.weatherIcon.setMaximumSize(QSize(64, 64)) self.weatherIcon.setText("") self.weatherIcon.setObjectName("weatherIcon") self.horizontalLayout_4.addWidget(self.weatherIcon) self.weatherLabel = QLabel(self.centralwidget) self.weatherLabel.setText("") self.weatherLabel.setObjectName("weatherLabel") self.horizontalLayout_4.addWidget(self.weatherLabel) self.verticalLayout.addLayout(self.horizontalLayout_4) self.gridLayout_2 = QGridLayout() self.gridLayout_2.setObjectName("gridLayout_2") self.forecastIcon4 = QLabel(self.centralwidget) sizePolicy = QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.forecastIcon4.sizePolicy().hasHeightForWidth()) self.forecastIcon4.setSizePolicy(sizePolicy) self.forecastIcon4.setMinimumSize(QSize(64, 64)) self.forecastIcon4.setMaximumSize(QSize(200, 32)) self.forecastIcon4.setBaseSize(QSize(0, 0)) self.forecastIcon4.setText("") self.forecastIcon4.setAlignment(Qt.AlignCenter) self.forecastIcon4.setObjectName("forecastIcon4") self.gridLayout_2.addWidget(self.forecastIcon4, 1, 3, 1, 1) self.forecastTemp2 = QLabel(self.centralwidget) self.forecastTemp2.setText("") self.forecastTemp2.setObjectName("forecastTemp2") self.gridLayout_2.addWidget(self.forecastTemp2, 2, 1, 1, 1) self.forecastTemp5 = QLabel(self.centralwidget) self.forecastTemp5.setText("") self.forecastTemp5.setObjectName("forecastTemp5") self.gridLayout_2.addWidget(self.forecastTemp5, 2, 4, 1, 1) self.forecastTemp4 = QLabel(self.centralwidget) self.forecastTemp4.setText("") self.forecastTemp4.setObjectName("forecastTemp4") self.gridLayout_2.addWidget(self.forecastTemp4, 2, 3, 1, 1) self.forecastIcon2 = QLabel(self.centralwidget) sizePolicy = QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.forecastIcon2.sizePolicy().hasHeightForWidth()) self.forecastIcon2.setSizePolicy(sizePolicy) self.forecastIcon2.setMinimumSize(QSize(64, 64)) self.forecastIcon2.setMaximumSize(QSize(200, 32)) self.forecastIcon2.setBaseSize(QSize(0, 0)) self.forecastIcon2.setText("") self.forecastIcon2.setAlignment(Qt.AlignCenter) self.forecastIcon2.setObjectName("forecastIcon2") self.gridLayout_2.addWidget(self.forecastIcon2, 1, 1, 1, 1) self.forecastIcon5 = QLabel(self.centralwidget) sizePolicy = QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.forecastIcon5.sizePolicy().hasHeightForWidth()) self.forecastIcon5.setSizePolicy(sizePolicy) self.forecastIcon5.setMinimumSize(QSize(64, 64)) self.forecastIcon5.setMaximumSize(QSize(200, 32)) self.forecastIcon5.setBaseSize(QSize(0, 0)) self.forecastIcon5.setText("") self.forecastIcon5.setAlignment(Qt.AlignCenter) self.forecastIcon5.setObjectName("forecastIcon5") self.gridLayout_2.addWidget(self.forecastIcon5, 1, 4, 1, 1) self.forecastIcon1 = QLabel(self.centralwidget) sizePolicy = QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.forecastIcon1.sizePolicy().hasHeightForWidth()) self.forecastIcon1.setSizePolicy(sizePolicy) self.forecastIcon1.setMinimumSize(QSize(64, 64)) self.forecastIcon1.setMaximumSize(QSize(200, 32)) self.forecastIcon1.setBaseSize(QSize(0, 0)) self.forecastIcon1.setText("") self.forecastIcon1.setAlignment(Qt.AlignCenter) self.forecastIcon1.setObjectName("forecastIcon1") self.gridLayout_2.addWidget(self.forecastIcon1, 1, 0, 1, 1) self.forecastIcon3 = QLabel(self.centralwidget) sizePolicy = QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.forecastIcon3.sizePolicy().hasHeightForWidth()) self.forecastIcon3.setSizePolicy(sizePolicy) self.forecastIcon3.setMinimumSize(QSize(64, 64)) self.forecastIcon3.setMaximumSize(QSize(200, 32)) self.forecastIcon3.setBaseSize(QSize(0, 0)) self.forecastIcon3.setText("") self.forecastIcon3.setAlignment(Qt.AlignCenter) self.forecastIcon3.setObjectName("forecastIcon3") self.gridLayout_2.addWidget(self.forecastIcon3, 1, 2, 1, 1) self.forecastTemp3 = QLabel(self.centralwidget) self.forecastTemp3.setText("") self.forecastTemp3.setObjectName("forecastTemp3") self.gridLayout_2.addWidget(self.forecastTemp3, 2, 2, 1, 1) self.forecastTemp1 = QLabel(self.centralwidget) self.forecastTemp1.setText("") self.forecastTemp1.setObjectName("forecastTemp1") self.gridLayout_2.addWidget(self.forecastTemp1, 2, 0, 1, 1) self.forecastTime1 = QLabel(self.centralwidget) self.forecastTime1.setAlignment(Qt.AlignCenter) self.forecastTime1.setObjectName("forecastTime1") self.gridLayout_2.addWidget(self.forecastTime1, 0, 0, 1, 1) self.forecastTime2 = QLabel(self.centralwidget) self.forecastTime2.setAlignment(Qt.AlignCenter) self.forecastTime2.setObjectName("forecastTime2") self.gridLayout_2.addWidget(self.forecastTime2, 0, 1, 1, 1) self.forecastTime3 = QLabel(self.centralwidget) self.forecastTime3.setAlignment(Qt.AlignCenter) self.forecastTime3.setObjectName("forecastTime3") self.gridLayout_2.addWidget(self.forecastTime3, 0, 2, 1, 1) self.forecastTime4 = QLabel(self.centralwidget) self.forecastTime4.setAlignment(Qt.AlignCenter) self.forecastTime4.setObjectName("forecastTime4") self.gridLayout_2.addWidget(self.forecastTime4, 0, 3, 1, 1) self.forecastTime5 = QLabel(self.centralwidget) self.forecastTime5.setAlignment(Qt.AlignCenter) self.forecastTime5.setObjectName("forecastTime5") self.gridLayout_2.addWidget(self.forecastTime5, 0, 4, 1, 1) self.verticalLayout.addLayout(self.gridLayout_2) self.gridLayout = QGridLayout() self.gridLayout.setObjectName("gridLayout") self.formLayout = QFormLayout() self.formLayout.setObjectName("formLayout") self.label_5 = QLabel(self.centralwidget) font = QFont() font.setBold(True) font.setWeight(75) self.label_5.setFont(font) self.label_5.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter) self.label_5.setObjectName("label_5") self.formLayout.setWidget(2, QFormLayout.LabelRole, self.label_5) self.label_6 = QLabel(self.centralwidget) self.label_6.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter) self.label_6.setObjectName("label_6") self.formLayout.setWidget(3, QFormLayout.LabelRole, self.label_6) self.temperatureLabel = QLabel(self.centralwidget) self.temperatureLabel.setText("") self.temperatureLabel.setObjectName("temperatureLabel") self.formLayout.setWidget(3, QFormLayout.FieldRole, self.temperatureLabel) self.label_7 = QLabel(self.centralwidget) self.label_7.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter) self.label_7.setObjectName("label_7") self.formLayout.setWidget(4, QFormLayout.LabelRole, self.label_7) self.humidityLabel = QLabel(self.centralwidget) self.humidityLabel.setText("") self.humidityLabel.setObjectName("humidityLabel") self.formLayout.setWidget(4, QFormLayout.FieldRole, self.humidityLabel) self.label_8 = QLabel(self.centralwidget) self.label_8.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter) self.label_8.setObjectName("label_8") self.formLayout.setWidget(5, QFormLayout.LabelRole, self.label_8) self.pressureLabel = QLabel(self.centralwidget) self.pressureLabel.setText("") self.pressureLabel.setObjectName("pressureLabel") self.formLayout.setWidget(5, QFormLayout.FieldRole, self.pressureLabel) self.label = QLabel(self.centralwidget) font = QFont() font.setBold(True) font.setWeight(75) self.label.setFont(font) self.label.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter) self.label.setObjectName("label") self.formLayout.setWidget(6, QFormLayout.LabelRole, self.label) self.label_2 = QLabel(self.centralwidget) self.label_2.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter) self.label_2.setObjectName("label_2") self.formLayout.setWidget(7, QFormLayout.LabelRole, self.label_2) self.longitudeLabel = QLabel(self.centralwidget) self.longitudeLabel.setText("") self.longitudeLabel.setObjectName("longitudeLabel") self.formLayout.setWidget(7, QFormLayout.FieldRole, self.longitudeLabel) self.label_3 = QLabel(self.centralwidget) self.label_3.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter) self.label_3.setObjectName("label_3") self.formLayout.setWidget(8, QFormLayout.LabelRole, self.label_3) self.latitudeLabel = QLabel(self.centralwidget) self.latitudeLabel.setText("") self.latitudeLabel.setObjectName("latitudeLabel") self.formLayout.setWidget(8, QFormLayout.FieldRole, self.latitudeLabel) self.label_4 = QLabel(self.centralwidget) self.label_4.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter) self.label_4.setObjectName("label_4") self.formLayout.setWidget(9, QFormLayout.LabelRole, self.label_4) self.sunriseLabel = QLabel(self.centralwidget) self.sunriseLabel.setText("") self.sunriseLabel.setObjectName("sunriseLabel") self.formLayout.setWidget(9, QFormLayout.FieldRole, self.sunriseLabel) self.label_9 = QLabel(self.centralwidget) self.label_9.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter) self.label_9.setObjectName("label_9") self.formLayout.setWidget(1, QFormLayout.LabelRole, self.label_9) self.label_10 = QLabel(self.centralwidget) font = QFont() font.setBold(True) font.setWeight(75) self.label_10.setFont(font) self.label_10.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter) self.label_10.setObjectName("label_10") self.formLayout.setWidget(0, QFormLayout.LabelRole, self.label_10) self.windLabel = QLabel(self.centralwidget) self.windLabel.setText("") self.windLabel.setObjectName("windLabel") self.formLayout.setWidget(1, QFormLayout.FieldRole, self.windLabel) self.label_11 = QLabel(self.centralwidget) self.label_11.setText("") self.label_11.setObjectName("label_11") self.formLayout.setWidget(0, QFormLayout.FieldRole, self.label_11) self.label_13 = QLabel(self.centralwidget) self.label_13.setText("") self.label_13.setObjectName("label_13") self.formLayout.setWidget(6, QFormLayout.FieldRole, self.label_13) self.label_12 = QLabel(self.centralwidget) self.label_12.setText("") self.label_12.setObjectName("label_12") self.formLayout.setWidget(2, QFormLayout.FieldRole, self.label_12) self.gridLayout.addLayout(self.formLayout, 1, 0, 1, 1) self.verticalLayout.addLayout(self.gridLayout) self.horizontalLayout.addLayout(self.verticalLayout) MainWindow.setCentralWidget(self.centralwidget) self.retranslateUi(MainWindow) QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): _translate = QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "Raindar")) self.lineEdit.setText(_translate("MainWindow", "Utrecht,the Netherlands")) self.forecastTime1.setText(_translate("MainWindow", "+3h")) self.forecastTime2.setText(_translate("MainWindow", "+6h")) self.forecastTime3.setText(_translate("MainWindow", "+9h")) self.forecastTime4.setText(_translate("MainWindow", "+12h")) self.forecastTime5.setText(_translate("MainWindow", "+15h")) self.label_5.setText(_translate("MainWindow", "Barometer")) self.label_6.setText(_translate("MainWindow", "Temperature")) self.label_7.setText(_translate("MainWindow", "Humidity")) self.label_8.setText(_translate("MainWindow", "Pressure")) self.label.setText(_translate("MainWindow", "Location")) self.label_2.setText(_translate("MainWindow", "Longitude")) self.label_3.setText(_translate("MainWindow", "Latitude")) self.label_4.setText(_translate("MainWindow", "Sunrise")) self.label_9.setText(_translate("MainWindow", "Speed")) self.label_10.setText(_translate("MainWindow", "Wind")) def alert(self, message): alert = QMessageBox.warning(self, "Warning", message) def update_weather(self): worker = WeatherWorker(self.lineEdit.text()) worker.signals.result.connect(self.weather_result) worker.signals.error.connect(self.alert) self.threadpool.start(worker) def weather_result(self, weather, forecasts): self.latitudeLabel.setText("%.2f °" % weather['coord']['lat']) self.longitudeLabel.setText("%.2f °" % weather['coord']['lon']) self.windLabel.setText("%.2f m/s" % weather['wind']['speed']) self.temperatureLabel.setText("%.1f °C" % weather['main']['temp']) self.pressureLabel.setText("%d" % weather['main']['pressure']) self.humidityLabel.setText("%d" % weather['main']['humidity']) self.sunriseLabel.setText(from_ts_to_time_of_day(weather['sys']['sunrise'])) self.weatherLabel.setText("%s (%s)" % ( weather['weather'][0]['main'], weather['weather'][0]['description'] ) ) self.set_weather_icon(self.weatherIcon, weather['weather']) for n, forecast in enumerate(forecasts['list'][:5], 1): getattr(self, 'forecastTime%d' % n).setText(from_ts_to_time_of_day(forecast['dt'])) self.set_weather_icon(getattr(self, 'forecastIcon%d' % n), forecast['weather']) getattr(self, 'forecastTemp%d' % n).setText("%.1f °C" % forecast['main']['temp']) def set_weather_icon(self, label, weather): label.setPixmap(QPixmap(os.path.join('images', "%s.png" % weather[0]['icon'])))
class Ui_GroupBox(object): def setupUi(self, GroupBox): if not GroupBox.objectName(): GroupBox.setObjectName(u"GroupBox") GroupBox.resize(452, 296) sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Minimum) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(GroupBox.sizePolicy().hasHeightForWidth()) GroupBox.setSizePolicy(sizePolicy) self.verticalLayout = QVBoxLayout(GroupBox) self.verticalLayout.setObjectName(u"verticalLayout") self.groupBox = QGroupBox(GroupBox) self.groupBox.setObjectName(u"groupBox") self.verticalLayout_3 = QVBoxLayout(self.groupBox) self.verticalLayout_3.setObjectName(u"verticalLayout_3") self.verticalLayout_2 = QVBoxLayout() self.verticalLayout_2.setObjectName(u"verticalLayout_2") self.verticalLayout_2.setContentsMargins(-1, 10, -1, -1) self.checkBox_asp_ser = QCheckBox(self.groupBox) self.checkBox_asp_ser.setObjectName(u"checkBox_asp_ser") self.verticalLayout_2.addWidget(self.checkBox_asp_ser) self.checkBox_ser_backbone = QCheckBox(self.groupBox) self.checkBox_ser_backbone.setObjectName(u"checkBox_ser_backbone") self.verticalLayout_2.addWidget(self.checkBox_ser_backbone) self.checkBox_glu_his = QCheckBox(self.groupBox) self.checkBox_glu_his.setObjectName(u"checkBox_glu_his") self.verticalLayout_2.addWidget(self.checkBox_glu_his) self.checkBox_his_his = QCheckBox(self.groupBox) self.checkBox_his_his.setObjectName(u"checkBox_his_his") self.verticalLayout_2.addWidget(self.checkBox_his_his) self.checkBox_asp_asn = QCheckBox(self.groupBox) self.checkBox_asp_asn.setObjectName(u"checkBox_asp_asn") self.verticalLayout_2.addWidget(self.checkBox_asp_asn) self.checkBox_his_ser = QCheckBox(self.groupBox) self.checkBox_his_ser.setObjectName(u"checkBox_his_ser") self.verticalLayout_2.addWidget(self.checkBox_his_ser) self.checkBox_asp_backbone = QCheckBox(self.groupBox) self.checkBox_asp_backbone.setObjectName(u"checkBox_asp_backbone") self.verticalLayout_2.addWidget(self.checkBox_asp_backbone) self.verticalLayout_3.addLayout(self.verticalLayout_2) self.verticalLayout.addWidget(self.groupBox) 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"Detect motif", None)) self.checkBox_asp_ser.setText( QCoreApplication.translate( "GroupBox", u"Asp/Glu carboxylate oxygen - Ser/Thr hydroxyl oxygen", None)) self.checkBox_ser_backbone.setText( QCoreApplication.translate( "GroupBox", u"Ser-Thr hydroxyl oxygen - backbone carbonyl oxygen", None)) self.checkBox_glu_his.setText( QCoreApplication.translate( "GroupBox", u"Asp/Glu carboxylate oxygen - His ND1 or NE2", None)) self.checkBox_his_his.setText( QCoreApplication.translate("GroupBox", u"His ND1 or NE2 - His ND1 or NE2", None)) self.checkBox_asp_asn.setText( QCoreApplication.translate( "GroupBox", u"Asp/Glu carboxylate oxygen - Asn ND1 or OD2", None)) self.checkBox_his_ser.setText( QCoreApplication.translate( "GroupBox", u"His ND1 or NE2 - Ser/Thr hydroxyl oxygen", None)) self.checkBox_asp_backbone.setText( QCoreApplication.translate( "GroupBox", u"Asp/Glu carboxylate oxygen - backbone", None))
class Ui_Error(object): def setupUi(self, Error): if not Error.objectName(): Error.setObjectName(u"Error") Error.resize(250, 150) Error.setMinimumSize(QSize(250, 150)) Error.setMaximumSize(QSize(250, 150)) self.horizontalLayout = QHBoxLayout(Error) self.horizontalLayout.setSpacing(0) self.horizontalLayout.setObjectName(u"horizontalLayout") self.horizontalLayout.setContentsMargins(0, 0, 0, 0) self.frame = QFrame(Error) self.frame.setObjectName(u"frame") self.frame.setStyleSheet(u"background:rgb(51,51,51);") self.frame.setFrameShape(QFrame.NoFrame) self.frame.setFrameShadow(QFrame.Plain) self.verticalLayout = QVBoxLayout(self.frame) self.verticalLayout.setSpacing(0) self.verticalLayout.setObjectName(u"verticalLayout") self.verticalLayout.setContentsMargins(2, 2, 2, 2) self.frame_top = QFrame(self.frame) self.frame_top.setObjectName(u"frame_top") self.frame_top.setMinimumSize(QSize(0, 55)) self.frame_top.setMaximumSize(QSize(16777215, 55)) self.frame_top.setStyleSheet(u"background:rgb(91,90,90);") self.frame_top.setFrameShape(QFrame.NoFrame) self.frame_top.setFrameShadow(QFrame.Plain) self.horizontalLayout_2 = QHBoxLayout(self.frame_top) self.horizontalLayout_2.setSpacing(5) self.horizontalLayout_2.setObjectName(u"horizontalLayout_2") self.horizontalLayout_2.setContentsMargins(15, 5, 0, 0) self.lab_icon = QLabel(self.frame_top) self.lab_icon.setObjectName(u"lab_icon") self.lab_icon.setMinimumSize(QSize(35, 35)) self.lab_icon.setMaximumSize(QSize(35, 35)) self.horizontalLayout_2.addWidget(self.lab_icon) self.lab_heading = QLabel(self.frame_top) self.lab_heading.setObjectName(u"lab_heading") font = QFont() font.setFamily(u"Segoe UI") font.setPointSize(12) self.lab_heading.setFont(font) self.lab_heading.setStyleSheet(u"color:rgb(255,255,255);") self.lab_heading.setWordWrap(True) self.horizontalLayout_2.addWidget(self.lab_heading) self.verticalLayout.addWidget(self.frame_top) self.frame_bottom = QFrame(self.frame) self.frame_bottom.setObjectName(u"frame_bottom") self.frame_bottom.setStyleSheet(u"background:rgb(91,90,90);") self.frame_bottom.setFrameShape(QFrame.NoFrame) self.frame_bottom.setFrameShadow(QFrame.Plain) self.gridLayout = QGridLayout(self.frame_bottom) self.gridLayout.setObjectName(u"gridLayout") self.gridLayout.setContentsMargins(-1, -1, -1, 0) self.bn_ok = QPushButton(self.frame_bottom) self.bn_ok.setObjectName(u"bn_ok") self.bn_ok.setMinimumSize(QSize(69, 25)) self.bn_ok.setMaximumSize(QSize(69, 25)) self.bn_ok.setStyleSheet(u"QPushButton {\n" " border: 2px solid rgb(51,51,51);\n" " border-radius: 5px; \n" " color:rgb(255,255,255);\n" " background-color: rgb(51,51,51);\n" "}\n" "QPushButton:hover {\n" " border: 2px solid rgb(0,143,150);\n" " background-color: rgb(0,143,150);\n" "}\n" "QPushButton:pressed { \n" " border: 2px solid rgb(0,143,150);\n" " background-color: rgb(51,51,51);\n" "}\n" "") self.gridLayout.addWidget(self.bn_ok, 0, 0, 1, 1) self.verticalLayout.addWidget(self.frame_bottom) self.horizontalLayout.addWidget(self.frame) self.retranslateUi(Error) QMetaObject.connectSlotsByName(Error) # setupUi def retranslateUi(self, Error): Error.setWindowTitle( QCoreApplication.translate("Error", u"Dialog", None)) self.lab_icon.setText("") self.lab_heading.setText("") self.bn_ok.setText("")
class Ui_MainWindow(object): def __init__(self): self.file_name = "" self.threadpool = QThreadPool() self.num_of_co = 1000 self.alpha = 0.1 self.watermarker = None def setupUi(self, MainWindow): if not MainWindow.objectName(): MainWindow.setObjectName(u"MainWindow") MainWindow.resize(1024, 768) self.centralwidget = QWidget(MainWindow) self.centralwidget.setObjectName(u"centralwidget") self.verticalLayoutWidget_2 = QWidget(self.centralwidget) self.verticalLayoutWidget_2.setObjectName(u"verticalLayoutWidget_2") self.verticalLayoutWidget_2.setGeometry(QRect(0, 0, 1021, 511)) self.pictureLayout = QVBoxLayout(self.verticalLayoutWidget_2) self.pictureLayout.setObjectName(u"pictureLayout") self.pictureLayout.setContentsMargins(0, 0, 0, 0) self.picture_label = QLabel(self.verticalLayoutWidget_2) self.picture_label.setObjectName(u"picture_label") self.pictureLayout.addWidget(self.picture_label) self.picture_button = QPushButton(self.verticalLayoutWidget_2) self.picture_button.setObjectName(u"picture_button") self.pictureLayout.addWidget(self.picture_button) self.horizontalLayoutWidget = QWidget(self.centralwidget) self.horizontalLayoutWidget.setObjectName(u"horizontalLayoutWidget") self.horizontalLayoutWidget.setGeometry(QRect(10, 520, 1011, 120)) self.horizontalLayout_2 = QHBoxLayout(self.horizontalLayoutWidget) self.horizontalLayout_2.setObjectName(u"horizontalLayout_2") self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0) self.verticalLayout_3 = QVBoxLayout() self.verticalLayout_3.setObjectName(u"verticalLayout_3") self.label_2 = QLabel(self.horizontalLayoutWidget) self.label_2.setObjectName(u"label_2") self.verticalLayout_3.addWidget(self.label_2) self.DCT_encode = QPushButton(self.horizontalLayoutWidget) self.DCT_encode.setObjectName(u"DCT_encode") self.verticalLayout_3.addWidget(self.DCT_encode) self.DCT_decode = QPushButton(self.horizontalLayoutWidget) self.DCT_decode.setObjectName(u"DCT_decode") self.verticalLayout_3.addWidget(self.DCT_decode) self.label_4 = QLabel(self.horizontalLayoutWidget) self.label_4.setObjectName(u"label_4") self.verticalLayout_3.addWidget(self.label_4) self.DCT_masg = QLineEdit(self.horizontalLayoutWidget) self.DCT_masg.setObjectName(u"DCT_masg") self.verticalLayout_3.addWidget(self.DCT_masg) self.horizontalLayout_2.addLayout(self.verticalLayout_3) self.verticalLayout = QVBoxLayout() self.verticalLayout.setObjectName(u"verticalLayout") self.label_3 = QLabel(self.horizontalLayoutWidget) self.label_3.setObjectName(u"label_3") self.verticalLayout.addWidget(self.label_3) self.LSB_encode = QPushButton(self.horizontalLayoutWidget) self.LSB_encode.setObjectName(u"LSB_encode") self.verticalLayout.addWidget(self.LSB_encode) self.LSB_decode = QPushButton(self.horizontalLayoutWidget) self.LSB_decode.setObjectName(u"LSB_decode") self.verticalLayout.addWidget(self.LSB_decode) self.lsb_encode_msg = QLabel(self.horizontalLayoutWidget) self.lsb_encode_msg.setObjectName(u"lsb_encode_msg") self.verticalLayout.addWidget(self.lsb_encode_msg) self.LSB_msg = QLineEdit(self.horizontalLayoutWidget) self.LSB_msg.setObjectName(u"LSB_msg") self.verticalLayout.addWidget(self.LSB_msg) self.horizontalLayout_2.addLayout(self.verticalLayout) self.verticalLayoutWidget_3 = QWidget(self.centralwidget) self.verticalLayoutWidget_3.setObjectName(u"verticalLayoutWidget_3") self.verticalLayoutWidget_3.setGeometry(QRect(20, 650, 981, 51)) self.verticalLayout_2 = QVBoxLayout(self.verticalLayoutWidget_3) self.verticalLayout_2.setObjectName(u"verticalLayout_2") self.verticalLayout_2.setContentsMargins(0, 0, 0, 0) self.label_6 = QLabel(self.verticalLayoutWidget_3) self.label_6.setObjectName(u"label_6") self.verticalLayout_2.addWidget(self.label_6) self.progressBar = QProgressBar(self.verticalLayoutWidget_3) self.progressBar.setObjectName(u"progressBar") self.progressBar.setValue(0) self.verticalLayout_2.addWidget(self.progressBar) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QMenuBar(MainWindow) self.menubar.setObjectName(u"menubar") self.menubar.setGeometry(QRect(0, 0, 1024, 21)) MainWindow.setMenuBar(self.menubar) self.statusbar = QStatusBar(MainWindow) self.statusbar.setObjectName(u"statusbar") MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) # bind functions self.picture_button.clicked.connect(self.open_file) self.LSB_encode.clicked.connect(self.call_lsb_encode) self.LSB_decode.clicked.connect(self.call_lsb_decode) self.DCT_encode.clicked.connect(self.call_dct_encode) self.DCT_decode.clicked.connect(self.call_dct_decode) # end bind functions() self.hide_progress_bar() self.disable_Methods(True) QMetaObject.connectSlotsByName(MainWindow) # setupUi def retranslateUi(self, MainWindow): MainWindow.setWindowTitle( QCoreApplication.translate("MainWindow", u"Watermarking tool", None)) # self.picture_label.setText(QCoreApplication.translate("MainWindow", u"TextLabel", None)) self.picture_button.setText( QCoreApplication.translate("MainWindow", u"Select picture", None)) self.label_2.setText( QCoreApplication.translate("MainWindow", u"DCT", None)) self.DCT_encode.setText( QCoreApplication.translate("MainWindow", u"encode", None)) self.DCT_decode.setText( QCoreApplication.translate("MainWindow", u"decode", None)) self.label_4.setText( QCoreApplication.translate("MainWindow", u"coeficient:", None)) self.DCT_masg.setText( QCoreApplication.translate("MainWindow", u"1000, 0.1", None)) self.label_3.setText( QCoreApplication.translate("MainWindow", u"LSB", None)) self.LSB_encode.setText( QCoreApplication.translate("MainWindow", u"encode", None)) self.LSB_decode.setText( QCoreApplication.translate("MainWindow", u"decode", None)) self.lsb_encode_msg.setText( QCoreApplication.translate("MainWindow", u"LSB msg:", None)) self.LSB_msg.setText( QCoreApplication.translate("MainWindow", u"secret", None)) self.label_6.setText( QCoreApplication.translate("MainWindow", u"Work in progress:", None)) # retranslateUi # def bindFunctions(self): def load_picture(self): pixmap = QPixmap(self.file_name[0]) if pixmap.width() > pixmap.height(): self.picture_label.setPixmap( pixmap.scaledToWidth(self.picture_label.width())) else: self.picture_label.setPixmap( pixmap.scaledToHeight(self.picture_label.height())) def open_file(self): self.hide_progress_bar() self.file_name = QFileDialog.getOpenFileName( None, "Open Image", "", "Image Files (*.png *.jpg *.bmp)") self.load_picture() self.disable_Methods(False) def method_LSB_encode(self, progress_callback): self.disable_Methods(True) progress_callback.emit(10) msg = self.LSB_msg.text() image = cv2.imread(self.file_name[0]) watermarker = LSBWatermarker(image=image, mode='encode-message', message=msg, filename='result.png') progress_callback.emit(50) self.file_name = ["result.png", ""] watermarker.run() progress_callback.emit(90) self.load_picture() self.disable_Methods(False) progress_callback.emit(100) def method_LSB_decode(self, progress_callback): self.disable_Methods(True) self.LSB_msg.setText("") progress_callback.emit(10) image = cv2.imread(self.file_name[0]) watermarker = LSBWatermarker(image=image, mode='decode-message') progress_callback.emit(50) watermarker.run() self.disable_Methods(False) progress_callback.emit(90) # self.show_decoded_msg(watermarker.decoded_msg) if watermarker.decoded_msg == "Provided file has no message encoded!": self.LSB_msg.setText(watermarker.decoded_msg) else: self.LSB_msg.setText("Decoded: " + watermarker.decoded_msg) progress_callback.emit(100) def method_DCT_encode(self, progress_callback): self.disable_Methods(True) progress_callback.emit(10) msg = self.DCT_masg.text().split(",") try: self.num_of_co = int(msg[0]) self.alpha = float(msg[1]) self.watermarker = WatermarkDCT(self.file_name[0], num_of_co=self.num_of_co, alpha=self.alpha) progress_callback.emit(50) self.watermarker.encode_watermark() self.file_name = ["result_DCT.png", ""] self.DCT_masg.setText("Picture is watermarked?:" + str(self.watermarker.detect_watermark())) except Exception as e: print(e) self.DCT_masg.setText("Error: wrong parameters: example 1000, 0.1") finally: progress_callback.emit(90) self.load_picture() self.disable_Methods(False) progress_callback.emit(100) def method_DCT_decode(self, progress_callback): self.disable_Methods(True) progress_callback.emit(10) try: if self.watermarker is None: self.watermarker = WatermarkDCT(self.file_name[0], num_of_co=self.num_of_co, alpha=self.alpha) progress_callback.emit(50) self.DCT_masg.setText( "Picture is watermarked?:" + str(self.watermarker.detect_watermark(self.file_name[0]))) except Exception as e: print(e) self.DCT_masg.setText("Error: Unable to check the picture.") finally: progress_callback.emit(90) self.load_picture() self.disable_Methods(False) progress_callback.emit(100) def show_decoded_msg(self, msg): msgBox = QMessageBox() msgBox.setWindowTitle("Decoded message:") msgBox.setText(msg) msgBox.exec_() def thread_complete(self): print("THREAD COMPLETE!") def progress_fn(self, n): self.progressBar.setValue(n) def print_output(self, s): print(s) def call_lsb_encode(self): self.show_progress_bar() self.call_function(self.method_LSB_encode) def call_lsb_decode(self): self.show_progress_bar() self.call_function(self.method_LSB_decode) def call_dct_encode(self): self.show_progress_bar() self.call_function(self.method_DCT_encode) def call_dct_decode(self): self.show_progress_bar() self.call_function(self.method_DCT_decode) def call_function(self, fn): worker = Worker( fn) # Any other args, kwargs are passed to the run function worker.signals.result.connect(self.print_output) worker.signals.finished.connect(self.thread_complete) worker.signals.progress.connect(self.progress_fn) # Execute self.threadpool.start(worker) def hide_progress_bar(self): self.progressBar.setValue(0) self.progressBar.setVisible(False) self.label_6.setVisible(False) def show_progress_bar(self): self.progressBar.setValue(0) self.progressBar.setVisible(True) self.label_6.setVisible(True) def disable_Methods(self, disable): self.LSB_encode.setDisabled(disable) self.LSB_decode.setDisabled(disable) self.DCT_decode.setDisabled(disable) self.DCT_encode.setDisabled(disable)
class Ui_spellDialog(object): def setupUi(self, spellDialog): if spellDialog.objectName(): spellDialog.setObjectName(u"spellDialog") spellDialog.resize(400, 372) self.verticalLayout = QVBoxLayout(spellDialog) self.verticalLayout.setObjectName(u"verticalLayout") self.formLayout = QFormLayout() self.formLayout.setObjectName(u"formLayout") self.preparedLabel = QLabel(spellDialog) self.preparedLabel.setObjectName(u"preparedLabel") self.formLayout.setWidget(0, QFormLayout.LabelRole, self.preparedLabel) self.preparedCheckBox = QCheckBox(spellDialog) self.preparedCheckBox.setObjectName(u"preparedCheckBox") self.formLayout.setWidget(0, QFormLayout.FieldRole, self.preparedCheckBox) self.levelLabel = QLabel(spellDialog) self.levelLabel.setObjectName(u"levelLabel") self.formLayout.setWidget(1, QFormLayout.LabelRole, self.levelLabel) self.levelSpinBox = QSpinBox(spellDialog) self.levelSpinBox.setObjectName(u"levelSpinBox") self.formLayout.setWidget(1, QFormLayout.FieldRole, self.levelSpinBox) self.spellNameLabel = QLabel(spellDialog) self.spellNameLabel.setObjectName(u"spellNameLabel") self.formLayout.setWidget(2, QFormLayout.LabelRole, self.spellNameLabel) self.spellNameLineEdit = QLineEdit(spellDialog) self.spellNameLineEdit.setObjectName(u"spellNameLineEdit") self.formLayout.setWidget(2, QFormLayout.FieldRole, self.spellNameLineEdit) self.sourceLabel = QLabel(spellDialog) self.sourceLabel.setObjectName(u"sourceLabel") self.formLayout.setWidget(3, QFormLayout.LabelRole, self.sourceLabel) self.sourceLineEdit = QLineEdit(spellDialog) self.sourceLineEdit.setObjectName(u"sourceLineEdit") self.formLayout.setWidget(3, QFormLayout.FieldRole, self.sourceLineEdit) self.saveAttackLabel = QLabel(spellDialog) self.saveAttackLabel.setObjectName(u"saveAttackLabel") self.formLayout.setWidget(4, QFormLayout.LabelRole, self.saveAttackLabel) self.saveAttackLineEdit = QLineEdit(spellDialog) self.saveAttackLineEdit.setObjectName(u"saveAttackLineEdit") self.formLayout.setWidget(4, QFormLayout.FieldRole, self.saveAttackLineEdit) self.timeLabel = QLabel(spellDialog) self.timeLabel.setObjectName(u"timeLabel") self.formLayout.setWidget(5, QFormLayout.LabelRole, self.timeLabel) self.timeLineEdit = QLineEdit(spellDialog) self.timeLineEdit.setObjectName(u"timeLineEdit") self.formLayout.setWidget(5, QFormLayout.FieldRole, self.timeLineEdit) self.rangeLabel = QLabel(spellDialog) self.rangeLabel.setObjectName(u"rangeLabel") self.formLayout.setWidget(6, QFormLayout.LabelRole, self.rangeLabel) self.rangeLineEdit = QLineEdit(spellDialog) self.rangeLineEdit.setObjectName(u"rangeLineEdit") self.formLayout.setWidget(6, QFormLayout.FieldRole, self.rangeLineEdit) self.componentsLabel = QLabel(spellDialog) self.componentsLabel.setObjectName(u"componentsLabel") self.formLayout.setWidget(7, QFormLayout.LabelRole, self.componentsLabel) self.componentsLineEdit = QLineEdit(spellDialog) self.componentsLineEdit.setObjectName(u"componentsLineEdit") self.formLayout.setWidget(7, QFormLayout.FieldRole, self.componentsLineEdit) self.durationLabel = QLabel(spellDialog) self.durationLabel.setObjectName(u"durationLabel") self.formLayout.setWidget(8, QFormLayout.LabelRole, self.durationLabel) self.durationLineEdit = QLineEdit(spellDialog) self.durationLineEdit.setObjectName(u"durationLineEdit") self.formLayout.setWidget(8, QFormLayout.FieldRole, self.durationLineEdit) self.pageReferenceLabel = QLabel(spellDialog) self.pageReferenceLabel.setObjectName(u"pageReferenceLabel") self.formLayout.setWidget(9, QFormLayout.LabelRole, self.pageReferenceLabel) self.pageReferenceLineEdit = QLineEdit(spellDialog) self.pageReferenceLineEdit.setObjectName(u"pageReferenceLineEdit") self.formLayout.setWidget(9, QFormLayout.FieldRole, self.pageReferenceLineEdit) self.notesLabel = QLabel(spellDialog) self.notesLabel.setObjectName(u"notesLabel") self.formLayout.setWidget(10, QFormLayout.LabelRole, self.notesLabel) self.notesLineEdit = QLineEdit(spellDialog) self.notesLineEdit.setObjectName(u"notesLineEdit") self.formLayout.setWidget(10, QFormLayout.FieldRole, self.notesLineEdit) self.verticalLayout.addLayout(self.formLayout) self.buttonBox = QDialogButtonBox(spellDialog) self.buttonBox.setObjectName(u"buttonBox") self.buttonBox.setOrientation(Qt.Horizontal) self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok) self.verticalLayout.addWidget(self.buttonBox) self.retranslateUi(spellDialog) self.buttonBox.accepted.connect(spellDialog.accept) self.buttonBox.rejected.connect(spellDialog.reject) QMetaObject.connectSlotsByName(spellDialog) # setupUi def retranslateUi(self, spellDialog): spellDialog.setWindowTitle( QCoreApplication.translate("spellDialog", u"dialog", None)) self.preparedLabel.setText( QCoreApplication.translate("spellDialog", u"Prepared", None)) self.levelLabel.setText( QCoreApplication.translate("spellDialog", u"Level", None)) self.spellNameLabel.setText( QCoreApplication.translate("spellDialog", u"Spell Name", None)) self.sourceLabel.setText( QCoreApplication.translate("spellDialog", u"Source", None)) self.saveAttackLabel.setText( QCoreApplication.translate("spellDialog", u"Save/Attack", None)) self.timeLabel.setText( QCoreApplication.translate("spellDialog", u"Time", None)) self.rangeLabel.setText( QCoreApplication.translate("spellDialog", u"Range", None)) self.componentsLabel.setText( QCoreApplication.translate("spellDialog", u"Components", None)) self.durationLabel.setText( QCoreApplication.translate("spellDialog", u"Duration", None)) self.pageReferenceLabel.setText( QCoreApplication.translate("spellDialog", u"Page Reference", None)) self.notesLabel.setText( QCoreApplication.translate("spellDialog", u"Notes", None))
class Ui_MainWindow(QMainWindow): def setupUi(self, MainWindow): if MainWindow.objectName(): MainWindow.setObjectName(u"MainWindow") MainWindow.resize(1080, 820) self.centralwidget = QWidget(MainWindow) self.centralwidget.setObjectName(u"centralwidget") self.MainLayout = QVBoxLayout(self.centralwidget) self.MainLayout.setSpacing(5) self.MainLayout.setObjectName(u"MainLayout") self.MainLayout.setContentsMargins(40, -1, 40, 20) self.MenuLayout = QHBoxLayout() self.MenuLayout.setSpacing(4) self.MenuLayout.setObjectName(u"MenuLayout") self.MenuLayout.setSizeConstraint(QLayout.SetMinimumSize) self.Select = QPushButton(self.centralwidget) self.Select.setObjectName(u"Select") self.MenuLayout.addWidget(self.Select) self.horizontalSpacer_2 = QSpacerItem( 98, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.MenuLayout.addItem(self.horizontalSpacer_2) self.label1 = QLabel(self.centralwidget) self.label1.setObjectName(u"label1") self.MenuLayout.addWidget(self.label1) self.MinSelect = QLineEdit(self.centralwidget) self.MinSelect.setObjectName(u"MInSelect") self.MinSelect.setMaximumSize(QSize(50, 16777215)) self.MenuLayout.addWidget(self.MinSelect) self.label2 = QLabel(self.centralwidget) self.label2.setObjectName(u"label2") font = QFont() font.setFamily(u"Arial") font.setPointSize(12) self.label2.setFont(font) self.label2.setAlignment(Qt.AlignCenter) self.MenuLayout.addWidget(self.label2) self.MaxSelect = QLineEdit(self.centralwidget) self.MaxSelect.setObjectName(u"MaxSelect") self.MaxSelect.setMaximumSize(QSize(50, 16777215)) self.MenuLayout.addWidget(self.MaxSelect) self.Button = QPushButton(self.centralwidget) self.Button.setObjectName(u"Button") self.Button.setMinimumSize(QSize(100, 0)) self.MenuLayout.addWidget(self.Button) self.horizontalSpacer_3 = QSpacerItem( 148, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.MenuLayout.addItem(self.horizontalSpacer_3) self.MainLayout.addLayout(self.MenuLayout) self.line = QFrame(self.centralwidget) self.line.setObjectName(u"line") self.line.setFrameShape(QFrame.HLine) self.line.setFrameShadow(QFrame.Sunken) self.MainLayout.addWidget(self.line) self.BankLayout = QVBoxLayout() self.BankLayout.setObjectName(u"BankLayout") self.label_0 = QLabel(self.centralwidget) self.label_0.setObjectName(u"label_0") font1 = QFont() font1.setFamily(u"\u5fae\u8f6f\u96c5\u9ed1") font1.setPointSize(12) self.label_0.setFont(font1) self.label_0.setAlignment(Qt.AlignLeading | Qt.AlignLeft | Qt.AlignTop) self.label_0.setWordWrap(True) self.BankLayout.addWidget(self.label_0) self.line_1 = QFrame(self.centralwidget) self.line_1.setObjectName(u"line_1") self.line_1.setFrameShape(QFrame.HLine) self.line_1.setFrameShadow(QFrame.Sunken) self.BankLayout.addWidget(self.line_1) self.label_1 = QLabel(self.centralwidget) self.label_1.setObjectName(u"label_1") self.label_1.setFont(font1) self.label_1.setAlignment(Qt.AlignLeading | Qt.AlignLeft | Qt.AlignTop) self.label_1.setWordWrap(True) self.BankLayout.addWidget(self.label_1) self.line_2 = QFrame(self.centralwidget) self.line_2.setObjectName(u"line_2") self.line_2.setFrameShape(QFrame.HLine) self.line_2.setFrameShadow(QFrame.Sunken) self.BankLayout.addWidget(self.line_2) self.label_2 = QLabel(self.centralwidget) self.label_2.setObjectName(u"label_2") self.label_2.setFont(font1) self.label_2.setAlignment(Qt.AlignLeading | Qt.AlignLeft | Qt.AlignTop) self.label_2.setWordWrap(True) self.BankLayout.addWidget(self.label_2) self.line_3 = QFrame(self.centralwidget) self.line_3.setObjectName(u"line_3") self.line_3.setFrameShape(QFrame.HLine) self.line_3.setFrameShadow(QFrame.Sunken) self.BankLayout.addWidget(self.line_3) self.label_3 = QLabel(self.centralwidget) self.label_3.setObjectName(u"label_3") self.label_3.setFont(font1) self.label_3.setAlignment(Qt.AlignLeading | Qt.AlignLeft | Qt.AlignTop) self.label_3.setWordWrap(True) self.BankLayout.addWidget(self.label_3) self.line_4 = QFrame(self.centralwidget) self.line_4.setObjectName(u"line_4") self.line_4.setFrameShape(QFrame.HLine) self.line_4.setFrameShadow(QFrame.Sunken) self.BankLayout.addWidget(self.line_4) self.label_4 = QLabel(self.centralwidget) self.label_4.setObjectName(u"label_4") self.label_4.setFont(font1) self.label_4.setAlignment(Qt.AlignLeading | Qt.AlignLeft | Qt.AlignTop) self.label_4.setWordWrap(True) self.BankLayout.addWidget(self.label_4) self.line_5 = QFrame(self.centralwidget) self.line_5.setObjectName(u"line_5") self.line_5.setFrameShape(QFrame.HLine) self.line_5.setFrameShadow(QFrame.Sunken) self.BankLayout.addWidget(self.line_5) self.label_5 = QLabel(self.centralwidget) self.label_5.setObjectName(u"label_5") self.label_5.setFont(font1) self.label_5.setAlignment(Qt.AlignLeading | Qt.AlignLeft | Qt.AlignTop) self.label_5.setWordWrap(True) self.BankLayout.addWidget(self.label_5) self.line_6 = QFrame(self.centralwidget) self.line_6.setObjectName(u"line_6") self.line_6.setFrameShape(QFrame.HLine) self.line_6.setFrameShadow(QFrame.Sunken) self.BankLayout.addWidget(self.line_6) self.label_6 = QLabel(self.centralwidget) self.label_6.setObjectName(u"label_6") self.label_6.setFont(font1) self.label_6.setAlignment(Qt.AlignLeading | Qt.AlignLeft | Qt.AlignTop) self.label_6.setWordWrap(True) self.BankLayout.addWidget(self.label_6) self.line_7 = QFrame(self.centralwidget) self.line_7.setObjectName(u"line_7") self.line_7.setFrameShape(QFrame.HLine) self.line_7.setFrameShadow(QFrame.Sunken) self.BankLayout.addWidget(self.line_7) self.label_7 = QLabel(self.centralwidget) self.label_7.setObjectName(u"label_7") self.label_7.setFont(font1) self.label_7.setAlignment(Qt.AlignLeading | Qt.AlignLeft | Qt.AlignTop) self.label_7.setWordWrap(True) self.BankLayout.addWidget(self.label_7) self.line_8 = QFrame(self.centralwidget) self.line_8.setObjectName(u"line_8") self.line_8.setFrameShape(QFrame.HLine) self.line_8.setFrameShadow(QFrame.Sunken) self.BankLayout.addWidget(self.line_8) self.label_8 = QLabel(self.centralwidget) self.label_8.setObjectName(u"label_8") self.label_8.setFont(font1) self.label_8.setAlignment(Qt.AlignLeading | Qt.AlignLeft | Qt.AlignTop) self.label_8.setWordWrap(True) self.BankLayout.addWidget(self.label_8) self.line_9 = QFrame(self.centralwidget) self.line_9.setObjectName(u"line_9") self.line_9.setFrameShape(QFrame.HLine) self.line_9.setFrameShadow(QFrame.Sunken) self.BankLayout.addWidget(self.line_9) self.label_9 = QLabel(self.centralwidget) self.label_9.setObjectName(u"label_9") self.label_9.setFont(font1) self.label_9.setAlignment(Qt.AlignLeading | Qt.AlignLeft | Qt.AlignTop) self.label_9.setWordWrap(True) self.BankLayout.addWidget(self.label_9) self.MainLayout.addLayout(self.BankLayout) MainWindow.setCentralWidget(self.centralwidget) QWidget.setTabOrder(self.MinSelect, self.MaxSelect) QWidget.setTabOrder(self.MaxSelect, self.Button) QWidget.setTabOrder(self.Button, self.Select) self.retranslateUi(MainWindow) QMetaObject.connectSlotsByName(MainWindow) self.setupUi_(MainWindow) # setupUI的补充 # setupUi def retranslateUi(self, MainWindow): MainWindow.setWindowTitle(QCoreApplication.translate( "MainWindow", u"MainWindow", None)) self.Select.setText(QCoreApplication.translate( "MainWindow", u"\u9009\u62e9", None)) self.label1.setText(QCoreApplication.translate( "MainWindow", u"\u9898\u76ee\u8303\u56f4\uff1a", None)) self.MinSelect.setText( QCoreApplication.translate("MainWindow", u"1", None)) self.label2.setText(QCoreApplication.translate( "MainWindow", u"\u2014", None)) # 最大题号 self.MaxSelect.setText( QCoreApplication.translate("MainWindow", u"305", None)) self.Button.setText(QCoreApplication.translate( "MainWindow", u"\u62bd\u9898", None)) self.label_0.setText(QCoreApplication.translate( "MainWindow", u"1\u3001", None)) self.label_1.setText(QCoreApplication.translate( "MainWindow", u"2\u3001", None)) self.label_2.setText(QCoreApplication.translate( "MainWindow", u"3\u3001", None)) self.label_3.setText(QCoreApplication.translate( "MainWindow", u"4\u3001", None)) self.label_4.setText(QCoreApplication.translate( "MainWindow", u"5\u3001", None)) self.label_5.setText(QCoreApplication.translate( "MainWindow", u"6\u3001", None)) self.label_6.setText(QCoreApplication.translate( "MainWindow", u"7\u3001", None)) self.label_7.setText(QCoreApplication.translate( "MainWindow", u"8\u3001", None)) self.label_8.setText(QCoreApplication.translate( "MainWindow", u"9\u3001", None)) self.label_9.setText(QCoreApplication.translate( "MainWindow", u"10\u3001", None)) # retranslateUi # -------------------------------------------------------------------- def setupUi_(self, MainWindow): # set Icon icon = QIcon() icon.addFile("./icon.ico") MainWindow.setWindowIcon(icon) # Set constant self.LABEL_N = {0: self.label_0, 1: self.label_1, 2: self.label_2, 3: self.label_3, 4: self.label_4, 5: self.label_5, 6: self.label_6, 7: self.label_7, 8: self.label_8, 9: self.label_9} self.QUESTIONS = [i for i in range(1, 11)] self.FILE = "./bank/货运组理论试题.xls" if os.access(self.FILE, os.F_OK) is False: self.FILE = '' self.selectFile() # set QMessageBox self.message = QMessageBox(text="选择题库") self.message.setWindowTitle(" ") # Action self.Select.clicked.connect(self.selectFile) self.Button.clicked.connect(self.cilckButton) for i in self.LABEL_N: _label = self.LABEL_N[i] _label.ANSWER = "" _label.TIME = 0 _label.installEventFilter(self) # 安装事件过滤器 # Filter _regex = QRegExp("^[0-9]*[1-9][0-9]*$") # 正则表达式:正整数 _validator = QRegExpValidator(_regex) self.MinSelect.setValidator(_validator) self.MaxSelect.setValidator(_validator) # opstion---------------------------------- def selectFile(self): # 选择文件 FILE = QFileDialog.getOpenFileName( caption="打开execl格式题库", filter="Execl files(*.xls;*.xlsx)") if FILE[0] != '': self.FILE = FILE[0] def cilckButton(self): # 抽题号 if self.FILE == '': self.message.exec_() return MIN = int(self.MinSelect.text()) + 2 MAX = int(self.MaxSelect.text()) + 2 MAX += 1 if MAX - MIN <= 9: return self.QUESTIONS = sample(range(MIN, MAX, 1), 10) self.QUESTIONS.sort() self.readExecl() def readExecl(self): # 读取execl wb = xlrd.open_workbook(self.FILE) sheet = wb.sheet_by_index(0) for i in range(0, 10): text = sheet.cell(self.QUESTIONS[i]-1, 1).value text = str( int(sheet.cell(self.QUESTIONS[i]-1, 0).value)) + ". " + text ANSWER = sheet.cell(self.QUESTIONS[i]-1, 2).value TIME = sheet.cell(self.QUESTIONS[i]-1, 5).value self.setLabel(i, text, ANSWER, TIME) def setLabel(self, i, text, ANSWER, TIME): # 设置label _label = self.LABEL_N[i] _label.setText(text) _label.ANSWER = ANSWER _label.TIME = TIME def callDialog(self, question, ANSWER, TIME): # 打开答案窗口 dialog = Ui_Dialog() dialogWindow = QDialog() dialog.setupUi(dialogWindow) dialog.setupUi_(question, ANSWER, TIME) dialogWindow.exec_() def eventFilter(self, obj, event): # 事件过滤器 try: if obj.TIME == 0: return False if event.type() == QEvent.MouseButtonPress: self.callDialog(obj.text(), obj.ANSWER, obj.TIME) return True else: return False except AttributeError: return False
class Ui_TransformDialog1(object): def setupUi(self, TransformDialog1): if not TransformDialog1.objectName(): TransformDialog1.setObjectName(u"TransformDialog1") TransformDialog1.resize(546, 248) self.verticalLayoutWidget = QWidget(TransformDialog1) self.verticalLayoutWidget.setObjectName(u"verticalLayoutWidget") self.verticalLayoutWidget.setGeometry(QRect(30, 20, 481, 211)) self.verticalLayout = QVBoxLayout(self.verticalLayoutWidget) self.verticalLayout.setObjectName(u"verticalLayout") self.verticalLayout.setContentsMargins(0, 0, 0, 0) self.horizontalLayout_2 = QHBoxLayout() self.horizontalLayout_2.setObjectName(u"horizontalLayout_2") self.dataRowBeginText = QLabel(self.verticalLayoutWidget) self.dataRowBeginText.setObjectName(u"dataRowBeginText") self.horizontalLayout_2.addWidget(self.dataRowBeginText) self.dataRowBegin = QLineEdit(self.verticalLayoutWidget) self.dataRowBegin.setObjectName(u"dataRowBegin") self.horizontalLayout_2.addWidget(self.dataRowBegin) self.dataRowEndText = QLabel(self.verticalLayoutWidget) self.dataRowEndText.setObjectName(u"dataRowEndText") self.horizontalLayout_2.addWidget(self.dataRowEndText) self.dataRowEnd = QLineEdit(self.verticalLayoutWidget) self.dataRowEnd.setObjectName(u"dataRowEnd") self.horizontalLayout_2.addWidget(self.dataRowEnd) self.verticalLayout.addLayout(self.horizontalLayout_2) self.horizontalLayout = QHBoxLayout() self.horizontalLayout.setObjectName(u"horizontalLayout") self.dataColBeginText = QLabel(self.verticalLayoutWidget) self.dataColBeginText.setObjectName(u"dataColBeginText") self.horizontalLayout.addWidget(self.dataColBeginText) self.dataColBegin = QLineEdit(self.verticalLayoutWidget) self.dataColBegin.setObjectName(u"dataColBegin") self.horizontalLayout.addWidget(self.dataColBegin) self.dataColEndText = QLabel(self.verticalLayoutWidget) self.dataColEndText.setObjectName(u"dataColEndText") self.horizontalLayout.addWidget(self.dataColEndText) self.dataColEnd = QLineEdit(self.verticalLayoutWidget) self.dataColEnd.setObjectName(u"dataColEnd") self.horizontalLayout.addWidget(self.dataColEnd) self.verticalLayout.addLayout(self.horizontalLayout) self.okButton = QPushButton(self.verticalLayoutWidget) self.okButton.setObjectName(u"okButton") self.verticalLayout.addWidget(self.okButton) self.retranslateUi(TransformDialog1) QMetaObject.connectSlotsByName(TransformDialog1) # setupUi def retranslateUi(self, TransformDialog1): TransformDialog1.setWindowTitle( QCoreApplication.translate("TransformDialog1", u"\u884c\u5217\u8f6c\u7f6e", None)) self.dataRowBeginText.setText( QCoreApplication.translate( "TransformDialog1", u"\u6570\u636e\u96c6\u8d77\u59cb\u884c\u6570\uff1a", None)) self.dataRowEndText.setText( QCoreApplication.translate( "TransformDialog1", u"\u6570\u636e\u96c6\u7ed3\u675f\u884c\u6570\uff1a", None)) self.dataColBeginText.setText( QCoreApplication.translate( "TransformDialog1", u"\u6570\u636e\u96c6\u8d77\u59cb\u5217\u6570\uff1a", None)) self.dataColEndText.setText( QCoreApplication.translate( "TransformDialog1", u"\u6570\u636e\u96c6\u7ed3\u675f\u5217\u6570\uff1a", None)) self.okButton.setText( QCoreApplication.translate("TransformDialog1", u"\u786e\u8ba4", None))
class WWSlotOut(QGroupBox): """Setup of QGroupBox for output for Winding Slot""" def __init__(self, parent=None): """Initialize the widget""" QGroupBox.__init__(self, parent) # Set main widget self.setTitle(self.tr("Output")) self.setMinimumSize(QSize(200, 0)) self.setObjectName("g_output") self.layout = QVBoxLayout(self) self.layout.setObjectName("layout") # The widget is composed of several QLabel in a vertical layout self.out_Wlam = QLabel(self) self.out_Wlam.setObjectName("out_Wlam") self.layout.addWidget(self.out_Wlam) self.out_slot_height = QLabel(self) self.out_slot_height.setObjectName("out_slot_height") self.layout.addWidget(self.out_slot_height) self.out_yoke_height = QLabel(self) self.out_yoke_height.setObjectName("out_yoke_height") self.layout.addWidget(self.out_yoke_height) self.out_wind_surface = QLabel(self) self.out_wind_surface.setObjectName("out_wind_surface") self.layout.addWidget(self.out_wind_surface) self.out_tot_surface = QLabel(self) self.out_tot_surface.setObjectName("out_tot_surface") self.layout.addWidget(self.out_tot_surface) self.out_op_angle = QLabel(self) self.out_op_angle.setObjectName("out_op_angle") self.layout.addWidget(self.out_op_angle) # self.layout.addWidget(self) def comp_output(self): """Update the Output with the computed values Parameters ---------- self : WWSlotOut A WWSlotOut object """ lam = self.parent().lamination WS_txt = self.tr("Active surface: ") TS_txt = self.tr("Slot surface: ") AO_txt = self.tr("Opening angle: ") SH_txt = self.tr("Slot height: ") YH_txt = self.tr("Yoke height: ") Wlam = format(gui_option.unit.get_m(lam.Rext - lam.Rint), ".4g") self.out_Wlam.setText( self.tr("Lamination width: ") + Wlam + " " + gui_option.unit.get_m_name() ) if self.parent().check(lam) is None: # Compute all the needed output as string w_surf = format( gui_option.unit.get_m2(lam.slot.comp_surface_active()), ".4g" ) tot_surf = format(gui_option.unit.get_m2(lam.slot.comp_surface()), ".4g") op_angle = "%.4g" % lam.slot.comp_angle_opening() slot_height = format(gui_option.unit.get_m(lam.slot.comp_height()), ".4g") yoke_height = format(gui_option.unit.get_m(lam.comp_height_yoke()), ".4g") # Update the GUI to display the Output self.out_wind_surface.setText( WS_txt + w_surf + " " + gui_option.unit.get_m2_name() ) self.out_tot_surface.setText( TS_txt + tot_surf + " " + gui_option.unit.get_m2_name() ) self.out_op_angle.setText(AO_txt + op_angle + u" rad") self.out_slot_height.setText( SH_txt + slot_height + " " + gui_option.unit.get_m_name() ) self.out_yoke_height.setText( YH_txt + yoke_height + " " + gui_option.unit.get_m_name() ) else: # We can't compute the output => We erase the previous version # (that way the user know that something is wrong) self.out_wind_surface.setText(WS_txt + "?") self.out_tot_surface.setText(TS_txt + "?") self.out_op_angle.setText(AO_txt + "?") self.out_slot_height.setText(SH_txt + "?") self.out_yoke_height.setText(YH_txt + "?")
class WBarOut(QGroupBox): """Setup of QGroupBox for output for Winding Slot""" def __init__(self, parent=None): """Initialize the widget""" # Main widget setup QGroupBox.__init__(self, parent) self.u = gui_option.unit self.setTitle(self.tr("Output")) self.setMinimumSize(QSize(200, 0)) self.setObjectName("g_output") self.layout = QVBoxLayout(self) self.layout.setObjectName("layout") # The widget is composed of 3 QLabel in a vertical layout self.out_Sbar = QLabel(self) self.out_Sbar.setObjectName("out_Sbar") self.layout.addWidget(self.out_Sbar) self.out_Sslot = QLabel(self) self.out_Sslot.setObjectName("out_Sslot") self.layout.addWidget(self.out_Sslot) self.out_ratio = QLabel(self) self.out_ratio.setMinimumSize(QSize(140, 0)) self.out_ratio.setObjectName("out_ratio") self.layout.addWidget(self.out_ratio) def comp_output(self): """Update the Output text with the computed values Parameters ---------- self : WBarOut A WBarOut object """ # For readibility obj = self.parent().machine.rotor.winding.conductor # Update Bar surface if possible txt_Sbar = self.tr("Sbar: ") try: Sbar = format(self.u.get_m2(obj.comp_surface_active()), ".4g") self.out_Sbar.setText(txt_Sbar + Sbar + " " + self.u.get_m2_name()) except Exception: self.out_Sbar.setText(txt_Sbar + "?") # Update Slot surface if possible txt_Sslot = self.tr("Sslot: ") try: Sslot = format( self.u.get_m2(self.parent().machine.rotor.slot.comp_surface()), ".4g") self.out_Sslot.setText(txt_Sslot + Sslot + " " + self.u.get_m2_name()) except Exception: self.out_Sslot.setText(txt_Sslot + " ?") # Update ratio if possible txt_ratio = self.tr("Sbar / Sslot: ") try: ratio = "%.4g" % (float(Sbar) / float(Sslot) * 100) self.out_ratio.setText(txt_ratio + ratio + u" %") except Exception: self.out_ratio.setText(txt_ratio + "?")
class DataBrowserMain(QWidget): sliceUpdated = Signal(int, int, int, int) def __init__(self, parent): super(DataBrowserMain, self).__init__(parent) # data import self.brkraw_obj = self.parent().brkraw_obj self.selectedScan = None self.selectedScanTR = None self.set_viewer_frame() self.set_controller_frame() self.set_gridlayouts() self.set_font() # self.set_palette() # TODO self.set_size() self.set_objectnames() self.set_texts() self.ratio_container = [] self.init_connection() self.inactivate_widgets() # Inactivate during startup def init_connection(self): self.parent().dataSelected.connect( self.selectScanEvent) # run selectScanEvent when data selected self.event_timer = QTimer() self.event_timer.timeout.connect(self.sliceUpdateEvent) # self.sliceUpdated.connect(self.updateImage) self.xaxis_slider.valueChanged.connect(self.xaxis_spinbox.setValue) self.xaxis_spinbox.valueChanged.connect(self.xaxis_slider.setValue) self.yaxis_slider.valueChanged.connect(self.yaxis_spinbox.setValue) self.yaxis_spinbox.valueChanged.connect(self.yaxis_slider.setValue) self.zaxis_slider.valueChanged.connect(self.zaxis_spinbox.setValue) self.zaxis_spinbox.valueChanged.connect(self.zaxis_slider.setValue) self.frame_slider.valueChanged.connect(self.frame_spinbox.setValue) self.frame_spinbox.valueChanged.connect(self.frame_slider.setValue) self.axial_view.pointed.connect(self.axialview_pointing_event) self.sagittal_view.pointed.connect(self.sagittalview_pointing_event) self.coronal_view.pointed.connect(self.coronalview_pointing_event) self.connect_sliders_to_update() def sagittalview_pointing_event(self, pos_x, pos_y, meta): max_x = self.yaxis_slider.maximum() max_y = self.zaxis_slider.maximum() # print(pos_x, pos_y, max_x, max_y) self.yaxis_slider.setValue(int(max_x * pos_x)) self.zaxis_slider.setValue(max_y - int(max_y * pos_y)) # print(int(max_x * pos_x), int(max_y * pos_y)) def axialview_pointing_event(self, pos_x, pos_y, meta): max_x = self.yaxis_slider.maximum() max_y = self.xaxis_slider.maximum() # print(pos_x, pos_y, max_x, max_y) self.yaxis_slider.setValue(int(max_x * pos_x)) self.xaxis_slider.setValue(int(max_y * pos_y)) # print(int(max_x * pos_x), int(max_y * pos_y)) def coronalview_pointing_event(self, pos_x, pos_y, meta): max_x = self.xaxis_slider.maximum() max_y = self.zaxis_slider.maximum() # print(pos_x, pos_y, max_x, max_y) self.xaxis_slider.setValue(int(max_x * pos_x)) self.zaxis_slider.setValue(max_y - int(max_y * pos_y)) # print(int(max_x * pos_x), int(max_y * pos_y)) def sliderChangeEvent(self): self.event_timer.start(10) def sliceUpdateEvent(self): # This will executed only when timer timeout x = self.xaxis_slider.value() y = self.yaxis_slider.value() z = self.zaxis_slider.value() t = self.frame_slider.value() self.sliceUpdated.emit(x, y, z, t) self.event_timer.stop() @staticmethod def slice_data(dataobj, slice_orient, slice_num): if slice_orient == 'axial': sliced_data = dataobj[:, :, slice_num] elif slice_orient == 'sagittal': sliced_data = dataobj[:, slice_num, ::-1] elif slice_orient == 'coronal': sliced_data = dataobj[slice_num, :, ::-1] else: popup_error_dialog(UnexpectedError.message) return None return sliced_data def updateImage(self, x, y, z, frame): if len(self.selectedScan.shape) == 4: dataobj = self.selectedScan[:, :, :, frame] else: dataobj = self.selectedScan[...] data_xy = self.slice_data(dataobj, 'axial', z) data_yz = self.slice_data(dataobj, 'sagittal', x) data_xz = self.slice_data(dataobj, 'coronal', y) ratio_xy, ratio_yz, ratio_xz = self.ratio_container # ratio_xy, ratio_yz, ratio_xz = 1, 1, 1 qm_xy = convert_arr2qpixmap(data_xy, ratio_xy) qm_yz = convert_arr2qpixmap(data_yz, ratio_yz) qm_xz = convert_arr2qpixmap(data_xz, ratio_xz) self.axial_view.setPixmap(qm_xy) self.sagittal_view.setPixmap(qm_yz) self.coronal_view.setPixmap(qm_xz) def selectScanEvent(self, delivery_package: list): """ this event is occurring when a scan selected on scanlist """ self.axial_view.setEnabled(True) self.sagittal_view.setEnabled(True) self.coronal_view.setEnabled(True) self.selectedScan, affine, resol, self.selectedScanTR, is_localizer = delivery_package self.selectedScanTR /= 1000 from slfmri.imgman import reorient_to_ras, determine_slice_plane slice_plane_ref = dict(sagittal=0, coronal=1, axial=2) if is_localizer: img_container = dict() for i, aff in enumerate(affine): size = config.get('ImageViewer', 'size') data = self.selectedScan[..., i] slice_plane = determine_slice_plane(2, aff, resol) ras_data, ras_resol = reorient_to_ras(data[:, :, np.newaxis], aff, resol) slice_axis = slice_plane_ref[slice_plane] ras_data = ras_data.mean(slice_axis) ras_resol = np.delete(ras_resol, slice_axis) qpixmap = convert_arr2qpixmap(ras_data, ras_resol, size) img_container[slice_plane] = qpixmap self.update_axisview(img_container) else: # other than localizer self.init_data(self.selectedScan) matrix_size = np.asarray(self.selectedScan.shape) resol = np.asarray(resol) fov = matrix_size[:3] * resol self.ratio_container = [ fov[0] / fov[1], fov[1] / fov[2], fov[0] / fov[2] ] # reset value init_x, init_y, init_z = (np.asarray(self.selectedScan.shape[:3]) / 2.0).astype(int) init_f = 0 self.disconnect_sliders_to_update() self.xaxis_slider.setValue(init_x) self.yaxis_slider.setValue(init_y) self.zaxis_slider.setValue(init_z) self.frame_slider.setValue(init_f) self.connect_sliders_to_update() self.updateImage(init_x, init_y, init_z, init_f) def connect_sliders_to_update(self): # connect to check slice update self.xaxis_slider.valueChanged.connect(self.sliderChangeEvent) self.yaxis_slider.valueChanged.connect(self.sliderChangeEvent) self.zaxis_slider.valueChanged.connect(self.sliderChangeEvent) self.frame_slider.valueChanged.connect(self.sliderChangeEvent) def disconnect_sliders_to_update(self): # disconnect to check slice update self.xaxis_slider.valueChanged.disconnect(self.sliderChangeEvent) self.yaxis_slider.valueChanged.disconnect(self.sliderChangeEvent) self.zaxis_slider.valueChanged.disconnect(self.sliderChangeEvent) self.frame_slider.valueChanged.disconnect(self.sliderChangeEvent) def init_data(self, dataobj): self.slicecontrol_pane.setEnabled(True) dim = len(dataobj.shape) if dim == 3: size_x, size_y, size_z = dataobj.shape size_frame = None elif dim == 4: size_x, size_y, size_z, size_frame = dataobj.shape else: popup_error_dialog(UnexpectedError.message) return None # init sliders and spinboxes self.xaxis_slider.setRange(0, size_x - 1) self.yaxis_slider.setRange(0, size_y - 1) self.zaxis_slider.setRange(0, size_z - 1) self.xaxis_spinbox.setRange(0, size_x - 1) self.yaxis_spinbox.setRange(0, size_y - 1) self.zaxis_spinbox.setRange(0, size_z - 1) if dim == 3: self.frame_label.setDisabled(True) self.frame_slider.setDisabled(True) self.frame_spinbox.setDisabled(True) else: self.frame_label.setEnabled(True) self.frame_slider.setEnabled(True) self.frame_spinbox.setEnabled(True) self.frame_slider.setRange(0, size_frame - 1) self.frame_spinbox.setRange(0, size_frame - 1) def update_axisview(self, img_container: dict): for view_plane, pixmap in img_container.items(): if view_plane == 'axial': self.axial_view.setPixmap(pixmap) elif view_plane == 'sagittal': self.sagittal_view.setPixmap(pixmap) else: self.coronal_view.setPixmap(pixmap) def inactivate_widgets(self): self.slicecontrol_pane.setDisabled(True) self.graph_frame.setDisabled(True) def set_navigationmode(self): # mouse click will navigate slice. pass def set_drawingmode(self): # roi drawing function pass def mask_data_handler(self): # mask later handler pass def slider_event_related(self): # slider for slicing. pass def set_viewer_frame(self): self.imageframe = QFrame(self) self.axial_view = SliceViewer(self.imageframe) self.axial_view.setDisabled(True) self.sagittal_view = SliceViewer(self.imageframe) self.sagittal_view.setDisabled(True) self.coronal_view = SliceViewer(self.imageframe) self.coronal_view.setDisabled(True) # TODO: Will reactivate these on later version # self.axial_title = QLabel(self.imageframe) # self.coronal_title = QLabel(self.imageframe) # self.sagittal_title = QLabel(self.imageframe) # # self.axialL_label = QLabel(self.imageframe) # self.axialA_label = QLabel(self.imageframe) # self.axialR_label = QLabel(self.imageframe) # self.axialP_label = QLabel(self.imageframe) # # self.sagittalS_label = QLabel(self.imageframe) # self.sagittalA_label = QLabel(self.imageframe) # self.sagittalI_label = QLabel(self.imageframe) # self.sagittalP_label = QLabel(self.imageframe) # # self.coronalL_label = QLabel(self.imageframe) # self.coronalS_label = QLabel(self.imageframe) # self.coronalR_label = QLabel(self.imageframe) # self.coronalI_label = QLabel(self.imageframe) # # self.axial_title.setTextFormat(Qt.MarkdownText) # self.axialL_label.setTextFormat(Qt.MarkdownText) # self.axialA_label.setTextFormat(Qt.MarkdownText) # self.axialR_label.setTextFormat(Qt.MarkdownText) # self.axialP_label.setTextFormat(Qt.MarkdownText) # # self.sagittal_title.setTextFormat(Qt.MarkdownText) # self.sagittalS_label.setTextFormat(Qt.MarkdownText) # self.sagittalA_label.setTextFormat(Qt.MarkdownText) # self.sagittalI_label.setTextFormat(Qt.MarkdownText) # self.sagittalP_label.setTextFormat(Qt.MarkdownText) # # self.coronal_title.setTextFormat(Qt.MarkdownText) # self.coronalL_label.setTextFormat(Qt.MarkdownText) # self.coronalS_label.setTextFormat(Qt.MarkdownText) # self.coronalR_label.setTextFormat(Qt.MarkdownText) # self.coronalI_label.setTextFormat(Qt.MarkdownText) # # self.axial_title.setAlignment(Qt.AlignCenter) # self.axialL_label.setAlignment(Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter) # self.axialA_label.setAlignment(Qt.AlignBottom | Qt.AlignHCenter) # self.axialR_label.setAlignment(Qt.AlignLeading | Qt.AlignLeft | Qt.AlignVCenter) # self.axialP_label.setAlignment(Qt.AlignHCenter | Qt.AlignTop) # # self.sagittal_title.setAlignment(Qt.AlignCenter) # self.sagittalS_label.setAlignment(Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter) # self.sagittalA_label.setAlignment(Qt.AlignBottom | Qt.AlignHCenter) # self.sagittalI_label.setAlignment(Qt.AlignLeading | Qt.AlignLeft | Qt.AlignVCenter) # self.sagittalP_label.setAlignment(Qt.AlignHCenter | Qt.AlignTop) # # self.coronal_title.setAlignment(Qt.AlignCenter) # self.coronalL_label.setAlignment(Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter) # self.coronalS_label.setAlignment(Qt.AlignBottom | Qt.AlignHCenter) # self.coronalR_label.setAlignment(Qt.AlignLeading | Qt.AlignLeft | Qt.AlignVCenter) # self.coronalI_label.setAlignment(Qt.AlignHCenter | Qt.AlignTop) def set_controller_frame(self): self.controller_frame = QFrame(self) self.slicecontrol_pane = QGroupBox(self.controller_frame) self.frame_spinbox = QSpinBox(self.slicecontrol_pane) self.xaxis_label = QLabel(self.slicecontrol_pane) self.yaxis_label = QLabel(self.slicecontrol_pane) self.zaxis_label = QLabel(self.slicecontrol_pane) self.frame_label = QLabel(self.slicecontrol_pane) self.xaxis_slider = QSlider(self.slicecontrol_pane) self.yaxis_slider = QSlider(self.slicecontrol_pane) self.zaxis_slider = QSlider(self.slicecontrol_pane) self.frame_slider = QSlider(self.slicecontrol_pane) self.xaxis_spinbox = QSpinBox(self.slicecontrol_pane) self.yaxis_spinbox = QSpinBox(self.slicecontrol_pane) self.zaxis_spinbox = QSpinBox(self.slicecontrol_pane) self.graph_frame = QFrame(self) self.graph_view = pg.PlotWidget(self.graph_frame) self.graph_view.setBackground('w') # TODO: Will reactivate these on later version # self.graph_view = QGraphicsView(self.graph_frame) # self.graphcontrol_pane = QGroupBox(self.graph_frame) # self.addmask_button = QPushButton(self.graphcontrol_pane) # self.removemask_button = QPushButton(self.graphcontrol_pane) # self.mask_listview = QListView(self.graphcontrol_pane) # self.savepng_button = QPushButton(self.graphcontrol_pane) # self.savecsv_button = QPushButton(self.graphcontrol_pane) self.axial_view.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter) self.sagittal_view.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter) self.coronal_view.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter) self.xaxis_slider.setOrientation(Qt.Horizontal) self.yaxis_slider.setOrientation(Qt.Horizontal) self.zaxis_slider.setOrientation(Qt.Horizontal) self.frame_slider.setOrientation(Qt.Horizontal) self.slicecontrol_pane.setAlignment(Qt.AlignCenter) self.xaxis_label.setAlignment(Qt.AlignCenter) self.yaxis_label.setAlignment(Qt.AlignCenter) self.zaxis_label.setAlignment(Qt.AlignCenter) self.frame_label.setAlignment(Qt.AlignCenter) # TODO: Will reactivate these on later version # self.graphcontrol_pane.setAlignment(Qt.AlignCenter) def set_size(self): size = int(config.get('ImageViewer', 'size')) self.imageframe.setLineWidth(0) self.axial_view.setMinimumSize(QSize(size, size)) self.axial_view.setMaximumSize(QSize(size, size)) self.axial_view.setLineWidth(0) self.sagittal_view.setMinimumSize(QSize(size, size)) self.sagittal_view.setMaximumSize(QSize(size, size)) self.sagittal_view.setLineWidth(0) self.coronal_view.setMinimumSize(QSize(size, size)) self.coronal_view.setMaximumSize(QSize(size, size)) self.coronal_view.setLineWidth(0) # TODO: Will reactivate these on later version # self.axialL_label.setMinimumSize(QSize(20, 0)) # self.axialA_label.setMinimumSize(QSize(0, 20)) # self.axialR_label.setMinimumSize(QSize(20, 0)) # self.axialP_label.setMinimumSize(QSize(0, 20)) # self.sagittalS_label.setMinimumSize(QSize(20, 0)) # self.sagittalA_label.setMinimumSize(QSize(0, 20)) # self.sagittalI_label.setMinimumSize(QSize(20, 0)) # self.sagittalP_label.setMinimumSize(QSize(0, 20)) # self.coronalL_label.setMinimumSize(QSize(20, 0)) # self.coronalS_label.setMinimumSize(QSize(0, 20)) # self.coronalR_label.setMinimumSize(QSize(20, 0)) # self.coronalI_label.setMinimumSize(QSize(0, 20)) self.controller_frame.setMinimumSize(QSize(300, 300)) self.controller_frame.setMaximumSize(QSize(400, 300)) self.graph_frame.setMinimumSize(QSize(0, 300)) self.graph_frame.setMaximumSize(QSize(4000, 4000)) self.graph_view.setMaximumSize(QSize(4000, 600)) # TODO: Will reactivate these on later version # self.graphcontrol_pane.setMinimumSize(QSize(300, 0)) # self.graphcontrol_pane.setMaximumSize(QSize(300, 4000)) # self.addmask_button.setMinimumSize(QSize(30, 0)) # self.addmask_button.setMaximumSize(QSize(30, 4000)) # self.removemask_button.setMinimumSize(QSize(30, 0)) # self.removemask_button.setMaximumSize(QSize(30, 4000)) def set_font(self): self.arial_8 = QFont() self.arial_8.setFamily(u"Arial") self.arial_8.setPointSize(8) self.setFont(self.arial_8) # TODO: Will reactivate these on later version # self.axial_title.setFont(self.arial_8) # self.coronal_title.setFont(self.arial_8) # self.sagittal_title.setFont(self.arial_8) # self.axialL_label.setFont(self.arial_8) # self.axialA_label.setFont(self.arial_8) # self.axialR_label.setFont(self.arial_8) # self.axialP_label.setFont(self.arial_8) # self.sagittalS_label.setFont(self.arial_8) # self.sagittalA_label.setFont(self.arial_8) # self.sagittalI_label.setFont(self.arial_8) # self.sagittalP_label.setFont(self.arial_8) # self.coronalL_label.setFont(self.arial_8) # self.coronalS_label.setFont(self.arial_8) # self.coronalR_label.setFont(self.arial_8) # self.coronalI_label.setFont(self.arial_8) self.slicecontrol_pane.setFont(self.arial_8) # TODO: Will reactivate these on later version # self.xaxis_label.setFont(self.arial_8) # self.yaxis_label.setFont(self.arial_8) # self.zaxis_label.setFont(self.arial_8) # self.frame_label.setFont(self.arial_8) # self.graphcontrol_pane.setFont(self.arial_8) # self.addmask_button.setFont(self.arial_8) # self.removemask_button.setFont(self.arial_8) # self.savepng_button.setFont(self.arial_8) # self.savecsv_button.setFont(self.arial_8) def set_palette(self): # Brush gray_text = QBrush(QColor(171, 171, 171, 255)) gray_text.setStyle(Qt.SolidPattern) black_background = QBrush(QColor(0, 0, 0, 255)) black_background.setStyle(Qt.SolidPattern) self.orientation_label_palette = QPalette() self.orientation_label_palette.setBrush(QPalette.Active, QPalette.WindowText, gray_text) self.orientation_label_palette.setBrush(QPalette.Inactive, QPalette.WindowText, gray_text) self.orientation_label_palette.setBrush(QPalette.Disabled, QPalette.WindowText, gray_text) self.ortho_viewer_palette = QPalette() self.ortho_viewer_palette.setBrush(QPalette.Active, QPalette.Base, black_background) self.ortho_viewer_palette.setBrush(QPalette.Inactive, QPalette.Base, black_background) self.ortho_viewer_palette.setBrush(QPalette.Disabled, QPalette.Base, black_background) self.axialA_label.setPalette(self.orientation_label_palette) self.axialL_label.setPalette(self.orientation_label_palette) self.axialR_label.setPalette(self.orientation_label_palette) self.axialP_label.setPalette(self.orientation_label_palette) self.axial_view.setPalette(self.ortho_viewer_palette) self.sagittalS_label.setPalette(self.orientation_label_palette) self.sagittalA_label.setPalette(self.orientation_label_palette) self.sagittalI_label.setPalette(self.orientation_label_palette) self.sagittalP_label.setPalette(self.orientation_label_palette) self.sagittal_view.setPalette(self.ortho_viewer_palette) self.coronalL_label.setPalette(self.orientation_label_palette) self.coronalS_label.setPalette(self.orientation_label_palette) self.coronalR_label.setPalette(self.orientation_label_palette) self.coronalI_label.setPalette(self.orientation_label_palette) self.coronal_view.setPalette(self.ortho_viewer_palette) def set_gridlayouts(self): self.axial_gridLayout = QGridLayout() self.coronal_gridLayout = QGridLayout() self.sagittal_gridLayout = QGridLayout() self.imagecont_gridLayout = QGridLayout(self.slicecontrol_pane) self.imageframe_gridLayout = QGridLayout(self.imageframe) # self.graphcontrol_gridLayout = QGridLayout(self.graphcontrol_pane) self.verticalLayout = QVBoxLayout(self.controller_frame) self.horizontalLayout = QHBoxLayout(self.graph_frame) self.main_gridLayout = QGridLayout(self) # TODO: Will reactivate these on later version # self.imageframe_gridLayout.addWidget(self.axial_title, 0, 1, 1, 1) # self.imageframe_gridLayout.addWidget(self.coronal_title, 0, 2, 1, 1) # self.imageframe_gridLayout.addWidget(self.sagittal_title, 0, 0, 1, 1) # self.axial_gridLayout.addWidget(self.axialL_label, 1, 0, 1, 1) # self.axial_gridLayout.addWidget(self.axialA_label, 0, 1, 1, 1) # self.axial_gridLayout.addWidget(self.axialR_label, 1, 2, 1, 1) # self.axial_gridLayout.addWidget(self.axialP_label, 2, 1, 1, 1) self.axial_gridLayout.addWidget(self.axial_view, 1, 1, 1, 1) # self.sagittal_gridLayout.addWidget(self.sagittalS_label, 1, 0, 1, 1) # self.sagittal_gridLayout.addWidget(self.sagittalA_label, 0, 1, 1, 1) # self.sagittal_gridLayout.addWidget(self.sagittalI_label, 1, 2, 1, 1) # self.sagittal_gridLayout.addWidget(self.sagittalP_label, 2, 1, 1, 1) self.sagittal_gridLayout.addWidget(self.sagittal_view, 1, 1, 1, 1) # self.coronal_gridLayout.addWidget(self.coronalL_label, 1, 0, 1, 1) # self.coronal_gridLayout.addWidget(self.coronalS_label, 0, 1, 1, 1) # self.coronal_gridLayout.addWidget(self.coronalR_label, 1, 2, 1, 1) # self.coronal_gridLayout.addWidget(self.coronalI_label, 2, 1, 1, 1) self.coronal_gridLayout.addWidget(self.coronal_view, 1, 1, 1, 1) self.imagecont_gridLayout.addWidget(self.xaxis_label, 0, 0, 1, 1) self.imagecont_gridLayout.addWidget(self.xaxis_slider, 0, 1, 1, 1) self.imagecont_gridLayout.addWidget(self.xaxis_spinbox, 0, 2, 1, 1) self.imagecont_gridLayout.addWidget(self.yaxis_label, 1, 0, 1, 1) self.imagecont_gridLayout.addWidget(self.yaxis_slider, 1, 1, 1, 1) self.imagecont_gridLayout.addWidget(self.yaxis_spinbox, 1, 2, 1, 1) self.imagecont_gridLayout.addWidget(self.zaxis_label, 2, 0, 1, 1) self.imagecont_gridLayout.addWidget(self.zaxis_slider, 2, 1, 1, 1) self.imagecont_gridLayout.addWidget(self.zaxis_spinbox, 2, 2, 1, 1) self.imagecont_gridLayout.addWidget(self.frame_label, 3, 0, 1, 1) self.imagecont_gridLayout.addWidget(self.frame_slider, 3, 1, 1, 1) self.imagecont_gridLayout.addWidget(self.frame_spinbox, 3, 2, 1, 1) self.imageframe_gridLayout.addLayout(self.axial_gridLayout, 1, 1, 1, 1) self.imageframe_gridLayout.addLayout(self.coronal_gridLayout, 1, 2, 1, 1) self.imageframe_gridLayout.addLayout(self.sagittal_gridLayout, 1, 0, 1, 1) # self.graphcontrol_gridLayout.addWidget(self.addmask_button, 3, 0, 1, 1) # self.graphcontrol_gridLayout.addWidget(self.removemask_button, 3, 1, 1, 1) # self.graphcontrol_gridLayout.addWidget(self.mask_listview, 0, 0, 1, 5) # self.graphcontrol_gridLayout.addWidget(self.savepng_button, 3, 4, 1, 1) # self.graphcontrol_gridLayout.addWidget(self.savecsv_button, 3, 3, 1, 1) self.verticalLayout.addWidget(self.slicecontrol_pane) self.horizontalLayout.addWidget(self.graph_view) # self.horizontalLayout.addWidget(self.graphcontrol_pane) self.main_gridLayout.addWidget(self.imageframe, 0, 0, 1, 2) self.main_gridLayout.addWidget(self.controller_frame, 1, 0, 1, 1) self.main_gridLayout.addWidget(self.graph_frame, 1, 1, 1, 1) def set_objectnames(self): self.setObjectName(u"data_browser") self.imageframe.setObjectName(u"image_frame") self.axial_gridLayout.setObjectName(u"axial_gridLayout") self.coronal_gridLayout.setObjectName(u"coronal_gridLayout") self.sagittal_gridLayout.setObjectName(u"sagittal_gridLayout") # TODO: Will reactivate these on later version # self.axial_title.setObjectName(u"axial_label") # self.coronal_title.setObjectName(u"coronal_label") # self.sagittal_title.setObjectName(u"sagittal_label") self.axial_view.setObjectName(u"axial_view") self.sagittal_view.setObjectName(u"sagittal_view") self.coronal_view.setObjectName(u"coronal_view") # self.axialL_label.setObjectName(u"axialL_label") # self.axialR_label.setObjectName(u"axialR_label") # self.axialA_label.setObjectName(u"axialA_label") # self.axialP_label.setObjectName(u"axialP_label") # self.sagittalS_label.setObjectName(u"sagittalS_label") # self.sagittalA_label.setObjectName(u"sagittalA_label") # self.sagittalI_label.setObjectName(u"sagittalI_label") # self.sagittalP_label.setObjectName(u"sagittalP_label") # self.coronalL_label.setObjectName(u"coronalL_label") # self.coronalS_label.setObjectName(u"coronalS_label") # self.coronalR_label.setObjectName(u"coronalR_label") # self.coronalI_label.setObjectName(u"coronalI_label") self.controller_frame.setObjectName(u"controller_frame") self.slicecontrol_pane.setObjectName(u"slicecontrol_pane") self.xaxis_label.setObjectName(u"xaxis_label") self.xaxis_slider.setObjectName(u"xaxis_slider") self.xaxis_spinbox.setObjectName(u"xaxis_spinbox") self.yaxis_label.setObjectName(u"yaxis_label") self.yaxis_slider.setObjectName(u"yaxis_slider") self.yaxis_spinbox.setObjectName(u"yaxis_spinbox") self.zaxis_label.setObjectName(u"zaxis_label") self.zaxis_slider.setObjectName(u"zaxis_slider") self.zaxis_spinbox.setObjectName(u"zaxis_spinbox") self.frame_label.setObjectName(u"frame_label") self.frame_slider.setObjectName(u"frame_slider") self.frame_spinbox.setObjectName(u"frame_spinbox") self.graph_frame.setObjectName(u"graph_frame") self.graph_view.setObjectName(u"graph_view") # TODO: Will reactivate these on later version # self.graphcontrol_pane.setObjectName(u"graphcontrol_pane") # self.addmask_button.setObjectName(u"addmask_button") # self.removemask_button.setObjectName(u"removemask_button") # self.mask_listview.setObjectName(u"mask_listview") # self.savepng_button.setObjectName(u"savepng_button") # self.savecsv_button.setObjectName(u"savecsv_button") self.imagecont_gridLayout.setObjectName(u"imagecont_gridLayout") self.imageframe_gridLayout.setObjectName(u"imageframe_gridLayout") # self.graphcontrol_gridLayout.setObjectName(u"graphcontrol_gridLayout") self.verticalLayout.setObjectName(u"verticalLayout") self.horizontalLayout.setObjectName(u"horizontalLayout") self.main_gridLayout.setObjectName(u"main_gridLayout") QMetaObject.connectSlotsByName(self) def set_texts(self): self.setWindowTitle(u"Data Browser") # TODO: Will reactivate these on later version # self.axial_title.setText(u"**Axial**") # self.coronal_title.setText(u"**Coronal**") # self.sagittal_title.setText(u"**Sagittal**") # self.sagittalS_label.setText(u"**S**") # self.sagittalA_label.setText(u"**A**") # self.sagittalI_label.setText(u"**I**") # self.sagittalP_label.setText(u"**P**") # self.axialL_label.setText(u"**L**") # self.axialA_label.setText(u"**A**") # self.axialR_label.setText(u"**R**") # self.axialP_label.setText( u"**P**") # self.coronalL_label.setText(u"**L**") # self.coronalS_label.setText(u"**S**") # self.coronalR_label.setText(u"**R**") # self.coronalI_label.setText(u"**I**") self.slicecontrol_pane.setTitle(u"Slice Control Pane") self.xaxis_label.setText(u"x") self.yaxis_label.setText(u"y") self.zaxis_label.setText(u"z") self.frame_label.setText(u"Frame") # TODO: Will reactivate these on later version # self.graphcontrol_pane.setTitle(u"Graph Control Pane") # self.addmask_button.setText(u"+") # self.removemask_button.setText(u"-") # self.savepng_button.setText(u"toPNG") # self.savecsv_button.setText(u"toCSV") def plot_timecourse(self, x, y): self.graph_frame.setEnabled(True) self.graph_view.clear() pen = pg.mkPen(color=(255, 0, 0)) if x is None: x = [0] y = [y] self.graph_view.plot(x, y, pen=pen, symbol='o') else: self.graph_view.plot(x, y, pen=pen) def get_coord(self): x = self.xaxis_slider.value() y = self.yaxis_slider.value() z = self.zaxis_slider.value() return (x, y, z)
class DBNavigatorWidget(QWidget): """ DBNavigatorWidget will provide a compound widget to display/edit/delete individual rows from tables. """ def __init__(self, parent, db, tablename): super(DBNavigatorWidget, self).__init__(parent) self.db = db self.tablename = tablename self.setupUi(self) self.show() def setupUi(self, DBNavigatorWidget): if DBNavigatorWidget.objectName(): DBNavigatorWidget.setObjectName(u"DBNavigatorWidget") self.verticalLayout = QVBoxLayout(DBNavigatorWidget) self.verticalLayout.setObjectName(u"verticalLayout") self.dbeditWidget = QWidget(DBNavigatorWidget) self.dbeditWidget.setObjectName(u"dbeditWidget") sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.dbeditWidget.sizePolicy().hasHeightForWidth()) self.dbeditWidget.setSizePolicy(sizePolicy) self.verticalLayout.addWidget(self.dbeditWidget) self.horizontalLayout = QHBoxLayout() self.horizontalLayout.setObjectName(u"horizontalLayout") self.horizontalLayout.setSizeConstraint(QLayout.SetMinimumSize) self.btnDBNavFirst = QPushButton(DBNavigatorWidget) self.btnDBNavFirst.setObjectName(u"btnDBNavFirst") self.horizontalLayout.addWidget(self.btnDBNavFirst) self.btnDBNavPrev = QPushButton(DBNavigatorWidget) self.btnDBNavPrev.setObjectName(u"btnDBNavPrev") self.horizontalLayout.addWidget(self.btnDBNavPrev) self.btnDBNavNext = QPushButton(DBNavigatorWidget) self.btnDBNavNext.setObjectName(u"btnDBNavNext") self.horizontalLayout.addWidget(self.btnDBNavNext) self.btnDBNavLast = QPushButton(DBNavigatorWidget) self.btnDBNavLast.setObjectName(u"btnDBNavLast") self.horizontalLayout.addWidget(self.btnDBNavLast) self.btnDBNavAdd = QPushButton(DBNavigatorWidget) self.btnDBNavAdd.setObjectName(u"btnDBNavAdd") self.horizontalLayout.addWidget(self.btnDBNavAdd) self.btnDBNavDelete = QPushButton(DBNavigatorWidget) self.btnDBNavDelete.setObjectName(u"btnDBNavDelete") self.horizontalLayout.addWidget(self.btnDBNavDelete) self.btnDBNavAccept = QPushButton(DBNavigatorWidget) self.btnDBNavAccept.setObjectName(u"btnDBNavAccept") self.horizontalLayout.addWidget(self.btnDBNavAccept) self.verticalLayout.addLayout(self.horizontalLayout) self.retranslateUi(DBNavigatorWidget) self.btnDBNavFirst.clicked.connect(DBNavigatorWidget.DBNavFirst) QMetaObject.connectSlotsByName(DBNavigatorWidget) # setupUi def retranslateUi(self, DBNavigatorWidget): DBNavigatorWidget.setWindowTitle(QCoreApplication.translate("DBNavigatorWidget", u"Form", None)) self.btnDBNavFirst.setText(QCoreApplication.translate("DBNavigatorWidget", u"<<", None)) self.btnDBNavPrev.setText(QCoreApplication.translate("DBNavigatorWidget", u"<", None)) self.btnDBNavNext.setText(QCoreApplication.translate("DBNavigatorWidget", u">", None)) self.btnDBNavLast.setText(QCoreApplication.translate("DBNavigatorWidget", u">>", None)) self.btnDBNavAdd.setText(QCoreApplication.translate("DBNavigatorWidget", u"+", None)) self.btnDBNavDelete.setText(QCoreApplication.translate("DBNavigatorWidget", u"-", None)) self.btnDBNavAccept.setText(QCoreApplication.translate("DBNavigatorWidget", u"Ok", None)) # retranslateUi def DBNavFirst(self): pass def DBNavPrev(self): pass def DBNavLast(self): pass def DBNavNext(self): pass def DBNavNew(self): pass def DBNavDelete(self): pass def DBNavAccept(self): pass
class MainWindow(QMainWindow): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.setObjectName("main_window") self.setEnabled(True) self.resize(608, 248) size_policy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) size_policy.setHorizontalStretch(0) size_policy.setVerticalStretch(0) size_policy.setHeightForWidth(self.sizePolicy().hasHeightForWidth()) self.setSizePolicy(size_policy) self.setAcceptDrops(True) self.setWindowTitle("FileHookPi") self.central_widget = QWidget(self) self.central_widget.setObjectName("central_widget") self.horizontalLayout = QHBoxLayout(self.central_widget) self.horizontalLayout.setObjectName("horizontalLayout") self.text_box = QPlainTextEdit(self.central_widget) self.text_box.setAcceptDrops(False) self.text_box.setReadOnly(True) self.text_box.setObjectName("text_box") self.horizontalLayout.addWidget(self.text_box) self.buttons_vertical_layout = QVBoxLayout() self.buttons_vertical_layout.setObjectName("buttons_vertical_layout") self.open_file_button = QPushButton(self.central_widget) self.open_file_button.setText("Open File") self.open_file_button.setObjectName("open_file_button") self.open_file_button.clicked.connect(self.select_file) self.buttons_vertical_layout.addWidget(self.open_file_button) self.line_counter = QLineEdit(self.central_widget) size_policy = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed) size_policy.setHorizontalStretch(0) size_policy.setVerticalStretch(0) size_policy.setHeightForWidth( self.line_counter.sizePolicy().hasHeightForWidth()) self.line_counter.setSizePolicy(size_policy) self.line_counter.setAcceptDrops(False) self.line_counter.setReadOnly(True) self.line_counter.setObjectName("line_counter") self.buttons_vertical_layout.addWidget(self.line_counter) self.next_line_button = QPushButton(self.central_widget) self.next_line_button.setText("Next Line") self.next_line_button.setObjectName("next_line_button") self.next_line_button.clicked.connect(self.advance_line) self.buttons_vertical_layout.addWidget(self.next_line_button) self.horizontalLayout.addLayout(self.buttons_vertical_layout) self.menuBar().addMenu(FileMenu(self)) self.setCentralWidget(self.central_widget) self.current_file = None self.line_count = 0 def select_file(self, *, advance=True): path, *_ = QFileDialog.getOpenFileName(self, "Open File", filter="Text Files (*.txt)") if not path: return self.open_file(path, advance=advance) def open_file(self, path, *, advance=True): if self.current_file is not None: self.cleanup() self.current_file = open(path, "r", encoding="utf-8") self.setWindowFilePath(path) if advance: self.advance_line() def advance_line(self): if self.current_file is None: return try: line = self.current_file.readline() except Exception as exc: message_box = QMessageBox( parent=self, text=f"Failed to read:\n{type(exc).__name__}: {exc}", icon=QMessageBox.Critical) message_box.setInformativeText("Close the file?") message_box.setStandardButtons(QMessageBox.No | QMessageBox.Yes) message_box.setDefaultButton(QMessageBox.Yes) if message_box.exec_() == QMessageBox.Yes: self.cleanup() return if not line: return self.line_count += 1 self.line_counter.setText(str(self.line_count)) QApplication.clipboard().setText(line.rstrip("\n")) self.text_box.setPlainText(line + self.text_box.toPlainText()) def cleanup(self): if self.current_file is not None: self.current_file.close() self.current_file = None self.text_box.clear() self.line_count = 0 self.line_counter.clear() self.setWindowFilePath("") def dragEnterEvent(self, event): urls = event.mimeData().urls() if urls and os.path.isfile(urls[0].path()): event.accept() def dropEvent(self, event): self.open_file(event.mimeData().urls()[0].path()) def closeEvent(self, event): self.cleanup() event.accept()
class PdfDialog(QDialog): def __init__(self, parent, importers_stringlist): super(PdfDialog, self).__init__(parent) self.resize(320, 240) self.importer_selected = 0 self.verticalLayout = QVBoxLayout(self) self.verticalLayout.setObjectName("verticalLayout") self.formLayout = QFormLayout() self.formLayout.setObjectName("formLayout") self.selected_file_label = QLabel(self) self.selected_file_label.setObjectName("selected_file_label") self.formLayout.setWidget(0, QFormLayout.LabelRole, self.selected_file_label) self.importer_label = QLabel(self) self.importer_label.setObjectName("importer_label") self.formLayout.setWidget(1, QFormLayout.LabelRole, self.importer_label) self.importer_combo_box = QComboBox(self) self.importer_combo_box.setObjectName("importer_combo_box") self.importer_combo_box.addItems(importers_stringlist) def set_importer_selected(x): self.importer_selected = x self.importer_combo_box.currentIndexChanged.connect( set_importer_selected) self.formLayout.setWidget(1, QFormLayout.FieldRole, self.importer_combo_box) self.selected_label = QLabel(self) self.selected_label.setObjectName("selected_label") self.formLayout.setWidget(0, QFormLayout.FieldRole, self.selected_label) self.importer_status = QLabel(self) self.importer_status.setObjectName("importer_status") self.formLayout.setWidget(2, QFormLayout.FieldRole, self.importer_status) self.verticalLayout.addLayout(self.formLayout) self.buttonBox = QDialogButtonBox(self) self.buttonBox.setObjectName("buttonBox") self.buttonBox.setOrientation(Qt.Horizontal) self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok) self.verticalLayout.addWidget(self.buttonBox) self.retranslateUi(self) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) QMetaObject.connectSlotsByName(self) # setupUi def retranslateUi(self, dialog): dialog.setWindowTitle( QCoreApplication.translate("dialog", "Import Character Sheet", None)) self.selected_file_label.setText( QCoreApplication.translate("dialog", "Selected File", None)) self.importer_label.setText( QCoreApplication.translate("dialog", "Importer", None)) self.selected_label.setText( QCoreApplication.translate("dialog", "TextLabel", None)) self.importer_status.setText( QCoreApplication.translate("dialog", "TextLabel", None))