fixed qweechat

This commit is contained in:
emdee 2022-11-23 19:23:21 +00:00
parent 0b1eaa1391
commit 948335c8a0
9 changed files with 92 additions and 67 deletions

View File

@ -46,7 +46,7 @@ Toxygen is powerful cross-platform [Tox](https://tox.chat/) client written in pu
## Forked ## Forked
This hard-forked from https://github.com/toxygen-project/toxygen This hard-forked from the dead https://github.com/toxygen-project/toxygen
```next_gen``` branch. ```next_gen``` branch.
https://git.plastiras.org/emdee/toxygen_wrapper needs packaging https://git.plastiras.org/emdee/toxygen_wrapper needs packaging
@ -69,12 +69,15 @@ or
/relay add weechat 9000 /relay add weechat 9000
/relay start weechat /relay start weechat
``` ```
and use the File/Connect menu item to connect to weechat. Weechat and use the Plugins/Weechat Console to start weechat under Toxygen.
has a Jabber plugin to enable XMPP: Then use th File/Connect menu item of the console to connect to weechat.
Weechat has a Jabber plugin to enable XMPP:
``` ```
/python load jabber.el /python load jabber.el
/help jabber /help jabber
``` ```
so you can have Tox, IRC and XMPP in the same application!
Work on Tox on this project is suspended until the Work on Tox on this project is suspended until the
[MultiDevice](https://git.plastiras.org/emdee/tox_profile/wiki/MultiDevice-Announcements-POC) problem is solved. Fork me! [MultiDevice](https://git.plastiras.org/emdee/tox_profile/wiki/MultiDevice-Announcements-POC) problem is solved. Fork me!

View File

@ -24,7 +24,7 @@
from PyQt5 import QtCore, QtWidgets as QtGui from PyQt5 import QtCore, QtWidgets as QtGui
from qweechat.version import qweechat_version from third_party.qweechat.version import qweechat_version
class AboutDialog(QtGui.QDialog): class AboutDialog(QtGui.QDialog):

View File

@ -28,9 +28,9 @@ from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import pyqtSignal from PyQt5.QtCore import pyqtSignal
Signal = pyqtSignal Signal = pyqtSignal
from qweechat.chat import ChatTextEdit from third_party.qweechat.chat import ChatTextEdit
from qweechat.input import InputLineEdit from third_party.qweechat.input import InputLineEdit
from qweechat.weechat import color from third_party.qweechat.weechat import color
class GenericListWidget(QtWidgets.QListWidget): class GenericListWidget(QtWidgets.QListWidget):

View File

@ -26,8 +26,8 @@ import datetime
from PyQt5 import QtCore, QtWidgets, QtGui from PyQt5 import QtCore, QtWidgets, QtGui
from qweechat import config from third_party.qweechat import config
from qweechat.weechat import color from third_party.qweechat.weechat import color
class ChatTextEdit(QtWidgets.QTextEdit): class ChatTextEdit(QtWidgets.QTextEdit):

View File

@ -45,6 +45,7 @@ class ConnectionDialog(QtWidgets.QDialog):
line_edit = QtWidgets.QLineEdit() line_edit = QtWidgets.QLineEdit()
line_edit.setFixedWidth(200) line_edit.setFixedWidth(200)
value = self.values.get('hostname', '') value = self.values.get('hostname', '')
if value in ['None', None]: value = ''
line_edit.insert(value) line_edit.insert(value)
grid.addWidget(line_edit, 0, 1) grid.addWidget(line_edit, 0, 1)
self.fields['hostname'] = line_edit self.fields['hostname'] = line_edit
@ -56,6 +57,10 @@ class ConnectionDialog(QtWidgets.QDialog):
line_edit = QtWidgets.QLineEdit() line_edit = QtWidgets.QLineEdit()
line_edit.setFixedWidth(200) line_edit.setFixedWidth(200)
value = self.values.get('port', '') value = self.values.get('port', '')
if value in ['None', None]:
value = '0'
elif type(value) == int:
value = str(value)
line_edit.insert(value) line_edit.insert(value)
grid.addWidget(line_edit, 1, 1) grid.addWidget(line_edit, 1, 1)
self.fields['port'] = line_edit self.fields['port'] = line_edit
@ -73,6 +78,7 @@ class ConnectionDialog(QtWidgets.QDialog):
line_edit.setFixedWidth(200) line_edit.setFixedWidth(200)
line_edit.setEchoMode(QtWidgets.QLineEdit.Password) line_edit.setEchoMode(QtWidgets.QLineEdit.Password)
value = self.values.get('password', '') value = self.values.get('password', '')
if value in ['None', None]: value = ''
line_edit.insert(value) line_edit.insert(value)
grid.addWidget(line_edit, 2, 1) grid.addWidget(line_edit, 2, 1)
self.fields['password'] = line_edit self.fields['password'] = line_edit

View File

@ -24,8 +24,8 @@
from PyQt5 import QtWidgets from PyQt5 import QtWidgets
from qweechat.chat import ChatTextEdit from third_party.qweechat.chat import ChatTextEdit
from qweechat.input import InputLineEdit from third_party.qweechat.input import InputLineEdit
class DebugDialog(QtWidgets.QDialog): class DebugDialog(QtWidgets.QDialog):

View File

@ -30,8 +30,8 @@ from PyQt5 import QtCore, QtNetwork
from PyQt5.QtCore import pyqtSignal from PyQt5.QtCore import pyqtSignal
Signal = pyqtSignal Signal = pyqtSignal
from qweechat import config from third_party.qweechat import config
from qweechat.debug import DebugDialog from third_party.qweechat.debug import DebugDialog
# list of supported hash algorithms on our side # list of supported hash algorithms on our side

View File

@ -39,13 +39,13 @@ from pkg_resources import resource_filename
from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5 import QtCore, QtGui, QtWidgets
from qweechat import config from third_party.qweechat import config
from qweechat.about import AboutDialog from third_party.qweechat.about import AboutDialog
from qweechat.buffer import BufferListWidget, Buffer from third_party.qweechat.buffer import BufferListWidget, Buffer
from qweechat.connection import ConnectionDialog from third_party.qweechat.connection import ConnectionDialog
from qweechat.network import Network, STATUS_DISCONNECTED from third_party.qweechat.network import Network, STATUS_DISCONNECTED
from qweechat.preferences import PreferencesDialog from third_party.qweechat.preferences import PreferencesDialog
from qweechat.weechat import protocol from third_party.qweechat.weechat import protocol
APP_NAME = 'QWeeChat' APP_NAME = 'QWeeChat'
@ -163,6 +163,13 @@ class MainWindow(QtWidgets.QMainWindow):
self.actions['quit']]) self.actions['quit']])
menu_window = self.menu.addMenu('&Window') menu_window = self.menu.addMenu('&Window')
menu_window.addAction(self.actions['debug']) menu_window.addAction(self.actions['debug'])
name = 'toggle'
menu_window.addAction(
QtWidgets.QAction(QtGui.QIcon(
resource_filename(__name__, 'data/icons/%s' % 'weechat.png')),
name.capitalize(), self))
#? .triggered.connect(self.onMyToolBarButtonClick)
menu_help = self.menu.addMenu('&Help') menu_help = self.menu.addMenu('&Help')
menu_help.addAction(self.actions['about']) menu_help.addAction(self.actions['about'])
self.network_status = QtWidgets.QLabel() self.network_status = QtWidgets.QLabel()
@ -170,23 +177,21 @@ class MainWindow(QtWidgets.QMainWindow):
self.network_status.setFixedWidth(200) self.network_status.setFixedWidth(200)
self.network_status.setContentsMargins(0, 0, 10, 0) self.network_status.setContentsMargins(0, 0, 10, 0)
self.network_status.setAlignment(QtCore.Qt.AlignRight) self.network_status.setAlignment(QtCore.Qt.AlignRight)
if hasattr(self, 'menuBar'): if hasattr(self.menu, 'setCornerWidget'):
if hasattr(self.menu, 'setCornerWidget'): self.menu.setCornerWidget(self.network_status,
self.menu.setCornerWidget(self.network_status, QtCore.Qt.TopRightCorner)
QtCore.Qt.TopRightCorner)
self.network_status_set(STATUS_DISCONNECTED) self.network_status_set(STATUS_DISCONNECTED)
# toolbar # toolbar
if hasattr(self, 'addToolBar'): toolbar = self.addToolBar('toolBar')
toolbar = self.addToolBar('toolBar') toolbar.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
toolbar.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon) toolbar.addActions([self.actions['connect'],
toolbar.addActions([self.actions['connect'], self.actions['disconnect'],
self.actions['disconnect'], self.actions['debug'],
self.actions['debug'], self.actions['preferences'],
self.actions['preferences'], self.actions['about'],
self.actions['about'], self.actions['quit']])
self.actions['quit']]) self.toolbar = toolbar
self.buffers[0].widget.input.setFocus() self.buffers[0].widget.input.setFocus()
# open debug dialog # open debug dialog
@ -198,9 +203,9 @@ class MainWindow(QtWidgets.QMainWindow):
self.network.connect_weechat( self.network.connect_weechat(
hostname=self.config.get('relay', 'hostname', fallback='127.0.0.1'), hostname=self.config.get('relay', 'hostname', fallback='127.0.0.1'),
port=self.config.get('relay', 'port', fallback='9000'), port=self.config.get('relay', 'port', fallback='9000'),
ssl=self.config.getboolean('relay', 'ssl', fallback=''), ssl=self.config.getboolean('relay', 'ssl', fallback=False),
password=self.config.get('relay', 'password', fallback=''), password=self.config.get('relay', 'password', fallback=''),
totp=None, totp=self.config.get('relay', 'password', fallback=''),
lines=self.config.get('relay', 'lines', fallback=''), lines=self.config.get('relay', 'lines', fallback=''),
) )
@ -239,7 +244,10 @@ class MainWindow(QtWidgets.QMainWindow):
"""Open a dialog with connection settings.""" """Open a dialog with connection settings."""
values = {} values = {}
for option in ('hostname', 'port', 'ssl', 'password', 'lines'): for option in ('hostname', 'port', 'ssl', 'password', 'lines'):
values[option] = self.config.get('relay', option, fallback='') val = self.config.get('relay', option, fallback='')
if val in [None, 'None']: val = ''
if option == 'port' and val in [None, 'None']: val = 0
values[option] = val
self.connection_dialog = ConnectionDialog(values, self) self.connection_dialog = ConnectionDialog(values, self)
self.connection_dialog.dialog_buttons.accepted.connect( self.connection_dialog.dialog_buttons.accepted.connect(
self.connect_weechat) self.connect_weechat)
@ -248,13 +256,19 @@ class MainWindow(QtWidgets.QMainWindow):
"""Connect to WeeChat.""" """Connect to WeeChat."""
self.network.connect_weechat( self.network.connect_weechat(
hostname=self.connection_dialog.fields['hostname'].text(), hostname=self.connection_dialog.fields['hostname'].text(),
self.config.set('relay', 'hostname', hostname)
port=self.connection_dialog.fields['port'].text(), port=self.connection_dialog.fields['port'].text(),
ssl=self.connection_dialog.fields['ssl'].isChecked(), ssl=self.connection_dialog.fields['ssl'].isChecked(),
password=self.connection_dialog.fields['password'].text(), password=self.connection_dialog.fields['password'].text(),
totp=self.connection_dialog.fields['totp'].text(), totp=self.connection_dialog.fields['totp'].text(),
lines=int(self.connection_dialog.fields['lines'].text()), lines=int(self.connection_dialog.fields['lines'].text()),
) )
hostname=self.connection_dialog.fields['hostname'].text()
port = self.connection_dialog.fields['port'].text()
ssl=self.connection_dialog.fields['ssl'].isChecked()
password = '' # self.connection_dialog.fields['password'].text()
self.config.set('relay', 'port', port)
self.config.set('relay', 'hostname', hostname)
self.config.set('relay', 'password', password)
self.connection_dialog.close() self.connection_dialog.close()
def _network_status_changed(self, status, extra): def _network_status_changed(self, status, extra):
@ -522,10 +536,10 @@ class MainWindow(QtWidgets.QMainWindow):
if next_buffer == '0x0': if next_buffer == '0x0':
index = len(self.buffers) index = len(self.buffers)
else: else:
index = [i for i, b in enumerate(self.buffers) elts = [i for i, b in enumerate(self.buffers)
if b.pointer() == next_buffer] if b.pointer() == next_buffer]
if index: if len(elts):
index = index[0] index = elts[0]
if index < 0: if index < 0:
print('Warning: unable to find position for buffer, using end of ' print('Warning: unable to find position for buffer, using end of '
'list by default') 'list by default')

