From de6369d242140055b9ff3f907dc29b3717fdde83 Mon Sep 17 00:00:00 2001
From: Walter Bender <walter@walter-laptop.(none)>
Date: Mon, 30 Nov 2009 09:28:21 -0500
Subject: [PATCH] color selector feature changes

---
 extensions/cpsection/aboutme/view.py |  209 ++++++++++++++++++++++++++++++++--
 src/jarabe/intro/colorpicker.py      |   72 ++++++++++++-
 src/jarabe/intro/window.py           |   81 ++++++++++++-
 3 files changed, 346 insertions(+), 16 deletions(-)

diff --git a/extensions/cpsection/aboutme/view.py b/extensions/cpsection/aboutme/view.py
index cabd66a..d92de87 100644
--- a/extensions/cpsection/aboutme/view.py
+++ b/extensions/cpsection/aboutme/view.py
@@ -20,11 +20,13 @@ from gettext import gettext as _
 
 from sugar.graphics.icon import Icon
 from sugar.graphics import style
+from sugar.graphics.toolbutton import ToolButton
 from sugar.graphics.xocolor import XoColor
 
 from jarabe.controlpanel.sectionview import SectionView
 from jarabe.controlpanel.inlinealert import InlineAlert
 
+
 class EventIcon(gtk.EventBox):
     __gtype_name__ = "SugarEventIcon"    
     def __init__(self, **kwargs):         
@@ -38,33 +40,131 @@ class EventIcon(gtk.EventBox):
 
         self.add(self.icon)
         self.icon.show()
+"""
+class StopButton(ToolButton):
+
+    def __init__(self, **kwargs):
+        ToolButton.__init__(self, 'activity-stop', **kwargs)
+        self.props.tooltip = _('Stop')
+        self.props.accelerator = '<Ctrl>Q'
+        self.connect('clicked', self.__stop_button_clicked_cb)
 
+    def __stop_button_clicked_cb(self, button):
+        print "out damn spot"
+"""
 class ColorPicker(EventIcon):
     __gsignals__ = {
         'color-changed': (gobject.SIGNAL_RUN_FIRST,
                           gobject.TYPE_NONE,
                           ([str]))
     }
-    def __init__(self, xocolor=None):
+    def __init__(self, me, xo_color=None):
         EventIcon.__init__(self)
-        self.icon.props.xo_color = xocolor
+        self.icon.props.xo_color = xo_color
         self.icon.props.icon_name = 'computer-xo'
         self.icon.props.pixel_size = style.XLARGE_ICON_SIZE
-        self.connect('button_press_event', self.__pressed_cb)
+        self.connect('button_press_event', self.__pressed_cb, me)
+
+    def __pressed_cb(self, button, event, me):
+        me.set_random_colors()
+
+class ColorPrev(EventIcon):
+    __gsignals__ = {
+        'color-changed': (gobject.SIGNAL_RUN_FIRST,
+                          gobject.TYPE_NONE,
+                          ([str]))
+    }
+    def __init__(self, me, xo_next_color=None):
+        EventIcon.__init__(self)
+        self.icon.props.xo_color = xo_next_color
+        self.icon.props.icon_name = 'computer-xo'
+        self.icon.props.pixel_size = style.STANDARD_ICON_SIZE
+        self.connect('button_press_event', self.__pressed_cb, me)
+
+    def __pressed_cb(self, button, event, me):
+        me.set_prev_colors()
+
+class ColorNext(EventIcon):
+    __gsignals__ = {
+        'color-changed': (gobject.SIGNAL_RUN_FIRST,
+                          gobject.TYPE_NONE,
+                          ([str]))
+    }
+    def __init__(self, me, xo_next_color=None):
+        EventIcon.__init__(self)
+        self.icon.props.xo_color = xo_next_color
+        self.icon.props.icon_name = 'computer-xo'
+        self.icon.props.pixel_size = style.STANDARD_ICON_SIZE
+        self.connect('button_press_event', self.__pressed_cb, me)
+
+    def __pressed_cb(self, button, event, me):
+        me.set_next_colors()
+
+class ColorUndo(EventIcon):
+    __gsignals__ = {
+        'color-changed': (gobject.SIGNAL_RUN_FIRST,
+                          gobject.TYPE_NONE,
+                          ([str]))
+    }
+    def __init__(self, me):
+        EventIcon.__init__(self)
+        self.icon.props.icon_name = 'edit-undo'
+        # self.icon.props.icon_name = 'view-refresh'
+        # self.icon.props.accelerator = '<Ctrl>z'
+        xocolor = XoColor()
+        xocolor.set_color("#FFFFFF,#FFFFFF")
+        self.icon.props.xo_color = xocolor
+        self.icon.props.pixel_size = style.MEDIUM_ICON_SIZE
+        self.connect('button_press_event', self.__pressed_cb, me)
 
