def _font_modified ( self, facet, new ):
     """ Handles one of the presentation fonts being changed.
     """
     theme     = facet[:-4] + 'theme'
     new_theme = Theme()
     new_theme.copy_facets( getattr( self, theme ) )
     new_theme.content_font = new
     setattr( self, theme, new_theme )
Beispiel #2
0
    def _paint ( self, event ):
        """ Paint the background using the associated ImageSlice object.
        """
        factory  = self.factory
        control  = self.adapter
        g        = control.graphics.graphics_buffer()
        wdx, wdy = control.client_size

        # Draw the range labels at the ends (if requested):
        tx  = factory.label_width
        tdx = wdx - (2 * tx)
        if tx > 0:
            global label_theme

            if label_theme is None:
                label_theme = Theme( '@xform:bg?l5', content = ( 3, 0 ) )

            label_theme.fill( g, 0, 0, tx, wdy )
            label_theme.fill( g, wdx - tx, 0, tx, wdy )
            label_theme.draw_text(
                g, self.string_value( self.low ), CENTER, 0, 0, tx, wdy
            )
            label_theme.draw_text(
                g, self.string_value( self.high ), CENTER, wdx - tx, 0, tx, wdy
            )

        # Draw the slider track:
        self.track_theme.fill( g, tx, 0, tdx, wdy )

        # Calculate the sizes of the slider tip:
        self._tsz = tsz = max( self._tsz, self._tip_size( g ) )

        # Calculate the available slider range (the slider tip is not
        # included):
        self._adx = adx = tdx - tsz - 1

        # Calculate the coordinate of the right side of the slider range:
        self._rx = rx = int( ((self.value - self.low) * float( adx )) /
                             (self.high - self.low) ) + 1

        # Draw the slider:
        self.middle_theme.fill( g, tx + 1, 0, rx - 1, wdy )
        self.right_theme.fill( g, tx + rx, 0, tsz, wdy )

        # Draw the current text value (if requested):
        if factory.show_value != 'None':
            g.font = control.font
            if factory.show_value == 'Tip':
                self._text_color( g, factory.tip_style )
                self.right_theme.draw_text(
                    g, self.value_text.text, CENTER, tx + rx - 1, 1, tsz, wdy
                )
            else:
                self._text_color( g, factory.body_style or factory.tip_style )
                self.middle_theme.draw_text(
                    g, self.value_text.text, CENTER, tx + 1, 1, rx, wdy
                )

        # Copy the buffer to the display:
        g.copy()
 def init ( self ):
     """ Initialize the control.
     """
     hue      = min( int( round( (self.factory.hue % 360) / 3.6 ) ), 99 )
     self.bar = Theme( '@xform:pb?H%dl4S41|l66' % hue )
class _ProgressBarEditor ( ControlEditor ):
    """ Defines the _ProgressBarEditor for tracking the progress of long-running
        processes.
    """

    #-- Facet Definitions ------------------------------------------------------

    # The current width of the progress bar (in pixels):
    width = Int( -1 )

    # The current percentage complete value:
    percent = Str

    # The fixed size of the control:
    fixed_size = ( -1, 23 )

    # The theme to use for the progress bar:
    bar = ATheme

    #-- Public Methods ---------------------------------------------------------

    def init ( self ):
        """ Initialize the control.
        """
        hue      = min( int( round( (self.factory.hue % 360) / 3.6 ) ), 99 )
        self.bar = Theme( '@xform:pb?H%dl4S41|l66' % hue )


    def paint ( self, g ):
        """ Paints the contents of the editor control.
        """
        dx, dy = self.control.size
        track.fill( g, 0, 0, dx, dy )
        self.bar.fill(   g, 0, 0, self.width, dy )
        track.draw_text( g, self.percent, 'right', 0, 0, dx - 3, dy )


    def resize ( self, event ):
        """ Handles the editor control being resized.
        """
        self._value_set()

        super( _ProgressBarEditor, self ).resize( event )

    #-- Facet Event Handlers ---------------------------------------------------

    def _value_set ( self ):
        """ Handles the 'value' facet being changed.
        """
        low, high    = self.factory.low, self.factory.high
        value        = min( max( self.value, low ), high )
        fraction     = ((value - low) / (high - low))
        self.percent = '%.0f%%' % (100.0 * fraction)
        self.width   = int( round( self.control.size[0] * fraction ) )


    @on_facet_set( 'width, percent' )
    def _update_display ( self ):
        """ Handles any value affecting the contents of the editor control being
            changed.
        """
        self.refresh()