From c7580c3a3530917a96aa44145224a1613ab4e3c7 Mon Sep 17 00:00:00 2001 From: emdee Date: Sat, 10 Feb 2024 06:29:40 +0000 Subject: [PATCH] qt6 fixes --- qweechat/connection.py | 12 ++++++++++++ qweechat/input.py | 2 +- qweechat/network.py | 26 ++++++++++++++++++++------ 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/qweechat/connection.py b/qweechat/connection.py index d867d2a..7f1884d 100644 --- a/qweechat/connection.py +++ b/qweechat/connection.py @@ -45,6 +45,10 @@ class ConnectionDialog(QtWidgets.QDialog): line_edit = QtWidgets.QLineEdit() line_edit.setFixedWidth(200) value = self.values.get('hostname', '') + if value in ['None', None]: + value = '0' + elif type(value) == int: + value = str(value) line_edit.insert(value) grid.addWidget(line_edit, 0, 1) self.fields['hostname'] = line_edit @@ -56,6 +60,10 @@ class ConnectionDialog(QtWidgets.QDialog): line_edit = QtWidgets.QLineEdit() line_edit.setFixedWidth(200) value = self.values.get('port', '') + if value in ['None', None]: + value = '0' + elif type(value) == int: + value = str(value) line_edit.insert(value) grid.addWidget(line_edit, 1, 1) self.fields['port'] = line_edit @@ -73,6 +81,10 @@ class ConnectionDialog(QtWidgets.QDialog): line_edit.setFixedWidth(200) line_edit.setEchoMode(QtWidgets.QLineEdit.Password) value = self.values.get('password', '') + if value in ['None', None]: + value = '0' + elif type(value) == int: + value = str(value) line_edit.insert(value) grid.addWidget(line_edit, 2, 1) self.fields['password'] = line_edit diff --git a/qweechat/input.py b/qweechat/input.py index 8ffcd29..98b05bd 100644 --- a/qweechat/input.py +++ b/qweechat/input.py @@ -23,7 +23,7 @@ """Input line for chat and debug window.""" from qtpy import QtCore, QtWidgets -from qtpy.QtCore import pyqtSignal as Signal +from qtpy.QtCore import Signal class InputLineEdit(QtWidgets.QLineEdit): """Input line.""" diff --git a/qweechat/network.py b/qweechat/network.py index 149837d..0127a98 100644 --- a/qweechat/network.py +++ b/qweechat/network.py @@ -27,7 +27,8 @@ import secrets import struct from qtpy import QtCore, QtNetwork -from qtoy.QtCore import pyqtSignal as Signal +# from PyQt5.QtCore import pyqtSignal as Signal +from qtpy.QtCore import Signal from qweechat import config from qweechat.debug import DebugDialog @@ -231,7 +232,19 @@ class Network(QtCore.QObject): def is_connected(self): """Return True if the socket is connected, False otherwise.""" - return self._socket.state() == QtNetwork.QAbstractSocket.ConnectedState + return is_state(self, at='ConnectedState') + + def is_state(self, at='ConnectedState'): + """Return True if the socket is connected, False otherwise.""" + if hasattr(QtNetwork.QAbstractSocket, 'ConnectedState'): + if self._socket.state() == getattr(QtNetwork.QAbstractSocket, at): + return True + return False + if hasattr(QtNetwork.QAbstractSocket, 'SocketState'): + if self._socket.state() == getattr(QtNetwork.QAbstractSocket.SocketState, at): + return True + return False + return False def is_ssl(self): """Return True if SSL is used, False otherwise.""" @@ -251,9 +264,10 @@ class Network(QtCore.QObject): self._lines = int(lines) except ValueError: self._lines = config.CONFIG_DEFAULT_RELAY_LINES - if self._socket.state() == QtNetwork.QAbstractSocket.ConnectedState: + # AttributeError: type object 'QAbstractSocket' has no attribute 'ConnectedState' + if self.is_connected(): return - if self._socket.state() != QtNetwork.QAbstractSocket.UnconnectedState: + if not self.is_state('UnconnectedState'): self._socket.abort() if self._ssl: self._socket.ignoreSslErrors() @@ -264,10 +278,10 @@ class Network(QtCore.QObject): def disconnect_weechat(self): """Disconnect from WeeChat.""" - if self._socket.state() == QtNetwork.QAbstractSocket.UnconnectedState: + if self.is_state('UnconnectedState'): self.set_status(STATUS_DISCONNECTED) return - if self._socket.state() == QtNetwork.QAbstractSocket.ConnectedState: + if self.is_state('ConnectedState'): self.send_to_weechat('quit\n') self._socket.waitForBytesWritten(1000) else: