def __init__(self, parent=None):
super(BlockingClient, self).__init__(parent)
self.thread = FortuneThread()
self.currentFortune = ''
hostLabel = QLabel("&Server name:")
portLabel = QLabel("S&erver port:")
for ipAddress in QNetworkInterface.allAddresses():
if ipAddress != QHostAddress.LocalHost and ipAddress.toIPv4Address() != 0:
break
else:
ipAddress = QHostAddress(QHostAddress.LocalHost)
ipAddress = ipAddress.toString()
self.hostLineEdit = QLineEdit(ipAddress)
self.portLineEdit = QLineEdit()
self.portLineEdit.setValidator(QIntValidator(1, 65535, self))
hostLabel.setBuddy(self.hostLineEdit)
portLabel.setBuddy(self.portLineEdit)
self.statusLabel = QLabel(
"This example requires that you run the Fortune Server example as well.")
self.statusLabel.setWordWrap(True)
self.getFortuneButton = QPushButton("Get Fortune")
self.getFortuneButton.setDefault(True)
self.getFortuneButton.setEnabled(False)
quitButton = QPushButton("Quit")
buttonBox = QDialogButtonBox()
buttonBox.addButton(self.getFortuneButton, QDialogButtonBox.ActionRole)
buttonBox.addButton(quitButton, QDialogButtonBox.RejectRole)
self.getFortuneButton.clicked.connect(self.requestNewFortune)
quitButton.clicked.connect(self.close)
self.hostLineEdit.textChanged.connect(self.enableGetFortuneButton)
self.portLineEdit.textChanged.connect(self.enableGetFortuneButton)
self.thread.newFortune.connect(self.showFortune)
self.thread.error.connect(self.displayError)
mainLayout = QGridLayout()
mainLayout.addWidget(hostLabel, 0, 0)
mainLayout.addWidget(self.hostLineEdit, 0, 1)
mainLayout.addWidget(portLabel, 1, 0)
mainLayout.addWidget(self.portLineEdit, 1, 1)
mainLayout.addWidget(self.statusLabel, 2, 0, 1, 2)
mainLayout.addWidget(buttonBox, 3, 0, 1, 2)
self.setLayout(mainLayout)
self.setWindowTitle("Blocking Fortune Client")
self.portLineEdit.setFocus()
评论列表
文章目录