add third_party

This commit is contained in:
emdee 2022-11-20 18:15:46 +00:00
parent f1d8ce105c
commit db37d29dc8
52 changed files with 4849 additions and 0 deletions

43
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,43 @@
name: CI
on:
- push
- pull_request
jobs:
build:
strategy:
matrix:
python-version:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
name: Python ${{ matrix.python-version }}
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install -r requirements.txt
pip install bandit flake8 pylint
- name: Lint with flake8
run: make flake8
# - name: Lint with pylint
# run: make pylint
- name: Lint with bandit
run: make bandit

2
requirements.txt Normal file
View File

@ -0,0 +1,2 @@
PyQt5

View File

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2011-2022 Sébastien Helleu <flashcode@flashtux.org>
#
# This file is part of QWeeChat, a Qt remote GUI for WeeChat.
#
# QWeeChat is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# QWeeChat is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#

61
toxygen/third_party/qweechat/about.py vendored Normal file
View File

@ -0,0 +1,61 @@
# -*- coding: utf-8 -*-
#
# about.py - about dialog box
#
# Copyright (C) 2011-2022 Sébastien Helleu <flashcode@flashtux.org>
#
# This file is part of QWeeChat, a Qt remote GUI for WeeChat.
#
# QWeeChat is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# QWeeChat is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
"""About dialog box."""
from PyQt5 import QtCore, QtWidgets as QtGui
from qweechat.version import qweechat_version
class AboutDialog(QtGui.QDialog):
"""About dialog."""
def __init__(self, app_name, author, weechat_site, *args):
QtGui.QDialog.__init__(*(self,) + args)
self.setModal(True)
self.setWindowTitle('About')
close_button = QtGui.QPushButton('Close')
close_button.pressed.connect(self.close)
hbox = QtGui.QHBoxLayout()
hbox.addStretch(1)
hbox.addWidget(close_button)
hbox.addStretch(1)
vbox = QtGui.QVBoxLayout()
messages = [
f'<b>{app_name}</b> {qweechat_version()}',
f'© 2011-2022 {author}',
'',
f'<a href="{weechat_site}">{weechat_site}</a>',
'',
]
for msg in messages:
label = QtGui.QLabel(msg)
label.setAlignment(QtCore.Qt.AlignHCenter)
vbox.addWidget(label)
vbox.addLayout(hbox)
self.setLayout(vbox)
self.show()

View File

@ -0,0 +1,27 @@
*** about.py.dst 2022-11-19 18:31:51.000000000 +0000
--- about.py 2022-11-19 18:32:41.000000000 +0000
***************
*** 20,30 ****
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
"""About dialog box."""
! from PySide6 import QtCore, QtWidgets as QtGui
from qweechat.version import qweechat_version
class AboutDialog(QtGui.QDialog):
--- 20,30 ----
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
"""About dialog box."""
! from PyQt5 import QtCore, QtWidgets as QtGui
from qweechat.version import qweechat_version
class AboutDialog(QtGui.QDialog):

View File

@ -0,0 +1,61 @@
# -*- coding: utf-8 -*-
#
# about.py - about dialog box
#
# Copyright (C) 2011-2022 Sébastien Helleu <flashcode@flashtux.org>
#
# This file is part of QWeeChat, a Qt remote GUI for WeeChat.
#
# QWeeChat is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# QWeeChat is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
"""About dialog box."""
from PySide6 import QtCore, QtWidgets as QtGui
from qweechat.version import qweechat_version
class AboutDialog(QtGui.QDialog):
"""About dialog."""
def __init__(self, app_name, author, weechat_site, *args):
QtGui.QDialog.__init__(*(self,) + args)
self.setModal(True)
self.setWindowTitle('About')
close_button = QtGui.QPushButton('Close')
close_button.pressed.connect(self.close)
hbox = QtGui.QHBoxLayout()
hbox.addStretch(1)
hbox.addWidget(close_button)
hbox.addStretch(1)
vbox = QtGui.QVBoxLayout()
messages = [
f'<b>{app_name}</b> {qweechat_version()}',
f'© 2011-2022 {author}',
'',
f'<a href="{weechat_site}">{weechat_site}</a>',
'',
]
for msg in messages:
label = QtGui.QLabel(msg)
label.setAlignment(QtCore.Qt.AlignHCenter)
vbox.addWidget(label)
vbox.addLayout(hbox)
self.setLayout(vbox)
self.show()

250
toxygen/third_party/qweechat/buffer.py vendored Normal file
View File

