My general answer to this will not be, it is impossible in direct light. The main problem is that when you start the application, it loads everything into memory, and your classes are associated with their methods, etc. Therefore, to update the values ββthat you changed in the class method, you will have to destroy this class (or widget) and recreate it under the updated source code (which would also kill children).
Its bad looking, but it would look something like this:
## main.py ## class MainWindow(QtGui.QMainWindow): def __init__(self, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) self.resize(640,480) self.central = widget.Widget() self.setCentralWidget(self.central) self.toolbar = QtGui.QToolBar() self.toolbar.addAction("Reload Entire Widget", self._reloadWidget) self.addToolBar(QtCore.Qt.TopToolBarArea, self.toolbar) def _reloadWidget(self): print "Reloading", widget reload(widget) self.central.deleteLater() self.central = widget.Widget() self.setCentralWidget(self.central) ## widget.py ## class Widget(QtGui.QWidget): def __init__(self, *args, **kwargs): super(Widget, self).__init__(*args, **kwargs) self.layout = QtGui.QVBoxLayout(self) self.button = QtGui.QPushButton("Click") self.layout.addWidget(self.button) self.button.clicked.connect(self.testMethod) def testMethod(self): print "testmethod(): FOO"
Again, I think this approach is problematic and difficult to handle, since you need to destroy and recreate your widget. More problems arise when parts of your application have signals tied to the slots of the updated widget. Then you also need to reboot your modules and reconnect their signals. This becomes a big dependency tree situation. It is quite difficult to do with the standard python script, not to mention trying to do it with something more stable and dynamic, like the PyQt structure.
In principle, do not rely on this ability. You better set up something with QTest to simulate your repetitive tasks.
source share