设为首页 加入收藏

TOP

PyQt5 signal and slot(三)
2017-12-07 14:22:55 】 浏览:739
Tags:PyQt5 signal and slot
Widget(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("Number format") def checkAndFix(self): thousands = self.thousandsEdit.text() decimal = 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): thousands = self.thousandsEdit.text() decimal = self.decimalMarkerEdit.text() self.format["thousandsseparator"] = thousands self.format["decimalmarker"] = decimal self.format["decimalplaces"] = self.decimalPlacesSpinBox.value() self.format["rednegatives"] = self.redNegativesCheckBox.isChecked() self.callback() class Form(QDialog): X_MAX = 26 Y_MAX = 60 def __init__(self, parent=None): super(Form, self).__init__(parent) self.numberDlg = None self.format = { "thousandsseparator":",", "decimalmarker":".", "decimalplaces":2, "rednegatives": False } self.numbers = {} for x in range(self.X_MAX): for y in range(self.Y_MAX): self.numbers[(x,y)] = 10000 * random.random() - 5000 self.table = QTableWidget() modalButton = QPushButton("Set numbe format...(&Modal)") modelessButton = QPushButton("Set number format...(M&odeless)") liveButton = QPushButton("Set number format...(&Live)") buttonLayout = QHBoxLayout() buttonLayout.addStretch() buttonLayout.addWidget(modalButton) buttonLayout.addWidget(modelessButton) buttonLayout.addWidget(liveButton) layout = QVBoxLayout() layout.addWidget(self.table) layout.addLayout(buttonLayout) self.setLayout(layout) modalButton.clicked.connect(self.setNumberFormatByModal) modelessButton.clicked.connect(self.setNumberFormatByModeless) liveButton.clicked.connect(self.setNumberFormatByLive) self.setWindowTitle("Set Number Format") self.refreshTable() def refreshTable(self): self.table.clear() self.table.setRowCount(self.Y_MAX) self.table.setColumnCount(self.X_MAX) self.table.setHorizontalHeaderLabels(list(string.ascii_uppercase)) for x in range(self.X_MAX): for y in range(self.Y_MAX): fraction, whole = math.modf(self.numbers[(x,y)]) sign = "-" if whole < 0 else "" whole = "{0}".format(int(math.floor(abs(whole)))) digits = [] for i, digit in enumerate(reversed(whole)): if i and i % 3 == 0: digits.insert(0, self.format["thousandsseparator"]) digits.insert(0, digit) if self.format["decimalplaces"]: fraction = "{0:.7f}".format(abs(fraction)) fraction = self.format["decimalmarker"] + fraction[2:self.format["decimalplaces"]+2] else: fraction =
首页 上一页 1 2 3 4 5 下一页 尾页 3/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇从CentOS安装完成到生成词云pytho.. 下一篇python装饰器探究与参数的领取

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目