In order to do some calculation, I need to read some information values, which it sets by user on different widgets and values should later pass to a class, by clicking on a button. The class activates and calculates some data, then later that data pass to some other widget in order to plot or write....
We need also to flag when one or more data lacking before proceeding to class.
Visualisation:
Figur 1: button clicks by user then it proceeds and reads values from multiple Widget tabs and pass those data to a class.
Figur 2: Information usually set by user for further reading.
Figur 3: Information usually set by user for reading.
Figur 4: Information usually set by user for reading.
Figur 5: Information usually set by user for reading.
The entire code:
import sys
from PyQt5 import QtCore, QtWidgets, QtGui
class Tabwidget(QtWidgets.QWidget):
def __init__(self, parent=None):
super( Tabwidget, self).__init__()
self.setFixedSize(400, 230)
tab = QtWidgets.QTabWidget()
self.geometry = firsttab()
self.roundsection = self.geometry
self.A = ClassA()
self.B = ClassB()
self.C = ClassC()
tab.addTab(self.geometry,'A')
tab.addTab(self.A,'B')
tab.addTab(self.B,'C')
tab.addTab(self.C, 'D')
tab.addTab(LoadTable(), 'E')
tab.setFont(QtGui.QFont("Georgia",9,QtGui.QFont.Normal))
vboxlayout = QtWidgets.QVBoxLayout()
vboxlayout.addWidget(tab)
self.setLayout(vboxlayout)
class firsttab(QtWidgets.QWidget):
valueChanged = QtCore.pyqtSignal(int)
valuesChanged = QtCore.pyqtSignal(int, int)
def __init__(self, parent=None):
super(firsttab, self).__init__(parent)
font = QtGui.QFont("Georgia",8,QtGui.QFont.Normal)
sectiontypegroupbox = QtWidgets.QGroupBox('&Type',self)
sectiontypegroupbox.setFont(QtGui.QFont("Georgia",10,QtGui.QFont.Normal))
tab1button = QtWidgets.QPushButton('')
circularlabel = QtWidgets.QLabel("Calculate",self)
circularlabel.setSizePolicy(QtWidgets.QSizePolicy.Expanding,QtWidgets.QSizePolicy.Expanding)
circularlabel.setFont(font)
circularlay = QtWidgets.QHBoxLayout()
circularlay.addWidget(tab1button)
circularlay.addWidget(circularlabel)
vboxlayout = QtWidgets.QVBoxLayout()
vboxlayout.addLayout(circularlay)
vboxlayout.setSizeConstraint(vboxlayout.SetFixedSize)
vboxlayout.setContentsMargins(25,25,25,25)
sectiontypegroupbox.setLayout(vboxlayout)
hboxlayout = QtWidgets.QHBoxLayout()
hboxlayout.addWidget(sectiontypegroupbox)
self.setLayout(hboxlayout)
# self.button = Calculate()
# tab1button.clicked.connect(self.button.parse_file)
class ClassA(QtWidgets.QWidget):
def __init__(self, parent=None):
super(ClassA, self).__init__(parent)
self.setFont(QtGui.QFont("Helvetica", 10, QtGui.QFont.Normal, italic=False))
self.c_lay = QtWidgets.QHBoxLayout()
fctd = "One\n\nTwo\n\nThree"
con_strength = QtWidgets.QLabel(fctd)
self.value = QtWidgets.QLineEdit('Test')
self.c_lay.addWidget(con_strength)
self.c_lay.addWidget(self.value, alignment=QtCore.Qt.AlignRight)
self.combo = QtWidgets.QComboBox()
self.combo.addItems(["10","12","14","16"])
self.hbox = QtWidgets.QHBoxLayout()
self.con = QtWidgets.QLabel("Number: ")
self.hbox.addWidget(self.con)
self.hbox.addWidget(self.combo)
self.vlay = QtWidgets.QVBoxLayout()
self.vlay.addLayout(self.hbox)
self.vlay.addLayout(self.c_lay)
self.vlay.addStretch()
Concrete_Group = QtWidgets.QGroupBox()
Concrete_Group.setTitle("&GroupA")
Concrete_Group.setLayout(self.vlay)
lay = QtWidgets.QVBoxLayout(self)
lay.addWidget(Concrete_Group)
self.comth = ["10","12","14","16"]
self.combo.activated.connect(self.setdatastrength)
@QtCore.pyqtSlot(int)
def setdatastrength(self, index):
value = self.comth[index]
self.display_data(value)
def display_data(self, value):
try:
f = value
f_value = "{}"
self.value.setText(f_value.format(f))
except ValueError:
print("Error")
class ClassB(QtWidgets.QWidget):
def __init__(self, parent=None):
super(ClassB, self).__init__(parent)
self.setFont(QtGui.QFont("Helvetica", 10, QtGui.QFont.Normal, italic=False))
self.combo_exclass = QtWidgets.QComboBox()
self.combo_exclass.addItems([" Very dry area"," Dry or permanently wet"," Wet, rarely dry"," Moderate humidity"," Tidal splash & spray zones"])
self.combo_lclass = QtWidgets.QComboBox()
self.combo_lclass.addItems(["L2","L4","L6","L8"])
self.combo_vct = QtWidgets.QComboBox()
self.combo_vct.addItems(["0.10","0.20","0.30","0.40",
"0.50","0.60","0.70"])
self.combo_in = QtWidgets.QComboBox()
self.combo_in.addItems(["Class1","Class2","Class3"])
self.tbox = QtWidgets.QHBoxLayout()
self.exclass = QtWidgets.QLabel("Class1: ")
self.tbox.addWidget(self.exclass)
self.tbox.addWidget(self.combo_exclass)
self.mtbox = QtWidgets.QHBoxLayout()
self.lclass = QtWidgets.QLabel("Class2: ")
self.mtbox.addWidget(self.lclass)
self.mtbox.addWidget(self.combo_lclass)
self.mbbox = QtWidgets.QHBoxLayout()
self.vct = QtWidgets.QLabel("Class3: ")
self.mbbox.addWidget(self.vct)
self.mbbox.addWidget(self.combo_vct)
self.bbox = QtWidgets.QHBoxLayout()
self.inl = QtWidgets.QLabel("Class4: ")
self.bbox.addWidget(self.inl)
self.bbox.addWidget(self.combo_in)
self.grid = QtWidgets.QGridLayout()
self.grid.addLayout(self.tbox, 0, 0, 1, 2)
self.grid.addLayout(self.mtbox, 1, 0)
self.grid.addLayout(self.mbbox, 2, 0)
self.grid.addLayout(self.bbox, 3, 0)
Environment_Group = QtWidgets.QGroupBox()
Environment_Group.setTitle("&Group2")
Environment_Group.setLayout(self.grid)
vlay = QtWidgets.QVBoxLayout(self)
vlay.addWidget(Environment_Group)
class ClassC(QtWidgets.QWidget):
def __init__(self, parent=None):
super(ClassC, self).__init__(parent)
self.setFont(QtGui.QFont("Helvetica", 10, QtGui.QFont.Normal, italic=False))
filenameLabel = QtWidgets.QLabel("Name number:")
fileNameEdit = QtWidgets.QLineEdit()
ftablayout = QtWidgets.QVBoxLayout()
ftablayout.addWidget(filenameLabel)
ftablayout.addWidget(fileNameEdit)
self.setLayout(ftablayout)
class LoadTable(QtWidgets.QTableWidget):
def __init__(self, parent=None):
super(LoadTable, self).__init__(1, 3, parent)
self.setFont(QtGui.QFont("Helvetica", 10, QtGui.QFont.Normal, italic=False))
headertitle = ("A","B","C")
self.setHorizontalHeaderLabels(headertitle)
self.verticalHeader().hide()
self.horizontalHeader().setHighlightSections(False)
self.horizontalHeader().setSectionResizeMode(QtWidgets.QHeaderView.Fixed)
self.setSelectionMode(QtWidgets.QAbstractItemView.NoSelection)
self.setColumnWidth(0, 130)
combox_lay = QtWidgets.QComboBox(self)
combox_lay.addItems(["I","II"])
self.setCellWidget(0, 2, combox_lay)
class Calculate():
def __init__(self,a,b,c,d,e,f,g):
self.x_value = None
self.a_frc = None
self.b_cap = None
self.bsst = None
self.tsst = None
self.bsst = None
self.tsstr = None
self.parse_file(a,b,c,d,e,f,g)
def parse_file(self,a,b,c,d,e,f,g):
#all the code for calculation where:
pass
self.x_value = '{:.3f}'.format(a)
self.a_frc = '{:.3f}'.format(b)
self.b_cap = '{:.3f}'.format(c)
self.bsst = '{:.3f}'.format(d)
self.tsst = '{:.3f}'.format(e)
self.bsst = '{:.3f}'.format(f)
self.tsstr = '{:.3f}'.format(g)
def __str__(self):
return ('\nx value: {0} \nAforce: {1} \nb capacity : {2} \nBottom strain : {3} '
'\nTop strain : {4} \nBottom stress :{5} \nTop stress : {6}'
.format(self.x_value, self.a_frc, self.b_cap, self.bsst, self.tsst, self.bsst, self.tsstr))
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
w = Tabwidget()
w.show()
sys.exit(app.exec_())
Thanks for your help.




