只有“plugin2.py”文件在工作。“已忽略”插件.py““
entry
刚刚连接上一个指定的“x”值
我希望我的所有插件都连接到textChanged
函数。我该怎么办?你知道吗
※如果将self.x
更改为x
不工作,但我没有得到任何错误。你知道吗
※如果删除self.x
变量和类型:
self.entry.textChanged.connect((__import__(plug["name"]).Window().textChangedd))
结果是一样的,不工作,但没有错误
pluginSystem/
main.py
plugin.py
plugin2.py
package.json
main.py
#imports
class Window(QWidget):
def __init__(self):
super().__init__()
self.vBox = QVBoxLayout()
self.entry = QLineEdit()
self.vBox.addWidget(self.entry)
with open("package.json") as f:
data = json.load(f)
for plug in data["Plugin"]:
importlib.import_module(plug["name"])
self.x = (__import__(plug["name"]).Window().textChangedd)
self.entry.textChanged.connect(self.x)
self.entry.textChanged.connect(self.textChanged)
self.setLayout(self.vBox)
self.show()
def textChanged(self, text):
if text == "close":
app.quit()
if __name__ == "__main__":
app = QApplication(sys.argv)
window = Window()
sys.exit(app.exec())
plugin.py
from pluginSystem.main import *
class Window(QObject):
def __init__(self):
super().__init__()
@pyqtSlot(str)
def textChangedd(self, text):
print("blabla")
plugin2.py
#Same as Plugin.py
package.json
{
"Plugin": [{"name" : "plugin"},{"name" : "plugin2"}]
}
您的代码无法工作,因为您需要保留对所有这些对象的引用,当您在
self.x
上设置时,前面的引用将丢失。你知道吗我已经改变了你项目的结构,然后我可以让它在我当地的环境中工作。你知道吗
主.py
插件.py
插件2.py
相关问题 更多 >
编程相关推荐