You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
3.8 KiB
Python

import os
import sys
import traceback
import logging
from qtpy import QtWidgets, QtGui, QtCore
from qtpy.QtWidgets import QApplication
global LOG
LOG = logging.getLogger('qweechat')
def iMain(lArgs=None):
try:
from qweechat import qweechat
from qweechat.config import write
LOG.info("Loading WeechatConsole")
except ImportError as e:
LOG.error(f"ImportError Loading import qweechat {e} {sys.path}")
LOG.debug(traceback.print_exc())
return 1
from qtpy.QtWidgets import QApplication
_app = QApplication([])
# is this still needed?
if sys.platform == 'Linux' and \
hasattr(QtCore.Qt, 'AA_X11InitThreads'):
QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_X11InitThreads)
try:
# WeeChat backported from PySide6 to PyQt5
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()
write(self.config)
except Exception as e:
LOG.exception(f"ERROR WeechatConsole {e}")
MainWindow = None
return 2
size = 12
font_name = "Courier New"
font_name = "DejaVu Sans Mono"
try:
LOG.info("Creating WeechatConsole")
_we = WeechatConsole()
_we.show()
_we.setWindowTitle('File/Connect to 127.0.0.1:9000')
# Fix the pyconsole geometry
try:
font = _we.buffers[0].widget.chat.defaultFont()
font.setFamily(font_name)
font.setBold(True)
if font_width is None:
font_width = QFontMetrics(font).width('M')
_we.setFont(font)
except Exception as e:
# LOG.debug(e)
font_width = size
geometry = _we.geometry()
# make this configable?
geometry.setWidth(int(font_width*70))
geometry.setHeight(int(font_width*(2+24)*11/8))
_we.setGeometry(geometry)
#? QtCore.QSize()
_we.resize(int(font_width*80+20), int(font_width*(2+24)*11/8))
_we.list_buffers.setSizePolicy(QtWidgets.QSizePolicy.Preferred,
QtWidgets.QSizePolicy.Preferred)
_we.stacked_buffers.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
QtWidgets.QSizePolicy.Expanding)
LOG.info("Showing WeechatConsole")
_we.show()
# or _we.eval_in_thread()
#? return 0
except Exception as e:
LOG.exception(f"Error creating WeechatConsole {e}")
return 4
LOG.info("_execute_app")
# self._app.lastWindowClosed.connect(self._app.quit)
while True:
try:
_app.exec_()
except Exception as ex:
LOG.error('Unhandled exception: ' + str(ex))
return 5
else:
pass # break
if __name__ == '__main__':
iRet = 0
try:
iRet = iMain(sys.argv[1:])
except KeyboardInterrupt:
iRet = 0
except SystemExit as e:
iRet = e
except Exception as e:
import traceback
sys.stderr.write(f"Exception from main {e}" \
+'\n' + traceback.format_exc() +'\n' )
iRet = 1
# Exception ignored in: <module 'threading' from '/usr/lib/python3.9/threading.py'>
# File "/usr/lib/python3.9/threading.py", line 1428, in _shutdown
# lock.acquire()
# gevent.exceptions.LoopExit as e:
# This operation would block forever
# sys.stderr.write('Calling sys.exit' +'\n')
# sys.exit(iRet)