Skip to content

Commit

Permalink
Add verbose mode status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
sam210723 committed May 5, 2024
1 parent 063bd9f commit e9a0c1f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
2 changes: 0 additions & 2 deletions wavebin/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Oscilloscope waveform capture viewer
"""


import argparse
import importlib.util
import logging
Expand Down Expand Up @@ -41,7 +40,6 @@ def main() -> None:
" | | /| / / __ `/ | / / _ \\/ __ \\/ / __ \\\n" +
" | |/ |/ / /_/ /| |/ / __/ /_/ / / / / / \n" +
f" |__/|__/\\__,_/ |___/\\___/_.___/_/_/ /_/ v{config.app.version}\n\n" +
f" Oscilloscope waveform capture viewer\n" +
" https://wavebin.vksdr.com\n\n"
)

Expand Down
35 changes: 31 additions & 4 deletions wavebin/interface/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import logging
from pathlib import Path
from PyQt6.QtWidgets import QApplication, QLabel, QMainWindow, QPushButton, QWidget, QGridLayout, QFileDialog, QTextEdit, QMessageBox
from PyQt6.QtWidgets import QApplication, QLabel, QMainWindow, QPushButton, QWidget, QGridLayout, QFileDialog, QTextEdit, QMessageBox, QStatusBar
from PyQt6.QtCore import Qt, QEvent, QRect
from PyQt6.QtGui import QFontDatabase, QIcon, QKeyEvent, QResizeEvent
import qtawesome as qta
Expand Down Expand Up @@ -74,6 +74,20 @@ def __init__(self) -> None:
self.tool_bar = MainToolBar(self)
self.window.addToolBar(Qt.ToolBarArea.TopToolBarArea, self.tool_bar)

# Add status bar to main window if verbose logging enabled
if logging.getLogger().handlers[1].level == logging.DEBUG:
logging.debug("Building tool bar")
self.status_label = QLabel()
self.status_label.setStyleSheet("background-color: #222; color: white;")
self.status_bar = QStatusBar()
self.status_bar.addPermanentWidget(self.status_label)
self.status_bar.setSizeGripEnabled(False)
self.status_bar.setLayoutDirection(Qt.LayoutDirection.RightToLeft)
self.status_bar.setContentsMargins(6, 0, 0, 2)
self.status_bar.setStyleSheet("QStatusBar { background-color: #222; color: white; } QStatusBar::item { border: None; }")
logging.getLogger().addHandler(StatusHandler(self.status_label))
self.window.setStatusBar(self.status_bar)

# Add menu bar to main window
logging.debug("Building menu bar")
self.menu_bar = MainMenuBar(self.tool_bar)
Expand Down Expand Up @@ -245,8 +259,8 @@ def update(self) -> None:
logging.debug("Resetting main grid layout")
while self.layout.count():
child = self.layout.takeAt(0)
if child.widget():
child.widget().deleteLater()
if child.widget(): # type: ignore
child.widget().deleteLater() # type: ignore

# Set file name in window title
self.window.setWindowTitle(config.file.name)
Expand Down Expand Up @@ -285,7 +299,7 @@ def update(self) -> None:
# Enable export and properties toolbar buttons
self.tool_bar.items['export'].setEnabled(True)
self.tool_bar.items['props'].setEnabled(True)

# Enable export and properties menu actions
self.menu_bar.menu_actions['file']['export'].setEnabled(True)
self.menu_bar.menu_actions['view']['props'].setEnabled(True)
Expand Down Expand Up @@ -429,3 +443,16 @@ def event_keypress(self, event: QKeyEvent) -> None:
elif mod == None and key == Qt.Key.Key_I:
# Show waveform properties dialog
if config.file: self.menu_bar.menu_view_props()


class StatusHandler(logging.Handler):
"""
Logging handler for main window status bar
"""

def __init__(self, widget: QLabel) -> None:
super().__init__(logging.DEBUG)
self.widget: QLabel = widget

def emit(self, record: logging.LogRecord):
self.widget.setText(record.message)

0 comments on commit e9a0c1f

Please sign in to comment.