diff options
| author | Joshua Lock <josh@linux.intel.com> | 2012-03-22 15:54:37 -0700 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2012-03-23 16:10:22 +0000 |
| commit | f76dcdb1cad85dd755ae14d18b3f5f7c67e273ee (patch) | |
| tree | 5075e50585ce766af11e8f2c9aa29a6345df25cc /bitbake/lib/bb/ui/crumbs/hobwidget.py | |
| parent | ce914a6742fd7802452295fb49cca58d3a2f133c (diff) | |
| download | poky-f76dcdb1cad85dd755ae14d18b3f5f7c67e273ee.tar.gz | |
lib/bb/ui/crumbs: replace HobXpmLabelButtonBox with HobImageButton
HobImageButton is an gtk.Button subclass, and therefore behaves like a
button with prelight and focus states, with an icon and two lines of text -
primary and secondary. The secondary text is displayed in a lighter colour
using a new module method, soften_color(), per the design.
(Bitbake rev: b91cc96c4ff4195ac26fdfd1fb0c2ff8db06aff8)
Signed-off-by: Joshua Lock <josh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/ui/crumbs/hobwidget.py')
| -rw-r--r-- | bitbake/lib/bb/ui/crumbs/hobwidget.py | 123 |
1 files changed, 64 insertions, 59 deletions
diff --git a/bitbake/lib/bb/ui/crumbs/hobwidget.py b/bitbake/lib/bb/ui/crumbs/hobwidget.py index 9d00023140..e8549a135a 100644 --- a/bitbake/lib/bb/ui/crumbs/hobwidget.py +++ b/bitbake/lib/bb/ui/crumbs/hobwidget.py | |||
| @@ -53,8 +53,10 @@ class hic: | |||
| 53 | ICON_INFO_HOVER_FILE = os.path.join(HOB_ICON_BASE_DIR, ('info/info_hover.png')) | 53 | ICON_INFO_HOVER_FILE = os.path.join(HOB_ICON_BASE_DIR, ('info/info_hover.png')) |
| 54 | ICON_INDI_CONFIRM_FILE = os.path.join(HOB_ICON_BASE_DIR, ('indicators/confirmation.png')) | 54 | ICON_INDI_CONFIRM_FILE = os.path.join(HOB_ICON_BASE_DIR, ('indicators/confirmation.png')) |
| 55 | ICON_INDI_ERROR_FILE = os.path.join(HOB_ICON_BASE_DIR, ('indicators/error.png')) | 55 | ICON_INDI_ERROR_FILE = os.path.join(HOB_ICON_BASE_DIR, ('indicators/error.png')) |
| 56 | ICON_INDI_REMOVE = os.path.join(HOB_ICON_BASE_DIR, ('indicators/remove.png')) | 56 | ICON_INDI_REMOVE_FILE = os.path.join(HOB_ICON_BASE_DIR, ('indicators/remove.png')) |
| 57 | ICON_INDI_ADD = os.path.join(HOB_ICON_BASE_DIR, ('indicators/add.png')) | 57 | ICON_INDI_REMOVE_HOVER_FILE = os.path.join(HOB_ICON_BASE_DIR, ('indicators/remove-hover.png')) |
| 58 | ICON_INDI_ADD_FILE = os.path.join(HOB_ICON_BASE_DIR, ('indicators/add.png')) | ||
| 59 | ICON_INDI_ADD_HOVER_FILE = os.path.join(HOB_ICON_BASE_DIR, ('indicators/add-hover.png')) | ||
| 58 | 60 | ||
| 59 | class hcc: | 61 | class hcc: |
| 60 | 62 | ||
| @@ -173,6 +175,27 @@ class HobViewTable (gtk.VBox): | |||
| 173 | if not view_column.get_title() in self.toggle_columns: | 175 | if not view_column.get_title() in self.toggle_columns: |
| 174 | self.emit("row-activated", tree.get_model(), path) | 176 | self.emit("row-activated", tree.get_model(), path) |
| 175 | 177 | ||
| 178 | """ | ||
| 179 | A method to calculate a softened value for the colour of widget when in the | ||
| 180 | provided state. | ||
| 181 | |||
| 182 | widget: the widget whose style to use | ||
| 183 | state: the state of the widget to use the style for | ||
| 184 | |||
| 185 | Returns a string value representing the softened colour | ||
| 186 | """ | ||
| 187 | def soften_color(widget, state=gtk.STATE_NORMAL): | ||
| 188 | # this colour munging routine is heavily inspired bu gdu_util_get_mix_color() | ||
| 189 | # from gnome-disk-utility: | ||
| 190 | # http://git.gnome.org/browse/gnome-disk-utility/tree/src/gdu-gtk/gdu-gtk.c?h=gnome-3-0 | ||
| 191 | blend = 0.7 | ||
| 192 | style = widget.get_style() | ||
| 193 | color = style.text[state] | ||
| 194 | color.red = color.red * blend + style.base[state].red * (1.0 - blend) | ||
| 195 | color.green = color.green * blend + style.base[state].green * (1.0 - blend) | ||
| 196 | color.blue = color.blue * blend + style.base[state].blue * (1.0 - blend) | ||
| 197 | return color.to_string() | ||
| 198 | |||
| 176 | class HobAltButton(gtk.Button): | 199 | class HobAltButton(gtk.Button): |
| 177 | """ | 200 | """ |
| 178 | A gtk.Button subclass which has no relief, and so is more discrete | 201 | A gtk.Button subclass which has no relief, and so is more discrete |
| @@ -181,64 +204,46 @@ class HobAltButton(gtk.Button): | |||
| 181 | gtk.Button.__init__(self, label) | 204 | gtk.Button.__init__(self, label) |
| 182 | self.set_relief(gtk.RELIEF_NONE) | 205 | self.set_relief(gtk.RELIEF_NONE) |
| 183 | 206 | ||
| 184 | class HobXpmLabelButtonBox(gtk.EventBox): | 207 | class HobImageButton(gtk.Button): |
| 185 | """ label: name of buttonbox | ||
| 186 | description: the simple description | ||
| 187 | """ | 208 | """ |
| 188 | def __init__(self, display_file="", hover_file="", label="", description=""): | 209 | A gtk.Button with an icon and two rows of text, the second of which is |
| 189 | gtk.EventBox.__init__(self) | 210 | displayed in a blended colour. |
| 190 | self._base_state_flags = gtk.STATE_NORMAL | 211 | |
| 191 | self.set_events(gtk.gdk.MOTION_NOTIFY | gtk.gdk.BUTTON_PRESS | gtk.gdk.EXPOSE) | 212 | primary_text: the main button label |
| 192 | 213 | secondary_text: optional second line of text | |
| 193 | self.connect("expose-event", self.cb) | 214 | icon_path: path to the icon file to display on the button |
| 194 | self.connect("enter-notify-event", self.pointer_enter_cb) | 215 | """ |
| 195 | self.connect("leave-notify-event", self.pointer_leave_cb) | 216 | def __init__(self, primary_text, secondary_text="", icon_path="", hover_icon_path=""): |
| 196 | 217 | gtk.Button.__init__(self) | |
| 197 | self.icon_hover = gtk.Image() | 218 | self.set_relief(gtk.RELIEF_NONE) |
| 198 | self.icon_hover.set_name("icon_image") | 219 | |
| 199 | if type(hover_file) == str: | 220 | self.icon_path = icon_path |
| 200 | pixbuf = gtk.gdk.pixbuf_new_from_file(hover_file) | 221 | self.hover_icon_path = hover_icon_path |
| 201 | self.icon_hover.set_from_pixbuf(pixbuf) | 222 | |
| 202 | 223 | hbox = gtk.HBox(False, 3) | |
| 203 | self.icon_display = gtk.Image() | 224 | hbox.show() |
| 204 | self.icon_display.set_name("icon_image") | 225 | self.add(hbox) |
| 205 | if type(display_file) == str: | 226 | self.icon = gtk.Image() |
| 206 | pixbuf = gtk.gdk.pixbuf_new_from_file(display_file) | 227 | self.icon.set_from_file(self.icon_path) |
| 207 | self.icon_display.set_from_pixbuf(pixbuf) | 228 | self.icon.set_alignment(0.5, 0.0) |
| 208 | 229 | self.icon.show() | |
| 209 | self.tb = gtk.Table(2, 10, True) | 230 | if self.hover_icon_path and len(self.hover_icon_path): |
| 210 | self.tb.set_row_spacing(1, False) | 231 | self.connect("enter-notify-event", self.set_hover_icon_cb) |
| 211 | self.tb.set_col_spacing(1, False) | 232 | self.connect("leave-notify-event", self.set_icon_cb) |
| 212 | self.add(self.tb) | 233 | hbox.pack_start(self.icon, False, False, 0) |
| 213 | self.tb.attach(self.icon_display, 0, 2, 0, 2, 0, 0) | 234 | label = gtk.Label() |
| 214 | self.tb.attach(self.icon_hover, 0, 2, 0, 2, 0, 0) | 235 | label.set_alignment(0.0, 0.5) |
| 215 | 236 | colour = soften_color(label) | |
| 216 | lbl = gtk.Label() | 237 | mark = "%s\n<span fgcolor='%s'><small>%s</small></span>" % (primary_text, colour, secondary_text) |
| 217 | lbl.set_alignment(0.0, 0.5) | 238 | label.set_markup(mark) |
| 218 | lbl.set_markup("<span foreground=\'#1C1C1C\' font_desc=\'18px\'>%s</span>" % label) | 239 | label.show() |
| 219 | self.tb.attach(lbl, 2, 10, 0, 1) | 240 | hbox.pack_start(label, True, True, 0) |
| 220 | 241 | ||
| 221 | lbl = gtk.Label() | 242 | def set_hover_icon_cb(self, widget, event): |
| 222 | lbl.set_alignment(0.0, 0.5) | 243 | self.icon.set_from_file(self.hover_icon_path) |
| 223 | lbl.set_markup("<span foreground=\'#1C1C1C\' font_desc=\'14px\'>%s</span>" % description) | 244 | |
| 224 | self.tb.attach(lbl, 2, 10, 1, 2) | 245 | def set_icon_cb(self, widget, event): |
| 225 | 246 | self.icon.set_from_file(self.icon_path) | |
| 226 | def pointer_enter_cb(self, *args): | ||
| 227 | #if not self.is_focus(): | ||
| 228 | self.set_state(gtk.STATE_PRELIGHT) | ||
| 229 | self._base_state_flags = gtk.STATE_PRELIGHT | ||
| 230 | self.icon_hover.show() | ||
| 231 | self.icon_display.hide() | ||
| 232 | |||
| 233 | def pointer_leave_cb(self, *args): | ||
| 234 | self.set_state(gtk.STATE_NORMAL) | ||
| 235 | self._base_state_flags = gtk.STATE_NORMAL | ||
| 236 | self.icon_display.show() | ||
| 237 | self.icon_hover.hide() | ||
| 238 | |||
| 239 | def cb(self, w,e): | ||
| 240 | """ Hide items - first time """ | ||
| 241 | pass | ||
| 242 | 247 | ||
| 243 | class HobInfoButton(gtk.EventBox): | 248 | class HobInfoButton(gtk.EventBox): |
| 244 | """ | 249 | """ |
