Re: [Rhythmbox-devel] python plugin not found
- From: gsubes <gsubes gmail com>
- To: rhythmbox-devel gnome org
- Subject: Re: [Rhythmbox-devel] python plugin not found
- Date: Thu, 22 Oct 2009 10:55:56 +0200
Hi again,
you were right. :) renaming the foler solved the problem.
This is the current working plugin:
-------
deletefile.rb-plugin:
[RB Plugin]
Loader=python
Module=deletefile
IAge=1
Name=Delete current song from harddisk
Description=Deletes the current song when Alt+Up is pressed.
Authors=gsubes gmail com
Copyright=Copyright © 2009 subes
Website=https://sourceforge.net/users/subes
-------
__init__.py:
#!/usr/bin/python
# coding: UTF-8
import Xlib.X
import rb
import os
from time import sleep
import Xlib
import Xlib.display
import gobject
import gtk
import pynotify
import glib
# TODO:
# - allow hotkey to be configured via gconf
# -> process keysyms (https://www.siafoo.net/snippet/239)
class DeleteFilePlugin (rb.Plugin):
# Alt+Up - get from xbindkeys -k
delete_key = 111
delete_mask = 0x8
numlock_mask = 0x10
capslock_mask = 0x2
scrolllock_mask = capslock_mask # TODO: unknown!
modifier_combinations = (
delete_mask,
delete_mask | numlock_mask,
delete_mask | scrolllock_mask,
delete_mask | capslock_mask,
delete_mask | numlock_mask | scrolllock_mask,
delete_mask | numlock_mask | capslock_mask,
delete_mask | scrolllock_mask | capslock_mask,
delete_mask | numlock_mask | scrolllock_mask | capslock_mask)
display = None
root = None
shell = None
doListen = False
# init plugin
def __init__(self):
rb.Plugin.__init__(self)
# register hotkey, tell X that we want keyrelease events and start
listening
def activate(self, shell):
self.display = Xlib.display.Display()
self.root = self.display.screen().root
self.display.allow_events(Xlib.X.AsyncKeyboard,
Xlib.X.CurrentTime)
self.root.change_attributes(event_mask = Xlib.X.KeyReleaseMask)
self.shell = shell
self.register_hotkey()
self.doListen = True
gobject.idle_add(self.listen_cb, priority=gobject.PRIORITY_LOW)
# stop listening, unregister hotkey and clean up
def deactivate(self, shell):
self.doListen = False
self.unregister_hotkey()
self.display.close()
# register the hotkey
def register_hotkey(self):
for modifier in self.modifier_combinations:
self.root.grab_key(self.delete_key, modifier, True,
Xlib.X.GrabModeAsync, Xlib.X.GrabModeAsync)
# unregister the hotkey
def unregister_hotkey(self):
for modifier in self.modifier_combinations:
self.root.ungrab_key(self.delete_key, modifier)
# callback for listening, checks if the hotkey has been pressed
def listen_cb(self):
gtk.gdk.threads_enter()
if(not self.doListen):
gtk.gdk.threads_leave()
return False
if(self.root.display.pending_events() > 0 and self.doListen):
event = self.root.display.next_event()
if event.type == Xlib.X.KeyRelease and event.detail ==
self.delete_key:
mask = event.state & ~(self.capslock_mask |
self.numlock_mask | self.scrolllock_mask)
if mask == self.delete_mask:
self.delete()
gtk.gdk.threads_leave()
return True
# deletes the current playing file
def delete(self):
file = self.shell.props.shell_player.get_playing_path()
file = file.replace("%20", " ")
file = file.replace("file://", "")
if(isinstance(file, str)):
filename = file.rpartition("/")[2]
n = pynotify.Notification(filename, "", "user-trash-full")
n.show()
try:
self.shell.props.shell_player.do_next()
except glib.GError:
None
recoversh = "/tmp/"+filename+".sh"
os.system("echo \"mv '"+filename+"' '"+file+"' && rm \$0\" >
'"+recoversh+"'")
os.system("chmod +x '"+recoversh+"'")
os.system("trash '"+file+"' '"+recoversh+"'")
-------
It depends on trash-cli. It moves the file to trash and creates a shell
script to recover the file to the original destination. To do this one
has to copy both the <file> and the <file>.sh out of trash and run the
<file>.sh.
Currently I am not interested in developing a GUI/GConf configuration
for this plugin. Though if somebody else is interested in this plugin I
might add this feature on demand.
Thanks for your help.
Am Mittwoch, den 21.10.2009, 12:28 -0400 schrieb Calvin Walton:
> Hi, I've responsed inline.
>
> On Wed, Oct 21, 2009 at 10:27, gsubes <gsubes googlemail com> wrote:
> > Hi,
> >
> > I am trying to write a rythmbox plugin that registers a global hotkey
> > and deletes the currently played file when the hotkey is pressed (to get
> > quickly rid of music I want to sort out of my collection).
> > I'm new to python programming and this is my first plugin ever.
>
> I can't say I'd ever want to delete anything (i tend to use a global
> hotkey to skip songs rather than delete them), but it seems like a
> useful simple plugin.
>
> > This is the folder i have put the plugin into:
> > /home/<user>/.gnome2/rhythmbox/plugins/DeleteFile/
> >
> > -- There is a deletefile.rb-plugin:
> >
> > [RB Plugin]
> > Loader=python
> > Module=deletefile
> <snip>
> > When I start rhythmbox, the plugin is shown but when I try to enable it,
> > the rhythmbox debug output tells me the following:
> >
> > (16:21:47) [0x2241040] [rb_python_module_init] rb-python-module.c:420:
> > Init of python module
> > ImportError: No module named deletefile
> >
> > (rhythmbox:19790): Rhythmbox-WARNING **: Could not load plugin
> > deletefile
>
> Here's your problem. In your rb-plugin file, you've listed the plugin
> as the module 'deletefile'. However, it is located in the directory
> 'DeleteFile'! Remember that linux filesystems are case sensitive, you
> have to make sure that they match.
>
> > Is there some way to properly debug plugins?
> > Maybe you have an idea why the plugin cannot be enabled?
>
> I unfortunately haven't found any way to debug rhythmbox plugins other
> than enabling the debug option on rhythmbox and adding a bunch of
> debugging print statements. Perhaps someone else knows a better way?
>
> > Best regards,
> > subes
>
> Hope that helps.
>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]