def __init__(self, *args): super().__init__(*args) self._init_connection() self.debug_lines = [] self.debug_dialog = None self._lines = config.CONFIG_DEFAULT_RELAY_LINES self._buffer = QtCore.QByteArray() self._socket = QtNetwork.QSslSocket() self._socket.connected.connect(self._socket_connected) self._socket.readyRead.connect(self._socket_read) self._socket.disconnected.connect(self._socket_disconnected)
def __init__(self, parent=None): super(Client, self).__init__(parent) self.blockSize = 0 self.currentFortune = '' hostLabel = QtWidgets.QLabel("&Server name:") portLabel = QtWidgets.QLabel("S&erver port:") self.hostLineEdit = QtWidgets.QLineEdit('Localhost') self.portLineEdit = QtWidgets.QLineEdit() self.portLineEdit.setValidator(QtGui.QIntValidator(1, 65535, self)) hostLabel.setBuddy(self.hostLineEdit) portLabel.setBuddy(self.portLineEdit) self.statusLabel = QtWidgets.QLabel("This examples requires that you run " "the Fortune Server example as well.") self.getFortuneButton = QtWidgets.QPushButton("Get Fortune") self.getFortuneButton.setDefault(True) self.getFortuneButton.setEnabled(False) quitButton = QtWidgets.QPushButton("Quit") buttonBox = QtWidgets.QDialogButtonBox() buttonBox.addButton(self.getFortuneButton, QtWidgets.QDialogButtonBox.ActionRole) buttonBox.addButton(quitButton, QtWidgets.QDialogButtonBox.RejectRole) self.tcpSocket = QtNetwork.QTcpSocket(self) self.hostLineEdit.textChanged.connect(self.enableGetFortuneButton) self.portLineEdit.textChanged.connect(self.enableGetFortuneButton) self.getFortuneButton.clicked.connect(self.requestNewFortune) quitButton.clicked.connect(self.close) self.tcpSocket.readyRead.connect(self.readFortune) self.tcpSocket.errorOccurred.connect(self.displayError) mainLayout = QtWidgets.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("Fortune Client") self.portLineEdit.setFocus()
def make_network_request( url: str, *, params: dict = {}, # noqa B006 finished_callback: collections.abc.Callable[[QtNetwork.QNetworkReply], t.Any], ) -> QtNetwork.QNetworkReply: """Make a network request to `url` with a `params` query and connect its reply to `callback`.""" log.debug(f"Sending request to {url} with {params=}") if params: url += "?" + urllib.parse.urlencode(params) qurl = QtCore.QUrl(url) request = QtNetwork.QNetworkRequest(qurl) reply = auto_neutron.network_mgr.get(request) reply.finished.connect(partial(finished_callback, reply)) return reply
def __init__(self, parent=None): super(Server, self).__init__(parent) statusLabel = QtWidgets.QLabel() quitButton = QtWidgets.QPushButton("Quit") quitButton.setAutoDefault(False) self.tcpServer = QtNetwork.QTcpServer(self) if not self.tcpServer.listen(): QtWidgets.QMessageBox.critical( self, "Fortune Server", "Unable to start the server: %s." % self.tcpServer.errorString()) self.close() return statusLabel.setText("The server is running on port %d.\nRun the " "Fortune Client example now." % self.tcpServer.serverPort()) self.fortunes = ( "You've been leading a dog's life. Stay off the furniture.", "You've got to think about tomorrow.", "You will be surprised by a loud noise.", "You will feel hungry again in another hour.", "You might have mail.", "You cannot kill time without injuring eternity.", "Computers are not intelligent. They only think they are.") quitButton.clicked.connect(self.close) self.tcpServer.newConnection.connect(self.sendFortune) buttonLayout = QtWidgets.QHBoxLayout() buttonLayout.addStretch(1) buttonLayout.addWidget(quitButton) buttonLayout.addStretch(1) mainLayout = QtWidgets.QVBoxLayout() mainLayout.addWidget(statusLabel) mainLayout.addLayout(buttonLayout) self.setLayout(mainLayout) self.setWindowTitle("Fortune Server")
def get(self, url: str): """Start downloading url. Emits signal, when done.""" logger.debug("Download %s", url) request = QtNetwork.QNetworkRequest(QtCore.QUrl(url)) request.setTransferTimeout(3000) self.manager.get(request)
def __init__(self): super().__init__() self.com = Communicate() self.manager = QtNetwork.QNetworkAccessManager() self.manager.finished.connect( # pylint: disable=no-member self._on_get_finished)
from auto_neutron.utils.file import base_path from auto_neutron.utils.logging import ( SessionBackupHandler, UsernameFormatter, init_qt_logging, ) from auto_neutron.utils.utils import ExceptionHandler, create_interrupt_timer ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(APPID) app = QtWidgets.QApplication(sys.argv) app.window_icon = QtGui.QIcon(str(base_path() / "resources/icons_library.ico")) app.application_name = APP app.organization_name = ORG app.set_style("Fusion") auto_neutron.network_mgr = QtNetwork.QNetworkAccessManager() # create org and app folders get_config_dir().mkdir(parents=True, exist_ok=True) root_logger = logging.getLogger() log_format = UsernameFormatter( "{asctime} | {module:>16} | {levelname:>7} | {message}", datefmt="%H:%M:%S", style="{", ) root_logger.setLevel(logging.DEBUG) if __debug__: stream_handler = logging.StreamHandler(stream=sys.stdout) stream_handler.setFormatter(log_format)