Exemplo n.º 1
0
 def _save_set ( self ):
     """ Handles the 'save' facet being changed.
     """
     file_name = join( self.path, self.file_name )
     if write_file( file_name, self.code ):
         exported_tools = self.facet_db_get( ExportedTools, {} )
         exported_tools[ self.title ] = ( file_name, self.class_name )
         self.facet_db_set( ExportedTools, exported_tools )
         self.facet_db_set( 'path', self.path )
         self.status = '%s saved on %s' % ( file_name, time_stamp() )
     else:
         self.status = 'Error occurred trying to write %s' % file_name
Exemplo n.º 2
0
    def _data_default ( self ):
        perspective = self.perspective
        classes     = list( set( [ t.__class__ for t in perspective.tools ] ) )
        feature_classes = list( perspective.features )
        classes.sort( lambda l, r: cmp( l.__name__, r.__name__ ) )
        feature_classes.sort( lambda l, r: cmp( l.__name__, r.__name__ ) )
        imports = [ 'from %s \\\n    import %s' % ( klass.__module__,
                                                    klass.__name__ )
                    for klass in classes + feature_classes ]
        features = feature_set = ''
        if len( feature_classes ) > 0:
            class_names = [ klass.__name__ for klass in feature_classes ]
            features    = (FeaturesTemplate % ', '.join( class_names ))
            feature_set = ('\n\nSupported Features:\n\n- %s' %
                           '\n- '.join( class_names ))

        tools = perspective.tools[:]
        tools.sort( lambda l, r: cmp( l.__class__.__name__,
                                      r.__class__.__name__ ) )
        tool_facets = [ "tool_%d = ToolInstance( %s, %r )" %
                        ( i + 1, tool.__class__.__name__, tool.name )
                        for i, tool in enumerate( tools ) ]
        tool_map = dict( [ ( tool, i+ 1 ) for i, tool in enumerate( tools ) ] )
        connections_default = ''
        connections         = perspective.connections
        if len( connections ) > 0:
            connection_items = [ ConnectionTemplate % ( connection.connection,
                            tool_map[ connection.object1 ], connection.name1,
                            tool_map[ connection.object2 ], connection.name2 )
                            for connection in connections ]
            connections_default = (ConnectionsDefaultTemplate %
                                   ',\n'.join( connection_items ))

        return {
            'perspective':         self.perspective_name,
            'date':                time_stamp(),
            'tools':               '\n- '.join( [ klass.__name__
                                                  for klass in classes ] ),
            'tool_facets':         '\n    '.join( tool_facets ),
            'imports':             '\n\n'.join( imports ),
            'dock_style':          perspective.dock_style,
            'template':            self._format_template(
                                       repr( dumps( perspective.layout ) ) ),
            'connections_default': connections_default,
            'features':            features,
            'feature_set':         feature_set
        }