def _get_image_not_found ( cls ): """ Returns the 'image not found' image resource. """ if cls._image_not_found is None: from facets.ui.ui_facets import image_for cls._image_not_found = image_for( '@facets:image_not_found' ) return cls._image_not_found #-- EOF ------------------------------------------------------------------------
def bitmap_cache ( name, standard_size, path = None ): """ Converts an image file name to a cached bitmap. """ global app_path, facets_path if name[:1] == '@': image = image_for( name.replace( ' ', '_' ).lower() ) if image is not None: return image.create_image().ConvertToBitmap() if path is None: if facets_path is None: import facets.ui.wx.editors facets_path = join( dirname( facets.ui.wx.editors.__file__ ), 'images' ) path = facets_path elif path == '': if app_path is None: app_path = join( dirname( sys.argv[ 0 ] ), '..', 'images' ) path = app_path filename = abspath( join( path, name.replace( ' ', '_' ).lower() + '.gif' ) ) bitmap = _bitmap_cache.get( filename + ( '*'[ not standard_size: ] ) ) if bitmap is not None: return bitmap std_bitmap = bitmap = wx.BitmapFromImage( wx.Image( filename ) ) _bitmap_cache[ filename ] = bitmap dx = bitmap.GetWidth() if dx < standard_bitmap_width: dy = bitmap.GetHeight() std_bitmap = wx.EmptyBitmap( standard_bitmap_width, dy ) dc1 = wx.MemoryDC() dc2 = wx.MemoryDC() dc1.SelectObject( std_bitmap ) dc2.SelectObject( bitmap ) dc1.SetPen( wx.TRANSPARENT_PEN ) dc1.SetBrush( wx.WHITE_BRUSH ) dc1.DrawRectangle( 0, 0, standard_bitmap_width, dy ) dc1.Blit( ( standard_bitmap_width - dx ) / 2, 0, dx, dy, dc2, 0, 0 ) _bitmap_cache[ filename + '*' ] = std_bitmap if standard_size: return std_bitmap return bitmap
def pixmap_cache ( name ): """ Return the QPixmap corresponding to a filename. If the filename does not contain a path component then the local 'images' directory is used. """ if name[:1] == '@': image = image_for( name ) if image is not None: return image.bitmap path, _ = os.path.split( name ) if not path: name = os.path.join( os.path.dirname( __file__ ), 'images', name ) pm = QPixmap() if not QPixmapCache.find( name, pm ): pm.load( name ) QPixmapCache.insert( name, pm ) return pm
# ------------------------------------------------------------------------------- # 'connection' metadata filter: # ------------------------------------------------------------------------------- def is_connection(value): return isinstance(value, Connection) # ------------------------------------------------------------------------------- # Constants: # ------------------------------------------------------------------------------- # Images used to create the composite feature image: unlinked_image = image_for("@facets:connect_unlinked_feature") linked_image = image_for("@facets:connect_linked_feature") drag_image = image_for("@facets:connect_drag_feature") to_image = image_for("@facets:connect_to_feature") from_image = image_for("@facets:connect_from_feature") file_image = image_for("@facets:connect_file_feature") object_image = image_for("@facets:connect_object_feature") # Menu to display when there are no available connections/disconnections: no_connections = Menu(Action(name="No connections available", enabled=False), name="popup") PermanentConnections = "facets.extra.features.ConnectFeature." "permanent_connections" # ------------------------------------------------------------------------------- # 'Connection' class: # -------------------------------------------------------------------------------
def _image_default ( self ): from facets.ui.ui_facets import image_for return image_for( '@facets:pyface.jpg' )
import facet_db from facets.ui.menu \ import Menu, Action from facets.ui.dock.api \ import DockWindowFeature from facets.ui.ui_facets \ import image_for #------------------------------------------------------------------------------- # Constants: #------------------------------------------------------------------------------- no_connections_image = image_for( '@facets:no_connections_feature' ) connections_image = image_for( '@facets:connections_feature' ) # Menu to display when there are no available connections/disconnections: no_connections = Menu( Action( name = 'No connections available', enabled = False ), name = 'popup' ) PermanentConnections = 'facets.extra.features.ConnectFeature.' \ 'permanent_connections' #------------------------------------------------------------------------------- # Filter for extracting facets which support the 'connect' protocol: #-------------------------------------------------------------------------------
#-- Imports -------------------------------------------------------------------- from facets.api \ import HasFacets, Any, Range, Int, PrototypedFrom, View, VSplit, Item, \ Handler from facets.ui.custom_control_editor \ import CustomControlEditor, ControlEditor from facets.ui.ui_facets \ import image_for #-- Global data ---------------------------------------------------------------- # The base images the LED digits are derived from: LEDDigits = [ image_for( '@led:D%s?H32S~H14l11S|l16' % c ) for c in '0123456789MB' ] LEDRatio = float( LEDDigits[0].width ) / LEDDigits[0].height #-- _LEDEditor class ----------------------------------------------------------- class _LEDEditor ( ControlEditor ): #-- Facet Definitions ------------------------------------------------------ # The number of digits to display: digits = PrototypedFrom( 'factory' ) # The images used to display each of the digits: images = Any
# Constants: #------------------------------------------------------------------------------- a_file_position = FilePosition() # Valid 'drop styles' and their corresponding types: valid_types = ( ( 'file_positions', [ a_file_position ] ), ( 'file_position', a_file_position ), ( 'file_names', [ '\\test' ] ), ( 'file_name', '\\test' ) ) # Feature images: feature_images = ( image_for( '@facets:drop_file_feature' ), image_for( '@facets:drag_file_feature' ) ) #------------------------------------------------------------------------------- # Defines the 'drop_file' metadata filter: #------------------------------------------------------------------------------- def drop_file_filter ( value ): return ((value is True) or isinstance( value, ( str, list, tuple, DropFile ) )) #------------------------------------------------------------------------------- # 'DropFileFeature' class: #-------------------------------------------------------------------------------
import on_facet_set from facets.ui.dock.api \ import DockWindowFeature from facets.ui.ui_facets \ import image_for from facets.extra.api \ import Saveable #------------------------------------------------------------------------------- # Constants: #------------------------------------------------------------------------------- save_feature = image_for( '@facets:save_feature' ) #------------------------------------------------------------------------------- # 'SaveFeature' class: #------------------------------------------------------------------------------- class SaveFeature ( DockWindowFeature ): #-- Facet Definitions ------------------------------------------------------ # The tooltip to display when the mouse is hovering over the image: tooltip = 'Click to save.' #-- Facet Event Handlers --------------------------------------------------- @on_facet_set( 'dock_control:object:needs_save' )
from dock_control \ import DockControl from dock_region \ import DockRegion from dock_section \ import DockSection #------------------------------------------------------------------------------- # Constants: #------------------------------------------------------------------------------- # DockWindowShell frame icon: FrameIcon = image_for( '@facets:shell.ico' ).create_icon() # DockWindowShell window style: shell_style = set( [ 'frame', 'resizable', 'min_max', 'float' ] ) #------------------------------------------------------------------------------- # 'DockWindowShell' class: #------------------------------------------------------------------------------- class DockWindowShell ( HasPrivateFacets ): #-- Facet Definitions ------------------------------------------------------ # The adapted toolkit window which is the actual shell: control = Instance( Control )
) context_menu = Menu( object_action, dock_control_action, control_action, ui_action, name = 'popup' ) #------------------------------------------------------------------------------- # Images: #------------------------------------------------------------------------------- feature_images = { 'object': image_for( '@facets:debug_object_feature' ), 'dock_control': image_for( '@facets:debug_dock_control_feature' ), 'control': image_for( '@facets:debug_control_feature' ), 'ui': image_for( '@facets:debug_ui_feature' ) } #------------------------------------------------------------------------------- # 'DebugFeature' class: #------------------------------------------------------------------------------- class DebugFeature ( DockWindowFeature ): #-- Class Constants -------------------------------------------------------- # The user interface name of the feature: feature_name = 'Debug'