From 91b24a8628b72806e1a725649a38c11e0aee6a31 Mon Sep 17 00:00:00 2001 From: Jan Pokorný Date: Fri, 27 Sep 2013 22:07:24 +0200 Subject: lib: reuse url attribute also for edges (not straightforward, though) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan Pokorný --- lib.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/lib.py b/lib.py index 26f0b9c..04ed31f 100644 --- a/lib.py +++ b/lib.py @@ -72,7 +72,11 @@ class LibMeta(type): if hasattr(self, 'web'): kwargs['URL'] = getattr(self, 'web', None) else: - kwargs['URL'] = "class://" + self.__class__.__name__ + url = "class://" + self.__class__.__name__ + for l in ('common_src_of', 'common_dst_of'): + url += ';' + url += getattr(self, l).__name__ if hasattr(self, l) else '' + kwargs['URL'] = url old_init(self, *args, **kwargs) super(cls, self).__init__(*args, **kwargs) @@ -157,10 +161,22 @@ def xdot_graph(*args, **kwargs): lambda self, *args: self.set_tooltip_markup(None)) def on_click(self, element, event): - if element is None or not element.url: + """Overload url attribute as it is the only passed internally""" + if element is None: return False + elif not hasattr(element, 'url'): + assert isinstance(element, xdot.Edge) + for access, i in ((element.src, 1), (element.dst, 2)): + which = access.url.split('class://', 1)[1].split(';')[i] + if which in REGISTRY: + # XXX: check matching label to be perfectly sure + cls = REGISTRY[which] + break + else: + return False + else: + cls = REGISTRY[element.url.split('class://', 1)[1].split(';')[0]] # create the resulting markup - cls = REGISTRY[element.url.split('class://', 1)[1]] markup = "" # XXX: sort the keys in dicts? if hasattr(cls, 'summary'): -- cgit