Skip to content
Snippets Groups Projects
Commit 644d321a authored by Christoph Schmidt's avatar Christoph Schmidt
Browse files

Added new Type FieldSelectableList that allows to define a list that can be...

Added new Type FieldSelectableList that allows to define a list that can be selected using Combo Boxes
parent 8ca6b180
No related branches found
No related tags found
No related merge requests found
......@@ -13,7 +13,7 @@ if __name__ == "__main__":
# setup the logging module
config = ApplicationConfig(internal_log_level=logging.INFO)
#print(config.load('./configs/ApplicationConfig.yaml'))
print(config.load('./configs/ApplicationConfig.yaml'))
#config.autosave(enable=True, path='./configs_autosave')
#print(config.wafer_version)
......
......@@ -117,7 +117,7 @@ class ConfigNode(CObject):
if not isinstance(getattr(self, attr), ConfigNode):
self._internal_logger.info(f"Deserializing field {attr} with content: {val}")
val = getattr(self, attr)._field_parser(val)
getattr(self, attr).set(val)
getattr(self, attr).set(**val)
else:
self._internal_logger.info(f"Deserializing config {attr} with content: {val}")
getattr(self, attr).deserialize(val)
......
......@@ -66,7 +66,7 @@ class Field(Generic[T], CObject):
elif isinstance(value, Path):
from confighandler.controller.fields.FieldPath import FieldPath
return super().__new__(FieldPath)
elif isinstance(value, tuple):
elif not isinstance(value, confighandler.SelectableList) and isinstance(value, tuple):
from confighandler.controller.fields.FieldTuple import FieldTuple
return super().__new__(FieldTuple)
elif not isinstance(value, confighandler.SelectableList) and isinstance(value, list):
......@@ -138,7 +138,7 @@ class Field(Generic[T], CObject):
def _field_parser(self, val):
# Dummy function, which can be overwritten, if the field should get parsed beforehand (e.g. when using pathes)
return val
return {"value": val}
# ==================================================================================================================
# Getter and Setter for value retrival
......@@ -166,10 +166,10 @@ class Field(Generic[T], CObject):
def get(self) -> T:
return self.replace_keywords(self.value)
def set(self, value: T):
def set(self, value: T, *args, **kwargs):
if not self.value == value:
self._internal_logger.info(f"{self.name} = {value} ({type(value)})")
self._set(value)
self._set(value, *args, **kwargs)
self.set_keywords()
# self.view.value_changed.emit(self.value)
# This emits a function that notifies the owner that the field has been set
......@@ -178,7 +178,7 @@ class Field(Generic[T], CObject):
# ==================================================================================================================
# Things that should happen when the value is changed
# ==================================================================================================================
def _set(self, value):
def _set(self, value, *args, **kwargs):
self._value = value
def _on_value_changed(self, value):
......
......@@ -20,4 +20,4 @@ class SelectableList(list):
def __str__(self):
bs = super().__str__()
return f"{str(bs)}({self._selected_index})"
return f"<{self._selected_index}>{str(bs)}"
......@@ -38,9 +38,9 @@ class FieldPath(Field):
match = re.findall(r'@Path:<([^>]*)>', val)
if len(match) > 0:
self._internal_logger.info(f"Found @Path: {val}. Check syntax, multiple @Path: are not allowed in one field.")
return Path(match[0])
return {"value": Path(match[0])}
elif len(match) == 0:
self._internal_logger.debug(f"No @Path: found in {val}. Please check field.")
return Path('./')
return {"value": Path('./')}
def __str__(self):
return str(Path(self.value).as_posix())
\ No newline at end of file
......@@ -5,6 +5,8 @@ Created: 2023-10-19 12:35
Package Version: 0.0.1
Description:
"""
import re
from ast import literal_eval
import confighandler as ch
from confighandler.controller.Field import T
......@@ -26,8 +28,21 @@ class FieldSelectableList(ch.Field):
def _value_to_emit(self):
return self._value.selected_index
def _set(self, value):
def _set(self, value, list = None):
if list is not None:
self._value = ch.SelectableList(list, selected_index=value)
self._value.selected_index = value
def _yaml_repr(self):
return str(f"{self._value} -> {self.value}")
return str(f"{self._value}")
def serialize(self):
"""Used for serializing instances. Returns the current field as a yaml-line."""
return f"{self.name}: {self._yaml_repr()} # -> {self.value} # {self.friendly_name}: {self.description}"
def _field_parser(self, val):
pattern = r'<(\d+)>(.*)'
match = re.match(pattern, val)
sel_index = match.group(1)
value = match.group(2)
#return ch.SelectableList(literal_eval(value), selected_index=sel_index)
return {"list": literal_eval(value), "value": int(sel_index)}
#return sel_index
\ No newline at end of file
......@@ -44,7 +44,7 @@ class FieldViewSelectableList(ch.FieldView):
self.parent_field.set(int(value))
def _on_value_changed(self, value):
print(f"FieldViewSelectableList._on_value_changed({value})")
self.parent_field.logger.info(f"{self.parent_field}: FieldViewSelectableList._on_value_changed {value}")
for edit in self.ui_edit_fields:
edit: QComboBox
edit.setCurrentIndex(value)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment