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


Python QLineEdit.setMaxLength方法代碼示例

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


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

示例1: __init__

# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import setMaxLength [as 別名]
	def __init__(self, parent=None):
		super(lineEditDemo, self).__init__(parent)
		e1 = QLineEdit()
		e1.setValidator( QIntValidator() )
		e1.setMaxLength(4)
		e1.setAlignment( Qt.AlignRight )
		e1.setFont( QFont("Arial",20))
		e2 = QLineEdit()
		e2.setValidator( QDoubleValidator(0.99,99.99,2))
		flo = QFormLayout()
		flo.addRow("integer validator", e1)
		flo.addRow("Double validator",e2)
		e3 = QLineEdit()
		e3.setInputMask('+99_9999_999999')
		flo.addRow("Input Mask",e3)
		e4 = QLineEdit()
		e4.textChanged.connect( self.textchanged )
		flo.addRow("Text changed",e4)
		e5 = QLineEdit()
		e5.setEchoMode( QLineEdit.Password )
		flo.addRow("Password",e5)
		e6 = QLineEdit("Hello PyQt5")
		e6.setReadOnly(True)
		flo.addRow("Read Only",e6 )
		e5.editingFinished.connect( self.enterPress )
		self.setLayout(flo)
		self.setWindowTitle("QLineEdit例子")
開發者ID:kiorry,項目名稱:PYQT,代碼行數:29,代碼來源:qt04_lineEdit04.py

示例2: __init__

# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import setMaxLength [as 別名]
    def __init__(self, settings):
        super(QWidget, self).__init__()
        self._layout = QBoxLayout(QBoxLayout.TopToBottom)
        self.setLayout(self._layout)
        self.settings = settings

        # eq directory
        widget = QWidget()
        layout = QBoxLayout(QBoxLayout.LeftToRight)
        widget.setLayout(layout)
        label = QLabel("Everquest Directory: ")
        layout.addWidget(label)
        text = QLineEdit()
        text.setText(self.settings.get_value("general", "eq_directory"))
        text.setToolTip(self.settings.get_value("general", "eq_directory"))
        text.setDisabled(True)
        self._text_eq_directory = text
        layout.addWidget(text, 1)
        button = QPushButton("Browse...")
        button.clicked.connect(self._get_eq_directory)
        layout.addWidget(button)
        self._layout.addWidget(widget, 0, Qt.AlignTop)

        # eq directory info
        frame = QFrame()
        frame.setFrameShadow(QFrame.Sunken)
        frame.setFrameShape(QFrame.Box)
        frame_layout = QBoxLayout(QBoxLayout.LeftToRight)
        frame.setLayout(frame_layout)
        widget = QWidget()
        layout = QBoxLayout(QBoxLayout.LeftToRight)
        widget.setLayout(layout)
        self._label_eq_directory = QLabel()
        layout.addWidget(self._label_eq_directory, 1)
        frame_layout.addWidget(widget, 1, Qt.AlignCenter)
        self._layout.addWidget(frame, 1)

        # parse interval
        widget = QWidget()
        layout = QBoxLayout(QBoxLayout.LeftToRight)
        widget.setLayout(layout)
        label = QLabel("Seconds between parse checks: ")
        layout.addWidget(label, 0, Qt.AlignLeft)
        text = QLineEdit()
        text.setText(str(self.settings.get_value("general", "parse_interval")))
        text.editingFinished.connect(self._parse_interval_editing_finished)
        text.setMaxLength(3)
        self._text_parse_interval = text
        metrics = QFontMetrics(QApplication.font())
        text.setFixedWidth(metrics.width("888888"))
        layout.addWidget(text, 0, Qt.AlignLeft)
        self._layout.addWidget(widget, 0, Qt.AlignTop | Qt.AlignLeft)

        # spacing at bottom of window
        widget = QWidget()
        self._layout.addWidget(widget, 1)

        # setup
        if settings.get_value("general", "eq_directory") is not None:
            self._check_directory_stats()
開發者ID:nomns,項目名稱:Parse99,代碼行數:62,代碼來源:generaltab.py

示例3: createEditor

# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import setMaxLength [as 別名]
    def createEditor(self, parent, option, index):
        editor = QLineEdit(parent)
        if self.max_length > 0:
            editor.setMaxLength(self.max_length)
        if self.validator is not None:
            editor.setValidator(self.validator)
        editor.setFrame(False)

        return editor
開發者ID:chippey,項目名稱:linux-show-player,代碼行數:11,代碼來源:qdelegates.py

示例4: create_LineEdit

# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import setMaxLength [as 別名]
def create_LineEdit(maxsize, validator, maxlength):
    """Create a lineEdit with the given attributes.

    Keyword arguments:
    maxsize -- maximum size
    validator -- a QValidator
    maxlength - maximum length

    Returns: QLineEdit
    """
    lineEdit = QLineEdit()
    if maxsize is not None:
        lineEdit.setMaximumSize(QSize(maxsize[0], maxsize[1]))
    if validator is not None:
        lineEdit.setValidator(validator)
    if maxlength is not None:
        lineEdit.setMaxLength(maxlength)
    return lineEdit
開發者ID:Ilias95,項目名稱:FF-Multi-Converter,代碼行數:20,代碼來源:utils.py

示例5: Calculator

# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import setMaxLength [as 別名]
class Calculator(QWidget):
    NumDigitButtons = 10
    
    def __init__(self, parent=None):
        super(Calculator, self).__init__(parent)

        self.pendingAdditiveOperator = ''
        self.pendingMultiplicativeOperator = ''

        self.sumInMemory = 0.0
        self.sumSoFar = 0.0
        self.factorSoFar = 0.0
        self.waitingForOperand = True

        self.display = QLineEdit('0')
        self.display.setReadOnly(True)
        self.display.setAlignment(Qt.AlignRight)
        self.display.setMaxLength(15)

        font = self.display.font()
        font.setPointSize(font.pointSize() + 8)
        self.display.setFont(font)

        self.digitButtons = []
        
        for i in range(Calculator.NumDigitButtons):
            self.digitButtons.append(self.createButton(str(i),
                    self.digitClicked))

        self.pointButton = self.createButton(".", self.pointClicked)
        self.changeSignButton = self.createButton(u"\N{PLUS-MINUS SIGN}",
                self.changeSignClicked)

        self.backspaceButton = self.createButton("Backspace",
                self.backspaceClicked)
        self.clearButton = self.createButton("Clear", self.clear)
        self.clearAllButton = self.createButton("Clear All", self.clearAll)

        self.clearMemoryButton = self.createButton("MC", self.clearMemory)
        self.readMemoryButton = self.createButton("MR", self.readMemory)
        self.setMemoryButton = self.createButton("MS", self.setMemory)
        self.addToMemoryButton = self.createButton("M+", self.addToMemory)

        self.divisionButton = self.createButton(u"\N{DIVISION SIGN}",
                self.multiplicativeOperatorClicked)
        self.timesButton = self.createButton(u"\N{MULTIPLICATION SIGN}",
                self.multiplicativeOperatorClicked)
        self.minusButton = self.createButton("-", self.additiveOperatorClicked)
        self.plusButton = self.createButton("+", self.additiveOperatorClicked)

        self.squareRootButton = self.createButton("Sqrt",
                self.unaryOperatorClicked)
        self.powerButton = self.createButton(u"x\N{SUPERSCRIPT TWO}",
                self.unaryOperatorClicked)
        self.reciprocalButton = self.createButton("1/x",
                self.unaryOperatorClicked)
        self.equalButton = self.createButton("=", self.equalClicked)

        mainLayout = QGridLayout()
        mainLayout.setSizeConstraint(QLayout.SetFixedSize)

        mainLayout.addWidget(self.display, 0, 0, 1, 6)
        mainLayout.addWidget(self.backspaceButton, 1, 0, 1, 2)
        mainLayout.addWidget(self.clearButton, 1, 2, 1, 2)
        mainLayout.addWidget(self.clearAllButton, 1, 4, 1, 2)

        mainLayout.addWidget(self.clearMemoryButton, 2, 0)
        mainLayout.addWidget(self.readMemoryButton, 3, 0)
        mainLayout.addWidget(self.setMemoryButton, 4, 0)
        mainLayout.addWidget(self.addToMemoryButton, 5, 0)

        for i in range(1, Calculator.NumDigitButtons):
            row = ((9 - i) / 3) + 2
            column = ((i - 1) % 3) + 1
            mainLayout.addWidget(self.digitButtons[i], row, column)

        mainLayout.addWidget(self.digitButtons[0], 5, 1)
        mainLayout.addWidget(self.pointButton, 5, 2)
        mainLayout.addWidget(self.changeSignButton, 5, 3)

        mainLayout.addWidget(self.divisionButton, 2, 4)
        mainLayout.addWidget(self.timesButton, 3, 4)
        mainLayout.addWidget(self.minusButton, 4, 4)
        mainLayout.addWidget(self.plusButton, 5, 4)

        mainLayout.addWidget(self.squareRootButton, 2, 5)
        mainLayout.addWidget(self.powerButton, 3, 5)
        mainLayout.addWidget(self.reciprocalButton, 4, 5)
        mainLayout.addWidget(self.equalButton, 5, 5)
        self.setLayout(mainLayout)

        self.setWindowTitle("Calculator")

    def digitClicked(self):
        clickedButton = self.sender()
        digitValue = int(clickedButton.text())

        if self.display.text() == '0' and digitValue == 0.0:
            return

#.........這裏部分代碼省略.........
開發者ID:death-finger,項目名稱:Scripts,代碼行數:103,代碼來源:calculator.py

示例6: hex

# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import setMaxLength [as 別名]
 else:
     s1 = "#"
     s2 = hex(int(value["color"]["r"]*255))[2:]
     if len(s2) == 1:
         s1 += "0"
     s1 += s2
     s2 = hex(int(value["color"]["g"]*255))[2:]
     if len(s2) == 1:
         s1 += "0"
     s1 += s2
     s2 = hex(int(value["color"]["b"]*255))[2:]
     if len(s2) == 1:
         s1 += "0"
     s1 += s2
 colorrgb = QLineEdit(s1)
 colorrgb.setMaxLength(8)
 maxWidth = colorrgb.fontMetrics().maxWidth()
 if maxWidth == 0:
     maxWidth = colorrgb.fontMetrics().width("W")
 if maxWidth > 0:
     colorrgb.setFixedWidth(7*maxWidth)
 colorRGBList.append(colorrgb)
 gLayout.addWidget(colorrgb, i, 3)
 s1 = "255"
 if "a" in value["color"]:
     s1 = str(int(value["color"]["a"]*255))
 colora = QLineEdit(s1)
 colora.setMaxLength(3)
 if maxWidth > 0:
     colora.setFixedWidth(3*maxWidth)
 colorAList.append(colora)
開發者ID:rock-simulation,項目名稱:mars,代碼行數:33,代碼來源:gui.py

示例7: MyCurrencyBox

# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import setMaxLength [as 別名]
class MyCurrencyBox(QFrame):

    _amount = None

    def __init__(self, *args):
        super(MyCurrencyBox, self).__init__(*args)
        Lumberjack.info('spawning a << MyCurrencyBox >>')
        self.currencyBoxlayout = QHBoxLayout(self)
        self.currencyBoxlayout.setObjectName("currencyBoxlayout")
        self.currencyLabel = QLabel('€')
        self.euroLineEdit = QLineEdit()
        self.euroLineEdit.setText('0')
        self.euroLineEdit.setAlignment(Qt.AlignRight)
        self.euroLineEdit.setObjectName("euroLineEdit")
        euroValidator = QIntValidator()
        self.euroLineEdit.setValidator(euroValidator)
        self.euroLineEdit.setMaxLength(6)
        self.commaLabel = QLabel(',')
        self.centsLineEdit = QLineEdit()
        self.centsLineEdit.setText('00')
        self.euroLineEdit.setAlignment(Qt.AlignRight)
        self.centsLineEdit.setObjectName("centsLineEdit")
        centsValidator = QIntValidator(0, 99)
        self.centsLineEdit.setValidator(centsValidator)
        self.centsLineEdit.setMaxLength(2)
        spacerItem1 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
        spacerItem2 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
        self.currencyBoxlayout.addItem(spacerItem1)
        self.currencyBoxlayout.addWidget(self.currencyLabel)
        self.currencyBoxlayout.addWidget(self.euroLineEdit)
        self.currencyBoxlayout.addWidget(self.commaLabel)
        self.currencyBoxlayout.addWidget(self.centsLineEdit)
        self.currencyBoxlayout.addItem(spacerItem2)

        self.centsLineEdit.textChanged.connect(self.on_text_input)
        self.euroLineEdit.textChanged.connect(self.on_text_input)

    def getAmount(self):
        Lumberjack.info('< MyCurrencyBox > - -> (getAmount)')
        if self._amount is None:
            return None
        euros = self.euroLineEdit.text()
        cents = self.centsLineEdit.text()
        full_amount = euros + cents
        self._amount = int(full_amount)
        return self._amount

    def setAmount(self, amount):
        Lumberjack.info('< MyCurrencyBox > - -> (setAmount)')
        if amount is None:
            self._amount = None
            euros = '0'
            cents = '00'
        else:
            euros = str(amount)[:-2]
            if euros == '':
                euros = '0'
            cents = str(amount)[-2:]
            if cents == '0':
                cents = '00'
        self.euroLineEdit.setText(euros)
        self.centsLineEdit.setText(cents)
        self._amount = amount

    amount = pyqtProperty(int, fget=getAmount, fset=setAmount)

    def on_text_input(self):
        Lumberjack.info('< MyCurrencyBox {}> - -> (on_text_input)')
        euros = self.euroLineEdit.text()
        cents = self.centsLineEdit.text()
        full_amount = euros + cents
        self._amount = int(full_amount)
開發者ID:MazeFX,項目名稱:pat,代碼行數:74,代碼來源:myWidgets.py

示例8: Login

# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import setMaxLength [as 別名]
class Login(QWidget):

    lblUser = 0
    lblPass = 0
    fldUser = 0
    fldPass = 0
    btnLogin = 0
    btnReset = 0
    username = 0
    password = 0

    def __init__(self):
        super().__init__()

        self.init()

    def init(self):

        form = QFormLayout()
        hbox = QHBoxLayout()

        self.lblUser = QLabel("Username")
        self.lblPass = QLabel("Password")
        self.fldUser = QLineEdit()
        self.fldPass = QLineEdit()
        self.btnLogin = QPushButton("Login")
        self.btnReset = QPushButton("Reset")

        form.setHorizontalSpacing(20)

        hbox.setSpacing(20)
        hbox.addStretch()
        hbox.addWidget(self.btnLogin)
        hbox.addWidget(self.btnReset)
        hbox.addStretch()

        self.fldUser.setMaxLength(25)
        self.fldUser.setAlignment(Qt.AlignCenter)
        self.fldPass.setMaxLength(20)
        self.fldPass.setAlignment(Qt.AlignCenter)
        self.fldPass.setEchoMode(QLineEdit.Password)

        self.fldUser.textChanged.connect(self.changeUsername)
        self.fldPass.textChanged.connect(self.changePassword)
        self.btnLogin.clicked.connect(self.loginAction)
        self.btnReset.clicked.connect(self.resetAction)

        self.setLayout(form)

        form.addRow(self.lblUser, self.fldUser)
        form.addRow(self.lblPass, self.fldPass)
        form.addRow(QLabel())
        form.addRow(hbox)

        self.setWindowTitle("Login Example")

        self.resize(250, 100)
        self.moveToCenter()

        self.show()

    def moveToCenter(self):
        frame = self.frameGeometry()
        pos = QDesktopWidget().availableGeometry().center()
        frame.moveCenter(pos)
        self.move(frame.topLeft())

    def loginAction(self):
        print('Login information: ')
        print('Username: {}, Password: {}'.format(self.username,
                                                  self.password))

    def resetAction(self):
        print('Click reset button.')
        self.fldUser.clear()
        self.fldPass.clear()

    def changeUsername(self, text):
        self.username = text

    def changePassword(self, text):
        self.password = text
開發者ID:thanhhungchu95,項目名稱:python-prj,代碼行數:84,代碼來源:login_example.py

示例9: LedgerAuthDialog

# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import setMaxLength [as 別名]
class LedgerAuthDialog(QDialog):
    def __init__(self, handler, data):
        '''Ask user for 2nd factor authentication. Support text, security card and paired mobile methods.
        Use last method from settings, but support new pairing and downgrade.
        '''
        QDialog.__init__(self, handler.top_level_window())
        self.handler = handler
        self.txdata = data
        self.idxs = self.txdata['keycardData'] if self.txdata['confirmationType'] > 1 else ''
        self.setMinimumWidth(650)
        self.setWindowTitle(_("Ledger Wallet Authentication"))
        self.cfg = copy.deepcopy(self.handler.win.wallet.get_keystore().cfg)
        self.dongle = self.handler.win.wallet.get_keystore().get_client().dongle
        self.ws = None
        self.pin = ''
        
        self.devmode = self.getDevice2FAMode()
        if self.devmode == 0x11 or self.txdata['confirmationType'] == 1:
            self.cfg['mode'] = 0
        
        vbox = QVBoxLayout()
        self.setLayout(vbox)
        
        def on_change_mode(idx):
            if idx < 2 and self.ws:
                self.ws.stop()
                self.ws = None
            self.cfg['mode'] = 0 if self.devmode == 0x11 else idx if idx > 0 else 1
            if self.cfg['mode'] > 1 and self.cfg['pair'] and not self.ws:
                self.req_validation()
            if self.cfg['mode'] > 0:
                self.handler.win.wallet.get_keystore().cfg = self.cfg
                self.handler.win.wallet.save_keystore()
            self.update_dlg()
        def add_pairing():
            self.do_pairing()
        def return_pin():
            self.pin = self.pintxt.text() if self.txdata['confirmationType'] == 1 else self.cardtxt.text() 
            if self.cfg['mode'] == 1:
                self.pin = ''.join(chr(int(str(i),16)) for i in self.pin)
            self.accept()
        
        self.modebox = QWidget()
        modelayout = QHBoxLayout()
        self.modebox.setLayout(modelayout)
        modelayout.addWidget(QLabel(_("Method:")))
        self.modes = QComboBox()
        modelayout.addWidget(self.modes, 2)
        self.addPair = QPushButton(_("Pair"))
        self.addPair.setMaximumWidth(60)
        modelayout.addWidget(self.addPair)
        modelayout.addStretch(1)
        self.modebox.setMaximumHeight(50)
        vbox.addWidget(self.modebox)
        
        self.populate_modes()
        self.modes.currentIndexChanged.connect(on_change_mode)
        self.addPair.clicked.connect(add_pairing)
        
        self.helpmsg = QTextEdit()
        self.helpmsg.setStyleSheet("QTextEdit { background-color: lightgray; }")
        self.helpmsg.setReadOnly(True)
        vbox.addWidget(self.helpmsg)
        
        self.pinbox = QWidget()
        pinlayout = QHBoxLayout()
        self.pinbox.setLayout(pinlayout)
        self.pintxt = QLineEdit()
        self.pintxt.setEchoMode(2)
        self.pintxt.setMaxLength(4)
        self.pintxt.returnPressed.connect(return_pin)
        pinlayout.addWidget(QLabel(_("Enter PIN:")))
        pinlayout.addWidget(self.pintxt)
        pinlayout.addWidget(QLabel(_("NOT DEVICE PIN - see above")))
        pinlayout.addStretch(1)
        self.pinbox.setVisible(self.cfg['mode'] == 0)
        vbox.addWidget(self.pinbox)
                    
        self.cardbox = QWidget()
        card = QVBoxLayout()
        self.cardbox.setLayout(card)
        self.addrtext = QTextEdit()
        self.addrtext.setStyleSheet("QTextEdit { color:blue; background-color:lightgray; padding:15px 10px; border:none; font-size:20pt; font-family:monospace; }")
        self.addrtext.setReadOnly(True)
        self.addrtext.setMaximumHeight(130)
        card.addWidget(self.addrtext)
        
        def pin_changed(s):
            if len(s) < len(self.idxs):
                i = self.idxs[len(s)]
                addr = self.txdata['address']
                if not constants.net.TESTNET:
                    text = addr[:i] + '<u><b>' + addr[i:i+1] + '</u></b>' + addr[i+1:]
                else:
                    # pin needs to be created from mainnet address
                    addr_mainnet = bitcoin.script_to_address(bitcoin.address_to_script(addr), net=constants.BitcoinMainnet)
                    addr_mainnet = addr_mainnet[:i] + '<u><b>' + addr_mainnet[i:i+1] + '</u></b>' + addr_mainnet[i+1:]
                    text = str(addr) + '\n' + str(addr_mainnet)
                self.addrtext.setHtml(str(text))
            else:
#.........這裏部分代碼省略.........
開發者ID:thrasher-,項目名稱:electrum-ltc,代碼行數:103,代碼來源:auth2fa.py

示例10: NumberFormatDlg

# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import setMaxLength [as 別名]
class NumberFormatDlg(QDialog):

    changed = pyqtSignal()
    
    def __init__(self, format, parent=None):
        super(NumberFormatDlg, self).__init__(parent)
        self.setAttribute(Qt.WA_DeleteOnClose)

        punctuationRe = QRegExp(r"[ ,;:.]")

        thousandsLabel = QLabel("&Thousands separator")
        self.thousandsEdit = QLineEdit(format["thousandsseparator"])
        thousandsLabel.setBuddy(self.thousandsEdit)
        self.thousandsEdit.setMaxLength(1)
        self.thousandsEdit.setValidator(
                QRegExpValidator(punctuationRe, self))

        decimalMarkerLabel = QLabel("Decimal &marker")
        self.decimalMarkerEdit = QLineEdit(format["decimalmarker"])
        decimalMarkerLabel.setBuddy(self.decimalMarkerEdit)
        self.decimalMarkerEdit.setMaxLength(1)
        self.decimalMarkerEdit.setValidator(
                QRegExpValidator(punctuationRe, self))
        self.decimalMarkerEdit.setInputMask("X")

        decimalPlacesLabel = QLabel("&Decimal places")
        self.decimalPlacesSpinBox = QSpinBox()
        decimalPlacesLabel.setBuddy(self.decimalPlacesSpinBox)
        self.decimalPlacesSpinBox.setRange(0, 6)
        self.decimalPlacesSpinBox.setValue(format["decimalplaces"])

        self.redNegativesCheckBox = QCheckBox("&Red negative numbers")
        self.redNegativesCheckBox.setChecked(format["rednegatives"])

        buttonBox = QDialogButtonBox(QDialogButtonBox.Apply|
                                     QDialogButtonBox.Close)

        self.format = format

        grid = QGridLayout()
        grid.addWidget(thousandsLabel, 0, 0)
        grid.addWidget(self.thousandsEdit, 0, 1)
        grid.addWidget(decimalMarkerLabel, 1, 0)
        grid.addWidget(self.decimalMarkerEdit, 1, 1)
        grid.addWidget(decimalPlacesLabel, 2, 0)
        grid.addWidget(self.decimalPlacesSpinBox, 2, 1)
        grid.addWidget(self.redNegativesCheckBox, 3, 0, 1, 2)
        grid.addWidget(buttonBox, 4, 0, 1, 2)
        self.setLayout(grid)

        buttonBox.button(QDialogButtonBox.Apply).clicked.connect(self.apply)
        buttonBox.rejected.connect(self.reject)
#        self.connect(buttonBox.button(QDialogButtonBox.Apply),
 #                    SIGNAL("clicked()"), self.apply)
#        self.connect(buttonBox, SIGNAL("rejected()"),
#                     self, SLOT("reject()"))
        self.setWindowTitle("Set Number Format (Modeless)")


    def apply(self):
        thousands = unicode(self.thousandsEdit.text())
        decimal = unicode(self.decimalMarkerEdit.text())
        if thousands == decimal:
            QMessageBox.warning(self, "Format Error",
                    "The thousands separator and the decimal marker "
                    "must be different.")
            self.thousandsEdit.selectAll()
            self.thousandsEdit.setFocus()
            return
        if len(decimal) == 0:
            QMessageBox.warning(self, "Format Error",
                    "The decimal marker may not be empty.")
            self.decimalMarkerEdit.selectAll()
            self.decimalMarkerEdit.setFocus()
            return

        self.format["thousandsseparator"] = thousands
        self.format["decimalmarker"] = decimal
        self.format["decimalplaces"] = (
                self.decimalPlacesSpinBox.value())
        self.format["rednegatives"] = (
                self.redNegativesCheckBox.isChecked())
        self.changed.emit()
開發者ID:drongh,項目名稱:pyqt5-book-code,代碼行數:85,代碼來源:numberformatdlg2.py

示例11: NumberFormatDlg

# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import setMaxLength [as 別名]
class NumberFormatDlg(QDialog):

    def __init__(self, format, callback, parent=None):
        super(NumberFormatDlg, self).__init__(parent)

        punctuationRe = QRegExp(r"[ ,;:.]")
        thousandsLabel = QLabel("&Thousands separator")
        self.thousandsEdit = QLineEdit(format["thousandsseparator"])
        thousandsLabel.setBuddy(self.thousandsEdit)
        self.thousandsEdit.setMaxLength(1)
        self.thousandsEdit.setValidator(QRegExpValidator(
                punctuationRe, self))
        decimalMarkerLabel = QLabel("Decimal &marker")
        self.decimalMarkerEdit = QLineEdit(format["decimalmarker"])
        decimalMarkerLabel.setBuddy(self.decimalMarkerEdit)
        self.decimalMarkerEdit.setMaxLength(1)
        self.decimalMarkerEdit.setValidator(QRegExpValidator(
                punctuationRe, self))
        self.decimalMarkerEdit.setInputMask("X")
        decimalPlacesLabel = QLabel("&Decimal places")
        self.decimalPlacesSpinBox = QSpinBox()
        decimalPlacesLabel.setBuddy(self.decimalPlacesSpinBox)
        self.decimalPlacesSpinBox.setRange(0, 6)
        self.decimalPlacesSpinBox.setValue(format["decimalplaces"])
        self.redNegativesCheckBox = QCheckBox("&Red negative numbers")
        self.redNegativesCheckBox.setChecked(format["rednegatives"])

        self.format = format
        self.callback = callback

        grid = QGridLayout()
        grid.addWidget(thousandsLabel, 0, 0)
        grid.addWidget(self.thousandsEdit, 0, 1)
        grid.addWidget(decimalMarkerLabel, 1, 0)
        grid.addWidget(self.decimalMarkerEdit, 1, 1)
        grid.addWidget(decimalPlacesLabel, 2, 0)
        grid.addWidget(self.decimalPlacesSpinBox, 2, 1)
        grid.addWidget(self.redNegativesCheckBox, 3, 0, 1, 2)
        self.setLayout(grid)

        self.thousandsEdit.textEdited.connect(self.checkAndFix)
        self.decimalMarkerEdit.textEdited.connect(self.checkAndFix)
        self.decimalPlacesSpinBox.valueChanged.connect(self.apply)
        self.redNegativesCheckBox.toggled.connect(self.apply)
        
        self.setWindowTitle("Set Number Format (`Live')")


    def checkAndFix(self):
        thousands = unicode(self.thousandsEdit.text())
        decimal = unicode(self.decimalMarkerEdit.text())
        if thousands == decimal:
            self.thousandsEdit.clear()
            self.thousandsEdit.setFocus()
        if len(decimal) == 0:
            self.decimalMarkerEdit.setText(".")
            self.decimalMarkerEdit.selectAll()
            self.decimalMarkerEdit.setFocus()
        self.apply()


    def apply(self):
        self.format["thousandsseparator"] = (
                unicode(self.thousandsEdit.text()))
        self.format["decimalmarker"] = (
                unicode(self.decimalMarkerEdit.text()))
        self.format["decimalplaces"] = (
                self.decimalPlacesSpinBox.value())
        self.format["rednegatives"] = (
                self.redNegativesCheckBox.isChecked())
        self.callback()