-    def __pressed_cb(self, button, event):
-        self._set_random_colors()
+    def __pressed_cb(self, button, event, me):
+        me.undo_colors()
 
-    def _set_random_colors(self):
+class Prev(EventIcon):
+    __gsignals__ = {
+        'color-changed': (gobject.SIGNAL_RUN_FIRST,
+                          gobject.TYPE_NONE,
+                          ([str]))
+    }
+    def __init__(self, me):
+        EventIcon.__init__(self)
+        self.icon.props.icon_name = 'go-left'
         xocolor = XoColor()
+        xocolor.set_color("#FFFFFF,#808080")
         self.icon.props.xo_color = xocolor
-        self.emit('color-changed', xocolor.to_string())
+        self.icon.props.pixel_size = style.STANDARD_ICON_SIZE
+        self.connect('button_press_event', self.__pressed_cb, me)
+
+    def __pressed_cb(self, button, event, me):
+        me.set_prev_colors()
+
+class Next(EventIcon):
+    __gsignals__ = {
+        'color-changed': (gobject.SIGNAL_RUN_FIRST,
+                          gobject.TYPE_NONE,
+                          ([str]))
+    }
+    def __init__(self, me):
+        EventIcon.__init__(self)
+        self.icon.props.icon_name = 'go-right'
+        xocolor = XoColor()
+        xocolor.set_color("#FFFFFF,#808080")
+        self.icon.props.xo_color = xocolor
+        self.icon.props.pixel_size = style.STANDARD_ICON_SIZE
+        self.connect('button_press_event', self.__pressed_cb, me)
+
+    def __pressed_cb(self, button, event, me):
+        me.set_next_colors()
 
 class AboutMe(SectionView):
     def __init__(self, model, alerts):
         SectionView.__init__(self)
 
         self._model = model
+        self._xo_color = XoColor(self._model.get_color_xo())
+        self._undo_colors = self._xo_color.to_string()
+        self._xo_next_color = XoColor(self._xo_color.get_next_color())
+        self._xo_prev_color = XoColor(self._xo_color.get_prev_color())
         self.restart_alerts = alerts
         self._nick_sid = 0
         self._color_valid = True
@@ -131,11 +231,37 @@ class AboutMe(SectionView):
         self._group.add_widget(label_color)
         self._color_box.pack_start(label_color, expand=False)
         label_color.show()
+
+        self._color_prev = ColorPrev(self,self._xo_prev_color)
+        self._color_box.pack_start(self._color_prev, expand=False)
+        self._color_prev.show()
         
-        self._color_picker = ColorPicker()
+        self._prev = Prev(self)
+        self._color_box.pack_start(self._prev, expand=False)
+        self._prev.show()
+
+        self._color_picker = ColorPicker(self,self._xo_color)
         self._color_box.pack_start(self._color_picker, expand=False)
         self._color_picker.show()
 
+        self._next = Next(self)
+        self._color_box.pack_start(self._next, expand=False)
+        self._next.show()
+
+        self._color_next = ColorNext(self,self._xo_next_color)
+        self._color_box.pack_start(self._color_next, expand=False)
+        self._color_next.show()
+
+        self._color_undo = ColorUndo(self)
+        self._color_box.pack_start(self._color_undo, expand=False)
+        self._color_undo.show()
+
+        """
+        self._stop = StopButton()
+        self._color_box.pack_start(self._stop, expand=False)
+        self._stop.show()
+        """
+
         label_color_error = gtk.Label()
         self._group.add_widget(label_color_error)
         self._color_alert_box.pack_start(label_color_error, expand=False)
@@ -152,10 +278,73 @@ class AboutMe(SectionView):
         self._color_box.show()
         self._color_alert_box.show()
     
