diff --git a/examples/ApplicationConfig.py b/examples/example2/ApplicationConfig.py similarity index 90% rename from examples/ApplicationConfig.py rename to examples/example2/ApplicationConfig.py index c76a8a3c6e11f9a38f0df723f4f1c8d242fb6add..670c438bf9bd832397d3500c987e5b51a03aec4b 100644 --- a/examples/ApplicationConfig.py +++ b/examples/example2/ApplicationConfig.py @@ -4,7 +4,7 @@ from pathlib import Path -sys.path.append('../src/') +sys.path.append('../../src/') import confighandler as cfg from confighandler.controller.SelectableList import SelectableList @@ -49,8 +49,6 @@ class ApplicationConfig(cfg.ConfigNode): friendly_name="wafer_list1", description="The version of the wafer") - # self.laser_config: LaserConfig = LaserConfig(internal_log=internal_log, - # internal_log_level=internal_log_level) - + self.laser_config: LaserConfig = LaserConfig() self.register() diff --git a/examples/LaserConfig.py b/examples/example2/LaserConfig.py similarity index 65% rename from examples/LaserConfig.py rename to examples/example2/LaserConfig.py index 3d1956b2659f8c0e5615ee55edec775878637c55..1e473d4018118317c161cd841bef21fafd1cb9d9 100644 --- a/examples/LaserConfig.py +++ b/examples/example2/LaserConfig.py @@ -3,8 +3,8 @@ import confighandler as cfg class LaserConfig(cfg.ConfigNode): - def __init__(self, internal_log, internal_log_level) -> None: - super().__init__(internal_log=internal_log, internal_log_level=internal_log_level) + def __init__(self) -> None: + super().__init__() self.wavelength_range = cfg.Field(850) self.velocity = cfg.Field(2.0) self.acceleration = cfg.Field(1.0) diff --git a/examples/main.py b/examples/example2/main.py similarity index 88% rename from examples/main.py rename to examples/example2/main.py index 7f4371da3ae901f498aea8020cd851c72e07a6b3..0eccfc7693cfca2a4a44372979d44e45bc9e5531 100644 --- a/examples/main.py +++ b/examples/example2/main.py @@ -41,8 +41,8 @@ if __name__ == "__main__": config.module_log_level = logging.DEBUG testclass = TestClass() time.sleep(1) - config.autosave(enable=True, path='./configs_autosave/ApplicationConfig.yaml') - (config.load('./configs/ApplicationConfig.yaml', as_auto_save=True)) + config.autosave(enable=True, path='../configs_autosave/ApplicationConfig.yaml') + # (config.load('./configs/ApplicationConfig.yaml', as_auto_save=True)) #print(config.wafer_version) #config.wafer_version.get() #config.wafer_number.get() @@ -52,7 +52,7 @@ if __name__ == "__main__": wdg = QWidget() grd = QtWidgets.QGridLayout() wdg.setLayout(grd) - grd.addWidget(config.view.widget(), 0, 0) + grd.addWidget(config.view.widget(max_level=1), 0, 0) #grd.addWidget(config.view.widget(), 1, 0) tree = QTreeWidget() @@ -60,7 +60,7 @@ if __name__ == "__main__": tree.setColumnCount(3) tree.setHeaderLabels(["Name", "Type", "asdf"]) - tree.addTopLevelItem(config.view.ui_tree_widget_item(tree)) + tree.addTopLevelItem(config.view.ui_tree_widget_item(tree, max_level=1)) grd.addWidget(tree, 2, 0) btn_set = QtWidgets.QPushButton("Set Wafer Number to 123") diff --git a/src/confighandler/controller/ConfigNode.py b/src/confighandler/controller/ConfigNode.py index c224623ceabb9d010d602b09dcb9a7c4ffa5899c..26100ae902b6f93b164a8f1aceaa2e531bd35c8b 100644 --- a/src/confighandler/controller/ConfigNode.py +++ b/src/confighandler/controller/ConfigNode.py @@ -151,6 +151,9 @@ class ConfigNode(CObject): self.fields[attr] = val val.module_log_enabled = self.module_log_enabled + @property + def level(self): + return self._level # ================================================================================================================== # Registering the fields and configs diff --git a/src/confighandler/view/ConfigView.py b/src/confighandler/view/ConfigView.py index 3549553376da56643e4055ba8298f6f236940d8d..01e3257d48766e3d67c411de8a17c1b154a7f585 100644 --- a/src/confighandler/view/ConfigView.py +++ b/src/confighandler/view/ConfigView.py @@ -10,6 +10,8 @@ from PySide6 import QtWidgets from PySide6.QtCore import Signal, QObject from PySide6.QtWidgets import QWidget, QLabel +import confighandler + class ConfigView(QObject): keywords_changed = Signal(dict) @@ -22,15 +24,15 @@ class ConfigView(QObject): # ================================================================================================================== # UI handling # ================================================================================================================== - def widget(self): + def widget(self, max_level=1): self.parent._module_logger.debug("Creating widget for config view.") widget = QWidget() - widget.setLayout(self._create_config_layout()) + widget.setLayout(self._create_config_layout(max_level)) return widget - def ui_tree_widget_item(self, tree_widget): + def ui_tree_widget_item(self, tree_widget, max_level=1): top_item = QtWidgets.QTreeWidgetItem() - top_item.setText(0, self.__class__.__name__) + top_item.setText(0, f"{self.__class__.__name__}") for attr, val in self.parent.fields.items(): item, le = val.view.ui_tree_widget_item() @@ -38,10 +40,13 @@ class ConfigView(QObject): tree_widget.setItemWidget(item, 1, le) for attr, val in self.parent.configs.items(): - top_item.addChild(val.view.ui_tree_widget_item(tree_widget)) + val: confighandler.ConfigNode + if val.level <= max_level: + top_item.addChild(val.view.ui_tree_widget_item(tree_widget)) + return top_item - def _create_config_layout(self): + def _create_config_layout(self, max_level): """ Creates a pyside 6 layout based on the fields of the class.""" grd_layout = QtWidgets.QGridLayout() row = 0 @@ -52,10 +57,11 @@ class ConfigView(QObject): row += 1 for attr, val in self.parent.configs.items(): - # Add a group box - gbox = QtWidgets.QGroupBox(val.name) - gbox.setLayout(val.view._create_config_layout()) - grd_layout.addWidget(gbox, row, 0, 1, 2) - row += 1 + val: confighandler.ConfigNode + if val.level <= max_level: + gbox = QtWidgets.QGroupBox(val.name) + gbox.setLayout(val.view._create_config_layout(max_level)) + grd_layout.addWidget(gbox, row, 0, 1, 2) + row += 1 return grd_layout \ No newline at end of file