2 # LADITools - Linux Audio Desktop Integration Tools
3 # laditray - System tray integration for LADI
4 # Copyright (C) 2012 Alessio Treglia <quadrispro@ubuntu.com>
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 from laditools
import _gettext_domain
26 gettext
.install(_gettext_domain
)
28 from laditools
import get_version_string
29 from laditools
import LadiConfiguration
30 from laditools
import LadiApp
32 from gi
.repository
import Gtk
33 from gi
.repository
import GObject
34 from laditools
import LadiManager
35 from laditools
.gtk
import LadiManagerGtk
36 from laditools
.gtk
import find_data_file
38 timeout_add
= GObject
.timeout_add
40 class LadiPlayer(LadiManagerGtk
, LadiApp
):
42 _appname
= 'ladi-player'
43 _appname_long
= _("LADI Player")
44 _appid
= 'org.linuxaudio.ladi.player'
46 # Default configuration
51 def on_about(self
, *args
):
52 LadiManagerGtk
.on_about(self
, parent
=self
.window_main
, version
=get_version_string())
54 def quit(self
, *args
, **kwargs
):
55 self
.global_config
.set_config_section (self
.appname
,
57 self
.global_config
.save()
60 def _run_select_studio_dialog(self
, title
, *args
):
61 studio_list
= self
.get_ladish_controller().studio_list()
63 dlg
= Gtk
.MessageDialog(None,Gtk
.DialogFlags
.MODAL | Gtk
.DialogFlags
.DESTROY_WITH_PARENT
,
65 Gtk
.ButtonsType
.CLOSE
,
66 _('No studio is available.'))
67 dlg
.set_transient_for(self
.window_main
)
74 treeview
= Gtk
.TreeView()
75 model
= Gtk
.ListStore(GObject
.TYPE_STRING
)
76 renderer
= Gtk
.CellRendererText()
77 column
= Gtk
.TreeViewColumn('Available studios', renderer
, text
=0)
79 treeview
.set_model(model
)
80 treeview
.append_column(column
)
81 treeview
.set_cursor(Gtk
.TreePath(path
=0),
85 for studio
in studio_list
:
86 model
.append((studio
,))
88 dlg
.set_transient_for(self
.window_main
)
90 dlg
.set_destroy_with_parent(True)
92 dlg
.get_content_area().pack_start(child
=treeview
,
96 dlg
.add_button(Gtk
.STOCK_OK
, Gtk
.ResponseType
.OK
)
97 dlg
.add_button(Gtk
.STOCK_CANCEL
, Gtk
.ResponseType
.CANCEL
)
102 if response
== Gtk
.ResponseType
.OK
:
103 path
, column
= treeview
.get_cursor()
108 def _toolbuttons_set_active(self
, group
, **kwargs
):
109 buttons
= getattr(self
, "%s_status_buttons" % group
)
111 status
= kwargs
['all']
112 for button
in buttons
:
113 buttons
[button
].set_sensitive(status
)
115 for button
in kwargs
:
116 buttons
[button
].set_sensitive(kwargs
[button
])
118 def jack_is_started(self
, *args
, **kwargs
):
121 return LadiManagerGtk
.jack_is_started(self
, *args
, **kwargs
)
126 def ladish_toolbuttons_set_active(self
, **kwargs
): self
._toolbuttons
_set
_active
('ladish', **kwargs
)
127 def jack_toolbuttons_set_active(self
, **kwargs
): self
._toolbuttons
_set
_active
('jack', **kwargs
)
128 def a2j_toolbuttons_set_active(self
, **kwargs
): self
._toolbuttons
_set
_active
('a2j', **kwargs
)
130 def ladish_status_buttons_update(self
):
131 buttons
= self
.ladish_status_buttons
133 # Setup ladish controls
134 if self
.ladish_is_available():
135 # Buttons "rename" and "unload"
136 if self
.studio_is_loaded():
137 self
.ladish_toolbuttons_set_active(unload
=True, rename
=True)
138 # Buttons "start" and "stop"
139 if self
.studio_is_started():
140 self
.ladish_toolbuttons_set_active(start
=False, stop
=True, save
=True)
142 self
.ladish_toolbuttons_set_active(start
=True, stop
=False, save
=False)
144 self
.ladish_toolbuttons_set_active(start
=True,
150 self
.ladish_toolbuttons_set_active(all
=False)
152 def jack_status_buttons_update(self
):
153 if not self
.jack_is_available():
156 buttons
= self
.jack_status_buttons
157 ladish_available
= self
.ladish_is_available()
158 jack_started
= self
.jack_is_started()
161 self
.jack_toolbuttons_set_active(jack_start
=False,
162 jack_stop
=(not ladish_available
),
163 jack_reset_xruns
=True,
164 jack_reactivate
=True)
166 self
.jack_toolbuttons_set_active(jack_start
=True,
168 jack_reset_xruns
=False,
169 jack_reactivate
=True)
172 def a2j_status_buttons_update(self
):
173 if not self
.a2j_is_available():
174 self
.a2j_toolbuttons_set_active(all
=False)
177 buttons
= self
.a2j_status_buttons
178 ladish_available
= self
.ladish_is_available()
179 a2j_started
= self
.a2j_is_started()
181 if not ladish_available
:
183 self
.a2j_toolbuttons_set_active(a2j_start
=False,
187 self
.a2j_toolbuttons_set_active(a2j_start
=True,
191 self
.a2j_toolbuttons_set_active(a2j_start
=False,
195 def update_status_buttons(self
):
198 self
.ladish_status_buttons_update()
199 self
.jack_status_buttons_update()
200 self
.a2j_status_buttons_update()
202 # Update status label and window icon
203 if self
.jack_is_started():
204 self
.window_main
.set_icon_name("ladi-started")
205 if self
.jack_is_realtime():
206 status_text
= "RT | "
210 status_text
+= str (round (float (self
.jack_get_load()),1)) + "% | "
212 status_text
+= str (self
.jack_get_xruns())
213 # Set a started status
214 self
.status_label
.set_label (status_text
)
216 self
.window_main
.set_icon_name("ladi-stopped")
217 self
.status_label
.set_label(_('<i>Stopped</i>'))
219 def update(self
, *args
, **kwargs
):
220 self
.update_status_buttons()
221 LadiManagerGtk
.update(self
, *args
, **kwargs
)
224 def _set_starting_status(self
):
225 self
.window_main
.set_icon_name("ladi-starting")
227 def action_ladish_new(self
, action
, *args
):
230 def action_ladish_start(self
, action
, *args
):
231 if self
.studio_is_loaded():
232 if not self
.studio_is_started():
233 self
._set
_starting
_status
()
235 self
.update_status_buttons()
237 self
._set
_starting
_status
()
239 self
.update_status_buttons()
241 def action_ladish_save(self
, action
, *args
):
244 def action_ladish_stop(self
, action
, *args
):
245 if self
.jack_is_started() and self
.studio_is_started():
247 self
.update_status_buttons()
249 def action_ladish_rename(self
, action
, *args
):
251 self
.update_status_buttons()
253 def action_ladish_load(self
, action
, *args
):
254 selection
= self
._run
_select
_studio
_dialog
(_('Load studio'))
256 self
.studio_load(studio
=selection
)
259 def action_ladish_delete(self
, action
, *args
):
260 selection
= self
._run
_select
_studio
_dialog
(_('Delete studio'))
262 LadiManager
.studio_delete(self
, studio
=selection
)
265 def action_ladish_unload(self
, action
, *args
):
268 if self
.studio_is_loaded():
270 self
.update_status_buttons()
276 def action_ladish_reactivate(self
, action
, *args
):
277 self
.ladish_reactivate()
279 def action_jack_start(self
, action
, *args
):
280 self
._set
_starting
_status
()
282 def action_jack_stop(self
, action
, *args
):
284 def action_jack_reset_xruns(self
, action
, *args
):
285 self
.jack_reset_xruns()
286 def action_jack_reactivate(self
, action
, *args
):
287 self
.jack_reactivate()
289 def action_a2j_start(self
, action
, *args
):
291 def action_a2j_stop(self
, action
, *args
):
293 def action_a2j_reactivate(self
, action
, *args
):
294 self
.a2j_reactivate()
296 def action_launcher_launch(self
, action
, *args
):
297 self
.launcher_exec(command
=self
._launcher
_which
(action
.get_name()))
301 LadiApp
.__init
__(self
)
302 # Handle the configuration
303 self
.global_config
= LadiConfiguration(self
.appname
, self
._default
_config
)
304 self
.config_dict
= self
.global_config
.get_config_section (self
.appname
)
305 autostart
= bool(eval(self
.config_dict
['autostart']))
307 LadiManagerGtk
.__init
__(self
, autostart
)
310 self
.connect_signals_quit()
313 builder
= Gtk
.Builder()
314 ui_path
= find_data_file("ladi-player.ui")
315 builder
.add_from_file(ui_path
)
316 sys
.stderr
.write( _("Loading interface from %s\n") % ui_path
)
320 self
.window_main
= builder
.get_object("window_main")
321 actiongroup_ladish
= builder
.get_object("actiongroup_ladish")
322 actiongroup_jack
= builder
.get_object("actiongroup_jack")
323 actiongroup_a2j
= builder
.get_object("actiongroup_a2j")
324 actiongroup_launcher
= builder
.get_object("actiongroup_launcher")
325 self
.status_label
= builder
.get_object('toolbutton_label_status')
327 # Setup status buttons
328 self
.ladish_status_buttons
= ladish_status_buttons
= {}
329 self
.jack_status_buttons
= jack_status_buttons
= {}
330 self
.a2j_status_buttons
= a2j_status_buttons
= {}
331 self
.launcher_status_buttons
= launcher_status_buttons
= {}
333 for action
in actiongroup_ladish
.list_actions():
334 ladish_status_buttons
[action
.get_name()] = action
335 for action
in actiongroup_jack
.list_actions():
336 jack_status_buttons
[action
.get_name()] = action
337 for action
in actiongroup_a2j
.list_actions():
338 a2j_status_buttons
[action
.get_name()] = action
339 for action
in actiongroup_launcher
.list_actions():
340 launcher_status_buttons
[action
.get_name()] = action
342 # Remove launchers for unavailable commands
343 for command
in launcher_status_buttons
:
344 if not self
._launcher
_which
(command
):
345 launcher_status_buttons
[command
].set_active(False)
348 # accelgroup = builder.get_object("accelgroup1")
349 # action = actiongroup_launcher.get_action("gladish")
350 # action.set_accel_group(accelgroup)
351 # action.set_accel_path("menu_studio")
353 # Get the initial status
355 # Add the auto update callback
356 self
.auto_updater
= timeout_add (250, self
.update
, None)
358 builder
.connect_signals(self
)
361 self
.window_main
.show_all()
364 if __name__
== "__main__":
365 parser
= argparse
.ArgumentParser(description
=_('graphical front-end that allows users to start, stop and '
366 'monitor JACK, as well as start some JACK related applications.'),
367 epilog
=_('This program is part of the LADITools suite.'))
368 parser
.add_argument('--version', action
='version', version
="%(prog)s " + get_version_string())