def _parentWidgetPath(self, widget): parent = widget.get_parent() while parent is not None and logutils.getWidgetName(parent) is None: parent = parent.get_parent() if parent is None: return [] return self._parentWidgetPath(parent) + [logutils.getWidgetName(parent)]
def sanity_check(widget, path=[]): widgetname = logutils.getWidgetName(widget) if widgetname: path = path + [widgetname] if logutils.findWidget(string.join(path, ':')) is not widget: raise ValueError("%s is not a unique widget name" % path) if isinstance(widget, gtk.Container): for child in widget.get_children(): sanity_check(child, path)
def location(self, widget, *args): name = logutils.getWidgetName(widget) if not name: raise logutils.GtkLoggerException("Unnamed widget") path = self._parentWidgetPath(widget) + [name] if path[0] not in logutils.getTopWidgetNames(): raise logutils.GtkLoggerException(string.join(path, ':') + " is not contained in a top-level widget") return "findWidget('%s')" % string.join(path, ':')
def _getMenuPath(self, gtkmenuitem): path = [logutils.getWidgetName(gtkmenuitem)] parent = gtkmenuitem.get_parent() if isinstance(parent, gtk.Menu): try: pp = parent.oofparent except AttributeError: # Parent is a Menu, but doesn't have oofparent set. # It must be a pop-up menu. pass else: pparent, ppath = self._getMenuPath(pp) return pparent, ppath + path return parent, path
def _getMenuPath(self, gtkmenuitem): path = [logutils.getWidgetName(gtkmenuitem)] parent = gtkmenuitem.get_parent() if isinstance(parent, gtk.Menu): try: pp = parent.oofparent except AttributeError: # Parent is a Menu, but doesn't have oofparent set. # It must be a pop-up menu. pass else: pparent, ppath = self._getMenuPath(pp) return pparent, ppath+path return parent, path