| 1 | # Copyright (C) 2007 Adriano Monteiro Marques |
|---|
| 2 | # |
|---|
| 3 | # Authors: Guilherme Polo <ggpolo@gmail.com> |
|---|
| 4 | # |
|---|
| 5 | # This program is free software; you can redistribute it and/or modify |
|---|
| 6 | # it under the terms of the GNU General Public License as published by |
|---|
| 7 | # the Free Software Foundation; either version 2 of the License, or |
|---|
| 8 | # (at your option) any later version. |
|---|
| 9 | # |
|---|
| 10 | # This program is distributed in the hope that it will be useful, |
|---|
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | # GNU General Public License for more details. |
|---|
| 14 | # |
|---|
| 15 | # You should have received a copy of the GNU General Public License |
|---|
| 16 | # along with this program; if not, write to the Free Software |
|---|
| 17 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
|---|
| 18 | # USA |
|---|
| 19 | |
|---|
| 20 | """ |
|---|
| 21 | A standard ToggleButton but with an colored eventbox. |
|---|
| 22 | """ |
|---|
| 23 | |
|---|
| 24 | import gtk |
|---|
| 25 | |
|---|
| 26 | class ColoredToggleButton(gtk.ToggleButton): |
|---|
| 27 | |
|---|
| 28 | def __init__(self, label, color): |
|---|
| 29 | gtk.ToggleButton.__init__(self) |
|---|
| 30 | |
|---|
| 31 | self.lbl = gtk.Label(label) |
|---|
| 32 | self.color_eb = gtk.EventBox() |
|---|
| 33 | self.color_eb.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(*color)) |
|---|
| 34 | |
|---|
| 35 | # XXX For some WMs the following two lines are needed in order to |
|---|
| 36 | # obtain the same results elsewhere, it is like eventbox changed |
|---|
| 37 | # its state. |
|---|
| 38 | self.color_eb.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.Color(*color)) |
|---|
| 39 | self.color_eb.modify_bg(gtk.STATE_ACTIVE, gtk.gdk.Color(*color)) |
|---|
| 40 | |
|---|
| 41 | self.__set_props() |
|---|
| 42 | self.__do_layout() |
|---|
| 43 | self.show_all() |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | def __set_props(self): |
|---|
| 47 | """ |
|---|
| 48 | Set eventbox width, height. |
|---|
| 49 | """ |
|---|
| 50 | self.color_eb.set_size_request(12, 6) |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | def __do_layout(self): |
|---|
| 54 | """ |
|---|
| 55 | Layout colored toggle button. |
|---|
| 56 | """ |
|---|
| 57 | color_align = gtk.Alignment(0, 0.6, 1, 0.1) |
|---|
| 58 | color_align.add(self.color_eb) |
|---|
| 59 | |
|---|
| 60 | button_box = gtk.HBox() |
|---|
| 61 | button_box.pack_start(color_align, False, False, 2) |
|---|
| 62 | button_box.add(self.lbl) |
|---|
| 63 | |
|---|
| 64 | self.add(button_box) |
|---|
| 65 | |
|---|