Fix pylint errors

This commit is contained in:
Sébastien Helleu 2021-11-13 19:50:33 +01:00
parent aa89cf7836
commit 1fe8853608
13 changed files with 79 additions and 64 deletions

View File

@ -20,6 +20,8 @@
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
"""About dialog box."""
from PySide6 import QtCore, QtWidgets as QtGui

View File

@ -20,6 +20,8 @@
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
"""Management of WeeChat buffers/nicklist."""
from pkg_resources import resource_filename
from PySide6 import QtCore, QtGui, QtWidgets
@ -68,9 +70,6 @@ class GenericListWidget(QtWidgets.QListWidget):
class BufferListWidget(GenericListWidget):
"""Widget with list of buffers."""
def __init__(self, *args):
super().__init__(*args)
def switch_prev_buffer(self):
if self.currentRow() > 0:
self.setCurrentRow(self.currentRow() - 1)
@ -148,9 +147,9 @@ class Buffer(QtCore.QObject):
bufferInput = QtCore.Signal(str, str)
def __init__(self, data={}):
def __init__(self, data=None):
QtCore.QObject.__init__(self)
self.data = data
self.data = data or {}
self.nicklist = {}
self.widget = BufferWidget(display_nicklist=self.data.get('nicklist',
0))
@ -234,12 +233,12 @@ class Buffer(QtCore.QObject):
' ': '',
'+': 'yellow',
}
color = prefix_color.get(nick['prefix'], 'green')
if color:
col = prefix_color.get(nick['prefix'], 'green')
if col:
icon = QtGui.QIcon(
resource_filename(__name__,
'data/icons/bullet_%s_8x8.png' %
color))
col))
else:
pixmap = QtGui.QPixmap(8, 8)
pixmap.fill()

View File

@ -20,6 +20,8 @@
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
"""Chat area."""
import datetime
from PySide6 import QtCore, QtWidgets, QtGui
@ -64,11 +66,11 @@ class ChatTextEdit(QtWidgets.QTextEdit):
def display(self, time, prefix, text, forcecolor=None):
if time == 0:
d = datetime.datetime.now()
now = datetime.datetime.now()
else:
d = datetime.datetime.fromtimestamp(float(time))
now = datetime.datetime.fromtimestamp(float(time))
self.setTextColor(QtGui.QColor('#999999'))
self.insertPlainText(d.strftime('%H:%M '))
self.insertPlainText(now.strftime('%H:%M '))
prefix = self._color.convert(prefix)
text = self._color.convert(text)
if forcecolor:
@ -136,5 +138,5 @@ class ChatTextEdit(QtWidgets.QTextEdit):
self._setfont[attr](self._fontvalues[self._font[attr]][attr])
def scroll_bottom(self):
bar = self.verticalScrollBar()
bar.setValue(bar.maximum())
scroll = self.verticalScrollBar()
scroll.setValue(scroll.maximum())

View File

@ -20,6 +20,8 @@
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
"""Configuration for QWeeChat."""
import configparser
import os

View File

@ -20,6 +20,8 @@
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
"""Connection window."""
from PySide6 import QtGui, QtWidgets

View File

@ -20,6 +20,8 @@
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
"""Debug window."""
from PySide6 import QtWidgets
from qweechat.chat import ChatTextEdit

View File

@ -20,6 +20,8 @@
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
"""Input line for chat and debug window."""
from PySide6 import QtCore, QtWidgets
@ -40,7 +42,7 @@ class InputLineEdit(QtWidgets.QLineEdit):
def keyPressEvent(self, event):
key = event.key()
modifiers = event.modifiers()
bar = self.scroll_widget.verticalScrollBar()
scroll = self.scroll_widget.verticalScrollBar()
if modifiers == QtCore.Qt.ControlModifier:
if key == QtCore.Qt.Key_PageUp:
self.bufferSwitchPrev.emit()
@ -54,19 +56,19 @@ class InputLineEdit(QtWidgets.QLineEdit):
elif key in (QtCore.Qt.Key_Right, QtCore.Qt.Key_Down):
self.bufferSwitchNext.emit()
elif key == QtCore.Qt.Key_PageUp:
bar.setValue(bar.value() - (bar.pageStep() / 10))
scroll.setValue(scroll.value() - (scroll.pageStep() / 10))
elif key == QtCore.Qt.Key_PageDown:
bar.setValue(bar.value() + (bar.pageStep() / 10))
scroll.setValue(scroll.value() + (scroll.pageStep() / 10))
elif key == QtCore.Qt.Key_Home:
bar.setValue(bar.minimum())
scroll.setValue(scroll.minimum())
elif key == QtCore.Qt.Key_End:
bar.setValue(bar.maximum())
scroll.setValue(scroll.maximum())
else:
QtWidgets.QLineEdit.keyPressEvent(self, event)
elif key == QtCore.Qt.Key_PageUp:
bar.setValue(bar.value() - bar.pageStep())
scroll.setValue(scroll.value() - scroll.pageStep())
elif key == QtCore.Qt.Key_PageDown:
bar.setValue(bar.value() + bar.pageStep())
scroll.setValue(scroll.value() + scroll.pageStep())
elif key == QtCore.Qt.Key_Up:
self._history_navigate(-1)
elif key == QtCore.Qt.Key_Down:

View File

@ -20,6 +20,8 @@
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
"""I/O with WeeChat/relay."""
import struct
from PySide6 import QtCore, QtNetwork

View File

@ -62,7 +62,7 @@ class MainWindow(QtWidgets.QMainWindow):
"""Main window."""
def __init__(self, *args):
super().__init__()
super().__init__(*args)
self.config = config.read()
@ -207,7 +207,7 @@ class MainWindow(QtWidgets.QMainWindow):
"""Save connection configuration."""
if self.network:
options = self.network.get_options()
for option in options.keys():
for option in options:
self.config.set('relay', option, options[option])
def debug_display(self, *args, **kwargs):
@ -550,8 +550,8 @@ def main():
app.setStyle(QtWidgets.QStyleFactory.create('Cleanlooks'))
app.setWindowIcon(QtGui.QIcon(
resource_filename(__name__, 'data/icons/weechat.png')))
main = MainWindow()
main.show()
main_win = MainWindow()
main_win.show()
sys.exit(app.exec_())

View File

@ -20,8 +20,11 @@
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
"""Version of QWeeChat."""
VERSION = '0.0.1-dev'
def qweechat_version():
"""Return QWeeChat version."""
return VERSION

View File

@ -20,6 +20,8 @@
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
"""Remove/replace colors in WeeChat strings."""
import re
import logging
@ -86,25 +88,25 @@ class Color():
def _rgb_color(self, index):
color = TERMINAL_COLORS[index*6:(index*6)+6]
r = int(color[0:2], 16) * 0.85
g = int(color[2:4], 16) * 0.85
b = int(color[4:6], 16) * 0.85
return '%02x%02x%02x' % (r, g, b)
col_r = int(color[0:2], 16) * 0.85
col_g = int(color[2:4], 16) * 0.85
col_b = int(color[4:6], 16) * 0.85
return '%02x%02x%02x' % (col_r, col_g, col_b)
def _convert_weechat_color(self, color):
try:
index = int(color)
return '\x01(Fr%s)' % self.color_options[index]
except: # noqa: E722
log.debug('Error decoding WeeChat color "%s"' % color)
except Exception: # noqa: E722
log.debug('Error decoding WeeChat color "%s"', color)
return ''
def _convert_terminal_color(self, fg_bg, attrs, color):
try:
index = int(color)
return '\x01(%s%s#%s)' % (fg_bg, attrs, self._rgb_color(index))
except: # noqa: E722
log.debug('Error decoding terminal color "%s"' % color)
except Exception: # noqa: E722
log.debug('Error decoding terminal color "%s"', color)
return ''
def _convert_color_attr(self, fg_bg, color):
@ -126,8 +128,8 @@ class Color():
index = int(color)
return self._convert_terminal_color(fg_bg, attrs,
WEECHAT_BASIC_COLORS[index][1])
except: # noqa: E722
log.debug('Error decoding color "%s"' % color)
except Exception: # noqa: E722
log.debug('Error decoding color "%s"', color)
return ''
def _attrcode_to_char(self, code):
@ -145,29 +147,27 @@ class Color():
if color[1] == 'b':
# bar code, ignored
return ''
elif color[1] == '\x1C':
if color[1] == '\x1C':
# reset
return '\x01(Fr)\x01(Br)'
elif color[1] in ('F', 'B'):
if color[1] in ('F', 'B'):
# foreground or background
return self._convert_color_attr(color[1], color[2:])
elif color[1] == '*':
if color[1] == '*':
# foreground with optional background
items = color[2:].split(',')
s = self._convert_color_attr('F', items[0])
str_col = self._convert_color_attr('F', items[0])
if len(items) > 1:
s += self._convert_color_attr('B', items[1])
return s
elif color[1] == '@':
str_col += self._convert_color_attr('B', items[1])
return str_col
if color[1] == '@':
# direct ncurses pair number, ignored
return ''
elif color[1] == 'E':
if color[1] == 'E':
# text emphasis, ignored
return ''
if color[1:].isdigit():
return self._convert_weechat_color(int(color[1:]))
# color code
pass
elif color[0] == '\x1A':
# set attribute
return '\x01(+%s)' % self._attrcode_to_char(color[1])
@ -191,7 +191,6 @@ class Color():
return ''
if self.debug:
return RE_COLOR.sub(self._convert_color_debug, text)
else:
return RE_COLOR.sub(self._convert_color, text)