@ -0,0 +1,250 @@
# -*- coding: utf-8 -*-
#
# buffer.py - management of WeeChat buffers/nicklist
#
# Copyright (C) 2011-2022 Sébastien Helleu <flashcode@flashtux.org>
#
# This file is part of QWeeChat, a Qt remote GUI for WeeChat.
#
# QWeeChat is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# QWeeChat is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
"""Management of WeeChat buffers/nicklist."""
from pkg_resources import resource_filename
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import pyqtSignal
Signal = pyqtSignal
from qweechat.chat import ChatTextEdit
from qweechat.input import InputLineEdit
from qweechat.weechat import color
class GenericListWidget(QtWidgets.QListWidget):
"""Generic QListWidget with dynamic size."""
def __init__(self, *args):
super().__init__(*args)
self.setMaximumWidth(100)
self.setTextElideMode(QtCore.Qt.ElideNone)
self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.setFocusPolicy(QtCore.Qt.NoFocus)
pal = self.palette()
pal.setColor(QtGui.QPalette.Highlight, QtGui.QColor('#ddddff'))
pal.setColor(QtGui.QPalette.HighlightedText, QtGui.QColor('black'))
self.setPalette(pal)
def auto_resize(self):
size = self.sizeHintForColumn(0)
if size > 0:
size += 4
self.setMaximumWidth(size)
def clear(self, *args):
"""Re-implement clear to set dynamic size after clear."""
QtWidgets.QListWidget.clear(*(self,) + args)
self.auto_resize()
def addItem(self, *args):
"""Re-implement addItem to set dynamic size after add."""
QtWidgets.QListWidget.addItem(*(self,) + args)
self.auto_resize()
def insertItem(self, *args):
"""Re-implement insertItem to set dynamic size after insert."""
QtWidgets.QListWidget.insertItem(*(self,) + args)
self.auto_resize()
class BufferListWidget(GenericListWidget):
"""Widget with list of buffers."""
def switch_prev_buffer(self):
if self.currentRow() > 0:
self.setCurrentRow(self.currentRow() - 1)
else:
self.setCurrentRow(self.count() - 1)
def switch_next_buffer(self):
if self.currentRow() < self.count() - 1:
self.setCurrentRow(self.currentRow() + 1)
else:
self.setCurrentRow(0)
class BufferWidget(QtWidgets.QWidget):
"""
Widget with (from top to bottom):
title, chat + nicklist (optional) + prompt/input.
"""
def __init__(self, display_nicklist=False):
super().__init__()
# title
self.title = QtWidgets.QLineEdit()
self.title.setFocusPolicy(QtCore.Qt.NoFocus)
# splitter with chat + nicklist
self.chat_nicklist = QtWidgets.QSplitter()
self.chat_nicklist.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
QtWidgets.QSizePolicy.Expanding)
self.chat = ChatTextEdit(debug=False)
self.chat_nicklist.addWidget(self.chat)
self.nicklist = GenericListWidget()
if not display_nicklist:
self.nicklist.setVisible(False)
self.chat_nicklist.addWidget(self.nicklist)
# prompt + input
self.hbox_edit = QtWidgets.QHBoxLayout()
self.hbox_edit.setContentsMargins(0, 0, 0, 0)
self.hbox_edit.setSpacing(0)
self.input = InputLineEdit(self.chat)
self.hbox_edit.addWidget(self.input)
prompt_input = QtWidgets.QWidget()
prompt_input.setLayout(self.hbox_edit)
# vbox with title + chat/nicklist + prompt/input
vbox = QtWidgets.QVBoxLayout()
vbox.setContentsMargins(0, 0, 0, 0)
vbox.setSpacing(0)
vbox.addWidget(self.title)
vbox.addWidget(self.chat_nicklist)
vbox.addWidget(prompt_input)
self.setLayout(vbox)
def set_title(self, title):
"""Set buffer title."""
self.title.clear()
if title is not None:
self.title.setText(title)
def set_prompt(self, prompt):
"""Set prompt."""
if self.hbox_edit.count() > 1:
self.hbox_edit.takeAt(0)
if prompt is not None:
label = QtWidgets.QLabel(prompt)
label.setContentsMargins(0, 0, 5, 0)
self.hbox_edit.insertWidget(0, label)
class Buffer(QtCore.QObject):
"""A WeeChat buffer."""
bufferInput = Signal(str, str)
def __init__(self, data=None):
QtCore.QObject.__init__(self)
self.data = data or {}
self.nicklist = {}
self.widget = BufferWidget(display_nicklist=self.data.get('nicklist',
0))
self.update_title()
self.update_prompt()
self.widget.input.textSent.connect(self.input_text_sent)
def pointer(self):
"""Return pointer on buffer."""
return self.data.get('__path', [''])[0]
def update_title(self):
"""Update title."""
try:
self.widget.set_title(
color.remove(self.data['title']))
except Exception: # noqa: E722
# TODO: Debug print the exception to be fixed.
# traceback.print_exc()
self.widget.set_title(None)
def update_prompt(self):
"""Update prompt."""
try:
self.widget.set_prompt(self.data['local_variables']['nick'])
except Exception: # noqa: E722
self.widget.set_prompt(None)
def input_text_sent(self, text):
"""Called when text has to be sent to buffer."""
if self.data:
self.bufferInput.emit(self.data['full_name'], text)
def nicklist_add_item(self, parent, group, prefix, name, visible):
"""Add a group/nick in nicklist."""
if group:
self.nicklist[name] = {
'visible': visible,
'nicks': []
}
else:
self.nicklist[parent]['nicks'].append({
'prefix': prefix,
'name': name,
'visible': visible,
})
def nicklist_remove_item(self, parent, group, name):
"""Remove a group/nick from nicklist."""
if group:
if name in self.nicklist:
del self.nicklist[name]
else:
if parent in self.nicklist:
self.nicklist[parent]['nicks'] = [
nick for nick in self.nicklist[parent]['nicks']
if nick['name'] != name
]
def nicklist_update_item(self, parent, group, prefix, name, visible):
"""Update a group/nick in nicklist."""
if group:
if name in self.nicklist:
self.nicklist[name]['visible'] = visible
else:
if parent in self.nicklist:
for nick in self.nicklist[parent]['nicks']:
if nick['name'] == name:
nick['prefix'] = prefix
nick['visible'] = visible
break
def nicklist_refresh(self):
"""Refresh nicklist."""
self.widget.nicklist.clear()
for group in sorted(self.nicklist):
for nick in sorted(self.nicklist[group]['nicks'],
key=lambda n: n['name']):
prefix_color = {
'': '',
' ': '',
'+': 'yellow',
}
col = prefix_color.get(nick['prefix'], 'green')
if col:
icon = QtGui.QIcon(
resource_filename(__name__,
'data/icons/bullet_%s_8x8.png' %
col))
else:
pixmap = QtGui.QPixmap(8, 8)
pixmap.fill()
icon = QtGui.QIcon(pixmap)
item = QtWidgets.QListWidgetItem(icon, nick['name'])
self.widget.nicklist.addItem(item)
self.widget.nicklist.setVisible(True)

