Fix the drawing of ColorToolButton, RadioToolButton and ToggleToolButton
Draw a black background in the buttons when the palette is up, as
commit 01a06943 did with the ToolButton. As the comment for that
commit states, we can change the prelight background color in the
theme, but not when the mouse moves over the Palette.
Also add testcase to test the three toolbuttons.
Signed-off-by: Manuel Quiñones <manuq@laptop.org>
Acked-by: Simon Schampijer <simon@laptop.org>
This commit is contained in:
@@ -523,20 +523,20 @@ class ColorToolButton(Gtk.ToolItem):
|
||||
|
||||
title = GObject.property(type=str, getter=get_title, setter=set_title)
|
||||
|
||||
def do_expose_event(self, event):
|
||||
def do_draw(self, cr):
|
||||
child = self.get_child()
|
||||
allocation = self.get_allocation()
|
||||
if self._palette and self._palette.is_up():
|
||||
invoker = self._palette.props.invoker
|
||||
invoker.draw_rectangle(event, self._palette)
|
||||
elif child.state == Gtk.StateType.PRELIGHT:
|
||||
child.style.paint_box(event.window, Gtk.StateType.PRELIGHT,
|
||||
Gtk.ShadowType.NONE, event.area,
|
||||
child, 'toolbutton-prelight',
|
||||
allocation.x, allocation.y,
|
||||
allocation.width, allocation.height)
|
||||
invoker.draw_rectangle(cr, self._palette)
|
||||
|
||||
Gtk.ToolButton.do_expose_event(self, event)
|
||||
allocation = self.get_allocation()
|
||||
# draw a black background, has been done by the engine before
|
||||
cr.set_source_rgb(0, 0, 0)
|
||||
cr.rectangle(0, 0, allocation.width, allocation.height)
|
||||
cr.paint()
|
||||
|
||||
Gtk.ToolButton.do_draw(self, cr)
|
||||
|
||||
def __notify_change(self, widget, pspec):
|
||||
self.notify(pspec.name)
|
||||
|
||||
@@ -165,18 +165,18 @@ class RadioToolButton(Gtk.RadioToolButton):
|
||||
palette_invoker = GObject.property(
|
||||
type=object, setter=set_palette_invoker, getter=get_palette_invoker)
|
||||
|
||||
def do_expose_event(self, event):
|
||||
def do_draw(self, cr):
|
||||
child = self.get_child()
|
||||
allocation = self.get_allocation()
|
||||
|
||||
if self.palette and self.palette.is_up():
|
||||
invoker = self.palette.props.invoker
|
||||
invoker.draw_rectangle(event, self.palette)
|
||||
elif child.state == Gtk.StateType.PRELIGHT:
|
||||
child.style.paint_box(event.window, Gtk.StateType.PRELIGHT,
|
||||
Gtk.ShadowType.NONE, event.area,
|
||||
child, 'toolbutton-prelight',
|
||||
allocation.x, allocation.y,
|
||||
allocation.width, allocation.height)
|
||||
invoker.draw_rectangle(cr, self.palette)
|
||||
|
||||
Gtk.RadioToolButton.do_expose_event(self, event)
|
||||
allocation = self.get_allocation()
|
||||
# draw a black background, has been done by the engine before
|
||||
cr.set_source_rgb(0, 0, 0)
|
||||
cr.rectangle(0, 0, allocation.width, allocation.height)
|
||||
cr.paint()
|
||||
|
||||
Gtk.RadioToolButton.do_draw(self, cr)
|
||||
|
||||
@@ -113,20 +113,20 @@ class ToggleToolButton(Gtk.ToggleToolButton):
|
||||
accelerator = GObject.property(type=str, setter=set_accelerator,
|
||||
getter=get_accelerator)
|
||||
|
||||
def do_expose_event(self, event):
|
||||
def do_draw(self, cr):
|
||||
allocation = self.get_allocation()
|
||||
child = self.get_child()
|
||||
|
||||
if self.palette and self.palette.is_up():
|
||||
invoker = self.palette.props.invoker
|
||||
invoker.draw_rectangle(event, self.palette)
|
||||
elif child.state == Gtk.StateType.PRELIGHT:
|
||||
child.style.paint_box(event.window, Gtk.StateType.PRELIGHT,
|
||||
Gtk.ShadowType.NONE, event.area,
|
||||
child, 'toolbutton-prelight',
|
||||
allocation.x, allocation.y,
|
||||
allocation.width, allocation.height)
|
||||
invoker.draw_rectangle(cr, self.palette)
|
||||
|
||||
Gtk.ToggleToolButton.do_expose_event(self, event)
|
||||
allocation = self.get_allocation()
|
||||
# draw a black background, has been done by the engine before
|
||||
cr.set_source_rgb(0, 0, 0)
|
||||
cr.rectangle(0, 0, allocation.width, allocation.height)
|
||||
cr.paint()
|
||||
|
||||
Gtk.ToggleToolButton.do_draw(self, cr)
|
||||
|
||||
palette = property(get_palette, set_palette)
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
from gi.repository import Gtk
|
||||
|
||||
from sugar3.graphics.toolbarbox import ToolbarBox
|
||||
from sugar3.graphics.colorbutton import ColorToolButton
|
||||
from sugar3.graphics.radiotoolbutton import RadioToolButton
|
||||
from sugar3.graphics.toggletoolbutton import ToggleToolButton
|
||||
|
||||
import common
|
||||
|
||||
|
||||
test = common.Test()
|
||||
test.show()
|
||||
|
||||
vbox = Gtk.VBox()
|
||||
test.pack_start(vbox, True, True, 0)
|
||||
vbox.show()
|
||||
|
||||
toolbar_box = ToolbarBox()
|
||||
vbox.pack_start(toolbar_box, False, False, 0)
|
||||
toolbar_box.show()
|
||||
|
||||
radial_button = RadioToolButton(named_icon='view-radial')
|
||||
toolbar_box.toolbar.insert(radial_button, -1)
|
||||
radial_button.show()
|
||||
|
||||
list_button = RadioToolButton(named_icon='view-list')
|
||||
list_button.props.group = radial_button
|
||||
toolbar_box.toolbar.insert(list_button, -1)
|
||||
list_button.show()
|
||||
|
||||
separator = Gtk.SeparatorToolItem()
|
||||
toolbar_box.toolbar.insert(separator, -1)
|
||||
separator.show()
|
||||
|
||||
color_button = ColorToolButton()
|
||||
toolbar_box.toolbar.insert(color_button, -1)
|
||||
color_button.show()
|
||||
|
||||
favorite_button = ToggleToolButton('emblem-favorite')
|
||||
toolbar_box.toolbar.insert(favorite_button, -1)
|
||||
favorite_button.show()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
common.main(test)
|
||||
Reference in New Issue
Block a user