當前位置: 首頁>>代碼示例>>Python>>正文


Python QLineEdit.hasAcceptableInput方法代碼示例

本文整理匯總了Python中PyQt5.QtWidgets.QLineEdit.hasAcceptableInput方法的典型用法代碼示例。如果您正苦於以下問題:Python QLineEdit.hasAcceptableInput方法的具體用法?Python QLineEdit.hasAcceptableInput怎麽用?Python QLineEdit.hasAcceptableInput使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PyQt5.QtWidgets.QLineEdit的用法示例。


在下文中一共展示了QLineEdit.hasAcceptableInput方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: ModeShiftDialog

# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import hasAcceptableInput [as 別名]
class ModeShiftDialog(QDialog):
	
    def __init__(self, parent=None):
        super(ModeShiftDialog, self).__init__(parent)
        
        mainLayout = QGridLayout()
        self.setLayout(mainLayout)
        
        self.keyLabel = QLabel()
        self.keyInput = QLineEdit()
        self.modeCombo = QComboBox()
        self.modeLabel = QLabel()
        
        self.buttons = QDialogButtonBox(
            QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
        userguide.addButton(self.buttons, "mode_shift")
        
        for m in sorted(modes.keys()):
            self.modeCombo.addItem(m)

        mainLayout.addWidget(self.keyLabel, 0, 0, 1, 1)
        mainLayout.addWidget(self.keyInput, 0, 1, 1, 1)
        mainLayout.addWidget(self.modeLabel, 1, 0, 1, 1)
        mainLayout.addWidget(self.modeCombo, 1, 1, 1, 1)
        mainLayout.addWidget(self.buttons, 9, 0, 2, 2)
        
        app.translateUI(self)
        qutil.saveDialogSize(self, "mode_shift/dialog/size", QSize(80, 60))
        self.buttons.accepted.connect(self.accept)
        self.buttons.rejected.connect(self.reject)
        
        self.keyInput.textEdited.connect(self.readKeyInput)
        self.modeCombo.currentIndexChanged.connect(self.readSettings)
        
        self.loadSettings()
    
    def translateUI(self):
        self.setWindowTitle(app.caption(_("Mode Shift")))
        self.keyLabel.setText(_("Key:"))
        self.modeLabel.setText(_("Mode:"))
        self.buttons.button(QDialogButtonBox.Ok).setText(_("shift pitches"))
        self.buttons.button(QDialogButtonBox.Ok).setEnabled(False)
        
    def setKeyValidator(self, validate):
        """Set function that validates the key input."""
        keyValidator = KeyValidator()
        keyValidator.setValidateFunc(validate)
        self.keyInput.setValidator(keyValidator)
    
    def readSettings(self):
        """Reads the current settings."""
        self._currentKey = self.keyInput.text()
        self._currentMode = self.modeCombo.currentText()
        
    def readKeyInput(self):
        """Read the key input and check if it's acceptable."""
        if self.keyInput.hasAcceptableInput():
            self.readSettings()
            self.buttons.button(QDialogButtonBox.Ok).setEnabled(True)
        else:
            self.buttons.button(QDialogButtonBox.Ok).setEnabled(False)
    
    def getMode(self):
        """Returns the chosen mode."""
        return self._currentKey, modes[self._currentMode]
        
    def loadSettings(self):
        """ get users previous settings """
        s = QSettings()
        s.beginGroup('mode_shift')
        key = s.value('key', "", str)
        self.keyInput.setText(key)
        index = s.value('mode', 0, int)
        self.modeCombo.setCurrentIndex(index)
        self.readKeyInput()
        
    def saveSettings(self):
        """ save users last settings """
        s = QSettings()
        s.beginGroup('mode_shift')
        s.setValue('key', self._currentKey)
        s.setValue('mode', self.modeCombo.currentIndex())
開發者ID:AlexSchr,項目名稱:frescobaldi,代碼行數:84,代碼來源:dialog.py

示例2: NewStudentDialog

# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import hasAcceptableInput [as 別名]

#.........這裏部分代碼省略.........
        self.combo = QComboBox(parent=self)
        self.combo.addItem(_('Separate given name and surname'))
        self.combo.addItem(_('Full name in just one field'))
        self.combo.currentIndexChanged.connect(self._update_combo)
        self.group_combo = QComboBox(parent=self)
        for listing in self.student_listings[1:]:
            self.group_combo.addItem(listing.group.name)
        layout.addRow(self.combo)
        layout.addRow(_('Id number'), self.id_field)
        layout.addRow(self.name_label, self.name_field)
        layout.addRow(self.surname_label, self.surname_field)
        layout.addRow(self.full_name_label, self.full_name_field)
        layout.addRow(_('Email'), self.email_field)
        layout.addRow(_('Group'), self.group_combo)
        self.buttons = QDialogButtonBox((QDialogButtonBox.Ok
                                         | QDialogButtonBox.Cancel))
        layout.addRow(self.buttons)
        self.buttons.accepted.connect(self.accept)
        self.buttons.rejected.connect(self.reject)
        self._check_values()
        # Set the combo box
        if NewStudentDialog._last_combo_value is None:
            NewStudentDialog._last_combo_value = 0
        self.combo.setCurrentIndex(NewStudentDialog._last_combo_value)
        if self.group_index is not None:
            self.group_combo.setCurrentIndex(self.group_index)
            self.group_combo.setEnabled(False)
        self._update_combo(NewStudentDialog._last_combo_value)

    def exec_(self):
        """Shows the dialog and waits until it is closed.

        Returns the text of the option selected by the user, or None if
        the dialog is cancelled.

        """
        result = super().exec_()
        if result == QDialog.Accepted:
            NewStudentDialog._last_combo_value = self.combo.currentIndex()
            listing = \
                self.student_listings[self.group_combo.currentIndex() + 1]
            email = self.email_field.text()
            if not email:
                email = None
            if self.combo.currentIndex() == 0:
                # First name, last name
                student = students.Student( \
                                    self.id_field.text(),
                                    None,
                                    self.name_field.text(),
                                    self.surname_field.text(),
                                    email,
                                    group_id=listing.group.identifier)
            else:
                # Full name
                student = students.Student( \
                                    self.id_field.text(),
                                    self.full_name_field.text(),
                                    None,
                                    None,
                                    email,
                                    group_id=listing.group.identifier)
            try:
                listing.add_students((student, ))
            except students.DuplicateStudentIdException:
                QMessageBox.critical(
                    self,
                    _('Adding a new student'),
                    _('The student cannot be added: '
                      'a student with the same id is already in the list'))
        else:
            student = None
        return student

    def _check_values(self):
        if (self.id_field.hasAcceptableInput()
            and (not self.email_field.text()
                 or self.email_field.hasAcceptableInput())):
            self.buttons.button(QDialogButtonBox.Ok).setEnabled(True)
        else:
            self.buttons.button(QDialogButtonBox.Ok).setEnabled(False)

    def _update_combo(self, new_index):
        if new_index == 0:
            self.name_field.setEnabled(True)
            self.surname_field.setEnabled(True)
            self.full_name_field.setEnabled(False)
            self.name_label.setEnabled(True)
            self.surname_label.setEnabled(True)
            self.full_name_label.setEnabled(False)
            self.full_name_field.setText('')
        else:
            self.name_field.setEnabled(False)
            self.surname_field.setEnabled(False)
            self.full_name_field.setEnabled(True)
            self.name_label.setEnabled(False)
            self.surname_label.setEnabled(False)
            self.full_name_label.setEnabled(True)
            self.name_field.setText('')
            self.surname_field.setText('')
開發者ID:jfisteus,項目名稱:eyegrade,代碼行數:104,代碼來源:students.py


注:本文中的PyQt5.QtWidgets.QLineEdit.hasAcceptableInput方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。