Example #1
0
 def __str__(self):
     n_children = len(self.child_items)
     if n_children == 0:
         return _("<TreeItem(0x{:x}): {} = {}>").format(
             id(self.obj), self.obj_path,
             cut_off_str(self.obj, MAX_OBJ_STR_LEN))
     else:
         return _("<TreeItem(0x{:x}): {} ({:d} children)>").format(
             id(self.obj), self.obj_path, len(self.child_items))
Example #2
0
    def refreshTree(self):
        """
        Refreshes the tree model from the underlying root object
        (which may have been changed).
        """
        logger.info("")
        logger.info("refreshTree: {}".format(self.rootItem))

        root_item = self.treeItem(self.rootIndex())
        logger.info("  root_item:      {} (idx={})".format(root_item,
                                                           self.rootIndex()))
        inspected_item = self.treeItem(self.inspectedIndex())
        logger.info("  inspected_item: {} (idx={})".format(
            inspected_item,
            self.inspectedIndex()))

        assert (root_item is inspected_item) != self.inspectedNodeIsVisible, \
            "sanity check"

        self._auxRefreshTree(self.inspectedIndex())

        root_obj = self.rootItem.obj
        logger.debug("After _auxRefreshTree, "
                     "root_obj: {}".format(cut_off_str(root_obj, 80)))
        self.rootItem.pretty_print()

        # Emit the dataChanged signal for all cells.
        # This is faster than checking which nodes
        # have changed, which may be slow for some underlying Python objects.
        n_rows = self.rowCount()
        n_cols = self.columnCount()
        top_left = self.index(0, 0)
        bottom_right = self.index(n_rows-1, n_cols-1)

        logger.debug("bottom_right: ({}, {})".format(bottom_right.row(),
                                                     bottom_right.column()))
        self.dataChanged.emit(top_left, bottom_right)