From 0aae7813af4bb9ccdc4f02ba7cd483c8967078f1 Mon Sep 17 00:00:00 2001 From: Vincent Vinet Date: Tue, 31 Mar 2009 19:17:42 +0000 Subject: Experimentation on introspecting gobjects --- diff --git a/src/sugar/tutorius/editor.py b/src/sugar/tutorius/editor.py index bf70216..42cc718 100644 --- a/src/sugar/tutorius/editor.py +++ b/src/sugar/tutorius/editor.py @@ -142,6 +142,38 @@ class WidgetIdentifier(gtk.Window): nbk.append_page(swd2, gtk.Label(_("Explorer"))) swd2.show() + ############################### + # GObject Explorer Page + ############################### + tree2 = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_STRING) + explorer2 = gtk.TreeView(tree2) + + pathrendr2 = gtk.CellRendererText() + pathrendr2.set_properties(background="#ffffff", foreground="#000000") + pathcol2 = gtk.TreeViewColumn(_("Path"), pathrendr2, text=0, background=0, foreground=0) + explorer2.append_column(pathcol2) + + typerendr2 = gtk.CellRendererText() + typerendr2.set_properties(background="#ffffff", foreground="#000000") + typecol2 = gtk.TreeViewColumn(_("Widget"), typerendr2, text=1, background=1, foreground=1) + explorer2.append_column(typecol2) + + self.__populate_gobject_treestore( + tree2, #tree + tree2.append(None, ["activity",self._activity.get_name()]), #parent + self._activity, #widget + "activity" #path + ) + + explorer2.set_expander_column(typecol2) + + swd3 = gtk.ScrolledWindow() + swd3.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) + swd3.add(explorer2) + explorer2.show() + nbk.append_page(swd3, gtk.Label(_("GObject Explorer"))) + swd3.show() + def __populate_treestore(self, tree, parent, widget, path): """Populates the treestore with the widget's children recursively @param tree gtk.TreeStore to populate @@ -163,6 +195,59 @@ class WidgetIdentifier(gtk.Window): ) + def __populate_gobject_treestore(self, tree, parent, widget, path, listed=None): + """Populates the treestore with the widget's children recursively + @param tree gtk.TreeStore to populate + @param parent gtk.TreeIter to append to + @param widget gtk.Widget to check for children + @param path treeish of the widget + """ + listed = listed or [] + if widget in listed: + return + listed.append(widget) + #DEBUG: show parameters in log window gehehe + #self._handle_events((path,str(type(widget)))) + #Add a child node + children = tree.append(parent, ["","children"]) + for i in dir(widget): + #Add if a gobject + try: + child = getattr(widget, i) + except: + continue + if isinstance(child,gobject.GObject): + childpath = ".".join([path, i]) + child = getattr(widget, i) + self.__populate_gobject_treestore( + tree, #tree + tree.append(children, [childpath, i]), #parent + child, #widget + path + "." + i, #path, + listed + ) + widgets = tree.append(parent, ["","widgets"]) + wchildren = get_children(widget) + for i in xrange(len(wchildren)): + childpath = ".".join([path, str(i)]) + child = wchildren[i] + self.__populate_gobject_treestore( + tree, #tree + tree.append(widgets, [childpath, (hasattr(child,"get_name") and child.get_name()) or i]), #parent + child, #widget + childpath, #path, + listed + ) + + #Add signals and attributes nodes + signals = tree.append(parent, ["","signals"]) + for signame in gobject.signal_list_names(widget): + tree.append(signals, ["",signame]) + + attributes = tree.append(parent, ["","properties"]) + for prop in gobject.list_properties(widget): + tree.append(attributes, ["",prop]) + def __filter_toggle_cb(self, btn, eventname): """Callback for signal name checkbuttons' toggling""" #Disconnect existing handlers on key -- cgit v0.9.1