GTK+ application specific skin possible?
I've started working with GTK+ and Vala and am having a hard time finding documentation on creating custom buttons (totally new looking buttons). In fact now that I think about it, every GTK+ app开发者_JAVA百科lication has that distinct look that gives away that it's a GTK+ app. Is it difficult to create a totally new look for my application if I decide to use GTK+?
It's made difficult on purpose, because "that distinct GTK look" is the whole point. GTK applications generally place a lot of value on usability, accessibility, and user experience. You, the application programmer, should concentrate on the content of your application, and let the user choose a theme they like. If you make custom buttons, then they might be too narrow to fit the translated labels for a user using your application in another language. Or maybe your custom buttons look really horrible on someone's preferred window background color.
RC code has been replaced in gtk+3. It now supports css for styling this may give you what you need.
http://developer.gnome.org/gtk3/3.1/gtk-migrating-GtkStyleContext.html
http://thegnomejournal.wordpress.com/2011/03/15/styling-gtk-with-css/
h te te p://kalmbach.wordpress.com/2011/03/12/gtk-3-0-client-side-theme/
You can use the GTK2_RC_FILES
environment variable to assign a special theme to (only) your application.
For example, you can create a batch starter (Windows) like so:
set GTK2_RC_FILES=%GTK_HOME%\share\themes\slickness-black\gtk-2.0\gtkrc
launch.exe
Or in Linux (haven't tried that one):
env GTK2_RC_FILES=/usr/share/themes/slickness-black/gtk-2.0/gtkrc ./launch
Hint: Don't trust in GTK_HOME to be set, rather use the absolute path of the GTK+ installation. If you install a special theme with your application, it might be possible to use a relative path (relative to the installation path of your app). Then you should make sure that the theme is supported by one of the most common theme engines because usually not all of them are installed (especially on Windows, where GTK installers are a mess).
@gtksharp:
string fileName = @"/usr/valapp/gtkrc3";
Gtk.Rc.AddDefaultFile(fileName);
Gtk.Rc.Parse(fileName);
精彩评论