From 2afa5398a281b5d3b52020445ee8629c0ce5f5c3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= <manuq@laptop.org>
Date: Wed, 31 Oct 2012 13:18:46 -0300
Subject: [PATCH toolkit-gtk3] Set correct background for subtoolbars - SL
#3987
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Mail-Followup-To: <sugar-devel@lists.sugarlabs.org>
- remove set_app_paintable from _SubtoolbarContainer (previously _Box)
to fix the bad coloring of subtoolbars. The documentation say we
can't rely on it to paint the themed background when this is set
[1].
- remove all calls to modify_bg from the code. Do all the styling in
the theme. Needs the artwork patch accompanied in the ticket. Note
the code removal in _setup_page function, which was iterating the
toolbar children to modify their background.
- add new class _ToolbarContainer with a __gtype_name__ to style it.
Primary toolbar is embedded in it.
- rename _Box class for _SubtoolbarContainer, make it inherit
_ToolbarContainer. Subtoolbars are embedded in these.
- call show() in the proper order, after widgets are packed. See
changes in _embed_page function.
- call the parent class __init__ insted of GObject.GObject.
- long lines fixed.
[1] http://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-set-app-paintable
Signed-off-by: Manuel Quiñones <manuq@laptop.org>
---
src/sugar3/graphics/toolbarbox.py | 76 +++++++++++++++------------------------
1 file changed, 29 insertions(+), 47 deletions(-)
diff --git a/src/sugar3/graphics/toolbarbox.py b/src/sugar3/graphics/toolbarbox.py
index ee709dd..d5b3a63 100644
a
|
b
|
class ToolbarButton(ToolButton): |
66 | 66 | if page is None: |
67 | 67 | self.page_widget = None |
68 | 68 | return |
69 | | self.page_widget, alignment_ = _embed_page(_Box(self), page) |
| 69 | self.page_widget, alignment_ = _embed_page(_SubToolbarContainer(self), |
| 70 | page) |
70 | 71 | self.page_widget.set_size_request(-1, style.GRID_CELL_SIZE) |
71 | | page.show() |
| 72 | self.page_widget.show() |
72 | 73 | if self.props.palette is None: |
73 | 74 | self.props.palette = _ToolbarPalette(invoker=ToolInvoker(self)) |
74 | 75 | self._move_page_to_palette() |
… |
… |
class ToolbarButton(ToolButton): |
97 | 98 | self._move_page_to_palette() |
98 | 99 | return |
99 | 100 | |
100 | | box = self.toolbar_box |
101 | | |
102 | | if box.expanded_button is not None: |
103 | | box.expanded_button.queue_draw() |
104 | | box.expanded_button.set_expanded(False) |
105 | | box.expanded_button = self |
| 101 | if self.toolbar_box.expanded_button is not None: |
| 102 | self.toolbar_box.expanded_button.queue_draw() |
| 103 | self.toolbar_box.expanded_button.set_expanded(False) |
| 104 | self.toolbar_box.expanded_button = self |
106 | 105 | |
107 | 106 | self._unparent() |
108 | 107 | |
109 | | self.modify_bg(Gtk.StateType.NORMAL, box.background) |
110 | | _setup_page(self.page_widget, box.background, box.props.padding) |
111 | | box.pack_start(self.page_widget, True, True, 0) |
| 108 | _setup_page(self.page_widget, self.toolbar_box.props.padding) |
| 109 | self.toolbar_box.pack_start(self.page_widget, True, True, 0) |
112 | 110 | |
113 | 111 | def _move_page_to_palette(self): |
114 | 112 | if self.is_in_palette(): |
… |
… |
class ToolbarButton(ToolButton): |
143 | 141 | class ToolbarBox(Gtk.VBox): |
144 | 142 | |
145 | 143 | def __init__(self, padding=style.TOOLBOX_HORIZONTAL_PADDING): |
146 | | GObject.GObject.__init__(self) |
| 144 | Gtk.VBox.__init__(self) |
147 | 145 | self._expanded_button_index = -1 |
148 | | self.background = None |
149 | 146 | |
150 | 147 | self._toolbar = Gtk.Toolbar() |
151 | 148 | self._toolbar.owner = self |
152 | 149 | self._toolbar.connect('remove', self.__remove_cb) |
153 | 150 | |
154 | 151 | self._toolbar_widget, self._toolbar_alignment = \ |
155 | | _embed_page(Gtk.EventBox(), self._toolbar) |
| 152 | _embed_page(_ToolbarContainer(), self._toolbar) |
156 | 153 | self.pack_start(self._toolbar_widget, True, True, 0) |
| 154 | self._toolbar_widget.show() |
157 | 155 | |
158 | 156 | self.props.padding = padding |
159 | | self.modify_bg(Gtk.StateType.NORMAL, |
160 | | style.COLOR_TOOLBAR_GREY.get_gdk_color()) |
161 | 157 | |
162 | 158 | def get_toolbar(self): |
163 | 159 | return self._toolbar |
… |
… |
class ToolbarBox(Gtk.VBox): |
186 | 182 | padding = GObject.property(type=object, |
187 | 183 | getter=get_padding, setter=set_padding) |
188 | 184 | |
189 | | def modify_bg(self, state, color): |
190 | | if state == Gtk.StateType.NORMAL: |
191 | | self.background = color |
192 | | self._toolbar_widget.modify_bg(state, color) |
193 | | self.toolbar.modify_bg(state, color) |
194 | | |
195 | 185 | def __remove_cb(self, sender, button): |
196 | 186 | if not isinstance(button, ToolbarButton): |
197 | 187 | return |
… |
… |
class _ToolbarPalette(PaletteWindow): |
255 | 245 | if button.is_expanded(): |
256 | 246 | return |
257 | 247 | box = button.toolbar_box |
258 | | _setup_page(button.page_widget, style.COLOR_BLACK.get_gdk_color(), |
259 | | box.props.padding) |
| 248 | _setup_page(button.page_widget, box.props.padding) |
260 | 249 | PaletteWindow.popup(self, immediate) |
261 | 250 | |
262 | 251 | def __group_popdown_cb(self, group): |
… |
… |
class _ToolbarPalette(PaletteWindow): |
264 | 253 | self.popdown(immediate=True) |
265 | 254 | |
266 | 255 | |
267 | | class _Box(Gtk.EventBox): |
| 256 | class _ToolbarContainer(Gtk.EventBox): |
| 257 | |
| 258 | __gtype_name__ = 'SugarToolbarContainer' |
| 259 | |
| 260 | def __init__(self): |
| 261 | Gtk.EventBox.__init__(self) |
| 262 | |
| 263 | |
| 264 | class _SubToolbarContainer(_ToolbarContainer): |
268 | 265 | |
269 | 266 | def __init__(self, toolbar_button): |
270 | | GObject.GObject.__init__(self) |
271 | | self.set_app_paintable(True) |
| 267 | _ToolbarContainer.__init__(self) |
272 | 268 | self._toolbar_button = toolbar_button |
273 | | self.modify_bg(Gtk.StateType.NORMAL, |
274 | | style.COLOR_TOOLBAR_GREY.get_gdk_color()) |
275 | 269 | |
276 | 270 | def do_draw(self, cr): |
277 | 271 | button_alloc = self._toolbar_button.get_allocation() |
… |
… |
class _Box(Gtk.EventBox): |
280 | 274 | cr.set_source_rgba(*style.COLOR_BUTTON_GREY.get_rgba()) |
281 | 275 | cr.move_to(0, 0) |
282 | 276 | cr.line_to(button_alloc.x + style.FOCUS_LINE_WIDTH, 0) |
283 | | cr.move_to(button_alloc.x + button_alloc.width - style.FOCUS_LINE_WIDTH, 0) |
| 277 | cr.move_to(button_alloc.x + button_alloc.width - style.FOCUS_LINE_WIDTH, |
| 278 | 0) |
284 | 279 | cr.line_to(self.get_allocation().width, 0) |
285 | 280 | cr.stroke() |
286 | 281 | |
287 | | Gtk.EventBox.do_draw(self, cr) |
| 282 | self.get_child().do_draw(self, cr) |
288 | 283 | |
289 | 284 | |
290 | | def _setup_page(page_widget, color, hpad): |
| 285 | def _setup_page(page_widget, hpad): |
291 | 286 | vpad = style.FOCUS_LINE_WIDTH |
292 | 287 | page_widget.get_child().set_padding(vpad, vpad, hpad, hpad) |
293 | 288 | |
294 | | page = _get_embedded_page(page_widget) |
295 | | page.modify_bg(Gtk.StateType.NORMAL, color) |
296 | | if isinstance(page, Gtk.Container): |
297 | | for i in page.get_children(): |
298 | | i.modify_bg(Gtk.StateType.INSENSITIVE, color) |
299 | | |
300 | | page_widget.modify_bg(Gtk.StateType.NORMAL, color) |
301 | | page_widget.modify_bg(Gtk.StateType.PRELIGHT, color) |
302 | | |
303 | 289 | |
304 | 290 | def _embed_page(page_widget, page): |
305 | | page.show() |
306 | | |
307 | 291 | alignment = Gtk.Alignment(xscale=1.0, yscale=1.0) |
308 | 292 | alignment.add(page) |
309 | | alignment.show() |
| 293 | page.show() |
310 | 294 | |
311 | | page_widget.modify_bg(Gtk.StateType.ACTIVE, |
312 | | style.COLOR_BUTTON_GREY.get_gdk_color()) |
313 | 295 | page_widget.add(alignment) |
314 | | page_widget.show() |
| 296 | alignment.show() |
315 | 297 | |
316 | 298 | return (page_widget, alignment) |
317 | 299 | |