Skip to content

Commit

Permalink
Generic way to set property value
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinStrohalm committed Dec 3, 2021
1 parent 04835e7 commit c228921
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions pyeds/eds/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,27 @@ def GetProperties(self, data_purpose=None):
return tuple(props)


def SetValue(self, prop_name, value):
"""
Sets given value to specified property.
Args:
prop_name: str
Property name.
value: ?
Value to set.
"""

# get property
prop = self.GetProperty(prop_name)

# set value to property
prop.Unlock()
prop.SetValue(value)
prop.Lock()


def SetProperties(self, props):
"""
Sets property values from given data.
Expand Down Expand Up @@ -381,13 +402,8 @@ def Check(self, value=True):
message = "'%s' is not checkable!" % (self._type.Name,)
raise KeyError(message)

# get property
prop = self.GetProperty('Checked')

# update property
prop.Unlock()
prop.SetValue(bool(value))
prop.Lock()
self.SetValue('Checked', bool(value))


def Tag(self, index, value=True):
Expand Down Expand Up @@ -421,6 +437,4 @@ def Tag(self, index, value=True):
tags[index] = value or None

# update property
prop.Unlock()
prop.SetValue(tags)
prop.Lock()
self.SetValue('Tags', tags)

0 comments on commit c228921

Please sign in to comment.