Exemple #1
0
def convert_theme ( value, level = 3, cache = True ):
    """ Converts a specified value to a Theme if possible.
    """
    if not isinstance( value, basestring ):
        return value

    from theme import Theme

    kind = value[:1]
    if kind in '?~#$':
        from facets.core.facet_db import facet_db

        theme = facet_db.get( value, db = 'themes' )
        if isinstance( theme, Theme ):
            return theme

    if (kind == '@') and (value.find( ':' ) >= 2):
        try:
            from facets.ui.image import ImageLibrary

            info = ImageLibrary().image_info( value )
            if info is not None:
                return info.theme
        except:
            info = None

    return Theme( image = image_for( value, level + 1, cache ) )
    def get_permanent_connections ( cls, context ):
        connections = cls.permanent_connections.get( context )
        if connections is None:
            connections = facet_db.get( context, [] )
            cls.permanent_connections[ context ] = connections

        return connections
Exemple #3
0
 def _selected_set ( self, record ):
     """ Handles the user selecting a database record.
     """
     if record is not None:
         # Display the contents of the selected data base record:
         id      = record.id
         payload = facet_db.get( id, Missing, db = self.database )
         if payload is not Missing:
             self.value = HasPayload( payload      = payload,
                                      payload_name = id.split( '.' )[-1],
                                      payload_full_name = id )
     else:
         self.value = None
    def feature_for ( cls, dock_control ):
        """ Returns a feature object for use with the specified DockControl (or
            None if the feature does not apply to the DockControl object).
        """
        object = dock_control.object
        if isinstance( object, HasFacets ):
            names = object.facet_names( save_state = True )
            if len( names ) > 0:

                # Get the id to save the options under:
                ids = object.facet_names( save_state_id = True )
                id  = ''
                if len( ids ) == 1:
                    id = getattr( object, ids[0] )

                if id == '':
                    id = 'unknown.plugins.%s.state' % dock_control.name

                # Assign the current saved state (if any) to the object:
                state = facet_db.get( id )
                if state is not None:
                    for name, value in state.iteritems():
                        try:
                            setattr( object, name, value )
                        except:
                            pass

                # Create and return the feature:
                return cls(
                    dock_control = dock_control,
                    id           = id ).set(
                    names        = names
                )

        return None

#-- EOF ------------------------------------------------------------------------
 def check_permanent_connections(cls):
     if not cls.permanent_loaded:
         cls.permanent_loaded = True
         cls.permanent_connections = facet_db.get(PermanentConnections, [])