It’s possible, but not encouraged.
Take the following, for example - it demonstrates the parsing of an
additional theme file, local modification of settings that are otherwise
shared and overriding the drawing of a particular widget.
–8<—
#!/usr/bin/ruby
vanilla = fork()
require ‘gtk2’
window = Gtk::Window.new
window.set_border_width(16)
window.add(button = Gtk::Button.new(“Text”))
button.children[0].set_padding(16,16)
unless vanilla
Parse custom gtkrc
Gtk::RC.parse_string <<-RC
style “displace”
{
GtkButton::child_displacement_y = 8
GtkButton::child_displacement_x = 8
}
class “GtkButton” style “displace”
RC
Modify local gtk settings, ie. theme
Gtk::Settings.default.gtk_theme_name = “HighContrastInverse”
Paint the button using cairo instead of theme
button.set_app_paintable(true)
button.signal_connect(‘expose-event’) do |widget,e|
cr = widget.window.create_cairo_context
xmod, ymod = widget.style_get_property(‘child-displacement-x’),
widget.style_get_property(‘child-displacement-y’)
allocation = widget.allocation
if widget.state == Gtk::STATE_ACTIVE
x, y, w, h = allocation.x + 2xmod, allocation.y + 2ymod,
allocation.width - 2xmod, allocation.height - 2ymod
else
x, y, w, h = allocation.x + xmod, allocation.y + xmod,
allocation.width - 2xmod, allocation.height - 2xmod
cr.save do
cr.translate(xmod, ymod)
cr.rounded_rectangle(x, y, w, h, 16)
cr.set_source_rgba(0.6,0.2,0.2,0.8)
cr.fill
end
end
cr.rounded_rectangle(x, y, w, h, 16)
cr.set_source_rgba(0.5,0.5,0.5,0.8)
cr.fill
Propagate expose event to child widgets
widget.children.each { |child| widget.propagate_expose(child, e) }
Block default expose-event handler
true
end
end
window.show_all
Gtk.main
–8<–