diff options
author | Sebastian Koslowski <koslowski@kit.edu> | 2016-07-14 14:32:20 +0200 |
---|---|---|
committer | Sebastian Koslowski <koslowski@kit.edu> | 2016-07-29 15:44:45 +0200 |
commit | 36f186bc46f528d95d9186955e91736d1fdb299e (patch) | |
tree | 7af20e85e4696be152d211df1f8bff0044ad0257 /grc/gui | |
parent | e9dae9194c5abc5582f640f4d5a66794dcdeb8ca (diff) |
grc: dynamic super-classing proof-of-concept =)
Diffstat (limited to 'grc/gui')
-rw-r--r-- | grc/gui/Block.py | 2 | ||||
-rw-r--r-- | grc/gui/Element.py | 7 | ||||
-rw-r--r-- | grc/gui/Platform.py | 3 | ||||
-rw-r--r-- | grc/gui/Port.py | 2 |
4 files changed, 11 insertions, 3 deletions
diff --git a/grc/gui/Block.py b/grc/gui/Block.py index c5a9f063a3..b55e471e37 100644 --- a/grc/gui/Block.py +++ b/grc/gui/Block.py @@ -41,7 +41,7 @@ class Block(CoreBlock, Element): Block constructor. Add graphics related params to the block. """ - CoreBlock.__init__(self, flow_graph, n) + super(self.__class__, self).__init__(flow_graph, n) self.states.update(_coordinate=(0, 0), _rotation=0) self.width = self.height = 0 diff --git a/grc/gui/Element.py b/grc/gui/Element.py index b51a64735f..cdbf548941 100644 --- a/grc/gui/Element.py +++ b/grc/gui/Element.py @@ -30,6 +30,13 @@ class Element(object): and methods to detect selection of those areas. """ + @classmethod + def make_cls_with_base(cls, super_cls): + name = super_cls.__name__ + bases = (super_cls,) + cls.__bases__[1:] + namespace = cls.__dict__.copy() + return type(name, bases, namespace) + def __init__(self): """ Make a new list of rectangular areas and lines, and set the coordinate and the rotation. diff --git a/grc/gui/Platform.py b/grc/gui/Platform.py index 25c755675c..b8dd6aa074 100644 --- a/grc/gui/Platform.py +++ b/grc/gui/Platform.py @@ -66,6 +66,7 @@ class Platform(CorePlatform): Config = Config FlowGraph = FlowGraph Connection = Connection - Block = Block + block_classes = {key: Block.make_cls_with_base(cls) + for key, cls in CorePlatform.block_classes.items()} Port = Port Param = Param diff --git a/grc/gui/Port.py b/grc/gui/Port.py index d8a180b7c8..4b3f6edb81 100644 --- a/grc/gui/Port.py +++ b/grc/gui/Port.py @@ -37,7 +37,7 @@ class Port(_Port, Element): Port constructor. Create list of connector coordinates. """ - _Port.__init__(self, block, n, dir) + super(Port, self).__init__(block, n, dir) Element.__init__(self) self._connector_coordinate = (0, 0) self._hovering = True |