View File

@ -0,0 +1,27 @@
*** buffer.py.dst 2022-11-19 18:31:51.000000000 +0000
--- buffer.py 2022-11-19 18:32:41.000000000 +0000
***************
*** 22,32 ****
"""Management of WeeChat buffers/nicklist."""
from pkg_resources import resource_filename
! from PySide6 import QtCore, QtGui, QtWidgets
from qweechat.chat import ChatTextEdit
from qweechat.input import InputLineEdit
from qweechat.weechat import color
--- 22,32 ----
"""Management of WeeChat buffers/nicklist."""
from pkg_resources import resource_filename
! from PyQt5 import QtCore, QtGui, QtWidgets
from qweechat.chat import ChatTextEdit
from qweechat.input import InputLineEdit
from qweechat.weechat import color

View File

@ -0,0 +1,248 @@
# -*- coding: utf-8 -*-
#
# buffer.py - management of WeeChat buffers/nicklist
#
# Copyright (C) 2011-2022 Sébastien Helleu <flashcode@flashtux.org>
#
# This file is part of QWeeChat, a Qt remote GUI for WeeChat.
#
# QWeeChat is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# QWeeChat is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# 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
from qweechat.chat import ChatTextEdit
from qweechat.input import InputLineEdit
from qweechat.weechat import color
class GenericListWidget(QtWidgets.QListWidget):
"""Generic QListWidget with dynamic size."""
def __init__(self, *args):
super().__init__(*args)
self.setMaximumWidth(100)
self.setTextElideMode(QtCore.Qt.ElideNone)
self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.setFocusPolicy(QtCore.Qt.NoFocus)
pal = self.palette()
pal.setColor(QtGui.QPalette.Highlight, QtGui.QColor('#ddddff'))
pal.setColor(QtGui.QPalette.HighlightedText, QtGui.QColor('black'))
self.setPalette(pal)
def auto_resize(self):
size = self.sizeHintForColumn(0)
if size > 0:
size += 4
self.setMaximumWidth(size)
def clear(self, *args):
"""Re-implement clear to set dynamic size after clear."""
QtWidgets.QListWidget.clear(*(self,) + args)
self.auto_resize()
def addItem(self, *args):
"""Re-implement addItem to set dynamic size after add."""
QtWidgets.QListWidget.addItem(*(self,) + args)
self.auto_resize()
def insertItem(self, *args):
"""Re-implement insertItem to set dynamic size after insert."""
QtWidgets.QListWidget.insertItem(*(self,) + args)
self.auto_resize()
class BufferListWidget(GenericListWidget):
"""Widget with list of buffers."""
def switch_prev_buffer(self):
if self.currentRow() > 0:
self.setCurrentRow(self.currentRow() - 1)
else:
self.setCurrentRow(self.count() - 1)
def switch_next_buffer(self):
if self.currentRow() < self.count() - 1:
self.setCurrentRow(self.currentRow() + 1)
else:
self.setCurrentRow(0)
class BufferWidget(QtWidgets.QWidget):
"""
Widget with (from top to bottom):
title, chat + nicklist (optional) + prompt/input.
"""
def __init__(self, display_nicklist=False):
super().__init__()
# title
self.title = QtWidgets.QLineEdit()
self.title.setFocusPolicy(QtCore.Qt.NoFocus)
# splitter with chat + nicklist
self.chat_nicklist = QtWidgets.QSplitter()
self.chat_nicklist.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
QtWidgets.QSizePolicy.Expanding)
self.chat = ChatTextEdit(debug=False)
self.chat_nicklist.addWidget(self.chat)
self.nicklist = GenericListWidget()
if not display_nicklist:
self.nicklist.setVisible(False)
self.chat_nicklist.addWidget(self.nicklist)
# prompt + input
self.hbox_edit = QtWidgets.QHBoxLayout()
self.hbox_edit.setContentsMargins(0, 0, 0, 0)
self.hbox_edit.setSpacing(0)
self.input = InputLineEdit(self.chat)
self.hbox_edit.addWidget(self.input)
prompt_input = QtWidgets.QWidget()
prompt_input.setLayout(self.hbox_edit)
# vbox with title + chat/nicklist + prompt/input
vbox = QtWidgets.QVBoxLayout()
vbox.setContentsMargins(0, 0, 0, 0)
vbox.setSpacing(0)
vbox.addWidget(self.title)
vbox.addWidget(self.chat_nicklist)
vbox.addWidget(prompt_input)
self.setLayout(vbox)
def set_title(self, title):
"""Set buffer title."""
self.title.clear()
if title is not None:
self.title.setText(title)
def set_prompt(self, prompt):
"""Set prompt."""
if self.hbox_edit.count() > 1:
self.hbox_edit.takeAt(0)
if prompt is not None:
label = QtWidgets.QLabel(prompt)
label.setContentsMargins(0, 0, 5, 0)
self.hbox_edit.insertWidget(0, label)
class Buffer(QtCore.QObject):
"""A WeeChat buffer."""
bufferInput = QtCore.Signal(str, str)
def __init__(self, data=None):
QtCore.QObject.__init__(self)
self.data = data or {}
self.nicklist = {}
self.widget = BufferWidget(display_nicklist=self.data.get('nicklist',
0))
self.update_title()
self.update_prompt()
self.widget.input.textSent.connect(self.input_text_sent)
def pointer(self):
"""Return pointer on buffer."""
return self.data.get('__path', [''])[0]
def update_title(self):
"""Update title."""
try:
self.widget.set_title(
color.remove(self.data['title']))
except Exception: # noqa: E722
# TODO: Debug print the exception to be fixed.
# traceback.print_exc()
self.widget.set_title(None)
def update_prompt(self):
"""Update prompt."""
try:
self.widget.set_prompt(self.data['local_variables']['nick'])
except Exception: # noqa: E722
self.widget.set_prompt(None)
def input_text_sent(self, text):
"""Called when text has to be sent to buffer."""
if self.data:
self.bufferInput.emit(self.data['full_name'], text)
def nicklist_add_item(self, parent, group, prefix, name, visible):
"""Add a group/nick in nicklist."""
if group:
self.nicklist[name] = {
'visible': visible,
'nicks': []
}
else:
self.nicklist[parent]['nicks'].append({
'prefix': prefix,
'name': name,
'visible': visible,
})
def nicklist_remove_item(self, parent, group, name):
"""Remove a group/nick from nicklist."""
if group:
if name in self.nicklist:
del self.nicklist[name]
else:
if parent in self.nicklist:
self.nicklist[parent]['nicks'] = [
nick for nick in self.nicklist[parent]['nicks']
if nick['name'] != name
]
def nicklist_update_item(self, parent, group, prefix, name, visible):
"""Update a group/nick in nicklist."""
if group:
if name in self.nicklist:
self.nicklist[name]['visible'] = visible
else:
if parent in self.nicklist:
for nick in self.nicklist[parent]['nicks']:
if nick['name'] == name:
nick['prefix'] = prefix
nick['visible'] = visible
break
def nicklist_refresh(self):
"""Refresh nicklist."""
self.widget.nicklist.clear()
for group in sorted(self.nicklist):
for nick in sorted(self.nicklist[group]['nicks'],
key=lambda n: n['name']):
prefix_color = {
'': '',
' ': '',
'+': 'yellow',
}
col = prefix_color.get(nick['prefix'], 'green')
if col:
icon = QtGui.QIcon(
resource_filename(__name__,
'data/icons/bullet_%s_8x8.png' %
col))
else:
pixmap = QtGui.QPixmap(8, 8)
pixmap.fill()
icon = QtGui.QIcon(pixmap)
item = QtWidgets.QListWidgetItem(icon, nick['name'])
self.widget.nicklist.addItem(item)
self.widget.nicklist.setVisible(True)

