Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Gnome to Wine color scraper
This is a Python script to extract GNOME/GTK's color scheme and apply it to Wine, so that the themes (approximately) match.
1. Set your Gnome theme as you would like it
2. Run with a command like "python"
3. Restart any apps running in Wine. They should match the Gnome theme colors now.
Better description with screenshots here:
This is also stored on
Just trying out
To do:
* Needs to separate out scrapers for each GTK engine where necessary. (Can't an interface for this just be built into the engines instead?)
* Copy Gnome fonts as well as colors. (Not sure where Wine stores these settings.)
* Something would need to call this script every time the Gnome theme is changed.
Everything else is working for me.
Other previous discussions: and scripts in Guidance package for KDE do the same things:
Similar code is built into Mozilla:
Will be integrated into Wine Doors?
All of Wine's 31 possible user.reg color values
Asterisk * next to comment if I've found a value that works for most themes
Question mark ? next to comment if not sure or can't find anywhere to scrape from
Some descriptions:
TitleText Active title bar text
ActiveTitle Left end of active title bar
GradientActiveTitle Right end of active title bar
ActiveBorder Active window border
InactiveTitleText Inactive title bar text
InactiveTitle Left end of inactive title bar
GradientInactiveTitle Right end of inactive title bar
InactiveBorder Inactive window border
AppWorkSpace Background color of multiple-document interface
Background Desktop solid color
ButtonText Button/tab text and glyphs
ButtonHilight Outermost button higlight / Grayed-out button text shadow
ButtonLight Inner button highlight, usually same as ButtonFace
ButtonFace Background for buttons and all 3D objects
ButtonAlternateFace ???
ButtonShadow Shadows of buttons / Grayed-out button text
ButtonDkShadow Outermost shadow of buttons
GrayText Grayed out text in windows, like labels for unavailable widgets
Hilight Background of selected text
HilightText Selected text
HotTrackingColor Single-click navigation hover color
InfoText ToolTip text
InfoWindow ToolTip background
Menu Background for menus, also background for menu bars in 3D mode
MenuBar Background for menu bars - rarely seen due to 3D menus
MenuHilight Highlight for flat menus - in 3D mode, Hilight is used instead
MenuText Menu text
Scrollbar Background color of scrollbar, but only in some apps
Window Background color of notepad, for instance
WindowFrame Glow around focused widget
WindowText Text in notepad, for instance
These were all found by trial and error. Please point out any mistakes.
License is GPL, I guess. If you need some other license or a more explicit statement, let me know.
2011-04: I use Windows 7 as my main OS now, so I won't be making many updates to this script. Fork it and improve it!
#!/usr/bin/env python
# Scrape colors from GTK and import them into Wine through the registry
# 2009-02-06
# Based on script by KillerKiwi [Ubuntu Forums] October 29th, 2007
# which is based on patch by Johannes Roith [Mono-winforms-list] Wed, 27 Aug 2003
import pygtk
import gtk
import os
from tempfile import NamedTemporaryFile
from gconf import Client
import re
# TODO: command line switch
debug_mode = False
def format_color_string(Color):
""" Convert 48-bit gdk.Color to 24-bit 'RRR GGG BBB' triple. """
if type(Color) is gtk.gdk.Color:
return '%s %s %s' % (,,
print('Not a GdkColor: ' + str(Color))
return None
def format_hex_color(color):
""" Convert from hex color string to decimal 'RRR GGG BBB' triple. """
if re.match('^#[0-9a-fA-F]{12}$', color):
r, g, b = color[1:3], color[5:7], color[9:11] #rrrrggggbbbb
elif re.match('^#[0-9a-fA-F]{6}$', color):
r, g, b = color[1:3], color[3:5], color[5:7] #RRGGBB
elif re.match('^#[0-9a-fA-F]{3}$', color):
r, g, b = color[1]*2, color[2]*2, color[3]*2 #09C becomes 0099CC.
print('Cannot understand color string format: ' + str(color))
return None
return '%s %s %s' % (int(r,16), int(g,16), int(b,16))
# TODO: fonts
# Get some colors from GTK
# gtk.Style object:
# Create a window to scrape colors from
window = gtk.Window()
button = gtk.Button()
vbox = gtk.VBox()
scrollbar = gtk.VScrollbar()
menubar = gtk.MenuBar()
menuitem = gtk.MenuItem()
# On show_all(), these are all converted from gtk.Style objects with wrong
# colors into __main__.EngineStyle objects with correct colors.
# Tooltips
tooltip = gtk.Window()
# Mappings for all the color values (described in readme.txt)
# TODO: Need to mark which colors do not work with which themes and double-check EVERYTHING
# * = Confirmed to work exactly for all themes (except Darklooks)
# + = Not perfect, but close?
# ? = Nothing to scrape? - Chose something similar
gtk_colors = {
# Title bars can't be accessed from PyGTK(?) so I just guessed to
# make it work reasonably well with themes like Human.
# Default Windows theme: Darker on left, light on right
'TitleText': , #? White since we're guessing on dark selection color for titlebar
'InactiveTitleText': , #? White since we're guessing on dark selection color for titlebar
'ActiveTitle':[gtk.STATE_SELECTED] , #? Guess on selection color like Clearlooks
'InactiveTitle':[gtk.STATE_NORMAL] , #? Darker color for gradient
'GradientActiveTitle':[gtk.STATE_SELECTED], #? Lighter version for gradient
'GradientInactiveTitle':[gtk.STATE_NORMAL] , #? Guess on base color
'ActiveBorder':[gtk.STATE_INSENSITIVE], #? Same as ButtonFace like Clearlooks
'InactiveBorder':[gtk.STATE_INSENSITIVE], #? Same as ButtonFace
'AppWorkSpace':[gtk.STATE_NORMAL], #? MDI not used in GTK; use same color as Window, like Glade
'Background': None , #* Scraped from gconf below
'ButtonText':[gtk.STATE_NORMAL] , #*
'ButtonHilight':[gtk.STATE_INSENSITIVE], #*
'ButtonLight':[gtk.STATE_INSENSITIVE] , #* Usually same as ButtonFace?
'ButtonFace':[gtk.STATE_INSENSITIVE] , #*
'ButtonAlternateFace':[gtk.STATE_INSENSITIVE] , #* Set to same as ButtonFace for now
'ButtonShadow':[gtk.STATE_INSENSITIVE] , #*
'ButtonDkShadow': , #*
'GrayText':[gtk.STATE_INSENSITIVE], #*
'Hilight':[gtk.STATE_SELECTED] , #*
'HilightText':[gtk.STATE_SELECTED] , #*
'HotTrackingColor':[gtk.STATE_NORMAL] , #? Doesn't seem to exist in GTK; use lighter ButtonFace color, like CompizConfig Settings Manager
'MenuBar':[gtk.STATE_NORMAL] ,
'MenuHilight':[gtk.STATE_SELECTED] ,
'MenuText':[gtk.STATE_NORMAL] ,
'Scrollbar':[gtk.STATE_ACTIVE], #+ Not right, even though gtk.RcStyle documentation says it is
'Window':[gtk.STATE_NORMAL] , #* base or bg?
'WindowFrame':[gtk.STATE_SELECTED], #+ bg selected or light selected?
'WindowText':[gtk.STATE_NORMAL] , #*
# As far as I know, there is no way to programmatically extract colors from GTK for the same elements in any engine, so we'll have to add engine-specific scrapers.
# "Engines can and do whatever they want with the colors from the rc file ... A theme includes both the colors, and the code that paints using colors. So the code can use any of the colors it wants."
# TODO: something like this:
print "GTK engine:",
if 'ClearlooksStyle' in repr( # kludgy, but works
print "Clearlooks"
# assign different colors to some elements
elif 'MurrineStyle' in repr(
print "Murrine"
elif 'CruxStyle' in repr(
print "Crux"
print "unknown"
# QtPixbufStyle GlideStyle PixbufStyle HcStyle IndustrialStyle MistStyle ThiniceStyle darklooks = gtk.Style
# Create list of formatted color value pair strings
# Windows registry values are in the form "name"="data" with no spaces
color_pairs = []
for name, data in gtk_colors.iteritems():
if data:
color_pairs.append('"%s"="%s"' % (name, format_color_string(data)))
# Get Desktop background color from Gnome's GConf, append to color pair list
c = Client()
desktop_color = format_hex_color(c.get_value('/desktop/gnome/background/primary_color'))
if desktop_color:
color_pairs.append('"Background"="%s"' % desktop_color)
# TODO: Get Desktop background color from Xfce
# import xfce4?
# "i see, yes xfce does have something like that. you find it in /home/$USER/.config/xfce4/mcs_settings/desktop.xml"
# Create a temporary Windows .reg registry file with the new values
# I'm not sure of the meaning of S-1-5-4. This may not work on all systems?
# I do know it is the same number under multiple accounts.
wineprefix = os.environ['WINEPREFIX']
except KeyError:
wineprefix = os.path.join(os.environ['HOME'],'.wine')
winetemp = os.path.join(wineprefix, 'drive_c','windows','temp')
f = NamedTemporaryFile(prefix = 'winecolors', suffix = '.reg', dir = winetemp, mode = 'w+')
[HKEY_USERS\S-1-5-4\Control Panel]
[HKEY_USERS\S-1-5-4\Control Panel\Colors]
# Alphabetize list (purely so that user.reg is easy to read; Wine doesn't care)
color_pairs = sorted(color_pairs)
# Append list to file, with newlines
f.writelines(line + '\n' for line in color_pairs)
# Debugging
if debug_mode:
print '---- [' + + '] ----'
for line in f:
print line,
print '--------\n'
# Import values into Wine registry using regedit command
print('Using regedit to import colors into registry...\n')
os.system('regedit ' +
# TODO: Check if this worked correctly.
# Delete temporary file
print('Done importing colors')
# TODO: catch errors from regedit not working?

First of all, thank you for commenting your code so well.

I tried using your script and although it seemed to finish successfully it did not. Then I changed "HKEY_USERS\S-1-5-4" to "HKEY_USERS\S-1-5-21-0-0-0-1000" everywhere (2 places). Now it works.

To find the new value i started regedit in wine and looked in HKEY_USERS:

I hope this will help someone.

This script gives this error whenever I try to execute it

File "./", line 26
""" Convert 48-bit gdk.Color to 24-bit 'RRR GGG BBB' triple. """
IndentationError: expected an indented block

Any clue how to solve this?


endolith commented Mar 18, 2014

@ENigma885: Make sure you use Download Gist, not copy and paste. In Python, whitespace matters, and copy and pasting from websites often doesn't preserve it.

GTK engine: unknown
Traceback (most recent call last):
File "./", line 160, in
desktop_color = format_hex_color(c.get_value('/desktop/gnome/background/primary_color'))
ValueError: gconf key /desktop/gnome/background/primary_color has no value

@JoelSjogren, thanks, it's helpfull!

Nice script ! Now with this and the Luna theme, my Wine apps look much more integrated. :)
By the way, I also had the problem with 'S-1-5-4' beeing the wrong ID. It worked when using the hive HKEY_CURRENT_USER instead, and this also seems more robust.
My fork:


endolith commented Sep 25, 2014

I don't use Ubuntu anymore, so this version will not get any updates/fixes. Use the forks, Luke.

Suggest: change HKEY_USERS\S-1-5-4 to HKEY_CURRENT_USER or HKCU.

S-1-5-4 is pointing to your local user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment