Ticket #1592: view.patch

File view.patch, 16.6 KB (added by walter, 14 years ago)

new as of 24-01-10

  • extensions/cpsection/aboutme/view.py

    diff --git a/extensions/cpsection/aboutme/view.py b/extensions/cpsection/aboutme/view.py
    index d92de87..d13d4ec 100644
    a b from gettext import gettext as _ 
    2121from sugar.graphics.icon import Icon
    2222from sugar.graphics import style
    2323from sugar.graphics.toolbutton import ToolButton
    24 from sugar.graphics.xocolor import XoColor
     24from sugar.graphics.xocolor import XoColor, get_random_color
    2525
    2626from jarabe.controlpanel.sectionview import SectionView
    2727from jarabe.controlpanel.inlinealert import InlineAlert
    2828
     29_DIRECTION_CENTER = 0
     30_DIRECTION_LEFT = 1
     31_DIRECTION_RIGHT = 2
     32_DIRECTION_TOP = 3
     33_DIRECTION_BOTTOM = 4
    2934
    3035class EventIcon(gtk.EventBox):
    3136    __gtype_name__ = "SugarEventIcon"   
    class EventIcon(gtk.EventBox): 
    4045
    4146        self.add(self.icon)
    4247        self.icon.show()
    43 """
    44 class StopButton(ToolButton):
    45 
    46     def __init__(self, **kwargs):
    47         ToolButton.__init__(self, 'activity-stop', **kwargs)
    48         self.props.tooltip = _('Stop')
    49         self.props.accelerator = '<Ctrl>Q'
    50         self.connect('clicked', self.__stop_button_clicked_cb)
    51 
    52     def __stop_button_clicked_cb(self, button):
    53         print "out damn spot"
    54 """
    55 class ColorPicker(EventIcon):
    56     __gsignals__ = {
    57         'color-changed': (gobject.SIGNAL_RUN_FIRST,
    58                           gobject.TYPE_NONE,
    59                           ([str]))
    60     }
    61     def __init__(self, me, xo_color=None):
    62         EventIcon.__init__(self)
    63         self.icon.props.xo_color = xo_color
    64         self.icon.props.icon_name = 'computer-xo'
    65         self.icon.props.pixel_size = style.XLARGE_ICON_SIZE
    66         self.connect('button_press_event', self.__pressed_cb, me)
    67 
    68     def __pressed_cb(self, button, event, me):
    69         me.set_random_colors()
    7048
    71 class ColorPrev(EventIcon):
    72     __gsignals__ = {
    73         'color-changed': (gobject.SIGNAL_RUN_FIRST,
    74                           gobject.TYPE_NONE,
    75                           ([str]))
    76     }
    77     def __init__(self, me, xo_next_color=None):
    78         EventIcon.__init__(self)
    79         self.icon.props.xo_color = xo_next_color
    80         self.icon.props.icon_name = 'computer-xo'
    81         self.icon.props.pixel_size = style.STANDARD_ICON_SIZE
    82         self.connect('button_press_event', self.__pressed_cb, me)
    83 
    84     def __pressed_cb(self, button, event, me):
    85         me.set_prev_colors()
    86 
    87 class ColorNext(EventIcon):
     49class ColorPicker(EventIcon):
    8850    __gsignals__ = {
    8951        'color-changed': (gobject.SIGNAL_RUN_FIRST,
    9052                          gobject.TYPE_NONE,
    9153                          ([str]))
    9254    }
    93     def __init__(self, me, xo_next_color=None):
     55    def __init__(self, me, xo_color=None, direction=_DIRECTION_CENTER):
    9456        EventIcon.__init__(self)
    95         self.icon.props.xo_color = xo_next_color
    9657        self.icon.props.icon_name = 'computer-xo'
    97         self.icon.props.pixel_size = style.STANDARD_ICON_SIZE
    98         self.connect('button_press_event', self.__pressed_cb, me)
    99 
    100     def __pressed_cb(self, button, event, me):
    101         me.set_next_colors()
    102 
    103 class ColorUndo(EventIcon):
    104     __gsignals__ = {
    105         'color-changed': (gobject.SIGNAL_RUN_FIRST,
    106                           gobject.TYPE_NONE,
    107                           ([str]))
    108     }
    109     def __init__(self, me):
    110         EventIcon.__init__(self)
    111         self.icon.props.icon_name = 'edit-undo'
    112         # self.icon.props.icon_name = 'view-refresh'
    113         # self.icon.props.accelerator = '<Ctrl>z'
    114         xocolor = XoColor()
    115         xocolor.set_color("#FFFFFF,#FFFFFF")
    116         self.icon.props.xo_color = xocolor
    117         self.icon.props.pixel_size = style.MEDIUM_ICON_SIZE
    118         self.connect('button_press_event', self.__pressed_cb, me)
    119 
    120     def __pressed_cb(self, button, event, me):
    121         me.undo_colors()
    122 
    123 class Prev(EventIcon):
    124     __gsignals__ = {
    125         'color-changed': (gobject.SIGNAL_RUN_FIRST,
    126                           gobject.TYPE_NONE,
    127                           ([str]))
    128     }
    129     def __init__(self, me):
    130         EventIcon.__init__(self)
    131         self.icon.props.icon_name = 'go-left'
    132         xocolor = XoColor()
    133         xocolor.set_color("#FFFFFF,#808080")
    134         self.icon.props.xo_color = xocolor
    135         self.icon.props.pixel_size = style.STANDARD_ICON_SIZE
    136         self.connect('button_press_event', self.__pressed_cb, me)
    137 
    138     def __pressed_cb(self, button, event, me):
    139         me.set_prev_colors()
    140 
    141 class Next(EventIcon):
    142     __gsignals__ = {
    143         'color-changed': (gobject.SIGNAL_RUN_FIRST,
    144                           gobject.TYPE_NONE,
    145                           ([str]))
    146     }
    147     def __init__(self, me):
    148         EventIcon.__init__(self)
    149         self.icon.props.icon_name = 'go-right'
    150         xocolor = XoColor()
    151         xocolor.set_color("#FFFFFF,#808080")
    152         self.icon.props.xo_color = xocolor
    153         self.icon.props.pixel_size = style.STANDARD_ICON_SIZE
    154         self.connect('button_press_event', self.__pressed_cb, me)
    155 
    156     def __pressed_cb(self, button, event, me):
    157         me.set_next_colors()
     58        if direction == _DIRECTION_CENTER:
     59            self.icon.props.pixel_size = style.XLARGE_ICON_SIZE
     60            self.icon.props.xo_color = xo_color
     61        else:
     62            self.icon.props.pixel_size = style.STANDARD_ICON_SIZE
     63            if direction == _DIRECTION_LEFT:
     64                self.icon.props.xo_color = XoColor(
     65                                               xo_color.get_prev_fill_color())
     66            elif direction == _DIRECTION_RIGHT:
     67                self.icon.props.xo_color = XoColor(
     68                                               xo_color.get_next_fill_color())
     69            elif direction == _DIRECTION_TOP:
     70                self.icon.props.xo_color = XoColor(
     71                                               xo_color.get_prev_stroke_color())
     72            else:
     73                self.icon.props.xo_color = XoColor(
     74                                               xo_color.get_next_stroke_color())
     75        self.connect('button_press_event', self.__pressed_cb, me, direction)
     76
     77    def __pressed_cb(self, button, event, me, direction):
     78        if direction == _DIRECTION_LEFT:
     79            me.set_prev_fill_colors()
     80        elif direction == _DIRECTION_RIGHT:
     81            me.set_next_fill_colors()
     82        elif direction == _DIRECTION_TOP:
     83            me.set_prev_stroke_colors()
     84        elif direction == _DIRECTION_BOTTOM:
     85            me.set_next_stroke_colors()
    15886
    15987class AboutMe(SectionView):
    16088    def __init__(self, model, alerts):
    class AboutMe(SectionView): 
    16290
    16391        self._model = model
    16492        self._xo_color = XoColor(self._model.get_color_xo())
    165         self._undo_colors = self._xo_color.to_string()
    166         self._xo_next_color = XoColor(self._xo_color.get_next_color())
    167         self._xo_prev_color = XoColor(self._xo_color.get_prev_color())
    16893        self.restart_alerts = alerts
    16994        self._nick_sid = 0
    17095        self._color_valid = True
    class AboutMe(SectionView): 
    184109
    185110        self._color_box = gtk.HBox(spacing=style.DEFAULT_SPACING)
    186111        self._color_alert_box = gtk.HBox(spacing=style.DEFAULT_SPACING)
    187         self._color_picker = None
     112        self._current_color = None
    188113        self._color_alert = None
    189114        self._setup_color()       
    190115
    class AboutMe(SectionView): 
    232157        self._color_box.pack_start(label_color, expand=False)
    233158        label_color.show()
    234159
    235         self._color_prev = ColorPrev(self,self._xo_prev_color)
    236         self._color_box.pack_start(self._color_prev, expand=False)
    237         self._color_prev.show()
     160        self._color_prev_fill = ColorPicker(self, self._xo_color,
     161                                                _DIRECTION_LEFT)
     162        self._color_box.pack_start(self._color_prev_fill, expand=False)
     163        self._color_prev_fill.show()
    238164       
    239         self._prev = Prev(self)
    240         self._color_box.pack_start(self._prev, expand=False)
    241         self._prev.show()
    242 
    243         self._color_picker = ColorPicker(self,self._xo_color)
    244         self._color_box.pack_start(self._color_picker, expand=False)
    245         self._color_picker.show()
    246 
    247         self._next = Next(self)
    248         self._color_box.pack_start(self._next, expand=False)
    249         self._next.show()
    250 
    251         self._color_next = ColorNext(self,self._xo_next_color)
    252         self._color_box.pack_start(self._color_next, expand=False)
    253         self._color_next.show()
    254 
    255         self._color_undo = ColorUndo(self)
    256         self._color_box.pack_start(self._color_undo, expand=False)
    257         self._color_undo.show()
    258 
    259         """
    260         self._stop = StopButton()
    261         self._color_box.pack_start(self._stop, expand=False)
    262         self._stop.show()
    263         """
     165        self._color_prev_stroke = ColorPicker(self, self._xo_color,
     166                                                  _DIRECTION_TOP)
     167        self._color_box.pack_start(self._color_prev_stroke, expand=False)
     168        self._color_prev_stroke.show()
     169
     170        self._current_color = ColorPicker(self, self._xo_color,
     171                                          _DIRECTION_CENTER)
     172        self._color_box.pack_start(self._current_color, expand=False)
     173        self._current_color.show()
     174
     175        self._color_next_stroke = ColorPicker(self, self._xo_color,
     176                                              _DIRECTION_BOTTOM)
     177        self._color_box.pack_start(self._color_next_stroke, expand=False)
     178        self._color_next_stroke.show()
     179
     180        self._color_next_fill = ColorPicker(self, self._xo_color,
     181                                            _DIRECTION_RIGHT)
     182        self._color_box.pack_start(self._color_next_fill, expand=False)
     183        self._color_next_fill.show()
    264184
    265185        label_color_error = gtk.Label()
    266186        self._group.add_widget(label_color_error)
    class AboutMe(SectionView): 
    277197        self.pack_start(self._color_alert_box, False)       
    278198        self._color_box.show()
    279199        self._color_alert_box.show()
    280    
    281     def set_prev_colors(self):
    282         # update next color to the current color
    283         self._xo_next_color.set_color(self._xo_color.to_string())
    284         self._color_next.icon.props.xo_color = self._xo_next_color
    285         self._color_next.emit('color-changed', self._xo_next_color.to_string())
    286         # update color picker to the prev color
    287         self._undo_colors = self._xo_color.to_string()
    288         self._xo_color.set_color(self._xo_prev_color.to_string())
    289         self._color_picker.icon.props.xo_color = self._xo_color
    290         self._color_picker.emit('color-changed', self._xo_color.to_string())
    291         # update prev color to its prev color
    292         self._xo_prev_color.set_color(self._xo_prev_color.get_prev_color())
    293         self._color_prev.icon.props.xo_color = self._xo_prev_color
    294         self._color_prev.emit('color-changed', self._xo_prev_color.to_string())
    295 
    296     def set_random_colors(self):
    297         # update this color to a random color
    298         self._undo_colors = self._xo_color.to_string()
    299         self._xo_color.set_color(self._xo_color.get_random_color())
    300         self._color_picker.icon.props.xo_color = self._xo_color
    301         self._color_picker.emit('color-changed', self._xo_color.to_string())
    302         # update prev color from the current color
    303         self._xo_prev_color.set_color(self._xo_color.get_prev_color())
    304         self._color_prev.icon.props.xo_color = self._xo_prev_color
    305         self._color_prev.emit('color-changed', self._xo_prev_color.to_string())
    306         # update next color from the current color
    307         self._xo_next_color.set_color(self._xo_color.get_next_color())
    308         self._color_next.icon.props.xo_color = self._xo_next_color
    309         self._color_next.emit('color-changed', self._xo_next_color.to_string())
    310 
    311     def set_next_colors(self):
    312         # update prev color to the current color
    313         self._xo_prev_color.set_color(self._xo_color.to_string())
    314         self._color_prev.icon.props.xo_color = self._xo_prev_color
    315         self._color_prev.emit('color-changed', self._xo_prev_color.to_string())
    316         # update color picker to the next color
    317         self._undo_colors = self._xo_color.to_string()
    318         self._xo_color.set_color(self._xo_next_color.to_string())
    319         self._color_picker.icon.props.xo_color = self._xo_color
    320         self._color_picker.emit('color-changed', self._xo_color.to_string())
    321         # update next color to its next color
    322         self._xo_next_color.set_color(self._xo_next_color.get_next_color())
    323         self._color_next.icon.props.xo_color = self._xo_next_color
    324         self._color_next.emit('color-changed', self._xo_next_color.to_string())
    325 
    326     def undo_colors(self):
    327         # undo last change
    328         tmp = self._xo_color.to_string()
    329         self._xo_color.set_color(self._undo_colors)
    330         self._undo_colors = tmp
    331         self._color_picker.icon.props.xo_color = self._xo_color
    332         self._color_picker.emit('color-changed', self._xo_color.to_string())
    333         # update prev color from the current color
    334         self._xo_prev_color.set_color(self._xo_color.get_prev_color())
    335         self._color_prev.icon.props.xo_color = self._xo_prev_color
    336         self._color_prev.emit('color-changed', self._xo_prev_color.to_string())
    337         # update next color from the current color
    338         self._xo_next_color.set_color(self._xo_color.get_next_color())
    339         self._color_next.icon.props.xo_color = self._xo_next_color
    340         self._color_next.emit('color-changed', self._xo_next_color.to_string())
    341    
     200       
     201    def set_prev_fill_colors(self):
     202        self._xo_color.set_color(self._xo_color.get_prev_fill_color())
     203        self._current_color.emit('color-changed', self._xo_color.to_string())
     204        self._current_color.icon.props.xo_color = self._xo_color
     205        self._update_button_colors()
     206
     207    def set_next_fill_colors(self):
     208        self._xo_color.set_color(self._xo_color.get_next_fill_color())
     209        self._current_color.emit('color-changed', self._xo_color.to_string())
     210        self._current_color.icon.props.xo_color = self._xo_color
     211        self._update_button_colors()
     212
     213    def set_prev_stroke_colors(self):
     214        self._xo_color.set_color(self._xo_color.get_prev_stroke_color())
     215        self._current_color.emit('color-changed', self._xo_color.to_string())
     216        self._current_color.icon.props.xo_color = self._xo_color
     217        self._update_button_colors()
     218
     219    def set_next_stroke_colors(self):
     220        self._xo_color.set_color(self._xo_color.get_next_stroke_color())
     221        self._current_color.emit('color-changed', self._xo_color.to_string())
     222        self._current_color.icon.props.xo_color = self._xo_color
     223        self._update_button_colors()
     224
     225    def _update_button_colors(self):
     226        next_fill_color = XoColor(self._xo_color.get_next_fill_color())
     227        self._color_next_fill.icon.props.xo_color = next_fill_color
     228        prev_fill_color = XoColor(self._xo_color.get_prev_fill_color())
     229        self._color_prev_fill.icon.props.xo_color = prev_fill_color
     230        next_stroke_color = XoColor(self._xo_color.get_next_stroke_color())
     231        self._color_next_stroke.icon.props.xo_color = next_stroke_color
     232        prev_stroke_color = XoColor(self._xo_color.get_prev_stroke_color())
     233        self._color_prev_stroke.icon.props.xo_color = prev_stroke_color
     234
    342235    def setup(self):
    343236        self._nick_entry.set_text(self._model.get_nick())
    344         # mycolor = self._model.get_color_xo()
    345         self._color_picker.icon.props.xo_color = self._xo_color
    346         self._color_next.icon.props.xo_color = self._xo_next_color
    347         self._color_prev.icon.props.xo_color = self._xo_prev_color
    348 
    349237        self._color_valid = True
    350238        self._nick_valid = True
    351239        self.needs_restart = False
    352         self._nick_change_handler = self._nick_entry.connect( \
     240        self._nick_change_handler = self._nick_entry.connect(
    353241                'changed', self.__nick_changed_cb)
    354         self._color_change_handler = self._color_picker.connect( \
     242        self._color_change_handler = self._current_color.connect(
    355243                'color-changed', self.__color_changed_cb)
    356244
    357245    def undo(self):
    358         self._color_picker.disconnect(self._color_change_handler)
     246        self._current_color.disconnect(self._color_change_handler)
    359247        self._nick_entry.disconnect(self._nick_change_handler)
    360248        self._model.undo()
    361249        self._nick_alert.hide()
    class AboutMe(SectionView): 
    392280        self._nick_alert.show()
    393281        return False
    394282
    395     def __color_changed_cb(self, colorpicker, xocolor):       
    396         self._model.set_color_xo(xocolor)
     283    def __color_changed_cb(self, colorpicker, xo_color):
     284        self._model.set_color_xo(xo_color)
    397285        self.needs_restart = True
    398286        self._color_alert.props.msg = self.restart_msg
    399287        self._color_valid = True