Hi guys, I'd like to consult with you about the following: is it possible to customize design of GTK+ apps? I mean they use system theme's settings by default(the same width, color, transparency etc.), but I'd like my application to look as I want. I've almost created my mp3 player, but it's look kills me. What should I do to use my own design features? Best, Roman.
on 2010-07-01 14:30
on 2010-07-01 18:42
yeah, you can't change the theme of a gtk app without changing the whole system theme. On Thu, Jul 1, 2010 at 1:49 PM, niklas | brueckenschlaeger <
on 2010-07-01 20:03
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 + 2*xmod, allocation.y + 2*ymod,
allocation.width - 2*xmod, allocation.height - 2*ymod
else
x, y, w, h = allocation.x + xmod, allocation.y + xmod,
allocation.width - 2*xmod, allocation.height - 2*xmod
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<--
on 2010-07-01 23:03
On Thu, 2010-07-01 at 14:30 +0200, Roman Tolmachev wrote: > Hi guys, I'd like to consult with you about the following: > is it possible to customize design of GTK+ apps? I mean they use system > theme's settings by default(the same width, color, transparency etc.), > but I'd like my application to look as I want. I've almost created my > mp3 player, but it's look kills me. What should I do to use my own > design features? When you need to step outside the standard set of GTK user interface elements, one approach is to use a canvas widget. The GNOME canvas is certainly one option and I think the Ruby bindings should work. Be warned that the GNOME canvas has been deprecated upstream but as yet no clear replacement has emerged. Recently I've been doing some work with the Clutter canvas which is very good. I have no idea about the availability of Ruby bindings for Clutter though as I've mostly been working with Perl. Cheers Grant
on 2010-07-01 23:08
It is not that wery hard to write your own widgets. If you want VERY fancy widgets you can also use Cairo. Take a look at http://www.raditex.nu//websvn/listing.php?repname=kurssrc.Exempel&path=%2FCairoCandy%2F#_CairoCandy_ Gorhas 2010/7/1 Grant McLean <grant@mclean.net.nz>
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.