142
toxygen/third_party/qweechat/chat.py vendored Normal file
View File

@ -0,0 +1,142 @@
# -*- coding: utf-8 -*-
#
# chat.py - chat area
#
# Copyright (C) 2011-2022 Sébastien Helleu <flashcode@flashtux.org>
#
# This file is part of QWeeChat, a Qt remote GUI for WeeChat.
#
# QWeeChat is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# QWeeChat is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
"""Chat area."""
import datetime
from PyQt5 import QtCore, QtWidgets, QtGui
from qweechat import config
from qweechat.weechat import color
class ChatTextEdit(QtWidgets.QTextEdit):
"""Chat area."""
def __init__(self, debug, *args):
QtWidgets.QTextEdit.__init__(*(self,) + args)
self.debug = debug
self.readOnly = True
self.setFocusPolicy(QtCore.Qt.NoFocus)
self.setFontFamily('monospace')
self._textcolor = self.textColor()
self._bgcolor = QtGui.QColor('#FFFFFF')
self._setcolorcode = {
'F': (self.setTextColor, self._textcolor),
'B': (self.setTextBackgroundColor, self._bgcolor)
}
self._setfont = {
'*': self.setFontWeight,
'_': self.setFontUnderline,
'/': self.setFontItalic
}
self._fontvalues = {
False: {
'*': QtGui.QFont.Normal,
'_': False,
'/': False
},
True: {
'*': QtGui.QFont.Bold,
'_': True,
'/': True
}
}
self._color = color.Color(config.color_options(), self.debug)
def display(self, time, prefix, text, forcecolor=None):
if time == 0:
now = datetime.datetime.now()
else:
now = datetime.datetime.fromtimestamp(float(time))
self.setTextColor(QtGui.QColor('#999999'))
self.insertPlainText(now.strftime('%H:%M '))
prefix = self._color.convert(prefix)
text = self._color.convert(text)
if forcecolor:
if prefix:
prefix = '\x01(F%s)%s' % (forcecolor, prefix)
text = '\x01(F%s)%s' % (forcecolor, text)
if prefix:
self._display_with_colors(prefix + ' ')
if text:
self._display_with_colors(text)
if text[-1:] != '\n':
self.insertPlainText('\n')
else:
self.insertPlainText('\n')
self.scroll_bottom()
def _display_with_colors(self, string):
self.setTextColor(self._textcolor)
self.setTextBackgroundColor(self._bgcolor)
self._reset_attributes()
items = string.split('\x01')
for i, item in enumerate(items):
if i > 0 and item.startswith('('):
pos = item.find(')')
if pos >= 2:
action = item[1]
code = item[2:pos]
if action == '+':
# set attribute
self._set_attribute(code[0], True)
elif action == '-':
# remove attribute
self._set_attribute(code[0], False)
else:
# reset attributes and color
if code == 'r':
self._reset_attributes()
self._setcolorcode[action][0](
self._setcolorcode[action][1])
else:
# set attributes + color
while code.startswith(('*', '!', '/', '_', '|',
'r')):
if code[0] == 'r':
self._reset_attributes()
elif code[0] in self._setfont:
self._set_attribute(
code[0],
not self._font[code[0]])
code = code[1:]
if code:
self._setcolorcode[action][0](
QtGui.QColor(code))
item = item[pos+1:]
if len(item) > 0:
self.insertPlainText(item)
def _reset_attributes(self):
self._font = {}
for attr in self._setfont:
self._set_attribute(attr, False)
def _set_attribute(self, attr, value):
self._font[attr] = value
self._setfont[attr](self._fontvalues[self._font[attr]][attr])
def scroll_bottom(self):
scroll = self.verticalScrollBar()
scroll.setValue(scroll.maximum())

