Skip to content

Commit 6c2dce6

Browse files
added collection objects to visited and removed __eq__ functionality
1 parent d293201 commit 6c2dce6

File tree

4 files changed

+17
-51
lines changed

4 files changed

+17
-51
lines changed

pyvba/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from .viewer import Viewer, FunctionViewer, CollectionViewer
22
from .browser import Browser, CollectionBrowser
3-
from .export import XMLExport, JSONExport
3+
from .export import ExportStr, XMLExport, JSONExport

pyvba/browser.py

Lines changed: 13 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ def _generate(self):
104104

105105
if value not in visited[value.type]:
106106
visited[value.type].append(value)
107-
else:
108-
self._all[name] = visited[value.type][visited[value.type].index(value)]
109107

110108
def browse_all(self):
111109
"""Populate the browser and all descendents of the browser."""
@@ -114,61 +112,33 @@ def browse_all(self):
114112

115113
# populate child browsers if not already visited
116114
for name, value in self._all.items():
117-
if type(value) is Browser and value not in visited[value.type]:
115+
if isinstance(value, Browser) and value not in visited[value.type]:
118116
name.browse_all()
119117

120-
def search(self, name: str, exact: bool = False):
121-
"""Return a dictionary in format {path: item} matching the name.
122-
123-
Search for all instances of a method or object containing a name.
124-
125-
Parameters
126-
----------
127-
exact: bool
128-
A flag that searches for exact matches.
129-
name: str
130-
The name of the attribute to search for.
131-
132-
Returns
133-
-------
134-
dict
135-
The results of the search in format {path: item}.
136-
"""
137-
...
138-
139-
def goto(self, path: str):
140-
"""Retrieve an object at a given location.
141-
142-
Parameters
143-
----------
144-
path: str
145-
The location of the item delimited by '/'.
146-
147-
Examples
148-
--------
149-
`goto('Bodies/Item/1/HybridShapes/GetItem')` yields the 'GetItem' function.
150-
151-
"""
152-
...
153-
154-
def view_vba(self) -> str:
155-
"""Returns a string that replicates the VBA tree."""
156-
...
157-
158118
def regen(self):
159119
"""Regenerate the `all` property."""
160120
self._all = {}
161121
self._generate()
162122

163123

164124
class CollectionBrowser(Browser, CollectionViewer):
165-
def __init__(self, obj: CollectionViewer):
125+
def __init__(self, obj):
166126
super().__init__(obj.com, obj.name, obj.parent)
167-
self._items = [self.from_viewer(i) for i in self._items]
127+
self._items = [self.from_viewer(item) for item in self._items]
168128

169129
def __str__(self):
170130
return "<class 'CollectionBrowser'>: " + self._name
171131

172132
def _generate(self):
133+
global visited
173134
super()._generate()
174135
self._all['Item'] = self._items
136+
137+
# add items to the visited dictionary
138+
for value in self._all['Item']:
139+
if isinstance(value, Viewer):
140+
if value.type not in visited:
141+
visited[value.type] = []
142+
143+
if value not in visited[value.type]:
144+
visited[value.type].append(value)

pyvba/export.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,8 @@ def _generate_vba(self, elem, tabs: int = 0, **kwargs) -> str:
435435
return json
436436

437437
def _generate_dict(self) -> str:
438-
# collect visited data and obtain a copy
439-
"""Begin generating the XML string based on the visited dictionary."""
438+
"""Begin generating the JSON string based on the visited dictionary."""
439+
440440
# populate browser and copy visited
441441
self._browser.browse_all()
442442
visited2 = copy.copy(visited)
@@ -464,7 +464,7 @@ def _generate_dict(self) -> str:
464464
json += '\t\t\t]},\n'
465465
else:
466466
if isinstance(value2, Browser):
467-
json += f'\t\t\t{{ \"{value2.name}\": \"BrowserObject\" }},\n'
467+
json += f'\t\t\t{{ "{value2.name}": "BrowserObject" }},\n'
468468

469469
elif isinstance(value2, com_error):
470470
if self._skip_err:

pyvba/viewer.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ def __init__(self, app, name: str = None, parent: object = None):
4141

4242
self._errors = {}
4343

44-
def __eq__(self, other):
45-
return other.type == self._type and other.name == self._name
46-
4744
def __getattr__(self, item):
4845
return self.getattr(item)
4946

@@ -190,7 +187,6 @@ def __init__(self, obj, name: str = None, parent: object = None):
190187
self._items = [
191188
Viewer.gettype(i, name, self)
192189
for i in self._com
193-
if i is not super()._com
194190
]
195191

196192
def __str__(self):

0 commit comments

Comments
 (0)