Use own color only for backlighted button.
[jack_freewheel_button.git] / jack_freewheel_button
blobbf72b69f1165f3d298bcbada1fab17a34dc82c51
1 #!/usr/bin/python
3 # JACK FreeWheel button
5 # Copyright (C) 2010 Nikita Zlobin <cook60020tmp@mail.ru>
7 #*************************************************************************
8 # This file implements dialogs that are not implemented in dedicated files
9 #*************************************************************************
11 # LADI Session Handler is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
16 # LADI Session Handler is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
23 # or write to the Free Software Foundation, Inc.,
24 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
27 import glib
28 import gtk
29 import jack
31 fw_on = "<b>ON</b>"
32 fw_off = "<b>OFF</b>"
33 fw_slave = "<b>ON</b> <small>SLAVE</small>"
34 text_generic = "<small>FREE WHEEL</small>"
36 jclient_name = "jack_freewheel_button"
38 def on_button_toggled(button):
39 label = button.get_children()[0]
40 if button.get_active():
41 b_label.set_label(text_generic+"\n"+fw_on)
42 jack.set_freewheel(1)
44 global blink_state
45 blink_state = True
46 button.modify_bg(gtk.STATE_NORMAL, backlight_bg)
47 blink_toggle()
48 else:
49 button.modify_bg(gtk.STATE_NORMAL, normal_bg)
50 b_label.modify_fg(gtk.STATE_NORMAL, normal_fg)
51 b_label.set_label(text_generic+"\n"+fw_off)
53 button.set_sensitive(True)
54 jack.set_freewheel(0)
56 def check_freewheel():
57 if jack.get_freewheel() > 0:
58 if button.get_active() == False:
59 button.set_active(True)
60 button.set_sensitive(False)
61 b_label.set_label("<span foreground=\"darkorange\">"+text_generic+"\n"+fw_slave+"</span>")
62 else:
63 button.set_active(False)
64 button.set_sensitive(True)
66 return True
68 def blink_toggle():
69 if not button.get_active():
70 return True
72 global blink_state
73 if blink_state:
74 button.modify_bg(gtk.STATE_ACTIVE, normal_bg)
75 button.modify_bg(gtk.STATE_PRELIGHT, normal_bg)
76 b_label.modify_fg(gtk.STATE_NORMAL, normal_fg)
77 b_label.modify_fg(gtk.STATE_ACTIVE, normal_fg)
78 blink_state = False
79 else:
80 button.modify_bg(gtk.STATE_ACTIVE, backlight_bg)
81 button.modify_bg(gtk.STATE_PRELIGHT, backlight_bg)
82 b_label.modify_fg(gtk.STATE_NORMAL, backlight_fg)
83 b_label.modify_fg(gtk.STATE_ACTIVE, backlight_fg)
84 blink_state = True
85 return True
87 # Create objects
88 window = gtk.Window()
89 window.set_title("JACK time wheel control")
90 window.set_resizable(False)
91 window.set_decorated(False)
93 button = gtk.ToggleButton()
94 button.set_active(False)
95 button.set_label(text_generic+"\n"+fw_off)
97 b_label = button.get_children()[0]
98 b_label.set_justify(gtk.JUSTIFY_CENTER)
99 b_label.set_use_markup(True)
101 blink_state = False
103 # Connections
104 window.connect("delete-event", gtk.main_quit);
105 button.connect("toggled", on_button_toggled);
106 window.add(button)
108 # Colors
109 b_style = button.get_modifier_style().copy()
110 t_style = b_label.get_modifier_style().copy()
111 normal_bg = b_style.bg[gtk.STATE_ACTIVE]
112 normal_fg = t_style.fg[gtk.STATE_ACTIVE]
113 backlight_bg = gtk.gdk.color_parse('brown')
114 backlight_fg = gtk.gdk.color_parse('darkorange')
115 button.modify_bg(gtk.STATE_INSENSITIVE, backlight_bg)
117 # JACK
118 jack.attach(jclient_name)
119 jack.activate()
120 glib.timeout_add(300, check_freewheel)
121 glib.timeout_add(700, blink_toggle)
123 window.show_all()
125 gtk.main()
127 jack.deactivate()
128 jack.detach()