#!/usr/bin/python
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
import gtk
import appindicator
import os
import time
import threading
import commands
class interface(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def create(self, buf, func = None):
"""Create menu object"""
item = gtk.MenuItem(buf)
if func != None:
item.connect("activate", func, buf)
self.menu.append(item)
item.show()
return(item)
def show(self, widget, string):
"""Show deadbeef"""
os.system('deadbeef')
def play(self, widget, string):
"""Play or pause"""
os.system('deadbeef --pause')
def after(self, widget, string):
"""Next song"""
os.system('deadbeef --next')
def previos(self, widget, string):
"""Previos song"""
os.system('deadbeef --prev')
def run(self):
ind = appindicator.Indicator ("deadbeef", "deadbeef",
appindicator.CATEGORY_APPLICATION_STATUS)
ind.set_status (appindicator.STATUS_ACTIVE)
self.menu = gtk.Menu()
self.now= self.create("Now playing")
self.show = self.create("Show/Hide", self.show)
self.play_menu = self.create("Play/Pause", self.play)
self.next_menu = self.create("Next", self.after)
self.previos_menu = self.create("Previos", self.previos)
ind.set_menu(self.menu)
gtk.main()
class nowplaying(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
while True:
needle = commands.getoutput('deadbeef --nowplaying "%a - %t"')
needle = needle.splitlines()
try:
int.now.set_label(needle<1>)
except:
int.now.set_label(needle<0>)
time.sleep(1)
if __name__ == "__main__":
gtk.gdk.threads_init()
gtk.gdk.threads_enter()
int = interface()
int.start()
gtk.gdk.threads_leave()
now = nowplaying()
now.start()
Ляпота!