Changed logging label to logging textedit
This commit is contained in:
parent
391562fd3a
commit
dcab27bf96
2 changed files with 37 additions and 18 deletions
|
@ -208,7 +208,7 @@ class Client:
|
||||||
self.skipped.append(data["uuid"])
|
self.skipped.append(data["uuid"])
|
||||||
|
|
||||||
entry = Entry(**data)
|
entry = Entry(**data)
|
||||||
print("Skipping: ", entry.title)
|
logger.info("Skipping: %s", entry.title)
|
||||||
source = self.sources[entry.source]
|
source = self.sources[entry.source]
|
||||||
|
|
||||||
await source.skip_current(Entry(**data))
|
await source.skip_current(Entry(**data))
|
||||||
|
|
53
syng/gui.py
53
syng/gui.py
|
@ -27,7 +27,7 @@ except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
from qasync import QEventLoop, QApplication
|
from qasync import QEventLoop, QApplication
|
||||||
from PyQt6.QtCore import QTimer, Qt
|
from PyQt6.QtCore import QObject, QTimer, Qt, pyqtSignal, pyqtSlot
|
||||||
from PyQt6.QtGui import QCloseEvent, QIcon, QPixmap
|
from PyQt6.QtGui import QCloseEvent, QIcon, QPixmap
|
||||||
from PyQt6.QtWidgets import (
|
from PyQt6.QtWidgets import (
|
||||||
QCheckBox,
|
QCheckBox,
|
||||||
|
@ -47,6 +47,7 @@ from PyQt6.QtWidgets import (
|
||||||
QSpinBox,
|
QSpinBox,
|
||||||
QTabBar,
|
QTabBar,
|
||||||
QTabWidget,
|
QTabWidget,
|
||||||
|
QTextEdit,
|
||||||
QVBoxLayout,
|
QVBoxLayout,
|
||||||
QWidget,
|
QWidget,
|
||||||
)
|
)
|
||||||
|
@ -207,6 +208,7 @@ class OptionFrame(QWidget):
|
||||||
label = QLabel(description, self)
|
label = QLabel(description, self)
|
||||||
|
|
||||||
self.int_options[name] = QSpinBox(self)
|
self.int_options[name] = QSpinBox(self)
|
||||||
|
self.int_options[name].setMaximum(9999)
|
||||||
self.int_options[name].setValue(value)
|
self.int_options[name].setValue(value)
|
||||||
self.form_layout.addRow(label, self.int_options[name])
|
self.form_layout.addRow(label, self.int_options[name])
|
||||||
self.rows[name] = (label, self.int_options[name])
|
self.rows[name] = (label, self.int_options[name])
|
||||||
|
@ -490,6 +492,8 @@ class SyngGui(QMainWindow):
|
||||||
if self.client is not None:
|
if self.client is not None:
|
||||||
self.client.quit_callback()
|
self.client.quit_callback()
|
||||||
|
|
||||||
|
self.log_label_handler.cleanup()
|
||||||
|
|
||||||
self.destroy()
|
self.destroy()
|
||||||
|
|
||||||
def add_buttons(self, show_advanced: bool) -> None:
|
def add_buttons(self, show_advanced: bool) -> None:
|
||||||
|
@ -588,7 +592,9 @@ class SyngGui(QMainWindow):
|
||||||
|
|
||||||
self.qr_label = QLabel(self.qr_widget)
|
self.qr_label = QLabel(self.qr_widget)
|
||||||
self.linklabel = QLabel(self.qr_widget)
|
self.linklabel = QLabel(self.qr_widget)
|
||||||
self.notification_label = QLabel("", self.qr_widget)
|
self.notification_label = QTextEdit(self.qr_widget)
|
||||||
|
self.notification_label.setReadOnly(True)
|
||||||
|
# QLabel("", self.qr_widget)
|
||||||
|
|
||||||
self.qr_layout.addWidget(self.qr_label)
|
self.qr_layout.addWidget(self.qr_label)
|
||||||
self.qr_layout.addWidget(self.linklabel)
|
self.qr_layout.addWidget(self.linklabel)
|
||||||
|
@ -641,6 +647,14 @@ class SyngGui(QMainWindow):
|
||||||
|
|
||||||
self.update_qr()
|
self.update_qr()
|
||||||
|
|
||||||
|
self.logqueue: Queue[logging.LogRecord] = Queue()
|
||||||
|
logger.addHandler(QueueHandler(self.logqueue))
|
||||||
|
self.log_label_handler = LoggingLabelHandler(self)
|
||||||
|
self.log_label_handler.log_signal_emiter.log_signal.connect(self.print_log)
|
||||||
|
|
||||||
|
self.syng_client_logging_listener = QueueListener(self.logqueue, self.log_label_handler)
|
||||||
|
self.syng_client_logging_listener.start()
|
||||||
|
|
||||||
self.setCentralWidget(self.central_widget)
|
self.setCentralWidget(self.central_widget)
|
||||||
|
|
||||||
self.timer = QTimer()
|
self.timer = QTimer()
|
||||||
|
@ -755,26 +769,23 @@ class SyngGui(QMainWindow):
|
||||||
self.startbutton.setText("Save and Start")
|
self.startbutton.setText("Save and Start")
|
||||||
|
|
||||||
def start_syng_client(self) -> None:
|
def start_syng_client(self) -> None:
|
||||||
|
logger.debug("Starting client")
|
||||||
if self.client is None or not self.client.is_running:
|
if self.client is None or not self.client.is_running:
|
||||||
self.save_config()
|
self.save_config()
|
||||||
config = self.gather_config()
|
config = self.gather_config()
|
||||||
queue: Queue[logging.LogRecord] = Queue()
|
|
||||||
|
|
||||||
self.syng_client_logging_listener = QueueListener(
|
|
||||||
queue, LoggingLabelHandler(self.notification_label)
|
|
||||||
)
|
|
||||||
self.syng_client_logging_listener.start()
|
|
||||||
|
|
||||||
logger.addHandler(QueueHandler(queue))
|
|
||||||
self.client = Client(config)
|
self.client = Client(config)
|
||||||
asyncio.run_coroutine_threadsafe(self.client.start_client(config), self.loop)
|
asyncio.run_coroutine_threadsafe(self.client.start_client(config), self.loop)
|
||||||
self.notification_label.setText("")
|
# self.notification_label.setText("")
|
||||||
self.timer.start(500)
|
self.timer.start(500)
|
||||||
self.set_client_button_stop()
|
self.set_client_button_stop()
|
||||||
else:
|
else:
|
||||||
self.client.quit_callback()
|
self.client.quit_callback()
|
||||||
self.set_client_button_start()
|
self.set_client_button_start()
|
||||||
|
|
||||||
|
@pyqtSlot(str)
|
||||||
|
def print_log(self, log: str) -> None:
|
||||||
|
self.notification_label.append(f"[{datetime.now().strftime('%H:%M:%S')}] {log}")
|
||||||
|
|
||||||
def change_qr(self, data: str) -> None:
|
def change_qr(self, data: str) -> None:
|
||||||
qr = QRCode(box_size=10, border=2)
|
qr = QRCode(box_size=10, border=2)
|
||||||
qr.add_data(data)
|
qr.add_data(data)
|
||||||
|
@ -799,15 +810,23 @@ class SyngGui(QMainWindow):
|
||||||
|
|
||||||
|
|
||||||
class LoggingLabelHandler(logging.Handler):
|
class LoggingLabelHandler(logging.Handler):
|
||||||
def __init__(self, label: QLabel):
|
class LogSignalEmiter(QObject):
|
||||||
|
log_signal = pyqtSignal(str)
|
||||||
|
|
||||||
|
def __init__(self, parent: Optional[QObject] = None):
|
||||||
|
super().__init__(parent)
|
||||||
|
|
||||||
|
def __init__(self, parent: Optional[QObject] = None):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.loglines: list[str] = []
|
self.log_signal_emiter = self.LogSignalEmiter(parent)
|
||||||
self.label = label
|
self._cleanup = False
|
||||||
|
|
||||||
def emit(self, record: logging.LogRecord) -> None:
|
def emit(self, record: logging.LogRecord) -> None:
|
||||||
self.loglines.append(self.format(record))
|
if not self._cleanup:
|
||||||
self.loglines = self.loglines[-5:]
|
self.log_signal_emiter.log_signal.emit(self.format(record))
|
||||||
self.label.setText("\n".join(self.loglines))
|
|
||||||
|
def cleanup(self) -> None:
|
||||||
|
self._cleanup = True
|
||||||
|
|
||||||
|
|
||||||
def run_gui() -> None:
|
def run_gui() -> None:
|
||||||
|
|
Loading…
Add table
Reference in a new issue