plugin_context.py
Go to the documentation of this file.
00001 # Copyright (c) 2011, Dirk Thomas, Dorian Scholz, TU Darmstadt
00002 # All rights reserved.
00003 #
00004 # Redistribution and use in source and binary forms, with or without
00005 # modification, are permitted provided that the following conditions
00006 # are met:
00007 #
00008 #   * Redistributions of source code must retain the above copyright
00009 #     notice, this list of conditions and the following disclaimer.
00010 #   * Redistributions in binary form must reproduce the above
00011 #     copyright notice, this list of conditions and the following
00012 #     disclaimer in the documentation and/or other materials provided
00013 #     with the distribution.
00014 #   * Neither the name of the TU Darmstadt nor the names of its
00015 #     contributors may be used to endorse or promote products derived
00016 #     from this software without specific prior written permission.
00017 #
00018 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00019 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00020 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00021 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00022 # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00023 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00024 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00025 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00026 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00027 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00028 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00029 # POSSIBILITY OF SUCH DAMAGE.
00030 
00031 from python_qt_binding.QtCore import QObject
00032 
00033 
00034 class PluginContext(QObject):
00035 
00036     """
00037     PluginContext providing information to the plugin and exposing methods for the plugin to interact with the framework.
00038     It relays all methods to the corresponding `PluginHandler`.
00039     """
00040 
00041     def __init__(self, handler):
00042         super(PluginContext, self).__init__(handler)
00043         self.setObjectName('PluginContext')
00044 
00045         self._handler = handler
00046 
00047     def serial_number(self):
00048         """
00049         Return the serial number of the plugin.
00050         For a specific type of plugin each instance gets a serial number (which is the first currently not used positive integer at construction time).
00051         @return: The serial number
00052         @rtype: int
00053         """
00054         return self._handler.instance_id().serial_number
00055 
00056     def argv(self):
00057         """
00058         Return the command line arguments of the plugin.
00059         @return: The arguments without a program name at the beginning
00060         @rtype: list
00061         """
00062         return self._handler.argv()
00063 
00064     def add_widget(self, widget):
00065         """
00066         Add a widget to the UI.
00067         The widget is embedded into a new QDockWidget which itself is added to the QMainWindow.
00068         This method can be called once for each widget a plugin would like to add and at any point in time (until the calling plugin has been shutdown).
00069         Note: The ownership of the widget is transferred to the callee which will delete it when the plugin is shut down.
00070         @param widget: The widget to add
00071         @type widget: QWidget
00072         """
00073         self._handler.add_widget(widget)
00074 
00075     def remove_widget(self, widget):
00076         """
00077         Remove a previously added widget from the UI.
00078         Note: The ownership of the widget is transferred to the caller.
00079         @param widget: The widget to remove
00080         @type widget: QWidget
00081         """
00082         self._handler.remove_widget(widget)
00083 
00084     def add_toolbar(self, toolbar):
00085         """
00086         Add a toolbar to the UI.
00087         The toolbar is directly added to the QMainWindow.
00088         This method can be called once for each toolbar a plugin would like to add and at any point in time (until the calling plugin has been shutdown).
00089         Note: The ownership of the toolbar is transferred to the callee which will delete it when the plugin is shut down.
00090         @param widget: The toolbar to add
00091         @type widget: QToolBar
00092         """
00093         self._handler.add_toolbar(toolbar)
00094 
00095     def remove_toolbar(self, toolbar):
00096         """
00097         Remove a previously added toolbar from the UI.
00098         Note: The ownership of the toolbar is transferred to the caller.
00099         @param widget: The toolbar to remove
00100         @type widget: QToolBar
00101         """
00102         self._handler.remove_toolbar(toolbar)
00103 
00104     def close_plugin(self):
00105         """
00106         Close the plugin.
00107         The framework will call `Plugin.shutdown_plugin()` and unload it afterwards.
00108         """
00109         self._handler.close_plugin()
00110 
00111     def reload_plugin(self):
00112         """
00113         Reload the plugin.
00114         """
00115         self._handler.reload_plugin()


qt_gui
Author(s): Dirk Thomas
autogenerated on Fri Feb 3 2017 03:42:12