我正在寻找资源以查看 pyqt4
.
我有一个finalPage
从类向导获取参数并希望显示基于该参数的一些结果,并且完成按钮应该在类向导的最后一个并且finalPage
只有关闭按钮。
我的代码
from PyQt4 import QtCore, QtGui
import sys
from ex import dbconnect
data = [['Male', 0, 'cheap', 'Low', 'Bus'], ['Male', 1, 'cheap', 'Medium', 'Bus'], ['Female', 1, 'cheap', 'Medium', 'Train'], ['Female', 0, 'cheap', 'Low', 'Bus'], ['Male', 1, 'cheap', 'Medium', 'Bus'], ['Male', 0, 'standard', 'Medium', 'Train'], ['Female', 1, 'standard', 'Medium', 'Train'], ['Female', 1, 'expensive', 'High', 'Car'], ['Male', 2, 'expensive', 'Medium', 'Car'], ['Female', 2, 'expensive', 'High', 'Car']]
data1 = ['Gender', 'car ownership', 'Travel Cost', 'Income Level', 'Transportation mode']
#this class i got helped with it
class Wizard(QtGui.QWizard):
def __init__(self):
super(Wizard, self).__init__()
datas = []
for l in range(len(data1) - 2):
y = []
for row in data:
x = row[l]
if not x in y:
y.append(x)
datas.append(y)
titles = data1
self.setStyleSheet(('font:50 10pt "MS Shell Dlg 2";'))
self.setWindowTitle("Recommender System")
self.groups = []
for title, options in zip(titles, datas):
page, group = Wizard.create_page(title, options)
self.addPage(page)
self.groups.append(group)
self.button(QtGui.QWizard.FinishButton).clicked.connect(
self.on_finished
)
self._results = []
self.show()
@property
def results(self):
self.get_options()
return self._results
def get_options(self):
self._results = []
for group in self.groups:
button = group.checkedButton()
if button is not None:
self._results.append(button.text())
@QtCore.pyqtSlot()
def on_finished(self):
print("finished", self.results)
@staticmethod
def create_page(title, options):
page = QtGui.QWizardPage()
group = QtGui.QButtonGroup(page)
page.setTitle(title)
page.setSubTitle("Please choose one of these state.")
hlay = QtGui.QHBoxLayout(page)
for option in options:
radiobutton = QtGui.QRadioButton(text=str(option))
group.addButton(radiobutton)
hlay.addWidget(radiobutton)
return page, group
########################################################################################################################
#this passed from the class like the r = Wizard.results()
def finalpage(r):
page = QtGui.QWizardPage()
page.setTitle("Conclusion!")
list1 = QtGui.QListView()
label2 = QtGui.QLabel('Based on these Ruls')
label2.setStyleSheet(("font:50 10pt \"MS Shell Dlg 2\";"))
model = QtGui.QStandardItemModel(list1)
for m in r:
item = QtGui.QStandardItem(str(m))
model.appendRow(item)
list1.setModel(model)
layout = QtGui.QVBoxLayout()
layout.addWidget(list1)
page.setLayout(layout)
return page
def run1():
global data, data1
app = QtGui.QApplication(sys.argv)
if app is None:
app = QtGui.QApplication([])
wizard = Wizard()
wizard.addpage(finalpage(wizard.results())
sys.exit(app.exec_())
run1()
我不知道何时何地调用最后一页