GTK+ Theme Changing in Gazpacho ============================================================================== Introduction ------------------------------------------------------------------------------ The Hildon widgets looks and behave a little bit weird in a plain GTK+ environment so in the Maemo platform a custom GTK+ Theme is provided to add some branding and make a difference when running in the Maemo devices. On the other side Gazpacho GUI is designed to work using standard GTK+ themes and when running using the Maemo GTK+ theme it looks and behaves wrong. Goal ------------------------------------------------------------------------------ * To run Gazpacho using two different GTK+ themes: one for the Gazpacho GUI and one for the widgets used in Hildon projects where a Hildon project is a Gazpacho project that uses Hildon widgets. Usually theses two themes would be the standard GTK+ one for Gazpacho GUI and the Maemo Seapwood theme for the Hildon projects. GTK+ support for changing the theme ------------------------------------------------------------------------------ Right now GTK+ has support for loading a different set of GtkRC files and use them instead of the boring system default. You usually do that with the following (Python) APIs: gtk.rc_set_default_files([rc_filename]) gtk.rc_reparse_all_for_settings(yourwidget.get_settings(), True) The problem ------------------------------------------------------------------------------ The problem is that when you change the rc files and reparse them you are changing the theme for *all* your widgets in the application. There is no way to programatically do this only for a specific set of widgets. One of the reasons for this is that all the widgets in a GdkScreen share the same GtkSettings. The solutions ------------------------------------------------------------------------------ Solution A: Fix GTK+ It seems that the mechanism to set a rc file per widget is already there in GTK+ but it is private/internal and it is not exported as a public API. When you call gtk.rc_reparse_all_for_settings you are basically creating a bunch of GtkStyles and setting them to all the widgets in your app. We would need just a hook to select the set of widgets we want to affect with this change in the theme. Problems: - Even when this looks like a simple solution the integration in a complex library like GTK+ could be non trivial and it may break other apps. - Inclusion in GTK+ upstream could be hard because of the previous point. Solution B: Change the RC Files on-the-fly A rc file is a set of style rules for GTK+ widgets. Each rules is targeted to a widget or class of widgets. Maybe it could be possible to change the rc file just before the call to gtk.rc_set_default_files and change its target descriptors to use the widgets we want to affect. Problems: - A rc files has a non trivial syntax that would need to be parsed. GTK+ is already parsing it so we would be duplicating code. - There are serveral ways to specify a target in a rc file so we should be careful in the way we modify the rc file on-the-fly - If we change the name of a widget in Gazpacho the rc file would need to be changed again and reloaded.