Manually sync Italian translations.
[laditools.git] / ladi-player
bloba439ce41092f2513a8fc4aebf72e73db22dd9dd0
1 #!/usr/bin/python
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/>.
19 import os
20 import sys
21 import time
22 import gettext
23 import argparse
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
47 _default_config = {
48 'autostart' : False,
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,
56 self.config_dict)
57 self.global_config.save()
58 Gtk.main_quit()
60 def _run_select_studio_dialog(self, title, *args):
61 studio_list = self.get_ladish_controller().studio_list()
62 if not studio_list:
63 dlg = Gtk.MessageDialog(None,Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
64 Gtk.MessageType.INFO,
65 Gtk.ButtonsType.CLOSE,
66 _('No studio is available.'))
67 dlg.set_transient_for(self.window_main)
68 dlg.set_title(title)
69 dlg.run()
70 dlg.destroy()
71 return None
73 dlg = Gtk.Dialog()
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),
82 focus_column=column,
83 start_editing=False)
85 for studio in studio_list:
86 model.append((studio,))
88 dlg.set_transient_for(self.window_main)
89 dlg.set_modal(True)
90 dlg.set_destroy_with_parent(True)
91 dlg.set_title(title)
92 dlg.get_content_area().pack_start(child=treeview,
93 expand=True,
94 fill=True,
95 padding=10)
96 dlg.add_button(Gtk.STOCK_OK, Gtk.ResponseType.OK)
97 dlg.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
98 dlg.show_all()
100 response = dlg.run()
101 ret = None
102 if response == Gtk.ResponseType.OK:
103 path, column = treeview.get_cursor()
104 ret = model[path][0]
105 dlg.hide()
106 return ret
108 def _toolbuttons_set_active(self, group, **kwargs):
109 buttons = getattr(self, "%s_status_buttons" % group)
110 if 'all' in kwargs:
111 status = kwargs['all']
112 for button in buttons:
113 buttons[button].set_sensitive(status)
114 else:
115 for button in kwargs:
116 buttons[button].set_sensitive(kwargs[button])
118 def jack_is_started(self, *args, **kwargs):
119 while True:
120 try:
121 return LadiManagerGtk.jack_is_started(self, *args, **kwargs)
122 except:
123 time.sleep(0.5)
124 continue
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)
141 else:
142 self.ladish_toolbuttons_set_active(start=True, stop=False, save=False)
143 else:
144 self.ladish_toolbuttons_set_active(start=True,
145 stop=False,
146 save=False,
147 unload=False,
148 rename=False)
149 else:
150 self.ladish_toolbuttons_set_active(all=False)
152 def jack_status_buttons_update(self):
153 if not self.jack_is_available():
154 return
156 buttons = self.jack_status_buttons
157 ladish_available = self.ladish_is_available()
158 jack_started = self.jack_is_started()
160 if jack_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)
165 else:
166 self.jack_toolbuttons_set_active(jack_start=True,
167 jack_stop=False,
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)
175 return
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:
182 if a2j_started:
183 self.a2j_toolbuttons_set_active(a2j_start=False,
184 a2j_stop=True,
185 a2j_reactivate=True)
186 else:
187 self.a2j_toolbuttons_set_active(a2j_start=True,
188 a2j_stop=False,
189 a2j_reactivate=True)
190 else:
191 self.a2j_toolbuttons_set_active(a2j_start=False,
192 a2j_stop=False,
193 a2j_reactivate=True)
195 def update_status_buttons(self):
197 # Update widgets
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 | "
207 else:
208 status_text = ""
209 # Get DSP Load
210 status_text += str (round (float (self.jack_get_load()),1)) + "% | "
211 # Get Xruns
212 status_text += str (self.jack_get_xruns())
213 # Set a started status
214 self.status_label.set_label (status_text)
215 else:
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)
222 return True
224 def _set_starting_status(self):
225 self.window_main.set_icon_name("ladi-starting")
227 def action_ladish_new(self, action, *args):
228 self.studio_new()
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()
234 self.studio_start()
235 self.update_status_buttons()
236 else:
237 self._set_starting_status()
238 self.jack_start()
239 self.update_status_buttons()
241 def action_ladish_save(self, action, *args):
242 self.studio_save()
244 def action_ladish_stop(self, action, *args):
245 if self.jack_is_started() and self.studio_is_started():
246 self.studio_stop()
247 self.update_status_buttons()
249 def action_ladish_rename(self, action, *args):
250 self.studio_rename()
251 self.update_status_buttons()
253 def action_ladish_load(self, action, *args):
254 selection = self._run_select_studio_dialog(_('Load studio'))
255 if selection:
256 self.studio_load(studio=selection)
257 return selection
259 def action_ladish_delete(self, action, *args):
260 selection = self._run_select_studio_dialog(_('Delete studio'))
261 if selection:
262 LadiManager.studio_delete(self, studio=selection)
263 return selection
265 def action_ladish_unload(self, action, *args):
266 while True:
267 try:
268 if self.studio_is_loaded():
269 self.studio_unload()
270 self.update_status_buttons()
271 break
272 except:
273 time.sleep(0.5)
274 continue
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()
281 self.jack_start()
282 def action_jack_stop(self, action, *args):
283 self.jack_stop()
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):
290 self.a2j_start()
291 def action_a2j_stop(self, action, *args):
292 self.a2j_stop()
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()))
299 def __init__(self):
300 # Initialize app
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)
309 # Handle signals
310 self.connect_signals_quit()
312 # Build the UI
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)
317 sys.stderr.flush()
319 # Retrieve objects
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)
347 # Accelerators
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
354 self.update ()
355 # Add the auto update callback
356 self.auto_updater = timeout_add (250, self.update, None)
358 builder.connect_signals(self)
360 def run(self):
361 self.window_main.show_all()
362 Gtk.main()
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())
369 parser.parse_args()
371 Gtk.init(None)
373 LadiPlayer().run()
375 sys.exit(0)