33 from python_qt_binding.QtCore
import qCritical, qDebug, QObject, Qt, qWarning, Signal, Slot
34 from python_qt_binding.QtWidgets
import QDockWidget, QToolBar
44 Base class for the bidirectional exchange between the framework and one `Plugin` instance. 46 It utilizes a `PluginProvider` to load/unload the plugin and provides callbacks for the 50 label_updated = Signal(str, str)
51 close_signal = Signal(str)
52 reload_signal = Signal(str)
53 help_signal = Signal(str)
54 _defered_check_close = Signal()
56 def __init__(self, parent, main_window, instance_id, application_context, container_manager,
58 super(PluginHandler, self).
__init__(parent)
59 self.setObjectName(
'PluginHandler')
65 self.
_argv = argv
if argv
else []
93 def load(self, plugin_provider, callback=None):
97 Completion is signaled asynchronously if a callback is passed. 103 except Exception
as e:
107 raise NotImplementedError
110 if exception
is not None:
115 callback(self, exception)
116 elif exception
is not None:
117 qCritical(
'PluginHandler.load() failed%s' %
118 (
':\n%s' % str(exception)
if not exception
else ''))
121 for widget
in list(self.
_widgets.keys()):
130 Shut down the plugin and remove all added widgets. 132 Completion is signaled asynchronously if a callback is passed. 138 qCritical(
'PluginHandler.shutdown_plugin() plugin "%s" raised an exception:\n%s' %
143 raise NotImplementedError
156 toolbar.deleteLater()
162 Completion is signaled asynchronously if a callback is passed. 168 qCritical(
'PluginHandler.unload() plugin "%s" raised an exception:\n%s' %
173 raise NotImplementedError
183 Save settings of the plugin and all dock widget title bars. 185 Completion is signaled asynchronously if a callback is passed. 187 qDebug(
'PluginHandler.save_settings()')
193 qCritical(
'PluginHandler.save_settings() plugin "%s" raised an exception:\n%s' %
198 raise NotImplementedError
201 qDebug(
'PluginHandler.emit_save_settings_completed()')
210 for dock_widget, _, _
in self.
_widgets.values():
211 name =
'dock_widget' + \
212 dock_widget.objectName().replace(self.
_instance_id.tidy_str(),
'', 1)
213 settings = instance_settings.get_settings(name)
214 method = getattr(dock_widget, method_name)
218 qCritical(
'PluginHandler._call_method_on_all_dock_widgets(%s) failed:\n%s' %
219 (method_name, traceback.format_exc()))
223 Restore settings of the plugin and all dock widget title bars. 225 Completion is signaled asynchronously if a callback is passed. 227 qDebug(
'PluginHandler.restore_settings()')
233 qCritical(
'PluginHandler.restore_settings() plugin "%s" raised an exception:\n%s' %
238 raise NotImplementedError
241 qDebug(
'PluginHandler.emit_restore_settings_completed()')
262 features = dock_widget.features()
263 dock_widget.setFeatures(features ^ QDockWidget.DockWidgetClosable)
267 features = dock_widget.features()
268 dock_widget.setFeatures(
269 features ^ (QDockWidget.DockWidgetMovable | QDockWidget.DockWidgetFloatable))
272 title_bar = dock_widget.titleBarWidget()
273 if title_bar
is None:
277 dock_widget.setTitleBarWidget(title_bar)
283 title_bar.show_button(
'help',
not hide_help)
286 title_bar.show_button(
'reload',
not hide_reload)
293 if 'icon' in action_attributes
and action_attributes[
'icon']
is not None:
296 action_attributes[
'icon'], action_attributes.get(
'icontype',
None), base_path)
297 widget.setWindowIcon(icon)
301 for dock_widget, _, _
in self.
_widgets.values():
302 title_bar = dock_widget.titleBarWidget()
303 title_bar.show_button(
'configuration')
306 widget = [key
for key, value
in self.
_widgets.items()
if value[0] == dock_widget][0]
316 self._plugin.trigger_configuration()
319 dock_widget.setWidget(widget)
321 dock_widget.setObjectName(self.
_instance_id.tidy_str() +
'__' + widget.objectName())
330 self.
_widgets[widget] = [dock_widget, signaler, signaler2]
339 old_dock_widget = self.
_main_window.findChild(DockWidget, dock_widget.objectName())
340 if old_dock_widget
is not None:
341 qWarning(
'PluginHandler._add_dock_widget_to_main_window() duplicate object name ' +
342 '"%s", assign unique object names before adding widgets!' %
343 dock_widget.objectName())
345 self.
_main_window.addDockWidget(Qt.BottomDockWidgetArea, dock_widget)
348 dock_widget, _, _ = self.
_widgets[widget]
349 dock_widget.setWindowIcon(widget.windowIcon())
352 dock_widget, _, _ = self.
_widgets[widget]
353 dock_widget.setWindowTitle(widget.windowTitle())
369 dock_widget, signaler, signaler2 = self.
_widgets[widget]
371 if signaler
is not None:
374 if signaler2
is not None:
376 signaler2.show_signal.emit(dock_widget)
381 dock_widget.parent().removeDockWidget(dock_widget)
383 dock_widget.setParent(
None)
384 widget.setParent(
None)
385 dock_widget.deleteLater()
392 toolbar_object_name = toolbar.objectName()
395 if not toolbar_object_name.startswith(prefix):
396 toolbar_object_name = prefix + toolbar_object_name
397 toolbar.setObjectName(toolbar_object_name)
400 toolbar.setMovable(
False)
405 old_toolbar = self.
_main_window.findChild(QToolBar, toolbar.objectName())
406 if old_toolbar
is not None:
407 qWarning(
'PluginHandler._add_toolbar() duplicate object name "%s", ' 408 'assign unique object names before adding toolbars!' %
409 toolbar.objectName())
410 self.
_main_window.addToolBar(Qt.TopToolBarArea, toolbar)
418 toolbar.parent().removeToolBar(toolbar)
def set_plugin_descriptor(self, plugin_descriptor)
def _emit_help_signal(self)
def remove_widget(self, widget)
def remove_toolbar(self, toolbar)
def unload(self, callback=None)
def _emit_close_plugin(self)
def __init__(self, parent, main_window, instance_id, application_context, container_manager, argv=None)
def _on_widget_icon_changed(self, widget)
def _delete_widget(self, widget)
def _add_toolbar(self, toolbar)
_minimized_dock_widgets_toolbar
def _on_dock_widget_show(self, dock_widget)
def emit_shutdown_plugin_completed(self)
_plugin_has_configuration
def save_settings(self, plugin_settings, instance_settings, callback=None)
def set_minimized_dock_widgets_toolbar(self, toolbar)
def shutdown_plugin(self, callback)
def _on_dock_widget_hide(self, dock_widget)
def _update_dock_widget_features(self, dock_widget)
def _emit_load_completed(self, exception=None)
def _trigger_configuration(self)
def emit_restore_settings_completed(self)
def restore_settings(self, plugin_settings, instance_settings, callback=None)
def _remove_widget_by_dock_widget(self, dock_widget)
def _on_widget_title_changed(self, widget)
def _emit_unload_completed(self)
def _update_title_bars(self)
def _add_dock_widget_to_main_window(self, dock_widget)
def _emit_reload_signal(self)
def _set_window_icon(self, widget)
def _create_dock_widget(self)
def _restore_settings(self, plugin_settings, instance_settings)
def _delete_toolbar(self, toolbar)
def _call_method_on_all_dock_widgets(self, method_name, instance_settings)
def emit_save_settings_completed(self)
def _update_title_bar(self, dock_widget, hide_help=False, hide_reload=False)
def _add_dock_widget(self, dock_widget, widget)
def _garbage_widgets_and_toolbars(self)
def _shutdown_plugin(self)
def get_icon(name, type_=None, base_path=None)
def _on_dock_widget_title_changed(self, dock_widget)
def load(self, plugin_provider, callback=None)
def _save_settings(self, plugin_settings, instance_settings)