Features/Enhanced color selector/Patch-view

From Sugar Labs
< Features‎ | Enhanced color selector
Revision as of 16:52, 19 November 2009 by Walter (talk | contribs) (Created page with '<pre> --- extensions/cpsection/aboutme/view.py 2009-11-10 12:15:50.000000000 -0500 +++ extensions/cpsection/aboutme/view.py 2009-11-19 15:07:55.000000000 -0500 @@ -20,11 +20,13 @…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
--- extensions/cpsection/aboutme/view.py	2009-11-10 12:15:50.000000000 -0500
+++ extensions/cpsection/aboutme/view.py	2009-11-19 15:07:55.000000000 -0500
@@ -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):         
@@ -45,26 +47,113 @@ class ColorPicker(EventIcon):
                           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):
-        self._set_random_colors()
+    def __pressed_cb(self, button, event, me):
+        me.set_next_colors()
 
-    def _set_random_colors(self):
+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.emit('color-changed', xocolor.to_string())
+        self.icon.props.pixel_size = style.MEDIUM_ICON_SIZE
+        self.connect('button_press_event', self.__pressed_cb, me)
+
+    def __pressed_cb(self, button, event, me):
+        me.undo_colors()
+
+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.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 +220,31 @@ 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()
+
         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 +261,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