app: Refactor get_all_objects.

This commit is contained in:
Florian Bruhin 2014-09-23 06:39:23 +02:00
parent 698e4049d3
commit 1ce1c91d69

View File

@ -465,16 +465,16 @@ class Application(QApplication):
lines.append(repr(w)) lines.append(repr(w))
return '\n'.join(lines) return '\n'.join(lines)
def get_all_objects(self, obj=None, depth=0, lines=None): def _get_pyqt_objects(self, lines, obj, depth=0):
"""Get all children of an object recursively as a string.""" """Recursive method for get_all_objects to get Qt objects."""
if lines is None:
lines = []
if obj is None:
obj = self
for kid in obj.findChildren(QObject): for kid in obj.findChildren(QObject):
lines.append(' ' * depth + repr(kid)) lines.append(' ' * depth + repr(kid))
self.get_all_objects(kid, depth + 1, lines) self._get_pyqt_objects(lines, kid, depth + 1)
if depth == 0:
def get_all_objects(self):
"""Get all children of an object recursively as a string."""
lines = []
self._get_pyqt_objects(lines, self)
lines.insert(0, '{} objects:'.format(len(lines))) lines.insert(0, '{} objects:'.format(len(lines)))
return '\n'.join(lines) return '\n'.join(lines)