0

Since yesterday I'm facing this issue I can't solve by myself. Can anyone please suggest a solution ?

File "C:/Myproj_python/pertesCVS.py", line 67, in recupVariables
    Eon1 = float((self.Eon1_lineEdit.text()))

As shown in the code, I'm importing a GUI called pertesCVSUI parametres generated by Qt designer.

In the method defined as RecupeVariables I'm trying to store as variables what the user writes in some QlineEdits and to do calculation on those float values in the method defined as fitenergy.

import numpy as np
import pertesCVSUI
from PyQt5 import QtGui, QtWidgets


class PertesCVS(pertesCVSUI.Ui_PertesCVS):
    def __init__(self, parent=None):
        # super(PertesCVS, self).__init__(parent)
        self.setupUi(parent)
        self.recupVariables()
        self.btnstate()
        self.fitenergy()

    def setupUi(self, parent):
        super(PertesCVS, self).setupUi(parent)

        # setup validators
        self.Eon1_lineEdit.setValidator(QtGui.QDoubleValidator(0.99, 99.99, 3))
        self.Eon2_lineEdit.setValidator(QtGui.QDoubleValidator(0.99, 99.99, 3))
        self.Eon3_lineEdit.setValidator(QtGui.QDoubleValidator(0.99, 99.99, 3))
        self.Ion1_lineEdit.setValidator(QtGui.QDoubleValidator(0.99, 99.99, 3))
        self.Ion2_lineEdit.setValidator(QtGui.QDoubleValidator(0.99, 99.99, 3))
        self.Ion3_lineEdit.setValidator(QtGui.QDoubleValidator(0.99, 99.99, 3))

        self.Eoff1_lineEdit.setValidator(QtGui.QDoubleValidator(0.99, 99.99, 3))
        self.Eoff2_lineEdit.setValidator(QtGui.QDoubleValidator(0.99, 99.99, 3))
        self.Eoff3_lineEdit.setValidator(QtGui.QDoubleValidator(0.99, 99.99, 3))
        self.Ioff1_lineEdit.setValidator(QtGui.QDoubleValidator(0.99, 99.99, 3))
        self.Ioff2_lineEdit.setValidator(QtGui.QDoubleValidator(0.99, 99.99, 3))
        self.Ioff3_lineEdit.setValidator(QtGui.QDoubleValidator(0.99, 99.99, 3))

        self.Vcc_lineEdit.setValidator(QtGui.QDoubleValidator(0.99, 99.99, 3))
        self.Imax_lineEdit.setValidator(QtGui.QDoubleValidator(0.99, 99.99, 3))
        self.Fd_lineEdit.setValidator(QtGui.QDoubleValidator(0.99, 99.99, 3))
        self.Mod_lineEdit.setValidator(QtGui.QDoubleValidator(0.99, 99.99, 3))
        self.Rdson_lineEdit.setValidator(QtGui.QDoubleValidator(0.99, 99.99, 3))
        self.Dc_lineEdit.setValidator(QtGui.QDoubleValidator(0.99, 99.99, 3))
        self.Tf_lineEdit.setValidator(QtGui.QDoubleValidator(0.99, 99.99, 3))

        # setup connection        
        self.calculate.clicked.connect(self.recupVariables)
        self.radioButton1.toggled.connect(self.btnstate)
        self.radioButton2.toggled.connect(self.btnstate)

    def btnstate(self):
        if self.radioButton1.isChecked():
            self.Mod_lineEdit.hide()
            self.label_19.hide()
            self.Dc_lineEdit.show()
            self.label_22.show()
        else:
            self.Mod_lineEdit.show()
            self.Dc_lineEdit.hide()
            self.label_22.hide()
            self.label_19.show()

    def recupVariables(self):
        Eon1 = float((self.Eon1_lineEdit.text()))
        Eon2 = float((self.Eon2_lineEdit.text()))
        Eon3 = float((self.Eon3_lineEdit.text()))
        Ion1 = float((self.Ion1_lineEdit.text()))
        Ion2 = float((self.Ion2_lineEdit.text()))
        Ion3 = float((self.Ion3_lineEdit.text()))
        Eoff1 = float((self.Eoff1_lineEdit.text()))
        Eoff2 = float((self.Eoff2_lineEdit.text()))
        Eoff3 = float((self.Eoff3_lineEdit.text()))
        Ioff1 = float((self.Ioff1_lineEdit.text()))
        Ioff2 = float((self.Ioff2_lineEdit.text()))
        Ioff3 = float((self.Ioff3_lineEdit.text()))

        Imax = (self.Imax_lineEdit.text())
        Fd = (self.Fd_lineEdit.text())

    def fitenergy(self):
        ##Energy on
        Aon = np.array([[1, Ion1, Ion1 * Ion1], [1, Ion2, Ion2 * Ion2],
                        [1, Ion3, Ion3 * Ion3]])  ## the error appears here

        Aon_inv = np.linalg.inv(Aon)
        *strong
        text *
        Bon = np.array([Eon1, Eon2, Eon3])

        xon = np.linalg.solve(Aon_inv, Bon)
        ##Energy_off
        Aoff = np.array(
            [[1, Ioff1, Ioff1 * Ioff1], [1, Ioff2, Ioff2 * Ioff2], [1, Ioff3, Ioff3 * Ioff3]])

        Aoff_inv = np.linalg.inv(Aoff)

        Boff = np.array([Eon1, Eon2, Eon3])

        xoff = np.linalg.solve(Aoff_inv, Boff)
        ###
        xon_T = np.transpose(xon)
        xoff_T = np.transpose(xoff)
        print(xon_T, xoff_T)


if __name__ == "__main__":
    import sys
app = QtWidgets.QApplication(sys.argv)
main_widget = QtWidgets.QTabWidget()
ui = PertesCVS(main_widget)
main_widget.show()
sys.exit(app.exec_())
kchomski
  • 2,872
  • 20
  • 31
Felahi.M
  • 3
  • 3
  • What is the error you're getting? – kchomski Jul 17 '18 at 10:17
  • show complete error message – eyllanesc Jul 17 '18 at 10:37
  • Why do not you use QDoubleSpinBox instead of QLineEdit ?, probably some QLineEdit this empty, and the empty text can not be converted to floating. – eyllanesc Jul 17 '18 at 10:38
  • My complete error message is : File "C:/Myproj_python/pertesCVS.py", line 67, in recupVariables Eon1 = float((self.Eon1_lineEdit.text())) ValueError: could not convert string to float: – Felahi.M Jul 17 '18 at 11:03
  • @Felahi.M you have an empty QLineEdit, since the error message is always: `... could not convert string to float: SOME_VALUE`, and in your case SOME_VALUE does not show what indicates that the text is empty. – eyllanesc Jul 17 '18 at 11:16
  • @Felahi.M Look at this answer in particular: https://stackoverflow.com/a/20929983/6622587 – eyllanesc Jul 17 '18 at 11:19
  • @eyllanesc well it's empty because values are put in the GUI that does not show up as there is errors – Felahi.M Jul 17 '18 at 11:22
  • @Felahi.M As I told you instead of using QLineEdit use QDoubleSpinBox that are designed for that specific task. – eyllanesc Jul 17 '18 at 11:24
  • Thank you @eyllanesc for your answer, i will give it a try and come back to you. – Felahi.M Jul 17 '18 at 11:33

0 Answers0