| 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 |
import dbus |
|---|
| 36 |
import dbus.glib |
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
import gtk |
|---|
| 40 |
import gtk.glade |
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
import gobject |
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
import os |
|---|
| 47 |
|
|---|
| 48 |
global win_position |
|---|
| 49 |
|
|---|
| 50 |
global playing |
|---|
| 51 |
playing = False |
|---|
| 52 |
|
|---|
| 53 |
global shuffle |
|---|
| 54 |
global repeat |
|---|
| 55 |
global loop |
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
shuffle = False |
|---|
| 59 |
repeat = False |
|---|
| 60 |
loop = False |
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
global root |
|---|
| 64 |
global player |
|---|
| 65 |
global tracklist |
|---|
| 66 |
|
|---|
| 67 |
global bus |
|---|
| 68 |
global identity |
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
def NameOwnerChanged(name, new, old): |
|---|
| 74 |
if old != "" and "org.mpris." in name: |
|---|
| 75 |
Connect(name) |
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
def TrackChange(Track): |
|---|
| 79 |
|
|---|
| 80 |
try: |
|---|
| 81 |
a = Track["artist"] |
|---|
| 82 |
except: |
|---|
| 83 |
a = "" |
|---|
| 84 |
try: |
|---|
| 85 |
t = Track["title"] |
|---|
| 86 |
except: |
|---|
| 87 |
t = Track["URI"] |
|---|
| 88 |
try: |
|---|
| 89 |
length = Track["length"] |
|---|
| 90 |
except: |
|---|
| 91 |
length = 0 |
|---|
| 92 |
if length > 0: |
|---|
| 93 |
time_s.set_range(0,Track["length"]) |
|---|
| 94 |
time_s.set_sensitive(True) |
|---|
| 95 |
else: |
|---|
| 96 |
|
|---|
| 97 |
time_s.set_sensitive(False) |
|---|
| 98 |
|
|---|
| 99 |
l_artist.set_text(a) |
|---|
| 100 |
l_title.set_text(t) |
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
def Connect(name): |
|---|
| 104 |
global root, player, tracklist |
|---|
| 105 |
global playing, identity |
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
root_o = bus.get_object(name, "/") |
|---|
| 109 |
player_o = bus.get_object(name, "/Player") |
|---|
| 110 |
tracklist_o = bus.get_object(name, "/TrackList") |
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
root = dbus.Interface(root_o, "org.freedesktop.MediaPlayer") |
|---|
| 114 |
tracklist = dbus.Interface(tracklist_o, "org.freedesktop.MediaPlayer") |
|---|
| 115 |
player = dbus.Interface(player_o, "org.freedesktop.MediaPlayer") |
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
player_o.connect_to_signal("TrackChange", TrackChange, dbus_interface="org.freedesktop.MediaPlayer") |
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
if player.GetStatus() == 0: |
|---|
| 122 |
playing = True |
|---|
| 123 |
TrackChange(player.GetMetadata()) |
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
identity = root.Identity() |
|---|
| 127 |
window.set_title(identity) |
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
def AddTrack(widget): |
|---|
| 131 |
mrl = e_mrl.get_text() |
|---|
| 132 |
if mrl != None and mrl != "": |
|---|
| 133 |
tracklist.AddTrack(mrl, True) |
|---|
| 134 |
e_mrl.set_text('') |
|---|
| 135 |
else: |
|---|
| 136 |
mrl = bt_file.get_filename() |
|---|
| 137 |
if mrl != None and mrl != "": |
|---|
| 138 |
tracklist.AddTrack("directory://" + mrl, True) |
|---|
| 139 |
update(0) |
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 |
def Next(widget): |
|---|
| 144 |
player.Next(reply_handler=(lambda *args: None), error_handler=(lambda *args: None)) |
|---|
| 145 |
update(0) |
|---|
| 146 |
|
|---|
| 147 |
def Prev(widget): |
|---|
| 148 |
player.Prev(reply_handler=(lambda *args: None), error_handler=(lambda *args: None)) |
|---|
| 149 |
update(0) |
|---|
| 150 |
|
|---|
| 151 |
def Stop(widget): |
|---|
| 152 |
player.Stop(reply_handler=(lambda *args: None), error_handler=(lambda *args: None)) |
|---|
| 153 |
update(0) |
|---|
| 154 |
|
|---|
| 155 |
def Quit(widget): |
|---|
| 156 |
root.Quit(reply_handler=(lambda *args: None), error_handler=(lambda *args: None)) |
|---|
| 157 |
l_title.set_text("") |
|---|
| 158 |
|
|---|
| 159 |
def Pause(widget): |
|---|
| 160 |
player.Pause() |
|---|
| 161 |
status = player.GetStatus() |
|---|
| 162 |
if status == 0: |
|---|
| 163 |
img_bt_toggle.set_from_stock(gtk.STOCK_MEDIA_PAUSE, gtk.ICON_SIZE_SMALL_TOOLBAR) |
|---|
| 164 |
else: |
|---|
| 165 |
img_bt_toggle.set_from_stock(gtk.STOCK_MEDIA_PLAY, gtk.ICON_SIZE_SMALL_TOOLBAR) |
|---|
| 166 |
update(0) |
|---|
| 167 |
|
|---|
| 168 |
def Repeat(widget): |
|---|
| 169 |
global repeat |
|---|
| 170 |
repeat = not repeat |
|---|
| 171 |
player.Repeat(repeat) |
|---|
| 172 |
|
|---|
| 173 |
def Shuffle(widget): |
|---|
| 174 |
global shuffle |
|---|
| 175 |
shuffle = not shuffle |
|---|
| 176 |
tracklist.Random(shuffle) |
|---|
| 177 |
|
|---|
| 178 |
def Loop(widget): |
|---|
| 179 |
global loop |
|---|
| 180 |
loop = not loop |
|---|
| 181 |
tracklist.Loop(loop) |
|---|
| 182 |
|
|---|
| 183 |
|
|---|
| 184 |
def update(widget): |
|---|
| 185 |
Track = player.GetMetadata() |
|---|
| 186 |
vol.set_value(player.VolumeGet()) |
|---|
| 187 |
try: |
|---|
| 188 |
a = Track["artist"] |
|---|
| 189 |
except: |
|---|
| 190 |
a = "" |
|---|
| 191 |
try: |
|---|
| 192 |
t = Track["title"] |
|---|
| 193 |
except: |
|---|
| 194 |
t = "" |
|---|
| 195 |
if t == "": |
|---|
| 196 |
try: |
|---|
| 197 |
t = Track["URI"] |
|---|
| 198 |
except: |
|---|
| 199 |
t = "" |
|---|
| 200 |
l_artist.set_text(a) |
|---|
| 201 |
l_title.set_text(t) |
|---|
| 202 |
try: |
|---|
| 203 |
length = Track["length"] |
|---|
| 204 |
except: |
|---|
| 205 |
length = 0 |
|---|
| 206 |
if length > 0: |
|---|
| 207 |
time_s.set_range(0,Track["length"]) |
|---|
| 208 |
time_s.set_sensitive(True) |
|---|
| 209 |
else: |
|---|
| 210 |
|
|---|
| 211 |
time_s.set_sensitive(False) |
|---|
| 212 |
GetPlayStatus(0) |
|---|
| 213 |
|
|---|
| 214 |
|
|---|
| 215 |
def volchange(widget, data): |
|---|
| 216 |
player.VolumeSet(vol.get_value_as_int(), reply_handler=(lambda *args: None), error_handler=(lambda *args: None)) |
|---|
| 217 |
|
|---|
| 218 |
|
|---|
| 219 |
def timechange(widget, x=None, y=None): |
|---|
| 220 |
player.PositionSet(int(time_s.get_value()), reply_handler=(lambda *args: None), error_handler=(lambda *args: None)) |
|---|
| 221 |
|
|---|
| 222 |
|
|---|
| 223 |
def timeset(): |
|---|
| 224 |
global playing |
|---|
| 225 |
if playing == True: |
|---|
| 226 |
try: |
|---|
| 227 |
time_s.set_value(player.PositionGet()) |
|---|
| 228 |
except: |
|---|
| 229 |
playing = False |
|---|
| 230 |
return True |
|---|
| 231 |
|
|---|
| 232 |
|
|---|
| 233 |
def expander(widget): |
|---|
| 234 |
if exp.get_expanded() == False: |
|---|
| 235 |
exp.set_label("Less") |
|---|
| 236 |
else: |
|---|
| 237 |
exp.set_label("More") |
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 |
def delete_event(self, widget): |
|---|
| 241 |
self.hide() |
|---|
| 242 |
return True |
|---|
| 243 |
|
|---|
| 244 |
|
|---|
| 245 |
def destroy(widget): |
|---|
| 246 |
gtk.main_quit() |
|---|
| 247 |
|
|---|
| 248 |
|
|---|
| 249 |
def key_release(widget, event): |
|---|
| 250 |
if event.keyval == gtk.keysyms.Escape: |
|---|
| 251 |
global win_position |
|---|
| 252 |
win_position = window.get_position() |
|---|
| 253 |
widget.hide() |
|---|
| 254 |
|
|---|
| 255 |
|
|---|
| 256 |
def tray_button(widget): |
|---|
| 257 |
global win_position |
|---|
| 258 |
if window.get_property('visible'): |
|---|
| 259 |
|
|---|
| 260 |
win_position = window.get_position() |
|---|
| 261 |
window.hide() |
|---|
| 262 |
else: |
|---|
| 263 |
|
|---|
| 264 |
window.move(win_position[0], win_position[1]) |
|---|
| 265 |
window.show() |
|---|
| 266 |
|
|---|
| 267 |
|
|---|
| 268 |
def icon_clicked(widget, event): |
|---|
| 269 |
update(0) |
|---|
| 270 |
|
|---|
| 271 |
|
|---|
| 272 |
def GetPlayStatus(widget): |
|---|
| 273 |
global playing |
|---|
| 274 |
global shuffle |
|---|
| 275 |
global loop |
|---|
| 276 |
global repeat |
|---|
| 277 |
status = player.GetStatus() |
|---|
| 278 |
|
|---|
| 279 |
playing = status[0] == 0 |
|---|
| 280 |
if playing: |
|---|
| 281 |
img_bt_toggle.set_from_stock("gtk-media-pause", gtk.ICON_SIZE_SMALL_TOOLBAR) |
|---|
| 282 |
else: |
|---|
| 283 |
img_bt_toggle.set_from_stock("gtk-media-play", gtk.ICON_SIZE_SMALL_TOOLBAR) |
|---|
| 284 |
shuffle = status[1] == 1 |
|---|
| 285 |
bt_shuffle.set_active( shuffle ) |
|---|
| 286 |
loop = status[2] == 1 |
|---|
| 287 |
bt_loop.set_active( loop ) |
|---|
| 288 |
repeat = status[3] == 1 |
|---|
| 289 |
bt_repeat.set_active( repeat ) |
|---|
| 290 |
|
|---|
| 291 |
|
|---|
| 292 |
import sys |
|---|
| 293 |
xml = gtk.glade.XML(os.path.join(os.path.dirname(sys.argv[0]) , 'mpris.glade')) |
|---|
| 294 |
|
|---|
| 295 |
|
|---|
| 296 |
bt_close = xml.get_widget('close') |
|---|
| 297 |
bt_quit = xml.get_widget('quit') |
|---|
| 298 |
bt_file = xml.get_widget('ChooseFile') |
|---|
| 299 |
bt_next = xml.get_widget('next') |
|---|
| 300 |
bt_prev = xml.get_widget('prev') |
|---|
| 301 |
bt_stop = xml.get_widget('stop') |
|---|
| 302 |
bt_toggle = xml.get_widget('toggle') |
|---|
| 303 |
bt_mrl = xml.get_widget('AddMRL') |
|---|
| 304 |
bt_shuffle = xml.get_widget('shuffle') |
|---|
| 305 |
bt_repeat = xml.get_widget('repeat') |
|---|
| 306 |
bt_loop = xml.get_widget('loop') |
|---|
| 307 |
l_artist = xml.get_widget('l_artist') |
|---|
| 308 |
l_title = xml.get_widget('l_title') |
|---|
| 309 |
e_mrl = xml.get_widget('mrl') |
|---|
| 310 |
window = xml.get_widget('window1') |
|---|
| 311 |
img_bt_toggle=xml.get_widget('image6') |
|---|
| 312 |
exp = xml.get_widget('expander2') |
|---|
| 313 |
expvbox = xml.get_widget('expandvbox') |
|---|
| 314 |
audioicon = xml.get_widget('eventicon') |
|---|
| 315 |
vol = xml.get_widget('vol') |
|---|
| 316 |
time_s = xml.get_widget('time_s') |
|---|
| 317 |
time_l = xml.get_widget('time_l') |
|---|
| 318 |
|
|---|
| 319 |
|
|---|
| 320 |
|
|---|
| 321 |
window.connect('delete_event', delete_event) |
|---|
| 322 |
window.connect('destroy', destroy) |
|---|
| 323 |
window.connect('key_release_event', key_release) |
|---|
| 324 |
|
|---|
| 325 |
tray = gtk.status_icon_new_from_icon_name("audio-x-generic") |
|---|
| 326 |
tray.connect('activate', tray_button) |
|---|
| 327 |
|
|---|
| 328 |
bt_close.connect('clicked', destroy) |
|---|
| 329 |
bt_quit.connect('clicked', Quit) |
|---|
| 330 |
bt_mrl.connect('clicked', AddTrack) |
|---|
| 331 |
bt_toggle.connect('clicked', Pause) |
|---|
| 332 |
bt_next.connect('clicked', Next) |
|---|
| 333 |
bt_prev.connect('clicked', Prev) |
|---|
| 334 |
bt_stop.connect('clicked', Stop) |
|---|
| 335 |
bt_loop.connect('clicked', Loop) |
|---|
| 336 |
bt_repeat.connect('clicked', Repeat) |
|---|
| 337 |
bt_shuffle.connect('clicked', Shuffle) |
|---|
| 338 |
exp.connect('activate', expander) |
|---|
| 339 |
vol.connect('change-value', volchange) |
|---|
| 340 |
vol.connect('scroll-event', volchange) |
|---|
| 341 |
time_s.connect('adjust-bounds', timechange) |
|---|
| 342 |
audioicon.set_events(gtk.gdk.BUTTON_PRESS_MASK) |
|---|
| 343 |
audioicon.connect('button_press_event', icon_clicked) |
|---|
| 344 |
time_s.set_update_policy(gtk.UPDATE_DISCONTINUOUS) |
|---|
| 345 |
|
|---|
| 346 |
library = "/media/mp3" |
|---|
| 347 |
|
|---|
| 348 |
|
|---|
| 349 |
try: |
|---|
| 350 |
os.chdir(library) |
|---|
| 351 |
bt_file.set_current_folder(library) |
|---|
| 352 |
except: |
|---|
| 353 |
bt_file.set_current_folder(os.path.expanduser("~")) |
|---|
| 354 |
|
|---|
| 355 |
|
|---|
| 356 |
bus = dbus.SessionBus() |
|---|
| 357 |
dbus_names = bus.get_object( "org.freedesktop.DBus", "/org/freedesktop/DBus" ) |
|---|
| 358 |
dbus_names.connect_to_signal("NameOwnerChanged", NameOwnerChanged, dbus_interface="org.freedesktop.DBus") |
|---|
| 359 |
|
|---|
| 360 |
dbus_o = bus.get_object("org.freedesktop.DBus", "/") |
|---|
| 361 |
dbus_intf = dbus.Interface(dbus_o, "org.freedesktop.DBus") |
|---|
| 362 |
name_list = dbus_intf.ListNames() |
|---|
| 363 |
|
|---|
| 364 |
|
|---|
| 365 |
for n in name_list: |
|---|
| 366 |
if "org.mpris." in n: |
|---|
| 367 |
Connect(n) |
|---|
| 368 |
window.set_title(identity) |
|---|
| 369 |
vol.set_value(player.VolumeGet()) |
|---|
| 370 |
update(0) |
|---|
| 371 |
break |
|---|
| 372 |
|
|---|
| 373 |
|
|---|
| 374 |
gobject.timeout_add( 1000, timeset) |
|---|
| 375 |
|
|---|
| 376 |
window.set_icon_name('audio-x-generic') |
|---|
| 377 |
window.show() |
|---|
| 378 |
|
|---|
| 379 |
icon_theme = gtk.icon_theme_get_default() |
|---|
| 380 |
try: |
|---|
| 381 |
pix = icon_theme.load_icon("audio-x-generic",24,0) |
|---|
| 382 |
window.set_icon(pix) |
|---|
| 383 |
except: |
|---|
| 384 |
True |
|---|
| 385 |
|
|---|
| 386 |
win_position = window.get_position() |
|---|
| 387 |
|
|---|
| 388 |
gtk.main() |
|---|
| 389 |
|
|---|