Example #1
0
 def __init__ ( self, **facets ):
     """ Initializes the object.
     """
     super( ObjectDebugger, self ).__init__( **facets )
     self.module = CBModuleFile( path        = self.file_name,
                                 python_path = self.python_path,
                                 object      = self.object )
     do_later( self.select_object )
Example #2
0
class ObjectDebugger ( HasPrivateFacets ):

    #-- Facet Definitions ------------------------------------------------------

    # The object that created this view:
    object_source = Any

    # The path of the file being debugged:
    file_name = File

    # The Python path the file was found in:
    python_path = Directory

    # The name to use on the debugger page:
    name = Property

    # The object being debugged:
    object = Any

    # The module descriptor for the file:
    module = Instance( CBModuleFile )

    # The currently selected object class:
    selected = Any

    #-- Facets View Definitions ------------------------------------------------

    view = View(
        Item( 'module',
              id         = 'browser',
              show_label = False,
              editor     = TreeEditor( nodes    = cb_tree_nodes,
                                       editable = False,
                                       selected = 'selected' ),
              resizable  = True
        ),
        id        = 'facets.extra.tools.object_source.ObjectDebugger',
        resizable = True
    )

    #-- Public Methods ---------------------------------------------------------

    def __init__ ( self, **facets ):
        """ Initializes the object.
        """
        super( ObjectDebugger, self ).__init__( **facets )
        self.module = CBModuleFile( path        = self.file_name,
                                    python_path = self.python_path,
                                    object      = self.object )
        do_later( self.select_object )


    def select_object ( self ):
        """ Selects the class of the current object in the class browser.
        """
        name = self.object.__class__.__name__
        for cb_class in self.module.get_children():
            if name == cb_class.name:
                self.selected = cb_class
                break

    #-- Facet Event Handlers ---------------------------------------------------

    def _selected_set ( self, selected ):
        """ Handles a tree node being selected.
        """
        # Read the object's text to force it to calculate the starting
        # line number of number of lines in the text fragment:
        ignore = selected.text

        # Set the file position for the object:
        self.object_source.file_position = FilePosition(
                                           name      = selected.name,
                                           file_name = selected.path,
                                           line      = selected.line_number + 1,
                                           lines     = selected.lines,
                                           object    = self.object )

    #-- Property Implementations -----------------------------------------------

    def _get_name ( self ):
        return basename( self.file_name )