diff options
author | Santiago Collazo <scollazo@activitycentral.com> | 2013-01-23 12:11:41 (GMT) |
---|---|---|
committer | Santiago Collazo <scollazo@activitycentral.com> | 2013-01-23 12:11:41 (GMT) |
commit | 7dab98681faf7fc60e72b306dfb4d0face4a454b (patch) | |
tree | f8497858cad4442225e1666dc9f346e0f0fcd262 | |
parent | bef4413649a096a4ed9b9116819d51a34104c8d6 (diff) | |
parent | c3396e0396878ec9fa8da69a20a5948f4713ac8b (diff) |
Merge remote-tracking branch 'ajay/0.97.7-as-base' into devel
-rw-r--r-- | src/sugar3/graphics/Makefile.am | 1 | ||||
-rw-r--r-- | src/sugar3/graphics/progressicon.py | 99 | ||||
-rw-r--r-- | tests/graphics/common.py | 3 | ||||
-rw-r--r-- | tests/graphics/progressicon.py | 66 |
4 files changed, 2 insertions, 167 deletions
diff --git a/src/sugar3/graphics/Makefile.am b/src/sugar3/graphics/Makefile.am index 344cc82..a4f9629 100644 --- a/src/sugar3/graphics/Makefile.am +++ b/src/sugar3/graphics/Makefile.am @@ -6,7 +6,6 @@ sugar_PYTHON = \ combobox.py \ iconentry.py \ icon.py \ - progressicon.py \ __init__.py \ menuitem.py \ notebook.py \ diff --git a/src/sugar3/graphics/progressicon.py b/src/sugar3/graphics/progressicon.py deleted file mode 100644 index 0153ae2..0000000 --- a/src/sugar3/graphics/progressicon.py +++ /dev/null @@ -1,99 +0,0 @@ -# Copyright (C) 2013, One Laptop Per Child -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the -# Free Software Foundation, Inc., 59 Temple Place - Suite 330, -# Boston, MA 02111-1307, USA. - -from gi.repository import Gtk -from sugar3.graphics.icon import get_surface -from sugar3.graphics import style - - -class ProgressIcon(Gtk.DrawingArea): - """Display the progress filling the icon. - - This class is compatible with the sugar3.graphics.icon.Icon class. - - Call update(progress) with the new progress to update the icon. - - The direction defaults to 'vertical', in which case the icon is - filled from bottom to top. If direction is set to 'horizontal', - it will be filled from right to left or from left to right, - depending on the system's language RTL setting. - - """ - def __init__(self, icon_name, pixel_size, stroke_color, fill_color, - direction='vertical'): - Gtk.DrawingArea.__init__(self) - - self._icon_name = icon_name - self._direction = direction - self._progress = 0 - - self._stroke = get_surface( - icon_name=icon_name, width=pixel_size, height=pixel_size, - stroke_color=stroke_color, - fill_color=style.COLOR_TRANSPARENT.get_svg()) - - self._fill = get_surface( - icon_name=icon_name, width=pixel_size, height=pixel_size, - stroke_color=style.COLOR_TRANSPARENT.get_svg(), - fill_color=fill_color) - - self.connect("draw", self.__draw_cb) - - def __draw_cb(self, widget, cr): - allocation = widget.get_allocation() - - # Center the graphic in the allocated space. - margin_x = (allocation.width - self._stroke.get_width()) / 2 - margin_y = (allocation.height - self._stroke.get_height()) / 2 - cr.translate(margin_x, margin_y) - - # Paint the fill, clipping it by the progress. - x_, y_ = 0, 0 - width, height = self._stroke.get_width(), self._stroke.get_height() - if self._direction == 'vertical': # vertical direction, bottom to top - y_ = self._stroke.get_height() - height *= self._progress * -1 - else: - rtl_direction = \ - Gtk.Widget.get_default_direction() == Gtk.TextDirection.RTL - if rtl_direction: # horizontal direction, right to left - x_ = self._stroke.get_width() - width *= self._progress * -1 - else: # horizontal direction, left to right - width *= self._progress - - cr.rectangle(x_, y_, width, height) - cr.clip() - cr.set_source_surface(self._fill, 0, 0) - cr.paint() - - # Paint the stroke over the fill. - cr.reset_clip() - cr.set_source_surface(self._stroke, 0, 0) - cr.paint() - - def do_get_preferred_width(self): - width = self._stroke.get_width() - return (width, width) - - def do_get_preferred_height(self): - height = self._stroke.get_height() - return (height, height) - - def update(self, progress): - self._progress = progress - self.queue_draw() diff --git a/tests/graphics/common.py b/tests/graphics/common.py index 8d516ad..02c3e19 100644 --- a/tests/graphics/common.py +++ b/tests/graphics/common.py @@ -31,7 +31,7 @@ def set_theme(): sugar_theme = 'sugar-100' settings.set_property('gtk-theme-name', sugar_theme) settings.set_property('gtk-icon-theme-name', 'sugar') -set_theme() + class Test(Gtk.VBox): def __init__(self): @@ -57,6 +57,7 @@ class TestPalette(Test): class TestRunner(object): def run(self, test): + set_theme() window = Gtk.Window() window.connect('destroy', lambda w: Gtk.main_quit()) window.add(test) diff --git a/tests/graphics/progressicon.py b/tests/graphics/progressicon.py deleted file mode 100644 index 3dbd4b1..0000000 --- a/tests/graphics/progressicon.py +++ /dev/null @@ -1,66 +0,0 @@ -# Copyright (C) 2013, One Laptop Per Child -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the -# Free Software Foundation, Inc., 59 Temple Place - Suite 330, -# Boston, MA 02111-1307, USA. - -""" -Test the sugar3.graphics.progressicon.ProgressIcon widget. -""" - - -from gi.repository import GObject - -from sugar3.graphics.progressicon import ProgressIcon -from sugar3.graphics.icon import Icon, get_surface -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 - progress += 0.05 - icon.update(progress) - icon2.update(progress) - if progress >= 1: - return False - return True - -GObject.timeout_add(50, timeout_cb) - -if __name__ == '__main__': - common.main(test) |