def attr_uuid_list( metadata=None, human_name="UUID List", data_display=None, list_selection_root=None, no_graham=False, default=attr.Factory(list), **field_options, ): if metadata is None: metadata = {} attribute = attr.ib( default=default, converter=convert_uuid_list, metadata=metadata, ) if not no_graham: graham.attrib( attribute=attribute, field=marshmallow.fields.List( marshmallow.fields.UUID(**field_options), **field_options ), ) attrib( attribute=attribute, human_name=human_name, data_display=data_display, delegate=epyqlib.attrsmodel.RootDelegateCache( list_selection_root=list_selection_root, multi_select=True, ), ) return attribute
class Group(object): name = attr.ib(default='<unnamed group>', ) graham.attrib( attribute=name, field=marshmallow.fields.String(), ) groups = attr.ib(default=attr.Factory(list), ) graham.attrib( attribute=groups, field=marshmallow.fields.Nested('self', many=True), ) leaves = attr.ib(default=attr.Factory(list), ) graham.attrib( attribute=leaves, field=marshmallow.fields.List( marshmallow.fields.Nested(graham.schema(Leaf))), ) mixed_list = attr.ib(default=attr.Factory(list), ) graham.attrib( attribute=mixed_list, field=graham.fields.MixedList(fields=( marshmallow.fields.Nested('Group'), marshmallow.fields.Nested(graham.schema(Leaf)), )), )
def attr_uuid( metadata=None, human_name="UUID", data_display=None, list_selection_root=None, list_selection_path=None, override_delegate=None, no_graham=False, default=attr.Factory(uuid.uuid4), editable=True, no_column=False, **field_options, ): if metadata is None: metadata = {} attribute = attr.ib( default=default, converter=convert_uuid, metadata=metadata, ) if not no_graham: graham.attrib( attribute=attribute, field=marshmallow.fields.UUID(**field_options), ) if list_selection_path is not None: if list_selection_root is not None: raise MultipleFoundError( "list_selection_path and list_selection_root both definded" ) else: attrib( attribute=attribute, human_name=human_name, data_display=data_display, delegate=CustomDelegate( list_selection_path=list_selection_path, override_delegate=override_delegate, ), editable=editable, no_column=no_column, ) else: attrib( attribute=attribute, human_name=human_name, data_display=data_display, delegate=RootDelegateCache(list_selection_root=list_selection_root), editable=editable, no_column=no_column, ) return attribute
def decimal_attrib(**kwargs): attrib = attr.ib( converter=epyqlib.attrsmodel.to_decimal_or_none, **kwargs, ) graham.attrib( attribute=attrib, field=marshmallow.fields.Decimal( allow_none=kwargs.get('default', False) is None, as_string=True, ), ) return attrib
class Test(object): test = attr.ib() graham.attrib(attribute=test, field=marshmallow.fields.String( load_from='test_load_dump', dump_to='test_load_dump', ))
class Test(object): test = attr.ib() graham.attrib( attribute=test, field=marshmallow.fields.String(), ) nope = attr.ib(default=None)
class Root(epyqlib.treenode.TreeNode): name = attr.ib( default=default_name, ) graham.attrib( attribute=name, field=marshmallow.fields.String(), ) children = attr.ib( default=attr.Factory(list), ) graham.attrib( attribute=children, field=graham.fields.MixedList(fields=( marshmallow.fields.Nested(graham.schema(type_)) for type_ in valid_types # marshmallow.fields.Nested('Group'), # marshmallow.fields.Nested(graham.schema(Leaf)), )), ) model = attr.ib(default=None) uuid = attr_uuid() def __attrs_post_init__(self): super().__init__() def can_drop_on(self, node): return isinstance(node, tuple(self.addable_types().values())) @staticmethod def can_delete(node=None): if node is None: return False return True
class TableGroupElement(epyqlib.treenode.TreeNode): name = attr.ib( default=None, convert=epyqlib.attrsmodel.to_str_or_none, metadata=graham.create_metadata( field=marshmallow.fields.String(allow_none=True) ), ) path = attr.ib( factory=tuple, ) epyqlib.attrsmodel.attrib( attribute=path, no_column=True, ) graham.attrib( attribute=path, field=graham.fields.Tuple(marshmallow.fields.UUID()), ) children = attr.ib( default=attr.Factory(list), cmp=False, repr=False, metadata=graham.create_metadata( field=graham.fields.MixedList(fields=( marshmallow.fields.Nested('TableGroupElement'), marshmallow.fields.Nested(graham.schema(TableArrayElement)), )), ), ) uuid = epyqlib.attrsmodel.attr_uuid() original = attr.ib(default=None) epyqlib.attrsmodel.attrib( attribute=original, no_column=True, ) def __attrs_post_init__(self): super().__init__() def can_drop_on(self, node): return False def can_delete(self, node=None): return False
class Event(epyqlib.treenode.TreeNode): time = attr.ib( converter=arrow.get, default=attr.Factory(arrow.utcnow), ) graham.attrib( attribute=time, field=marshmallow.fields.DateTime(), ) epyqlib.attrsmodel.attrib( attribute=time, editable=False, ) value = attr.ib( converter=epyqlib.attrsmodel.to_int_or_none, default=None, ) epyqlib.attrsmodel.attrib( attribute=value, editable=False, ) description = attr.ib( converter=str, default=None, ) epyqlib.attrsmodel.attrib( attribute=description, editable=False, ) uuid = epyqlib.attrsmodel.attr_uuid() def __attrs_post_init__(self): super().__init__() def can_drop_on(self, node): return False @staticmethod def can_delete(node=None): return False remove_old_on_drop = epyqlib.attrsmodel.default_remove_old_on_drop child_from = epyqlib.attrsmodel.default_child_from internal_move = epyqlib.attrsmodel.default_internal_move check = epyqlib.attrsmodel.check_just_children
class TableArrayElement(epyqlib.treenode.TreeNode): name = attr.ib( default=None, convert=epyqlib.attrsmodel.to_str_or_none, metadata=graham.create_metadata( field=marshmallow.fields.String(allow_none=True) ), ) path = attr.ib( factory=tuple, ) epyqlib.attrsmodel.attrib( attribute=path, no_column=True, ) graham.attrib( attribute=path, field=graham.fields.Tuple(marshmallow.fields.UUID()), ) access_level_uuid = epyqlib.attrsmodel.attr_uuid( default=None, allow_none=True, # converter=lambda x: x if x is None else AccessLevelsAccessLevel(x), human_name='Access Level', data_display=epyqlib.attrsmodel.name_from_uuid, list_selection_root='access level', no_graham=True, ) minimum = attr.ib( default=None, converter=epyqlib.attrsmodel.to_decimal_or_none, metadata=graham.create_metadata( field=marshmallow.fields.Decimal(allow_none=True, as_string=True), ), ) maximum = attr.ib( default=None, converter=epyqlib.attrsmodel.to_decimal_or_none, metadata=graham.create_metadata( field=marshmallow.fields.Decimal(allow_none=True, as_string=True), ), ) nv_format = attr.ib( default=None, converter=epyqlib.attrsmodel.to_str_or_none, metadata=graham.create_metadata( field=marshmallow.fields.String(allow_none=True) ), ) nv_factor = attr.ib( default=None, converter=epyqlib.attrsmodel.to_str_or_none, metadata=graham.create_metadata( field=marshmallow.fields.String(allow_none=True) ), ) nv_cast = attr.ib( default=False, converter=epyqlib.attrsmodel.two_state_checkbox, metadata=graham.create_metadata( field=marshmallow.fields.Boolean(), ), ) comment = attr.ib( default=None, converter=epyqlib.attrsmodel.to_str_or_none, metadata=graham.create_metadata( field=marshmallow.fields.String(allow_none=True), ), ) enumeration_uuid = epyqlib.attrsmodel.attr_uuid( default=None, allow_none=True, ) units = attr.ib( default=None, converter=epyqlib.attrsmodel.to_str_or_none, metadata=graham.create_metadata( field=marshmallow.fields.String(allow_none=True), ), ) visibility = epyqlib.attrsmodel.attr_uuid_list( default=None, allow_none=True, ) epyqlib.attrsmodel.attrib( attribute=visibility, human_name='Visibility', data_display=epyqlib.attrsmodel.names_from_uuid_list, delegate=epyqlib.attrsmodel.RootDelegateCache( list_selection_root='visibility', multi_select=True, ) ) display_hexadecimal = attr.ib( default=False, converter=epyqlib.attrsmodel.two_state_checkbox, metadata=graham.create_metadata( field=marshmallow.fields.Boolean(), ), ) # TODO: CAMPid 1342975467516679768543165421 default = attr.ib( default=None, converter=epyqlib.attrsmodel.to_decimal_or_none, metadata=graham.create_metadata( field=marshmallow.fields.Decimal(allow_none=True, as_string=True), ), ) decimal_places = attr.ib( default=None, converter=epyqlib.attrsmodel.to_int_or_none, metadata=graham.create_metadata( field=marshmallow.fields.Integer(allow_none=True), ), ) uuid = epyqlib.attrsmodel.attr_uuid() original = attr.ib( default=None, repr=False, ) epyqlib.attrsmodel.attrib( attribute=original, no_column=True, ) def __attrs_post_init__(self): super().__init__() def can_drop_on(self, node): return False can_delete = epyqlib.attrsmodel.childless_can_delete
class Root(epyqlib.treenode.TreeNode): name = attr.ib( default=default_name, ) graham.attrib( attribute=name, field=marshmallow.fields.String(), ) children = attr.ib( default=attr.Factory(list), ) graham.attrib( attribute=children, field=graham.fields.MixedList( fields=( marshmallow.fields.Nested(graham.schema(type_)) for type_ in valid_types # marshmallow.fields.Nested('Group'), # marshmallow.fields.Nested(graham.schema(Leaf)), ) ), ) model = attr.ib(default=None) uuid = attr_uuid() def __attrs_post_init__(self): super().__init__() def can_drop_on(self, node): return isinstance(node, tuple(self.addable_types().values())) remove_old_on_drop = default_remove_old_on_drop child_from = default_child_from internal_move = default_internal_move def check_and_append(self, models, parent=None): # TODO: ugh, circular dependencies import epyqlib.checkresultmodel if parent is None: parent = epyqlib.checkresultmodel.Root() for child in self.children: result = child.check(models=models) if result is not None: parent.append_child(result) return parent def check(self, models): return self.check_and_append(models=models) @staticmethod def can_delete(node=None): if node is None: return False return True
class Test(object): email = attr.ib() graham.attrib( attribute=email, field=marshmallow.fields.Email(), )
class Test(object): a = attr.ib() graham.attrib(attribute=a, field=marshmallow.fields.Integer()) def done(self): result.append(self.a)
class TableRepeatingBlock(epyqlib.treenode.TreeNode): uuid = epyqlib.attrsmodel.attr_uuid() name = attr.ib( default="Table Reference", metadata=graham.create_metadata(field=marshmallow.fields.String(), ), ) abbreviation = epyqlib.pm.parametermodel.create_abbreviation_attribute() children = attr.ib( factory=list, metadata=graham.create_metadata(field=graham.fields.MixedList( fields=(marshmallow.fields.Nested(graham.schema(DataPoint)), )), ), ) offset = attr.ib( default=2, converter=int, ) repeats = attr.ib( default=0, converter=int, ) path = attr.ib(factory=tuple, ) epyqlib.attrsmodel.attrib( attribute=path, no_column=True, ) graham.attrib( attribute=path, field=graham.fields.Tuple(marshmallow.fields.UUID()), ) def __attrs_post_init__(self): super().__init__() @classmethod def all_addable_types(cls): return epyqlib.attrsmodel.create_addable_types(()) @staticmethod def addable_types(): return {} def can_drop_on(self, node): return False def can_delete(self, node=None): if node is None: return self.tree_parent.can_delete(node=self) return False def check_block_offsets_and_length(self): return self.repeats * check_block_offsets_and_length(self) remove_old_on_drop = epyqlib.attrsmodel.default_remove_old_on_drop child_from = epyqlib.attrsmodel.default_child_from internal_move = epyqlib.attrsmodel.default_internal_move check = epyqlib.attrsmodel.check_just_children
class Leaf(object): name = attr.ib(default='<unnamed leaf>', ) graham.attrib( attribute=name, field=marshmallow.fields.String(), )
class Signal(epyqlib.treenode.TreeNode): name = epyqlib.attrsmodel.create_code_identifier_string_attribute( default='NewSignal', ) bits = epyqlib.attrsmodel.create_integer_attribute(default=0) signed = attr.ib( default=False, convert=epyqlib.attrsmodel.two_state_checkbox, metadata=graham.create_metadata( field=marshmallow.fields.Boolean(), ), ) factor = attr.ib( default=1, converter=epyqlib.attrsmodel.to_decimal_or_none, metadata=graham.create_metadata( field=marshmallow.fields.Decimal(as_string=True), ), ) start_bit = epyqlib.attrsmodel.create_integer_attribute(default=0) parameter_uuid = epyqlib.attrsmodel.attr_uuid( default=None, allow_none=True, ) epyqlib.attrsmodel.attrib( attribute=parameter_uuid, human_name='Parameter UUID', ) enumeration_uuid = epyqlib.attrsmodel.attr_uuid( default=None, allow_none=True, ) epyqlib.attrsmodel.attrib( attribute=enumeration_uuid, human_name='Enumeration', data_display=epyqlib.attrsmodel.name_from_uuid, delegate=epyqlib.attrsmodel.RootDelegateCache( list_selection_root='enumerations', ) ) path = attr.ib( factory=tuple, ) epyqlib.attrsmodel.attrib( attribute=path, no_column=True, ) graham.attrib( attribute=path, field=graham.fields.Tuple(marshmallow.fields.UUID()), ) uuid = epyqlib.attrsmodel.attr_uuid() def __attrs_post_init__(self): super().__init__() def can_drop_on(self, node): return isinstance(node, epyqlib.pm.parametermodel.Parameter) def child_from(self, node): self.parameter_uuid = node.uuid return None can_delete = epyqlib.attrsmodel.childless_can_delete def calculated_min_max(self): bits = self.bits if self.signed: bits -= 1 r = 2 ** bits if self.signed: minimum = -r maximum = r - 1 else: minimum = 0 maximum = r - 1 minimum *= self.factor maximum *= self.factor return minimum, maximum @epyqlib.attrsmodel.check_children def check(self, result, models): results = [] if self.bits < 1: results.append( f'Bit length should be greater than zero: {self.bits}', ) for r in results: result.append_child(epyqlib.checkresultmodel.Result( node=self, message=r, )) return result remove_old_on_drop = epyqlib.attrsmodel.default_remove_old_on_drop internal_move = epyqlib.attrsmodel.default_internal_move
class Multiplexer(epyqlib.treenode.TreeNode): name = epyqlib.attrsmodel.create_code_identifier_string_attribute( default='NewMultiplexer', ) identifier = attr.ib( default=None, convert=epyqlib.attrsmodel.to_int_or_none, metadata=graham.create_metadata( field=marshmallow.fields.Integer(allow_none=True), ) ) length = epyqlib.attrsmodel.create_integer_attribute(default=0) cycle_time = attr.ib( default=None, convert=epyqlib.attrsmodel.to_decimal_or_none, metadata=graham.create_metadata( field=marshmallow.fields.Decimal(allow_none=True, as_string=True), ), ) comment = attr.ib( default=None, convert=epyqlib.attrsmodel.to_str_or_none, metadata=graham.create_metadata( field=marshmallow.fields.String(allow_none=True), ), ) children = attr.ib( default=attr.Factory(list), metadata=graham.create_metadata( field=graham.fields.MixedList(fields=( marshmallow.fields.Nested(graham.schema(Signal)), )), ), ) path = attr.ib( factory=tuple, ) epyqlib.attrsmodel.attrib( attribute=path, no_column=True, ) graham.attrib( attribute=path, field=graham.fields.Tuple(marshmallow.fields.UUID()), ) path_children = attr.ib( factory=tuple, ) epyqlib.attrsmodel.attrib( attribute=path_children, no_column=True, ) graham.attrib( attribute=path_children, field=graham.fields.Tuple(marshmallow.fields.UUID()), ) uuid = epyqlib.attrsmodel.attr_uuid() def __attrs_post_init__(self): super().__init__() def child_from(self, node): return create_child_signal_from(node=node) @classmethod def all_addable_types(cls): return epyqlib.attrsmodel.create_addable_types((Signal,)) def addable_types(self): return {} def can_drop_on(self, node): return isinstance( node, ( epyqlib.pm.parametermodel.Parameter, Signal, ), ) def can_delete(self, node=None): if node is None: return self.tree_parent.can_delete(node=self) return True remove_old_on_drop = epyqlib.attrsmodel.default_remove_old_on_drop internal_move = epyqlib.attrsmodel.default_internal_move check = epyqlib.attrsmodel.check_just_children
class Test: test = attr.ib() graham.attrib( attribute=test, field=marshmallow.fields.String(), )