Improvements: text markup, colors, blinking when time wheel is freed.
authorNikita Zlobin <cook60020tmp@mail.ru>
Mon, 27 Dec 2010 23:54:27 +0000 (28 04:54 +0500)
committerNikita Zlobin <cook60020tmp@mail.ru>
Mon, 27 Dec 2010 23:54:27 +0000 (28 04:54 +0500)
jack_freewheel_button

index 26ac0ec..d3ac65c 100644 (file)
@@ -28,31 +28,59 @@ import glib
 import gtk
 import jack
 
-text_freewheel = "ON"
-text_rtwheel = "OFF"
-text_generic = "Free wheel: "
+fw_on = "<b>ON</b>"
+fw_off = "<b>OFF</b>"
+fw_slave = "<b>ON</b> <small>SLAVE</small>"
+text_generic = "<small>FREE WHEEL</small>"
 
 jclient_name = "jack_freewheel_button"
 
 def on_button_toggled(button):
+  label = button.get_children()[0]
   if button.get_active():
-    button.set_label(text_generic+text_freewheel)
+    b_label.set_label(text_generic+"\n"+fw_on)
     jack.set_freewheel(1)
+    blink_toggle()
   else:
-    button.set_label(text_generic+text_rtwheel)
+    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)
 
-def timeout():
+def check_freewheel():
   if jack.get_freewheel() > 0:
     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'))
   else:
     button.set_active(False)
 
   return True
 
+def blink_toggle():
+  if not button.get_active():
+    return True
+
+  global blink_state
+  if blink_state:
+    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'))
+    blink_state = False
+  else:
+    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'))
+    blink_state = True
+  return True
+
 # Create objects
 window = gtk.Window()
 window.set_title("JACK time wheel control")
@@ -61,17 +89,31 @@ window.set_decorated(False)
 
 button = gtk.ToggleButton()
 button.set_active(False)
-button.set_label(text_generic+text_rtwheel)
+button.set_label(text_generic+"\n"+fw_off)
+
+b_label = button.get_children()[0]
+b_label.set_justify(gtk.JUSTIFY_CENTER)
+b_label.set_use_markup(True)
+
+blink_state = False
 
 # Connections
 window.connect("delete-event", gtk.main_quit);
 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'))
+
 # JACK
 jack.attach(jclient_name)
 jack.activate()
-glib.timeout_add(300, timeout)
+glib.timeout_add(300, check_freewheel)
+glib.timeout_add(700, blink_toggle)
 
 window.show_all()