diff --git a/app/init.py b/app/init.py new file mode 100644 index 0000000..19714fd --- /dev/null +++ b/app/init.py @@ -0,0 +1,25 @@ +''' app/init.py ''' +import sys +from PyQt6.QtWidgets import QApplication +from .ui.main_window import MainWindow +from .utils.config import AppConfig +from cpdctrl.utility.config_file import ConfigFile + + +def run() -> int: + """ + Initializes the application and runs it. + + Returns: + int: The exit status code. + """ + app: QApplication = QApplication(sys.argv) + AppConfig.initialize() + cf = ConfigFile(AppConfig.MAIN_CFG) + print(cf.values) + cf.set("key", "value") + + window: MainWindow = MainWindow() + window.show() + cf.save() + return sys.exit(app.exec()) diff --git a/app/ui/main_window.py b/app/ui/main_window.py new file mode 100644 index 0000000..46cda62 --- /dev/null +++ b/app/ui/main_window.py @@ -0,0 +1,124 @@ +''' app/ui/main_window.py ''' +from PyQt6.QtCore import Qt +from PyQt6.QtWidgets import QMainWindow, QWidget, QHBoxLayout, QTextEdit, QLabel +from ..utils.config import AppConfig +from .widgets.menubar import MenuBar +from .widgets.toolbar import ToolBar +from .widgets.statusbar import StatusBar +from .widgets.metadata_input import MetadataInput +from .widgets.plot import Plot +# from .widgets.treeview import TreeView + + +class MainWindow(QMainWindow): + """ + MainWindow + + Args: + QMainWindow (QMainWindow): Inheritance + """ + + def __init__(self) -> None: + """ + Initialize the Main-Window. + """ + super().__init__() + # Window-Settings + self.setWindowTitle(AppConfig.APP_NAME) + self.setGeometry(100, 100, 800, 600) + central_widget = QWidget(self) + self.setCentralWidget(central_widget) + + layout = QHBoxLayout(central_widget) + central_widget.setLayout(layout) + + # Create Widgets + # self.treeview = self.create_treeview() + self.editbox = self.create_edit() + + self.create_toolbars() + + # Add Widgets to Window + self.setMenuBar(MenuBar(self)) + self.setStatusBar(StatusBar(self)) + + # layout.addWidget(self.treeview) + layout.addWidget(self.editbox, stretch=1) + layout.addWidget(self.editbox) + + init_elements = [("name1", "val1"), ("name2", "val2")] + layout.addWidget(MetadataInput(init_elements)) + layout.addWidget(Plot()) + + def create_toolbars(self) -> None: + """ + Creates and adds the top and right toolbars to the main window. + """ + # Top Toolbar [PyQt6.QtWidgets.QToolBar] + self.topbar = ToolBar(self, orientation=Qt.Orientation.Horizontal, + style=Qt.ToolButtonStyle.ToolButtonTextUnderIcon, icon_size=(24, 24)) + + # Top Toolbar Buttons + self.topbar.add_button( + "Open", "resources/assets/icons/windows/imageres-10.ico", self.open_file) + self.topbar.add_button( + "Save", "resources/assets/icons/windows/shell32-259.ico", self.save_file) + self.topbar.add_separator() + self.topbar.add_button( + "Exit", "resources/assets/icons/windows/shell32-220.ico", self.exit_app) + + # Right Toolbar [PyQt6.QtWidgets.QToolBar] + self.rightbar = ToolBar(self, orientation=Qt.Orientation.Vertical, + style=Qt.ToolButtonStyle.ToolButtonIconOnly, + icon_size=(24, 24)) + + # Right Toolbar Buttons + self.rightbar.add_separator() + self.rightbar.add_button( + "Privacy", "resources/assets/icons/windows/shell32-167.ico", self.privacy_window) + self.rightbar.add_button( + "Settings", "resources/assets/icons/windows/shell32-315.ico", self.settings_window) + + self.addToolBar(Qt.ToolBarArea.TopToolBarArea, self.topbar) + self.addToolBar(Qt.ToolBarArea.RightToolBarArea, self.rightbar) + + # def create_treeview(self) -> TreeView: + """ + Creates and adds the tree view widget to the main window. + """ + # return TreeView(self) + + def create_edit(self) -> QTextEdit: + """ + Creates and adds the QTextEdit widget to the main window. + """ + return QTextEdit(self) + + def open_file(self) -> None: + """ + Event handler for the "Open" button. Displays the "Open File" dialog. + """ + print("Open") + + def save_file(self) -> None: + """ + Event handler for the "Save" button. Displays the "Save File" dialog. + """ + print("Save") + + def exit_app(self) -> None: + """ + Event handler for the "Exit" button. Closes the application. + """ + self.close() + + def settings_window(self) -> None: + """ + Event handler for the "Settings" button. Displays the "Settings" window. + """ + + def privacy_window(self) -> None: + """ + Event handler for the "Privacy" button. Displays the "Privacy" window. + """ + print("privacy_window") diff --git a/app/ui/widgets/metadata_input.py b/app/ui/widgets/metadata_input.py index e69de29..cbf264d 100644 --- a/app/ui/widgets/metadata_input.py +++ b/app/ui/widgets/metadata_input.py @@ -0,0 +1,18 @@ +from PyQt6.QtWidgets import QWidget, QVBoxLayout, QLabel, QLineEdit, QSpacerItem + +class MetadataInput(QWidget): + def __init__(self, elements: list[tuple[str, str]]=None): + super().__init__() + self.layout = QVBoxLayout() + self.elements = [] + if elements is not None: + for (n, v) in elements: + self.addElement(n, v) + self.layout.addStretch() + self.setLayout(self.layout) + + def addElement(self, name, init_val=""): + self.elements.append((name, init_val)) + self.layout.addWidget(QLabel(name)) + self.layout.addWidget(QLineEdit(init_val)) + self.layout.addItem(QSpacerItem(0, 1)) diff --git a/app/ui/widgets/plot.py b/app/ui/widgets/plot.py index e69de29..ecfc745 100644 --- a/app/ui/widgets/plot.py +++ b/app/ui/widgets/plot.py @@ -0,0 +1,19 @@ +import pyqtgraph as pg +from PyQt6.QtWidgets import QWidget + +class Plot(pg.PlotWidget): + def __init__(self): + super().__init__() + self.setBackground("w") + self.setTitle("Test") + self.setLabel("bottom", "time [s]") + self.setLabel("left", "Voltage [V]") + self.setLabel("right", "LED [%]") + self.showGrid(x=True, y=True) + self.time = list(range(10)) + self.voltage = list(range(10)) + self.led = list(range(-10)) + self.line = self.plot( + self.time, + self.voltage + ) diff --git a/app/utils/config.py b/app/utils/config.py new file mode 100644 index 0000000..eb628b0 --- /dev/null +++ b/app/utils/config.py @@ -0,0 +1,25 @@ +''' app/utils/config.py ''' + +from os import path, environ + + +class AppConfig: + """ + Configuration File + """ + APP_NAME: str = "cpdctrl-gui" + CONFIG_DIR: str = path.expanduser("~/.config/cpdctrl") + MAIN_CFG: str = "" + @classmethod + def initialize(cls) -> None: + """ + Perform any necessary initializations here, e.g.: + - Loading settings from a file + """ + if 'XDG_CONFIG_HOME' in environ.keys(): + AppConfig.CONFIG_DIR = path.join(environ["XDG_CONFIG_HOME"], "cpdctrl") + AppConfig.MAIN_CFG = path.join(AppConfig.CONFIG_DIR, "cpdctrl-gui.yaml") + + + +