recursive_plugin_provider.py
Go to the documentation of this file.
1 # Copyright (c) 2011, Dirk Thomas, Dorian Scholz, TU Darmstadt
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions
6 # are met:
7 #
8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following
12 # disclaimer in the documentation and/or other materials provided
13 # with the distribution.
14 # * Neither the name of the TU Darmstadt nor the names of its
15 # contributors may be used to endorse or promote products derived
16 # from this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 # POSSIBILITY OF SUCH DAMAGE.
30 
31 import traceback
32 
33 from python_qt_binding.QtCore import qCritical
34 
35 from qt_gui.composite_plugin_provider import CompositePluginProvider
36 
37 
39  """
40  Plugin provider which directly loads and returns all discovered plugins.
41 
42  Discovered plugins should be plugin providers themselves.
43  """
44 
45  def __init__(self, plugin_provider):
46  super(RecursivePluginProvider, self).__init__([])
47  self.setObjectName('RecursivePluginProvider')
48 
49  self._plugin_provider = plugin_provider
50 
51  def discover(self, discovery_data):
52  # discover plugins, which are providers themselves
53  plugin_descriptors = self._plugin_provider.discover(discovery_data)
54 
55  # instantiate plugins
56  plugin_providers = []
57  for plugin_descriptor in plugin_descriptors:
58  try:
59  # pass None as PluginContext for PluginProviders
60  instance = self._plugin_provider.load(plugin_descriptor.plugin_id(), None)
61  except Exception:
62  qCritical('RecursivePluginProvider.discover() loading plugin "%s" failed:\n%s' %
63  (str(plugin_descriptor.plugin_id()), traceback.format_exc()))
64  else:
65  if instance is not None:
66  plugin_providers.append(instance)
67 
68  # delegate discovery through instantiated plugin providers to base class
69  self.set_plugin_providers(plugin_providers)
70  return CompositePluginProvider.discover(self, discovery_data)


qt_gui
Author(s): Dirk Thomas
autogenerated on Thu Jun 6 2019 19:54:27