Ticket #1592: new-view.patch
File new-view.patch, 16.9 KB (added by walter, 14 years ago) |
---|
-
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 _ 20 20 21 21 from sugar.graphics.icon import Icon 22 22 from sugar.graphics import style 23 from sugar.graphics.toolbutton import ToolButton24 23 from sugar.graphics.xocolor import XoColor 25 24 26 25 from jarabe.controlpanel.sectionview import SectionView 27 26 from jarabe.controlpanel.inlinealert import InlineAlert 28 27 28 _DIRECTION_LEFT = 0 29 _DIRECTION_TOP = 1 30 _DIRECTION_CENTER = 2 31 _DIRECTION_BOTTOM = 3 32 _DIRECTION_RIGHT = 4 29 33 30 34 class EventIcon(gtk.EventBox): 31 35 __gtype_name__ = "SugarEventIcon" … … class EventIcon(gtk.EventBox): 40 44 41 45 self.add(self.icon) 42 46 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 55 48 class ColorPicker(EventIcon): 56 49 __gsignals__ = { 57 50 'color-changed': (gobject.SIGNAL_RUN_FIRST, 58 51 gobject.TYPE_NONE, 59 ([ str]))52 ([object])) 60 53 } 61 def __init__(self, me, xo_color=None):54 def __init__(self, direction): 62 55 EventIcon.__init__(self) 63 self.icon.props.xo_color = xo_color64 self.icon.props.icon_name = 'computer-xo'65 self.icon.props.pixel_size = style.XLARGE_ICON_SIZE66 self.connect('button_press_event', self.__pressed_cb, me)67 68 def __pressed_cb(self, button, event, me):69 me.set_random_colors()70 56 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_color80 57 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 86 60 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 140 62 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 = xocolor153 self.icon.props.pixel_size = style.STANDARD_ICON_SIZE154 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 155 77 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) 158 81 159 82 class AboutMe(SectionView): 160 83 def __init__(self, model, alerts): 161 84 SectionView.__init__(self) 162 85 163 86 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())168 87 self.restart_alerts = alerts 169 88 self._nick_sid = 0 170 89 self._color_valid = True 171 90 self._nick_valid = True 172 self._color_change_handler = None 173 self._nick_change_handler = None 91 self._handlers = [] 174 92 175 93 self.set_border_width(style.DEFAULT_SPACING * 2) 176 94 self.set_spacing(style.DEFAULT_SPACING) 177 95 self._group = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL) 178 96 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) 185 98 self._color_box = gtk.HBox(spacing=style.DEFAULT_SPACING) 186 99 self._color_alert_box = gtk.HBox(spacing=style.DEFAULT_SPACING) 187 self._color_picker = None188 100 self._color_alert = None 189 self._setup_color()190 101 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() 191 118 self.setup() 192 119 193 120 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 202 121 self._nick_entry = gtk.Entry() 203 122 self._nick_entry.modify_bg(gtk.STATE_INSENSITIVE, 204 123 style.COLOR_WHITE.get_gdk_color()) … … class AboutMe(SectionView): 219 138 self._nick_alert.props.msg = self.restart_msg 220 139 self._nick_alert.show() 221 140 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) 223 144 self.pack_start(self._nick_alert_box, False) 224 145 self._nick_box.show() 225 146 self._nick_alert_box.show() 147 self._center_in_panel.show() 226 148 227 149 def _setup_color(self): 228 150 label_color = gtk.Label(_('Click to change your color:')) 229 151 label_color.modify_fg(gtk.STATE_NORMAL, 230 152 style.COLOR_SELECTION_GREY.get_gdk_color()) 231 153 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) 233 155 label_color.show() 234 156 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) 264 161 265 162 label_color_error = gtk.Label() 266 163 self._group.add_widget(label_color_error) … … class AboutMe(SectionView): 273 170 self._color_alert.props.msg = self.restart_msg 274 171 self._color_alert.show() 275 172 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) 277 177 self.pack_start(self._color_alert_box, False) 178 self._color_label.show() 278 179 self._color_box.show() 279 180 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() 341 182 342 183 def setup(self): 343 184 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_color346 self._color_next.icon.props.xo_color = self._xo_next_color347 self._color_prev.icon.props.xo_color = self._xo_prev_color348 349 185 self._color_valid = True 350 186 self._nick_valid = True 351 187 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) 356 195 357 196 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) 360 199 self._model.undo() 361 200 self._nick_alert.hide() 362 201 self._color_alert.hide() 363 202 203 def _update_pickers(self, color): 204 for picker in self._pickers.values(): 205 picker.update(color) 206 364 207 def _validate(self): 365 208 if self._nick_valid and self._color_valid: 366 209 self.props.is_valid = True … … class AboutMe(SectionView): 392 235 self._nick_alert.show() 393 236 return False 394 237 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()) 397 240 self.needs_restart = True 398 241 self._color_alert.props.msg = self.restart_msg 399 242 self._color_valid = True … … class AboutMe(SectionView): 401 244 402 245 self._validate() 403 246 self._color_alert.show() 247 248 self._update_pickers(color) 249 404 250 return False