MVC pattern and value storage
I have developed a small pyqt app for my workplace, I am not a developer by training so a lot of it is a combination of poorly designed classes and methods, and some magic numbers peppered through.
It does the job but the increase in features and complexity makes me want to go back to the drawing board and refactor the code using a model view controller design pattern, hopefully to make it easier to later expand the feature set.
One thing I am not to clear on: currently most of my UI and back end are more or less contained in the same class. It’s messy but it makes it easy to have the system communicate and find the relevant data.
So for example, if at any point one of my logics requires a value previously set by the user in the UI, I simply call the widget’s relevant method ( my_widget.get_current_text() for example).
I take assume that this is a bit of a big no no in an MVC pattern,since we want to decouple the systems from the UI as much as possible? So then, should I:
-have signals emitted from my widgets which on any change (animal_combobox changes to “cat”)
-controller would detect those signals and pass the changes values to the model.
-this would update class variables in the model itself. (self.animal = “cat”)
-any logic executed from the model would uniquely rely on the values stored in the model itself, completely oblivious to the status of the Ui.
Did I get that correctly?
Secondary question, on such a system, would we want to create signals for each user interaction widget in the interface so that each can affect their own relevant variable in the model? Because that may end up requiring hundreds of signals connected to hundreds of variables.
Or is it more practical to instead execute a generic “ui updated, scan and save all variables” (or something in between, I feel like I’m missing a bit of the pythonic / OOP logic to make the workflow more dynamic)