View File

@ -686,10 +686,10 @@ class MainWindow(QtWidgets.QMainWindow):
font_width = QFontMetrics(font).width('M') font_width = QFontMetrics(font).width('M')
self._pe.setFont(font) self._pe.setFont(font)
geometry = self._pe.geometry() geometry = self._pe.geometry()
geometry.setWidth(font_width*80+20) geometry.setWidth(font_width*50+20)
geometry.setHeight(font_width*40) geometry.setHeight(font_width*24*13/8)
self._pe.setGeometry(geometry) self._pe.setGeometry(geometry)
self._pe.resize(font_width*80+20, font_width*40) self._pe.resize(font_width*50+20, font_width*24*13/8)
self._pe.show() self._pe.show()
self._pe.eval_queued() self._pe.eval_queued()
@ -699,27 +699,30 @@ class MainWindow(QtWidgets.QMainWindow):
LOG.debug(e) LOG.debug(e)
def weechat_console(self): def weechat_console(self):
if self._we:
self._we.show()
return
LOG.info("Loading WeechatConsole")
from third_party.qweechat import qweechat
from third_party.qweechat import config
try: try:
# WeeChat backported from PySide6 to PyQt5 # WeeChat backported from PySide6 to PyQt5
from third_party.qweechat import MainWindow as MainWindow
from third_party.qweechat import config
LOG.info("Adding WeechatConsole") LOG.info("Adding WeechatConsole")
class WeechatConsole(qweechat.MainWindow):
def __init__(self, *args):
qweechat.MainWindow.__init__(self, *args)
def closeEvent(self, event):
"""Called when QWeeChat window is closed."""
self.network.disconnect_weechat()
if self.network.debug_dialog:
self.network.debug_dialog.close()
qweechat.config.write(self.config)
except Exception as e: except Exception as e:
LOG.exception(f"ERROR WeechatConsole {e}") LOG.exception(f"ERROR WeechatConsole {e}")
MainWindow = None MainWindow = None
return return
LOG.debug(f"calling {MainWindow}")
if not MainWindow: return
class WeechatConsole(MainWindow):
def __init__(self, *args):
MainWindow.__init__(self, *args)
def closeEvent(self, event):
"""Called when QWeeChat window is closed."""
self.network.disconnect_weechat()
if self.network.debug_dialog:
self.network.debug_dialog.close()
config.write(self.config)
app = self._app app = self._app
if app and app._settings: if app and app._settings:
size = app._settings['message_font_size'] size = app._settings['message_font_size']
@ -728,15 +731,13 @@ class MainWindow(QtWidgets.QMainWindow):
size = 12 size = 12
font_name = "Courier New" font_name = "Courier New"
size = font_width = 10
font_name = "DejaVu Sans Mono" font_name = "DejaVu Sans Mono"
try: try:
if not self._we: LOG.info("Creating WeechatConsole")
LOG.debug("creating WeechatConsole") self._we = WeechatConsole()
self._we = WeechatConsole() self._we.show()
# self._we.setWindowTitle('variable: app is the application') self._we.setWindowTitle('File/Connect to 127.0.0.1:9000')
# self._we.edit.setStyleSheet('foreground: white; background-color: black;}')
# Fix the pyconsole geometry # Fix the pyconsole geometry
try: try:
font = self._we.buffers[0].widget.chat.defaultFont() font = self._we.buffers[0].widget.chat.defaultFont()
@ -746,19 +747,20 @@ class MainWindow(QtWidgets.QMainWindow):
font_width = QFontMetrics(font).width('M') font_width = QFontMetrics(font).width('M')
self._we.setFont(font) self._we.setFont(font)
except Exception as e: except Exception as e:
LOG.debug(e) # LOG.debug(e)
font_width = size font_width = size
geometry = self._we.geometry() geometry = self._we.geometry()
geometry.setWidth(font_width*80+20) geometry.setWidth(font_width*80+20)
geometry.setHeight(font_width*40) geometry.setHeight(font_width*(2+24)*11/8)
self._we.setGeometry(geometry) self._we.setGeometry(geometry)
self._we.resize(font_width*80+20, font_width*40) self._we.resize(font_width*80+20, font_width*(2+24)*11/8)
self._we.list_buffers.setSizePolicy(QtWidgets.QSizePolicy.Preferred, self._we.list_buffers.setSizePolicy(QtWidgets.QSizePolicy.Preferred,
QtWidgets.QSizePolicy.Preferred) QtWidgets.QSizePolicy.Preferred)
self._we.stacked_buffers.setSizePolicy(QtWidgets.QSizePolicy.Expanding, self._we.stacked_buffers.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
QtWidgets.QSizePolicy.Expanding) QtWidgets.QSizePolicy.Expanding)
LOG.info("Showing WeechatConsole")
self._we.show() self._we.show()
# or self._we.eval_in_thread() # or self._we.eval_in_thread()
return return