+    def set_prev_colors(self):
+        # update next color to the current color
+        self._xo_next_color.set_color(self._xo_color.to_string())
+        self._color_next.icon.props.xo_color = self._xo_next_color
+        self._color_next.emit('color-changed', self._xo_next_color.to_string())
+        # update color picker to the prev color
+        self._undo_colors = self._xo_color.to_string()
+        self._xo_color.set_color(self._xo_prev_color.to_string())
+        self._color_picker.icon.props.xo_color = self._xo_color
+        self._color_picker.emit('color-changed', self._xo_color.to_string())
+        # update prev color to its prev color
+        self._xo_prev_color.set_color(self._xo_prev_color.get_prev_color())
+        self._color_prev.icon.props.xo_color = self._xo_prev_color
+        self._color_prev.emit('color-changed', self._xo_prev_color.to_string())
+
+    def set_random_colors(self):
+        # update this color to a random color
+        self._undo_colors = self._xo_color.to_string()
+        self._xo_color.set_color(self._xo_color.get_random_color())
+        self._color_picker.icon.props.xo_color = self._xo_color
+        self._color_picker.emit('color-changed', self._xo_color.to_string())
+        # update prev color from the current color
+        self._xo_prev_color.set_color(self._xo_color.get_prev_color())
+        self._color_prev.icon.props.xo_color = self._xo_prev_color
+        self._color_prev.emit('color-changed', self._xo_prev_color.to_string())
+        # update next color from the current color
+        self._xo_next_color.set_color(self._xo_color.get_next_color())
+        self._color_next.icon.props.xo_color = self._xo_next_color
+        self._color_next.emit('color-changed', self._xo_next_color.to_string())
+
+    def set_next_colors(self):
+        # update prev color to the current color
+        self._xo_prev_color.set_color(self._xo_color.to_string())
+        self._color_prev.icon.props.xo_color = self._xo_prev_color
+        self._color_prev.emit('color-changed', self._xo_prev_color.to_string())
+        # update color picker to the next color
+        self._undo_colors = self._xo_color.to_string()
+        self._xo_color.set_color(self._xo_next_color.to_string())
+        self._color_picker.icon.props.xo_color = self._xo_color
+        self._color_picker.emit('color-changed', self._xo_color.to_string())
+        # update next color to its next color
+        self._xo_next_color.set_color(self._xo_next_color.get_next_color())
+        self._color_next.icon.props.xo_color = self._xo_next_color
+        self._color_next.emit('color-changed', self._xo_next_color.to_string())
+
+    def undo_colors(self):
+        # undo last change
+        tmp = self._xo_color.to_string()
+        self._xo_color.set_color(self._undo_colors)
+        self._undo_colors = tmp
+        self._color_picker.icon.props.xo_color = self._xo_color
+        self._color_picker.emit('color-changed', self._xo_color.to_string())
+        # update prev color from the current color
+        self._xo_prev_color.set_color(self._xo_color.get_prev_color())
+        self._color_prev.icon.props.xo_color = self._xo_prev_color
+        self._color_prev.emit('color-changed', self._xo_prev_color.to_string())
+        # update next color from the current color
+        self._xo_next_color.set_color(self._xo_color.get_next_color())
+        self._color_next.icon.props.xo_color = self._xo_next_color
+        self._color_next.emit('color-changed', self._xo_next_color.to_string())
+    
     def setup(self):
         self._nick_entry.set_text(self._model.get_nick())
-        color = XoColor(self._model.get_color_xo())
-        self._color_picker.icon.props.xo_color = color
+        # mycolor = self._model.get_color_xo()
+        self._color_picker.icon.props.xo_color = self._xo_color
+        self._color_next.icon.props.xo_color = self._xo_next_color
+        self._color_prev.icon.props.xo_color = self._xo_prev_color
 
         self._color_valid = True
         self._nick_valid = True
diff --git a/src/jarabe/intro/colorpicker.py b/src/jarabe/intro/colorpicker.py
index a939857..d37d1d1 100644
--- a/src/jarabe/intro/colorpicker.py
+++ b/src/jarabe/intro/colorpicker.py
@@ -19,7 +19,7 @@ import hippo
 from sugar.graphics.icon import CanvasIcon
 from sugar.graphics import style
 from sugar.graphics.xocolor import XoColor