View File

@ -0,0 +1,27 @@
*** chat.py.dst 2022-11-19 18:31:51.000000000 +0000
--- chat.py 2022-11-19 18:32:41.000000000 +0000
***************
*** 22,32 ****
"""Chat area."""
import datetime
! from PySide6 import QtCore, QtWidgets, QtGui
from qweechat import config
from qweechat.weechat import color
--- 22,32 ----
"""Chat area."""
import datetime
! from PyQt5 import QtCore, QtWidgets, QtGui
from qweechat import config
from qweechat.weechat import color

142
toxygen/third_party/qweechat/chat.py.dst vendored Normal file
View File

@ -0,0 +1,142 @@
# -*- coding: utf-8 -*-
#
# chat.py - chat area
#
# Copyright (C) 2011-2022 Sébastien Helleu <flashcode@flashtux.org>
#
# This file is part of QWeeChat, a Qt remote GUI for WeeChat.
#
# QWeeChat is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# QWeeChat is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
"""Chat area."""
import datetime
from PySide6 import QtCore, QtWidgets, QtGui
from qweechat import config
from qweechat.weechat import color
class ChatTextEdit(QtWidgets.QTextEdit):
"""Chat area."""
def __init__(self, debug, *args):
QtWidgets.QTextEdit.__init__(*(self,) + args)
self.debug = debug
self.readOnly = True
self.setFocusPolicy(QtCore.Qt.NoFocus)
self.setFontFamily('monospace')
self._textcolor = self.textColor()
self._bgcolor = QtGui.QColor('#FFFFFF')
self._setcolorcode = {
'F': (self.setTextColor, self._textcolor),
'B': (self.setTextBackgroundColor, self._bgcolor)
}
self._setfont = {
'*': self.setFontWeight,
'_': self.setFontUnderline,
'/': self.setFontItalic
}
self._fontvalues = {
False: {
'*': QtGui.QFont.Normal,
'_': False,
'/': False
},
True: {
'*': QtGui.QFont.Bold,
'_': True,
'/': True
}
}
self._color = color.Color(config.color_options(), self.debug)
def display(self, time, prefix, text, forcecolor=None):
if time == 0:
now = datetime.datetime.now()
else:
now = datetime.datetime.fromtimestamp(float(time))
self.setTextColor(QtGui.QColor('#999999'))
self.insertPlainText(now.strftime('%H:%M '))
prefix = self._color.convert(prefix)
text = self._color.convert(text)
if forcecolor:
if prefix:
prefix = '\x01(F%s)%s' % (forcecolor, prefix)
text = '\x01(F%s)%s' % (forcecolor, text)
if prefix:
self._display_with_colors(prefix + ' ')
if text:
self._display_with_colors(text)
if text[-1:] != '\n':
self.insertPlainText('\n')
else:
self.insertPlainText('\n')
self.scroll_bottom()
def _display_with_colors(self, string):
self.setTextColor(self._textcolor)
self.setTextBackgroundColor(self._bgcolor)
self._reset_attributes()
items = string.split('\x01')
for i, item in enumerate(items):
if i > 0 and item.startswith('('):
pos = item.find(')')
if pos >= 2:
action = item[1]
code = item[2:pos]
if action == '+':
# set attribute
self._set_attribute(code[0], True)
elif action == '-':
# remove attribute
self._set_attribute(code[0], False)
else:
# reset attributes and color
if code == 'r':
self._reset_attributes()
self._setcolorcode[action][0](
self._setcolorcode[action][1])
else:
# set attributes + color
while code.startswith(('*', '!', '/', '_', '|',
'r')):
if code[0] == 'r':
self._reset_attributes()
elif code[0] in self._setfont:
self._set_attribute(
code[0],
not self._font[code[0]])
code = code[1:]
if code:
self._setcolorcode[action][0](
QtGui.QColor(code))
item = item[pos+1:]
if len(item) > 0:
self.insertPlainText(item)
def _reset_attributes(self):
self._font = {}
for attr in self._setfont:
self._set_attribute(attr, False)
def _set_attribute(self, attr, value):
self._font[attr] = value
self._setfont[attr](self._fontvalues[self._font[attr]][attr])
def scroll_bottom(self):
scroll = self.verticalScrollBar()
scroll.setValue(scroll.maximum())

