4 xmms-status : A status widget for XMMS2.
6 Copyright (C) 2007 Sadrul Habib Chowdhury <sadrul@users.sourceforge.net>
8 This application is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
13 This application is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public
19 License along with this application; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301
25 import xmmsclient
.glib
as xg
26 import xmmsclient
.collections
as xc
34 __version__
= "0.0.1alpha"
35 __author__
= "Sadrul Habib Chowdhury <sadrul@users.sourceforge.net>"
36 __copyright__
= "Copyright 2007, Sadrul Habib Chowdhury"
40 sys
.setdefaultencoding("utf-8")
42 class XStatus(gnt
.Box
):
43 """A generic widget displaying the playback status of XMMS2."""
44 def __init__(self
, xmms
):
45 gnt
.Box
.__init
__(self
, False, False)
46 self
.set_property('vertical', True)
52 self
.tv
= gnt
.TextView()
53 self
.tv
.set_flag(gnt
.TEXT_VIEW_NO_SCROLL
)
54 self
.tv
.set_flag(gnt
.TEXT_VIEW_TOP_ALIGN
)
56 self
.tv
.append_text_with_flags("Title: ", gnt
.TEXT_FLAG_BOLD
)
57 self
.tv
.append_text_with_tag("...", gnt
.TEXT_FLAG_NORMAL
, "title")
58 self
.tv
.append_text_with_flags("\nArtist: ", gnt
.TEXT_FLAG_BOLD
)
59 self
.tv
.append_text_with_tag("...", gnt
.TEXT_FLAG_NORMAL
, "artist")
60 self
.tv
.append_text_with_flags("\nDuration: ", gnt
.TEXT_FLAG_BOLD
)
61 self
.tv
.append_text_with_tag(".../...", gnt
.TEXT_FLAG_NORMAL
, "playtime")
62 self
.tv
.set_size(-1, 3)
64 self
.status
= gnt
.Label(" " * 15)
65 self
.status
.set_property("text-flag", gnt
.TEXT_FLAG_BOLD
);
66 gnt
.unset_flag(self
.status
, gnt
.WIDGET_GROW_X
)
68 self
.progress
= gnt
.Slider(False, 1, 0)
69 gnt
.unset_flag(self
.progress
, gnt
.WIDGET_CAN_TAKE_FOCUS
)
71 self
.add_widget(self
.tv
)
72 self
.add_widget(common
.pack_widget(False, [self
.status
, self
.progress
]))
74 # Update playback status
75 self
.xmms
.broadcast_playback_status(self
.update_status
)
76 self
.xmms
.playback_status(self
.update_status
)
78 # Update playback time
79 self
.xmms
.signal_playback_playtime(self
.update_playtime
)
80 self
.xmms
.playback_playtime(self
.update_playtime
)
82 # Update song information
83 self
.xmms
.broadcast_playback_current_id(self
.update_song_info
)
84 self
.xmms
.playback_current_id(self
.update_song_info
)
86 def medialib_entry_changed(result
):
88 if song
== self
.current
['id']:
89 self
.update_song_info()
90 self
.xmms
.broadcast_medialib_entry_changed(medialib_entry_changed
)
92 def update_status(self
, result
):
95 if val
== xmmsclient
.PLAYBACK_STATUS_STOP
:
97 elif val
== xmmsclient
.PLAYBACK_STATUS_PLAY
:
99 elif val
== xmmsclient
.PLAYBACK_STATUS_PAUSE
:
101 self
.status
.set_text(status
)
103 def update_playtime(self
, result
):
104 val
= result
.value() / 1000
105 self
.tv
.tag_change("playtime", "%02d:%02d/%s" % (val
/ 60, val
% 60, self
.playtime
), True)
107 self
.progress
.set_value(val
)
110 def update_song(self
):
111 self
.tv
.tag_change("title", self
.current
['title'], True)
112 self
.tv
.tag_change("artist", self
.current
['artist'], True)
114 def update_song_info(self
, result
= None):
118 val
= self
.current
['id']
119 def received_song_info(result
):
120 self
.current
= result
.value()
121 playtime
= int(self
.current
.get('duration', 0) / 1000)
122 self
.progress
.set_range(0, playtime
)
123 self
.playtime
= "%02d:%02d" % (playtime
/ 60, playtime
% 60)
125 self
.xmms
.medialib_get_info(val
, received_song_info
)
130 win
.set_title("XMMS2 Status")
135 xmms
= xmmsclient
.XMMS("pygnt-search")
137 xmms
.connect(os
.getenv("XMMS_PATH"))
138 conn
= xg
.GLibConnector(xmms
)
141 except IOError, detail
:
142 common
.show_error("Connection failed: " + str(detail
))
144 if __name__
== '__main__':