我将 Python 与 PyQt 一起用于我的界面,并使用 Yapsi 来添加插件。Yapsy 找到了我所有的插件并将所有插件添加到我的主窗口中的菜单中。每个插件都被触发信号激活。QAction 的这个信号没有参数,我需要知道是什么插件发出了信号。
这是相关代码:
pluginMenu = self.menuBar().addMenu("P&lugins")
# Create plugin manager
self.manager = PluginManager(categories_filter={ "Formatters": Formatter})
self.manager.setPluginPlaces(["plugins"])
# Load plugins
self.manager.locatePlugins()
self.manager.loadPlugins()
# A do-nothing formatter by default
self.formatters = {}
for plugin in self.manager.getPluginsOfCategory("Formatters"):
# plugin.plugin_object is an instance of the plugin
print(plugin.plugin_object.name)
# The method to create action associated each input to default triggered() signal
newAction = self.createAction(plugin.plugin_object.name, slot=self.updatePreview())
self.addActions(pluginMenu, (newAction, None))
self.formatters[plugin.plugin_object.name] = (plugin.plugin_object, newAction)
def updatePreview(self):
# Here I need know what plugin emit the signal
#===================================================================
我想用一些参数将信号与其他信号连接起来,但我不知道该怎么做。