Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions src/cfclient/ui/tabs/LogClientTab.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,32 @@
Shows information from the Python logging framework
"""

from __future__ import annotations

import logging

from PySide6.QtUiTools import loadUiType
from PySide6.QtCore import Signal
from PySide6.QtCore import Signal, SignalInstance

import cfclient
from cfclient.ui.pluginhelper import PluginHelper
from cfclient.ui.tab_toolbox import TabToolbox

__author__ = 'Bitcraze AB'
__all__ = ['LogClientTab']
__author__ = "Bitcraze AB"
__all__ = ["LogClientTab"]

logger = logging.getLogger(__name__)

log_client_tab_class = loadUiType(cfclient.module_path + "/ui/tabs/logClientTab.ui")[0]


class LogHandler(logging.StreamHandler):
def __init__(self, signal):
def __init__(self, signal: SignalInstance) -> None:
logging.StreamHandler.__init__(self)
self._signal = signal

def emit(self, record):
fmt = '%(levelname)s:%(name)s:%(message)s'
def emit(self, record: logging.LogRecord) -> None:
fmt = "%(levelname)s:%(name)s:%(message)s"
formatter = logging.Formatter(fmt)
#
# Calling .emit() on the signal will make the callback
Expand All @@ -65,10 +68,11 @@ class LogClientTab(TabToolbox, log_client_tab_class):
A tab for showing client logging information, such
as USB Gamepad connections or scan feedback.
"""

_update = Signal(str)

def __init__(self, helper):
super(LogClientTab, self).__init__(helper, 'Log Client')
def __init__(self, helper: PluginHelper) -> None:
super(LogClientTab, self).__init__(helper, "Log Client")
self.setupUi(self)

self._update.connect(self.printText)
Expand All @@ -77,9 +81,9 @@ def __init__(self, helper):
cflogger = logging.getLogger(None)
cflogger.addHandler(LogHandler(self._update))

def printText(self, text):
def printText(self, text: str) -> None:
logger.debug("[%s]", text)
self.syslog.insertPlainText(text + '\n')
self.syslog.insertPlainText(text + "\n")

def clear(self):
def clear(self) -> None:
self.syslog.clear()
6 changes: 4 additions & 2 deletions src/cfclient/ui/tabs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@
# from .CrtpSharkToolbox import CrtpSharkToolbox
# from .ExampleTab import ExampleTab
from .FlightTab import FlightTab

# from .GpsTab import GpsTab
# from .LEDRingTab import LEDRingTab
# from .LogBlockTab import LogBlockTab
# from .LogTab import LogTab
from .ParamTab import ParamTab

# from .PlotTab import PlotTab
# from .locopositioning_tab import LocoPositioningTab
# from .LogClientTab import LogClientTab
from .LogClientTab import LogClientTab
# from .lighthouse_tab import LighthouseTab
# from .TuningTab import TuningTab
# from .ColorLEDTab import ColorLEDTab
Expand All @@ -63,7 +65,7 @@
# PlotTab,
# LocoPositioningTab,
# LighthouseTab,
# LogClientTab,
LogClientTab,
# TuningTab,
# CrtpSharkToolbox,
]
Loading