Exemplo n.º 1
0
    def __init__(self, message, button_callback):
        Gtk.EventBox.__init__(self)

        self.modify_bg(Gtk.StateType.NORMAL,
                       style.COLOR_WHITE.get_gdk_color())

        alignment = Gtk.Alignment.new(0.5, 0.5, 0.1, 0.1)
        self.add(alignment)
        alignment.show()

        box = Gtk.VBox()
        alignment.add(box)
        box.show()

        icon = ProgressIcon(icon_name='book',
                            pixel_size=style.LARGE_ICON_SIZE,
                            stroke_color=style.COLOR_BUTTON_GREY.get_svg(),
                            fill_color=style.COLOR_SELECTION_GREY.get_svg())
        self.progress_icon = icon

        box.pack_start(icon, expand=True, fill=False, padding=0)
        icon.show()

        label = Gtk.Label()
        color = style.COLOR_BUTTON_GREY.get_html()
        label.set_markup('<span weight="bold" color="%s">%s</span>' % (
            color, GLib.markup_escape_text(message)))
        box.pack_start(label, expand=True, fill=False, padding=0)
        label.show()

        button_box = Gtk.HButtonBox()
        button_box.set_layout(Gtk.ButtonBoxStyle.CENTER)
        box.pack_start(button_box, False, True, 0)
        button_box.show()

        button = Gtk.Button(label=_('Cancel'))
        button.connect('clicked', button_callback)
        button.props.image = Icon(icon_name='dialog-cancel',
                                  pixel_size=style.SMALL_ICON_SIZE)
        button_box.pack_start(button, expand=True, fill=False, padding=0)
        button.show()
class ProgressToolButton(ToolButton):
    '''
    This button is just like a normal tool button, except that the
    icon can dynamically fill based on a progress number.
    '''

    __gtype_name__ = 'SugarProgressToolButton'

    def __init__(self, **kwargs):
        self._xo_color = XoColor('insensitive')
        self._icon_name = None
        self._direction = 'vertical'
        self._progress = 0.0

        ToolButton.__init__(self, **kwargs)
        # GObject should do this, but something down the ToolButton chain of
        # parents is not passing the kwargs to GObject
        if 'xo_color' in kwargs:
            self.props.xo_color = kwargs['xo_color']
        if 'icon_name' in kwargs:
            self.props.icon_name = kwargs['icon_name']
        if 'direction' in kwargs:
            self.props.direction = kwargs['direction']
        self._updated()

    @GObject.property
    def xo_color(self):
        '''
        This property defines the stroke and fill of the icon, and is
        the type :class:`sugar3.graphics.xocolor.XoColor`
        '''
        return self._xo_color

    @xo_color.setter
    def xo_color(self, new):
        self._xo_color = new
        self._updated()

    @GObject.property
    def icon_name(self):
        '''
        Icon name (same as with a :class:`sugar3.graphics.icon.Icon`), as the
        type :class:`str`
        '''
        return self._icon_name

    @icon_name.setter
    def icon_name(self, new):
        self._icon_name = new
        self._updated()

    @GObject.property
    def direction(self):
        '''
        Direction for the icon to fill as it progresses, filling either,
        * :class:`Gtk.Orientation.VERTICAL` - bottom to top
        * :class:`Gtk.Orientation.HORIZONTAL` - user's text direction
        '''
        if self._direction == 'vertical':
            return Gtk.Orientation.VERTICAL
        else:
            return Gtk.Orientation.HORIZONTAL

    @direction.setter
    def direction(self, new):
        if new == Gtk.Orientation.VERTICAL:
            self._direction = 'vertical'
        else:
            self._direction = 'horizontal'
        self._updated()

    def _updated(self):
        self._icon = ProgressIcon(
            self._icon_name,
            style.STANDARD_ICON_SIZE,
            self._xo_color.get_stroke_color(),
            self._xo_color.get_fill_color(),
            self._direction)
        self._icon.update(self._progress)
        self.set_icon_widget(self._icon)
        self._icon.show()

    def update(self, progress):
        '''
        Redraw the icon with a different percentage filled in

        Args:
            progress (float): a value from 0.0 to 1.0, where 1.0 fully
                fills the icon and 0.0 results in only the stroke being
                visible
        '''
        self._progress = progress
        self._icon.update(progress)
        self.queue_draw()
Exemplo n.º 3
0
from sugar3.graphics.progressicon import ProgressIcon
from sugar3.graphics import style

