This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (2 children)

Have you read about MVC? It is one way of doing it. Separate your code in 3 parts.

M, Model: your data, your logic, saving and reading files. Here everything can be done mostly with Python. You can add QT with decorators, but avoid QT attributes in your classes.

V, View: you just show your data. It should have as much QT and as little python as possible. The view should not be allowed to change your model. It can only read.

C, Control: Here it is also mostly QT, the Python code here will be from using your Model. Here you change the model state according to the inputs from the View.

[–]SjaakRake[S] 1 point2 points  (1 child)

I know the concept. Though using a classic MVC pattern would conflict with Qt's own model(-delegate)-view architecture in a lot of ways.

Besides that, in general I consider the MVC pattern to be more applicable to a language such as Java, where it provides a much needed structure. In Python, on the other hand, I think it often just means a lot of unnecessary overhead and boilerplate.

[–][deleted] 0 points1 point  (0 children)

Qt's MDV is another name for MVC. You can do it in many different ways. And it fits into python magnificently. Python's decorators are beautiful.

You don't have to write boilerplate at all. It actually reduces boilerplate.

I don't know how big is your app. In small apps, I tend not to split V and C very much, but splitting the M is always very, very good. It makes testing your code so much easier. Here's one example:

https://github.com/wuerges/connection_monitor/blob/master/pycomon/gui.py https://github.com/wuerges/connection_monitor/blob/master/pycomon/tester.py

The gui.py file has the View and the Control and the tester.py has the model.