Esempio n. 1
0
    def __init__ ( self, **traits ):
        """ Initializes the object.
        """
        super( AnFBIViewer, self ).__init__( **traits )

        source = read_file( self.file_name )
        if source is not None:
            text   = source.split( '\n' )
            nlines = self.lines
            if nlines >= 0:
                self.nlines = nlines
                line        = self.line - 1
                source      = '\n'.join( text[ line: line + nlines ] )
                self.line   = 1
                self.starting_line = line
            else:
                self.nlines = len( text )

            self.selected_line = self.cursor = self.line
            self.source        = source

            self.module = fbi_object.get_module( self.file_name )
            self.module.on_trait_change( self.update_viewer, 'bp_lines' )
            self.module.on_trait_change( self.update_viewer, 'bp_lines_items' )

            title  = self.file_name
            object = self.object
            if object is not None:
                title += '     Object: %s(0x%08X)' % (
                         object.__class__.__name__, id( object ) )
            self.title = title

            self.update_viewer()
Esempio n. 2
0
    def _get_source ( self ):
        if self._source is None:
            self._source = ''
            source       = read_file( self.file_name )
            if source is not None:
                try:
                    self._source = source.split( '\n' )[ self.line - 1 ].strip()
                except:
                    pass

        return self._source
Esempio n. 3
0
    def _get_source(self):
        if self._source is None:
            self._source = ''
            source = read_file(self.file_name)
            if source is not None:
                try:
                    self._source = source.split('\n')[self.line - 1].strip()
                except:
                    pass

        return self._source
Esempio n. 4
0
 def _load_file_name ( self, file_name ):
     """ Loads a specified source file.
     """
     self._dont_update = True
     self.can_save = True
     source        = read_file( file_name )
     if source is None:
         self.error    = 'Error reading file'
         self.can_save = False
         source     = ''
     self.source = source
     self._dont_update = False
     self.needs_save   = False
Esempio n. 5
0
 def _update ( self, file_name ):
     """ Updates the view with the contents of the specified file.
     """
     data = read_file( file_name )
     if data is not None:
         if self.is_text( data ):
             if self.lines > 0:
                 self.text = '\n'.join( data.split( '\n' )
                             [ max( 0, self.line - 1 ):
                               self.line + self.lines - 1 ] )
             else:
                 self.text = data
         else:
             format    = self.format
             self.text = '\n'.join( [ format( i, data[ i: i + 16 ] )
                                    for i in range( 0, len( data ), 16 ) ] )
Esempio n. 6
0
    def invoke(self, file_name, monitor):
        """ Invokes the rule for a specified file name.
        """
        path, base = split(file_name)
        root, ext = splitext(base)
        dic = {
            '%n': repr(file_name),
            '%p': repr(path),
            '%b': repr(base),
            '%r': repr(root),
            '%x': repr(ext),
            '%^': repr(monitor.path),
            '%.': repr(join(path, root)),
            '%m': 'monitor'
        }
        if '%c' in rule:
            dic['%c'] = repr(read_file(file_name))

        monitor.invoke(file_name, self.substitute(rule, dic))
Esempio n. 7
0
    def invoke ( self, file_name, monitor ):
        """ Invokes the rule for a specified file name.
        """
        path, base = split( file_name )
        root, ext  = splitext( base )
        dic = {
            '%n': repr( file_name ),
            '%p': repr( path ),
            '%b': repr( base ),
            '%r': repr( root ),
            '%x': repr( ext ),
            '%^': repr( monitor.path ),
            '%.': repr( join( path, root ) ),
            '%m': 'monitor'
        }
        if '%c' in rule:
            dic[ '%c' ] = repr( read_file( file_name ) )

        monitor.invoke( file_name, self.substitute( rule, dic ) )
Esempio n. 8
0
    def _item_changed ( self, item ):
        """ Handles the 'item' trait being changed.
        """
        # Check to see if it is a list of File objects, which represent files
        # dropped onto the view from an external source (like MS Explorer):
        if isinstance( item, list ) and (len( item ) > 0):
            for an_item in item:
                if not isinstance( an_item, File ):
                    break
            else:
                for an_item in item:
                    self._item_changed( an_item )
                return

        # Set up the default values:
        name  = full_name = ''
        line  = 0
        lines = -1

        # Extract the file name from a File object:
        if isinstance( item, File ):
            item = item.absolute_path

        # Handle the case of an item which contains a payload:
        elif isinstance( item, HasPayload ):
            name      = item.payload_name
            full_name = item.payload_full_name
            item      = item.payload

        # Handle the case of a file position, which has a file name and a
        # possible starting line and range of lines:
        if isinstance( item, FilePosition ):
            name  = item.name
            line  = item.line
            lines = item.lines
            item  = item.file_name

        # Only create an inspector if there actually is a valid item:
        if item is not None:
            inspector = None

            # If it is a string value, check to see if it is a valid file name:
            if isinstance( item, basestring ):
                data = read_file( item, 'r' )
                if data is not None:
                    if name == '':
                        name      = basename( item )
                        full_name = item
                    try:
                        inspector = ObjectInspector(
                            object    = self._object_from_pickle( data ),
                            name      = name,
                            full_name = full_name )
                    except:
                        try:
                            inspector = ObjectInspector(
                                object    = self._object_from_pickle(
                                                read_file( item ) ),
                                name      = name,
                                full_name = full_name )
                        except:
                            inspector = FileInspector( name      = name,
                                                       line      = line,
                                                       lines     = lines ).set(
                                                       file_name = item )

            # If it is not a file, then it must just be a generic object:
            if inspector is None:
                inspector = ObjectInspector( object    = item,
                                             name      = name,
                                             full_name = full_name )

            inspectors = self.inspectors

            # Make sure the # of inspectors doesn't exceed the maximum allowed:
            if len( inspectors ) >= self.max_inspectors:
                del inspectors[0]

            # Add the new inspector to the list of inspectors (which will
            # cause it to appear as a new notebook page):
            inspectors.append( inspector )

            # Reset the current item to None, so we are ready for a new item:
            do_later( self.set, item = None )