import common

test = common.Test()
test.show()

icon = ProgressIcon(
    pixel_size=style.LARGE_ICON_SIZE,
    icon_name='computer-xo',
    stroke_color=style.COLOR_BUTTON_GREY.get_svg(),
    fill_color=style.COLOR_WHITE.get_svg())
test.pack_start(icon, True, True, 0)
icon.show()

icon2 = ProgressIcon(
    pixel_size=style.LARGE_ICON_SIZE,
    icon_name='computer-xo',
    stroke_color=style.COLOR_BUTTON_GREY.get_svg(),
    fill_color=style.COLOR_WHITE.get_svg(),
    direction='horizontal')
test.pack_start(icon2, True, True, 0)
icon2.show()

progress = 0


def timeout_cb():
    global progress
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
test.pack_start(box, True, True, 0)

toolbar_box = ToolbarBox()
box.pack_start(toolbar_box, False, False, 0)

separator = Gtk.SeparatorToolItem()
toolbar_box.toolbar.insert(separator, -1)

icon = ProgressIcon(pixel_size=style.LARGE_ICON_SIZE,
                    icon_name='computer-xo',
                    stroke_color=style.COLOR_BUTTON_GREY.get_svg(),
                    fill_color=style.COLOR_WHITE.get_svg())
test.pack_start(icon, True, True, 0)
icon.show()

icon2 = ProgressIcon(pixel_size=style.LARGE_ICON_SIZE,
                     icon_name='computer-xo',
                     stroke_color=style.COLOR_BUTTON_GREY.get_svg(),
                     fill_color=style.COLOR_WHITE.get_svg(),
                     direction='horizontal')
test.pack_start(icon2, True, True, 0)
icon2.show()

test.show_all()

progress = 0


def timeout_cb():
class ProgressToolButton(ToolButton):

    '''
    This button is just like a normal tool button, except that the
    icon can dynamically fill based on a progress number.
    '''

    __gtype_name__ = 'SugarProgressToolButton'

    def __init__(self, **kwargs):
        self._xo_color = XoColor('insensitive')
        self._icon_name = None
        self._direction = 'vertical'
        self._progress = 0.0

        ToolButton.__init__(self, **kwargs)
        # GObject should do this, but something down the ToolButton chain of
        # parents is not passing the kwargs to GObject
        if 'xo_color' in kwargs:
            self.props.xo_color = kwargs['xo_color']
        if 'icon_name' in kwargs:
            self.props.icon_name = kwargs['icon_name']
        if 'direction' in kwargs:
            self.props.direction = kwargs['direction']
        self._updated()

    @GObject.property
    def xo_color(self):
        '''
        This property defines the stroke and fill of the icon, and is
        the type :class:`sugar3.graphics.xocolor.XoColor`
        '''
        return self._xo_color

    @xo_color.setter
    def xo_color(self, new):
        self._xo_color = new
        self._updated()

    @GObject.property
    def icon_name(self):
        '''
        Icon name (same as with a :class:`sugar3.graphics.icon.Icon`), as the
        type :class:`str`
        '''
        return self._icon_name

    @icon_name.setter
    def icon_name(self, new):
        self._icon_name = new
        self._updated()

    @GObject.property
    def direction(self):
        '''
        Direction for the icon to fill as it progresses, filling either,
        * :class:`Gtk.Orientation.VERTICAL` - bottom to top
        * :class:`Gtk.Orientation.HORIZONTAL` - user's text direction
        '''
        if self._direction == 'vertical':
            return Gtk.Orientation.VERTICAL
        else:
            return Gtk.Orientation.HORIZONTAL

    @direction.setter
    def direction(self, new):
        if new == Gtk.Orientation.VERTICAL:
            self._direction = 'vertical'
        else:
            self._direction = 'horizontal'
        self._updated()

    def _updated(self):
        self._icon = ProgressIcon(
            self._icon_name,
            style.STANDARD_ICON_SIZE,
            self._xo_color.get_stroke_color(),
            self._xo_color.get_fill_color(),
            self._direction)
        self._icon.update(self._progress)
        self.set_icon_widget(self._icon)
        self._icon.show()

    def update(self, progress):
        '''
        Redraw the icon with a different percentage filled in

        Args:
            progress (float): a value from 0.0 to 1.0, where 1.0 fully
                fills the icon and 0.0 results in only the stroke being
                visible
        '''
        self._progress = progress
        self._icon.update(progress)
        self.queue_draw()