设为首页 加入收藏

TOP

PyQt5 signal and slot(二)
2017-12-07 14:22:55 】 浏览:740
Tags:PyQt5 signal and slot
, 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.accepted.connect(self.accept) buttonBox.rejected.connect(self.reject) self.setWindowTitle("Number format") def accept(self): class ThousandsError(Exception): pass class DecimalError(Exception): pass Punctuation = frozenset(" ,;:.") thousands = str(self.thousandsEdit.text()) decimal = str(self.decimalMarkerEdit.text()) try: if len(decimal) == 0: raise DecimalError("The decimal marker may not be empty.") if len(thousands) > 1: raise ThousandsError("The thousands separator may only be empty or one charactor.") if len(decimal) > 1: raise DecimalError("The decimal marker must be one character.") if thousands == decimal: raise ThousandsError("The thousands separator and decimal marker must be different.") if thousands and thousands not in Punctuation: raise ThousandsError("The thousands separator must be in Punctuation.") if decimal and decimal not in Punctuation: raise DecimalError("The decimal marker must be a punctuation symbol.") except ThousandsError as e: QMessageBox.warning(self, "Thousands separator error:", str(e)) self.thousandsEdit.selectAll() self.thousandsEdit.setFocus() return except DecimalError as e: QMessageBox.warning(self, "Decimal marker error:", str(e)) 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() QDialog.accept(self) def numberFormat(self): return self.format class NumberModelessDialog(QDialog): changed = pyqtSignal() def __init__(self, format, parent=None): super(NumberModelessDialog, self).__init__(parent) self.setAttribute(Qt.WA_DeleteOnClose) punctuationRe = QRegularExpression(r"[ ,;:.]") thousandsLabel = QLabel("&Thousands separator:") self.thousandsEdit = QLineEdit(format["thousandsseparator"]) thousandsLabel.setBuddy(self.thousandsEdit) self.thousandsEdit.setMaxLength(1) self.thousandsEdit.setValidator(QRegularExpressionValidator(punctuationRe, self)) decimalMarkerLabel = QLabel("Decimal $marker:") self.decimalMarkerEdit = QLineEdit(format["decimalmarker"]) decimalMarkerLabel.setBuddy(self.decimalMarkerEdit) self.decimalMarkerEdit.setMaxLength(1) self.decimalMarkerEdit.setValidator(QRegularExpressionValidator(punctuationRe, self)) 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") sel
首页 上一页 1 2 3 4 5 下一页 尾页 2/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇从CentOS安装完成到生成词云pytho.. 下一篇python装饰器探究与参数的领取

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目