136
toxygen/third_party/qweechat/config.py vendored Normal file
View File

@ -0,0 +1,136 @@
# -*- coding: utf-8 -*-
#
# config.py - configuration for QWeeChat
#
# Copyright (C) 2011-2022 Sébastien Helleu <flashcode@flashtux.org>
#
# This file is part of QWeeChat, a Qt remote GUI for WeeChat.
#
# QWeeChat is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# QWeeChat is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
"""Configuration for QWeeChat."""
import configparser
import os
from pathlib import Path
CONFIG_DIR = '%s/.config/qweechat' % os.getenv('HOME')
CONFIG_FILENAME = '%s/qweechat.conf' % CONFIG_DIR
CONFIG_DEFAULT_RELAY_LINES = 50
CONFIG_DEFAULT_SECTIONS = ('relay', 'look', 'color')
CONFIG_DEFAULT_OPTIONS = (('relay.hostname', '127.0.0.1'),
('relay.port', '9000'),
('relay.ssl', 'off'),
('relay.password', ''),
('relay.autoconnect', 'off'),
('relay.lines', str(CONFIG_DEFAULT_RELAY_LINES)),
('look.debug', 'off'),
('look.statusbar', 'on'))
# Default colors for WeeChat color options (option name, #rgb value)
CONFIG_DEFAULT_COLOR_OPTIONS = (
('separator', '#000066'), # 0
('chat', '#000000'), # 1
('chat_time', '#999999'), # 2
('chat_time_delimiters', '#000000'), # 3
('chat_prefix_error', '#FF6633'), # 4
('chat_prefix_network', '#990099'), # 5
('chat_prefix_action', '#000000'), # 6
('chat_prefix_join', '#00CC00'), # 7
('chat_prefix_quit', '#CC0000'), # 8
('chat_prefix_more', '#CC00FF'), # 9
('chat_prefix_suffix', '#330099'), # 10
('chat_buffer', '#000000'), # 11
('chat_server', '#000000'), # 12
('chat_channel', '#000000'), # 13
('chat_nick', '#000000'), # 14
('chat_nick_self', '*#000000'), # 15
('chat_nick_other', '#000000'), # 16
('', '#000000'), # 17 (nick1 -- obsolete)
('', '#000000'), # 18 (nick2 -- obsolete)
('', '#000000'), # 19 (nick3 -- obsolete)
('', '#000000'), # 20 (nick4 -- obsolete)
('', '#000000'), # 21 (nick5 -- obsolete)
('', '#000000'), # 22 (nick6 -- obsolete)
('', '#000000'), # 23 (nick7 -- obsolete)
('', '#000000'), # 24 (nick8 -- obsolete)
('', '#000000'), # 25 (nick9 -- obsolete)
('', '#000000'), # 26 (nick10 -- obsolete)
('chat_host', '#666666'), # 27
('chat_delimiters', '#9999FF'), # 28
('chat_highlight', '#3399CC'), # 29
('chat_read_marker', '#000000'), # 30
('chat_text_found', '#000000'), # 31
('chat_value', '#000000'), # 32
('chat_prefix_buffer', '#000000'), # 33
('chat_tags', '#000000'), # 34
('chat_inactive_window', '#000000'), # 35
('chat_inactive_buffer', '#000000'), # 36
('chat_prefix_buffer_inactive_buffer', '#000000'), # 37
('chat_nick_offline', '#000000'), # 38
('chat_nick_offline_highlight', '#000000'), # 39
('chat_nick_prefix', '#000000'), # 40
('chat_nick_suffix', '#000000'), # 41
('emphasis', '#000000'), # 42
('chat_day_change', '#000000'), # 43
)
config_color_options = []
def read():
"""Read config file."""
global config_color_options
config = configparser.RawConfigParser()
if os.path.isfile(CONFIG_FILENAME):
config.read(CONFIG_FILENAME)
# add missing sections/options
for section in CONFIG_DEFAULT_SECTIONS:
if not config.has_section(section):
config.add_section(section)
for option in reversed(CONFIG_DEFAULT_OPTIONS):
section, name = option[0].split('.', 1)
if not config.has_option(section, name):
config.set(section, name, option[1])
section = 'color'
for option in reversed(CONFIG_DEFAULT_COLOR_OPTIONS):
if option[0] and not config.has_option(section, option[0]):
config.set(section, option[0], option[1])
# build list of color options
config_color_options = []
for option in CONFIG_DEFAULT_COLOR_OPTIONS:
if option[0]:
config_color_options.append(config.get('color', option[0]))
else:
config_color_options.append('#000000')
return config
def write(config):
"""Write config file."""
Path(CONFIG_DIR).mkdir(mode=0o0700, parents=True, exist_ok=True)
with open(CONFIG_FILENAME, 'w') as cfg:
config.write(cfg)
def color_options():
"""Return color options."""
global config_color_options
return config_color_options

View File