開發者ID:drongh,項目名稱:pyqt5-book-code,代碼行數:73,代碼來源:numberformatdlg3.py

示例12: MultiPlayerMenu

# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import setMaxLength [as 別名]
class MultiPlayerMenu(QWidget):
    def __init__(self):
        super(MultiPlayerMenu, self).__init__()
        nameLayout = self.createNameField()
        networkConfig = self.createIpAndPortFields()
        networkButtons = self.createConnectAndHostButtons()

        mainLayout = QVBoxLayout()
        mainLayout.addWidget(self.createTitleLabel('Online'))
        mainLayout.addLayout(nameLayout)
        mainLayout.addLayout(networkConfig)
        mainLayout.addLayout(networkButtons)
        mainLayout.addWidget(self.createHorizontalLine())
        mainLayout.addWidget(self.createTitleLabel('Hotseat on one PC'))
        mainLayout.addWidget(self.createHotseatButton())
        self.setLayout(mainLayout)

    def createNameField(self):
        self.nameLabel = QLabel('Your name: ')
        self.nameField = QLineEdit()
        self.nameField.setMaxLength(20)
        self.nameField.textChanged.connect(self.nameChange)
        layout = QHBoxLayout()
        layout.addWidget(self.nameLabel)
        layout.addWidget(self.nameField)
        return layout

    def createIpAndPortFields(self):
        ipLabel = QLabel('Opponent IP:')
        ipLabel.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
        portLabel = QLabel('Game port:')
        portLabel.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
        self.ipField = QLineEdit()
        self.ipField.setInputMask('000.000.000.000; ')
        self.ipField.setFixedWidth(130)
        self.ipField.textChanged.connect(self.ipChange)
        self.portSpinBox = QSpinBox()
        self.portSpinBox.setRange(1024, 8080)
        self.portSpinBox.setFixedWidth(80)
        layout = QGridLayout()
        layout.addWidget(ipLabel, 0, 0)
        layout.addWidget(self.ipField, 0, 1)
        layout.addWidget(portLabel, 1, 0)
        layout.addWidget(self.portSpinBox, 1, 1)
        return layout

    def createConnectAndHostButtons(self):
        self.connectButton = QPushButton('Connect')
        self.connectButton.setEnabled(False)
        self.hostButton = QPushButton('Host game')
        self.hostButton.setEnabled(False)
        layout = QHBoxLayout()
        layout.addWidget(self.connectButton)
        layout.addWidget(self.hostButton)
        return layout

    def createTitleLabel(self, title):
        titleLabel = QLabel(title)
        titleLabel.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
        return titleLabel

    def createHotseatButton(self):
        self.hotseatButton = QPushButton('Play')
        return self.hotseatButton

    def createHorizontalLine(self):
        line = QLabel()
        line.setFrameStyle(QFrame.HLine)
        return line

    def nameChange(self):
        if self.nameIsValid():
            self.hostButton.setEnabled(True)
            if self.ipIsValid():
                self.connectButton.setEnabled(True)
        else:
            self.hostButton.setEnabled(False)
            self.connectButton.setEnabled(False)

    def ipChange(self):
        if self.ipIsValid():
            if self.nameIsValid():
                self.connectButton.setEnabled(True)
        else:
            self.connectButton.setEnabled(False)

    def ipIsValid(self):
        return QHostAddress().setAddress(self.ipField.text())

    def nameIsValid(self):
        if self.nameField.text():
            return True
        return False
開發者ID:stoimenoff,項目名稱:ultimate-tic-tac-toe,代碼行數:95,代碼來源:multiplayer.py

示例13: Form

# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import setMaxLength [as 別名]
class Form(QWidget):
    def __init__(self, parent=None):
        super(Form, self).__init__(parent)
 
        # Set up the first list (elements that can be used)
        elements = QListWidget()
        elements.viewport().setAcceptDrops(True)
        elements.setDragEnabled(True)
        elements.setDefaultDropAction(Qt.MoveAction)
        elements.setSelectionMode(QAbstractItemView.ExtendedSelection)
        elements.addItem(u"Last Name")
        elements.addItem(u"First Name")
        elements.addItem(u"Middle Initial")
        elements.addItem(u"Full Name")
        elements.addItem(u"DMIS ID")
        elements.addItem(u"SPIN Number")
        elements.addItem(u"SSN Prefix")
        elements.addItem(u"Social Security Number")
        elements.addItem(u"Date of Birth")
        elements.addItem(u"Gender")
        elements.addItem(u"Accession")
        elements.addItem(u"Isolation Date")
        elements.addItem(u"Culture Type")
        elements.addItem(u"Source")
        elements.addItem(u"Location Type")
        elements.addItem(u"Location")
        elements.addItem(u"Isolate Number")
        elements.addItem(u"Organism Name")
        elements.addItem(u"Alternate Organism Name")
        elements.addItem(u"Equipment")
        elements.addItem(u"Drug Info")
        elements.addItem(u"ESBL")
        elements.addItem(u"AMPC")


        # Set up the second list (elements to generate a config file from)
        self.selected_elements = QListWidget()
        self.selected_elements.viewport().setAcceptDrops(True)
        self.selected_elements.setDragEnabled(True)
        self.selected_elements.setDefaultDropAction(Qt.MoveAction)
        self.selected_elements.setSelectionMode(QAbstractItemView.ExtendedSelection)

        ok_button = QPushButton(u"OK")
        cancel_button = QPushButton(u"Cancel")
        about_button = QPushButton(u"About")
        insert_blank_line_button = QPushButton(u"Insert blank line")
        drug_validator = QIntValidator(1, 999)
        self.drugs = QLineEdit("1")
        self.drugs.setValidator(drug_validator)
        drugs_label = QLabel("Number of drugs per line")
        self.drugformat = QLineEdit("MIC,Call")
        drugformat_label = QLabel("Format of the drug information")
        self.date = QLineEdit("MM/dd/yyyy")
        date_label = QLabel("Date format")
        self.machine = QLineEdit("Machine name")
        machine_label = QLabel("Machine the file is from")
        buttons = QHBoxLayout()

        ok_button.clicked.connect(self.export_parser)
        cancel_button.clicked.connect(self.close_program)
        about_button.clicked.connect(self.about)
        insert_blank_line_button.clicked.connect(self.insert_blank_line)
        self.drugs.setMaxLength(3)

        buttons.addWidget(ok_button)
        buttons.addWidget(cancel_button)
        buttons.addWidget(about_button)
        buttons.addWidget(insert_blank_line_button)
 
        mainLayout = QGridLayout()
        mainLayout.addWidget(elements, 0, 0)
        mainLayout.addWidget(self.selected_elements, 0, 1)
        mainLayout.addLayout(buttons, 1, 0)
        mainLayout.addWidget(self.drugs, 2, 0)
        mainLayout.addWidget(drugs_label, 2, 1)
        mainLayout.addWidget(self.drugformat, 3, 0)
        mainLayout.addWidget(drugformat_label, 3, 1)
        mainLayout.addWidget(self.date, 4, 0)
        mainLayout.addWidget(date_label, 4, 1)
        mainLayout.addWidget(self.machine, 5, 0)
        mainLayout.addWidget(machine_label, 5, 1)
 
        self.setLayout(mainLayout)
        self.setWindowTitle(u"RevealerParserWizard")
        
    def export_parser(self):
        u'''
        Extract the text of the elements in selected_elements, then pass them
        to write_output so they can be fully converted and written to a parser
        file.
        '''
        extracted_elements = []
        element_num = self.selected_elements.count()
        if element_num < 1:
            no_entries = QMessageBox()
            no_entries.setIcon(QMessageBox.Warning)
            no_entries.setText(u"No elements selected!")
            no_entries.exec_()
            return
        for i in xrange(0, element_num):
#.........這裏部分代碼省略.........
開發者ID:rsclifford,項目名稱:RevealerParserWizard,代碼行數:103,代碼來源:main.py

示例14: initUI

# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import setMaxLength [as 別名]
 def initUI(self):
     app_icon = QIcon()
     app_icon.addFile("key.png", QSize(256, 256))
     self.setWindowIcon(app_icon)
     # open
     openFile = QAction('Open', self)
     openFile.setShortcut('Ctrl+O')
     openFile.setStatusTip('Open new File')
     openFile.triggered.connect(self.fileOpen)
     # save
     saveFile = QAction('Save', self)
     saveFile.setShortcut('Ctrl+S')
     saveFile.setStatusTip('Save new File')
     saveFile.triggered.connect(self.fileSave)
     printAction = QAction("Print", self)
     printAction.triggered.connect(self.printSetup)
     # exit
     exitAction = QAction('Exit', self)
     exitAction.triggered.connect(self.closeEvent)
     # menu object
     menubar = self.menuBar()
     # file drop down
     fileMenu = menubar.addMenu('&File')
     fileMenu.addAction(openFile)
     fileMenu.addAction(saveFile)
     fileMenu.addAction(printAction)
     fileMenu.addAction(exitAction)
     # widgets
     grid = QGridLayout()
     horiz = QVBoxLayout()
     bigHoriz = QHBoxLayout()
     horizLayout = QHBoxLayout()
     window = QWidget()
     window.setLayout(bigHoriz)
     leftPane = QFormLayout()
     bigHoriz.addLayout(leftPane)
     bigHoriz.addLayout(horiz)
     self.setCentralWidget(window)
     btn = QPushButton('Generate', self)
     btn.clicked.connect(lambda: self.runGen())
     clearBtn = QPushButton("Clear", self)
     clearBtn.clicked.connect(self.clearList)
     self.mainText = QListWidget(self)
     self.mainText.itemSelectionChanged.connect(self.listItemClicked)
     self.mainText.setFont(
         QFontDatabase.systemFont(QFontDatabase.FixedFont))
     self.mastInput = []
     i = 0
     while i < 6:
         t = QLineEdit()
         t.setMaxLength(1)
         t.setAlignment(Qt.AlignHCenter)
         t.textChanged.connect(self.textInputed)
         self.mastInput.append(t)
         i = i + 1
     for e in self.mastInput:
         horizLayout.addWidget(e)
     self.mast = QLineEdit()
     self.tenants = QLineEdit()
     self.inc = QLineEdit()
     self.title = QLineEdit()
     self.title.setMinimumWidth(200)
     self.desc = QLineEdit()
     self.address = QLineEdit()
     self.contact = QLineEdit()
     self.phone = QLineEdit()
     self.email = QLineEdit()
     self.notes = QTextEdit()
     self.keyway = QLineEdit()
     label = QLabel("Master Cuts")
     incLabel = QLabel("Increment")
     tenantLabel = QLabel("Tenants")
     # add widgets to layouts
     leftPane.addRow(QLabel("Title"), self.title)
     leftPane.addRow(QLabel("Description"), self.desc)
     leftPane.addRow(QLabel("Keyway"), self.keyway)
     leftPane.addRow(QLabel("Address"), self.address)
     leftPane.addRow(QLabel("contact"), self.contact)
     leftPane.addRow(QLabel("Phone"), self.phone)
     leftPane.addRow(QLabel("Email"), self.email)
     leftPane.addRow(QLabel("Notes"), self.notes)
     grid.addWidget(incLabel, 3, 0)
     grid.addWidget(tenantLabel, 2, 0)
     grid.addWidget(label, 1, 0)
     grid.addWidget(btn, 0, 0)
     horiz.addWidget(self.mainText)
     horiz.addLayout(grid)
     # horiz.addLayout(horizLayout)
     grid.addWidget(clearBtn, 0, 1)
     grid.addWidget(self.tenants, 2, 1)
     grid.addWidget(self.inc, 3, 1)
     grid.addLayout(horizLayout, 1, 1)
     # window properties
     self.setGeometry(300, 300, 500, 425)
     self.setWindowTitle('PySchlageGen')
     self.show()
