How to move class method out of gui modul
-
@jsulm When QTCreator is used, your code is big as my very fast. Tab controll with few pages produce plenty of lines of code ...
Ok, few words about my project.
My project involves RaspberryPi as a Master in RS485 network. This application is like a sort of SCADA for home. On the other side of the network there are slaves responsible for diferent things like temperatures, humidity, consumption of watter, electricity, ...
So Master collets those data, do some calcullations, diagrams, storing data, ... , and most important do some graphic visualisation of everything in network.
At the momment my code covers three slaves, but there are three slaves more to include into aplication. Each slave contains Microchip microcontroller PIC18F458 ...
Slaves are already in function in real situation. -
@California To keep your gui.py smaller you can create one widget for each tab in its own file (using designer, widget_1.py, widget_2.py, ...). Then add those widgets to the tabs.
-
@jsulm that would be very usefull, do you have any example of how to do it or where it could be find to look?
-
What are your skills level with python ?
-
So you know how to split your code in several logical modules/files and import them to use them ?
-
Smal change in function makes script running without an error but only "Unchecked" is printed out when radiobutton is checked or it is unchecked. How to fix this to have correct respond?
# python 2.7.9 from PyQt4 import QtCore, QtGui #from gui_1 import Ui_Form def print_situation(*args): radioButton = QtGui.QRadioButton() if radioButton.isChecked(): print "Checked" else: print "Unchecked"
-
Importing functions or classes is exactly the same process.
The thing that you seem to want to do is take apart class functions
Take a look at the 3rd example from the PyQt 5 designer introduction documentation.
Basically, you have your generated file from pyuic5, then you create your own class that will use the generated code. Finally a main.py where you will instantiate your custom widget(s) and start the application.
-
Hi
Wontdef print_situation(*args): radioButton = QtGui.QRadioButton() if radioButton.isChecked(): print "Checked" else: print "Unchecked"
radioButton = QtGui.QRadioButton()
create a new QRadioButtonEach time and its unchecked by default.
Hence it always says "Unchecked" ?
-
@mrjj you are right I suppose
@SGaist I tried to follow your point but ...
code:# python 2.7.9 from PyQt4 import QtCore, QtGui from PyQt4.QtGui import QCheckBox #from gui_5 import Ui_Form class My_app(QCheckBox): def __init__(self): super(My_app, self).__init__() # Set up the user interface from Designer. self.setupUi(self) self.checkBox = QtGui.QCheckBox(self) # Connect up the buttons. self.checkBox.clicked.connect(self.accept) def print_situation(self, *args): if self.checkBox.checkState() == QtCore.Qt.Checked: print "Checked" else: print "Unchecked"
error:
Traceback (most recent call last): File "/home/pi/Desktop/Qt4/Project/01/Test_Class/main_5.py", line 17, in <module> master.checkBox.clicked.connect(My_app.print_situation) AttributeError: 'function' object has no attribute '__pyqtSignature__'
-
Why are you deriving from a QCheckBox and then create a new checkbox in it ?
-
Would you be so kind to rewritte this code to loose error, because I am lost at the momment.
A lot of time was spent for this issue in last month and I didn't make any progress at all. -
I will take no respond as this issue is mission impossible.
Thanks for your help.Vlado
-
@California said in How to move class method out of gui modul:
mission impossible.
Well you seem to lack (some ?) understanding of classes in python.
https://www.tutorialspoint.com/python/python_classes_objects.htmI think all the issue comes from that. Using Qt does not change anything.
So maybe stop with Qt for a day. Try to use own objects like you want to with Qt.
If you do not know how to make instance of a class or how to use them as parameters etc then
its hard to split to extra files.Just saying. Im even bigger Beginner with python. :)
-
Thanks for this useffull link.