From d337d5bda1bd90d0828934910c78e3b2dc21c472 Mon Sep 17 00:00:00 2001 From: Marco Biasini <marco.biasini@unibas.ch> Date: Fri, 18 Feb 2011 17:21:42 +0100 Subject: [PATCH] added glob-style access to GfxNodes --- modules/gfx/pymod/__init__.py | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/modules/gfx/pymod/__init__.py b/modules/gfx/pymod/__init__.py index 23dced4ec..4dfc0fd64 100644 --- a/modules/gfx/pymod/__init__.py +++ b/modules/gfx/pymod/__init__.py @@ -140,3 +140,47 @@ def FitToScreen(gfx_ent, width=None, height=None, margin=0.01): factor_y*(1+margin)*geom.Length(sorted_axes[1]))+z_off) scene.SetRTC(rtc) + +class GfxNodeListAttrProxy: + def __init__(self, node_list, name): + self._node_list=node_list + self._name=name + + def __iter__(self): + for node in self._node_list: + yield getattr(node, self._name) + + def __call__(self, *args, **kwargs): + for node in self._node_list: + bound_method=getattr(node, self._name) + bound_method(*args, **kwargs) + +class GfxNodeListProxy(object): + def __init__(self, node_list): + self._nodes=node_list + + def __getattr__(self, name): + if name.startswith('_'): + return super(GfxNodeListProxy, self).__getattr__(name) + return GfxNodeListAttrProxy(self._nodes, name) + + def __setattr__(self, name, value): + if name.startswith('_'): + super(GfxNodeListProxy, self).__setattr__(name, value) + for node in self._nodes: + setattr(node, name, value) + +def _Match(scene, pattern="*"): + import os + import fnmatch + def _Recurse(path, node, pattern): + matches=[] + for child in node.children: + full_name=os.path.join(path, child.name) + if fnmatch.fnmatchcase(full_name, pattern): + matches.append(child) + matches.extend(_Recurse(full_name, child, pattern)) + return matches + return GfxNodeListProxy(_Recurse("", Scene().root_node, pattern)) + +SceneSingleton.__getitem__=_Match -- GitLab