Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

What are the standard notification colors in 11.10? I'm writing an app with an AppIndicator, and I'd like it to match the desktop color scheme.

Is there anywhere this stuff is documented? I checked developer.ubuntu.com, but without any luck.

share|improve this question
4  
I believe you shouldn't hard code the colors - but use the theme's colors instead; however, I don't have any resources to provide to support my beliefs –  Marco Ceppi Oct 14 '11 at 1:15
    
I second that. You should be able to query GTK for the colour scheme. –  Oli Oct 14 '11 at 1:17
    
How do I get the colors from the theme? And how do I draw the colors onto the image for my appindicator? –  Erigami Oct 14 '11 at 1:32
add comment

1 Answer

up vote 2 down vote accepted

Assuming that your real question is given in your comment (and assuming python since you have added a py-appindicator tag): " 1.) How do I get the colors from the global menu? 2.) And how do I draw the colors onto the image for my appindicator? "

Your second question is actually composed of two questions: 2.a) How do I draw an image? 2.b) How to define an Appindicator icon theme?

I have no answer to 2.b). The Appindicator is either extremely bad documented, or the documentation is extremely well hidden. Some not so useful stuff can be found here and here. You probably have to run myindicator.set_icon_theme_path but I did not find the names of the different icons that are used.

To 1.): To get the colors of a gtk widget programmatically for use in cairo (to draw them later) you can use something like this (for a menu):

import gtk
def get_menubar_colors_for_cairo():
    w = gtk.Window()
    b = gtk.MenuBar()
    w.add(b)
    w.show_all()
    w.hide()
    style = b.get_style()
    del(w)
    del(b)
    bg = {}
    fg = {}
    for name, state in [("normal", gtk.STATE_NORMAL),
                        ("active", gtk.STATE_ACTIVE),
                        ("prelight", gtk.STATE_PRELIGHT),
                        ("selected", gtk.STATE_SELECTED),
                        ("insensitive", gtk.STATE_INSENSITIVE)]:
        bg[name] = (style.bg[state].red / 65535.0, style.bg[state].green / 65535.0, style.bg[state].blue / 65535.0)
        fg[name] = (style.fg[state].red / 65535.0, style.fg[state].green / 65535.0, style.fg[state].blue / 65535.0)
    return fg, bg

This gives you the forground and background style for different states. (There are probably better ways, but this should still work...)

Note that the bright blue or bright red do not seem to be part of the standard menu colors. I could not find out where they come from.

Note also that if the gtk theme changes but you leave your icons as they are, they will stand out since they then might have the wrong colors.

To 2.a) You can use cairo to draw images to various surfaces (png, pdf, svg, gtk widgets, ...). Here is an example that draws some rectangles onto png surfaces and saves the files in your current working directory. Each rectangle has the foreground color drawn onto the background color of the given state:

import cairo
def draw_a_rect(fg, bg, state, outfilename):
    surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, 200, 200)
    context = cairo.Context(surf)

    context.rectangle(0, 0, 200, 200)
    context.set_source_rgb(*bg[state])
    context.fill()

    context.rectangle(50, 50, 100, 100)
    context.set_source_rgb(*fg[state])
    context.fill()
    surf.write_to_png(outfilename % state)

fg, bg = get_menubar_colors_for_cairo()
for state_name in ["normal", "active", "prelight", "selected", "insensitive"]:
    draw_a_rect(fg, bg, state_name, "test_%s.png")

A last note: you probably want to leave the background of your icons transparent, so you have one color less to worry about.

share|improve this answer
    
Thanks for a very complete answer. –  Erigami Oct 22 '11 at 6:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.