@ -0,0 +1,136 @@
# -*- coding: utf-8 -*-
#
# config.py - configuration for QWeeChat
#
# Copyright (C) 2011-2022 Sébastien Helleu <flashcode@flashtux.org>
#
# This file is part of QWeeChat, a Qt remote GUI for WeeChat.
#
# QWeeChat is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# QWeeChat is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
"""Configuration for QWeeChat."""
import configparser
import os
from pathlib import Path
CONFIG_DIR = '%s/.config/qweechat' % os.getenv('HOME')
CONFIG_FILENAME = '%s/qweechat.conf' % CONFIG_DIR
CONFIG_DEFAULT_RELAY_LINES = 50
CONFIG_DEFAULT_SECTIONS = ('relay', 'look', 'color')
CONFIG_DEFAULT_OPTIONS = (('relay.hostname', ''),
('relay.port', ''),
('relay.ssl', 'off'),
('relay.password', ''),
('relay.autoconnect', 'off'),
('relay.lines', str(CONFIG_DEFAULT_RELAY_LINES)),
('look.debug', 'off'),
('look.statusbar', 'off'))
# Default colors for WeeChat color options (option name, #rgb value)
CONFIG_DEFAULT_COLOR_OPTIONS = (
('separator', '#000066'), # 0
('chat', '#000000'), # 1
('chat_time', '#999999'), # 2
('chat_time_delimiters', '#000000'), # 3
('chat_prefix_error', '#FF6633'), # 4
('chat_prefix_network', '#990099'), # 5
('chat_prefix_action', '#000000'), # 6
('chat_prefix_join', '#00CC00'), # 7
('chat_prefix_quit', '#CC0000'), # 8
('chat_prefix_more', '#CC00FF'), # 9
('chat_prefix_suffix', '#330099'), # 10
('chat_buffer', '#000000'), # 11
('chat_server', '#000000'), # 12
('chat_channel', '#000000'), # 13
('chat_nick', '#000000'), # 14
('chat_nick_self', '*#000000'), # 15
('chat_nick_other', '#000000'), # 16
('', '#000000'), # 17 (nick1 -- obsolete)
('', '#000000'), # 18 (nick2 -- obsolete)
('', '#000000'), # 19 (nick3 -- obsolete)
('', '#000000'), # 20 (nick4 -- obsolete)
('', '#000000'), # 21 (nick5 -- obsolete)
('', '#000000'), # 22 (nick6 -- obsolete)
('', '#000000'), # 23 (nick7 -- obsolete)
('', '#000000'), # 24 (nick8 -- obsolete)
('', '#000000'), # 25 (nick9 -- obsolete)
('', '#000000'), # 26 (nick10 -- obsolete)
('chat_host', '#666666'), # 27
('chat_delimiters', '#9999FF'), # 28
('chat_highlight', '#3399CC'), # 29
('chat_read_marker', '#000000'), # 30
('chat_text_found', '#000000'), # 31
('chat_value', '#000000'), # 32
('chat_prefix_buffer', '#000000'), # 33
('chat_tags', '#000000'), # 34
('chat_inactive_window', '#000000'), # 35
('chat_inactive_buffer', '#000000'), # 36
('chat_prefix_buffer_inactive_buffer', '#000000'), # 37
('chat_nick_offline', '#000000'), # 38
('chat_nick_offline_highlight', '#000000'), # 39
('chat_nick_prefix', '#000000'), # 40
('chat_nick_suffix', '#000000'), # 41
('emphasis', '#000000'), # 42
('chat_day_change', '#000000'), # 43
)
config_color_options = []
def read():
"""Read config file."""
global config_color_options
config = configparser.RawConfigParser()
if os.path.isfile(CONFIG_FILENAME):
config.read(CONFIG_FILENAME)
# add missing sections/options
for section in CONFIG_DEFAULT_SECTIONS:
if not config.has_section(section):
config.add_section(section)
for option in reversed(CONFIG_DEFAULT_OPTIONS):
section, name = option[0].split('.', 1)
if not config.has_option(section, name):
config.set(section, name, option[1])
section = 'color'
for option in reversed(CONFIG_DEFAULT_COLOR_OPTIONS):
if option[0] and not config.has_option(section, option[0]):
config.set(section, option[0], option[1])
# build list of color options
config_color_options = []
for option in CONFIG_DEFAULT_COLOR_OPTIONS:
if option[0]:
config_color_options.append(config.get('color', option[0]))
else:
config_color_options.append('#000000')
return config
def write(config):
"""Write config file."""
Path(CONFIG_DIR).mkdir(mode=0o0700, parents=True, exist_ok=True)
with open(CONFIG_FILENAME, 'w') as cfg:
config.write(cfg)
def color_options():
"""Return color options."""
global config_color_options
return config_color_options

View File

