11from pyvba .viewer import Viewer , FunctionViewer , CollectionViewer
2+ from collections import OrderedDict
23
34# used to skip predetermined objects by exact name
4- # fixme: remove extra parameters
5- skip = ['Application' , 'Parent' , 'Units' , 'Parameters' ]
5+ skip = ['Application' , 'Parent' ]
6+
7+ # store a dictionary of the discovered items
8+ found = OrderedDict ()
69
710
8- # TODO: fix infinite recursion issue
911class Browser (Viewer ):
1012 def __init__ (self , app , name : str , parent : Viewer = None ):
1113 """Create a browser from an application string or win32com object.
@@ -38,18 +40,26 @@ def from_viewer(viewer, parent=None):
3840 else Browser (viewer .com , viewer .name , viewer .parent if parent is None else parent )
3941
4042 @staticmethod
41- def skip (item : str ):
42- """Adds a keyword to the skip list."""
43+ def clr_found ():
44+ """Clears the stored dictionary of items browsed."""
45+ global found
46+ found = OrderedDict ()
47+
48+ @staticmethod
49+ def skip (* item : str ):
50+ """Add one or more keywords to the skip list."""
4351 global skip
44- if item not in skip :
45- skip .append (item )
52+ for i in item :
53+ if i not in skip :
54+ skip .append (i )
4655
4756 @staticmethod
48- def rm_skip (item : str ):
49- """Remove a keyword from the skip list."""
57+ def rm_skip (* item : str ):
58+ """Remove one or more keywords from the skip list."""
5059 global skip
51- if item in skip :
52- skip .remove (item )
60+ for i in item :
61+ if i not in skip :
62+ skip .remove (i )
5363
5464 @staticmethod
5565 def clr_skip ():
@@ -66,8 +76,9 @@ def all(self) -> dict:
6676
6777 def _generate (self ):
6878 """Iterates through all objects when called upon."""
69- global skip
79+ global skip , found
7080
81+ # iterate through items
7182 for name in self ._objects + [i .name for i in self ._methods ]:
7283 if name in skip :
7384 continue
@@ -83,6 +94,17 @@ def _generate(self):
8394 self ._errors [name ] = e .args
8495 continue
8596
97+ # add items to the 'found' dictionary
98+ for name , value in self ._all .items ():
99+ if isinstance (value , Viewer ):
100+ if value .type not in found :
101+ found [value .type ] = []
102+
103+ if value not in found [value .type ]:
104+ found [value .type ].append (value )
105+ else :
106+ self ._all [name ] = found [value .type ].index (value )
107+
86108 def search (self , name : str , exact : bool = False ):
87109 """Return a dictionary in format {path: item} matching the name.
88110
0 commit comments