def run(self): """Run method that starts all the real work""" # Create the dialog with elements (after translation) and keep reference # Only create GUI ONCE in callback, so that it will only load when the plugin is started if self.first_start: self.first_start = False self.dlg = ProevenVerzamelingDialog() self.reset_ui() # Initialize QGIS filewidget to select a directory self.dlg.fileWidget.setStorageMode(1) # Signalling the Open button. Here the actual logic behind the plugin starts self.dlg.buttonBox.button(QDialogButtonBox.Ok).clicked.connect( self.read_form) # Signalling the reset button. self.dlg.buttonBox.button( QDialogButtonBox.RestoreDefaults).clicked.connect( self.reset_ui) rx1 = QRegExp(r"^\[\d{1,2}(\.\d{1})?(?:,\d{1,2}(\.\d{1})?)+\]$") vg_validator = QRegExpValidator(rx1) self.dlg.le_vg_sdp.setValidator(vg_validator) self.dlg.le_vg_trx.setValidator(vg_validator) rx2 = QRegExp(r"^[\w\-. ]+$") filename_validator = QRegExpValidator(rx2) self.dlg.le_outputName.setValidator(filename_validator) # show the dialog self.dlg.show()
def __init__(self, iface): """Constructor. :param iface: An interface instance that will be passed to this class which provides the hook by which you can manipulate the QGIS application at run time. :type iface: QgsInterface """ # Save reference to the QGIS interface self.iface = iface # initialize plugin directory self.plugin_dir = os.path.dirname(__file__) self.dlg = ConstIdentificacionDialog(parent=iface.mainWindow()) # initialize locale locale = QSettings().value('locale/userLocale')[0:2] locale_path = os.path.join(self.plugin_dir, 'i18n', 'ConstIdentificacion_{}.qm'.format(locale)) if os.path.exists(locale_path): self.translator = QTranslator() self.translator.load(locale_path) QCoreApplication.installTranslator(self.translator) # Declare instance attributes self.actions = [] self.menu = self.tr(u'&Constancia Identificacion') self.abrePredio5 = False self.directorioAGuardar5 = None self.cve_catastral5 = None self.canvas = iface.mapCanvas() # eventos self.dlg.btnBrowse_4.clicked.connect(self.selectDirectory4) self.dlg.btnGenerar_4.clicked.connect(self.generarDoc4) self.dlg.btnSeleccionar_4.clicked.connect(self.activarSeleccion4) self.dlg.exit_signal.connect(self.closeEvent) self.dlg.fldCveCat_4.textChanged.connect(self.lineEditToUpper4) #validaciones rx = QRegExp("[a-zA-Z0-9]{31}") val = QRegExpValidator(rx) self.dlg.fldCveCat_4.setValidator(val) rx = QRegExp("[a-zA-ZÀ-ÿ ]{255}") val = QRegExpValidator(rx) self.dlg.fldNomSolic.setValidator(val) self.onlyInt = QIntValidator() self.dlg.fldNumSolucitud.setValidator(self.onlyInt) self.dlg.dateEdit_2.setDate(QDate.currentDate())
def __init__(self, triplestoreconf, prefixes, prefixstore, comboBox): super(QDialog, self).__init__() self.setupUi(self) self.triplestoreconf = triplestoreconf self.prefixstore = prefixstore self.comboBox = comboBox self.prefixes = prefixes for item in triplestoreconf: self.tripleStoreChooser.addItem(item["name"]) self.tripleStoreChooser.currentIndexChanged.connect( self.loadTripleStoreConfig) #self.addTripleStoreButton.clicked.connect(self.addNewSPARQLEndpoint) urlregex = QRegExp( "http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+" ) urlvalidator = QRegExpValidator(urlregex, self) self.tripleStoreEdit.setValidator(urlvalidator) self.tripleStoreEdit.textChanged.connect(self.check_state1) self.tripleStoreEdit.textChanged.emit(self.tripleStoreEdit.text()) self.epsgEdit.setValidator(QIntValidator(1, 100000)) prefixregex = QRegExp("[a-z]+") prefixvalidator = QRegExpValidator(prefixregex, self) self.tripleStorePrefixNameEdit.setValidator(prefixvalidator) self.addPrefixButton.clicked.connect(self.addPrefixToList) self.removePrefixButton.clicked.connect(self.removePrefixFromList) self.testConnectButton.clicked.connect(self.testTripleStoreConnection) self.deleteTripleStore.clicked.connect(self.deleteTripleStoreFunc) self.resetConfiguration.clicked.connect(self.restoreFactory) self.newTripleStore.clicked.connect(self.createNewTripleStore) #self.exampleQuery.textChanged.connect(self.validateSPARQL) self.sparqlhighlighter = SPARQLHighlighter(self.exampleQuery) self.tripleStorePrefixEdit.setValidator(urlvalidator) self.tripleStorePrefixEdit.textChanged.connect(self.check_state2) self.tripleStorePrefixEdit.textChanged.emit( self.tripleStorePrefixEdit.text()) self.tripleStoreApplyButton.clicked.connect( self.applyCustomSPARQLEndPoint) self.tripleStoreCloseButton.clicked.connect( self.closeTripleStoreDialog) self.detectConfiguration.clicked.connect( self.detectTripleStoreConfiguration) s = QSettings() #getting proxy from qgis options settings self.proxyEnabled = s.value("proxy/proxyEnabled") self.proxyType = s.value("proxy/proxyType") self.proxyHost = s.value("proxy/proxyHost") self.proxyPort = s.value("proxy/proxyPort") self.proxyUser = s.value("proxy/proxyUser") self.proxyPassword = s.value("proxy/proxyPassword")
def __init__(self): """Constructor for the dialog. """ QDialog.__init__(self) self.setupUi(self) self.btnsave = self.buttonBox.button(QDialogButtonBox.Save) self.saveCtrl() re = QRegExp('[0-9.]+') val = QRegExpValidator(re) self.lineEdit_longitude.setValidator(val) self.lineEdit_2_latitude.setValidator(val) self.toolButton.setToolTip('Degree - decimal conversion') self.toolButton.clicked.connect(self.trafo) self.lineEdit_3.textChanged.connect(self.saveCtrl) self.lineEdit_5.textChanged.connect(self.saveCtrl) self.comboBox.currentIndexChanged.connect(self.saveCtrl) self.funcs = VetEpiGISFuncs()
def clicked_event(self): # Create the dialog self.dlg_manager = EpaManager() load_settings(self.dlg_manager) # Manage widgets reg_exp = QRegExp("^[A-Za-z0-9_]{1,16}$") self.dlg_manager.txt_result_id.setValidator(QRegExpValidator(reg_exp)) # Fill combo box and table view self.fill_combo_result_id() self.dlg_manager.tbl_rpt_cat_result.setSelectionBehavior( QAbstractItemView.SelectRows) fill_table(self.dlg_manager.tbl_rpt_cat_result, 'v_ui_rpt_cat_result') set_table_columns(self.dlg_manager, self.dlg_manager.tbl_rpt_cat_result, 'v_ui_rpt_cat_result') # Set signals self.dlg_manager.btn_delete.clicked.connect( partial(multi_rows_delete, self.dlg_manager.tbl_rpt_cat_result, 'rpt_cat_result', 'result_id')) self.dlg_manager.btn_close.clicked.connect( partial(close_dialog, self.dlg_manager)) self.dlg_manager.rejected.connect( partial(close_dialog, self.dlg_manager)) self.dlg_manager.txt_result_id.editTextChanged.connect( self.filter_by_result_id) # Open form open_dialog(self.dlg_manager, dlg_name='go2epa_manager')
def set_regexp_date_validator(widget, button=None, regex_type=1): """ Set QRegExpression in order to validate QLineEdit(widget) field type date. Also allow to enable or disable a QPushButton(button), like typical accept button @Type=1 (yyy-mm-dd), @Type=2 (dd-mm-yyyy) """ placeholder = "yyyy-mm-dd" if regex_type == 1: widget.setPlaceholderText("yyyy-mm-dd") placeholder = "yyyy-mm-dd" reg_exp = QRegExp( "(((\d{4})([-])(0[13578]|10|12)([-])(0[1-9]|[12][0-9]|3[01]))|" "((\d{4})([-])(0[469]|11)([-])([0][1-9]|[12][0-9]|30))|" "((\d{4})([-])(02)([-])(0[1-9]|1[0-9]|2[0-8]))|" "(([02468][048]00)([-])(02)([-])(29))|" "(([13579][26]00)([-])(02)([-])(29))|" "(([0-9][0-9][0][48])([-])(02)([-])(29))|" "(([0-9][0-9][2468][048])([-])(02)([-])(29))|" "(([0-9][0-9][13579][26])([-])(02)([-])(29)))") elif regex_type == 2: widget.setPlaceholderText("dd-mm-yyyy") placeholder = "dd-mm-yyyy" reg_exp = QRegExp( "(((0[1-9]|[12][0-9]|3[01])([-])(0[13578]|10|12)([-])(\d{4}))|" "(([0][1-9]|[12][0-9]|30)([-])(0[469]|11)([-])(\d{4}))|" "((0[1-9]|1[0-9]|2[0-8])([-])(02)([-])(\d{4}))|" "((29)(-)(02)([-])([02468][048]00))|" "((29)([-])(02)([-])([13579][26]00))|" "((29)([-])(02)([-])([0-9][0-9][0][48]))|" "((29)([-])(02)([-])([0-9][0-9][2468][048]))|" "((29)([-])(02)([-])([0-9][0-9][13579][26])))") widget.setValidator(QRegExpValidator(reg_exp)) widget.textChanged.connect( partial(eval_regex, widget, reg_exp, button, placeholder))
def __init__(self, parent=None): super(LCDefineDegradationWidget, self).__init__(parent) self.setupUi(self) self.classes = [self.tr("Tree-covered"), self.tr("Grassland"), self.tr("Cropland"), self.tr("Wetland"), self.tr("Artificial"), self.tr("Bare land"), self.tr("Water body")] self.deg_def_matrix.setRowCount(len(self.classes)) self.deg_def_matrix.setColumnCount(len(self.classes)) self.deg_def_matrix.setHorizontalHeaderLabels(self.classes) self.deg_def_matrix.setVerticalHeaderLabels(self.classes) self.trans_matrix_default = [0, -1, -1, -1, -1, -1, 0, # Tree-covered 1, 0, 1, -1, -1, -1, 0, # grassland 1, -1, 0, -1, -1, -1, 0, # cropland -1, -1, -1, 0, -1, -1, 0, # wetland 1, 1, 1, 1, 0, 1, 0, # artificial 1, 1, 1, 1, -1, 0, 0, # Other land 0, 0, 0, 0, 0, 0, 0] # water body for row in range(0, self.deg_def_matrix.rowCount()): for col in range(0, self.deg_def_matrix.columnCount()): line_edit = TransMatrixEdit() line_edit.setValidator(QRegExpValidator(QRegExp("[-0+]"))) line_edit.setAlignment(Qt.AlignHCenter) self.deg_def_matrix.setCellWidget(row, col, line_edit) self.trans_matrix_set() # Setup the vertical label for the rows of the table label_lc_baseline_year = VerticalLabel(self) label_lc_baseline_year.setText(QtWidgets.QApplication.translate("DlgCalculateLC", "Land cover in initial year ", None)) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Minimum) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.label_lc_target_year.sizePolicy().hasHeightForWidth()) label_lc_baseline_year.setSizePolicy(sizePolicy) font = QFont() font.setBold(True) font.setWeight(75) label_lc_baseline_year.setFont(font) self.lc_trans_table_layout.addWidget(label_lc_baseline_year, 1, 0, 1, 1, Qt.AlignCenter) self.deg_def_matrix.setStyleSheet('QTableWidget {border: 0px;}') self.deg_def_matrix.horizontalHeader().setStyleSheet('QHeaderView::section {background-color: white;border: 0px;}') self.deg_def_matrix.verticalHeader().setStyleSheet('QHeaderView::section {background-color: white;border: 0px;}') self.deg_def_matrix.horizontalHeader().setResizeMode(QtWidgets.QHeaderView.Stretch) self.deg_def_matrix.verticalHeader().setResizeMode(QtWidgets.QHeaderView.Stretch) self.btn_transmatrix_reset.clicked.connect(self.trans_matrix_set) self.btn_transmatrix_loadfile.clicked.connect(self.trans_matrix_loadfile) self.btn_transmatrix_savefile.clicked.connect(self.trans_matrix_savefile) self.legend_deg.setStyleSheet('QLineEdit {background: #AB2727;} QLineEdit:hover {border: 1px solid gray; background: #AB2727;}') self.legend_imp.setStyleSheet('QLineEdit {background: #45A146;} QLineEdit:hover {border: 1px solid gray; background: #45A146;}') self.legend_stable.setStyleSheet('QLineEdit {background: #FFFFE0;} QLineEdit:hover {border: 1px solid gray; background: #FFFFE0;}')
def __init__(self, column, row, triplestoreconf, prefixes, interlinkOrEnrich, table, propOrClass=False, bothOptions=False, currentprefixes=None, addVocab=None): super(QDialog, self).__init__() self.setupUi(self) self.currentcol = column self.currentrow = row self.table = table self.prefixes = prefixes self.currentprefixes = currentprefixes self.bothOptions = bothOptions self.triplestoreconf = triplestoreconf self.interlinkOrEnrich = interlinkOrEnrich self.addVocab = addVocab if column != 4: self.findConcept.setChecked(True) if column == 4 or (not interlinkOrEnrich and column != 4) or (not interlinkOrEnrich and propOrClass): self.findProperty.setChecked(True) if not bothOptions: self.findProperty.setEnabled(False) self.findConcept.setEnabled(False) self.tripleStoreEdit.setEnabled(False) for triplestore in self.triplestoreconf: if not "File" == triplestore["name"]: self.tripleStoreEdit.addItem(triplestore["name"]) if addVocab != None: for cov in addVocab: self.tripleStoreEdit.addItem(addVocab[cov]["label"]) self.searchButton.clicked.connect(self.getClassesFromLabel) urlregex = QRegExp( "http[s]?://(?:[a-zA-Z#]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+" ) urlvalidator = QRegExpValidator(urlregex, self) self.costumproperty.setValidator(urlvalidator) self.costumproperty.textChanged.connect(self.check_state3) self.costumproperty.textChanged.emit(self.costumproperty.text()) self.costumpropertyButton.clicked.connect(self.applyConceptToColumn2) self.applyButton.clicked.connect(self.applyConceptToColumn) s = QSettings() #getting proxy from qgis options settings self.proxyEnabled = s.value("proxy/proxyEnabled") self.proxyType = s.value("proxy/proxyType") self.proxyHost = s.value("proxy/proxyHost") self.proxyPort = s.value("proxy/proxyPort") self.proxyUser = s.value("proxy/proxyUser") self.proxyPassword = s.value("proxy/proxyPassword") if self.proxyHost != None and self.ProxyPort != None: proxy = urllib.ProxyHandler({'http': proxyHost}) opener = urllib.build_opener(proxy) urllib.install_opener(opener)
def __init__(self, db_connector, uri, type, parent=None): """ Constructor :param db: database connection instance :param type: type of parameter to capture (database or schema) :param parent: parent of dialog """ QDialog.__init__(self, parent) self.type = type self.db_connector = db_connector self.uri = uri self.parent = parent self.setupUi(self) if self.type == 'database': self.message_label.setText( QCoreApplication.translate("GetDBOrSchemaNameDialog", "Enter the name of the database:")) self.parameter_line_edit.setPlaceholderText( QCoreApplication.translate( "GetDBOrSchemaNameDialog", "[Name of the database to be created]")) else: self.message_label.setText( QCoreApplication.translate("GetDBOrSchemaNameDialog", "Enter the name of the schema:")) self.parameter_line_edit.setPlaceholderText( QCoreApplication.translate( "GetDBOrSchemaNameDialog", "[Name of the schema to be created]")) self.setWindowTitle( QCoreApplication.translate("GetDBOrSchemaNameDialog", "Create {type}").format(type=self.type)) self.validators = Validators() # schema name mustn't have special characters regex = QRegExp("[a-zA-Z0-9_]+") validator = QRegExpValidator(regex) self.parameter_line_edit.setValidator(validator) self.parameter_line_edit.setMaxLength(63) self.parameter_line_edit.textChanged.connect( self.validators.validate_line_edits_lower_case) self.parameter_line_edit.textChanged.emit( self.parameter_line_edit.text()) self.bar = QgsMessageBar() self.bar.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed) self.layout().addWidget(self.bar, 0, 0, Qt.AlignTop) self.buttonBox.accepted.disconnect() self.buttonBox.accepted.connect(self.accepted) self.buttonBox.clear() self.buttonBox.addButton(QDialogButtonBox.Cancel) self.buttonBox.addButton( QCoreApplication.translate("GetDBOrSchemaNameDialog", "Create {type}").format(type=self.type), QDialogButtonBox.AcceptRole)
def __init__(self, settings): super(ConfigDialog, self).__init__(None) self.setupUi(self) SettingDialog.__init__(self, settings) self.settings = settings regex = QRegExp(MUNCODE_REGEX, Qt.CaseInsensitive) self.muncodeValidator = QRegExpValidator(regex) self.kommunefilter.setValidator(self.muncodeValidator)
def __init__(self, iface, parent=None): """ Contructor """ super().__init__(parent) self.setupUi(self) self.parent = parent self.iface = iface # Int Validator self.onlyInt = QIntValidator() self.ln_port.setValidator(self.onlyInt) # IP Validator v = QRegExpValidator(self) rx = QRegExp( "((1{0,1}[0-9]{0,2}|2[0-4]{1,1}[0-9]{1,1}|25[0-5]{1,1})\\.){3,3}(1{0,1}[0-9]{0,2}|2[0-4]{1,1}[0-9]{1,1}|25[0-5]{1,1})" ) v.setRegExp(rx) self.ln_host.setValidator(v)
def validate_text(self, text): """ Validates and updates the entered text if necessary. Spaces are replaced by _ and capital letters are replaced by small. :param text: The text entered :type text: String """ text_edit = self.sender() cursor_position = text_edit.cursorPosition() text_edit.setValidator(None) if len(text) == 0: return locale = (QSettings().value("locale/userLocale") or 'en-US')[0:2] last_character = text[-1:] if locale == 'en': name_regex = QRegExp('^(?=.{0,40}$)[ _a-zA-Z][a-zA-Z0-9_ ]*$') name_validator = QRegExpValidator(name_regex) text_edit.setValidator(name_validator) QApplication.processEvents() state = name_validator.validate(text, text.index(last_character))[0] if state != QValidator.Acceptable: self.show_notification( '"{}" is not allowed at this position.'.format( last_character)) text = text[:-1] # fix caps, underscores, and spaces if last_character.isupper(): text = text.lower() if last_character == ' ': text = text.replace(' ', '_') if len(text) > 1: if text[0] == ' ' or text[0] == '_': text = text[1:] text = text.replace(' ', '_').lower() self.blockSignals(True) text_edit.setText(text) text_edit.setCursorPosition(cursor_position) self.blockSignals(False) text_edit.setValidator(None)
def de9imWidget(self): """ Creates a new widget to handle DE-9IM masks as input. :return: (QLineEdit) a line edit with a DE-9IM text validator. """ le = QLineEdit() regex = QRegExp("[FfTt012\*]{9}") le.setValidator(QRegExpValidator(regex, le)) le.setPlaceholderText(self.tr("Type in a DE-9IM as 'T*F0*F21*'...")) return le
def cardinalityWidget(self): """ Retrieves a widget for cardinality setting. :return: (QLineEdit) cardinality widget with its content validation applied. """ le = QLineEdit() regex = QRegExp("[0-9\*]\.\.[0-9\*]") le.setValidator(QRegExpValidator(regex, le)) le.setPlaceholderText("1..*") return le
def __init__(self,triplestoreconf={},maindlg=None,parent=None): """Constructor.""" super(LoadGraphDialog, self).__init__(parent) self.setupUi(self) self.triplestoreconf=triplestoreconf self.dlg=parent self.maindlg=maindlg urlregex = QRegExp("http[s]?://(?:[a-zA-Z#]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+") urlvalidator = QRegExpValidator(urlregex, self) self.graphURIEdit.setValidator(urlvalidator) self.loadFromFileButton.clicked.connect(self.loadFile) self.loadFromURIButton.clicked.connect(self.loadURI)
def init_gui(self): """ Initializes form widgets """ charlen_regex = QRegExp('^[0-9]{1,3}$') charlen_validator = QRegExpValidator(charlen_regex) self.edtCharLen.setValidator(charlen_validator) self.edtCharLen.setText(str(self._max_len)) self.edtCharLen.setFocus() self.edtCharLen.setEnabled(not self.in_db)
def init_gui(self): """Initialize the dialog: Set the current date. Accept only lower characters as project name (= database schema). Fill modules combobox. """ today = QDateTime.currentDateTime() self.dateTimeEdit.setDateTime(today) self.dateTimeEdit.setCalendarPopup(True) # You are only allowed to use lower case characters as project name ( # = database schema). self.lineEditDbSchema.setValidator( QRegExpValidator(QRegExp("^[a-z][a-z0-9_]+"), self.lineEditDbSchema)) # Fill out the modules combobox. try: modules_dir = os.path.join(get_modules_dir()) modules = [] for module_name in get_subdirs(modules_dir): module_file = os.path.join(modules_dir, module_name, 'module.yml') if os.path.isfile(module_file): module = yaml_load_file(module_file) module['dirname'] = module_name modules.append(module) if modules: sorted_modules_list = sorted(modules, key=lambda k: k['displayname']) self.cmbBoxAppModule.clear() for module in sorted_modules_list: self.cmbBoxAppModule.addItem(str(module["displayname"]), module) self.cmbBoxAppModule.insertItem(0, "", None) self.cmbBoxAppModule.setCurrentIndex(0) except Exception as e: message = "Error while parsing the available modules." self.message_bar.pushMessage("VeriSO", tr(message), QgsMessageBar.CRITICAL, duration=0) QgsMessageLog.logMessage(str(e), "VeriSO", QgsMessageLog.CRITICAL) return self.cmbBoxIliModelName.insertItem(0, "", None) return True
def __init__(self): """Constructor for the dialog. """ QDialog.__init__(self) self.setupUi(self) re = QRegExp("""[^|'"]+""") val = QRegExpValidator(re) self.lineEdit.setValidator(val) self.lineEdit.setFocus()
def validate_text(self, text): """ Validates and updates the entered text if necessary. Spaces are replaced by _ and capital letters are replaced by small. :param text: The text entered :type text: String """ text_edit = self.sender() cursor_position = text_edit.cursorPosition() text_edit.setValidator(None) if len(text) == 0: return locale = (QSettings().value("locale/userLocale") or 'en-US')[0:2] name_regex = QRegExp('^(?=.{0,40}$)[ _a-zA-Z][a-zA-Z0-9_ ]*$') name_validator = QRegExpValidator(name_regex) text_edit.setValidator(name_validator) QApplication.processEvents() last_character = text[-1:] state = name_validator.validate(text, text.index(last_character))[0] msg = QApplication.translate('EntityEditor', 'is not allowed at this position.') if state != QValidator.Acceptable: self.show_notification('"{}" {}'.format(last_character, msg)) text = text[:-1] # remove space and underscore at the beginning of the text if len(text) > 1: if text[0] == ' ' or text[0] == '_': text = text[1:] self.blockSignals(True) text_edit.setText(text) text_edit.setCursorPosition(cursor_position) self.blockSignals(False) text_edit.setValidator(None)
def validate_text(self, text): """ Validates and updates the entered text if necessary. :param text: The text entered :type text: String """ text_edit = self.sender() cursor_position = text_edit.cursorPosition() text_edit.setValidator(None) if len(text) == 0: return locale = (QSettings().value("locale/userLocale") or 'en-US')[0:2] if locale == 'en': name_regex = QRegExp('^[ _0-9a-zA-Z][a-zA-Z0-9_/\\-()|.:,; ]*$') name_validator = QRegExpValidator(name_regex) text_edit.setValidator(name_validator) QApplication.processEvents() last_character = text[-1:] state = name_validator.validate(text, text.index(last_character))[0] if state != QValidator.Acceptable: self.show_notification('"{}" is not allowed at this position.'. format(last_character) ) text = text[:-1] if len(text) > 1: if text[0] == ' ' or text[0] == '_': text = text[1:] self.blockSignals(True) text_edit.setText(text) text_edit.setCursorPosition(cursor_position) self.blockSignals(False) text_edit.setValidator(None)
def initGui(self): ''' Set control properties based on the mode ''' # Set 'Create Role' button properties btnCreateRole = self.buttonBox.button(QDialogButtonBox.Ok) btnCreateRole.setText(QApplication.translate("newRoleDlg", "Create Role")) btnCreateRole.clicked.connect(self.acceptdlg) # Set validator for preventing rolename from having whitespace rx = QRegExp("\\S+") rxValidator = QRegExpValidator(rx, self) self.txtRoleName.setValidator(rxValidator) self.txtRoleName.setFocus()
def initGui(self): ''' Set control properties based on the mode ''' # Set the minimum date to current self.dtValidity.setMinimumDate(date.today()) # Set 'Create User' button properties btnCreateUser = self.buttonBox.button(QDialogButtonBox.Ok) btnCreateUser.setText( QApplication.translate("newUserDlg", "Create User")) btnCreateUser.clicked.connect(self.acceptdlg) # Set validator for preventing username from having whitespace rx = QRegExp("\\S+") rxValidator = QRegExpValidator(rx, self) self.txtUserName.setValidator(rxValidator) # Connect signals self.chkValidity.stateChanged.connect(self.validityChanged) if self.user != None: self.txtUserName.setText(self.user.UserName) self.txtUserName.setEnabled(False) btnCreateUser.setText( QApplication.translate("newUserDlg", "Update User")) self.setWindowTitle( QApplication.translate("newUserDlg", "Update User Account")) self.groupBox.setTitle( QApplication.translate("newUserDlg", "User Account Information")) if self.user.Validity != None: if self.user.Validity == 'infinity': self.chkValidity.setCheckState(Qt.Checked) else: # Try convert the date from string expDate = QDateTime.fromString(self.user.Validity, "yyyy-MM-dd") self.dtValidity.setDate(expDate.date()) self.chkValidity.setCheckState(Qt.Unchecked) else: self.chkValidity.setCheckState(Qt.Checked) self.txtUserName.setFocus()
def __init__(self): """Constructor for the dialog. """ QDialog.__init__(self) self.setupUi(self) # self.model = QSqlQueryModel() self.tablst = [] re = QRegExp('[a-z0-9\_]+') val = QRegExpValidator(re) self.lineEdit.setValidator(val) self.lineEdit.textChanged.connect(self.nameCtrl)
def on_addMappingBtn_clicked(self): lastRow = self.attributeTable.rowCount() self.attributeTable.insertRow(lastRow) combo = QComboBox(self.attributeTable) combo.addItem("String", QVariant.String) combo.addItem("Integer", QVariant.Int) combo.addItem("Real", QVariant.Double) combo.addItem("Date/Time", QVariant.DateTime) self.attributeTable.setCellWidget(lastRow, 1, combo) lineEdit = QLineEdit(self.attributeTable) # exclude id, fid and _xml from allowed field names lineEdit.setValidator(QRegExpValidator(QRegExp("(?!(id|fid|_xml_)).*"))) self.attributeTable.setCellWidget(lastRow, 0, lineEdit) self.attributeTable.setItem(lastRow, 2, QTableWidgetItem())
def _open_workspace_manager(self): """ Open workspace manager """ # Main dialog self.dlg_workspace_manager = GwWorkspaceManagerUi() tools_gw.load_settings(self.dlg_workspace_manager) self._check_workspace() self.filter_name = self.dlg_workspace_manager.findChild( QLineEdit, 'txt_name') reg_exp = QRegExp( '([^"\'\\\\])*' ) # Don't allow " or ' or \ because it breaks the query self.filter_name.setValidator(QRegExpValidator(reg_exp)) # Fill table self.tbl_wrkspcm = self.dlg_workspace_manager.findChild( QTableView, 'tbl_wrkspcm') self._fill_tbl() # Disable tab log tools_gw.disable_tab_log(self.dlg_workspace_manager) # Connect main dialog signals self.dlg_workspace_manager.txt_name.textChanged.connect( partial(self._fill_tbl)) self.dlg_workspace_manager.btn_create.clicked.connect( partial(self._open_create_workspace_dlg)) self.dlg_workspace_manager.btn_current.clicked.connect( partial(self._set_current_workspace)) # btn_reset disabled for now. Must add the button to the ui before uncommenting this next line # self.dlg_workspace_manager.btn_reset.clicked.connect(partial(self._reset_workspace)) selection_model = self.dlg_workspace_manager.tbl_wrkspcm.selectionModel( ) selection_model.selectionChanged.connect(partial(self._fill_info)) self.dlg_workspace_manager.btn_delete.clicked.connect( partial(self._delete_workspace)) self.dlg_workspace_manager.btn_cancel.clicked.connect( partial(tools_gw.close_dialog, self.dlg_workspace_manager)) self.dlg_workspace_manager.rejected.connect( partial(tools_gw.save_settings, self.dlg_workspace_manager)) # Open dialog tools_gw.open_dialog(self.dlg_workspace_manager, 'workspace_manager')
def __init__(self): """Constructor for the dialog. """ QDialog.__init__(self) self.setupUi(self) re = QRegExp('[0-9.]+') val = QRegExpValidator(re) self.lineEdit.setValidator(val) self.lineEdit_2.setValidator(val) self.lineEdit_3.setValidator(val) self.lineEdit_4.setValidator(val) self.lineEdit_5.setValidator(val) self.lineEdit_6.setValidator(val)
def init_gui(self): self.lineEditDbPort.setValidator( QRegExpValidator(QRegExp("[0-9]+"), self.lineEditDbPort)) self.lineEditProjectsDatabase.setText( self.settings.value("options/general/projects_database")) self.lineEditProjectsRootDir.setText( self.settings.value("options/general/projects_root_directory")) self.lineEditImportJar.setText( self.settings.value("options/import/jar")) vm_arguments = self.settings.value("options/import/vm_arguments") if vm_arguments == "" or not vm_arguments or vm_arguments is None: self.plainTextEditImportVMArguments.insertPlainText( "-Xms128m -Xmx1024m") else: self.plainTextEditImportVMArguments.insertPlainText(vm_arguments) self.lineEditDbHost.setText(self.settings.value("options/db/host")) self.lineEditDbDatabase.setText(self.settings.value("options/db/name")) self.lineEditDbPort.setText(self.settings.value("options/db/port")) self.lineEditDbUser.setText(self.settings.value("options/db/user")) self.lineEditDbUserPwd.setText(self.settings.value("options/db/pwd")) self.lineEditDbAdmin.setText(self.settings.value("options/db/admin")) self.lineEditDbAdminPwd.setText( self.settings.value("options/db/adminpwd")) default_repo = [ 'http://www.catais.org/models/', 'http://models.geo.admin.ch/' ] self.listWidgetModelRepos.insertItems( 0, self.settings.value("options/model_repositories/repositories", default_repo)) QWidget.setTabOrder(self.lineEditDbHost, self.lineEditDbDatabase) QWidget.setTabOrder(self.lineEditDbDatabase, self.lineEditDbPort) QWidget.setTabOrder(self.lineEditDbPort, self.lineEditDbUser) QWidget.setTabOrder(self.lineEditDbUser, self.lineEditDbUserPwd) QWidget.setTabOrder(self.lineEditDbUserPwd, self.lineEditDbAdmin) QWidget.setTabOrder(self.lineEditDbAdmin, self.lineEditDbAdminPwd)
def __init__(self, ttlstring, triplestoreconf, currentindex): super(QDialog, self).__init__() self.setupUi(self) self.ttlstring = ttlstring urlregex = QRegExp( "http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+" ) urlvalidator = QRegExpValidator(urlregex, self) if "endpoint" in triplestoreconf[currentindex]: self.tripleStoreURLEdit.setText( triplestoreconf[currentindex]["endpoint"]) self.tripleStoreURLEdit.setValidator(urlvalidator) self.tripleStoreURLEdit.textChanged.connect(self.check_state1) self.tripleStoreURLEdit.textChanged.emit( self.tripleStoreURLEdit.text()) endpointurls = [] for item in triplestoreconf: endpointurls.append(item["endpoint"]) self.tripleStoreURLEdit.setCompleter(QCompleter(endpointurls)) self.checkConnectionButton.clicked.connect(self.checkConnection) self.applyButton.clicked.connect(self.addNewLayerToTripleStore)
def _manage_go2epa(self): # Create the dialog self.dlg_manager = GwEpaManagerUi() tools_gw.load_settings(self.dlg_manager) # Manage widgets reg_exp = QRegExp("^[A-Za-z0-9_]{1,16}$") self.dlg_manager.txt_result_id.setValidator(QRegExpValidator(reg_exp)) self.dlg_manager.txt_infolog.setReadOnly(True) # Fill combo box and table view self._fill_combo_result_id() self.dlg_manager.tbl_rpt_cat_result.setSelectionBehavior( QAbstractItemView.SelectRows) message = tools_qt.fill_table(self.dlg_manager.tbl_rpt_cat_result, 'v_ui_rpt_cat_result') if message: tools_qgis.show_warning(message) tools_gw.set_tablemodel_config(self.dlg_manager, self.dlg_manager.tbl_rpt_cat_result, 'v_ui_rpt_cat_result') # Set signals self.dlg_manager.btn_delete.clicked.connect( partial(self._multi_rows_delete, self.dlg_manager.tbl_rpt_cat_result, 'rpt_cat_result', 'result_id')) selection_model = self.dlg_manager.tbl_rpt_cat_result.selectionModel() selection_model.selectionChanged.connect( partial(self._fill_txt_infolog)) self.dlg_manager.btn_close.clicked.connect( partial(tools_gw.close_dialog, self.dlg_manager)) self.dlg_manager.rejected.connect( partial(tools_gw.close_dialog, self.dlg_manager)) self.dlg_manager.txt_result_id.editTextChanged.connect( self._filter_by_result_id) # Open form tools_gw.open_dialog(self.dlg_manager, dlg_name='go2epa_manager')
def _set_mask_tags(self, lineEdit): lineEdit.setValidator(QRegExpValidator(QRegExp("^\\b.*\\b$")))