def _setup_table(self, prechecked_elements, state_list, state_list_enables, partly_disabled, disable_fancy, auto_depresso): self.signalMapper = QtCore.QSignalMapper(self) self.signalMapper.mapped[QWidget].connect(self.previewToggler) self.signalMapper2 = QtCore.QSignalMapper(self) self.signalMapper2.mapped[QWidget].connect(self.elementToggler) self.signalMapper3 = QtCore.QSignalMapper(self) self.signalMapper3.mapped[QWidget].connect(self.emit_right_clicked) self.signalMapper4 = QtCore.QSignalMapper(self) self.signalMapper4.mapped[QWidget].connect(self.focus_on_toggler) self.signalMapper5 = QtCore.QSignalMapper(self) self.signalMapper5.mapped[QWidget].connect(self.focus_off_toggler) self.signalMapper6 = QtCore.QSignalMapper(self) self.signalMapper6.mapped[QWidget].connect(self.emit_triggered) is_checkable = not auto_depresso for i in pt_indexes: pt_button = HoverableButton(i, partly_disabled=partly_disabled, disable_fancy=disable_fancy, is_checkable=is_checkable) pt_button.setMinimumSize(16, 16) pt_button.setMaximumSize(512, 512) if i in prechecked_elements: pt_button.setChecked(True) self.layout().addWidget(pt_button, pt_indexes[i][0], pt_indexes[i][1]) # pt_button.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) pt_button.hoverChanged.connect(self.signalMapper.map) pt_button.toggled.connect(self.signalMapper2.map) pt_button.rightClicked.connect(self.signalMapper3.map) pt_button.gainedFocus.connect(self.signalMapper4.map) pt_button.lostFocus.connect(self.signalMapper5.map) pt_button.pressed.connect(self.signalMapper6.map) self.signalMapper.setMapping(pt_button, pt_button) self.signalMapper2.setMapping(pt_button, pt_button) self.signalMapper3.setMapping(pt_button, pt_button) self.signalMapper4.setMapping(pt_button, pt_button) self.signalMapper5.setMapping(pt_button, pt_button) self.signalMapper6.setMapping(pt_button, pt_button) line = QFrame() line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) line.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) self.layout().addWidget(line, 6, 3, 1, 15) # dissable elements/buttons for provided list: if state_list_enables: disabled_elements = set(pt_indexes).difference(state_list) else: disabled_elements = state_list for i in disabled_elements: self.getButton(pt_indexes[i]).setEnabled(False) lant_text = QLabel('Lan') act_text = QLabel('Act') lant_text.setAlignment(QtCore.Qt.AlignCenter) act_text.setAlignment(QtCore.Qt.AlignCenter) self.layout().addWidget(lant_text, 5, 2) self.layout().addWidget(act_text, 6, 2) lant_text.setEnabled(False) act_text.setEnabled(False)
def update_history_view(self): """Update the history view.""" historic_folder = query_historic() files = os.listdir(historic_folder) self.dialog.list_historic.clear() for file in files[::-1]: file_path = join(historic_folder, file) with open(file_path, encoding='utf8') as json_file: data = json.load(json_file, object_hook=as_enum) name = data['file_name'] item = QListWidgetItem(self.dialog.list_historic) self.dialog.list_historic.addItem(item) group = QFrame() group.setFrameStyle(QFrame.StyledPanel) group.setStyleSheet('QFrame { margin: 3px; }') group.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) hbox = QHBoxLayout() vbox = QVBoxLayout() label_name = QLabel(name) label_name.setStyleSheet('font-weight: bold;') label_name.setWordWrap(True) vbox.addWidget(label_name) for label in data['description']: if not label: label = tr('No description') real_label = QLabel(label) real_label.setWordWrap(True) vbox.addWidget(real_label) hbox.addItem(vbox) button_run = QPushButton() button_save = QPushButton() button_run.setIcon(QIcon(QgsApplication.iconPath("mActionStart.svg"))) button_save.setIcon(QIcon(QgsApplication.iconPath("mActionFileSave.svg"))) button_run.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) button_save.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) button_run.setToolTip(tr('Run the query')) button_save.setToolTip(tr('Save this query in a new preset')) hbox.addWidget(button_run) hbox.addWidget(button_save) group.setLayout(hbox) # Actions on click run = partial(self.run_saved_query, data) button_run.clicked.connect(run) save = partial(self.save_history_preset, data) button_save.clicked.connect(save) item.setSizeHint(group.minimumSizeHint()) self.dialog.list_historic.setItemWidget(item, group)
def setup_default_preset(self): """Setup the display of presets""" preset_folder = resources_path('map_preset') folders = os.listdir(preset_folder) for folder_name in folders: file_path = join(preset_folder, folder_name, folder_name + '.json') with open(file_path, encoding='utf8') as json_file: data = json.load(json_file, object_hook=as_enum) item = QListWidgetItem(self.dialog.list_default_mp) item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsUserCheckable | Qt.ItemIsEnabled) self.dialog.list_default_mp.addItem(item) widget = QFrame() widget.setFrameStyle(QFrame.StyledPanel) widget.setStyleSheet('QFrame { margin: 3px; };') widget.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) hbox = QHBoxLayout() vbox = QVBoxLayout() picture = QLabel() icon_path = resources_path('map_preset', folder_name, folder_name + '_icon.png') if not os.path.isfile(icon_path): icon_path = resources_path('icons', 'QuickOSM.svg') icon = QPixmap(icon_path) icon.scaled(QSize(150, 250), Qt.KeepAspectRatio) picture.setPixmap(icon) picture.setStyleSheet( 'max-height: 150px; max-width: 250px; margin-right: 50px;') hbox.addWidget(picture) title = QLabel(data['file_name']) title.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) title.setStyleSheet('font: bold 20px; margin-bottom: 25px;') vbox.addWidget(title) for label in data['description']: if not label: label = tr('No description') real_label = QLabel(label) real_label.setWordWrap(True) vbox.addWidget(real_label) hbox.addItem(vbox) widget.setLayout(hbox) item.setSizeHint(widget.minimumSizeHint()) self.dialog.list_default_mp.setItemWidget(item, widget)
def _create_bar(self): for i in range(len(self.steps)): self.widgets[i] = [] if i != 0: line = QFrame() line.setFrameShape(QFrame.HLine) line.setLineWidth(3) line.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) line.setFixedHeight(self.bar_height) self.layout_bar.addWidget(line) self.widgets[i].append(line) dot = QLabel("•") dot.font_size = self.bar_height * 2.6 dot.setFixedWidth(self.dot_width) dot.setFixedHeight(self.bar_height) dot.setAlignment(Qt.AlignCenter) self.layout_bar.addWidget(dot) self.widgets[i].append(dot)
class Ui_DistroMap(object): def setupUi(self, DistroMap): DistroMap.setObjectName("DistroMap") DistroMap.resize(439, 657) self.gridLayout_3 = QGridLayout(DistroMap) self.gridLayout_3.setObjectName("gridLayout_3") self.scrollArea = QScrollArea(DistroMap) self.scrollArea.setWidgetResizable(True) self.scrollArea.setObjectName("scrollArea") self.scrollAreaWidgetContents = QWidget() self.scrollAreaWidgetContents.setGeometry(QRect(0, 0, 419, 573)) self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents") self.gridLayout_6 = QGridLayout(self.scrollAreaWidgetContents) self.gridLayout_6.setObjectName("gridLayout_6") self.verticalLayout = QVBoxLayout() self.verticalLayout.setObjectName("verticalLayout") self.label_5 = QLabel(self.scrollAreaWidgetContents) self.label_5.setObjectName("label_5") self.verticalLayout.addWidget(self.label_5) self.comboLocalities = QComboBox(self.scrollAreaWidgetContents) self.comboLocalities.setObjectName("comboLocalities") self.verticalLayout.addWidget(self.comboLocalities) self.gridLayout_6.addLayout(self.verticalLayout, 1, 0, 1, 1) self.horizontalLayout_6 = QHBoxLayout() self.horizontalLayout_6.setObjectName("horizontalLayout_6") self.verticalLayout_13 = QVBoxLayout() self.verticalLayout_13.setObjectName("verticalLayout_13") self.label_19 = QLabel(self.scrollAreaWidgetContents) self.label_19.setObjectName("label_19") self.verticalLayout_13.addWidget(self.label_19) self.horizontalLayout_3 = QHBoxLayout() self.horizontalLayout_3.setObjectName("horizontalLayout_3") self.spnOutWidth = QSpinBox(self.scrollAreaWidgetContents) self.spnOutWidth.setMaximum(999999) self.spnOutWidth.setProperty("value", 325) self.spnOutWidth.setObjectName("spnOutWidth") self.horizontalLayout_3.addWidget(self.spnOutWidth) self.label_20 = QLabel(self.scrollAreaWidgetContents) self.label_20.setAlignment(Qt.AlignCenter) self.label_20.setObjectName("label_20") self.horizontalLayout_3.addWidget(self.label_20) self.spnOutHeight = QSpinBox(self.scrollAreaWidgetContents) self.spnOutHeight.setMaximum(999999) self.spnOutHeight.setProperty("value", 299) self.spnOutHeight.setObjectName("spnOutHeight") self.horizontalLayout_3.addWidget(self.spnOutHeight) self.verticalLayout_13.addLayout(self.horizontalLayout_3) self.horizontalLayout_6.addLayout(self.verticalLayout_13) self.horizontalLayout_5 = QHBoxLayout() self.horizontalLayout_5.setObjectName("horizontalLayout_5") self.verticalLayout_14 = QVBoxLayout() self.verticalLayout_14.setObjectName("verticalLayout_14") self.label_21 = QLabel(self.scrollAreaWidgetContents) sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.label_21.sizePolicy().hasHeightForWidth()) self.label_21.setSizePolicy(sizePolicy) self.label_21.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter) self.label_21.setObjectName("label_21") self.verticalLayout_14.addWidget(self.label_21) self.horizontalLayout_4 = QHBoxLayout() self.horizontalLayout_4.setObjectName("horizontalLayout_4") spacerItem = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout_4.addItem(spacerItem) self.btnColour = QPushButton(self.scrollAreaWidgetContents) sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.btnColour.sizePolicy().hasHeightForWidth()) self.btnColour.setSizePolicy(sizePolicy) self.btnColour.setObjectName("btnColour") self.horizontalLayout_4.addWidget(self.btnColour) self.verticalLayout_14.addLayout(self.horizontalLayout_4) self.horizontalLayout_5.addLayout(self.verticalLayout_14) self.frmColour = QFrame(self.scrollAreaWidgetContents) sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.frmColour.sizePolicy().hasHeightForWidth()) self.frmColour.setSizePolicy(sizePolicy) self.frmColour.setMinimumSize(QSize(45, 45)) self.frmColour.setSizeIncrement(QSize(1, 1)) self.frmColour.setBaseSize(QSize(0, 0)) self.frmColour.setFrameShape(QFrame.StyledPanel) self.frmColour.setFrameShadow(QFrame.Raised) self.frmColour.setObjectName("frmColour") self.horizontalLayout_5.addWidget(self.frmColour) self.horizontalLayout_6.addLayout(self.horizontalLayout_5) self.gridLayout_6.addLayout(self.horizontalLayout_6, 4, 0, 1, 1) self.verticalLayout_2 = QVBoxLayout() self.verticalLayout_2.setObjectName("verticalLayout_2") self.label_6 = QLabel(self.scrollAreaWidgetContents) self.label_6.setObjectName("label_6") self.verticalLayout_2.addWidget(self.label_6) self.comboTaxonField = QComboBox(self.scrollAreaWidgetContents) self.comboTaxonField.setObjectName("comboTaxonField") self.verticalLayout_2.addWidget(self.comboTaxonField) self.gridLayout_6.addLayout(self.verticalLayout_2, 2, 0, 1, 1) self.verticalLayout_5 = QVBoxLayout() self.verticalLayout_5.setObjectName("verticalLayout_5") self.label_9 = QLabel(self.scrollAreaWidgetContents) self.label_9.setObjectName("label_9") self.verticalLayout_5.addWidget(self.label_9) self.horizontalLayout = QHBoxLayout() self.horizontalLayout.setObjectName("horizontalLayout") self.leOutDir = QLineEdit(self.scrollAreaWidgetContents) self.leOutDir.setPlaceholderText("") self.leOutDir.setObjectName("leOutDir") self.horizontalLayout.addWidget(self.leOutDir) self.btnBrowse = QPushButton(self.scrollAreaWidgetContents) self.btnBrowse.setObjectName("btnBrowse") self.horizontalLayout.addWidget(self.btnBrowse) self.verticalLayout_5.addLayout(self.horizontalLayout) self.gridLayout_6.addLayout(self.verticalLayout_5, 5, 0, 1, 1) self.verticalLayout_6 = QVBoxLayout() self.verticalLayout_6.setObjectName("verticalLayout_6") self.label = QLabel(self.scrollAreaWidgetContents) self.label.setObjectName("label") self.verticalLayout_6.addWidget(self.label) self.gridLayout = QGridLayout() self.gridLayout.setObjectName("gridLayout") self.label_2 = QLabel(self.scrollAreaWidgetContents) self.label_2.setObjectName("label_2") self.gridLayout.addWidget(self.label_2, 0, 0, 1, 1) self.comboSecondary = QComboBox(self.scrollAreaWidgetContents) self.comboSecondary.setObjectName("comboSecondary") self.gridLayout.addWidget(self.comboSecondary, 1, 1, 1, 1) self.comboSurface = QComboBox(self.scrollAreaWidgetContents) self.comboSurface.setObjectName("comboSurface") self.gridLayout.addWidget(self.comboSurface, 2, 1, 1, 1) self.label_3 = QLabel(self.scrollAreaWidgetContents) self.label_3.setObjectName("label_3") self.gridLayout.addWidget(self.label_3, 1, 0, 1, 1) self.label_4 = QLabel(self.scrollAreaWidgetContents) self.label_4.setObjectName("label_4") self.gridLayout.addWidget(self.label_4, 2, 0, 1, 1) self.comboBase = QComboBox(self.scrollAreaWidgetContents) self.comboBase.setObjectName("comboBase") self.gridLayout.addWidget(self.comboBase, 0, 1, 1, 1) self.gridLayout.setColumnStretch(0, 1) self.gridLayout.setColumnStretch(1, 3) self.verticalLayout_6.addLayout(self.gridLayout) self.gridLayout_6.addLayout(self.verticalLayout_6, 0, 0, 1, 1) self.verticalLayout_3 = QVBoxLayout() self.verticalLayout_3.setObjectName("verticalLayout_3") self.label_7 = QLabel(self.scrollAreaWidgetContents) self.label_7.setObjectName("label_7") self.verticalLayout_3.addWidget(self.label_7) self.comboGrid = QComboBox(self.scrollAreaWidgetContents) self.comboGrid.setObjectName("comboGrid") self.verticalLayout_3.addWidget(self.comboGrid) self.verticalLayout_4 = QVBoxLayout() self.verticalLayout_4.setObjectName("verticalLayout_4") self.label_8 = QLabel(self.scrollAreaWidgetContents) self.label_8.setObjectName("label_8") self.verticalLayout_4.addWidget(self.label_8) self.gridLayout_2 = QGridLayout() self.gridLayout_2.setObjectName("gridLayout_2") self.leMaxY = QLineEdit(self.scrollAreaWidgetContents) self.leMaxY.setObjectName("leMaxY") self.gridLayout_2.addWidget(self.leMaxY, 0, 1, 1, 1) self.leMinX = QLineEdit(self.scrollAreaWidgetContents) self.leMinX.setObjectName("leMinX") self.gridLayout_2.addWidget(self.leMinX, 1, 0, 1, 1) self.leMaxX = QLineEdit(self.scrollAreaWidgetContents) self.leMaxX.setObjectName("leMaxX") self.gridLayout_2.addWidget(self.leMaxX, 1, 2, 1, 1) self.leMinY = QLineEdit(self.scrollAreaWidgetContents) self.leMinY.setObjectName("leMinY") self.gridLayout_2.addWidget(self.leMinY, 2, 1, 1, 1) self.btnExtent = QPushButton(self.scrollAreaWidgetContents) self.btnExtent.setObjectName("btnExtent") self.gridLayout_2.addWidget(self.btnExtent, 1, 1, 1, 1) self.verticalLayout_4.addLayout(self.gridLayout_2) self.verticalLayout_3.addLayout(self.verticalLayout_4) self.gridLayout_6.addLayout(self.verticalLayout_3, 3, 0, 1, 1) self.scrollArea.setWidget(self.scrollAreaWidgetContents) self.gridLayout_3.addWidget(self.scrollArea, 0, 0, 1, 1) self.buttonBox = QDialogButtonBox(DistroMap) self.buttonBox.setOrientation(Qt.Horizontal) self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Ok) self.buttonBox.setObjectName("buttonBox") self.gridLayout_3.addWidget(self.buttonBox, 2, 0, 1, 1) self.progressBar = QProgressBar(DistroMap) self.progressBar.setProperty("value", 0) self.progressBar.setObjectName("progressBar") self.gridLayout_3.addWidget(self.progressBar, 1, 0, 1, 1) self.retranslateUi(DistroMap) self.buttonBox.rejected.connect(DistroMap.reject) QMetaObject.connectSlotsByName(DistroMap) def retranslateUi(self, DistroMap): DistroMap.setWindowTitle(QApplication.translate("DistroMap", "Distribution Map Generator", None)) self.label_5.setText(QApplication.translate("DistroMap", "Point localities layer", None)) self.label_19.setText(QApplication.translate("DistroMap", "Output resolution", None)) self.label_20.setText(QApplication.translate("DistroMap", "x", None)) self.label_21.setText(QApplication.translate("DistroMap", "Map background", None)) self.btnColour.setText(QApplication.translate("DistroMap", "Change", None)) self.label_6.setText(QApplication.translate("DistroMap", "Taxon identifier field", None)) self.label_9.setText(QApplication.translate("DistroMap", "Output directory", None)) self.btnBrowse.setText(QApplication.translate("DistroMap", "Browse...", None)) self.label.setText(QApplication.translate("DistroMap", "Background layers:", None)) self.label_2.setText(QApplication.translate("DistroMap", "Base", None)) self.label_3.setText(QApplication.translate("DistroMap", "Secondary", None)) self.label_4.setText(QApplication.translate("DistroMap", "Surface", None)) self.label_7.setText(QApplication.translate("DistroMap", "Grid layer", None)) self.label_8.setText(QApplication.translate("DistroMap", "Output extent:", None)) self.leMaxY.setText(QApplication.translate("DistroMap", "-21.00", None)) self.leMinX.setText(QApplication.translate("DistroMap", "14.75", None)) self.leMaxX.setText(QApplication.translate("DistroMap", "34.00", None)) self.leMinY.setText(QApplication.translate("DistroMap", "-36.00", None)) self.btnExtent.setText(QApplication.translate("DistroMap", "Use current", None))
def update_personal_preset_view(self): """Update the presets displayed.""" preset_folder = query_preset() files = filter( lambda folder: os.path.isdir(join(preset_folder, folder)), os.listdir(preset_folder)) self.dialog.list_personal_preset_mp.clear() for file in files: file_path = join(preset_folder, file, file + '.json') with open(file_path, encoding='utf8') as json_file: data = json.load(json_file, object_hook=as_enum) name = data['file_name'] item = QListWidgetItem(self.dialog.list_personal_preset_mp) item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsUserCheckable | Qt.ItemIsEnabled) self.dialog.list_personal_preset_mp.addItem(item) preset = QFrame() preset.setObjectName('FramePreset') preset.setFrameStyle(QFrame.StyledPanel) preset.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) hbox = QHBoxLayout() vbox = QVBoxLayout() label_name = QLabel(name) label_name.setStyleSheet('font-weight: bold;') label_name.setWordWrap(True) vbox.addWidget(label_name) for label in data['description']: if not label: label = tr('No description') real_label = QLabel(label) real_label.setWordWrap(True) vbox.addWidget(real_label) hbox.addItem(vbox) button_edit = QPushButton() button_remove = QPushButton() button_edit.setIcon( QIcon(QgsApplication.iconPath("mActionToggleEditing.svg"))) button_remove.setIcon( QIcon(QgsApplication.iconPath('symbologyRemove.svg'))) button_edit.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) button_remove.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) button_edit.setToolTip(tr('Edit the preset')) button_remove.setToolTip(tr('Delete the preset')) hbox.addWidget(button_edit) hbox.addWidget(button_remove) if data['advanced']: self.listAdvanced.append(True) preset.setStyleSheet('#FramePreset { margin: 3px;' ' border: 3px solid ' + self.advanced_selected + ';' ' border-width: 1px 1px 1px 4px;}') else: self.listAdvanced.append(False) preset.setStyleSheet('#FramePreset { margin: 3px;' ' border: 3px solid ' + self.basic_selected + ';' ' border-width: 1px 1px 1px 4px;}') preset.setLayout(hbox) # Actions on click remove = partial(self.verification_remove_preset, item, name) button_remove.clicked.connect(remove) edit = partial(self.edit_preset, data) button_edit.clicked.connect(edit) item.setSizeHint(preset.minimumSizeHint()) self.dialog.list_personal_preset_mp.setItemWidget(item, preset) self.listAdvanced.append(False)