diff options
author | Jan Pokorný <jpokorny@redhat.com> | 2013-09-24 23:39:09 +0200 |
---|---|---|
committer | Jan Pokorný <jpokorny@redhat.com> | 2013-09-24 23:39:09 +0200 |
commit | 2cee66ec06d192decd7dd8836daf7c4917b36aeb (patch) | |
tree | 0ddab48eb481a609de9ae0a43aab542891556e9c | |
parent | 72bf1f9b79db444f47089d521825f4d05dc35964 (diff) | |
download | cluster-overview-2cee66ec06d192decd7dd8836daf7c4917b36aeb.tar.gz cluster-overview-2cee66ec06d192decd7dd8836daf7c4917b36aeb.tar.xz cluster-overview-2cee66ec06d192decd7dd8836daf7c4917b36aeb.zip |
Fix issue with empty menus caused by 98155ef
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
-rw-r--r-- | lib.py | 20 |
1 files changed, 14 insertions, 6 deletions
@@ -9,7 +9,7 @@ from sys import path from os.path import expanduser, extsep from pydot import Dot, Edge, Node, Subgraph -__all__ = [] +REGISTRY = {} # modify/mutate BLACKLIST in order to filter some elements out # (not a beautiful, rather ad-hoc design, I know) @@ -41,9 +41,15 @@ def bl_map_nodes_edges(nodes, edges, prev_nnames=None): e.get_attributes()['style'] = 'invis' + class LibMeta(type): + def __new__(cls, name, bases, attrs): + ret = super(LibMeta, cls).__new__(cls, name, bases, attrs) + if REGISTRY.setdefault(name, ret) is not ret: + raise RuntimeError("Unexpected redefinition in REGISTRY") + return ret + def __init__(cls, name, bases, attrs): - __all__.append(name) super(LibMeta, cls).__init__(name, bases, attrs) old_init = cls.__init__ @@ -142,13 +148,13 @@ def xdot_graph(*args, **kwargs): label = widget.get_label() bl = self._kwargs.setdefault('blacklist', []) change = False - cls = globals()[label] + cls = REGISTRY[label] if widget.active and cls in bl: bl.remove(cls) bs = bases(cls) bs.remove(cls) for item in filter(lambda x: isinstance(x, gtk.CheckMenuItem) - and globals()[x.get_label()] in bs, + and REGISTRY[x.get_label()] in bs, widget.get_parent().get_children()): if not item.get_active(): item.set_active(True) @@ -218,9 +224,11 @@ def xdot_graph(*args, **kwargs): nodemenu.append(nodemenuitem) nodemenu.append(gtk.SeparatorMenuItem()) - for i in __all__: + # memoization + convenience + EdgeInvisible = REGISTRY.get('EdgeInvisible') + NodeInvisible = REGISTRY.get('NodeInvisible') + for i in REGISTRY.itervalues(): try: - i = globals()[i] if issubclass(i, LibEdge): if i in (LibEdge, EdgeInvisible): continue |