optimized button_height
[panucci.git] / src / panucci / qtui / qtmain.py
blobb3df6d4bacf384df8c302c16e8387d1e9dea3bfe
1 # -*- coding: utf-8 -*-
3 # This file is part of Panucci.
4 # Copyright (c) 2008-2011 The Panucci Project
6 # Panucci 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 # Panucci 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 Panucci. If not, see <http://www.gnu.org/licenses/>.
19 from __future__ import absolute_import
21 import logging
22 import os.path
23 import cgi
24 from PySide import QtCore
25 from PySide import QtGui
27 try:
28 import pynotify
29 pynotify.init('Panucci')
30 have_pynotify = True
31 except:
32 have_pynotify = False
34 import panucci
35 from panucci import util
36 from panucci import platform
37 from panucci import playlist
38 from panucci.dbusinterface import interface
39 from panucci.services import ObservableService
40 from panucci.qtui import qtutil
41 from panucci.qtui import qtplaylist
42 from panucci.qtui import qtwidgets
44 ##################################################
45 # PanucciGUI
46 ##################################################
47 class PanucciGUI(object):
48 """ The object that holds the entire panucci gui """
50 def __init__(self, settings, filename=None):
51 self.__log = logging.getLogger('panucci.panucci.PanucciGUI')
52 interface.register_gui(self)
53 self.config = settings.config
54 self.playlist = playlist.Playlist(self.config)
56 self.app = QtGui.QApplication(["Panucci"])
57 self.app.setWindowIcon(QtGui.QIcon(util.find_data_file('panucci.png')))
58 self.main_window = QtGui.QMainWindow(None)
59 if platform.FREMANTLE:
60 self.main_window.setAttribute(QtCore.Qt.WA_Maemo5StackedWindow)
61 self.main_window.closeEvent = self.close_main_window_callback
62 self.create_actions()
63 self.__player_tab = PlayerTab(self)
64 self.__playlist_tab = qtplaylist.PlaylistTab(self, self.playlist)
65 if platform.MAEMO:
66 self.create_maemo_menus()
67 else:
68 self.create_menus()
69 widget = QtGui.QWidget()
70 widget.setLayout(self.__player_tab.mainbox)
71 self.main_window.setCentralWidget(widget)
72 self.main_window.show()
73 self.playlist.init(filepath=filename)
74 self.app.exec_()
76 def create_actions(self):
77 # File menu
78 self.action_add_file = QtGui.QAction(QtGui.QIcon(':/actions/add.png'), _("Add File").decode("utf-8"), self.main_window, shortcut="Ctrl+A",
79 statusTip="Add file to playlist", triggered=self.add_file_callback)
80 self.action_add_folder = QtGui.QAction(QtGui.QIcon(':/images/open.png'), _("Add Folder").decode("utf-8"), self.main_window, shortcut="Ctrl+D",
81 statusTip="Add folder to playlist", triggered=self.add_folder_callback)
82 self.action_save_playlist = QtGui.QAction(QtGui.QIcon(':/images/save.png'), _("Save Playlist").decode("utf-8"), self.main_window, shortcut="Ctrl+W",
83 statusTip="Save current playlist as m3u", triggered=self.save_playlist_callback)
84 self.action_clear_playlist = QtGui.QAction(QtGui.QIcon(':/images/trashcan.png'), _("Clear Playlist").decode("utf-8"), self.main_window, shortcut="Ctrl+H",
85 statusTip="Clear current playlist", triggered=self.clear_playlist_callback)
86 self.action_delete_bookmarks = QtGui.QAction(QtGui.QIcon(':/images/trashcan.png'), _("Delete All Bookmarks").decode("utf-8"), self.main_window, shortcut="Ctrl+K",
87 statusTip="Delete all bookmarks", triggered=self.delete_bookmarks_callback)
88 self.action_quit = QtGui.QAction(QtGui.QIcon('/usr/share/icons/gnome/16x16/actions/exit.png'), "Quit", self.main_window, shortcut="Ctrl+Q",
89 statusTip="Exit the application", triggered=self.quit_panucci)
90 # Tools menu
91 self.action_playlist = QtGui.QAction(_("Playlist"), self.main_window, shortcut="Ctrl+P",
92 statusTip=_("Open playlist"), triggered=self.playlist_callback)
93 self.action_settings = QtGui.QAction(_("Settings"), self.main_window, shortcut="Ctrl+C",
94 statusTip=_("Open settings dialog"), triggered=self.settings_callback)
95 self.action_timer = QtGui.QAction(_("Sleep Timer"), self.main_window, shortcut="Ctrl+T",
96 statusTip=_("Start a timed shutdown"), triggered=self.create_timer_dialog)
97 # Settings menu
98 self.action_lock_progress = QtGui.QAction(_("Lock Progress Bar").decode("utf-8"), self.main_window, shortcut="Ctrl+L",
99 statusTip="Lock progress bar", triggered=self.lock_progress_callback)
100 self.action_lock_progress.setCheckable(True)
101 self.action_lock_progress.setChecked(self.config.getboolean("options", "lock_progress"))
102 self.action_dual_action = QtGui.QAction(_("Dual Action Button").decode("utf-8"), self.main_window, shortcut="Ctrl+B",
103 statusTip="Set dual action button", triggered=self.dual_action_callback)
104 self.action_dual_action.setCheckable(True)
105 self.action_dual_action.setChecked(self.config.getboolean("options", "dual_action_button"))
106 self.action_stay_at_end = QtGui.QAction(_("Stay at End").decode("utf-8"), self.main_window, shortcut="Ctrl+E",
107 statusTip="Stay at file end", triggered=self.stay_at_end_callback)
108 self.action_stay_at_end.setCheckable(True)
109 self.action_stay_at_end.setChecked(self.config.getboolean("options", "stay_at_end"))
110 self.action_seek_back = QtGui.QAction(_("Seek Back").decode("utf-8"), self.main_window, shortcut="Ctrl+S",
111 statusTip="Seek back to previous file", triggered=self.seek_back_callback)
112 self.action_seek_back.setCheckable(True)
113 self.action_seek_back.setChecked(self.config.getboolean("options", "seek_back"))
114 self.action_scrolling_labels = QtGui.QAction(_("Scrolling Labels").decode("utf-8"), self.main_window, shortcut="Ctrl+V",
115 statusTip="Scroll title labels when too long", triggered=self.scrolling_labels_callback)
116 self.action_scrolling_labels.setCheckable(True)
117 self.action_scrolling_labels.setChecked(self.config.getboolean("options", "scrolling_labels"))
118 self.action_play_mode_all = QtGui.QAction(_("All").decode("utf-8"), self.main_window, statusTip="Set play mode",
119 triggered=self.play_mode_all_callback)
120 self.action_play_mode_all.setCheckable(True)
121 self.action_play_mode_single = QtGui.QAction(_("Single").decode("utf-8"), self.main_window, statusTip="Set play mode",
122 triggered=self.play_mode_single_callback)
123 self.action_play_mode_single.setCheckable(True)
124 self.action_play_mode_random = QtGui.QAction(_("Random").decode("utf-8"), self.main_window, statusTip="Set play mode",
125 triggered=self.play_mode_random_callback)
126 self.action_play_mode_random.setCheckable(True)
127 self.action_play_mode_repeat = QtGui.QAction(_("Repeat").decode("utf-8"), self.main_window, statusTip="Set play mode",
128 triggered=self.play_mode_repeat_callback)
129 self.action_play_mode_repeat.setCheckable(True)
130 actiongroup = QtGui.QActionGroup(self.main_window)
131 actiongroup.setExclusive(True)
132 self.action_play_mode_all.setActionGroup(actiongroup)
133 self.action_play_mode_single.setActionGroup(actiongroup)
134 self.action_play_mode_random.setActionGroup(actiongroup)
135 self.action_play_mode_repeat.setActionGroup(actiongroup)
136 if self.config.get("options", "play_mode") == "single":
137 self.action_play_mode_single.setChecked(True)
138 elif self.config.get("options", "play_mode") == "random":
139 self.action_play_mode_random.setChecked(True)
140 elif self.config.get("options", "play_mode") == "repeat":
141 self.action_play_mode_repeat.setChecked(True)
142 else:
143 self.action_play_mode_all.setChecked(True)
144 # help menu
145 self.action_about = QtGui.QAction(QtGui.QIcon('about.png'), _("About").decode("utf-8"), self.main_window,
146 statusTip="Show about dialog", triggered=self.about_callback)
148 def create_menus(self):
149 # File menu
150 self.menu_file = self.main_window.menuBar().addMenu(_("File").decode("utf-8"))
151 self.menu_file.addAction(self.action_add_file)
152 self.menu_file.addAction(self.action_add_folder)
153 self.menu_file.addAction(self.action_save_playlist)
154 self.menu_file.addAction(self.action_clear_playlist)
155 self.menu_file.addAction(self.action_delete_bookmarks)
156 self.menu_file.addSeparator()
157 self.menu_file.addAction(self.action_quit)
158 # Tools menu
159 self.menu_tools = self.main_window.menuBar().addMenu(_("Tools").decode("utf-8"))
160 self.menu_tools.addAction(self.action_playlist)
161 self.menu_tools.addAction(self.action_timer)
162 #self.menu_tools.addAction(self.action_settings)
163 # Settings menu
164 self.menu_settings = self.main_window.menuBar().addMenu(_("Settings").decode("utf-8"))
165 self.menu_settings.addAction(self.action_lock_progress)
166 self.menu_settings.addAction(self.action_dual_action)
167 self.menu_settings.addAction(self.action_stay_at_end)
168 self.menu_settings.addAction(self.action_seek_back)
169 self.menu_settings.addAction(self.action_scrolling_labels)
170 self.menu_play_mode = self.menu_settings.addMenu(_("Play Mode").decode("utf-8"))
171 self.menu_play_mode.addAction(self.action_play_mode_all)
172 self.menu_play_mode.addAction(self.action_play_mode_single)
173 self.menu_play_mode.addAction(self.action_play_mode_random)
174 self.menu_play_mode.addAction(self.action_play_mode_repeat)
175 # Help menu
176 self.menu_help = self.main_window.menuBar().addMenu(_("Help").decode("utf-8"))
177 self.menu_help.addAction(self.action_about)
179 def create_maemo_menus(self):
180 # Player menu
181 self.menu_player = self.main_window.menuBar().addMenu("Player")
182 self.menu_player.addAction(self.action_settings)
183 self.menu_player.addAction(self.action_playlist)
184 self.menu_player.addAction(self.action_add_file)
185 self.menu_player.addAction(self.action_add_folder)
186 self.menu_player.addAction(self.action_clear_playlist)
187 self.menu_player.addAction(self.action_timer)
188 self.menu_player.addAction(self.action_about)
189 # Playlist menu
190 self.menu_playlist = self.__playlist_tab.main_window.menuBar().addMenu("Playlist")
191 self.menu_playlist.addAction(self.action_save_playlist)
192 self.menu_playlist.addAction(self.action_delete_bookmarks)
194 def create_timer_dialog(self):
195 response = QtGui.QInputDialog.getInteger(self.main_window, _("Sleep Timer"), _("Shutdown time in minutes"),
196 value=5, minValue=1)
197 if response[1]:
198 QtCore.QTimer.singleShot(60000*response[0], self.quit_panucci)
200 def quit_panucci(self):
201 self.main_window.hide()
202 self.playlist.quit()
203 util.write_config(self.config)
204 self.app.exit()
206 def close_main_window_callback(self, event):
207 self.quit_panucci()
209 def show_main_window(self):
210 self.main_window.activateWindow()
212 def add_file_callback(self):
213 filenames = qtutil.get_file_from_filechooser(self)
214 if filenames:
215 self._play_file(filenames[0].encode('utf-8'))
217 def add_folder_callback(self):
218 filenames = qtutil.get_file_from_filechooser(self, folder=True)
219 if filenames:
220 self._play_file(filenames[0].encode('utf-8'))
222 def save_playlist_callback(self):
223 filenames = qtutil.get_file_from_filechooser(self, save_file=True, save_to=True)
224 if not filenames:
225 return False
227 filename = filenames[0]
228 if os.path.isfile(filename):
229 response = qtutil.dialog(self.main_window, _('File already exists!'),
230 _('The file %s already exists. You can choose another name or '
231 'overwrite the existing file.') % os.path.basename(filename), False, True, True, True)
233 if response == QtGui.QMessageBox.Cancel:
234 return None
235 elif response == QtGui.QMessageBox.Discard:
236 return self.save_playlist_callback()
238 ext = util.detect_filetype(filename)
239 if not self.playlist.save_to_new_playlist(filename, ext):
240 self.notify(_('Error saving playlist...'))
241 return False
243 return True
245 def clear_playlist_callback(self):
246 self.playlist.reset_playlist()
247 self.__playlist_tab.clear_model()
249 def delete_bookmarks_callback(self):
250 response = qtutil.dialog(self.main_window, _('Delete all bookmarks?'),
251 _('By accepting all bookmarks in the database will be deleted.'), True, False, True, False)
252 if response == QtGui.QMessageBox.Ok:
253 self.playlist.delete_all_bookmarks()
255 def playlist_callback(self):
256 self.__playlist_tab.main_window.show()
258 def settings_callback(self):
259 from panucci.qtui.qtsettingsdialog import SettingsDialog
260 SettingsDialog(self)
262 def lock_progress_callback(self):
263 self.set_config_option("lock_progress", str(self.action_lock_progress.isChecked()).lower())
265 def dual_action_callback(self):
266 self.set_config_option("dual_action_button", str(self.action_dual_action.isChecked()).lower())
268 def stay_at_end_callback(self):
269 self.set_config_option("stay_at_end", str(self.action_stay_at_end.isChecked()).lower())
271 def seek_back_callback(self):
272 self.set_config_option("seek_back", str(self.action_seek_back.isChecked()).lower())
274 def scrolling_labels_callback(self):
275 self.set_config_option("scrolling_labels", str(self.action_scrolling_labels.isChecked()).lower())
276 self.__player_tab.label_title.set_scrolling(self.config.getboolean("options", "scrolling_labels"))
278 def play_mode_all_callback(self):
279 self.set_config_option("play_mode", "all")
281 def play_mode_single_callback(self):
282 self.set_config_option("play_mode", "single")
284 def play_mode_random_callback(self):
285 self.set_config_option("play_mode", "random")
287 def play_mode_repeat_callback(self):
288 self.set_config_option("play_mode", "repeat")
290 def about_callback(self):
291 from panucci.qtui import qtaboutdialog
292 qtaboutdialog.AboutDialog(self.main_window, panucci.__version__)
294 def set_config_option(self, option, value):
295 self.config.set("options", option, value)
297 def _play_file(self, filename, pause_on_load=False):
298 self.playlist.load( os.path.abspath(filename) )
300 if self.playlist.is_empty:
301 return False
303 ##################################################
304 # PlayerTab
305 ##################################################
306 class PlayerTab(ObservableService):
307 """ The tab that holds the player elements """
309 signals = [ 'select-current-item-request', ]
311 def __init__(self, gui_root):
312 self.__log = logging.getLogger('panucci.panucci.PlayerTab')
313 self.__gui_root = gui_root
314 self.config = gui_root.config
315 self.playlist = gui_root.playlist
316 ObservableService.__init__(self, self.signals, self.__log)
318 self.playlist.player.register( 'stopped', self.on_player_stopped )
319 self.playlist.player.register( 'playing', self.on_player_playing )
320 self.playlist.player.register( 'paused', self.on_player_paused )
321 #self.playlist.player.register( 'eof', self.on_player_eof )
322 self.playlist.register( 'end-of-playlist', self.on_player_end_of_playlist )
323 self.playlist.register( 'new-track-loaded', self.on_player_new_track )
324 self.playlist.register( 'new-metadata-available', self.on_player_new_metadata )
325 self.playlist.register( 'reset-playlist', self.on_player_reset_playlist )
327 self.mainbox = QtGui.QVBoxLayout()
328 self.mainbox.setContentsMargins(0, 0, 0, 0)
329 self.mainbox.setSpacing(0)
331 layout = QtGui.QHBoxLayout()
332 layout.setContentsMargins(0, 0, 0, 0)
333 layout.setSpacing(0)
334 self.label_cover = QtGui.QLabel()
335 self.label_cover.setContentsMargins(0, 5, 2, 5)
336 layout.addWidget(self.label_cover)
337 vlayout = QtGui.QVBoxLayout()
338 vlayout.setContentsMargins(0, 0, 0, 0)
339 vlayout.setSpacing(0)
340 vlayout.addStretch(5)
341 self.label_artist = QtGui.QLabel()
342 self.label_album = QtGui.QLabel()
343 self.label_artist.setContentsMargins(3, 0, 5, 10)
344 self.label_album.setContentsMargins(3, 0, 5, 10)
345 self.label_title = qtwidgets.ScrollingLabel(self.config)
346 self.label_title.setContentsMargins(0, 0, 0, 0)
347 vlayout.addWidget(self.label_artist)
348 vlayout.addWidget(self.label_album)
349 vlayout.addWidget(self.label_title)
350 vlayout.addStretch(5)
351 layout.addLayout(vlayout, 2)
352 self.mainbox.addLayout(layout, 8)
354 self.progress = QtGui.QProgressBar()
355 self.progress.setContentsMargins(0, 0, 0, 0)
356 self.mainbox.addWidget(self.progress)
357 self.progress.setTextVisible(True)
358 self.progress.setFormat("00:00 / 00:00")
359 self.progress.setValue(0)
360 self.progress.mousePressEvent = self.on_progress_clicked
361 progress_height = self.config.getint("options", "progress_height")
362 if progress_height != -1:
363 self.progress.setFixedHeight(progress_height)
365 self.icon_play = QtGui.QIcon(util.find_data_file('media-playback-start.png'))
366 self.icon_pause = QtGui.QIcon(util.find_data_file('media-playback-pause.png'))
368 self.button_rrewind = qtwidgets.DualActionButton(self.config,
369 QtGui.QIcon(util.find_data_file('media-skip-backward.png')),
370 self.button_rrewind_callback,
371 QtGui.QIcon("/usr/share/icons/gnome/24x24/actions/gtk-goto-first-ltr.png"),
372 self.playlist.prev)
373 self.button_rewind = QtGui.QPushButton(QtGui.QIcon(util.find_data_file('media-seek-backward.png')), "")
374 self.button_rewind.clicked.connect(self.button_rewind_callback)
375 self.button_play = QtGui.QPushButton(self.icon_play, "")
376 self.button_play.clicked.connect(self.button_play_callback)
377 self.button_forward = QtGui.QPushButton(QtGui.QIcon(util.find_data_file('media-seek-forward.png')), "")
378 self.button_forward.clicked.connect(self.button_forward_callback)
379 self.button_fforward = qtwidgets.DualActionButton(self.config,
380 QtGui.QIcon(util.find_data_file('media-skip-forward.png')),
381 self.button_fforward_callback,
382 QtGui.QIcon("/usr/share/icons/gnome/24x24/actions/gtk-goto-last-ltr.png"),
383 self.playlist.next)
384 self.button_bookmark = QtGui.QPushButton(QtGui.QIcon(util.find_data_file('bookmark-new.png')), "")
385 self.button_bookmark.clicked.connect(self.button_bookmark_callback)
387 button_height = self.config.getint("options", "button_height")
388 if button_height != -1:
389 self.button_rrewind.setFixedHeight(button_height)
390 self.button_rewind.setFixedHeight(button_height)
391 self.button_play.setFixedHeight(button_height)
392 self.button_forward.setFixedHeight(button_height)
393 self.button_fforward.setFixedHeight(button_height)
394 self.button_bookmark.setFixedHeight(button_height)
396 layout = QtGui.QHBoxLayout()
397 layout.setContentsMargins(0, 4, 0, 0)
398 layout.setSpacing(0)
399 layout.addWidget(self.button_rrewind)
400 layout.addWidget(self.button_rewind)
401 layout.addWidget(self.button_play)
402 layout.addWidget(self.button_forward)
403 layout.addWidget(self.button_fforward)
404 layout.addWidget(self.button_bookmark)
405 self.mainbox.addLayout(layout)
407 self.timer = QtCore.QTimer()
408 self.timer.setInterval(1000);
409 self.timer.timeout.connect(self.timer_callback)
411 def on_player_stopped(self):
412 self.stop_progress_timer()
413 #self.set_controls_sensitivity(False)
414 self.button_play.setIcon(self.icon_play)
416 def on_player_playing(self):
417 self.start_progress_timer()
418 self.button_play.setIcon(self.icon_pause)
419 #self.set_controls_sensitivity(True)
421 def on_player_paused( self, position, duration ):
422 self.stop_progress_timer()
423 #self.set_progress_callback( position, duration )
424 self.button_play.setIcon(self.icon_play)
426 def on_player_new_track(self):
427 for widget in [self.label_title, self.label_artist, self.label_album, self.label_cover]:
428 widget.setText('')
429 self.label_cover.hide()
430 self.has_coverart = False
432 def on_player_new_metadata(self):
433 self.metadata = self.playlist.get_file_metadata()
434 self.set_metadata(self.metadata)
436 if not self.playlist.player.playing:
437 position = self.playlist.get_current_position()
438 estimated_length = self.metadata.get('length', 0)
439 self.set_progress_callback( position, estimated_length )
440 self.playlist.player.set_position_duration(position, 0)
442 def on_player_end_of_playlist(self, loop):
443 if not loop:
444 self.playlist.player.stop_end_of_playlist()
445 estimated_length = self.metadata.get('length', 0)
446 self.set_progress_callback( 0, estimated_length )
447 self.playlist.player.set_position_duration(0, 0)
449 def on_player_reset_playlist(self):
450 self.on_player_stopped()
451 self.on_player_new_track()
452 self.reset_progress()
453 self.__gui_root.main_window.setWindowTitle("Panucci")
455 def reset_progress(self):
456 self.set_progress_callback(0,0)
458 def button_rrewind_callback(self):
459 self.do_seek(-1*self.config.getint("options", "seek_long"))
461 def button_rewind_callback(self):
462 self.do_seek(-1*self.config.getint("options", "seek_short"))
464 def button_play_callback(self):
465 self.playlist.player.play_pause_toggle()
467 def button_forward_callback(self):
468 self.do_seek(self.config.getint("options", "seek_short"))
470 def button_fforward_callback(self):
471 self.do_seek(self.config.getint("options", "seek_long"))
473 def button_bookmark_callback(self):
474 self.playlist.player.add_bookmark_at_current_position()
476 def set_progress_callback(self, time_elapsed, total_time):
477 """ times must be in nanoseconds """
478 time_string = "%s / %s" % ( util.convert_ns(time_elapsed),
479 util.convert_ns(total_time) )
480 self.progress.setFormat( time_string )
481 fraction = float(time_elapsed) / float(total_time) if total_time else 0
482 self.progress.setValue( int(fraction*100) )
484 def on_progress_clicked(self, event):
485 if ( not self.config.getboolean("options", "lock_progress") and
486 event.button() == QtCore.Qt.MouseButton.LeftButton ):
487 new_fraction = float(event.x())/float(self.progress.width())
488 resp = self.playlist.player.do_seek(percent=new_fraction)
489 if resp:
490 # Preemptively update the progressbar to make seeking smoother
491 self.set_progress_callback( *resp )
493 def timer_callback( self ):
494 if self.playlist.player.playing and not self.playlist.player.seeking:
495 pos_int, dur_int = self.playlist.player.get_position_duration()
496 # This prevents bogus values from being set while seeking
497 if ( pos_int > 10**9 ) and ( dur_int > 10**9 ):
498 self.set_progress_callback( pos_int, dur_int )
499 return True
501 def start_progress_timer( self ):
502 self.timer.start()
504 def stop_progress_timer( self ):
505 self.timer.stop()
507 def get_cover_size(self):
508 if self.__gui_root.main_window.isFullScreen():
509 size = self.config.getint("options", "cover_full_height")
510 else:
511 size = self.config.getint("options", "cover_height")
512 return size
514 def set_cover_size(self):
515 if self.has_coverart:
516 size = self.get_cover_size()
517 pixmap = self.label_cover.pixmap().scaled(size, size, mode=QtCore.Qt.SmoothTransformation)
518 self.label_cover.setPixmap(pixmap)
520 def set_metadata( self, tag_message ):
521 tags = { 'title': self.label_title, 'artist': self.label_artist,
522 'album': self.label_album }
524 # set the coverart
525 if tag_message.has_key('image') and tag_message['image'] is not None:
526 value = tag_message['image']
528 try:
529 pixmap = QtGui.QPixmap()
530 pixmap.loadFromData(value)
531 size = self.get_cover_size()
532 pixmap = pixmap.scaled(size, size, mode=QtCore.Qt.SmoothTransformation)
533 self.label_cover.setPixmap(pixmap)
534 self.label_cover.show()
535 self.has_coverart = True
536 except Exception, e:
537 self.__log.exception('Error setting coverart...')
539 # set the text metadata
540 for tag,value in tag_message.iteritems():
541 if tags.has_key(tag) and value is not None and value.strip():
542 value = value.decode('utf-8')
543 if tag == "artist":
544 _str = '<big>' + cgi.escape(value) + '</big>'
545 elif tag == "album":
546 _str = cgi.escape(value)
547 elif tag == "title":
548 _str = '<b><big>' + cgi.escape(value) + '</big></b>'
549 if not platform.MAEMO:
550 value += ' - Panucci'
551 if platform.FREMANTLE and len(value) > 25:
552 value = value[:24] + '...'
553 self.__gui_root.main_window.setWindowTitle(value)
555 if not self.has_coverart:
556 tags[tag].setAlignment(QtCore.Qt.AlignHCenter)
557 else:
558 tags[tag].setAlignment(QtCore.Qt.AlignLeft)
559 try:
560 tags[tag].setText(_str)
561 except TypeError, e:
562 self.__log.exception(str(e))
564 tags[tag].show()
566 def do_seek(self, seek_amount):
567 resp = self.playlist.do_seek(seek_amount*10**9)
568 if resp:
569 # Preemptively update the progressbar to make seeking smoother
570 self.set_progress_callback( *resp )