Re: Plugin Amarok



William,


it works like a charm, very good solution thanks.

The problem with the modified plugin is that I was getting the error:

 File "/home/rafael/.local/share/kupfer/plugins/volumeControl.py",
line 17, in show_notification   VolumeNotifier.nid =
uiutils.show_notification(title, body, icon_name, VolumeNotifier.nid)
AttributeError: class VolumeNotifier has no attribute 'nid'

so I added nid = 0 in the class.

Also I cleaned the code, follow attached the new version of the plugin
but works just with the patch sent by William(hope that it get to the
main code already in the next release)


anyone could give it a try?


cheers



                                       Rafael Brundo Uriarte



On 19 November 2010 05:13, William Friesen <wfriesen gmail com> wrote:
> 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 VolumeUtils():
	nid = 0

	def __init__(self):
		VolumeUtils.nid = 0

	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])

	def set_master_volume(self, option):
		command = '/usr/bin/amixer sset Master,0 '+ option	
		utils.launch_commandline(command, in_terminal=False)

	def show_notification(self, title, body, icon_name):
		VolumeUtils.nid = uiutils.show_notification(title, body, icon_name, VolumeUtils.nid)

class Mute (RunnableLeaf, VolumeUtils):
	def __init__(self):
		RunnableLeaf.__init__(self, name=_("Mute"))
		VolumeUtils.__init__(self)

	def run(self):
		self.set_master_volume('mute')
		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, VolumeUtils):
	def __init__(self):
		RunnableLeaf.__init__(self, name=_("UnMute"))
		VolumeUtils.__init__(self)

	def run(self):
		self.set_master_volume('unmute')
		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, VolumeUtils):
	def __init__(self):
		RunnableLeaf.__init__(self, name=_("VolumeUp"))
		VolumeUtils.__init__(self)

	def run(self):
		self.set_master_volume('6+')
		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"


class VolumeDown (RunnableLeaf, VolumeUtils):
	def __init__(self):
		RunnableLeaf.__init__(self, name=_("VolumeDown"))
		VolumeUtils.__init__(self)

	def run(self):
		self.set_master_volume('6-')
		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"


class VolumeMax (RunnableLeaf, VolumeUtils):
	def __init__(self):
		RunnableLeaf.__init__(self, name=_("VolumeMax"))
		VolumeUtils.__init__(self)

	def run(self):
		self.set_master_volume('100')
		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]