Initial Commit
This commit is contained in:
BIN
util/gui/__pycache__/app_window.cpython-313.pyc
Normal file
BIN
util/gui/__pycache__/app_window.cpython-313.pyc
Normal file
Binary file not shown.
BIN
util/gui/__pycache__/characteristics.cpython-313.pyc
Normal file
BIN
util/gui/__pycache__/characteristics.cpython-313.pyc
Normal file
Binary file not shown.
BIN
util/gui/__pycache__/window.cpython-313.pyc
Normal file
BIN
util/gui/__pycache__/window.cpython-313.pyc
Normal file
Binary file not shown.
BIN
util/gui/__pycache__/windows.cpython-313.pyc
Normal file
BIN
util/gui/__pycache__/windows.cpython-313.pyc
Normal file
Binary file not shown.
BIN
util/gui/logic/__pycache__/app_window_types.cpython-313.pyc
Normal file
BIN
util/gui/logic/__pycache__/app_window_types.cpython-313.pyc
Normal file
Binary file not shown.
BIN
util/gui/logic/__pycache__/characteristics.cpython-313.pyc
Normal file
BIN
util/gui/logic/__pycache__/characteristics.cpython-313.pyc
Normal file
Binary file not shown.
41
util/gui/logic/app_window_types.py
Normal file
41
util/gui/logic/app_window_types.py
Normal file
@@ -0,0 +1,41 @@
|
||||
# Local Library
|
||||
from util.gui.logic.characteristics import Characteristics
|
||||
|
||||
# External Library
|
||||
from PySide6.QtWidgets import (QApplication, QMainWindow, QMdiArea, QMdiSubWindow, QTextEdit, QPushButton, QVBoxLayout, QWidget, QToolBar)
|
||||
from PySide6.QtGui import QKeySequence, QShortcut
|
||||
|
||||
class MDIApp(QMainWindow):
|
||||
def __init__(self, characteristics: Characteristics):
|
||||
super().__init__()
|
||||
|
||||
self.mdi_area = QMdiArea(self)
|
||||
self.setCentralWidget(self.mdi_area)
|
||||
|
||||
for component in characteristics.components:
|
||||
component.build(self)
|
||||
|
||||
self.fullscreen_shortcut = QShortcut(QKeySequence("F11"), self)
|
||||
self.fullscreen_shortcut.activated.connect(self.toggle_fullscreen)
|
||||
|
||||
def toggle_fullscreen(self):
|
||||
if self.isFullScreen():
|
||||
self.showNormal()
|
||||
else:
|
||||
self.showFullScreen()
|
||||
|
||||
class App(QMainWindow):
|
||||
def __init__(self, characteristics: Characteristics):
|
||||
super().__init__()
|
||||
|
||||
for component in characteristics.components:
|
||||
component.build(self)
|
||||
|
||||
self.fullscreen_shortcut = QShortcut(QKeySequence("F11"), self)
|
||||
self.fullscreen_shortcut.activated.connect(self.toggle_fullscreen)
|
||||
|
||||
def toggle_fullscreen(self):
|
||||
if self.isFullScreen():
|
||||
self.showNormal()
|
||||
else:
|
||||
self.showFullScreen()
|
||||
57
util/gui/logic/characteristics.py
Normal file
57
util/gui/logic/characteristics.py
Normal file
@@ -0,0 +1,57 @@
|
||||
# Standard Library
|
||||
from dataclasses import dataclass
|
||||
from typing import List, Callable, Protocol
|
||||
|
||||
# External Library
|
||||
from PySide6.QtWidgets import (QToolBar, QMainWindow, QWidget, QMdiArea, QMdiSubWindow)
|
||||
from PySide6.QtGui import (QAction)
|
||||
|
||||
class UIComponent(Protocol):
|
||||
def build(self, app: QMainWindow):
|
||||
pass
|
||||
|
||||
@dataclass
|
||||
class ToolbarAction:
|
||||
name: str
|
||||
callback: Callable[[QMainWindow], None]
|
||||
|
||||
@dataclass
|
||||
class Toolbar(UIComponent):
|
||||
name: str
|
||||
actions: List[ToolbarAction]
|
||||
|
||||
def build(self, app: QMainWindow):
|
||||
toolbar = QToolBar(self.name)
|
||||
for action in self.actions:
|
||||
qt_action = QAction(action.name, app)
|
||||
qt_action.triggered.connect(lambda checked=False, cb=action.callback: cb(app))
|
||||
toolbar.addAction(qt_action)
|
||||
app.addToolBar(toolbar)
|
||||
|
||||
@dataclass
|
||||
class SubWindow(UIComponent):
|
||||
name: str
|
||||
content_factory: Callable[[], QWidget]
|
||||
|
||||
def build(self, app: QMainWindow):
|
||||
if not hasattr(app, 'mdi_area'):
|
||||
raise AttributeError("MDI area not found in app")
|
||||
|
||||
mdi_area: QMdiArea = getattr(app, 'mdi_area')
|
||||
sub_window = QMdiSubWindow()
|
||||
sub_window.setWidget(self.content_factory())
|
||||
sub_window.setWindowTitle(self.name)
|
||||
mdi_area.addSubWindow(sub_window)
|
||||
sub_window.show()
|
||||
|
||||
@dataclass
|
||||
class Window(UIComponent):
|
||||
title: str
|
||||
|
||||
def build(self, app: QMainWindow):
|
||||
app.setWindowTitle(self.title)
|
||||
|
||||
@dataclass
|
||||
class Characteristics:
|
||||
components: List[UIComponent]
|
||||
|
||||
14
util/gui/windows.py
Normal file
14
util/gui/windows.py
Normal file
@@ -0,0 +1,14 @@
|
||||
# External Library
|
||||
from PySide6.QtWidgets import QApplication, QTextEdit, QMdiSubWindow
|
||||
|
||||
class Windows:
|
||||
note_counter = 0
|
||||
|
||||
@staticmethod
|
||||
def create_note(app_instance):
|
||||
Windows.note_counter += 1
|
||||
sub = QMdiSubWindow()
|
||||
sub.setWidget(QTextEdit(f"Notes {Windows.note_counter}"))
|
||||
sub.setWindowTitle(f"Notes {Windows.note_counter}")
|
||||
app_instance.mdi_area.addSubWindow(sub)
|
||||
sub.show()
|
||||
Reference in New Issue
Block a user