diff --git a/extensions/cpsection/aboutme/view.py b/extensions/cpsection/aboutme/view.py
index cabd66a..5e429d2 100644
a
|
b
|
from sugar.graphics.xocolor import XoColor |
25 | 25 | from jarabe.controlpanel.sectionview import SectionView |
26 | 26 | from jarabe.controlpanel.inlinealert import InlineAlert |
27 | 27 | |
| 28 | _DIRECTION_LEFT = 0 |
| 29 | _DIRECTION_TOP = 1 |
| 30 | _DIRECTION_CENTER = 2 |
| 31 | _DIRECTION_BOTTOM = 3 |
| 32 | _DIRECTION_RIGHT = 4 |
| 33 | |
28 | 34 | class EventIcon(gtk.EventBox): |
29 | 35 | __gtype_name__ = "SugarEventIcon" |
30 | 36 | def __init__(self, **kwargs): |
… |
… |
class ColorPicker(EventIcon): |
43 | 49 | __gsignals__ = { |
44 | 50 | 'color-changed': (gobject.SIGNAL_RUN_FIRST, |
45 | 51 | gobject.TYPE_NONE, |
46 | | ([str])) |
| 52 | ([object])) |
47 | 53 | } |
48 | | def __init__(self, xocolor=None): |
| 54 | def __init__(self, direction): |
49 | 55 | EventIcon.__init__(self) |
50 | | self.icon.props.xo_color = xocolor |
| 56 | |
51 | 57 | self.icon.props.icon_name = 'computer-xo' |
| 58 | self._direction = direction |
| 59 | self._color = None |
| 60 | |
52 | 61 | self.icon.props.pixel_size = style.XLARGE_ICON_SIZE |
53 | | self.connect('button_press_event', self.__pressed_cb) |
54 | 62 | |
55 | | def __pressed_cb(self, button, event): |
56 | | self._set_random_colors() |
| 63 | self.connect('button_press_event', self.__pressed_cb, direction) |
57 | 64 | |
58 | | def _set_random_colors(self): |
59 | | xocolor = XoColor() |
60 | | self.icon.props.xo_color = xocolor |
61 | | self.emit('color-changed', xocolor.to_string()) |
| 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 |
| 77 | |
| 78 | def __pressed_cb(self, button, event, direction): |
| 79 | if direction != _DIRECTION_CENTER: |
| 80 | self.emit('color-changed', self._color) |
62 | 81 | |
63 | 82 | class AboutMe(SectionView): |
64 | 83 | def __init__(self, model, alerts): |
… |
… |
class AboutMe(SectionView): |
69 | 88 | self._nick_sid = 0 |
70 | 89 | self._color_valid = True |
71 | 90 | self._nick_valid = True |
72 | | self._color_change_handler = None |
73 | | self._nick_change_handler = None |
| 91 | self._handlers = [] |
74 | 92 | |
75 | 93 | self.set_border_width(style.DEFAULT_SPACING * 2) |
76 | 94 | self.set_spacing(style.DEFAULT_SPACING) |
77 | 95 | self._group = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL) |
78 | 96 | |
79 | | self._nick_box = gtk.HBox(spacing=style.DEFAULT_SPACING) |
80 | | self._nick_alert_box = gtk.HBox(spacing=style.DEFAULT_SPACING) |
81 | | self._nick_entry = None |
82 | | self._nick_alert = None |
83 | | self._setup_nick() |
84 | | |
| 97 | self._color_label = gtk.HBox(spacing=style.DEFAULT_SPACING) |
85 | 98 | self._color_box = gtk.HBox(spacing=style.DEFAULT_SPACING) |
86 | 99 | self._color_alert_box = gtk.HBox(spacing=style.DEFAULT_SPACING) |
87 | | self._color_picker = None |
88 | 100 | self._color_alert = None |
89 | | self._setup_color() |
90 | 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() |
91 | 118 | self.setup() |
92 | 119 | |
93 | 120 | def _setup_nick(self): |
94 | | label_entry = gtk.Label(_('Name:')) |
95 | | label_entry.modify_fg(gtk.STATE_NORMAL, |
96 | | style.COLOR_SELECTION_GREY.get_gdk_color()) |
97 | | self._group.add_widget(label_entry) |
98 | | label_entry.set_alignment(1, 0.5) |
99 | | self._nick_box.pack_start(label_entry, expand=False) |
100 | | label_entry.show() |
101 | | |
102 | 121 | self._nick_entry = gtk.Entry() |
103 | 122 | self._nick_entry.modify_bg(gtk.STATE_INSENSITIVE, |
104 | 123 | style.COLOR_WHITE.get_gdk_color()) |
… |
… |
class AboutMe(SectionView): |
119 | 138 | self._nick_alert.props.msg = self.restart_msg |
120 | 139 | self._nick_alert.show() |
121 | 140 | |
122 | | 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) |
123 | 144 | self.pack_start(self._nick_alert_box, False) |
124 | 145 | self._nick_box.show() |
125 | 146 | self._nick_alert_box.show() |
| 147 | self._center_in_panel.show() |
126 | 148 | |
127 | 149 | def _setup_color(self): |
128 | 150 | label_color = gtk.Label(_('Click to change your color:')) |
129 | 151 | label_color.modify_fg(gtk.STATE_NORMAL, |
130 | 152 | style.COLOR_SELECTION_GREY.get_gdk_color()) |
131 | 153 | self._group.add_widget(label_color) |
132 | | self._color_box.pack_start(label_color, expand=False) |
| 154 | self._color_label.pack_start(label_color, expand=False) |
133 | 155 | label_color.show() |
134 | | |
135 | | self._color_picker = ColorPicker() |
136 | | self._color_box.pack_start(self._color_picker, expand=False) |
137 | | self._color_picker.show() |
| 156 | |
| 157 | for direction in sorted(self._pickers.keys()): |
| 158 | if direction == _DIRECTION_CENTER: |
| 159 | left_separator = gtk.SeparatorToolItem() |
| 160 | left_separator.show() |
| 161 | self._color_box.pack_start(left_separator, expand=False) |
| 162 | |
| 163 | picker = self._pickers[direction] |
| 164 | picker.show() |
| 165 | self._color_box.pack_start(picker, expand=False) |
| 166 | |
| 167 | if direction == _DIRECTION_CENTER: |
| 168 | right_separator = gtk.SeparatorToolItem() |
| 169 | right_separator.show() |
| 170 | self._color_box.pack_start(right_separator, expand=False) |
138 | 171 | |
139 | 172 | label_color_error = gtk.Label() |
140 | 173 | self._group.add_widget(label_color_error) |
… |
… |
class AboutMe(SectionView): |
147 | 180 | self._color_alert.props.msg = self.restart_msg |
148 | 181 | self._color_alert.show() |
149 | 182 | |
150 | | self.pack_start(self._color_box, False) |
| 183 | self._center_in_panel = gtk.Alignment(0.5) |
| 184 | self._center_in_panel.add(self._color_box) |
| 185 | self.pack_start(self._color_label, False) |
| 186 | self.pack_start(self._center_in_panel, False) |
151 | 187 | self.pack_start(self._color_alert_box, False) |
| 188 | self._color_label.show() |
152 | 189 | self._color_box.show() |
153 | 190 | self._color_alert_box.show() |
| 191 | self._center_in_panel.show() |
154 | 192 | |
155 | 193 | def setup(self): |
156 | 194 | self._nick_entry.set_text(self._model.get_nick()) |
157 | | color = XoColor(self._model.get_color_xo()) |
158 | | self._color_picker.icon.props.xo_color = color |
159 | | |
160 | 195 | self._color_valid = True |
161 | 196 | self._nick_valid = True |
162 | 197 | self.needs_restart = False |
163 | | self._nick_change_handler = self._nick_entry.connect( \ |
164 | | 'changed', self.__nick_changed_cb) |
165 | | self._color_change_handler = self._color_picker.connect( \ |
166 | | 'color-changed', self.__color_changed_cb) |
| 198 | |
| 199 | def connect(widget, signal, cb): |
| 200 | self._handlers.append((widget, widget.connect(signal, cb))) |
| 201 | |
| 202 | connect(self._nick_entry, 'changed', self.__nick_changed_cb) |
| 203 | for picker in self._pickers.values(): |
| 204 | connect(picker, 'color-changed', self.__color_changed_cb) |
167 | 205 | |
168 | 206 | def undo(self): |
169 | | self._color_picker.disconnect(self._color_change_handler) |
170 | | self._nick_entry.disconnect(self._nick_change_handler) |
| 207 | for widget, handler in self._handlers: |
| 208 | widget.disconnect(handler) |
171 | 209 | self._model.undo() |
172 | 210 | self._nick_alert.hide() |
173 | 211 | self._color_alert.hide() |
174 | 212 | |
| 213 | def _update_pickers(self, color): |
| 214 | for picker in self._pickers.values(): |
| 215 | picker.update(color) |
| 216 | |
175 | 217 | def _validate(self): |
176 | 218 | if self._nick_valid and self._color_valid: |
177 | 219 | self.props.is_valid = True |
… |
… |
class AboutMe(SectionView): |
203 | 245 | self._nick_alert.show() |
204 | 246 | return False |
205 | 247 | |
206 | | def __color_changed_cb(self, colorpicker, xocolor): |
207 | | self._model.set_color_xo(xocolor) |
| 248 | def __color_changed_cb(self, colorpicker, color): |
| 249 | self._model.set_color_xo(color.to_string()) |
208 | 250 | self.needs_restart = True |
209 | 251 | self._color_alert.props.msg = self.restart_msg |
210 | 252 | self._color_valid = True |
… |
… |
class AboutMe(SectionView): |
212 | 254 | |
213 | 255 | self._validate() |
214 | 256 | self._color_alert.show() |
| 257 | |
| 258 | self._update_pickers(color) |
| 259 | |
215 | 260 | return False |