rework documentation launch, use generated files instead of pure mkdocs, add quiet handler for use with logging in terminal
This commit is contained in:
@@ -1,11 +1,23 @@
|
||||
from PySide6.QtCore import QThread
|
||||
from src.utils.documentation import run_mkdocs
|
||||
from PySide6.QtCore import QThread, Slot
|
||||
from src.utils.documentation import website, QuietHandler
|
||||
from wsgiref.simple_server import make_server
|
||||
|
||||
|
||||
class DocumentationThread(QThread):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self._server = None # store server so we can shut it down
|
||||
|
||||
def run(self):
|
||||
# launch_documentation()
|
||||
run_mkdocs()
|
||||
self._server = make_server(
|
||||
"localhost", 8000, website(), handler_class=QuietHandler
|
||||
)
|
||||
while not self.isInterruptionRequested():
|
||||
self._server.handle_request()
|
||||
|
||||
@Slot() # slot you can connect to aboutToQuit
|
||||
def stop(self):
|
||||
self.requestInterruption() # ask the loop above to exit
|
||||
if self._server:
|
||||
self._server.shutdown() # unblock handle_request()
|
||||
@@ -1923,8 +1923,8 @@ Einige Angaben müssen ggf angepasst werden</string>
|
||||
<property name="title">
|
||||
<string>Help</string>
|
||||
</property>
|
||||
<addaction name="actionDokumentation_lokal"/>
|
||||
<addaction name="actionAbout"/>
|
||||
<addaction name="actionDokumentation"/>
|
||||
</widget>
|
||||
<addaction name="menuDatei"/>
|
||||
<addaction name="menuEinstellungen"/>
|
||||
@@ -1956,17 +1956,6 @@ Einige Angaben müssen ggf angepasst werden</string>
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionDokumentation">
|
||||
<property name="text">
|
||||
<string>Dokumentation (online)</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>F1</string>
|
||||
</property>
|
||||
<property name="shortcutContext">
|
||||
<enum>Qt::ApplicationShortcut</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionAbout">
|
||||
<property name="text">
|
||||
<string>About</string>
|
||||
@@ -1975,9 +1964,9 @@ Einige Angaben müssen ggf angepasst werden</string>
|
||||
<enum>QAction::AboutRole</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionDokumentation_lokal">
|
||||
<action name="actionDokumentation">
|
||||
<property name="text">
|
||||
<string>Dokumentation (lokal)</string>
|
||||
<string>Dokumentation</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>F1</string>
|
||||
@@ -2009,8 +1998,6 @@ Einige Angaben müssen ggf angepasst werden</string>
|
||||
<tabstop>automation_add_selected_books</tabstop>
|
||||
<tabstop>saveandcreate</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="../../resources.qrc"/>
|
||||
</resources>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -12,7 +12,7 @@ from typing import Any, Union
|
||||
import loguru
|
||||
from natsort import natsorted
|
||||
from PySide6 import QtCore, QtGui, QtWidgets
|
||||
from PySide6.QtCore import QThread
|
||||
from PySide6.QtCore import QThread, Qt
|
||||
from PySide6.QtGui import QRegularExpressionValidator
|
||||
|
||||
from src import LOG_DIR, Icon
|
||||
@@ -23,7 +23,6 @@ from src.backend.semester import Semester
|
||||
from src.logic import (
|
||||
APP_NRS,
|
||||
Apparat,
|
||||
# PROF_TITLES,
|
||||
ApparatData,
|
||||
BookData,
|
||||
Prof,
|
||||
@@ -118,7 +117,7 @@ class Ui(Ui_Semesterapparat):
|
||||
# Actions
|
||||
self.actionEinstellungen.triggered.connect(self.open_settings) # type:ignore
|
||||
Icon("settings", self.actionEinstellungen)
|
||||
self.actionDokumentation_lokal.triggered.connect(self.open_documentation) # type:ignore
|
||||
self.documentation_open = False
|
||||
Icon("offAction", self.actionBeenden)
|
||||
self.actionBeenden.triggered.connect(self.quit) # type:ignore
|
||||
self.actionAbout.triggered.connect(self.open_about) # type:ignore
|
||||
@@ -204,7 +203,7 @@ class Ui(Ui_Semesterapparat):
|
||||
self.add_medium.setEnabled(False)
|
||||
self.docu = DocumentationThread()
|
||||
|
||||
self.actionDokumentation_lokal.triggered.connect(self.open_documentation) # type:ignore
|
||||
self.actionDokumentation.triggered.connect(self.open_documentation) # type:ignore
|
||||
|
||||
# get all current apparats and cache them in a list
|
||||
self.apparats = self.get_apparats()
|
||||
@@ -329,10 +328,16 @@ class Ui(Ui_Semesterapparat):
|
||||
|
||||
def open_documentation(self):
|
||||
log.info("Opening Documentation")
|
||||
if not self.docu.isRunning():
|
||||
self.statusBar.showMessage("Dokumentation wird geöffnet", 5000)
|
||||
|
||||
if not self.documentation_open:
|
||||
# write "opening documentation in 5s into status bar"
|
||||
self.documentation_open = True
|
||||
self.docu.start()
|
||||
time.sleep(5)
|
||||
time.sleep(5)
|
||||
|
||||
webbrowser.open("http://localhost:8000")
|
||||
self.statusBar.showMessage("")
|
||||
|
||||
def update_calendar(self, data: list[dict[str, Any]]):
|
||||
self.calendarWidget.setMessages([data])
|
||||
@@ -1832,8 +1837,14 @@ def launch_gui():
|
||||
# #log.debug(aui.active_user)
|
||||
MainWindow.show()
|
||||
# atexit.register()
|
||||
app.aboutToQuit.connect(
|
||||
aui.validate_thread.quit
|
||||
) # if that thread uses an event loop
|
||||
app.aboutToQuit.connect(aui.docu.terminate) # our new slot
|
||||
app.aboutToQuit.connect(aui.docu.wait)
|
||||
atexit.register(tempdelete)
|
||||
atexit.register(aui.validate_thread.quit)
|
||||
# atexit.register(aui.validate_thread.quit)
|
||||
# atexit.register(aui.docu.quit)
|
||||
sys.exit(app.exec())
|
||||
|
||||
elif ui.lresult == 0:
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
import os
|
||||
import sys
|
||||
from pyramid.config import Configurator
|
||||
from wsgiref.simple_server import make_server
|
||||
from wsgiref.simple_server import make_server, WSGIRequestHandler
|
||||
|
||||
docport = 8000
|
||||
|
||||
class QuietHandler(WSGIRequestHandler):
|
||||
# suppress “GET /…” access log
|
||||
def log_request(self, code="-", size="-"):
|
||||
pass
|
||||
|
||||
# suppress all other messages (errors, etc.)
|
||||
def log_message(self, fmt, *args):
|
||||
pass
|
||||
|
||||
def website():
|
||||
config = Configurator()
|
||||
@@ -20,7 +28,7 @@ def website():
|
||||
|
||||
def launch_documentation():
|
||||
app = website()
|
||||
server = make_server("localhost", docport, app)
|
||||
server = make_server("localhost", docport, app, handler_class=QuietHandler)
|
||||
print("Serving MkDocs documentation on http://0.0.0.0:{}".format(docport))
|
||||
server.serve_forever()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user