Ticket #1592: new-view.patch

File new-view.patch, 16.9 KB (added by walter, 14 years ago)

Feb 8 patch acording to Christian's Feb 6 design

  • extensions/cpsection/aboutme/view.py

    diff --git a/extensions/cpsection/aboutme/view.py b/extensions/cpsection/aboutme/view.py
    index d92de87..58f3972 100644
    a b from gettext import gettext as _ 
    2020
    2121from sugar.graphics.icon import Icon
    2222from sugar.graphics import style
    23 from sugar.graphics.toolbutton import ToolButton
    2423from sugar.graphics.xocolor import XoColor
    2524
    2625from jarabe.controlpanel.sectionview import SectionView
    2726from jarabe.controlpanel.inlinealert import InlineAlert
    2827
     28_DIRECTION_LEFT = 0
     29_DIRECTION_TOP = 1
     30_DIRECTION_CENTER = 2
     31_DIRECTION_BOTTOM = 3
     32_DIRECTION_RIGHT = 4
    2933
    3034class EventIcon(gtk.EventBox):
    3135    __gtype_name__ = "SugarEventIcon"   
    class EventIcon(gtk.EventBox): 
    4044
    4145        self.add(self.icon)
    4246        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 """
     47
    5548class ColorPicker(EventIcon):
    5649    __gsignals__ = {
    5750        'color-changed': (gobject.SIGNAL_RUN_FIRST,
    5851                          gobject.TYPE_NONE,
    59                           ([str]))
     52                          ([object]))
    6053    }
    61     def __init__(self, me, xo_color=None):
     54    def __init__(self, direction):
    6255        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()
    7056
    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
    8057        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()
     58        self._direction = direction
     59        self._color = None
    8660
    87 class ColorNext(EventIcon):
    88     __gsignals__ = {
    89         'color-changed': (gobject.SIGNAL_RUN_FIRST,
    90                           gobject.TYPE_NONE,
    91                           ([str]))
    92     }
    93     def __init__(self, me, xo_next_color=None):
    94         EventIcon.__init__(self)
    95         self.icon.props.xo_color = xo_next_color
    96         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()
     61        self.icon.props.pixel_size = style.XLARGE_ICON_SIZE
    14062
    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)
     63        self.connect('button_press_event', self.__pressed_cb, direction)
     64
     65    def update(self, color):
     66        if self._direction == _DIRECTION_CENTER:
     67            self._color = color
     68        elif self._direction == _DIRECTION_LEFT:
     69            self._color = XoColor(color.get_prev_fill_color())
     70        elif self._direction == _DIRECTION_RIGHT:
     71            self._color = XoColor(color.get_prev_stroke_color())
     72        elif self._direction == _DIRECTION_TOP:
     73            self._color = XoColor(color.get_next_fill_color())
     74        else:
     75            self._color = XoColor(color.get_next_stroke_color())
     76        self.icon.props.xo_color = self._color
    15577
    156     def __pressed_cb(self, button, event, me):
    157         me.set_next_colors()
     78    def __pressed_cb(self, button, event, direction):
     79        if direction != _DIRECTION_CENTER:
     80            self.emit('color-changed', self._color)
    15881
    15982class AboutMe(SectionView):
    16083    def __init__(self, model, alerts):
    16184        SectionView.__init__(self)
    16285
    16386        self._model = model
    164         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())
    16887        self.restart_alerts = alerts
    16988        self._nick_sid = 0
    17089        self._color_valid = True
    17190        self._nick_valid = True
    172         self._color_change_handler = None
    173         self._nick_change_handler = None
     91        self._handlers = []
    17492
    17593        self.set_border_width(style.DEFAULT_SPACING * 2)
    17694        self.set_spacing(style.DEFAULT_SPACING)
    17795        self._group = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL)
    17896
    179         self._nick_box = gtk.HBox(spacing=style.DEFAULT_SPACING)
    180         self._nick_alert_box = gtk.HBox(spacing=style.DEFAULT_SPACING)
    181         self._nick_entry = None
    182         self._nick_alert = None
    183         self._setup_nick()
    184 
     97        self._color_label = gtk.HBox(spacing=style.DEFAULT_SPACING)
    18598        self._color_box = gtk.HBox(spacing=style.DEFAULT_SPACING)
    18699        self._color_alert_box = gtk.HBox(spacing=style.DEFAULT_SPACING)
    187         self._color_picker = None
    188100        self._color_alert = None
    189         self._setup_color()       
    190101
     102        self._pickers = {
     103                _DIRECTION_CENTER: ColorPicker(_DIRECTION_CENTER),
     104                _DIRECTION_LEFT: ColorPicker(_DIRECTION_LEFT),
     105                _DIRECTION_RIGHT: ColorPicker(_DIRECTION_RIGHT),
     106                _DIRECTION_TOP: ColorPicker(_DIRECTION_TOP),
     107                _DIRECTION_BOTTOM: ColorPicker(_DIRECTION_BOTTOM)}
     108
     109        self._setup_color()
     110        initial_color = XoColor(self._model.get_color_xo())
     111        self._update_pickers(initial_color)
     112
     113        self._nick_box = gtk.HBox(spacing=style.DEFAULT_SPACING)
     114        self._nick_alert_box = gtk.HBox(spacing=style.DEFAULT_SPACING)
     115        self._nick_entry = None
     116        self._nick_alert = None
     117        self._setup_nick()
    191118        self.setup()
    192119
    193120    def _setup_nick(self):
    194         label_entry = gtk.Label(_('Name:'))
    195         label_entry.modify_fg(gtk.STATE_NORMAL,
    196                               style.COLOR_SELECTION_GREY.get_gdk_color())
    197         self._group.add_widget(label_entry)
    198         label_entry.set_alignment(1, 0.5)
    199         self._nick_box.pack_start(label_entry, expand=False)
    200         label_entry.show()
    201 
    202121        self._nick_entry = gtk.Entry()               
    203122        self._nick_entry.modify_bg(gtk.STATE_INSENSITIVE,
    204123                                   style.COLOR_WHITE.get_gdk_color())
    class AboutMe(SectionView): 
    219138            self._nick_alert.props.msg = self.restart_msg
    220139            self._nick_alert.show()
    221140
    222         self.pack_start(self._nick_box, False)
     141        self._center_in_panel = gtk.Alignment(0.5)
     142        self._center_in_panel.add(self._nick_box)
     143        self.pack_start(self._center_in_panel, False)
    223144        self.pack_start(self._nick_alert_box, False)
    224145        self._nick_box.show()
    225146        self._nick_alert_box.show()
     147        self._center_in_panel.show()
    226148   
    227149    def _setup_color(self):               
    228150        label_color = gtk.Label(_('Click to change your color:'))
    229151        label_color.modify_fg(gtk.STATE_NORMAL,
    230152                              style.COLOR_SELECTION_GREY.get_gdk_color())
    231153        self._group.add_widget(label_color)
    232         self._color_box.pack_start(label_color, expand=False)
     154        self._color_label.pack_start(label_color, expand=False)
    233155        label_color.show()
    234156
    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()
    238        
    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         """
     157        for direction in sorted(self._pickers.keys()):
     158            picker = self._pickers[direction]
     159            picker.show()
     160            self._color_box.pack_start(picker, expand=False)
    264161
    265162        label_color_error = gtk.Label()
    266163        self._group.add_widget(label_color_error)
    class AboutMe(SectionView): 
    273170            self._color_alert.props.msg = self.restart_msg
    274171            self._color_alert.show()
    275172
    276         self.pack_start(self._color_box, False)
     173        self._center_in_panel = gtk.Alignment(0.5)
     174        self._center_in_panel.add(self._color_box)
     175        self.pack_start(self._color_label, False)
     176        self.pack_start(self._center_in_panel, False)
    277177        self.pack_start(self._color_alert_box, False)       
     178        self._color_label.show()
    278179        self._color_box.show()
    279180        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())
     181        self._center_in_panel.show()
    341182   
    342183    def setup(self):
    343184        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 
    349185        self._color_valid = True
    350186        self._nick_valid = True
    351187        self.needs_restart = False
    352         self._nick_change_handler = self._nick_entry.connect( \
    353                 'changed', self.__nick_changed_cb)
    354         self._color_change_handler = self._color_picker.connect( \
    355                 'color-changed', self.__color_changed_cb)
     188
     189        def connect(widget, signal, cb):
     190            self._handlers.append((widget, widget.connect(signal, cb)))
     191
     192        connect(self._nick_entry, 'changed', self.__nick_changed_cb)
     193        for picker in self._pickers.values():
     194            connect(picker, 'color-changed', self.__color_changed_cb)
    356195
    357196    def undo(self):
    358         self._color_picker.disconnect(self._color_change_handler)
    359         self._nick_entry.disconnect(self._nick_change_handler)
     197        for widget, handler in self._handlers:
     198            widget.disconnect(handler)
    360199        self._model.undo()
    361200        self._nick_alert.hide()
    362201        self._color_alert.hide()       
    363202
     203    def _update_pickers(self, color):
     204        for picker in self._pickers.values():
     205            picker.update(color)
     206
    364207    def _validate(self):
    365208        if self._nick_valid and self._color_valid:
    366209            self.props.is_valid = True
    class AboutMe(SectionView): 
    392235        self._nick_alert.show()
    393236        return False
    394237
    395     def __color_changed_cb(self, colorpicker, xocolor):       
    396         self._model.set_color_xo(xocolor)
     238    def __color_changed_cb(self, colorpicker, color):
     239        self._model.set_color_xo(color.to_string())
    397240        self.needs_restart = True
    398241        self._color_alert.props.msg = self.restart_msg
    399242        self._color_valid = True
    class AboutMe(SectionView): 
    401244
    402245        self._validate()
    403246        self._color_alert.show()
     247
     248        self._update_pickers(color)
     249
    404250        return False