View File

@ -30,6 +30,8 @@
# start dev
#
"""Decode binary messages received from WeeChat/relay."""
import collections
import struct
import zlib
@ -49,10 +51,10 @@ class WeechatObject:
self.indent = ' ' if separator == '\n' else ''
self.separator1 = '\n%s' % self.indent if separator == '\n' else ''
def _str_value(self, v):
if type(v) is str and v is not None:
return '\'%s\'' % v
return str(v)
def _str_value(self, val):
if isinstance(val, str) and val is not None:
return '\'%s\'' % val
return str(val)
def _str_value_hdata(self):
lines = ['%skeys: %s%s%spath: %s' % (self.separator1,
@ -84,17 +86,17 @@ class WeechatObject:
return self._str_value(self.value)
def __str__(self):
self._obj_cb = {
obj_cb = {
'hda': self._str_value_hdata,
'inl': self._str_value_infolist,
}
return '%s: %s' % (self.objtype,
self._obj_cb.get(self.objtype,
self._str_value_other)())
obj_cb.get(self.objtype, self._str_value_other)())
class WeechatObjects(list):
def __init__(self, separator='\n'):
super().__init__()
self.separator = separator
def __str__(self):
@ -117,7 +119,6 @@ class WeechatMessage:
self.size, self.size_uncompressed,
100 - ((self.size * 100) // self.size_uncompressed),
self.msgid, self.objects)
else:
return 'size: %d, id=\'%s\', objects:\n%s' % (self.size,
self.msgid,
self.objects)
@ -127,6 +128,7 @@ class Protocol:
"""Decode binary message received from WeeChat/relay."""
def __init__(self):
self.data = ''
self._obj_cb = {
'chr': self._obj_char,
'int': self._obj_int,
@ -349,7 +351,7 @@ def hex_and_ascii(data, bytes_per_line=10):
char = b'x'
byte = struct.unpack('B', char)[0]
str_hex.append(b'%02X' % int(byte))
if byte >= 32 and byte <= 127:
if 32 <= byte <= 127:
str_ascii.append(char)
else:
str_ascii.append(b'.')

View File

@ -20,9 +20,7 @@
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
"""
Command-line program for testing WeeChat/relay protocol.
"""
"""Command-line program for testing WeeChat/relay protocol."""
import argparse
import os
@ -81,7 +79,7 @@ class TestProto(object):
self.sock.sendall(msg + b'\n')
sys.stdout.write(
(b'\x1b[33m<-- ' + msg + b'\x1b[0m\n').decode())
except: # noqa: E722
except Exception: # noqa: E722
traceback.print_exc()
print('Failed to send message')
return False
@ -106,7 +104,7 @@ class TestProto(object):
protocol.hex_and_ascii(msgd.uncompressed, 20)))
# display decoded message
print('\x1b[32m--> {0}\x1b[0m'.format(msgd))
except: # noqa: E722
except Exception: # noqa: E722
traceback.print_exc()
print('Error while decoding message from WeeChat')
return False
@ -183,7 +181,7 @@ class TestProto(object):
recvbuf = b''
sys.stdout.write((prompt + message).decode())
sys.stdout.flush()
except: # noqa: E722
except Exception: # noqa: E722
traceback.print_exc()
self.send(b'quit')
return 0