from jmwright 72b67da

This commit is contained in:
jdegenstein
2022-09-16 13:52:44 -05:00
committed by GitHub
parent 04978a6f78
commit fffb6db0f2
50 changed files with 14900 additions and 0 deletions

43
cq_editor/widgets/log.py Normal file
View File

@@ -0,0 +1,43 @@
import logbook as logging
from PyQt5.QtWidgets import QPlainTextEdit
from PyQt5 import QtCore
from ..mixins import ComponentMixin
class QtLogHandler(logging.Handler,logging.StringFormatterHandlerMixin):
def __init__(self, log_widget,*args,**kwargs):
super(QtLogHandler,self).__init__(*args,**kwargs)
logging.StringFormatterHandlerMixin.__init__(self,None)
self.log_widget = log_widget
def emit(self, record):
msg = self.format(record)
QtCore.QMetaObject\
.invokeMethod(self.log_widget,
'appendPlainText',
QtCore.Qt.QueuedConnection,
QtCore.Q_ARG(str, msg))
class LogViewer(QPlainTextEdit, ComponentMixin):
name = 'Log viewer'
def __init__(self,*args,**kwargs):
super(LogViewer,self).__init__(*args,**kwargs)
self._MAX_ROWS = 500
self.setReadOnly(True)
self.setMaximumBlockCount(self._MAX_ROWS)
self.setLineWrapMode(QPlainTextEdit.NoWrap)
self.handler = QtLogHandler(self)
def append(self,msg):
self.appendPlainText(msg)