@ -0,0 +1,122 @@
# -*- coding: utf-8 -*-
#
# connection.py - connection window
#
# Copyright (C) 2011-2022 Sébastien Helleu <flashcode@flashtux.org>
#
# This file is part of QWeeChat, a Qt remote GUI for WeeChat.
#
# QWeeChat is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# QWeeChat is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
"""Connection window."""
from PyQt5 import QtGui, QtWidgets
class ConnectionDialog(QtWidgets.QDialog):
"""Connection window."""
def __init__(self, values, *args):
super().__init__(*args)
self.values = values
self.setModal(True)
self.setWindowTitle('Connect to WeeChat')
grid = QtWidgets.QGridLayout()
grid.setSpacing(10)
self.fields = {}
focus = None
# hostname
grid.addWidget(QtWidgets.QLabel('<b>Hostname</b>'), 0, 0)
line_edit = QtWidgets.QLineEdit()
line_edit.setFixedWidth(200)
value = self.values.get('hostname', '')
line_edit.insert(value)
grid.addWidget(line_edit, 0, 1)
self.fields['hostname'] = line_edit
if not focus and not value:
focus = 'hostname'
# port / SSL
grid.addWidget(QtWidgets.QLabel('<b>Port</b>'), 1, 0)
line_edit = QtWidgets.QLineEdit()
line_edit.setFixedWidth(200)
value = self.values.get('port', '')
line_edit.insert(value)
grid.addWidget(line_edit, 1, 1)
self.fields['port'] = line_edit
if not focus and not value:
focus = 'port'
ssl = QtWidgets.QCheckBox('SSL')
ssl.setChecked(self.values['ssl'] == 'on')
grid.addWidget(ssl, 1, 2)
self.fields['ssl'] = ssl
# password
grid.addWidget(QtWidgets.QLabel('<b>Password</b>'), 2, 0)
line_edit = QtWidgets.QLineEdit()
line_edit.setFixedWidth(200)
line_edit.setEchoMode(QtWidgets.QLineEdit.Password)
value = self.values.get('password', '')
line_edit.insert(value)
grid.addWidget(line_edit, 2, 1)
self.fields['password'] = line_edit
if not focus and not value:
focus = 'password'
# TOTP (Time-Based One-Time Password)
label = QtWidgets.QLabel('TOTP')
label.setToolTip('Time-Based One-Time Password (6 digits)')
grid.addWidget(label, 3, 0)
line_edit = QtWidgets.QLineEdit()
line_edit.setPlaceholderText('6 digits')
validator = QtGui.QIntValidator(0, 999999, self)
line_edit.setValidator(validator)
line_edit.setFixedWidth(80)
value = self.values.get('totp', '')
line_edit.insert(value)
grid.addWidget(line_edit, 3, 1)
self.fields['totp'] = line_edit
if not focus and not value:
focus = 'totp'
# lines
grid.addWidget(QtWidgets.QLabel('Lines'), 4, 0)
line_edit = QtWidgets.QLineEdit()
line_edit.setFixedWidth(200)
validator = QtGui.QIntValidator(0, 2147483647, self)
line_edit.setValidator(validator)
line_edit.setFixedWidth(80)
value = self.values.get('lines', '')
line_edit.insert(value)
grid.addWidget(line_edit, 4, 1)
self.fields['lines'] = line_edit
if not focus and not value:
focus = 'lines'
self.dialog_buttons = QtWidgets.QDialogButtonBox()
self.dialog_buttons.setStandardButtons(
QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel)
self.dialog_buttons.rejected.connect(self.close)
grid.addWidget(self.dialog_buttons, 5, 0, 1, 2)
self.setLayout(grid)
self.show()
if focus:
self.fields[focus].setFocus()

View File

@ -0,0 +1,27 @@
*** connection.py.dst 2022-11-19 18:31:51.000000000 +0000
--- connection.py 2022-11-19 18:32:41.000000000 +0000
***************
*** 20,30 ****
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
"""Connection window."""
! from PySide6 import QtGui, QtWidgets
class ConnectionDialog(QtWidgets.QDialog):
"""Connection window."""
--- 20,30 ----
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
"""Connection window."""
! from PyQt5 import QtGui, QtWidgets
class ConnectionDialog(QtWidgets.QDialog):
"""Connection window."""

View File

@ -0,0 +1,122 @@
# -*- coding: utf-8 -*-
#
# connection.py - connection window
#
# Copyright (C) 2011-2022 Sébastien Helleu <flashcode@flashtux.org>
#
# This file is part of QWeeChat, a Qt remote GUI for WeeChat.
#
# QWeeChat is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# QWeeChat is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
"""Connection window."""
from PySide6 import QtGui, QtWidgets
class ConnectionDialog(QtWidgets.QDialog):
"""Connection window."""
def __init__(self, values, *args):
super().__init__(*args)
self.values = values
self.setModal(True)
self.setWindowTitle('Connect to WeeChat')
grid = QtWidgets.QGridLayout()
grid.setSpacing(10)
self.fields = {}
focus = None
# hostname
grid.addWidget(QtWidgets.QLabel('<b>Hostname</b>'), 0, 0)
line_edit = QtWidgets.QLineEdit()
line_edit.setFixedWidth(200)
value = self.values.get('hostname', '')
line_edit.insert(value)
grid.addWidget(line_edit, 0, 1)
self.fields['hostname'] = line_edit
if not focus and not value:
focus = 'hostname'
# port / SSL
grid.addWidget(QtWidgets.QLabel('<b>Port</b>'), 1, 0)
line_edit = QtWidgets.QLineEdit()
line_edit.setFixedWidth(200)
value = self.values.get('port', '')
line_edit.insert(value)
grid.addWidget(line_edit, 1, 1)
self.fields['port'] = line_edit
if not focus and not value:
focus = 'port'
ssl = QtWidgets.QCheckBox('SSL')
ssl.setChecked(self.values['ssl'] == 'on')
grid.addWidget(ssl, 1, 2)
self.fields['ssl'] = ssl
# password
grid.addWidget(QtWidgets.QLabel('<b>Password</b>'), 2, 0)
line_edit = QtWidgets.QLineEdit()
line_edit.setFixedWidth(200)
line_edit.setEchoMode(QtWidgets.QLineEdit.Password)
value = self.values.get('password', '')
line_edit.insert(value)
grid.addWidget(line_edit, 2, 1)
self.fields['password'] = line_edit
if not focus and not value:
focus = 'password'
# TOTP (Time-Based One-Time Password)