3

Project Hamster: Theme colors

view full story
linux-howto

http://projecthamster.wordpress.com – If you are using hamster on the dark side of the theme force (seems to be the trend nowadays), it just became much friendlier to your eyes. Since now the background colors match, I could also remove the frame around the graph which made it much lighter and less padding is required. Change not too complex, still might be reusable for somebody in the interwebs. First, let’s grab theme colors. It is as easy as some_widget.get_style(). Any widget will do, no matter if it is a label, input box, or a window – they all point to the same style. Correct me if I’m wrong. Here’s a chart of colours in Clearlooks. It is not the same as the one found in your preferences, because elements need states. (The script to regenerate it for your current theme can be found in hamster experiments): Text/Base couple refers to text color and background color in an text input field, like text entry, or a treeview.. The fg/bg refer to the same duo, just for labels and background type of elements. Notice that text and fg are almost the same except for when in the selected state. As it should be, most of the time themes have a good contrast between foreground and background, so there are a few levels in between that can come handy: Grab the theme color, appropriate for our task. Say, for the bars we would start with the background color: bg_color = self.get_style().bg[gtk.STATE_NORMAL] Next, using colorsys (part of python’s stdlib), convert it to HSV (hue, saturation, value) – which will allow us to specifically change the brightness (value) of the colour. And then, check – if the color is dark (value is below your chosen treshold), then you should go up the scale, and if it is light – go down. You can either reuse or grab the code from the relevant part in hamster graphics (the input color can be a tuple, a triple, a string, or gdk.Color). In action it looks like (using graphics.py): bg_color = self.get_style().bg[gtk.STATE_NORMAL].to_string() if self.colors.is_light(bg_color): bar_color = self.colors.darker(bg_color, 30) else: bar_color = self.colors.darker(bg_color, -30) (Software)