Ejemplo n.º 1
0
class Image(hippo.CanvasWidget):
    def __init__(self, palette=None, tooltip=None, pixbuf=None, **kwargs):
        self.image = gtk.Image()
        self._invoker = CanvasInvoker()

        hippo.CanvasBox.__init__(self, widget=self.image, **kwargs)

        self._invoker._position_hint = self._invoker.AT_CURSOR
        self._invoker.attach(self)

        self.connect('destroy', self._destroy_cb)

        if palette:
            self.palette = palette
        if tooltip:
            self.tooltip = tooltip
        if pixbuf:
            self.pixbuf = pixbuf

    def _destroy_cb(self, widget):
        if self._invoker is not None:
            self._invoker.detach()

    def create_palette(self):
        return None

    def get_palette(self):
        return self._invoker.palette

    def set_palette(self, palette):
        self._invoker.palette = palette

    palette = gobject.property(type=object,
                               setter=set_palette,
                               getter=get_palette)
    palette = property(get_palette, set_palette)

    def get_tooltip(self):
        return self._invoker.palette and self._invoker.palette.primary_text

    def set_tooltip(self, text):
        self.set_palette(Palette(text))

    tooltip = gobject.property(type=str,
                               setter=set_tooltip,
                               getter=get_tooltip)
    tooltip = property(get_tooltip, set_tooltip)

    def set_pixbuf(self, value):
        self.image.set_from_pixbuf(value)
        self.props.box_width = value.get_width()
        self.props.box_height = value.get_height()

    pixbuf = gobject.property(type=object, setter=set_pixbuf, getter=None)
    pixbuf = property(None, set_pixbuf)
