fishyboteso/fishy/gui/log_config.py
DESKTOP-JVKHS7I\Adam 3e96fbed2c 0.3.3 reworked notifications again (now uses discord chat)
- fixed ui scaling issues
- now uses callables for thread comunication instead of enums (removed comms.py altogether)
- added options to run using test server
2020-05-19 10:56:50 +05:30

29 lines
837 B
Python

from logging import StreamHandler
import typing
if typing.TYPE_CHECKING:
from . import GUI
class GUIStreamHandler(StreamHandler):
def __init__(self, gui):
StreamHandler.__init__(self)
self.gui = gui
def emit(self, record):
msg = self.format(record)
self.gui.call_in_thread(lambda: _write_to_console(self.gui, msg))
def _write_to_console(root: 'GUI', msg):
numlines = root._console.index('end - 1 line').split('.')[0]
root._console['state'] = 'normal'
if int(numlines) >= 50: # delete old lines
root._console.delete(1.0, 2.0)
if root._console.index('end-1c') != '1.0': # new line for each log
root._console.insert('end', '\n')
root._console.insert('end', msg)
root._console.see("end") # scroll to bottom
root._console['state'] = 'disabled'