Clone wiki

VPlayer / Plugin_development

Plugin development

VPlayer has full support for plugins.
This article will explain how to use it.

Basic rules

  • Your plugin should inherit BasePlugin class
  • Plugin should have plugin_info dict parameter (see example below)
  • It should not call parent's method outside _ _init_ _
  • All communication with program should be through QT's signals
  • Do not replace program's methods, modify signals istead
  • Plugins _ _init_ _ will receive MainWindow instance as an argument

How it works

VPlayer loads plugin like plugin = PluginClass(self) and then runs the thread like plugin.start(). As plugins are QThreads, start method invokes run method that can be overloaded. Use it to make plugin that do some work in a cycle or requires much time to load. All code in run method will run in a new thread without slowing down GUI and player.
Plugin receives MainWindow instance address as _ _init_ _ argument. In init you can make modifications to GUI and some other work that does not require much time. If it does, make it in run method. Though MainWindow's instance address plugin can access all parts of program and also other plugins using parent.plugins thread list.
Remember that _ _init_ _ method run's in main thread.
To imagine how it all works take a look at this scheme:
VPlayer scheme It is not full, but good enoght for plugin development. Also some methods can change names while development.
White - files with classes, main program structure.
Grey - GUI's slots for receiving track information.
Yellow - comments.

Settings storage

To save your plugin settings you should use QtCore.QSettings() instance. Please read it's documentation.
Please use "plugins/your_plugin_name/" prefix for settings.

Example plugin

This plugin will print playing track names to console. To create IM status changer plugin you can simply modify this code.

from vplayer.plugins.base_plugin import BasePlugin
class TrackPrinter(BasePlugin):
    plugin_info = { 'name': 'Track name printer',
                    'version': '1.0',
                    'author': 'Somebody',
                    'e-mail': '',
                    'homepage': 'donthave'}
    def __init__(self, parent):
        BasePlugin.__init__(self) #ancestor class init
        QtCore.QObject.connect(parent, QtCore.SIGNAL('playerstatus'),
                               self.status_receiver) #connect parent's signal
    def status_receiver(self, status):
        if type(status) is tuple: # status signal is a tuple
            if status[0] == 'start':
                print status[1].artist, '-', status[1].title # status[1] is a Track object

If you have some ideas how to improve plugin support, please make a record in issues.