-
+"""
 class ColorPicker(hippo.CanvasBox, hippo.CanvasItem):
     def __init__(self, **kwargs):
         hippo.CanvasBox.__init__(self, **kwargs)
@@ -41,3 +41,73 @@ class ColorPicker(hippo.CanvasBox, hippo.CanvasItem):
     def _set_random_colors(self):
         self._xo_color = XoColor()
         self._xo.props.xo_color = self._xo_color
+"""
+class ColorPicker(hippo.CanvasBox, hippo.CanvasItem):
+    def __init__(self, me, **kwargs):
+        hippo.CanvasBox.__init__(self, **kwargs)
+        self.props.orientation = hippo.ORIENTATION_HORIZONTAL
+        self._xo_color = None
+
+        self._xo = CanvasIcon(size=style.XLARGE_ICON_SIZE,
+                              icon_name='computer-xo')
+        self._xo.connect('activated', self.__pressed_cb, me)
+        self.append(self._xo)
+
+    def __pressed_cb(self, item, me):
+        me.set_random_colors()
+
+class ColorPrev(hippo.CanvasBox, hippo.CanvasItem):
+    def __init__(self, me, **kwargs):
+        hippo.CanvasBox.__init__(self, **kwargs)
+        self.props.orientation = hippo.ORIENTATION_HORIZONTAL
+        self._xo_color = None
+
+        self._xo = CanvasIcon(size=style.STANDARD_ICON_SIZE,
+                              icon_name='computer-xo')
+        self._xo.connect('activated', self.__pressed_cb, me)
+        self.append(self._xo)
+
+    def __pressed_cb(self, item, me):
+        me.set_prev_colors()
+
+class ColorNext(hippo.CanvasBox, hippo.CanvasItem):
+    def __init__(self, me, **kwargs):
+        hippo.CanvasBox.__init__(self, **kwargs)
+        self.props.orientation = hippo.ORIENTATION_HORIZONTAL
+        self._xo_color = None
+
+        self._xo = CanvasIcon(size=style.STANDARD_ICON_SIZE,
+                              icon_name='computer-xo')
+        self._xo.connect('activated', self.__pressed_cb, me)
+        self.append(self._xo)
+
+    def __pressed_cb(self, item, me):
+        me.set_next_colors()
+
+class Prev(hippo.CanvasBox, hippo.CanvasItem):
+    def __init__(self, me, **kwargs):
+        hippo.CanvasBox.__init__(self, **kwargs)
+        self.props.orientation = hippo.ORIENTATION_HORIZONTAL
+        self._xo_color = None
+
+        self._xo = CanvasIcon(size=style.STANDARD_ICON_SIZE,
+                              icon_name='go-left')
+        self._xo.connect('activated', self.__pressed_cb, me)
+        self.append(self._xo)
+
+    def __pressed_cb(self, item, me):
+        me.set_prev_colors()
+
+class Next(hippo.CanvasBox, hippo.CanvasItem):
+    def __init__(self, me, **kwargs):
+        hippo.CanvasBox.__init__(self, **kwargs)
+        self.props.orientation = hippo.ORIENTATION_HORIZONTAL
+        self._xo_color = None
+
+        self._xo = CanvasIcon(size=style.STANDARD_ICON_SIZE,
+                              icon_name='go-right')
+        self._xo.connect('activated', self.__pressed_cb, me)
+        self.append(self._xo)
+
+    def __pressed_cb(self, item, me):
+        me.set_prev_colors()
diff --git a/src/jarabe/intro/window.py b/src/jarabe/intro/window.py
index 94c6782..9665d1b 100644
--- a/src/jarabe/intro/window.py
+++ b/src/jarabe/intro/window.py
@@ -125,14 +125,68 @@ class _ColorPage(_Page):
                                        xalign=hippo.ALIGNMENT_CENTER)
         self.append(self._label)
 
