Python Forum
[PyQt] Decoupling business logic from GUI elements
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] Decoupling business logic from GUI elements
#1
I'd like some insight on how to structure a PyQt GUI architecture in a way that decouples the GUI from the underlying business logic.
My understanding of PyQt is that the Views also act as a controller, and any event handling must go through QObjects (and subclasses). This seems straightforward for gui related stuff, but most of the examples I have seen also rely on PyQt for the event handling in the models and such. I must say I'm not really a fan of having such a close coupling between core elements of my program and the gui architecture.

My approach would be to use PyQt signals for gui related elements only, and use an observer pattern (or similar like pubsub) for the other parts of the program. This would separate the models from anything PyQt, with the downside of having to implement controllers that subscribe to both gui signals and business logic events in order to bring the two parts together.

Is it okay to do this, or am I going in the wrong direction?
Reply
#2
I would agree with your thinking, have the GUI just doing GUI stuff, the controller binds to GUI events and observes and calls the model.
Only the controller knows about both the GUI and the model, the model and the GUI are totally independent, they know nothing about each other.
Reply
#3
(May-09-2021, 09:11 PM)Yoriz Wrote: I would agree with your thinking, have the GUI just doing GUI stuff, the controller binds to GUI events and observes and calls the model.
Only the controller knows about both the GUI and the model, the model and the GUI are totally independent, they know nothing about each other.

Would you have any examples of an application written that way in PyQt that I could have a look at? My main issue is that I am beginning to have a fait amount of widgets and models that need to communicate with each other but I can't figure out how to properly organize them within the program.
Reply
#4
I don't really know much PyQt so someone else might have a better idea but here are some links.
Creating a Calculator With Python and PyQt
Python - PyQt5 - MVC
Reply
#5
I've done quite a bit with PyQt5.

https://github.com/search?q=user%3AAxel-Erfurt+pyqt5
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020