From 7a3a48a56fa6504550295eb4709001556dd8d485 Mon Sep 17 00:00:00 2001 From: Abhilash Raj Date: Mon, 31 May 2021 22:43:37 -0700 Subject: [PATCH] A bunch of more fixes. - Update README - Remove some spurious comments here and there - Fix flake8 errors. --- README.adoc | 6 +++--- qweechat/buffer.py | 6 ++---- qweechat/network.py | 4 +--- qweechat/qweechat.py | 17 ++++++++++------- qweechat/weechat/protocol.py | 5 +++-- qweechat/weechat/testproto.py | 5 ++--- 6 files changed, 21 insertions(+), 22 deletions(-) diff --git a/README.adoc b/README.adoc index c3378b0..074dc3d 100644 --- a/README.adoc +++ b/README.adoc @@ -25,13 +25,13 @@ Following packages are *required*: * WeeChat (version >= 0.3.7) on local or remote machine, with relay plugin enabled and listening on a port with protocol "weechat" -* Python 2.x >= 2.6 -* PySide (recommended, packages: python.pyside.*) or PyQt4 (python-qt4) +* Python 3.7+ +* PySide6 === Install via source distribution ---- -$ python setup.py install +$ pip install . ---- == WeeChat setup diff --git a/qweechat/buffer.py b/qweechat/buffer.py index 88e403e..c501d48 100644 --- a/qweechat/buffer.py +++ b/qweechat/buffer.py @@ -19,8 +19,6 @@ # You should have received a copy of the GNU General Public License # along with QWeeChat. If not, see . # -import traceback - from pkg_resources import resource_filename from qweechat.chat import ChatTextEdit from qweechat.input import InputLineEdit @@ -169,7 +167,7 @@ class Buffer(QtCore.QObject): try: self.widget.set_title( color.remove(self.data['title'])) - except Exception as e: # noqa: E722 + except Exception: # noqa: E722 # TODO: Debug print the exception to be fixed. # traceback.print_exc() self.widget.set_title(None) @@ -178,7 +176,7 @@ class Buffer(QtCore.QObject): """Update prompt.""" try: self.widget.set_prompt(self.data['local_variables']['nick']) - except Exception as e: # noqa: E722 + except Exception: # noqa: E722 self.widget.set_prompt(None) def input_text_sent(self, text): diff --git a/qweechat/network.py b/qweechat/network.py index 52e190c..fe64d0f 100644 --- a/qweechat/network.py +++ b/qweechat/network.py @@ -23,10 +23,8 @@ import struct from qweechat import config from PySide6 import QtCore, QtNetwork -from PySide6.QtCore import QObject, Signal +from PySide6.QtCore import Signal -# QtCore = qt_compat.import_module('QtCore') -# QtNetwork = qt_compat.import_module('QtNetwork') _PROTO_INIT_CMD = ['init password=%(password)s'] diff --git a/qweechat/qweechat.py b/qweechat/qweechat.py index 0b38226..76db5a4 100644 --- a/qweechat/qweechat.py +++ b/qweechat/qweechat.py @@ -46,9 +46,7 @@ from qweechat.debug import DebugDialog from qweechat.about import AboutDialog from qweechat.version import qweechat_version -from PySide6.QtWidgets import ( - QApplication, QLabel, QPushButton, QVBoxLayout, QWidget) -from PySide6.QtCore import Qt, Slot +from PySide6.QtWidgets import QApplication from PySide6 import QtGui, QtWidgets, QtCore @@ -331,7 +329,7 @@ class MainWindow(QtWidgets.QMainWindow): 'message uncompressed (%d bytes):\n%s' % (message.size_uncompressed, protocol.hex_and_ascii(message.uncompressed, 20)), - forcecolor='#008800') + forcecolor='#008800') self.debug_display(0, '', 'Message: %s' % message) self.parse_message(message) except Exception: # noqa: E722 @@ -516,10 +514,14 @@ class MainWindow(QtWidgets.QMainWindow): def insert_buffer(self, index, buf): """Insert a buffer in list.""" self.buffers.insert(index, buf) - self.list_buffers.insertItem(index, '%d. %s' - % (buf.data['number'], - buf.data['full_name'])) + self.list_buffers.insertItem(index, '%s' + % (buf.data['local_variables']['name'])) self.stacked_buffers.insertWidget(index, buf.widget) + self._reorder_buffers() + + def _reorder_buffers(self): + """Order buffers by server.""" + pass def remove_buffer(self, index): """Remove a buffer.""" @@ -553,6 +555,7 @@ class MainWindow(QtWidgets.QMainWindow): config.write(self.config) QtWidgets.QMainWindow.closeEvent(self, event) + def main(): app = QApplication(sys.argv) app.setStyle(QtWidgets.QStyleFactory.create('Cleanlooks')) diff --git a/qweechat/weechat/protocol.py b/qweechat/weechat/protocol.py index 6283b2b..4a69378 100644 --- a/qweechat/weechat/protocol.py +++ b/qweechat/weechat/protocol.py @@ -34,6 +34,7 @@ import collections import struct import zlib + class WeechatDict(collections.OrderedDict): def __str__(self): return '{%s}' % ', '.join( @@ -314,7 +315,7 @@ class Protocol: uncompressed = zlib.decompress(self.data[5:]) size_uncompressed = len(uncompressed) + 5 uncompressed = b'%s%s%s' % (struct.pack('>i', size_uncompressed), - struct.pack('b', 0), uncompressed) + struct.pack('b', 0), uncompressed) self.data = uncompressed else: uncompressed = self.data[:] @@ -343,7 +344,7 @@ def hex_and_ascii(data, bytes_per_line=10): for i in range(num_lines): str_hex = [] str_ascii = [] - for j in range(bytes_per_line): # data[i*bytes_per_line:(i*bytes_per_line)+bytes_per_line]: + for j in range(bytes_per_line): # We can't easily iterate over individual bytes, so we are going to # do it this way. index = (i*bytes_per_line) + j diff --git a/qweechat/weechat/testproto.py b/qweechat/weechat/testproto.py index 06a0b53..54cd2c8 100644 --- a/qweechat/weechat/testproto.py +++ b/qweechat/weechat/testproto.py @@ -24,8 +24,6 @@ Command-line program for testing WeeChat/relay protocol. """ - - import argparse import os import select @@ -80,7 +78,8 @@ class TestProto(object): if msg == b'quit': self.has_quit = True self.sock.sendall(msg + b'\n') - sys.stdout.write((b'\x1b[33m<-- ' + msg + b'\x1b[0m\n').decode()) + sys.stdout.write( + (b'\x1b[33m<-- ' + msg + b'\x1b[0m\n').decode()) except: # noqa: E722 traceback.print_exc() print('Failed to send message')