[pygtk] Scraping colors from the current theme

endolith 3m0mdpc02 at sneakemail.com
Wed Aug 20 04:52:49 WST 2008


On Tue, Aug 5, 2008 at 12:43 AM, Jeremy S dumbmatter-at-......... |pygtk| <
...> wrote:

> I don't know the answer to most of your questions because I don't know
> much about GTK themes, but the desktop background color for Gnome is
> stored in gconf.  You can get it like this:
>
> import gconf
>
> client = gconf.client_get_default()
> client.add_dir('/desktop/gnome/background', gconf.CLIENT_PRELOAD_NONE)
>
> print client.get_string('/desktop/gnome/background/primary_color')
> print client.get_string('/desktop/gnome/background/secondary_color')
>

(Re-responding on-list)

My script currently reads it from gconf using this:

from gconf import Client
c = Client()
desktopcolor = c.get_value("/desktop/gnome/background/primary_color")

and then a function to convert the color string.  There's no secondary
desktop color (gradients) in Wine, so no need to extract that.


I figured out some of my problems.  The menu selection color was wrong when
menuitem.style is "gtk.Style object", but if I add it to a real gtk.Window
instead of gtk.Invisible, and then do window.show_all(), menuitem.style
changes to "__main__.ClearlooksStyle object" (or whatever engine I am using)
and the color is now correct.  I'm sure there's a better way to do this, but
I found that by trial and error.  (I wish the pygtk reference had examples
for each item, but maybe it's easy enough for others to decipher as is.)

I still can't figure out:


   - How to add a Tooltip to my window and scrape its colors
   - I don't think there's any such thing as an MDI in GTK, so I don't have
   a color to scrape for the MDI background
    - I still don't know how to get title bar/border colors, since those
   aren't provided by GTK.  Or are they?  They change when I change the GTK
   engine.  I really don't understand the relationship between Clearlooks,
   Metacity, GTK, and window decorations.  Who sets the title bar colors?
   - Some of the color mappings seem different from one engine to the next.
   I'm reverse engineering these by color-picking from the screen and matching
   the value up with "object.style.attr[gtk.STATE]", for every combination of
   "STATE" and "attr".  Surely there's documentation for these mappings
   somewhere?


Script so far:

http://www.endolith.com/wordpress/wp-content/uploads/2008/08/wine_colors_from_gnome.py
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20080819/77dff17f/attachment.htm 


More information about the pygtk mailing list