Fix blinking
[jack_freewheel_button.git] / jack_freewheel_button
blob82761f1fe33d581e9c4a8ec02883c293defe7025
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)
43 blink_toggle()
44 else:
45 b_label.set_label(text_generic+"\n"+fw_off)
46 # Return default colors
47 button.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('darkgreen'))
48 button.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.color_parse('darkgreen'))
49 button.modify_bg(gtk.STATE_ACTIVE, gtk.gdk.color_parse('darkgreen'))
50 b_label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse('lightgreen'))
52 button.set_sensitive(True)
53 jack.set_freewheel(0)
55 def check_freewheel():
56 if jack.get_freewheel() > 0:
57 if button.get_active() == False:
58 button.set_active(True)
59 button.set_sensitive(False)
60 b_label.set_label(text_generic+"\n"+fw_slave)
61 b_label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse('pink'))
62 else:
63 button.set_active(False)
65 return True
67 def blink_toggle():
68 if not button.get_active():
69 return True
71 global blink_state
72 if blink_state:
73 button.modify_bg(gtk.STATE_ACTIVE, gtk.gdk.color_parse('brown'))
74 button.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.color_parse('brown'))
75 b_label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse('pink'))
76 blink_state = False
77 else:
78 button.modify_bg(gtk.STATE_ACTIVE, gtk.gdk.color_parse('darkorange'))
79 button.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.color_parse('darkorange'))
80 b_label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse('lightyellow'))
81 blink_state = True
82 return True
84 # Create objects
85 window = gtk.Window()
86 window.set_title("JACK time wheel control")
87 window.set_resizable(False)
88 window.set_decorated(False)
90 button = gtk.ToggleButton()
91 button.set_active(False)
92 button.set_label(text_generic+"\n"+fw_off)
94 b_label = button.get_children()[0]
95 b_label.set_justify(gtk.JUSTIFY_CENTER)
96 b_label.set_use_markup(True)
98 blink_state = False
100 # Connections
101 window.connect("delete-event", gtk.main_quit);
102 button.connect("toggled", on_button_toggled);
103 window.add(button)
105 # Colors
106 button.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('darkgreen'))
107 button.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.color_parse('darkgreen'))
108 button.modify_bg(gtk.STATE_ACTIVE, gtk.gdk.color_parse('darkgreen'))
109 button.modify_bg(gtk.STATE_INSENSITIVE, gtk.gdk.color_parse('darkred'))
110 b_label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse('lightgreen'))
112 # JACK
113 jack.attach(jclient_name)
114 jack.activate()
115 glib.timeout_add(300, check_freewheel)
116 glib.timeout_add(700, blink_toggle)
118 window.show_all()
120 gtk.main()
122 jack.deactivate()
123 jack.detach()