Example #1
0
    def init ( self, parent ):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """
        self.adapter = toolkit().create_text_input( parent, read_only = True )
        self.adapter.background_color = ReadonlyColor

        self.set_tooltip()
Example #2
0
    def __init__ ( self, parent, *args, **kw ):
        """ Creates a wx.Panel that correctly sets its background color to be
            the same as its parents.
        """
        from facets.extra.helper.debug import created_from; created_from( self )

        wx.Panel.__init__( self, parent, *args, **kw )

        wx.EVT_CHILD_FOCUS(      self, self.OnChildFocus )
        wx.EVT_ERASE_BACKGROUND( self, self.OnEraseBackground )
        wx.EVT_PAINT(            self, self.OnPaint )

        self.SetBackgroundColour( parent.GetBackgroundColour() )

        # Make sure that we have an associated GUI toolkit neutral adapter
        # defined so we don't have to check in the paint handler each time:
        toolkit().control_adapter_for( self )
Example #3
0
    def init ( self, parent ):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """
        self.adapter = toolkit().create_checkbox( parent )
        self.adapter.set_event_handler( checked = self.update_object )

        self.set_tooltip()
Example #4
0
    def dockable_get_control ( self, parent ):
        """ Gets a control that can be docked into a DockWindow.
        """
        print "The 'IDockable.dockable_get_control' method must be overridden"
        panel = toolkit().create_panel( parent )
        panel.background_color = 0xFF0000

        return panel()
Example #5
0
    def show ( self ):
        """ Shows the feature bar.
        """
        # Make sure all prerequisites are met:
        dock_control, parent = self.dock_control, self.parent
        if (dock_control is None) or (parent is None):
            return

        # Create the actual control (if needed):
        control = self.control
        if control is None:
            self.control = control = toolkit().create_frame( parent,
                                                             feature_bar_style )

            # Set up all of the event handlers:
            control.set_event_handler(
                paint      = self.paint,
                left_down  = self.left_down,
                left_up    = self.left_up,
                right_down = self.right_down,
                right_up   = self.right_up,
                motion     = self.mouse_move,
                enter      = self.mouse_enter
            )

            # Set up to handle drag and drop events:
            control.drop_target = self

        # Calculate the best size and position for the feature bar:
        size          = ( 32, 32 )
        width         = height = 0
        horizontal    = self.horizontal
        self.features = [ feature
            for feature in dock_control.active_features
            if feature.is_enabled() and (feature.bitmap is not None)
        ]
        for feature in self.features:
            bitmap = feature.bitmap
            dx, dy = control.bitmap_size( bitmap )
            if horizontal:
                width += (dx + 3)
                height = max( height, dy )
            else:
                width   = max( width, dx )
                height += (dy + 3)

        if width > 0:
            if horizontal:
                width  += 5
                height += 8
            else:
                width  += 8
                height += 5

        px, py          = parent.screen_position
        fx, fy          = dock_control.feature_popup_position
        control.bounds  = ( px + fx, py + fy, width, height )
        control.visible = True
