Use own color only for backlighted button.mastermob
authorNikita Zlobin <cook60020tmp@mail.ru>
Tue, 28 Dec 2010 23:05:40 +0000 (29 04:05 +0500)
committerNikita Zlobin <cook60020tmp@mail.ru>
Tue, 28 Dec 2010 23:05:40 +0000 (29 04:05 +0500)
jack_freewheel_button

index ddd7cf1..bf72b69 100755 (executable)
@@ -43,14 +43,12 @@ def on_button_toggled(button):
 
     global blink_state
     blink_state = True
+    button.modify_bg(gtk.STATE_NORMAL, backlight_bg)
     blink_toggle()
   else:
+    button.modify_bg(gtk.STATE_NORMAL, normal_bg)
+    b_label.modify_fg(gtk.STATE_NORMAL, normal_fg)
     b_label.set_label(text_generic+"\n"+fw_off)
-    # Return default colors
-    button.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('darkgreen'))
-    button.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.color_parse('darkgreen'))
-    button.modify_bg(gtk.STATE_ACTIVE, gtk.gdk.color_parse('darkgreen'))
-    b_label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse('lightgreen'))
 
     button.set_sensitive(True)
     jack.set_freewheel(0)
@@ -60,10 +58,10 @@ def check_freewheel():
     if button.get_active() == False:
       button.set_active(True)
       button.set_sensitive(False)
-      b_label.set_label(text_generic+"\n"+fw_slave)
-      b_label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse('pink'))
+      b_label.set_label("<span foreground=\"darkorange\">"+text_generic+"\n"+fw_slave+"</span>")
   else:
     button.set_active(False)
+    button.set_sensitive(True)
 
   return True
 
@@ -73,14 +71,16 @@ def blink_toggle():
 
   global blink_state
   if blink_state:
-    button.modify_bg(gtk.STATE_ACTIVE, gtk.gdk.color_parse('brown'))
-    button.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.color_parse('brown'))
-    b_label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse('pink'))
+    button.modify_bg(gtk.STATE_ACTIVE, normal_bg)
+    button.modify_bg(gtk.STATE_PRELIGHT, normal_bg)
+    b_label.modify_fg(gtk.STATE_NORMAL, normal_fg)
+    b_label.modify_fg(gtk.STATE_ACTIVE, normal_fg)
     blink_state = False
   else:
-    button.modify_bg(gtk.STATE_ACTIVE, gtk.gdk.color_parse('darkorange'))
-    button.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.color_parse('darkorange'))
-    b_label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse('lightyellow'))
+    button.modify_bg(gtk.STATE_ACTIVE, backlight_bg)
+    button.modify_bg(gtk.STATE_PRELIGHT, backlight_bg)
+    b_label.modify_fg(gtk.STATE_NORMAL, backlight_fg)
+    b_label.modify_fg(gtk.STATE_ACTIVE, backlight_fg)
     blink_state = True
   return True
 
@@ -106,11 +106,13 @@ button.connect("toggled", on_button_toggled);
 window.add(button)
 
 # Colors
-button.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('darkgreen'))
-button.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.color_parse('darkgreen'))
-button.modify_bg(gtk.STATE_ACTIVE, gtk.gdk.color_parse('darkgreen'))
-button.modify_bg(gtk.STATE_INSENSITIVE, gtk.gdk.color_parse('darkred'))
-b_label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse('lightgreen'))
+b_style = button.get_modifier_style().copy()
+t_style = b_label.get_modifier_style().copy()
+normal_bg = b_style.bg[gtk.STATE_ACTIVE]
+normal_fg = t_style.fg[gtk.STATE_ACTIVE]
+backlight_bg = gtk.gdk.color_parse('brown')
+backlight_fg = gtk.gdk.color_parse('darkorange')
+button.modify_bg(gtk.STATE_INSENSITIVE, backlight_bg)
 
 # JACK
 jack.attach(jclient_name)