plugin_context.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 from python_qt_binding.QtCore import QObject
32 
33 
34 class PluginContext(QObject):
35  """
36  Provides information to the plugin and exposes methods to interact with the framework.
37 
38  PluginContext relays all methods to the corresponding `PluginHandler`.
39  """
40 
41  def __init__(self, handler):
42  super(PluginContext, self).__init__(handler)
43  self.setObjectName('PluginContext')
44 
45  self._handler = handler
46 
47  def serial_number(self):
48  """
49  Return the serial number of the plugin.
50 
51  For a specific type of plugin each instance gets a serial number (which is the first
52  currently not used positive integer at construction time).
53  @return: The serial number
54  @rtype: int
55  """
56  return self._handler.instance_id().serial_number
57 
58  def argv(self):
59  """
60  Return the command line arguments of the plugin.
61 
62  @return: The arguments without a program name at the beginning
63  @rtype: list
64  """
65  return self._handler.argv()
66 
67  def add_widget(self, widget):
68  """
69  Add a widget to the UI.
70 
71  The widget is embedded into a new QDockWidget which itself is added to the QMainWindow.
72  This method can be called once for each widget a plugin would like to add and at any point
73  in time (until the calling plugin has been shutdown).
74 
75  Note: The ownership of the widget is transferred to the callee which will delete it when
76  the plugin is shut down.
77  @param widget: The widget to add
78  @type widget: QWidget
79  """
80  self._handler.add_widget(widget)
81 
82  def remove_widget(self, widget):
83  """
84  Remove a previously added widget from the UI.
85 
86  Note: The ownership of the widget is transferred to the caller.
87  @param widget: The widget to remove
88  @type widget: QWidget
89  """
90  self._handler.remove_widget(widget)
91 
92  def add_toolbar(self, toolbar):
93  """
94  Add a toolbar to the UI, which is directly added to the QMainWindow.
95 
96  This method can be called once for each toolbar a plugin would like to add and at any point
97  in time (until the calling plugin has been shutdown).
98  Note: The ownership of the toolbar is transferred to the callee which will delete it when
99  the plugin is shut down.
100  @param widget: The toolbar to add
101  @type widget: QToolBar
102  """
103  self._handler.add_toolbar(toolbar)
104 
105  def remove_toolbar(self, toolbar):
106  """
107  Remove a previously added toolbar from the UI.
108 
109  Note: The ownership of the toolbar is transferred to the caller.
110  @param widget: The toolbar to remove
111  @type widget: QToolBar
112  """
113  self._handler.remove_toolbar(toolbar)
114 
115  def close_plugin(self):
116  """
117  Close the plugin.
118 
119  The framework will call `Plugin.shutdown_plugin()` and unload it afterwards.
120  """
121  self._handler.close_plugin()
122 
123  def reload_plugin(self):
124  """Reload the plugin."""
125  self._handler.reload_plugin()


qt_gui
Author(s): Dirk Thomas
autogenerated on Fri Jun 24 2022 02:42:37