国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python3+PyQt5+Qt Designer實(shí)現(xiàn)擴(kuò)展對(duì)話框

2020-02-22 23:46:10
字體:
供稿:網(wǎng)友

本文是對(duì)《Python Qt GUI快速編程》的第9章的擴(kuò)展對(duì)話框例子Find and replace用Python3+PyQt5+Qt Designer進(jìn)行改寫。

第一部分無借用Qt Designer,完全用代碼實(shí)現(xiàn)。
第二部分則借用Qt Designer,快速實(shí)現(xiàn)。

第一部分:

import sysfrom PyQt5.QtCore import Qt,pyqtSignalfrom PyQt5.QtWidgets import (QApplication, QCheckBox, QDialog, QFrame,    QGridLayout, QHBoxLayout, QLabel, QLayout, QLineEdit,    QPushButton, QVBoxLayout)class FindAndReplaceDlg(QDialog):  find = pyqtSignal(str,bool,bool,bool,bool,bool)  replace = pyqtSignal(str,str,bool,bool,bool,bool,bool)     def __init__(self, parent=None):    super(FindAndReplaceDlg, self).__init__(parent)    findLabel = QLabel("Find &what:")    self.findLineEdit = QLineEdit()    findLabel.setBuddy(self.findLineEdit)    replaceLabel = QLabel("Replace w&ith:")    self.replaceLineEdit = QLineEdit()    replaceLabel.setBuddy(self.replaceLineEdit)    self.caseCheckBox = QCheckBox("&Case sensitive")    self.wholeCheckBox = QCheckBox("Wh&ole words")    self.wholeCheckBox.setChecked(True)    self.moreFrame = QFrame()    self.moreFrame.setFrameStyle(QFrame.StyledPanel|QFrame.Sunken)    self.backwardsCheckBox = QCheckBox("Search &Backwards")    self.regexCheckBox = QCheckBox("Regular E&xpression")    self.ignoreNotesCheckBox = QCheckBox("Ignore foot¬es "                          "and endnotes")    line = QFrame()    line.setFrameStyle(QFrame.VLine|QFrame.Sunken)    self.findButton = QPushButton("&Find")    self.replaceButton = QPushButton("&Replace")    closeButton = QPushButton("Close")    self.moreButton = QPushButton("&More")    self.moreButton.setCheckable(True)    gridLayout = QGridLayout()    gridLayout.addWidget(findLabel, 0, 0)    gridLayout.addWidget(self.findLineEdit, 0, 1)    gridLayout.addWidget(replaceLabel, 1, 0)    gridLayout.addWidget(self.replaceLineEdit, 1, 1)    frameLayout = QVBoxLayout()    frameLayout.addWidget(self.backwardsCheckBox)    frameLayout.addWidget(self.regexCheckBox)    frameLayout.addWidget(self.ignoreNotesCheckBox)    self.moreFrame.setLayout(frameLayout)    leftLayout = QVBoxLayout()    leftLayout.addLayout(gridLayout)    leftLayout.addWidget(self.caseCheckBox)    leftLayout.addWidget(self.wholeCheckBox)    leftLayout.addWidget(self.moreFrame)    buttonLayout = QVBoxLayout()    buttonLayout.addWidget(self.findButton)    buttonLayout.addWidget(self.replaceButton)    buttonLayout.addWidget(closeButton)    buttonLayout.addWidget(self.moreButton)    buttonLayout.addStretch()    mainLayout = QHBoxLayout()    mainLayout.addLayout(leftLayout)    mainLayout.addWidget(line)    mainLayout.addLayout(buttonLayout)    self.setLayout(mainLayout)    self.moreFrame.hide()    mainLayout.setSizeConstraint(QLayout.SetFixedSize)    self.moreButton.toggled[bool].connect(self.setvisible)    self.findLineEdit.textEdited.connect(self.updateUi)    self.findButton.clicked.connect(self.findClicked)    self.replaceButton.clicked.connect(self.replaceClicked)    self.updateUi()    self.setWindowTitle("Find and Replace")  def setvisible(self,YN):    self.moreFrame.setVisible(YN)  def findClicked(self):    self.find.emit(self.findLineEdit.text(),        self.caseCheckBox.isChecked(),        self.wholeCheckBox.isChecked(),        self.backwardsCheckBox.isChecked(),        self.regexCheckBox.isChecked(),        self.ignoreNotesCheckBox.isChecked())  def replaceClicked(self):    self.replace.emit(self.findLineEdit.text(),        self.replaceLineEdit.text(),        self.caseCheckBox.isChecked(),        self.wholeCheckBox.isChecked(),        self.backwardsCheckBox.isChecked(),        self.regexCheckBox.isChecked(),        self.ignoreNotesCheckBox.isChecked())  def updateUi(self):    enable = self.findLineEdit.text()    self.findButton.setEnabled(bool(enable))    self.replaceButton.setEnabled(bool(enable))if __name__ == "__main__":  def find(what, *args):    print("Find {0} {1}".format(what, [x for x in args]))  def replace(old, new, *args):    print("Replace {0} with {1} {2}".format(       old, new, [x for x in args]))  app = QApplication(sys.argv)  form = FindAndReplaceDlg()  form.find.connect(find)  form.replace.connect(replace)      form.show()  app.exec_()            
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 上犹县| 昌乐县| 专栏| 泰来县| 诸城市| 鲁山县| 五莲县| 天气| 安仁县| 新和县| 普定县| 唐海县| 延边| 六枝特区| 东方市| 宜章县| 察隅县| 伊川县| 凉山| 即墨市| 温宿县| 林西县| 天柱县| 特克斯县| 平定县| 阿拉善盟| 金乡县| 东安县| 大安市| 阜康市| 两当县| 通州市| 颍上县| 宜章县| 中西区| 方山县| 绥芬河市| 长葛市| 东平县| 长汀县| 龙海市|