Example #6
0
    def init ( self, parent ):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """
        label        = self.factory.label or self.item.get_label( self.ui )
        self.adapter = toolkit().create_button( parent,
                                                self.string_value( label ) )
        self.adapter.set_event_handler( clicked = self.update_object )
        self.sync_value( self.factory.label_value, 'label', 'from' )

        self.set_tooltip()
Example #7
0
    def _height_default(self):
        if self.volume is None:
            return 0

        image = self.volume.image_resource(self.image_name)
        if image is None:
            self.width = 0

            return 0

        self.width, height = toolkit().image_size(image.create_image())

        return height
Example #8
0
    def create_control ( self, parent ):
        """ Creates the underlying window used for the notebook.
        """
        # Create the correct type of window based on whether or not it should
        # be scrollable:
        root = parent
        if self.scrollable:
            root = toolkit().create_scrolled_panel( parent )

        self.control = control = toolkit().create_panel( root )
        control._image_slice   = getattr( parent, '_image_slice', None )
        self.layout            = VerticalNotebookLayout( notebook = self )

        # Set up the painting event handler:
        control.set_event_handler( paint = self._paint )

        if root is parent:
            return control

        root.content = control

        return root
Example #9
0
    def _get_screen_graphics ( self ):
        from facets.ui.toolkit import toolkit

        if self._screen_graphics is None:
            control = self.control
            pixmap  = QPixmap.grabWindow( control.winId() )
            self._sg_control = sg = toolkit().create_control( self )
            sg._pixmap = pixmap
            dx, dy     = self.size
            sg.bounds  = ( 0, 0, dx, dy )
            sg.set_event_handler( paint = self._screen_graphics_paint )
            painter = painter_for( pixmap )
            painter._control = sg.control
            self._screen_graphics = (
                QtGraphics( painter, bitmap = pixmap ), 0, 0
            )

        return self._screen_graphics
Example #10
0
    def wdump ( control, msg = '', root = True ):
        """ Dumps a GUI toolkit neutral control hierarchy to standard out.
        """
        from facets.ui.toolkit import toolkit

        control = toolkit().as_toolkit_adapter( control )
        if root:
            parent = control.parent
            while parent is not None:
                control = parent
                parent = control.parent

        if msg == '':
            msg = stack( 1 )[1][3]

        print '--- %s %s' % ( msg, '-' * (74 - len( msg )) )

        _wdump( control, 0, '' )
Example #11
0
    def edit_facets ( self, view       = None, parent  = None, kind = None,
                            context    = None, handler = None, id   = '',
                            scrollable = None, **args ):
        """ Edits the object's facets.
        """
        if context is None:
            context = self

        if handler is None:
            handler = self

        view = self.facet_view( view )

        from facets.ui.toolkit          import toolkit
        from facets.ui.view_application import view_application

        if toolkit().is_application_running():
            return view.ui( context, parent, kind, self.facet_view_elements(),
                            handler, id, scrollable, args )

        return view_application( context, view, kind, handler, id, scrollable,
                                 args )
Example #12
0
    def _fonts_matching ( self, match_value ):
        """ Returns a list of all font names whose fixed versus proportional
            type is the same as *match_value* (a boolean).
        """
        font_cache     = self.facet_db_get( 'font_db', {} )
        cache_modified = False
        matching_fonts = []
        font_fixed     = toolkit().font_fixed
        for font in self.fonts:
            is_fixed = font_cache.get( font, None )
            if is_fixed is None:
                font_cache[ font ] = is_fixed = font_fixed( font )
                cache_modified     = True

            if is_fixed == match_value:
                matching_fonts.append( font )

        if cache_modified:
            self.facet_db_set( 'font_db', font_cache )

        matching_fonts.sort()

        return matching_fonts
Example #13
0
def normalized_color ( color, has_alpha = False, as_int = True ):
    """ Returns the value of *color* as a normalized color tuple of the form:
        ( red, green, blue [, alpha] ), where reg, green, blue and alpha are
        integers in the range 0..255 if *as_int* is True and are floats in the
        range 0.0..1.0 otherwise. If *has_alpha* is True, the result will have
        four elements; otherwise it will have three.

        The *color* value can be:
        - a 'web' color string of the form: '#rgb' or '#rrggbb'.
        - an integer value of the form: 0xAARRGGBB.
        - a tuple or list of the form: ( hue, level, saturation [, alpha] )
          representing an HLS(A) encoded color, where hue is an integer value in
          the range 0..359, and level, saturation and alpa are float values in
          the range 0.0..1.0.
        - a tuple or list of the form: ( red, green, blue [, alpha] ), where
          red, green, blue and alpha can all be integer values in the range
          0..255, or float values in the range 0.0..1.0.
        - a GUI toolkit specific color object.

        Any input value not matching this description will cause a FacetError to
        be raised.
    """
    # Handle case of 'web' color of the form: '#rgb' or '#rrggbb':
    if isinstance( color, basestring ) and color.startswith( '#' ):
        code = color[1:]
        if len( code ) == 3:
            r, g, b = code
            code    = '%s%s%s%s%s%s' % ( r, r, g, g, b, b )

        if len( code ) == 6:
            try:
                color = int( code, 16 )
            except:
                pass

    # Initialize the component types (True = int, False = float):
    r = g = b = a = True

    if isinstance( color, IntegerTypes ):
        alpha = 255 - int( (color >> 24) & 0xFF )
        red   = int( (color >> 16) & 0xFF )
        green = int( (color >>  8) & 0xFF )
        blue  = int( color         & 0xFF )
    elif isinstance( color, SequenceTypes ) and (3 <= len( color ) <= 4):

        def color_component ( color, index, upper = 255 ):
            value = color[ index ] if index < len( color ) else 255
            if isinstance( value, IntegerTypes ):
                if 0 <= value <= upper:
                    return ( True, value )
            elif isinstance( value, float ) and (0.0 <= value <= 1.0):
                return ( False, value )

            raise FacetError

        a, alpha = color_component( color, 3 )
        if (isinstance( color[0], IntegerTypes ) and
            isinstance( color[1], float )        and
            isinstance( color[2], float )):
            # Handle an HLS(A) encoded tuple, which has the form:
            # ( int, float, float [, float ] ):
            from colorsys import hls_to_rgb

            r = g = b = False
            red, green, blue = hls_to_rgb(
                color_component( color, 0, 359 )[1] / 360.0,
                color_component( color, 1 )[1],
                color_component( color, 2 )[1]
            )
        else:
            r, red   = color_component( color, 0 )
            g, green = color_component( color, 1 )
            b, blue  = color_component( color, 2 )
    else:
        from facets.ui.toolkit import toolkit

        try:
            value = toolkit().from_toolkit_color( color )
            if len( value ) == 3:
                red, green, blue = value
                alpha            = 255
            else:
                red, green, blue, alpha = value
        except:
            raise FacetError

    if as_int:
        if not r: red   = int( 255.0 * red   )
        if not g: green = int( 255.0 * green )
        if not b: blue  = int( 255.0 * blue  )
        if not a: alpha = int( 255.0 * alpha )
    else:
        if r: red   /= 255.0
        if g: green /= 255.0
        if b: blue  /= 255.0
        if a: alpha /= 255.0

    return (( red, green, blue, alpha ) if has_alpha else ( red, green, blue ))
Example #14
0
    def _fonts_default ( self ):
        names = toolkit().font_names()
        names.sort()

        return names
Example #15
0
 def _layout_set ( self, layout ):
     """ Handles the 'layout' facet being changed by linking the
         underlying toolkit specific control and layout objects together.
     """
     self.control.layout = toolkit().layout_adapter_for( layout )