Esempio n. 1
0
 def update_debug_inspector(self, locals_dict):
     """
     Given the contents of a dict representation of the locals in the
     current stack frame, update the debug inspector with the new values.
     """
     excluded_names = ['__builtins__', '__debug_code__',
                       '__debug_script__', ]
     names = sorted([x for x in locals_dict if x not in excluded_names])
     self.debug_model.clear()
     self.debug_model.setHorizontalHeaderLabels([_('Name'), _('Value'), ])
     for name in names:
         try:
             # DANGER!
             val = eval(locals_dict[name])
         except Exception:
             val = None
         if isinstance(val, list):
             # Show a list consisting of rows of position/value
             list_item = DebugInspectorItem(name)
             for i, i_val in enumerate(val):
                 list_item.appendRow([
                     DebugInspectorItem(str(i)),
                     DebugInspectorItem(repr(i_val))
                 ])
             self.debug_model.appendRow([
                 list_item,
                 DebugInspectorItem(_('(A list of {} items.)')
                                    .format(len(val)))
             ])
         elif isinstance(val, dict):
             # Show a dict consisting of rows of key/value pairs.
             dict_item = DebugInspectorItem(name)
             for k, k_val in val.items():
                 dict_item.appendRow([
                     DebugInspectorItem(repr(k)),
                     DebugInspectorItem(repr(k_val))
                 ])
             self.debug_model.appendRow([
                 dict_item,
                 DebugInspectorItem(_('(A dict of {} items.)')
                                    .format(len(val)))
             ])
         else:
             self.debug_model.appendRow([
                 DebugInspectorItem(name),
                 DebugInspectorItem(locals_dict[name]),
             ])
Esempio n. 2
0
 def update_debug_inspector(self, locals_dict):
     """
     Given the contents of a dict representation of the locals in the
     current stack frame, update the debug inspector with the new values.
     """
     excluded_names = ['__builtins__', '__debug_code__',
                       '__debug_script__', ]
     names = sorted([x for x in locals_dict if x not in excluded_names])
     self.debug_model.clear()
     self.debug_model.setHorizontalHeaderLabels([_('Name'), _('Value'), ])
     for name in names:
         try:
             # DANGER!
             val = eval(locals_dict[name])
         except Exception:
             val = None
         if isinstance(val, list):
             # Show a list consisting of rows of position/value
             list_item = DebugInspectorItem(name)
             for i, i_val in enumerate(val):
                 list_item.appendRow([
                     DebugInspectorItem(str(i)),
                     DebugInspectorItem(repr(i_val))
                 ])
             self.debug_model.appendRow([
                 list_item,
                 DebugInspectorItem(_('(A list of {} items.)')
                                    .format(len(val)))
             ])
         elif isinstance(val, dict):
             # Show a dict consisting of rows of key/value pairs.
             dict_item = DebugInspectorItem(name)
             for k, k_val in val.items():
                 dict_item.appendRow([
                     DebugInspectorItem(repr(k)),
                     DebugInspectorItem(repr(k_val))
                 ])
             self.debug_model.appendRow([
                 dict_item,
                 DebugInspectorItem(_('(A dict of {} items.)')
                                    .format(len(val)))
             ])
         else:
             self.debug_model.appendRow([
                 DebugInspectorItem(name),
                 DebugInspectorItem(locals_dict[name]),
             ])
Esempio n. 3
0
    def update_debug_inspector(self, locals_dict):
        """
        Given the contents of a dict representation of the locals in the
        current stack frame, update the debug inspector with the new values.
        """
        excluded_names = ["__builtins__", "__debug_code__", "__debug_script__"]
        names = sorted([x for x in locals_dict if x not in excluded_names])

        # Remove rows so we keep the same column layouts if manually set
        while self.debug_model.rowCount() > 0:
            self.debug_model.removeRow(0)
        for name in names:
            item_to_expand = None
            try:
                # DANGER!
                val = eval(locals_dict[name])
            except Exception:
                val = None
            if isinstance(val, list):
                # Show a list consisting of rows of position/value
                list_item = DebugInspectorItem(name)
                item_to_expand = list_item
                for i, i_val in enumerate(val):
                    list_item.appendRow([
                        DebugInspectorItem(str(i)),
                        DebugInspectorItem(repr(i_val)),
                    ])
                self.debug_model.appendRow([
                    list_item,
                    DebugInspectorItem(
                        _("(A list of {} items.)").format(len(val))),
                ])
            elif isinstance(val, dict):
                # Show a dict consisting of rows of key/value pairs.
                dict_item = DebugInspectorItem(name)
                item_to_expand = dict_item
                for k, k_val in val.items():
                    dict_item.appendRow([
                        DebugInspectorItem(repr(k)),
                        DebugInspectorItem(repr(k_val)),
                    ])
                self.debug_model.appendRow([
                    dict_item,
                    DebugInspectorItem(
                        _("(A dict of {} items.)").format(len(val))),
                ])
            else:
                self.debug_model.appendRow([
                    DebugInspectorItem(name),
                    DebugInspectorItem(locals_dict[name]),
                ])
            # Expand dicts/list with names matching old expanded entries
            if (hasattr(self, "debug_inspector")
                    and name in self.debug_inspector.expanded_dicts
                    and item_to_expand is not None):
                self.debug_inspector.expand(
                    self.debug_model.indexFromItem(item_to_expand))