def buildPoleHeader(self): headerRow = QHBoxLayout() spacerItemA = QSpacerItem(60, 20, QSizePolicy.Fixed, QSizePolicy.Minimum) spacerItemE = QSpacerItem(60, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) headername = QLabel(self.tr('Stuetzenbezeichnung')) headername.setMinimumSize(QSize(180, 30)) headerDist = QLabel(self.tr('Hori.distanz')) headerDist.setMinimumSize(QSize(95, 30)) headerHeight = QLabel(self.tr('Hoehe')) headerHeight.setMinimumSize(QSize(85, 30)) headerRow.addItem(spacerItemA) headerRow.addWidget(headername) headerRow.addWidget(headerDist) headerRow.addWidget(headerHeight) headerRow.addItem(spacerItemE) self.outerLayout.addLayout(headerRow)
def construct_form_param_system(self, row, pos): widget = None for field in row[pos]['fields']: if field['label']: lbl = QLabel() lbl.setObjectName('lbl' + field['widgetname']) lbl.setText(field['label']) lbl.setMinimumSize(160, 0) lbl.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) lbl.setToolTip(field['tooltip']) if field['widgettype'] == 'text' or field[ 'widgettype'] == 'linetext': widget = QLineEdit() widget.setText(field['value']) widget.editingFinished.connect( partial(self.get_values_changed_param_system, widget)) widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) elif field['widgettype'] == 'textarea': widget = QTextEdit() widget.setText(field['value']) widget.editingFinished.connect( partial(self.get_values_changed_param_system, widget)) widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) elif field['widgettype'] == 'combo': widget = QComboBox() self.populate_combo(widget, field) widget.currentIndexChanged.connect( partial(self.get_values_changed_param_system, widget)) widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) elif field['widgettype'] == 'checkbox' or field[ 'widgettype'] == 'check': widget = QCheckBox() if field['value'].lower() == 'true': widget.setChecked(True) elif field['value'].lower() == 'FALSE': widget.setChecked(False) widget.stateChanged.connect( partial(self.get_values_changed_param_system, widget)) widget.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) elif field['widgettype'] == 'datepickertime': widget = QDateEdit() widget.setCalendarPopup(True) date = QDate.fromString(field['value'], 'yyyy/MM/dd') widget.setDate(date) widget.dateChanged.connect( partial(self.get_values_changed_param_system, widget)) widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) elif field['widgettype'] == 'spinbox': widget = QDoubleSpinBox() if 'value' in field and field['value'] is not None: value = float(str(field['value'])) widget.setValue(value) widget.valueChanged.connect( partial(self.get_values_changed_param_system, widget)) widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) else: pass if widget: widget.setObjectName(field['widgetname']) else: pass # Order Widgets if field['layout_id'] == 1: self.order_widgets_system(field, self.basic_form, lbl, widget) elif field['layout_id'] == 2: self.order_widgets_system(field, self.om_form, lbl, widget) elif field['layout_id'] == 3: self.order_widgets_system(field, self.workcat_form, lbl, widget) elif field['layout_id'] == 4: self.order_widgets_system(field, self.mapzones_form, lbl, widget) elif field['layout_id'] == 5: self.order_widgets_system(field, self.cad_form, lbl, widget) elif field['layout_id'] == 6: self.order_widgets_system(field, self.epa_form, lbl, widget) elif field['layout_id'] == 7: self.order_widgets_system(field, self.masterplan_form, lbl, widget) elif field['layout_id'] == 8: self.order_widgets_system(field, self.other_form, lbl, widget) elif field['layout_id'] == 9: self.order_widgets_system(field, self.node_type_form, lbl, widget) elif field['layout_id'] == 10: self.order_widgets_system(field, self.cat_form, lbl, widget) elif field['layout_id'] == 11: self.order_widgets_system(field, self.utils_form, lbl, widget) elif field['layout_id'] == 12: self.order_widgets_system(field, self.connec_form, lbl, widget) elif field['layout_id'] == 13: self.order_widgets_system(field, self.topology_form, lbl, widget) elif field['layout_id'] == 14: self.order_widgets_system(field, self.builder_form, lbl, widget) elif field['layout_id'] == 15: self.order_widgets_system(field, self.review_form, lbl, widget) elif field['layout_id'] == 16: self.order_widgets_system(field, self.analysis_form, lbl, widget) elif field['layout_id'] == 17: self.order_widgets_system(field, self.system_form, lbl, widget)
def construct_form_param_system(self, row, pos): widget = None for field in row[pos]['fields']: if field['label']: lbl = QLabel() lbl.setObjectName('lbl' + field['widgetname']) lbl.setText(field['label']) lbl.setMinimumSize(160, 0) lbl.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) lbl.setToolTip(field['tooltip']) if field['widgettype'] == 'text' or field[ 'widgettype'] == 'linetext': widget = QLineEdit() widget.setText(field['value']) widget.editingFinished.connect( partial(self.get_values_changed_param_system, widget)) widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) elif field['widgettype'] == 'textarea': widget = QTextEdit() widget.setText(field['value']) widget.editingFinished.connect( partial(self.get_values_changed_param_system, widget)) widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) elif field['widgettype'] == 'combo': widget = QComboBox() self.populate_combo(widget, field) widget.currentIndexChanged.connect( partial(self.get_values_changed_param_system, widget)) widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) elif field['widgettype'] == 'checkbox' or field[ 'widgettype'] == 'check': widget = QCheckBox() if field['value'] in ('true', 'True', 'TRUE', True): widget.setChecked(True) elif field['value'] in ('false', 'False', 'FALSE', False): widget.setChecked(False) widget.stateChanged.connect( partial(self.get_values_changed_param_system, widget)) widget.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) elif field['widgettype'] == 'datetime': widget = QDateEdit() widget.setCalendarPopup(True) if field['value']: field['value'] = field['value'].replace('/', '-') date = QDate.fromString(field['value'], 'yyyy-MM-dd') widget.setDate(date) widget.dateChanged.connect( partial(self.get_values_changed_param_system, widget)) widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) elif field['widgettype'] == 'spinbox': widget = QSpinBox() if 'value' in field and field['value'] is not None: value = float(str(field['value'])) widget.setValue(value) widget.valueChanged.connect( partial(self.get_values_changed_param_system, widget)) widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) else: pass if widget: widget.setObjectName(field['widgetname']) else: pass # Order Widgets if 'layoutname' in field: if field['layoutname'] == 'lyt_topology': self.order_widgets_system(field, self.topology_form, lbl, widget) elif field['layoutname'] == 'lyt_builder': self.order_widgets_system(field, self.builder_form, lbl, widget) elif field['layoutname'] == 'lyt_review': self.order_widgets_system(field, self.review_form, lbl, widget) elif field['layoutname'] == 'lyt_analysis': self.order_widgets_system(field, self.analysis_form, lbl, widget) elif field['layoutname'] == 'lyt_system': self.order_widgets_system(field, self.system_form, lbl, widget)
def construct_form_param_user(self, row, pos): widget = None for field in row[pos]['fields']: if field['label']: lbl = QLabel() lbl.setObjectName('lbl' + field['widgetname']) lbl.setText(field['label']) lbl.setMinimumSize(160, 0) lbl.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) lbl.setToolTip(field['tooltip']) chk = QCheckBox() chk.setObjectName('chk_' + field['widgetname']) if field['checked'] in ('true', 'True', 'TRUE', True): chk.setChecked(True) elif field['checked'] in ('false', 'False', 'FALSE', False): chk.setChecked(False) chk.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) if field['widgettype'] == 'text' or field[ 'widgettype'] == 'linetext' or field[ 'widgettype'] == 'typeahead': widget = QLineEdit() widget.setText(field['value']) widget.editingFinished.connect( partial(self.get_values_changed_param_user, chk, widget, field)) widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) if field['widgettype'] == 'typeahead': completer = QCompleter() if 'dv_querytext' in field or 'dv_querytext_filterc' in field: widget.setProperty('typeahead', True) model = QStringListModel() widget.textChanged.connect( partial(self.populate_typeahead, completer, model, field, self.dlg_config, widget)) elif field['widgettype'] == 'textarea': widget = QTextEdit() widget.setText(field['value']) widget.editingFinished.connect( partial(self.get_values_changed_param_user, chk, widget, field)) widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) elif field['widgettype'] == 'combo': widget = QComboBox() self.populate_combo(widget, field) widget.currentIndexChanged.connect( partial(self.get_values_changed_param_user, chk, widget, field)) widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) elif field['widgettype'] == 'check': widget = chk widget.stateChanged.connect( partial(self.get_values_changed_param_user, chk, chk, field)) widget.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) elif field['widgettype'] == 'datetime': widget = QgsDateTimeEdit() widget.setAllowNull(True) widget.setCalendarPopup(True) widget.setDisplayFormat('dd/MM/yyyy') if field['value']: field['value'] = field['value'].replace('/', '-') date = QDate.fromString(field['value'], 'yyyy-MM-dd') if date: widget.setDate(date) else: widget.clear() widget.dateChanged.connect( partial(self.get_values_changed_param_user, chk, widget, field)) widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) elif field['widgettype'] == 'spinbox': widget = QDoubleSpinBox() if 'value' in field and field['value'] is not None: value = float(str(field['value'])) widget.setValue(value) widget.valueChanged.connect( partial(self.get_values_changed_param_user, chk, widget, field)) widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) else: pass widget.setObjectName(field['widgetname']) # Set signals chk.stateChanged.connect( partial(self.get_values_checked_param_user, chk, widget, field)) if field['layoutname'] == 'lyt_basic': self.order_widgets(field, self.basic_form, lbl, chk, widget) elif field['layoutname'] == 'lyt_om': self.order_widgets(field, self.om_form, lbl, chk, widget) elif field['layoutname'] == 'lyt_inventory': self.order_widgets(field, self.inventory_form, lbl, chk, widget) elif field['layoutname'] == 'lyt_mapzones': self.order_widgets(field, self.mapzones_form, lbl, chk, widget) elif field['layoutname'] == 'lyt_edit': self.order_widgets(field, self.cad_form, lbl, chk, widget) elif field['layoutname'] == 'lyt_epa': self.order_widgets(field, self.epa_form, lbl, chk, widget) elif field['layoutname'] == 'lyt_masterplan': self.order_widgets(field, self.masterplan_form, lbl, chk, widget) elif field['layoutname'] == 'lyt_other': self.order_widgets(field, self.other_form, lbl, chk, widget) elif field['layoutname'] == 'lyt_node_vdef': self.order_widgets(field, self.node_type_form, lbl, chk, widget) elif field['layoutname'] == 'lyt_arc_vdef': self.order_widgets(field, self.cat_form, lbl, chk, widget) elif field['layoutname'] == 'lyt_utils_vdef': self.order_widgets(field, self.utils_form, lbl, chk, widget) elif field['layoutname'] == 'lyt_connec_vdef': self.order_widgets(field, self.connec_form, lbl, chk, widget) elif field['layoutname'] == 'lyt_gully_vdef': self.order_widgets(field, self.gully_form, lbl, chk, widget) elif field['layoutname'] == 'lyt_fluid_type': self.order_widgets(field, self.fluid_type_form, lbl, chk, widget) elif field['layoutname'] == 'lyt_location_type': self.order_widgets(field, self.location_type_form, lbl, chk, widget) elif field['layoutname'] == 'lyt_category_type': self.order_widgets(field, self.category_type_form, lbl, chk, widget) elif field['layoutname'] == 'lyt_function_type': self.order_widgets(field, self.function_type_form, lbl, chk, widget) elif field['layoutname'] == 'lyt_addfields': self.order_widgets(field, self.addfields_form, lbl, chk, widget)
class TrackingDisplay(QToolBar): ''' Display the position of a mobile and add action for centering the map on the vehicle and erasing the track ''' def __init__(self, mobile, parent=None): super(TrackingDisplay, self).__init__(parent) self.setMovable(True) self.setFloatable(True) self.mobile = mobile self.timedOut = True self.lastFix = 0.0 s = QSettings() self.defFormat = s.value('PosiView/Misc/DefaultFormat', defaultValue=0, type=int) self.format = self.defFormat & 3 self.withSuff = QgsCoordinateFormatter.FlagDegreesUseStringSuffix if bool(self.defFormat & 4) else QgsCoordinateFormatter.FormatFlag(0) self.createActions() self.mobile.newPosition.connect(self.onNewPosition) self.mobile.timeout.connect(self.onTimeout) def createActions(self): self.nameLabel = QLabel(self.mobile.name) self.nameLabel.setMinimumSize(80, 23) self.nameLabelAction = QWidgetAction(self) self.nameLabelAction.setDefaultWidget(self.nameLabel) self.addAction(self.nameLabelAction) self.enableAction = QAction("Enable Display", self) self.enableAction.setCheckable(True) self.enableAction.setChecked(True) icon = QIcon(':/plugins/PosiView/ledgrey.png') icon.addFile(':/plugins/PosiView/ledgreen.png', QSize(), QIcon.Normal, QIcon.On) self.enableAction.setIcon(icon) self.addAction(self.enableAction) self.enableAction.triggered.connect(self.onEnableClicked) self.enableAction.triggered.connect(self.mobile.setEnabled) self.addSeparator() self.posLabel = QLabel("--:--:-- 0.000000 0.000000") self.posLabel.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter) widths = (180, 196, 204, 180, 184, 200, 208, 184) self.posLabel.setMinimumSize(widths[self.format], 23) self.posLabel.setStyleSheet('background: red; font-size: 8pt; color: white;') self.posLabelAction = QWidgetAction(self) self.posLabelAction.setDefaultWidget(self.posLabel) self.addAction(self.posLabelAction) self.centerAction = QAction(QIcon(':/plugins/PosiView/center.png'), "Center &Map", self) self.addAction(self.centerAction) self.deleteTrackAction = QAction(QIcon(':/plugins/PosiView/deletetrack.png'), 'Delete &Track', self) self.addAction(self.deleteTrackAction) self.deleteTrackAction.triggered.connect(self.mobile.deleteTrack) self.centerAction.triggered.connect(self.mobile.centerOnMap) @pyqtSlot(float, QgsPointXY, float, float) def onNewPosition(self, fix, pos, depth, altitude): s = str() if fix > 0: s = strftime('%H:%M:%S ', gmtime(fix)) else: s = '--:--:-- ' if self.format == 0: s += "{:f} {:f}".format(pos.y(), pos.x()) elif self.format == 1: s += ', '.join(QgsCoordinateFormatter.format(pos, QgsCoordinateFormatter.FormatDegreesMinutes, 4, self.withSuff ).rsplit(',')[::-1]) else: s += ', '.join(QgsCoordinateFormatter.format(pos, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, self.withSuff ).rsplit(',')[::-1]) if depth > -9999: s += "\nd = {:.1f}".format(depth) if altitude > -9999: if depth > -9999: s += " alt = {:.1f}".format(altitude) else: s += "\nalt = {:.1f}".format(altitude) self.posLabel.setText(s) if self.timedOut: if fix > self.lastFix: self.posLabel.setStyleSheet('background: lime; font-size: 8pt; color: black;') self.timedOut = False self.lastFix = fix @pyqtSlot() def onTimeout(self): if not self.timedOut: self.timedOut = True self.posLabel.setStyleSheet('background: red; font-size: 8pt; color: white;') @pyqtSlot(bool) def onEnableClicked(self, enable): self.timedOut = True if enable: self.posLabel.setStyleSheet('background: red; font-size: 8pt; color: white;') else: self.posLabel.setStyleSheet('background: white; font-size: 8pt; color: black;') def releaseMobile(self): self.mobile = None
class TrackingDisplay(QToolBar): ''' Display the position of a mobile and add action for centering the map on the vehicle and erasing the track ''' def __init__(self, mobile, parent=None): super(TrackingDisplay, self).__init__(parent) self.setMovable(True) self.setFloatable(True) self.mobile = mobile self.timedOut = True self.lastFix = 0.0 s = QSettings() self.defFormat = s.value('PosiView/Misc/DefaultFormat', defaultValue=0, type=int) self.format = self.defFormat & 3 self.withSuff = cf.FlagDegreesUseStringSuffix if bool( self.defFormat & 4) else cf.FormatFlag(0) try: self.sep = cf.separator() + ' ' except AttributeError: self.sep = ', ' self.createActions() self.mobile.newPosition.connect(self.onNewPosition) self.mobile.timeout.connect(self.onTimeout) self.posText = '0.000000, 0.000000' def createActions(self): self.nameLabel = QLabel(self.mobile.name) self.nameLabel.setMinimumSize(80, 23) self.nameLabelAction = QWidgetAction(self) self.nameLabelAction.setDefaultWidget(self.nameLabel) self.addAction(self.nameLabelAction) self.enableAction = QAction("Enable Display", self) self.enableAction.setCheckable(True) self.enableAction.setChecked(True) icon = QIcon(':/plugins/PosiView/ledgrey.png') icon.addFile(':/plugins/PosiView/ledgreen.png', QSize(), QIcon.Normal, QIcon.On) self.enableAction.setIcon(icon) self.addAction(self.enableAction) self.enableAction.triggered.connect(self.onEnableClicked) self.enableAction.triggered.connect(self.mobile.setEnabled) self.addSeparator() self.posLabel = QLabel("--:--:-- 0.000000, 0.000000") self.posLabel.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter) widths = (180, 196, 204, 180, 184, 200, 208, 184) self.posLabel.setMinimumSize(widths[self.format], 23) self.posLabel.setStyleSheet( 'background: red; font-size: 8pt; color: white;') self.posLabelAction = QWidgetAction(self) self.posLabelAction.setDefaultWidget(self.posLabel) self.addAction(self.posLabelAction) self.centerAction = QAction(QIcon(':/plugins/PosiView/center.png'), "Center &Map", self) self.addAction(self.centerAction) self.deleteTrackAction = QAction( QIcon(':/plugins/PosiView/deletetrack.png'), 'Delete &Track', self) self.addAction(self.deleteTrackAction) self.deleteTrackAction.triggered.connect(self.mobile.deleteTrack) self.centerAction.triggered.connect(self.mobile.centerOnMap) @pyqtSlot(float, QgsPointXY, float, float) def onNewPosition(self, fix, pos, depth, altitude): s = str() if fix > 0: s = strftime('%H:%M:%S ', gmtime(fix)) else: s = '--:--:-- ' if self.format == 1: f, pr = cf.FormatDegreesMinutes, 4 elif self.format == 2: f, pr = cf.FormatDegreesMinutesSeconds, 2 else: f, pr = cf.FormatDecimalDegrees, 6 self.posText = self.sep.join( (cf.formatY(pos.y(), f, pr, self.withSuff), cf.formatX(pos.x(), f, pr, self.withSuff))) s += self.posText if depth > -9999: s += "\nd = {:.1f}".format(depth) if altitude > -9999: if depth > -9999: s += " alt = {:.1f}".format(altitude) else: s += "\nalt = {:.1f}".format(altitude) self.posLabel.setText(s) if self.timedOut: if fix > self.lastFix: self.posLabel.setStyleSheet( 'background: lime; font-size: 8pt; color: black;') self.timedOut = False self.lastFix = fix @pyqtSlot() def onTimeout(self): if not self.timedOut: self.timedOut = True self.posLabel.setStyleSheet( 'background: red; font-size: 8pt; color: white;') @pyqtSlot(bool) def onEnableClicked(self, enable): self.timedOut = True if enable: self.posLabel.setStyleSheet( 'background: red; font-size: 8pt; color: white;') else: self.posLabel.setStyleSheet( 'background: white; font-size: 8pt; color: black;') def mousePressEvent(self, event): if event.button() == Qt.LeftButton: if event.modifiers() == Qt.ControlModifier: QGuiApplication.clipboard().setText(self.posText) else: drag = QDrag(self) mimeData = QMimeData() mimeData.setText(self.posText) drag.setMimeData(mimeData) drag.exec_() def releaseMobile(self): self.mobile = None
class ParamDxf2Rfu(QWidget, gui_dlg_dxf2rfu): send_nw_params = pyqtSignal(dict) def __init__(self, dwg_lyrs, dwg_blocks, typo_nature_som, typo_nature_lim, precision_class, auth_creator, user, parent=None): super(ParamDxf2Rfu, self).__init__(parent) self.setupUi(self) # Initialization of the closing method (False= quit by red cross) self.quit_valid = False self.param_dxf = {} self.valid_btn.clicked.connect(self.butt_ok) # Delete Widget on close event.. # self.setAttribute(Qt.WA_DeleteOnClose, True) # Load the original parameters try: self.params_path = os.path.join(os.path.dirname(__file__), r"import_dxf2rfu_param.json") except IOError as error: raise error with codecs.open(self.params_path, encoding='utf-8', mode='r') as json_file: self.json_params = json.load(json_file) self.old_params = self.json_params[r"dxfparams"] # Manage delim_pub_chk text self.delim_pub_chk.stateChanged.connect(self.settext_delim_pub_chk) # Create sorted list of the names of dwg layers self.dwg_lyrs = dwg_lyrs lyr_names = [] for lyr in self.dwg_lyrs: lyr_names.append(str(lyr.name)) lyr_names.sort() # Create sorted list of the names of blocks self.dwg_blocks = dwg_blocks blk_names = [] for blk_def in self.dwg_blocks: if len(blk_def.name) > 0: if (not blk_def.is_xref) and (not blk_def.is_anonymous) and blk_def.name[0] != '*': blk_names.append(str(blk_def.name)) blk_names.sort() self.typo_nature_som = typo_nature_som self.typo_nature_lim = typo_nature_lim self.precision_class = precision_class self.auth_creator = auth_creator self.user = user # Fill the delim_pub checkbox if "delim_pub" in self.old_params: if self.old_params["delim_pub"] == 'true': self.delim_pub_chk.setChecked(True) else: self.delim_pub_chk.setChecked(False) # Populate createur list creat_param = False for i, e in enumerate(self.auth_creator): self.createur_cmb.addItem("%s (%s)" % (e[1], e[0])) # Find the creator in the params if "createur" in self.old_params: if self.old_params["createur"] == e[0]: self.createur_cmb.setCurrentIndex(i) creat_param = True # Set current user as the creator by default if self.user == e[0] and not creat_param: self.createur_cmb.setCurrentIndex(i) # Populate the precision class list prec_class_dft = None prec_class_curidx = 0 prec_class_dft_exist = False if "prec_class" in self.old_params: prec_class_dft = self.old_params["prec_class"] for (idx, prec_val) in enumerate(self.precision_class): if prec_class_dft == self.precision_class[idx][1]: prec_class_curidx = idx prec_class_dft_exist = True if not prec_class_dft_exist: self.precision_class_cmb.addItem(prec_class_dft) self.precision_class_cmb.setItemData(0, QColor("red"), Qt.TextColorRole) for prec_class in self.precision_class: self.precision_class_cmb.addItem(prec_class[1]) self.precision_class_cmb.setCurrentIndex(prec_class_curidx) # Populate the layer list (for vertices) vtx_lyr_dft = None vtx_curidx = 0 if "vtx_lyr" in self.old_params: vtx_lyr_dft = self.old_params["vtx_lyr"] else: vtx_lyr_dft = "0" if vtx_lyr_dft in lyr_names: vtx_curidx = lyr_names.index(vtx_lyr_dft) else: self.vtx_lyr_cmb.addItem(vtx_lyr_dft) self.vtx_lyr_cmb.setItemData(0, QColor("red"), Qt.TextColorRole) for lyr_name in lyr_names: self.vtx_lyr_cmb.addItem(lyr_name) self.vtx_lyr_cmb.setCurrentIndex(vtx_curidx) # Populate the different types of points for idx, pt_type in enumerate (self.typo_nature_som): self.symb_corr_lab = QLabel(self.pt_type_gpb) sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.symb_corr_lab.sizePolicy().hasHeightForWidth()) self.symb_corr_lab.setSizePolicy(sizePolicy) self.symb_corr_lab.setAlignment(Qt.AlignRight | Qt.AlignVCenter) self.symb_corr_lab.setMinimumSize(QSize(160, 25)) self.symb_corr_lab.setMaximumSize(QSize(160, 25)) self.symb_corr_lab.setObjectName("symb_corr_lab" + str(idx)) self.symb_corr_lab.setText(str(pt_type)) self.corr_grid_lay.addWidget(self.symb_corr_lab, (idx), 0, 1, 1) self.symb_corr_cmb = QComboBox(self.pt_type_gpb) self.symb_corr_cmb.setMinimumSize(QSize(0, 25)) self.symb_corr_cmb.setMaximumSize(QSize(16777215, 25)) self.symb_corr_cmb.setObjectName("symb_corr_cmb" + str(idx)) self.corr_grid_lay.addWidget(self.symb_corr_cmb, (idx), 1, 1, 1) self.cur_cmb = self.findChild(QComboBox, "symb_corr_cmb" + str(idx)) # Manage the background color of the comboboxes self.cur_cmb.currentTextChanged.connect(partial(self.chk_cmb_bkgrd, self.cur_cmb)) # Add specific values (all block and no none block) self.cur_cmb.addItem(no_blk) self.cur_cmb.setItemData(0, QColor(111,111,111), Qt.TextColorRole) self.cur_cmb.addItem(all_blks) self.cur_cmb.setItemData(1, QColor(42,195,124), Qt.TextColorRole) blk_dft = None blk_curidx = 0 # Manage v2.1 new config.json structure if "blk_corrs" in self.old_params: blks_params = self.old_params["blk_corrs"] # Manage old config.json structure else: blks_params = self.old_params # Find the correct param if str(pt_type) in blks_params: blk_dft = blks_params[str(pt_type)] if blk_dft in blk_names : blk_curidx = blk_names.index(blk_dft) + 2 else: if blk_dft == no_blk: blk_curidx = 0 elif blk_dft == all_blks: blk_curidx = 1 else: self.cur_cmb.addItem(blk_dft) blk_curidx = 2 self.cur_cmb.setItemData(2, QColor("red"), Qt.TextColorRole) for blk_name in blk_names: self.cur_cmb.addItem(blk_name) self.cur_cmb.setCurrentIndex(blk_curidx) sp_item1 = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding) self.corr_grid_lay.addItem(sp_item1, (idx + 1), 0, 1, 1) # Adapt the size of the dlg self.pt_type_gpb.setMinimumSize(QSize(470, 56+29*(idx+1))) # Populate the different types of limits for idx, lim_type in enumerate (self.typo_nature_lim): self.lim_corr_lab = QLabel(self.lim_type_gpb) sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.lim_corr_lab.sizePolicy().hasHeightForWidth()) self.lim_corr_lab.setSizePolicy(sizePolicy) self.lim_corr_lab.setAlignment(Qt.AlignRight | Qt.AlignVCenter) self.lim_corr_lab.setMinimumSize(QSize(160, 25)) self.lim_corr_lab.setMaximumSize(QSize(160, 25)) self.lim_corr_lab.setObjectName("lim_corr_lab" + str(idx)) self.lim_corr_lab.setText(str(lim_type)) self.lim_grid_lay.addWidget(self.lim_corr_lab, (idx), 0, 1, 1) self.lim_corr_cmb = QComboBox(self.lim_type_gpb) self.lim_corr_cmb.setMinimumSize(QSize(0, 25)) self.lim_corr_cmb.setMaximumSize(QSize(16777215, 25)) self.lim_corr_cmb.setObjectName("lim_corr_cmb" + str(idx)) self.lim_grid_lay.addWidget(self.lim_corr_cmb, (idx), 1, 1, 1) self.cur_cmb = self.findChild(QComboBox, "lim_corr_cmb" + str(idx)) # Manage the background color of the comboboxes self.cur_cmb.currentTextChanged.connect(partial(self.chk_cmb_bkgrd, self.cur_cmb)) # Add specific value (none layer) self.cur_cmb.addItem(no_lyr) self.cur_cmb.setItemData(0, QColor(111,111,111), Qt.TextColorRole) lyr_dft = None lyr_cur_idx = 0 # Manage v2.1 new config.json structure if "lim_lyrs" in self.old_params: lim_lyrs_params = self.old_params["lim_lyrs"] # Manage old config.json structure else: lim_lyrs_params = self.old_params # Find the correct param if str(lim_type) in lim_lyrs_params: lyr_dft = lim_lyrs_params[str(lim_type)] else: lyr_dft = "0" if lyr_dft in lyr_names: lyr_cur_idx = lyr_names.index(lyr_dft) + 1 else: if lyr_dft == no_lyr: lyr_cur_idx = 0 else: self.cur_cmb.addItem(lyr_dft) lyr_cur_idx = 1 self.cur_cmb.setItemData(1, QColor("red"), Qt.TextColorRole) for lyr_name in lyr_names: self.cur_cmb.addItem(lyr_name) self.cur_cmb.setCurrentIndex(lyr_cur_idx) sp_item2 = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding) self.lim_grid_lay.addItem(sp_item2, (idx + 1), 0, 1, 1) # Adapt the size of the dlg self.lim_type_gpb.setMinimumSize(QSize(470, 56+29*(idx+1))) # Change the text of the delim_pub checkbox def settext_delim_pub_chk(self): if self.delim_pub_chk.isChecked(): self.delim_pub_chk.setText('oui') else: self.delim_pub_chk.setText('non') # Manage the background color of comboboxes # (depends on the color of the current item) # And the all block sate -> only one block combobox with this state def chk_cmb_bkgrd(self, combo): sel_col = "QComboBox QAbstractItemView {selection-background-color: lightgray;}" std_bkg_col = "QComboBox:on {background-color: rgb(240, 240, 240);}" if combo.itemData(combo.currentIndex(), Qt.TextColorRole) == QColor("red"): css = "QComboBox {background-color: rgb(255, 189, 189);}" + sel_col + std_bkg_col combo.setStyleSheet(css) elif combo.itemData(combo.currentIndex(), Qt.TextColorRole) == QColor(42,195,124): css = "QComboBox {background-color: rgb(208, 255, 222);}" + sel_col + std_bkg_col combo.setStyleSheet(css) for idx, pt_type in enumerate(self.typo_nature_som): type_cmb = self.findChild(QComboBox, "symb_corr_cmb" + str(idx)) if type_cmb: if type_cmb != combo: type_cmb.setCurrentText(no_blk) elif combo.itemData(combo.currentIndex(), Qt.TextColorRole) == QColor(111,111,111): css = "QComboBox {background-color: rgb(144, 144, 144);}" + sel_col + std_bkg_col combo.setStyleSheet(css) else: css = "" combo.setStyleSheet(css) # Deactivate the all_blks combobox if another combox is used change = False for idx, pt_type in enumerate(self.typo_nature_som): type_cmb = self.findChild(QComboBox, "symb_corr_cmb" + str(idx)) if type_cmb: if type_cmb.currentText() != all_blks and type_cmb.currentText() != no_blk: change = True if change: for idx, pt_type in enumerate(self.typo_nature_som): type_cmb = self.findChild(QComboBox, "symb_corr_cmb" + str(idx)) if type_cmb: if type_cmb.currentText() == all_blks: type_cmb.setCurrentText(no_blk) # Close the window when clicking on the OK button def butt_ok(self): self.quit_valid = True self.close() # Send the parameters when the windows is quit def closeEvent(self, event): if self.quit_valid: # Save the different parameters self.param_dxf["createur"] = self.createur_cmb.currentText()[-6:-1] self.param_dxf["vtx_lyr"] = self.vtx_lyr_cmb.currentText() self.param_dxf["prec_class"] = self.precision_class_cmb.currentText() # Transform the delim_pub checkbox into the correct value self.param_dxf["delim_pub"] = chkbox_to_truefalse(self.delim_pub_chk) blk_def = {} for idx, pt_type in enumerate(self.typo_nature_som): type_cmb = self.findChild(QComboBox, "symb_corr_cmb" + str(idx)) blk_def[str(pt_type)] = str(type_cmb.currentText()) self.param_dxf["blk_corrs"] = blk_def lim_def = {} for idx, lim_type in enumerate(self.typo_nature_lim): type_cmb = self.findChild(QComboBox, "lim_corr_cmb" + str(idx)) lim_def[str(lim_type)] = str(type_cmb.currentText()) self.param_dxf["lim_lyrs"] = lim_def self.hide() # Update the new parameters in the json file json_params = {} json_params["dxfparams"] = self.param_dxf with codecs.open(self.params_path, encoding='utf-8', mode='w') as json_file: json_file.write(json.dumps(json_params, indent=4, separators=(',', ': '), ensure_ascii=False)) # Send the parameters self.send_nw_params.emit(self.param_dxf) else: # Hide the window self.hide()
def _build_dialog_options(self, row, tab): self.tab = tab for field in row['fields']: try: widget = None self.chk = None if field['label']: lbl = QLabel() lbl.setObjectName('lbl' + field['widgetname']) lbl.setText(field['label']) lbl.setMinimumSize(160, 0) lbl.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) lbl.setToolTip(field['tooltip']) if self.tab == 'user': self.chk = QCheckBox() self.chk.setObjectName('chk_' + field['widgetname']) if field['checked'] in ('true', 'True', 'TRUE', True): self.chk.setChecked(True) elif field['checked'] in ('false', 'False', 'FALSE', False): self.chk.setChecked(False) self.chk.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) if field['widgettype'] in ('text', 'linetext', 'typeahead'): widget = QLineEdit() widget.setText(field['value']) widget.editingFinished.connect( partial(self._get_dialog_changed_values, widget, self.tab, self.chk)) widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) if field['widgettype'] == 'typeahead': completer = QCompleter() if 'dv_querytext' in field: widget.setProperty('typeahead', True) model = QStringListModel() widget.textChanged.connect( partial(self.populate_typeahead, completer, model, field, self.dlg_config, widget)) elif field['widgettype'] == 'textarea': widget = QTextEdit() widget.setText(field['value']) widget.editingFinished.connect( partial(self._get_dialog_changed_values, widget, self.tab, self.chk)) widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) elif field['widgettype'] == 'combo': widget = QComboBox() self._fill_combo(widget, field) widget.currentIndexChanged.connect( partial(self._get_dialog_changed_values, widget, self.tab, self.chk)) widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) elif field['widgettype'] == 'check': self.chk = QCheckBox() self.chk.setObjectName(field['widgetname']) if self.tab == 'user' and field['checked'] in ( 'true', 'True', 'TRUE', True): self.chk.setChecked(True) elif self.tab == 'user' and field['checked'] in ( 'false', 'False', 'FALSE', False): self.chk.setChecked(False) elif field['value'] in ('true', 'True', 'TRUE', True): self.chk.setChecked(True) elif field['value'] in ('false', 'False', 'FALSE', False): self.chk.setChecked(False) self.chk.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) self.chk.stateChanged.connect( partial(self._get_dialog_changed_values, self.chk, self.tab, self.chk)) elif field['widgettype'] == 'datetime': widget = QgsDateTimeEdit() widget.setAllowNull(True) widget.setCalendarPopup(True) widget.setDisplayFormat('dd/MM/yyyy') if global_vars.date_format in ("dd/MM/yyyy", "dd-MM-yyyy", "yyyy/MM/dd", "yyyy-MM-dd"): widget.setDisplayFormat(global_vars.date_format) if field['value']: field['value'] = field['value'].replace('/', '-') date = QDate.fromString(field['value'], 'yyyy-MM-dd') if date: widget.setDate(date) else: widget.clear() widget.valueChanged.connect( partial(self._get_dialog_changed_values, widget, self.tab, self.chk)) widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) elif field['widgettype'] == 'spinbox': widget = QDoubleSpinBox() if 'value' in field and field['value'] is not None: value = float(str(field['value'])) widget.setValue(value) widget.valueChanged.connect( partial(self._get_dialog_changed_values, widget, self.tab, self.chk)) widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) if widget: widget.setObjectName(field['widgetname']) # Set signals if self.tab == 'user' and widget is not None: self.chk.stateChanged.connect( partial(self._get_dialog_changed_values, widget, self.tab, self.chk)) if widget is None: widget = self.chk self._order_widgets(field, lbl, widget) except Exception as e: msg = f"{type(e).__name__} {e}. widgetname='{field['widgetname']}' AND widgettype='{field['widgettype']}'" tools_qgis.show_message(msg, 2)