diff --git a/README.md b/README.md index 7985dc0..d24f14b 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Toxygen is powerful cross-platform [Tox](https://tox.chat/) client written in pu ## 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. https://git.plastiras.org/emdee/toxygen_wrapper needs packaging @@ -69,12 +69,15 @@ or /relay add weechat 9000 /relay start weechat ``` -and use the File/Connect menu item to connect to weechat. Weechat -has a Jabber plugin to enable XMPP: +and use the Plugins/Weechat Console to start weechat under Toxygen. +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 /help jabber ``` +so you can have Tox, IRC and XMPP in the same application! 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! diff --git a/toxygen/third_party/qweechat/about.py b/toxygen/third_party/qweechat/about.py index ac28af0..5754136 100644 --- a/toxygen/third_party/qweechat/about.py +++ b/toxygen/third_party/qweechat/about.py @@ -24,7 +24,7 @@ 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): diff --git a/toxygen/third_party/qweechat/buffer.py b/toxygen/third_party/qweechat/buffer.py index b51afd6..b948133 100644 --- a/toxygen/third_party/qweechat/buffer.py +++ b/toxygen/third_party/qweechat/buffer.py @@ -28,9 +28,9 @@ 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 +from third_party.qweechat.chat import ChatTextEdit +from third_party.qweechat.input import InputLineEdit +from third_party.qweechat.weechat import color class GenericListWidget(QtWidgets.QListWidget): diff --git a/toxygen/third_party/qweechat/chat.py b/toxygen/third_party/qweechat/chat.py index 328de1a..50ed52e 100644 --- a/toxygen/third_party/qweechat/chat.py +++ b/toxygen/third_party/qweechat/chat.py @@ -26,8 +26,8 @@ import datetime from PyQt5 import QtCore, QtWidgets, QtGui -from qweechat import config -from qweechat.weechat import color +from third_party.qweechat import config +from third_party.qweechat.weechat import color class ChatTextEdit(QtWidgets.QTextEdit): diff --git a/toxygen/third_party/qweechat/connection.py b/toxygen/third_party/qweechat/connection.py index 43d898f..3b44aab 100644 --- a/toxygen/third_party/qweechat/connection.py +++ b/toxygen/third_party/qweechat/connection.py @@ -45,6 +45,7 @@ class ConnectionDialog(QtWidgets.QDialog): line_edit = QtWidgets.QLineEdit() line_edit.setFixedWidth(200) value = self.values.get('hostname', '') + if value in ['None', None]: value = '' line_edit.insert(value) grid.addWidget(line_edit, 0, 1) self.fields['hostname'] = line_edit @@ -56,6 +57,10 @@ class ConnectionDialog(QtWidgets.QDialog): line_edit = QtWidgets.QLineEdit() line_edit.setFixedWidth(200) value = self.values.get('port', '') + if value in ['None', None]: + value = '0' + elif type(value) == int: + value = str(value) line_edit.insert(value) grid.addWidget(line_edit, 1, 1) self.fields['port'] = line_edit @@ -73,6 +78,7 @@ class ConnectionDialog(QtWidgets.QDialog): line_edit.setFixedWidth(200) line_edit.setEchoMode(QtWidgets.QLineEdit.Password) value = self.values.get('password', '') + if value in ['None', None]: value = '' line_edit.insert(value) grid.addWidget(line_edit, 2, 1) self.fields['password'] = line_edit diff --git a/toxygen/third_party/qweechat/debug.py b/toxygen/third_party/qweechat/debug.py index 785be98..a55f8f3 100644 --- a/toxygen/third_party/qweechat/debug.py +++ b/toxygen/third_party/qweechat/debug.py @@ -24,8 +24,8 @@ from PyQt5 import QtWidgets -from qweechat.chat import ChatTextEdit -from qweechat.input import InputLineEdit +from third_party.qweechat.chat import ChatTextEdit +from third_party.qweechat.input import InputLineEdit class DebugDialog(QtWidgets.QDialog): diff --git a/toxygen/third_party/qweechat/network.py b/toxygen/third_party/qweechat/network.py index 5e3fe65..d17d330 100644 --- a/toxygen/third_party/qweechat/network.py +++ b/toxygen/third_party/qweechat/network.py @@ -30,8 +30,8 @@ from PyQt5 import QtCore, QtNetwork from PyQt5.QtCore import pyqtSignal Signal = pyqtSignal -from qweechat import config -from qweechat.debug import DebugDialog +from third_party.qweechat import config +from third_party.qweechat.debug import DebugDialog # list of supported hash algorithms on our side diff --git a/toxygen/third_party/qweechat/qweechat.py b/toxygen/third_party/qweechat/qweechat.py index 98187be..9b057bd 100644 --- a/toxygen/third_party/qweechat/qweechat.py +++ b/toxygen/third_party/qweechat/qweechat.py @@ -39,13 +39,13 @@ from pkg_resources import resource_filename from PyQt5 import QtCore, QtGui, QtWidgets -from qweechat import config -from qweechat.about import AboutDialog -from qweechat.buffer import BufferListWidget, Buffer -from qweechat.connection import ConnectionDialog -from qweechat.network import Network, STATUS_DISCONNECTED -from qweechat.preferences import PreferencesDialog -from qweechat.weechat import protocol +from third_party.qweechat import config +from third_party.qweechat.about import AboutDialog +from third_party.qweechat.buffer import BufferListWidget, Buffer +from third_party.qweechat.connection import ConnectionDialog +from third_party.qweechat.network import Network, STATUS_DISCONNECTED +from third_party.qweechat.preferences import PreferencesDialog +from third_party.qweechat.weechat import protocol APP_NAME = 'QWeeChat' @@ -163,6 +163,13 @@ class MainWindow(QtWidgets.QMainWindow): self.actions['quit']]) menu_window = self.menu.addMenu('&Window') 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.addAction(self.actions['about']) self.network_status = QtWidgets.QLabel() @@ -170,23 +177,21 @@ class MainWindow(QtWidgets.QMainWindow): self.network_status.setFixedWidth(200) self.network_status.setContentsMargins(0, 0, 10, 0) self.network_status.setAlignment(QtCore.Qt.AlignRight) - if hasattr(self, 'menuBar'): - if hasattr(self.menu, 'setCornerWidget'): - self.menu.setCornerWidget(self.network_status, - QtCore.Qt.TopRightCorner) + if hasattr(self.menu, 'setCornerWidget'): + self.menu.setCornerWidget(self.network_status, + QtCore.Qt.TopRightCorner) self.network_status_set(STATUS_DISCONNECTED) # toolbar - if hasattr(self, 'addToolBar'): - toolbar = self.addToolBar('toolBar') - toolbar.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon) - toolbar.addActions([self.actions['connect'], - self.actions['disconnect'], - self.actions['debug'], - self.actions['preferences'], - self.actions['about'], - self.actions['quit']]) - + toolbar = self.addToolBar('toolBar') + toolbar.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon) + toolbar.addActions([self.actions['connect'], + self.actions['disconnect'], + self.actions['debug'], + self.actions['preferences'], + self.actions['about'], + self.actions['quit']]) + self.toolbar = toolbar self.buffers[0].widget.input.setFocus() # open debug dialog @@ -198,9 +203,9 @@ class MainWindow(QtWidgets.QMainWindow): self.network.connect_weechat( hostname=self.config.get('relay', 'hostname', fallback='127.0.0.1'), 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=''), - totp=None, + totp=self.config.get('relay', 'password', fallback=''), lines=self.config.get('relay', 'lines', fallback=''), ) @@ -239,7 +244,10 @@ class MainWindow(QtWidgets.QMainWindow): """Open a dialog with connection settings.""" values = {} 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.dialog_buttons.accepted.connect( self.connect_weechat) @@ -248,13 +256,19 @@ class MainWindow(QtWidgets.QMainWindow): """Connect to WeeChat.""" self.network.connect_weechat( hostname=self.connection_dialog.fields['hostname'].text(), - self.config.set('relay', 'hostname', hostname) port=self.connection_dialog.fields['port'].text(), ssl=self.connection_dialog.fields['ssl'].isChecked(), password=self.connection_dialog.fields['password'].text(), totp=self.connection_dialog.fields['totp'].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() def _network_status_changed(self, status, extra): @@ -522,10 +536,10 @@ class MainWindow(QtWidgets.QMainWindow): if next_buffer == '0x0': index = len(self.buffers) 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 index: - index = index[0] + if len(elts): + index = elts[0] if index < 0: print('Warning: unable to find position for buffer, using end of ' 'list by default') diff --git a/toxygen/ui/main_screen.py b/toxygen/ui/main_screen.py index a7e6f99..4bdc4dc 100644 --- a/toxygen/ui/main_screen.py +++ b/toxygen/ui/main_screen.py @@ -686,10 +686,10 @@ class MainWindow(QtWidgets.QMainWindow): font_width = QFontMetrics(font).width('M') self._pe.setFont(font) geometry = self._pe.geometry() - geometry.setWidth(font_width*80+20) - geometry.setHeight(font_width*40) + geometry.setWidth(font_width*50+20) + geometry.setHeight(font_width*24*13/8) 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.eval_queued() @@ -699,27 +699,30 @@ class MainWindow(QtWidgets.QMainWindow): LOG.debug(e) 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: # WeeChat backported from PySide6 to PyQt5 - from third_party.qweechat import MainWindow as MainWindow - from third_party.qweechat import config 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: LOG.exception(f"ERROR WeechatConsole {e}") MainWindow = None 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 if app and app._settings: size = app._settings['message_font_size'] @@ -728,15 +731,13 @@ class MainWindow(QtWidgets.QMainWindow): size = 12 font_name = "Courier New" - size = font_width = 10 font_name = "DejaVu Sans Mono" try: - if not self._we: - LOG.debug("creating WeechatConsole") - self._we = WeechatConsole() -# self._we.setWindowTitle('variable: app is the application') -# self._we.edit.setStyleSheet('foreground: white; background-color: black;}') + LOG.info("Creating WeechatConsole") + self._we = WeechatConsole() + self._we.show() + self._we.setWindowTitle('File/Connect to 127.0.0.1:9000') # Fix the pyconsole geometry try: font = self._we.buffers[0].widget.chat.defaultFont() @@ -746,19 +747,20 @@ class MainWindow(QtWidgets.QMainWindow): font_width = QFontMetrics(font).width('M') self._we.setFont(font) except Exception as e: - LOG.debug(e) +# LOG.debug(e) font_width = size geometry = self._we.geometry() 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.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, QtWidgets.QSizePolicy.Preferred) self._we.stacked_buffers.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) + LOG.info("Showing WeechatConsole") self._we.show() # or self._we.eval_in_thread() return