diff options
author | Sebastian Koslowski <koslowski@kit.edu> | 2016-06-09 14:45:24 +0200 |
---|---|---|
committer | Sebastian Koslowski <koslowski@kit.edu> | 2016-06-10 14:42:14 +0200 |
commit | 7ac7cf6246e4d984d36c64df10ba4d2b2f6b2204 (patch) | |
tree | de6a780c3fe791087f53913883bba6efa6040e51 | |
parent | 435e2b16c903b4a9d16d40ffba649698c4ded190 (diff) |
grc: gtk3: fix paste and domain color settings
-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 | ||||
-rw-r--r-- | grc/gui/Colors.py | 2 | ||||
-rw-r--r-- | grc/gui/Connection.py | 11 | ||||
-rw-r--r-- | grc/gui/FlowGraph.py | 6 |
9 files changed, 52 insertions, 50 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'] diff --git a/grc/gui/Colors.py b/grc/gui/Colors.py index b2ed55b711..6ee31e5e18 100644 --- a/grc/gui/Colors.py +++ b/grc/gui/Colors.py @@ -47,6 +47,8 @@ CONNECTION_ENABLED_COLOR = get_color('#000000') CONNECTION_DISABLED_COLOR = get_color('#BBBBBB') CONNECTION_ERROR_COLOR = get_color('#FF0000') +DEFAULT_DOMAIN_COLOR = get_color('#777777') + ################################################################################# # param box colors ################################################################################# diff --git a/grc/gui/Connection.py b/grc/gui/Connection.py index 3af6badaa0..d893060aa6 100644 --- a/grc/gui/Connection.py +++ b/grc/gui/Connection.py @@ -26,7 +26,6 @@ from . import Utils from .Constants import CONNECTOR_ARROW_BASE, CONNECTOR_ARROW_HEIGHT from .Element import Element -from ..core.Constants import GR_MESSAGE_DOMAIN from ..core.Connection import Connection as _Connection @@ -93,9 +92,13 @@ class Connection(Element, _Connection): # self.line_attributes[1] = Gdk.LINE_DOUBLE_DASH \ # if not source_domain == sink_domain == GR_MESSAGE_DOMAIN \ # else Gdk.LINE_ON_OFF_DASH - get_domain_color = lambda d: Colors.get_color(( - self.get_parent().get_parent().domains.get(d, {}) - ).get('color') or Colors.DEFAULT_DOMAIN_COLOR_CODE) + + def get_domain_color(domain_name): + domain = self.parent_platform.domains.get(domain_name, {}) + color_spec = domain.get('color') + return Colors.get_color(color_spec) if color_spec else \ + Colors.DEFAULT_DOMAIN_COLOR + self._color = get_domain_color(source_domain) self._bg_color = get_domain_color(sink_domain) self._arrow_color = self._bg_color if self.is_valid() else Colors.CONNECTION_ERROR_COLOR diff --git a/grc/gui/FlowGraph.py b/grc/gui/FlowGraph.py index 8e4a26ea7e..d7745a529d 100644 --- a/grc/gui/FlowGraph.py +++ b/grc/gui/FlowGraph.py @@ -131,8 +131,6 @@ class FlowGraph(Element, _Flowgraph): ########################################################################### def get_drawing_area(self): return self.drawing_area def queue_draw(self): self.get_drawing_area().queue_draw() - def get_size(self): return self.get_drawing_area().get_size_request() - def set_size(self, *args): self.get_drawing_area().set_size_request(*args) def get_scroll_pane(self): return self.drawing_area.get_parent().get_parent() def get_ctrl_mask(self): return self.drawing_area.ctrl_mask def get_mod1_mask(self): return self.drawing_area.mod1_mask @@ -207,8 +205,8 @@ class FlowGraph(Element, _Flowgraph): #recalc the position h_adj = self.get_scroll_pane().get_hadjustment() v_adj = self.get_scroll_pane().get_vadjustment() - x_off = h_adj.get_value() - x_min + h_adj.page_size/4 - y_off = v_adj.get_value() - y_min + v_adj.page_size/4 + x_off = h_adj.get_value() - x_min + h_adj.get_page_size() / 4 + y_off = v_adj.get_value() - y_min + v_adj.get_page_size() / 4 if len(self.get_elements()) <= 1: x_off, y_off = 0, 0 #create blocks |