0

The idea is I want to separate between UI and service layer using pyQt.

I read and know that I can use a generated class from .ui by subclassing it so I don't change the layout from here.

But I don't know how to put my service, inside or outside GUI. I know only how to connect UI and method/service using slot and signals.

My service called Fan has a motor, switch and speed sensor.

Ui only has a start button, stop button, a label to display the result of self_checking and value from sensors. And before starting, Fan let say will do self-checking by running and fan and reading a sensor. All fan, motor, switch and speed sensor are QObjects.

I have difficulties applying it (service layer pattern) using pyQt5 starts with:

  1. Where I instantiate my Fan()? I assume that I have to instantiate inside GUI class. Can I instantiate outside GUI class and connect it with GUI class with slot?

  2. If a first page contains a progress-barr which value is added each time Fan successfully check motor, sensor and switch then: 2.1 Does it means I need to put fan.checking() in a thread to do all of this checking? and update all its results to progress bar using signal and slot?

  3. How should I make Fan() in separate Thread meanwhile, Fan() doesn't do smth which is blocking, it only turns on, off a motor. Once motor (as hardware)is turned on, it runs until it is turned off.

Any suggestion and thought are welcomed.

many thanks...

slawalata
  • 389
  • 1
  • 2
  • 14
  • I remember going for the second approach – emanuel sanga May 21 '21 at 11:37
  • 1
    See the PyQt Docs: [Qt Designer - Using the Generated Code](https://www.riverbankcomputing.com/static/Docs/PyQt5/designer.html#using-the-generated-code). – ekhumoro May 21 '21 at 11:52
  • Trying to implement the program in pyuic generated files is a terrible idea. Consider that those files should **NEVER** be modified (luckily, the latest versions of pyqt added a more clear warning about this). Follow the link given by ekhumuro (the multiple inheritance method explained there is the most suggested). Otherwise, consider using the `uic` module, which allows you to dynamically load the UI on a widget subclass by calling `uic.loadUi('somefile.ui', self)` at the very beginning of the `__init__`. In any case, never, NEVER edit those files by hand. – musicamante May 21 '21 at 11:52

0 Answers0