Ejemplo n.º 2
0
class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):

    __gtype_name__ = 'CanvasIcon'

    def __init__(self, **kwargs):
        from sugar.graphics.palette import CanvasInvoker

        self._buffer = _IconBuffer()
        self._palette_invoker = CanvasInvoker()

        hippo.CanvasBox.__init__(self, **kwargs)

        self._palette_invoker.attach(self)

        self.connect('destroy', self.__destroy_cb)

    def _emit_paint_needed_icon_area(self):
        surface = self._buffer.get_surface()
        if surface:
            width, height = self.get_allocation()
            s_width = surface.get_width()
            s_height = surface.get_height()

            x = (width - s_width) / 2
            y = (height - s_height) / 2

            self.emit_paint_needed(x, y, s_width, s_height)

    def __destroy_cb(self, icon):
        if self._palette_invoker is not None:
            self._palette_invoker.detach()

    def set_file_name(self, value):
        """
        Parameters
        ----------
        value:

        Returns
        -------
        None

        \"\"\"

        """
        if self._buffer.file_name != value:
            self._buffer.file_name = value
            self.emit_paint_needed(0, 0, -1, -1)

    def get_file_name(self):
        """
        Parameters
        ----------
        None

        Returns
        -------
        file name :

        """
        return self._buffer.file_name

    file_name = gobject.property(
        type=object, getter=get_file_name, setter=set_file_name)

    def set_icon_name(self, value):
        """
        Parameters
        ----------
        value:

        Returns
        -------
        None

        """
        if self._buffer.icon_name != value:
            self._buffer.icon_name = value
            self.emit_paint_needed(0, 0, -1, -1)

    def get_icon_name(self):
        """
        Parameters
        ----------
        None

        Returns
        -------
        icon name :

        """
        return self._buffer.icon_name

    icon_name = gobject.property(
        type=object, getter=get_icon_name, setter=set_icon_name)

    def set_xo_color(self, value):
        """
        Parameters
        ----------
        value:

        Returns
        -------
        None

        """
        if self._buffer.xo_color != value:
            self._buffer.xo_color = value
            self._emit_paint_needed_icon_area()

    xo_color = gobject.property(
        type=object, getter=None, setter=set_xo_color)

    def set_fill_color(self, value):
        """
        Parameters
        ----------
        value:

        Returns
        -------
        None

        """
        if self._buffer.fill_color != value:
            self._buffer.fill_color = value
            self._emit_paint_needed_icon_area()

    def get_fill_color(self):
        """
        Parameters
        ----------
        None

        Returns
        -------
        fill color :

        """
        return self._buffer.fill_color

    fill_color = gobject.property(
        type=object, getter=get_fill_color, setter=set_fill_color)

    def set_stroke_color(self, value):
        """
        Parameters
        ----------
        value:

        Returns
        -------
        None

        """
        if self._buffer.stroke_color != value:
            self._buffer.stroke_color = value
            self._emit_paint_needed_icon_area()

    def get_stroke_color(self):
        """
        Parameters
        ----------
        None

        Returns
        -------
        stroke color :

        """
        return self._buffer.stroke_color

    stroke_color = gobject.property(
        type=object, getter=get_stroke_color, setter=set_stroke_color)

    def set_background_color(self, value):
        """
        Parameters
        ----------
        value:

        Returns
        -------
        None

        """
        if self._buffer.background_color != value:
            self._buffer.background_color = value
            self.emit_paint_needed(0, 0, -1, -1)

    def get_background_color(self):
        """
        Parameters
        ----------
        None

        Returns
        -------
        fill color :

        """
        return self._buffer.background_color

    background_color = gobject.property(
        type=object, getter=get_background_color, setter=set_background_color)

    def set_size(self, value):
        """
        Parameters
        ----------
        value:

        Returns
        -------
        None

        """
        if self._buffer.width != value:
            self._buffer.width = value
            self._buffer.height = value
            self.emit_request_changed()

    def get_size(self):
        """
        Parameters
        ----------
        None

        Returns
        -------
        size :

        """
        return self._buffer.width

    size = gobject.property(
        type=object, getter=get_size, setter=set_size)

    def set_scale(self, value):
        """
        Parameters
        ----------
        value:

        Returns
        -------
        None

        """
        logging.warning(
            'CanvasIcon: the scale parameter is currently unsupported')
        if self._buffer.scale != value:
            self._buffer.scale = value
            self.emit_request_changed()

    def get_scale(self):
        """
        Parameters
        ----------
        None

        Returns
        -------
        scale :

        """
        return self._buffer.scale

    scale = gobject.property(
        type=float, getter=get_scale, setter=set_scale)

    def set_cache(self, value):
        """
        Parameters
        ----------
        cache

        Returns
        -------
        None

        """
        self._buffer.cache = value

    def get_cache(self):
        """
        Parameters
        ----------
        None

        Returns
        -------
        cache :

        """
        return self._buffer.cache

    cache = gobject.property(
        type=bool, default=False, getter=get_cache, setter=set_cache)

    def set_badge_name(self, value):
        """
        Parameters
        ----------
        value :

        Returns
        -------
        None

        """
        if self._buffer.badge_name != value:
            self._buffer.badge_name = value
            self.emit_paint_needed(0, 0, -1, -1)

    def get_badge_name(self):
        """
        Parameters
        ----------
        None

        Returns
        -------
        badge name :

        """
        return self._buffer.badge_name

    badge_name = gobject.property(
        type=object, getter=get_badge_name, setter=set_badge_name)

    def do_paint_below_children(self, cr, damaged_box):
        """
        Parameters
        ----------
        cr :

        damaged_box :

        Returns
        -------
        None

        """
        surface = self._buffer.get_surface()
        if surface:
            width, height = self.get_allocation()

            x = (width - surface.get_width()) / 2
            y = (height - surface.get_height()) / 2

            cr.set_source_surface(surface, x, y)
            cr.paint()

    def do_get_content_width_request(self):
        """
        Parameters
        ----------
        None

        Returns
        -------
        width :

        """
        surface = self._buffer.get_surface()
        if surface:
            size = surface.get_width()
        elif self._buffer.width:
            size = self._buffer.width
        else:
            size = 0

        return size, size

    def do_get_content_height_request(self, for_width):
        surface = self._buffer.get_surface()
        if surface:
            size = surface.get_height()
        elif self._buffer.height:
            size = self._buffer.height
        else:
            size = 0

        return size, size

    def do_button_press_event(self, event):
        if event.button == 1:
            self.emit_activated()
            return True
        else:
            return False

    def create_palette(self):
        return None

    def get_palette(self):
        return self._palette_invoker.palette

    def set_palette(self, palette):
        self._palette_invoker.palette = palette

    palette = gobject.property(
        type=object, setter=set_palette, getter=get_palette)

    def get_palette_invoker(self):
        return self._palette_invoker

    def set_palette_invoker(self, palette_invoker):
        self._palette_invoker.detach()
        self._palette_invoker = palette_invoker

    palette_invoker = gobject.property(
        type=object, setter=set_palette_invoker, getter=get_palette_invoker)

    def set_tooltip(self, text):
        from sugar.graphics.palette import Palette

        self.set_palette(Palette(text))
