cryptoref
cryptoref

Reputation: 413

Saving connect statements pyqt when UI is still changing

This is a project construction question. I'm building a window using QT designer, but i'm still new at it so I'm making lots of changes. I want to start using that in my real code, not just the previewer, so i generate my PY code. It specifically says, and it's true, that any changes made to the PY file are lost the next time you run the pyuic4 command. I have lots of connections that i'm making and those go in the constructor. Obviously lost if they are in the generated py file.

My idea is to create a new class, inherit from the Ui class, and just add in connects in my setupUi.

generated.py
class Ui_MainWindow(object):
  def setupUi(self, MainWindow):
  ... setup stuff

my.py
class MyMain(Ui_MainWindow)
  def setupUi(self, MyMain):
    self.connect(self.button...)
    ...

Is this the pythonic way to do this?

Upvotes: 0

Views: 178

Answers (1)

danidee
danidee

Reputation: 9634

of course this is the way to do it...it allows you to modify the logic of your code independently without touching the auto-generated ui, you can even move the auto-generated ui files into a seperate package for better modularity

/project
    /ui
        # your auto-generated ui files
    /logic
        # your application logic which get their ui from the ui package

    main.py

your main.py should be very minimal something like this

def main():
    app = QtGui.QApplication(sys.argv)
    window = Window()
    window.show()
    sys.exit(app.exec_())

if __name__ == '__main__': main()

Upvotes: 1

Related Questions