2025-04-03 19:03:08 +02:00

50 lines
1.8 KiB
Python

from PyQt6.QtWidgets import QWidget, QTextBrowser, QHBoxLayout, QListWidget, QListWidgetItem
from PyQt6.QtGui import QDesktopServices
from ...resources import get_resource_path
from .about import MarkdownView
import logging
log = logging.getLogger(__name__)
# Ordered list of help files to use
GUI_FILES = [
("about.md", "About"),
("sample_changing.md", "Changing the Sample"),
("measurement_settings.md", "Measurement Settings"),
("led_control.md", "LED Control"),
("troubleshooting.md", "Troubleshooting"),
("technical_information.md", "Technical Information"),
]
class HelpMenu(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.setLayout(QHBoxLayout())
self.w_list = QListWidget()
self.w_list.setMaximumWidth(200)
self.layout().addWidget(self.w_list)
self.w_viewer = MarkdownView()
self.layout().addWidget(self.w_viewer)
files = [(get_resource_path(f), name) for (f,name) in GUI_FILES]
for i, (f, name) in enumerate(files):
w_item = QListWidgetItem(name)
w_item.filepath = f
self.w_list.addItem(w_item)
if i == 0:
self.set_view(w_item)
self.w_list.setCurrentRow(0)
self.w_list.itemClicked.connect(self.set_view)
def set_view(self, list_item):
try:
filepath = list_item.filepath
try:
with open(filepath, "r") as file:
content = file.read()
self.w_viewer.setMarkdown(content)
except FileNotFoundError:
log.error(f"File not found: {filepath}")
self.w_viewer.setMarkdown(f"## File not found\n`{filepath}`")
except AttributeError:
log.error(f"Invalid list item")