mirror of
https://github.com/jdegenstein/jmwright-CQ-Editor.git
synced 2025-12-19 22:24:19 +01:00
from jmwright 72b67da
This commit is contained in:
43
cq_editor/widgets/log.py
Normal file
43
cq_editor/widgets/log.py
Normal 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)
|
||||
Reference in New Issue
Block a user