Helpviewer/WebPlugins/WebPluginFactory.py

Sun, 10 Feb 2013 18:31:31 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 10 Feb 2013 18:31:31 +0100
changeset 2403
e3d7a861547c
parent 2302
f29e9405c851
child 2525
8b507a9a2d40
child 2954
bf0215fe12d1
permissions
-rw-r--r--

Continued implementing the delayed import.

# -*- coding: utf-8 -*-

# Copyright (c) 2012 - 2013 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing the web plug-in factory.
"""

from PyQt4.QtWebKit import QWebPluginFactory


class WebPluginFactory(QWebPluginFactory):
    """
    Class implementing the web plug-in factory.
    """
    def __init__(self, parent=None):
        """
        Constructor
        
        @param parent reference to the parent object (QObject)
        """
        super().__init__(parent)
        
        self.__loaded = False
    
    def create(self, mimeType, url, argumentNames, argumentValues):
        """
        Public method to create a plug-in instance for the given MIME type with
        the given data.
        
        @param mimeType MIME type for the plug-in (string)
        @param url URL for the plug-in (QUrl)
        @param argumentNames list of argument names (list of strings)
        @param argumentValues list of argument values (list of strings)
        @return reference to the created object (QObject)
        """
        if not self.__loaded:
            self.__initialize()
        
        if mimeType in self.__pluginsCache:
            return self.__pluginsCache[mimeType].create(
                mimeType, url, argumentNames, argumentValues)
        else:
            return None
    
    def plugins(self):
        """
        Public method to get a list of plug-ins.
        
        @return list of plug-ins (list of QWebPluginFactory.Plugin)
        """
        if not self.__loaded:
            self.__initialize()
        
        plugins = []
        for plugin in self.__plugins.values():
            if not plugin.isAnonymous():
                pluginInfo = plugin.metaPlugin()
                plugins.append(pluginInfo)
        return plugins
    
    def refreshPlugins(self):
        """
        Public method to refresh the list of supported plug-ins.
        """
        self.__initialize()
        super().refreshPlugins()
    
    def __initialize(self):
        """
        Private method to initialize the factory.
        """
        self.__loaded = True
        self.__plugins = {}
        self.__pluginsCache = {}
        
        from .ClickToFlash.ClickToFlashPlugin import ClickToFlashPlugin
        self.__plugins["ClickToFlash"] = ClickToFlashPlugin()
        
        for plugin in self.__plugins.values():
            for pluginMimeType in plugin.metaPlugin().mimeTypes:
                self.__pluginsCache[pluginMimeType.name] = plugin
    
    def plugin(self, name):
        """
        Public method to get a reference to the named plug-in.
        
        @param name name of the plug-in (string)
        """
        if not self.__loaded:
            self.__initialize()
        
        if name in self.__plugins:
            return self.__plugins[name]
        
        return None

eric ide

mercurial