Introduce ProviderOptions class

It is a template class for provider's options, it inherits from OptionsPage.
This commit is contained in:
Laurent Monin
2015-07-03 17:46:07 +02:00
parent 5f9f1d34a6
commit f101de35d0

View File

@@ -19,13 +19,51 @@
from picard import log, config
from picard.plugin import ExtensionPoint
from picard.ui.options import OptionsPage, register_options_page
_cover_art_providers = ExtensionPoint()
class ProviderOptions(OptionsPage):
""" Template class for provider's options
It works like OptionsPage for the most (options, load, save)
It will append the provider's options page as a child of the main
cover art's options page.
The property _options_ui must be set to a valid Qt Ui class
containing the layout and widgets for defined provider's options.
A specific provider class (inhereting from CoverArtProvider) has
to set the subclassed ProviderOptions as OPTIONS property.
Options will be registered at the same time as the provider.
class MyProviderOptions(ProviderOptions):
_options_ui = Ui_MyProviderOptions
....
class MyProvider(CoverArtProvider):
OPTIONS = ProviderOptionsMyProvider
....
"""
PARENT = "cover"
def __init__(self, parent=None):
super(ProviderOptions, self).__init__(parent)
self.ui = self._options_ui()
self.ui.setupUi(self)
def register_cover_art_provider(provider):
_cover_art_providers.register(provider.__module__, provider)
if hasattr(provider, 'OPTIONS') and provider.OPTIONS:
provider.OPTIONS.NAME = provider.NAME
provider.OPTIONS.TITLE = provider.TITLE or provider.NAME
register_options_page(provider.OPTIONS)
def cover_art_providers():