summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib.py20
1 files changed, 14 insertions, 6 deletions
diff --git a/lib.py b/lib.py
index 0918e36..4cd9ac7 100644
--- a/lib.py
+++ b/lib.py
@@ -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