/usr/share/pyshared/pithos/sound_menu.py is in pithos 0.3.17-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | # -*- coding: utf-8; tab-width: 4; indent-tabs-mode: nil; -*-
### BEGIN LICENSE
# Copyright (C) 2011 Rick Spencer <rick.spencer@canonical.com>
# Copyright (C) 2011-2012 Kevin Mehall <km@kevinmehall.net>
#This program is free software: you can redistribute it and/or modify it
#under the terms of the GNU General Public License version 3, as published
#by the Free Software Foundation.
#
#This program is distributed in the hope that it will be useful, but
#WITHOUT ANY WARRANTY; without even the implied warranties of
#MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
#PURPOSE. See the GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License along
#with this program. If not, see <http://www.gnu.org/licenses/>.
### END LICENSE
import dbus
import dbus.service
DESKTOP_NAME = 'pithos'
class PithosSoundMenu(dbus.service.Object):
def __init__(self, window):
"""
Creates a PithosSoundMenu object.
Requires a dbus loop to be created before the gtk mainloop,
typically by calling DBusGMainLoop(set_as_default=True).
"""
bus_str = """org.mpris.MediaPlayer2.%s""" % DESKTOP_NAME
bus_name = dbus.service.BusName(bus_str, bus=dbus.SessionBus())
dbus.service.Object.__init__(self, bus_name, "/org/mpris/MediaPlayer2")
self.window = window
self.song_changed()
self.window.connect("song-changed", self.songchange_handler)
self.window.connect("play-state-changed", self.playstate_handler)
def playstate_handler(self, window, state):
if state:
self.signal_playing()
else:
self.signal_paused()
def songchange_handler(self, window, song):
self.song_changed([song.artist], song.album, song.title, song.artRadio)
self.signal_playing()
def song_changed(self, artists = None, album = None, title = None, artUrl=''):
"""song_changed - sets the info for the current song.
This method is not typically overriden. It should be called
by implementations of this class when the player has changed
songs.
named arguments:
artists - a list of strings representing the artists"
album - a string for the name of the album
title - a string for the title of the song
"""
if artists is None:
artists = ["Artist Unknown"]
if album is None:
album = "Album Unknown"
if title is None:
title = "Title Unknown"
if artUrl is None:
artUrl = ''
self.__meta_data = dbus.Dictionary({"xesam:album":album,
"xesam:title":title,
"xesam:artist":artists,
"mpris:artUrl":artUrl,
}, "sv", variant_level=1)
@dbus.service.method('org.mpris.MediaPlayer2')
def Raise(self):
"""Bring the media player to the front when selected by the sound menu"""
self.window.bring_to_top()
@dbus.service.method(dbus.PROPERTIES_IFACE, in_signature='ss', out_signature='v')
def Get(self, interface, prop):
"""Get
A function necessary to implement dbus properties.
This function is only called by the Sound Menu, and should not
be overriden or called directly.
"""
my_prop = self.__getattribute__(prop)
return my_prop
@dbus.service.method(dbus.PROPERTIES_IFACE, in_signature='ssv')
def Set(self, interface, prop, value):
"""Set
A function necessary to implement dbus properties.
This function is only called by the Sound Menu, and should not
be overriden or called directly.
"""
my_prop = self.__getattribute__(prop)
my_prop = value
@dbus.service.method(dbus.PROPERTIES_IFACE, in_signature='s', out_signature='a{sv}')
def GetAll(self, interface):
"""GetAll
A function necessary to implement dbus properties.
This function is only called by the Sound Menu, and should not
be overriden or called directly.
"""
return [DesktopEntry, PlaybackStatus, MetaData]
@property
def DesktopEntry(self):
"""DesktopEntry
The name of the desktop file.
This propert is only used by the Sound Menu, and should not
be overriden or called directly.
"""
return DESKTOP_NAME
@property
def PlaybackStatus(self):
"""PlaybackStatus
Current status "Playing", "Paused", or "Stopped"
This property is only used by the Sound Menu, and should not
be overriden or called directly.
"""
if not self.window.current_song:
return "Stopped"
if self.window.playing:
return "Playing"
else:
return "Paused"
@property
def MetaData(self):
"""MetaData
The info for the current song.
This property is only used by the Sound Menu, and should not
be overriden or called directly.
"""
return self.__meta_data
@dbus.service.method('org.mpris.MediaPlayer2.Player')
def Next(self):
"""Next
This function is called when the user has clicked
the next button in the Sound Indicator.
"""
self.window.next_song()
@dbus.service.method('org.mpris.MediaPlayer2.Player')
def Previous(self):
"""Previous
This function is called when the user has clicked
the previous button in the Sound Indicator.
"""
pass
@dbus.service.method('org.mpris.MediaPlayer2.Player')
def PlayPause(self):
self.window.playpause()
def signal_playing(self):
"""signal_playing - Tell the Sound Menu that the player has
started playing.
"""
self.__playback_status = "Playing"
d = dbus.Dictionary({"PlaybackStatus":self.__playback_status, "Metadata":self.__meta_data},
"sv",variant_level=1)
self.PropertiesChanged("org.mpris.MediaPlayer2.Player",d,[])
def signal_paused(self):
"""signal_paused - Tell the Sound Menu that the player has
been paused
"""
self.__playback_status = "Paused"
d = dbus.Dictionary({"PlaybackStatus":self.__playback_status},
"sv",variant_level=1)
self.PropertiesChanged("org.mpris.MediaPlayer2.Player",d,[])
@dbus.service.signal(dbus.PROPERTIES_IFACE, signature='sa{sv}as')
def PropertiesChanged(self, interface_name, changed_properties,
invalidated_properties):
"""PropertiesChanged
A function necessary to implement dbus properties.
Typically, this function is not overriden or called directly.
"""
pass
|