31 from python_qt_binding.QtCore
import QObject, QSignalMapper, Signal, Slot
32 from python_qt_binding.QtWidgets
import QAction, QMenu
40 """Menu of available plugins to load and running plugin instances to unload.""" 42 load_plugin_signal = Signal(str)
43 unload_plugin_signal = Signal(str)
47 self.setObjectName(
'PluginMenu')
49 plugin_menu = menu_bar.addMenu(menu_bar.tr(
'&Plugins'))
50 running_menu = menu_bar.addMenu(menu_bar.tr(
'&Running'))
56 ' Hidden action to work around QTBUG-52582', self._running_menu_manager.menu)
57 action.setVisible(
False)
58 self._running_menu_manager.add_item(action)
65 base_path = plugin_descriptor.attributes().get(
'plugin_path')
69 for group
in plugin_descriptor.groups():
70 label = group[
'label']
71 if menu_manager.contains_menu(label):
72 submenu = menu_manager.get_menu(label)
74 submenu = QMenu(label, menu_manager.menu)
75 menu_action = submenu.menuAction()
77 menu_manager.add_item(submenu)
80 action_attributes = plugin_descriptor.action_attributes()
81 action = QAction(action_attributes[
'label'], menu_manager.menu)
84 self._plugin_mapper.setMapping(action, plugin_descriptor.plugin_id())
85 action.triggered.connect(self._plugin_mapper.map)
87 not_available = plugin_descriptor.attributes().get(
'not_available')
89 action.setEnabled(
False)
90 action.setStatusTip(self.tr(
'Plugin is not available: %s') % not_available)
93 menu_manager.add_item(action)
96 action_attributes = plugin_descriptor.action_attributes()
97 action = QAction(action_attributes[
'label'], self._plugin_menu_manager.menu)
99 self._plugin_mapper.setMapping(action, plugin_descriptor.plugin_id())
100 action.triggered.connect(self._plugin_mapper.map)
101 self._plugin_menu_manager.add_prefix(action)
104 action_attributes = plugin_descriptor.action_attributes()
106 str(instance_id)), self._running_menu_manager.menu)
107 base_path = plugin_descriptor.attributes().get(
'plugin_path')
110 self._running_mapper.setMapping(action, str(instance_id))
111 action.triggered.connect(self._running_mapper.map)
113 self._running_menu_manager.add_item(action)
118 self._running_mapper.removeMappings(action)
119 self._running_menu_manager.remove_item(action)
128 return self.tr(
'Close:') +
' ' + label
131 if 'icon' in action_attributes
and action_attributes[
'icon']
is not None:
133 action_attributes[
'icon'], action_attributes.get(
'icontype',
None), base_path)
136 if 'statustip' in action_attributes:
137 action.setStatusTip(action_attributes[
'statustip'])
def get_icon(name, type_=None, base_path=None)