[Tutor] Rhythmbox python plugin to capture middle click event

Lachlan d lachlan.00 at gmail.com
Wed Apr 6 07:10:35 CEST 2011


I've been working on some python rhythmbox plugins for the past few
months and now i've decided to try writing my own.
I've been able to get actions working correctly in my other plugin.
(http://launchpad.net/rb-fileorganizer) but that uses buttons and a
gui i built rather than mouse clicks.

What i'm trying to create is a plugin that will perform and action
every time the middle mouse button is clicked in rhythmbox. I haven't
been able to find any solid information about doing this on the net.

The plugin will load but i don't think anything in capture_click is correct.
Any help getting this to just print the test message in the console
would be greatly appreciated!

Here's my code that i've written up so far:

class middleclick(rb.Plugin):

   def __init__(self):
       rb.Plugin.__init__(self)

   # Rhythmbox standard Activate method
   def activate(self, shell):
       self.shell = shell
       self.capture_click(shell)

   # Rhythmbox standard Deactivate method
   def deactivate(self, shell):
       self.shell = None

   # Run test_plugin for middle click
   def capture_click(self, shell):
       self.action = gtk.Action('MiddleClick', _('Middle Click'),
_('Action on Middle Click'), gtk.gdk.BUTTON_PRESS_MASK)
       self.action.connect('activate', self.test_plugin, shell)
       self.action_group = gtk.ActionGroup('OnClickActions')
       self.action_group.add_action(self.action)
       uim = shell.get_ui_manager()
       uim.insert_action_group(self.action_group, 0)
       uim.ensure_update()

   def test_plugin(self, shell):
       if event.button == 2:
           print 'THIS IS AN EVENT'
       else
           print 'WRONG EVENT'


More information about the Tutor mailing list