-        self._cp = colorpicker.ColorPicker(xalign=hippo.ALIGNMENT_CENTER)
-        self.append(self._cp)
+        self._box = hippo.CanvasBox(orientation=hippo.ORIENTATION_HORIZONTAL)
+
+        self._p = colorpicker.Prev(self)
+        self._box.append(self._p)
+
+        self._pc = colorpicker.ColorPrev(self)
+        self._box.append(self._pc)
+
+        self._cp = colorpicker.ColorPicker(self)
+        self._box.append(self._cp)
+
+        self._nc = colorpicker.ColorNext(self)
+        self._box.append(self._nc)
+
+        self._n = colorpicker.Next(self)
+        self._box.append(self._n)
+
+        self.append(self._box)
 
-        self._color = self._cp.get_color()
         self.set_valid(True)
 
+        self.init_colors()
+        self.set_random_colors()
+
+    def init_colors(self):
+        self._cp._xo_color = XoColor()
+        self._cp._xo.props.xo_color = self._cp._xo_color
+        self._pc._xo_color = XoColor()
+        self._pc._xo.props.xo_color = self._pc._xo_color
+        self._nc._xo_color = XoColor()
+        self._nc._xo.props.xo_color = self._nc._xo_color
+        self._p._xo_color = XoColor()
+        self._p._xo_color.set_color("#808080,#808080")
+        self._p._xo.props.xo_color = self._p._xo_color
+        self._n._xo.props.xo_color = self._p._xo_color
+        
+    def set_random_colors(self):
+        self._cp._xo_color.set_color(self._cp._xo_color.get_random_color())
+        self._cp._xo.props.xo_color = self._cp._xo_color
+        self._pc._xo_color.set_color(self._cp._xo_color.get_prev_color())
+        self._pc._xo.props.xo_color = self._pc._xo_color
+        self._nc._xo_color.set_color(self._cp._xo_color.get_next_color())
+        self._nc._xo.props.xo_color = self._nc._xo_color
+
+    def set_prev_colors(self):
+        self._nc._xo_color.set_color(self._cp._xo_color.to_string())
+        self._nc._xo.props.xo_color = self._nc._xo_color
+        self._cp._xo_color.set_color(self._pc._xo_color.to_string())
+        self._cp._xo.props.xo_color = self._cp._xo_color
+        self._pc._xo_color.set_color(self._pc._xo_color.get_prev_color())
+        self._pc._xo.props.xo_color = self._pc._xo_color
+
+    def set_next_colors(self):
+        self._pc._xo_color.set_color(self._cp._xo_color.to_string())
+        self._pc._xo.props.xo_color = self._pc._xo_color
+        self._cp._xo_color.set_color(self._nc._xo_color.to_string())
+        self._cp._xo.props.xo_color = self._cp._xo_color
+        self._nc._xo_color.set_color(self._nc._xo_color.get_next_color())
+        self._nc._xo.props.xo_color = self._nc._xo_color
+
     def get_color(self):
-        return self._cp.get_color()
+        return self._cp._xo_color
 
 class _IntroBox(hippo.CanvasBox):
     __gsignals__ = {
@@ -170,7 +224,18 @@ class _IntroBox(hippo.CanvasBox):
 
         button_box = hippo.CanvasBox(orientation=hippo.ORIENTATION_HORIZONTAL)
 
-        if self._page != self.PAGE_FIRST:
+        if self._page == self.PAGE_FIRST:
+            lang_button = hippo.CanvasButton()
+            image = Icon(icon_name='module-language')
+            lang_button.props.widget.set_image(image)
+            lang_button.connect('activated', self._lang_activated_cb)
+            button_box.append(lang_button)
+            keyboard_button = hippo.CanvasButton()
+            image = Icon(icon_name='module-keyboard')
+            keyboard_button.props.widget.set_image(image)
+            keyboard_button.connect('activated', self._keyboard_activated_cb)
+            button_box.append(keyboard_button)
+        else:
             back_button = hippo.CanvasButton(text=_('Back'))
             image = Icon(icon_name='go-left')
             back_button.props.widget.set_image(image)
@@ -213,6 +278,12 @@ class _IntroBox(hippo.CanvasBox):
     def _back_activated_cb(self, item):
         self.back()
 
+    def _lang_activated_cb(self, item):
+        print "Language button pressed"
+
+    def _keyboard_activated_cb(self, item):
+        print "Keyboard button pressed"
+
     def back(self):
         if self._page != self.PAGE_FIRST:
             self._page -= 1
-- 
1.6.3.3