開發者ID:colchuck,項目名稱:pySchlageGen,代碼行數:98,代碼來源:gui.py

示例15: PiezoBuzzer

# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import setMaxLength [as 別名]
class PiezoBuzzer(PluginBase):
    qtcb_beep_finished = pyqtSignal()
    qtcb_morse_finished = pyqtSignal()

    def __init__(self, *args):
        super().__init__(BrickletPiezoBuzzer, *args)

        self.pb = self.device

        self.qtcb_beep_finished.connect(self.cb_beep)
        self.pb.register_callback(self.pb.CALLBACK_BEEP_FINISHED,
                                  self.qtcb_beep_finished.emit)
        self.qtcb_morse_finished.connect(self.cb_morse)
        self.pb.register_callback(self.pb.CALLBACK_MORSE_CODE_FINISHED,
                                  self.qtcb_morse_finished.emit)

        self.beep_edit = QLineEdit()
        self.beep_edit.setText(str(1000))
        self.beep_label = QLabel('Duration [ms]:')
        self.beep_button = QPushButton('Send Beep')
        self.beep_layout = QHBoxLayout()
        self.beep_layout.addWidget(self.beep_label)
        self.beep_layout.addWidget(self.beep_edit)
        self.beep_layout.addWidget(self.beep_button)

        self.morse_edit = QLineEdit()
        self.morse_edit.setText('- .. -. -.- . .-. ..-. --- .-. --. .')
        self.morse_edit.setMaxLength(60)
        self.morse_edit.setValidator(QRegularExpressionValidator(QRegularExpression("[\\s|\\-|\\.]*")))
        self.morse_label = QLabel('Morse Code:')
        self.morse_button = QPushButton('Send Morse Code')
        self.morse_layout = QHBoxLayout()
        self.morse_layout.addWidget(self.morse_label)
        self.morse_layout.addWidget(self.morse_edit)
        self.morse_layout.addWidget(self.morse_button)

        self.status_label = QLabel('Status: Idle')

        self.beep_button.clicked.connect(self.beep_clicked)
        self.morse_button.clicked.connect(self.morse_clicked)

        layout = QVBoxLayout(self)
        layout.addLayout(self.beep_layout)
        layout.addLayout(self.morse_layout)
        layout.addWidget(self.status_label)
        layout.addStretch()

    def start(self):
        pass

    def stop(self):
        pass

    def destroy(self):
        pass

    @staticmethod
    def has_device_identifier(device_identifier):
        return device_identifier == BrickletPiezoBuzzer.DEVICE_IDENTIFIER

    def cb_beep(self):
        self.beep_button.setDisabled(False)
        self.morse_button.setDisabled(False)
        self.status_label.setText('Status: Idle')

    def cb_morse(self):
        self.beep_button.setDisabled(False)
        self.morse_button.setDisabled(False)
        self.status_label.setText('Status: Idle')

    def beep_clicked(self):
        duration = int(self.beep_edit.text())
        try:
            self.pb.beep(duration)
        except ip_connection.Error:
            return

        self.beep_button.setDisabled(True)
        self.morse_button.setDisabled(True)
        self.status_label.setText('Status: Beeping...')

    def morse_clicked(self):
        morse = self.morse_edit.text()
        try:
            self.pb.morse_code(morse)
        except ip_connection.Error:
            return

        self.beep_button.setDisabled(True)
        self.morse_button.setDisabled(True)
        self.status_label.setText('Status: Beeping...')
開發者ID:Tinkerforge,項目名稱:brickv,代碼行數:93,代碼來源:piezo_buzzer.py


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