~ubuntu-branches/ubuntu/karmic/quodlibet/karmic

« back to all changes in this revision

Viewing changes to quodlibet/qltk/info.py

  • Committer: Bazaar Package Importer
  • Author(s): Luca Falavigna
  • Date: 2009-01-30 23:55:34 UTC
  • mfrom: (1.1.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20090130235534-l4e72ulw0vqfo17w
Tags: 2.0-1ubuntu1
* Merge from Debian experimental (LP: #276856), remaining Ubuntu changes:
  + debian/patches/40-use-music-profile.patch:
    - Use the "Music and Movies" pipeline per default.
* Refresh the above patch for new upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
# Copyright 2004-2005 Joe Wreschnig, Michael Urman, Iñigo Serna
 
3
#
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License version 2 as
 
6
# published by the Free Software Foundation
 
7
#
 
8
# $Id: info.py 4330 2008-09-14 03:19:26Z piman $
 
9
 
 
10
import os
 
11
 
 
12
import gtk
 
13
import pango
 
14
 
 
15
from quodlibet import const
 
16
from quodlibet import qltk
 
17
from quodlibet import stock
 
18
from quodlibet.qltk.properties import SongProperties
 
19
from quodlibet.qltk.information import Information
 
20
 
 
21
from quodlibet.parse import XMLFromPattern
 
22
from quodlibet.qltk.textedit import PatternEdit
 
23
 
 
24
class SongInfo(gtk.Label):
 
25
    _pattern = """\
 
26
\\<span weight='bold' size='large'\\><title>\\</span\\>\
 
27
<~length| (<~length>)><version|
 
28
\\<small\\>\\<b\\><version>\\</b\\>\\</small\\>><~people|
 
29
%(people)s><album|
 
30
\\<b\\><album>\\</b\\><discnumber| - %(disc)s>\
 
31
<discsubtitle| - \\<b\\><discsubtitle>\\</b\\>><tracknumber| - %(track)s>>"""%{
 
32
        # Translators: As in "by Artist Name"
 
33
        "people": _("by %s") % "<~people>",
 
34
        "disc": _("Disc %s") % "<discnumber>",
 
35
        "track": _("Track %s") % "<tracknumber>"
 
36
        }
 
37
 
 
38
    __PATTERN_FILENAME = os.path.join(const.USERDIR, "songinfo")
 
39
 
 
40
    def __init__(self, library, player):
 
41
        super(SongInfo, self).__init__()
 
42
        self.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
 
43
        self.set_selectable(True)
 
44
        self.set_alignment(0.0, 0.0)
 
45
        library.connect_object('changed', self.__check_change, player)
 
46
        player.connect('song-started', self.__check_started)
 
47
 
 
48
        self.connect_object('populate-popup', self.__menu, player, library)
 
49
 
 
50
        try: self._pattern = file(self.__PATTERN_FILENAME).read().rstrip()
 
51
        except EnvironmentError: pass
 
52
        self._compiled = XMLFromPattern(self._pattern)
 
53
 
 
54
    def __menu(self, player, menu, library):
 
55
        item = qltk.MenuItem(_("_Edit Display..."), gtk.STOCK_EDIT)
 
56
        item.show()
 
57
        item.connect_object('activate', self.__edit, player)
 
58
        menu.append(item)
 
59
 
 
60
        sep = gtk.SeparatorMenuItem()
 
61
        menu.append(sep)
 
62
        sep.show()
 
63
        props = gtk.ImageMenuItem(stock.EDIT_TAGS)
 
64
        props.connect_object(
 
65
            'activate', SongProperties, library, [player.song])
 
66
        props.show()
 
67
        props.set_sensitive(bool(player.song))
 
68
        menu.append(props)
 
69
        info = gtk.ImageMenuItem(gtk.STOCK_INFO)
 
70
        info.connect_object(
 
71
            'activate', Information, library, [player.song])
 
72
        info.show()
 
73
        menu.append(info)
 
74
        info.set_sensitive(bool(player.song))
 
75
 
 
76
    def __edit(self, player):
 
77
        editor = PatternEdit(self, SongInfo._pattern)
 
78
        editor.text = self._pattern
 
79
        editor.apply.connect_object('clicked', self.__set, editor, player)
 
80
 
 
81
    def __set(self, edit, player):
 
82
        self._pattern = edit.text.rstrip()
 
83
        if (self._pattern == SongInfo._pattern):
 
84
            try: os.unlink(self.__PATTERN_FILENAME)
 
85
            except OSError: pass
 
86
        else:
 
87
            pattern_file = file(os.path.join(const.USERDIR, "songinfo"), "w")
 
88
            pattern_file.write(self._pattern + "\n")
 
89
            pattern_file.close()
 
90
        self._compiled = XMLFromPattern(self._pattern)
 
91
        self.__update_info(player)
 
92
 
 
93
    def __check_change(self, player, songs):
 
94
        if player.info in songs:
 
95
            self.__update_info(player)
 
96
 
 
97
    def __check_started(self, player, song):
 
98
        self.__update_info(player)
 
99
 
 
100
    def __update_info(self, player):
 
101
        if player.info is not None:
 
102
            text = self._compiled % player.info
 
103
        else:
 
104
            text = "<span size='xx-large'>%s</span>" % _("Not playing")
 
105
        self.set_markup(text)