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 PySide6.QtCore import QThread, Slot
|
||||||
from src.utils.documentation import run_mkdocs
|
from src.utils.documentation import website, QuietHandler
|
||||||
|
from wsgiref.simple_server import make_server
|
||||||
|
|
||||||
|
|
||||||
class DocumentationThread(QThread):
|
class DocumentationThread(QThread):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
self._server = None # store server so we can shut it down
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
# launch_documentation()
|
# 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">
|
<property name="title">
|
||||||
<string>Help</string>
|
<string>Help</string>
|
||||||
</property>
|
</property>
|
||||||
<addaction name="actionDokumentation_lokal"/>
|
|
||||||
<addaction name="actionAbout"/>
|
<addaction name="actionAbout"/>
|
||||||
|
<addaction name="actionDokumentation"/>
|
||||||
</widget>
|
</widget>
|
||||||
<addaction name="menuDatei"/>
|
<addaction name="menuDatei"/>
|
||||||
<addaction name="menuEinstellungen"/>
|
<addaction name="menuEinstellungen"/>
|
||||||
@@ -1956,17 +1956,6 @@ Einige Angaben müssen ggf angepasst werden</string>
|
|||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</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">
|
<action name="actionAbout">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>About</string>
|
<string>About</string>
|
||||||
@@ -1975,9 +1964,9 @@ Einige Angaben müssen ggf angepasst werden</string>
|
|||||||
<enum>QAction::AboutRole</enum>
|
<enum>QAction::AboutRole</enum>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionDokumentation_lokal">
|
<action name="actionDokumentation">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Dokumentation (lokal)</string>
|
<string>Dokumentation</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="shortcut">
|
<property name="shortcut">
|
||||||
<string>F1</string>
|
<string>F1</string>
|
||||||
@@ -2009,8 +1998,6 @@ Einige Angaben müssen ggf angepasst werden</string>
|
|||||||
<tabstop>automation_add_selected_books</tabstop>
|
<tabstop>automation_add_selected_books</tabstop>
|
||||||
<tabstop>saveandcreate</tabstop>
|
<tabstop>saveandcreate</tabstop>
|
||||||
</tabstops>
|
</tabstops>
|
||||||
<resources>
|
<resources/>
|
||||||
<include location="../../resources.qrc"/>
|
|
||||||
</resources>
|
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -12,7 +12,7 @@ from typing import Any, Union
|
|||||||
import loguru
|
import loguru
|
||||||
from natsort import natsorted
|
from natsort import natsorted
|
||||||
from PySide6 import QtCore, QtGui, QtWidgets
|
from PySide6 import QtCore, QtGui, QtWidgets
|
||||||
from PySide6.QtCore import QThread
|
from PySide6.QtCore import QThread, Qt
|
||||||
from PySide6.QtGui import QRegularExpressionValidator
|
from PySide6.QtGui import QRegularExpressionValidator
|
||||||
|
|
||||||
from src import LOG_DIR, Icon
|
from src import LOG_DIR, Icon
|
||||||
@@ -23,7 +23,6 @@ from src.backend.semester import Semester
|
|||||||
from src.logic import (
|
from src.logic import (
|
||||||
APP_NRS,
|
APP_NRS,
|
||||||
Apparat,
|
Apparat,
|
||||||
# PROF_TITLES,
|
|
||||||
ApparatData,
|
ApparatData,
|
||||||
BookData,
|
BookData,
|
||||||
Prof,
|
Prof,
|
||||||
@@ -118,7 +117,7 @@ class Ui(Ui_Semesterapparat):
|
|||||||
# Actions
|
# Actions
|
||||||
self.actionEinstellungen.triggered.connect(self.open_settings) # type:ignore
|
self.actionEinstellungen.triggered.connect(self.open_settings) # type:ignore
|
||||||
Icon("settings", self.actionEinstellungen)
|
Icon("settings", self.actionEinstellungen)
|
||||||
self.actionDokumentation_lokal.triggered.connect(self.open_documentation) # type:ignore
|
self.documentation_open = False
|
||||||
Icon("offAction", self.actionBeenden)
|
Icon("offAction", self.actionBeenden)
|
||||||
self.actionBeenden.triggered.connect(self.quit) # type:ignore
|
self.actionBeenden.triggered.connect(self.quit) # type:ignore
|
||||||
self.actionAbout.triggered.connect(self.open_about) # 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.add_medium.setEnabled(False)
|
||||||
self.docu = DocumentationThread()
|
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
|
# get all current apparats and cache them in a list
|
||||||
self.apparats = self.get_apparats()
|
self.apparats = self.get_apparats()
|
||||||
@@ -329,10 +328,16 @@ class Ui(Ui_Semesterapparat):
|
|||||||
|
|
||||||
def open_documentation(self):
|
def open_documentation(self):
|
||||||
log.info("Opening Documentation")
|
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()
|
self.docu.start()
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
webbrowser.open("http://localhost:8000")
|
webbrowser.open("http://localhost:8000")
|
||||||
|
self.statusBar.showMessage("")
|
||||||
|
|
||||||
def update_calendar(self, data: list[dict[str, Any]]):
|
def update_calendar(self, data: list[dict[str, Any]]):
|
||||||
self.calendarWidget.setMessages([data])
|
self.calendarWidget.setMessages([data])
|
||||||
@@ -1832,8 +1837,14 @@ def launch_gui():
|
|||||||
# #log.debug(aui.active_user)
|
# #log.debug(aui.active_user)
|
||||||
MainWindow.show()
|
MainWindow.show()
|
||||||
# atexit.register()
|
# 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(tempdelete)
|
||||||
atexit.register(aui.validate_thread.quit)
|
# atexit.register(aui.validate_thread.quit)
|
||||||
|
# atexit.register(aui.docu.quit)
|
||||||
sys.exit(app.exec())
|
sys.exit(app.exec())
|
||||||
|
|
||||||
elif ui.lresult == 0:
|
elif ui.lresult == 0:
|
||||||
|
|||||||
@@ -1,10 +1,18 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from pyramid.config import Configurator
|
from pyramid.config import Configurator
|
||||||
from wsgiref.simple_server import make_server
|
from wsgiref.simple_server import make_server, WSGIRequestHandler
|
||||||
|
|
||||||
docport = 8000
|
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():
|
def website():
|
||||||
config = Configurator()
|
config = Configurator()
|
||||||
@@ -20,7 +28,7 @@ def website():
|
|||||||
|
|
||||||
def launch_documentation():
|
def launch_documentation():
|
||||||
app = website()
|
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))
|
print("Serving MkDocs documentation on http://0.0.0.0:{}".format(docport))
|
||||||
server.serve_forever()
|
server.serve_forever()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user