eric6/Helpviewer/WebPlugins/WebPluginFactory.py

branch
maintenance
changeset 7286
7eb04391adf7
parent 7226
babe80d84a3e
parent 7285
1ff497f33f31
child 7287
1c17f2191bdd
equal deleted inserted replaced
7226:babe80d84a3e 7286:7eb04391adf7
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2012 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the web plug-in factory.
8 """
9
10 from __future__ import unicode_literals
11
12 from PyQt5.QtWebKit import QWebPluginFactory
13
14
15 class WebPluginFactory(QWebPluginFactory):
16 """
17 Class implementing the web plug-in factory.
18 """
19 def __init__(self, parent=None):
20 """
21 Constructor
22
23 @param parent reference to the parent object (QObject)
24 """
25 super(WebPluginFactory, self).__init__(parent)
26
27 self.__loaded = False
28
29 def create(self, mimeType, url, argumentNames, argumentValues):
30 """
31 Public method to create a plug-in instance for the given MIME type with
32 the given data.
33
34 @param mimeType MIME type for the plug-in (string)
35 @param url URL for the plug-in (QUrl)
36 @param argumentNames list of argument names (list of strings)
37 @param argumentValues list of argument values (list of strings)
38 @return reference to the created object (QObject)
39 """
40 if not self.__loaded:
41 self.__initialize()
42
43 if mimeType in self.__pluginsCache:
44 return self.__pluginsCache[mimeType].create(
45 mimeType, url, argumentNames, argumentValues)
46 else:
47 return None
48
49 def plugins(self):
50 """
51 Public method to get a list of plug-ins.
52
53 @return list of plug-ins (list of QWebPluginFactory.Plugin)
54 """
55 if not self.__loaded:
56 self.__initialize()
57
58 plugins = []
59 for plugin in self.__plugins.values():
60 if not plugin.isAnonymous():
61 pluginInfo = plugin.metaPlugin()
62 plugins.append(pluginInfo)
63 return plugins
64
65 def refreshPlugins(self):
66 """
67 Public method to refresh the list of supported plug-ins.
68 """
69 self.__initialize()
70 super(WebPluginFactory, self).refreshPlugins()
71
72 def __initialize(self):
73 """
74 Private method to initialize the factory.
75 """
76 self.__loaded = True
77 self.__plugins = {}
78 self.__pluginsCache = {}
79
80 from .ClickToFlash.ClickToFlashPlugin import ClickToFlashPlugin
81 self.__plugins["ClickToFlash"] = ClickToFlashPlugin()
82
83 for plugin in self.__plugins.values():
84 for pluginMimeType in plugin.metaPlugin().mimeTypes:
85 self.__pluginsCache[pluginMimeType.name] = plugin
86
87 def plugin(self, name):
88 """
89 Public method to get a reference to the named plug-in.
90
91 @param name name of the plug-in (string)
92 @return reference to the named plug-in
93 """
94 if not self.__loaded:
95 self.__initialize()
96
97 if name in self.__plugins:
98 return self.__plugins[name]
99
100 return None

eric ide

mercurial