Ejemplo n.º 3
0
class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):

    __gtype_name__ = 'CanvasIcon'

    def __init__(self, **kwargs):
        from sugar.graphics.palette import CanvasInvoker

        self._buffer = _IconBuffer()
        self._palette_invoker = CanvasInvoker()
        self._alpha = 1.0

        hippo.CanvasBox.__init__(self, **kwargs)

        self._palette_invoker.attach(self)

        self.connect('destroy', self.__destroy_cb)

    def _emit_paint_needed_icon_area(self):
        surface = self._buffer.get_surface()
        if surface:
            width, height = self.get_allocation()
            s_width = surface.get_width()
            s_height = surface.get_height()

            x = (width - s_width) / 2
            y = (height - s_height) / 2

            self.emit_paint_needed(x, y, s_width, s_height)

    def __destroy_cb(self, icon):
        if self._palette_invoker is not None:
            self._palette_invoker.detach()

    def set_file_name(self, value):
        """
        Parameters
        ----------
        value:

        Returns
        -------
        None

        \"\"\"

        """
        if self._buffer.file_name != value:
            self._buffer.file_name = value
            self.emit_paint_needed(0, 0, -1, -1)

    def get_file_name(self):
        """
        Parameters
        ----------
        None

        Returns
        -------
        file name :

        """
        return self._buffer.file_name

    file_name = gobject.property(
        type=object, getter=get_file_name, setter=set_file_name)

    def set_icon_name(self, value):
        """
        Parameters
        ----------
        value:

        Returns
        -------
        None

        """
        if self._buffer.icon_name != value:
            self._buffer.icon_name = value
            self.emit_paint_needed(0, 0, -1, -1)

    def get_icon_name(self):
        """
        Parameters
        ----------
        None

        Returns
        -------
        icon name :

        """
        return self._buffer.icon_name

    icon_name = gobject.property(
        type=object, getter=get_icon_name, setter=set_icon_name)

    def set_xo_color(self, value):
        """
        Parameters
        ----------
        value:

        Returns
        -------
        None

        """
        if self._buffer.xo_color != value:
            self._buffer.xo_color = value
            self._emit_paint_needed_icon_area()

    xo_color = gobject.property(
        type=object, getter=None, setter=set_xo_color)

    def set_fill_color(self, value):
        """
        Parameters
        ----------
        value:

        Returns
        -------
        None

        """
        if self._buffer.fill_color != value:
            self._buffer.fill_color = value
            self._emit_paint_needed_icon_area()

    def get_fill_color(self):
        """
        Parameters
        ----------
        None

        Returns
        -------
        fill color :

        """
        return self._buffer.fill_color

    fill_color = gobject.property(
        type=object, getter=get_fill_color, setter=set_fill_color)

    def set_stroke_color(self, value):
        """
        Parameters
        ----------
        value:

        Returns
        -------
        None

        """
        if self._buffer.stroke_color != value:
            self._buffer.stroke_color = value
            self._emit_paint_needed_icon_area()

    def get_stroke_color(self):
        """
        Parameters
        ----------
        None

        Returns
        -------
        stroke color :

        """
        return self._buffer.stroke_color

    stroke_color = gobject.property(
        type=object, getter=get_stroke_color, setter=set_stroke_color)

    def set_background_color(self, value):
        """
        Parameters
        ----------
        value:

        Returns
        -------
        None

        """
        if self._buffer.background_color != value:
            self._buffer.background_color = value
            self.emit_paint_needed(0, 0, -1, -1)

    def get_background_color(self):
        """
        Parameters
        ----------
        None

        Returns
        -------
        fill color :

        """
        return self._buffer.background_color

    background_color = gobject.property(
        type=object, getter=get_background_color, setter=set_background_color)

    def set_size(self, value):
        """
        Parameters
        ----------
        value:

        Returns
        -------
        None

        """
        if self._buffer.width != value:
            self._buffer.width = value
            self._buffer.height = value
            self.emit_request_changed()

    def get_size(self):
        """
        Parameters
        ----------
        None

        Returns
        -------
        size :

        """
        return self._buffer.width

    size = gobject.property(
        type=object, getter=get_size, setter=set_size)

    def set_scale(self, value):
        """
        Parameters
        ----------
        value:

        Returns
        -------
        None

        """
        if self._buffer.scale != value:
            self._buffer.scale = value
            self.emit_request_changed()

    def get_scale(self):
        """
        Parameters
        ----------
        None

        Returns
        -------
        scale :

        """
        return self._buffer.scale

    scale = gobject.property(
        type=float, getter=get_scale, setter=set_scale)

    def set_alpha(self, alpha):
        if self._alpha != alpha:
            self._alpha = alpha
            self.emit_paint_needed(0, 0, -1, -1)

    alpha = gobject.property(
        type=float, setter=set_alpha)

    def set_cache(self, value):
        """
        Parameters
        ----------
        cache

        Returns
        -------
        None

        """
        self._buffer.cache = value

    def get_cache(self):
        """
        Parameters
        ----------
        None

        Returns
        -------
        cache :

        """
        return self._buffer.cache

    cache = gobject.property(
        type=bool, default=False, getter=get_cache, setter=set_cache)

    def set_badge_name(self, value):
        """
        Parameters
        ----------
        value :

        Returns
        -------
        None

        """
        if self._buffer.badge_name != value:
            self._buffer.badge_name = value
            self.emit_paint_needed(0, 0, -1, -1)

    def get_badge_name(self):
        """
        Parameters
        ----------
        None

        Returns
        -------
        badge name :

        """
        return self._buffer.badge_name

    badge_name = gobject.property(
        type=object, getter=get_badge_name, setter=set_badge_name)

    def do_paint_below_children(self, cr, damaged_box):
        """
        Parameters
        ----------
        cr :

        damaged_box :

        Returns
        -------
        None

        """
        surface = self._buffer.get_surface()
        if surface:
            width, height = self.get_allocation()

            x = (width - surface.get_width()) / 2
            y = (height - surface.get_height()) / 2

            cr.set_source_surface(surface, x, y)
            if self._alpha == 1.0:
                cr.paint()
            else:
                cr.paint_with_alpha(self._alpha)

    def do_get_content_width_request(self):
        """
        Parameters
        ----------
        None

        Returns
        -------
        width :

        """
        surface = self._buffer.get_surface()
        if surface:
            size = surface.get_width()
        elif self._buffer.width:
            size = self._buffer.width
        else:
            size = 0

        return size, size

    def do_get_content_height_request(self, for_width):
        surface = self._buffer.get_surface()
        if surface:
            size = surface.get_height()
        elif self._buffer.height:
            size = self._buffer.height
        else:
            size = 0

        return size, size

    def do_button_press_event(self, event):
        if event.button == 1:
            self.emit_activated()
            return True
        else:
            return False

    def create_palette(self):
        return None

    def get_palette(self):
        return self._palette_invoker.palette

    def set_palette(self, palette):
        self._palette_invoker.palette = palette

    palette = gobject.property(
        type=object, setter=set_palette, getter=get_palette)

    def get_palette_invoker(self):
        return self._palette_invoker

    def set_palette_invoker(self, palette_invoker):
        self._palette_invoker.detach()
        self._palette_invoker = palette_invoker

    palette_invoker = gobject.property(
        type=object, setter=set_palette_invoker, getter=get_palette_invoker)

    def set_tooltip(self, text):
        from sugar.graphics.palette import Palette

        self.set_palette(Palette(text))