robosim.traits

traits.py - Generic traits for various OOP classes. Should be methods only (no data), so kinda opposite of components. Import level: 1.

 1"""
 2traits.py - Generic traits for various OOP classes. Should be methods only (no data), so kinda opposite of components.
 3Import level: 1.
 4"""
 5from __future__ import annotations
 6from abc import ABC, abstractmethod
 7
 8class Drawable(ABC):
 9    """generic drawable object"""
10    @abstractmethod
11    def draw(self):
12        """draws the object"""
13
14class Serializable(ABC):
15    """serializable object"""
16    @abstractmethod
17    def to_dict(self) -> dict:
18        """the dict representation of this object for serialization purposes"""
19
20    @staticmethod
21    @abstractmethod
22    def from_dict(state: dict) -> Serializable:
23        """loads this object from a serialized dict representation"""
24
25class Restorable(ABC):
26    """restorable (inplace) object. Used by Scene and ScenePlugins where recreation (serializable) is not prefered"""
27    @abstractmethod
28    def to_dict(self) -> dict:
29        """the dict representation of this object for serialization purposes"""
30
31    @abstractmethod
32    def load_state_dict(self, state: dict):
33        """Loads in place this object from a serialized dict representation"""
class Drawable(abc.ABC):
 9class Drawable(ABC):
10    """generic drawable object"""
11    @abstractmethod
12    def draw(self):
13        """draws the object"""

generic drawable object

@abstractmethod
def draw(self):
11    @abstractmethod
12    def draw(self):
13        """draws the object"""

draws the object

class Serializable(abc.ABC):
15class Serializable(ABC):
16    """serializable object"""
17    @abstractmethod
18    def to_dict(self) -> dict:
19        """the dict representation of this object for serialization purposes"""
20
21    @staticmethod
22    @abstractmethod
23    def from_dict(state: dict) -> Serializable:
24        """loads this object from a serialized dict representation"""

serializable object

@abstractmethod
def to_dict(self) -> dict:
17    @abstractmethod
18    def to_dict(self) -> dict:
19        """the dict representation of this object for serialization purposes"""

the dict representation of this object for serialization purposes

@staticmethod
@abstractmethod
def from_dict(state: dict) -> Serializable:
21    @staticmethod
22    @abstractmethod
23    def from_dict(state: dict) -> Serializable:
24        """loads this object from a serialized dict representation"""

loads this object from a serialized dict representation

class Restorable(abc.ABC):
26class Restorable(ABC):
27    """restorable (inplace) object. Used by Scene and ScenePlugins where recreation (serializable) is not prefered"""
28    @abstractmethod
29    def to_dict(self) -> dict:
30        """the dict representation of this object for serialization purposes"""
31
32    @abstractmethod
33    def load_state_dict(self, state: dict):
34        """Loads in place this object from a serialized dict representation"""

restorable (inplace) object. Used by Scene and ScenePlugins where recreation (serializable) is not prefered

@abstractmethod
def to_dict(self) -> dict:
28    @abstractmethod
29    def to_dict(self) -> dict:
30        """the dict representation of this object for serialization purposes"""

the dict representation of this object for serialization purposes

@abstractmethod
def load_state_dict(self, state: dict):
32    @abstractmethod
33    def load_state_dict(self, state: dict):
34        """Loads in place this object from a serialized dict representation"""

Loads in place this object from a serialized dict representation