diff options
Diffstat (limited to 'grc/core')
-rw-r--r-- | grc/core/Connection.py | 6 | ||||
-rw-r--r-- | grc/core/Element.py | 68 | ||||
-rw-r--r-- | grc/core/FlowGraph.py | 2 | ||||
-rw-r--r-- | grc/core/Param.py | 2 | ||||
-rw-r--r-- | grc/core/Platform.py | 3 | ||||
-rw-r--r-- | grc/core/Port.py | 2 |
6 files changed, 41 insertions, 42 deletions
diff --git a/grc/core/Connection.py b/grc/core/Connection.py index 2309d159c8..52cba4257c 100644 --- a/grc/core/Connection.py +++ b/grc/core/Connection.py @@ -24,7 +24,7 @@ import collections from six.moves import range from . import Constants -from .Element import Element, lazyproperty +from .Element import Element, lazy_property class Connection(Element): @@ -131,11 +131,11 @@ class Connection(Element): """ return self.source_block.get_enabled() and self.sink_block.get_enabled() - @lazyproperty + @lazy_property def source_block(self): return self.source_port.parent_block - @lazyproperty + @lazy_property def sink_block(self): return self.sink_port.parent_block diff --git a/grc/core/Element.py b/grc/core/Element.py index a046d6beb4..f07bb113e1 100644 --- a/grc/core/Element.py +++ b/grc/core/Element.py @@ -1,36 +1,37 @@ -""" -Copyright 2008, 2009, 2015 Free Software Foundation, Inc. -This file is part of GNU Radio - -GNU Radio Companion is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -GNU Radio Companion is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -""" +# Copyright 2008, 2009, 2015, 2016 Free Software Foundation, Inc. +# This file is part of GNU Radio +# +# GNU Radio Companion is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# GNU Radio Companion is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA import weakref +import functools -class lazyproperty(object): +class lazy_property(object): + def __init__(self, func): self.func = func + functools.update_wrapper(self, func) def __get__(self, instance, cls): if instance is None: return self - else: - value = self.func(instance) - setattr(instance, self.func.__name__, value) - return value + value = self.func(instance) + weak_value = weakref.proxy(value) if not weakref.ProxyType else value + setattr(instance, self.func.__name__, weak_value) + return weak_value class Element(object): @@ -108,35 +109,34 @@ class Element(object): def parent(self): return self._parent() - def get_parent_of_type(self, cls): + def get_parent_by_type(self, cls): parent = self.parent if parent is None: return None elif isinstance(parent, cls): return parent else: - return parent.get_parent_of_type(cls) + return parent.get_parent_by_type(cls) - @lazyproperty + @lazy_property def parent_platform(self): from .Platform import Platform - return self.get_parent_of_type(Platform) + return self.get_parent_by_type(Platform) - @lazyproperty + @lazy_property def parent_flowgraph(self): from .FlowGraph import FlowGraph - return self.get_parent_of_type(FlowGraph) + return self.get_parent_by_type(FlowGraph) - @lazyproperty + @lazy_property def parent_block(self): from .Block import Block - return self.get_parent_of_type(Block) + return self.get_parent_by_type(Block) - def reset_parents(self): + def reset_parents_by_type(self): """Reset all lazy properties""" - # todo: use case? for name, obj in vars(Element): - if isinstance(obj, lazyproperty): + if isinstance(obj, lazy_property): delattr(self, name) def get_children(self): diff --git a/grc/core/FlowGraph.py b/grc/core/FlowGraph.py index 16842595c8..67e86f3e6e 100644 --- a/grc/core/FlowGraph.py +++ b/grc/core/FlowGraph.py @@ -53,7 +53,7 @@ class FlowGraph(Element): Returns: the flow graph object """ - Element.__init__(self, platform) + Element.__init__(self, parent=platform) self._timestamp = time.ctime() self._options_block = self.parent_platform.get_new_block(self, 'options') diff --git a/grc/core/Param.py b/grc/core/Param.py index b21cbcddf1..35bb176744 100644 --- a/grc/core/Param.py +++ b/grc/core/Param.py @@ -172,7 +172,7 @@ class Param(Element): if self._tab_label not in block.get_param_tab_labels(): block.get_param_tab_labels().append(self._tab_label) # Build the param - Element.__init__(self, block) + Element.__init__(self, parent=block) # Create the Option objects from the n data self._options = list() self._evaluated = None diff --git a/grc/core/Platform.py b/grc/core/Platform.py index 2c0b83dca4..069870d389 100644 --- a/grc/core/Platform.py +++ b/grc/core/Platform.py @@ -53,10 +53,9 @@ class Platform(Element): def __init__(self, *args, **kwargs): """ Make a platform for GNU Radio """ - Element.__init__(self) + Element.__init__(self, parent=None) self.config = self.Config(*args, **kwargs) - self.block_docstrings = {} self.block_docstrings_loaded_callback = lambda: None # dummy to be replaced by BlockTreeWindow diff --git a/grc/core/Port.py b/grc/core/Port.py index 99b5a25508..9a33c5c506 100644 --- a/grc/core/Port.py +++ b/grc/core/Port.py @@ -128,7 +128,7 @@ class Port(Element): n.setdefault('key', str(next(block.port_counters[dir == 'source']))) # Build the port - Element.__init__(self, block) + Element.__init__(self, parent=block) # Grab the data self._name = n['name'] self._key = n['key'] |