Re: Plugin Amarok



uiutils.show_notification doesn't provide a way to set the timeout for
a notification, but it does return a notification id. The DBus method
that it uses accepts an argument to replace a notification, given this
id.
I think a better way to do this would be to store the id of the
notifications for this plugin, and update them each time one is
displayed.
I have submitted a patch for uiutils that will allow this here:
https://bugs.launchpad.net/kupfer/+bug/677352
and attached is an updated version of the plugin that uses a new
VolumeNotifier class that will control the updating of notifications.


2010/11/19 Rafael Brundo Uriarte <rafael uriarte gmail com>:
> Folks,
>
> as I said, I finished a simple plugin to control the sound system
> (mute, unmute, volume up,down and max) and I am sending attached.
> Could some please give it a try and tell me how is it going?
>
>
> I could not find a place to set the notification time(what is too long
> if you do for example twice volume up, takes a life to the second
> notification show up) and I could not find where to make the text
> bigger(in notification) as well.
>
>
> Andreas, I've been using the amarok plugin and is working very well,
> just miss the features(that currently are no possible) as search in
> collection, playlist editor, etc. Have you come to a solution about
> the play and running amarok?
>
>                                        Rafael Brundo Uriarte
>
>
>
> On 16 November 2010 21:24, Rafael Brundo Uriarte
> <rafael uriarte gmail com> wrote:
>> Folks,
>>
>> I've developed a very simple plugin to control amarok playback(based
>> on the audacious one, thanks folks). it has got only Play, Pause,
>> Stop, Next Song and Previous Song (amarok 2.X hasn't got yet and dbus
>> interface to manage collection). I am not sure if it's worth to put in
>> the official release but for those who use amarok and want to give a
>> try, here it go (just save as ~/.local/share/kupfer/plugins/amarok.py
>> ) :
>>
>> "
>> __kupfer_name__ = _("Amarok")
>> __kupfer_sources__ = ("AmarokSource", )
>> __description__ = _("Very Simple Plugin to Control Amarok(2.X)
>> Playback, it includes Play, Stop, Pause, Next Song and Previous Song.
>> Make sure that amarok is running")
>> __version__ = "2010-11-16"
>> __author__ = "Rafael Brundo Uriarte<rafael uriarte gmail com>"
>>
>> import subprocess
>>
>> from kupfer.objects import Leaf, Source, Action
>> from kupfer.objects import AppLeaf, RunnableLeaf, SourceLeaf
>> from kupfer.obj.apps import AppLeafContentMixin
>> from kupfer import objects, icons, utils
>> from kupfer import plugin_support
>> from kupfer import kupferstring
>>
>> class Play (RunnableLeaf):
>>        def __init__(self):
>>                RunnableLeaf.__init__(self, name=_("Play"))
>>        def run(self):
>>                utils.launch_commandline("qdbus org.mpris.amarok /Player Play",
>> in_terminal=False)
>>        def get_description(self):
>>                return _("Resume playback in Amarok")
>>        def get_icon_name(self):
>>                return "media-playback-start"
>>
>> class Stop (RunnableLeaf):
>>        def __init__(self):
>>                RunnableLeaf.__init__(self, name=_("Stop"))
>>        def run(self):
>>                utils.launch_commandline("qdbus org.mpris.amarok /Player Stop",
>> in_terminal=False)
>>        def get_description(self):
>>                return _("Stop playback in Amarok")
>>        def get_icon_name(self):
>>                return "media-playback-stop"
>>
>> class Pause (RunnableLeaf):
>>        def __init__(self):
>>                RunnableLeaf.__init__(self, name=_("Pause"))
>>        def run(self):
>>                utils.launch_commandline("qdbus org.mpris.amarok /Player Pause",
>> in_terminal=False)
>>        def get_description(self):
>>                return _("Pause playback in Amarok")
>>        def get_icon_name(self):
>>                return "media-playback-pause"
>>
>> class Next (RunnableLeaf):
>>        def __init__(self):
>>                RunnableLeaf.__init__(self, name=_("Next"))
>>        def run(self):
>>                utils.launch_commandline("qdbus org.mpris.amarok /Player Next",
>> in_terminal=False)
>>        def get_description(self):
>>                return _("Jump to next track in Amarok")
>>        def get_icon_name(self):
>>                return "media-skip-forward"
>>
>> class Previous (RunnableLeaf):
>>        def __init__(self):
>>                RunnableLeaf.__init__(self, name=_("Previous"))
>>        def run(self):
>>                utils.launch_commandline("qdbus org.mpris.amarok
>> /Player Prev", in_terminal=False)
>>
>>        def get_description(self):
>>                return _("Jump to previous track in Amarok")
>>        def get_icon_name(self):
>>                return "media-skip-backward"
>>
>>
>> class AmarokSource (AppLeafContentMixin, Source):
>>        appleaf_content_id = "Amarok"
>>        source_user_reloadable = True
>>
>>        def __init__(self):
>>                Source.__init__(self, _("Amarok"))
>>        def get_items(self):
>>                yield Play()
>>                yield Stop()
>>                yield Pause()
>>                yield Next()
>>                yield Previous()
>>        def get_description(self):
>>                return __description__
>>        def get_icon_name(self):
>>                return "Amarok"
>>        def provides(self):
>>                yield RunnableLeaf
>>
>> "
>>
>> The next one I am planning (apart from improving this one) is to
>> control the general volume (Mute, Volume Up....)
>>
>> any suggestion or critic is welcome...
>>
>> cheers
>>                                        Rafael Brundo Uriarte
>>
>
> _______________________________________________
> kupfer-list mailing list
> kupfer-list gnome org
> http://mail.gnome.org/mailman/listinfo/kupfer-list
>
>
__kupfer_name__ = _("VolumeControl")
__kupfer_sources__ = ("VolumeControlSource", )
__description__ = _("Simple Plugin to Control the system volume. It includes Mute, Unmute, Volume Up, Volume Down and VolumeMax.")
__version__ = "2010-11-18"
__author__ = "Rafael Brundo Uriarte<rafael uriarte gmail com>"

import subprocess
from kupfer.objects import Source
from kupfer.objects import RunnableLeaf
from kupfer.obj.apps import AppLeafContentMixin
from kupfer import utils, uiutils

class VolumeNotifier():
	def __init__(self):
		VolumeNotifier.nid = 0
	def show_notification(self, title, body, icon_name):
		VolumeNotifier.nid = uiutils.show_notification(title, body, icon_name, VolumeNotifier.nid)

class Mute (RunnableLeaf, VolumeNotifier):
	def __init__(self):
		RunnableLeaf.__init__(self, name=_("Mute"))
		VolumeNotifier.__init__(self)
	def run(self):
		#check if is not muted already
		#proc = subprocess.Popen('/usr/bin/amixer sget Master', shell=True, stdout=subprocess.PIPE)
		#result = str(proc.communicate())
		#if "off" not in result:
		utils.launch_commandline("amixer sset Master,0 mute", in_terminal=False)
		title, body = "Volume", "Muted"
		self.show_notification(title, body, icon_name=self.get_icon_name())

	def get_description(self):
		return _("Mute Volume")
	def get_icon_name(self):
		return "stock_volume-mute"

class UnMute (RunnableLeaf, VolumeNotifier):
	def __init__(self):
		RunnableLeaf.__init__(self, name=_("UnMute"))
		VolumeNotifier.__init__(self)
	def run(self):
		utils.launch_commandline("amixer sset Master unmute", in_terminal=False)
		title, body = "Volume", "UnMuted"
		self.show_notification(title, body, icon_name=self.get_icon_name())
	def get_description(self):
		return _("UnMute the Volume")
	def get_icon_name(self):
		return "stock_volume"

class VolumeUp (RunnableLeaf, VolumeNotifier):
	def __init__(self):
		RunnableLeaf.__init__(self, name=_("VolumeUp"))
		VolumeNotifier.__init__(self)
	def run(self):
		utils.launch_commandline("amixer sset Master,0 6+", in_terminal=False)
		title= "Volume"
		body = "Up, now is %s"%int(self.get_master_volume())
		self.show_notification(title, body+"%", icon_name=self.get_icon_name())
	def get_description(self):
		return _("Volume Up")
	def get_icon_name(self):
		return "stock_volume-med"
	def get_master_volume(self):
       		proc = subprocess.Popen('/usr/bin/amixer sget Master', shell=True, stdout=subprocess.PIPE)
		amixer_stdout = proc.communicate()[0].split('\n')[4]
		proc.wait()

		find_start = amixer_stdout.find('[') + 1
		find_end = amixer_stdout.find('%]', find_start)
		return float(amixer_stdout[find_start:find_end])

class VolumeDown (RunnableLeaf, VolumeNotifier):
	def __init__(self):
		RunnableLeaf.__init__(self, name=_("VolumeDown"))
		VolumeNotifier.__init__(self)
	def run(self):
		utils.launch_commandline("amixer sset Master,0 6-", in_terminal=False)
		title = "Volume"
		body = "Down, now is %s"%int(self.get_master_volume())
		self.show_notification(title, body+"%", icon_name=self.get_icon_name())
	def get_description(self):
		return _("Volume Down")
	def get_icon_name(self):
		return "stock_volume-min"
	def get_master_volume(self):
       		proc = subprocess.Popen('/usr/bin/amixer sget Master', shell=True, stdout=subprocess.PIPE)
		amixer_stdout = proc.communicate()[0].split('\n')[4]
		proc.wait()

		find_start = amixer_stdout.find('[') + 1
		find_end = amixer_stdout.find('%]', find_start)
		return float(amixer_stdout[find_start:find_end])

class VolumeMax (RunnableLeaf, VolumeNotifier):
	def __init__(self):
		RunnableLeaf.__init__(self, name=_("VolumeMax"))
		VolumeNotifier.__init__(self)
	def run(self):
		utils.launch_commandline("amixer sset Master 100", in_terminal=False)
		title, body = "Volume", "100%"
		self.show_notification(title, body, icon_name=self.get_icon_name())
	def get_description(self):
		return _("Volume 100%")
	def get_icon_name(self):
		return "stock_volume-max"




class VolumeControlSource (AppLeafContentMixin, Source):
	appleaf_content_id = "Volume Control"
	source_user_reloadable = True

	def __init__(self):
		Source.__init__(self, _("Volume Control"))
	def get_items(self):
		yield Mute()
		yield UnMute()
		yield VolumeUp()
		yield VolumeDown()
		yield VolumeMax()
	def get_description(self):
		return __description__
	def get_icon_name(self):
		return "stock_volume"
	def provides(self):
		yield RunnableLeaf


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]