# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
+"""About dialog box."""
+
from PySide6 import QtCore, QtWidgets as QtGui
# 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
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)
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))
' ': '',
'+': '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()
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
+"""Chat area."""
+
import datetime
from PySide6 import QtCore, QtWidgets, QtGui
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:
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())
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
+"""Configuration for QWeeChat."""
+
import configparser
import os
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
+"""Connection window."""
+
from PySide6 import QtGui, QtWidgets
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
+"""Debug window."""
+
from PySide6 import QtWidgets
from qweechat.chat import ChatTextEdit
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
+"""Input line for chat and debug window."""
+
from PySide6 import QtCore, QtWidgets
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()
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:
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
+"""I/O with WeeChat/relay."""
+
import struct
from PySide6 import QtCore, QtNetwork
"""Main window."""
def __init__(self, *args):
- super().__init__()
+ super().__init__(*args)
self.config = config.read()
"""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):
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_())
# 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
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
+"""Remove/replace colors in WeeChat strings."""
+
import re
import logging
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):
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):
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])
return ''
if self.debug:
return RE_COLOR.sub(self._convert_color_debug, text)
- else:
- return RE_COLOR.sub(self._convert_color, text)
+ return RE_COLOR.sub(self._convert_color, text)
def remove(text):
# start dev
#
+"""Decode binary messages received from WeeChat/relay."""
+
import collections
import struct
import zlib
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,
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):
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)
+ return 'size: %d, id=\'%s\', objects:\n%s' % (self.size,
+ self.msgid,
+ self.objects)
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,
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'.')
# 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
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
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
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