![]() |
ubuntu.com - launchpad.net - ubuntu help
|
|
|||||||
|
Programming Talk This forum is for all programming questions. The questions do not have to be directly related to Ubuntu and any programming language is allowed. |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
100% Pure Ubuntu
![]() Join Date: Feb 2007
Location: New York
Beans: 852
Ubuntu 9.10 Karmic Koala
|
[Python] Scraping colors from the current Gnome/GTK/Metacity theme
In Bug 111061 I suggested writing a script to scrape colors from Gnome and import them into Wine to make the color scheme match. (There is theming support in Wine but it really hurts performance, so this would be a middle ground solution.)
Since I had been wanting to learn some Python, I tried to take a stab at it but got pretty stuck. Most of it was already done for me by KillerKiwi; I added some things and fixed some things, but I cannot figure out how to get many of the colors. Can anyone help with this? Some of the colors can be found in gtk.something, but others either don't exist there, or don't match the actual colors being used, so I think that is the wrong place to be looking. I think I need to get some of the colors from metacity or the other active window manager instead, since the window borders are not part of GTK, right? (I don't even know how to figure out which window manager is running in Python.) I know I can "import metacity", but I have no idea what to do with it, and can't find any documentation on it. I posted my script so far in the thread here, but I don't think many Python experts are going to see it in the Tutorials & Tips section.
__________________
"Please remember to do things the Ubuntu way. There is always more than one solution to a problem, choose the one you think will be the easiest for the user. ... Try to think as a green user and choose the simplest solution." — Code of Conduct Last edited by Endolith; September 12th, 2008 at 10:10 AM.. Reason: Change title to [Python] |
|
|
|
|
|
#2 |
|
100% Pure Ubuntu
![]() Join Date: Feb 2007
Location: New York
Beans: 852
Ubuntu 9.10 Karmic Koala
|
Re: Scraping colors from the current Gnome/GTK/Metacity theme in Python
No one knows anything about this? I really don't understand the relationship between metacity and clearlooks and gtk. I want to scrape the colors metacity uses to draw window borders and titles, but I can't find any documentation on this.
__________________
"Please remember to do things the Ubuntu way. There is always more than one solution to a problem, choose the one you think will be the easiest for the user. ... Try to think as a green user and choose the simplest solution." — Code of Conduct |
|
|
|
|
|
#3 |
|
Has an Ubuntu Drip
![]() Join Date: Dec 2007
Location: .
My beans are hidden!
Ubuntu 9.10 Karmic Koala
|
Re: Scraping colors from the current Gnome/GTK/Metacity theme in Python
The metacity module is used for metacity theme previewing.Not what you want.
Unless wine programs are inside a gtk widget.(The Metacity module can generate a preview of a window that is a gtk container) Otherwise there is no good solution because some metacity themes use images for a lot of stuff and there are no colors to get.But you can get the color the users set in the preferences dialog using the module "gconf". But even then you probably won't get all the colors specified in gtk themes.You will have to parse those to get all the colors.
__________________
Don't like the new position of notifications in Karmic? There is a fix. |
|
|
|
|
|
#4 | ||||
|
100% Pure Ubuntu
![]() Join Date: Feb 2007
Location: New York
Beans: 852
Ubuntu 9.10 Karmic Koala
|
Re: Scraping colors from the current Gnome/GTK/Metacity theme in Python
Quote:
Quote:
Quote:
Quote:
__________________
"Please remember to do things the Ubuntu way. There is always more than one solution to a problem, choose the one you think will be the easiest for the user. ... Try to think as a green user and choose the simplest solution." — Code of Conduct |
||||
|
|
|
|
|
#5 | |
|
100% Pure Ubuntu
![]() Join Date: Feb 2007
Location: New York
Beans: 852
Ubuntu 9.10 Karmic Koala
|
Re: Scraping colors from the current Gnome/GTK/Metacity theme in Python
Alright, I'm looking at this again and I still can't $#@&$*#&$* figure it out. gtk.RcStyle Class Reference says:
Quote:
In Human, though, it's completely different. The menu hover highlight is yellowish orange, while menuitem.style.bg[gtk.STATE_PRELIGHT] gives me #F3F0ED, almost white. Why is the style object giving me the wrong color?? In the Human gtkrc file, there's a bit like this: Code:
style "ubuntulooks-menu-item" = "ubuntulooks-default"
{
xthickness = 2
ythickness = 3
bg[SELECTED] = @selected_bg_color
fg[PRELIGHT] = @selected_fg_color
text[PRELIGHT] = @text_color
}
(In the top of the gtkrc file, there's "selected_bg_color:#FFD799", which is where it comes from, I guess.) But if I try to use this bg SELECTED value to get the color for Raleigh, it gives me a blue, which is not correct. How do I get the actual color being used by a widget? Not the GTK color it's theoretically supposed to us, but the color that GTK actually uses to draw it.
__________________
"Please remember to do things the Ubuntu way. There is always more than one solution to a problem, choose the one you think will be the easiest for the user. ... Try to think as a green user and choose the simplest solution." — Code of Conduct Last edited by Endolith; September 4th, 2008 at 07:24 PM.. |
|
|
|
|
|
|
#6 |
|
100% Pure Ubuntu
![]() Join Date: Feb 2007
Location: New York
Beans: 852
Ubuntu 9.10 Karmic Koala
|
Re: Scraping colors from the current Gnome/GTK/Metacity theme in Python
The script works pretty well for most themes, but I've since learned that getting it perfect for all themes would require writing a separate scraper for each engine, since they can basically use the GTK colors however they want.
I've also found out that CSS2 defines a number of system colors that coincide with the colors used in Windows/Wine. So whatever web browsers like Firefox/Epiphany use for finding out these colors could be applied to Wine, too (or vice versa). However, the colors I have seen them render are not so good.
__________________
"Please remember to do things the Ubuntu way. There is always more than one solution to a problem, choose the one you think will be the easiest for the user. ... Try to think as a green user and choose the simplest solution." — Code of Conduct |
|
|
|
|
|
#7 | |
|
Chocolate Ubuntu Mocha Blend
![]() Join Date: Aug 2007
Location: 127.0.0.1
Beans: 1,726
Ubuntu 9.10 Karmic Koala
|
Re: Scraping colors from the current Gnome/GTK/Metacity theme in Python
Quote:
__________________
"Premature optimization is the root of all evil" (Donald Knuth)
|
|
|
|
|
|
|
#8 |
|
5 Cups of Ubuntu
![]() Join Date: Aug 2005
Beans: 36
|
Re: Scraping colors from the current Gnome/GTK/Metacity theme in Python
A little bit of self promotion here
I recently made my own script for gtk colour manipulations with python, to work with my new project SledgeMan see Sig. It takes colour settings from gconf, but only when the theme has a colour-scheme. In practice this works for most themes, but the occasional theme crashes the program Some other features of the script include: Getting the theme name and path. So it would be possible to parse the gtkrc file directly. Converting hex strings to other formats. Converting rgba values in the range 0-1, into hex strings. And a pretty poor hex colour shifter. I can't help but feel python can already do most of this, but it's still fun to reinvent wheels. Colour.py
__________________
SledgeMan - A Sliding File Browser at the edge of the screen. |
|
|
|
|
|
#9 | |
|
Chocolate Ubuntu Mocha Blend
![]() Join Date: Aug 2007
Location: 127.0.0.1
Beans: 1,726
Ubuntu 9.10 Karmic Koala
|
Re: Scraping colors from the current Gnome/GTK/Metacity theme in Python
Quote:
__________________
"Premature optimization is the root of all evil" (Donald Knuth)
|
|
|
|
|
|
|
#10 |
|
100% Pure Ubuntu
![]() Join Date: Feb 2007
Location: New York
Beans: 852
Ubuntu 9.10 Karmic Koala
|
Re: Scraping colors from the current Gnome/GTK/Metacity theme in Python
Indeed, I have found someone else with the same problem... the Mozilla developers! It appears that these are scraped by nsLookAndFeel.cpp, which exists separately for each toolkit (mac, gtk2, qt) They have tons of comments in their code explaining that they're not sure what they're doing, just like mine.
Code:
// It's really hard to effectively map these to the Appearance Manager properly,
// since they are modeled word for word after the win32 system colors and don't have any
// real counterparts in the Mac world. I'm sure we'll be tweaking these for
// years to come.
...
// NOTE: this is an MDI color and does not exist on macOS.
//used the closest match, which will likely be white.
PHP Code:
PHP Code:
PHP Code:
PHP Code:
__________________
"Please remember to do things the Ubuntu way. There is always more than one solution to a problem, choose the one you think will be the easiest for the user. ... Try to think as a green user and choose the simplest solution." — Code of Conduct |
|
|
|
| Bookmarks |
| Tags |
| gnome, gtk, metacity, python, wine |
| Thread Tools | |
| Display Modes | |
|
|