Beispiel #1
0
    def __init__(self, indices=None, nombres=None, x=None, y=None, parent=None):
        super(Binary_distillation, self).__init__(parent)
        self.setWindowTitle(self.title)
        layout=QtWidgets.QGridLayout(self)
        layout.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate("equipment", "Component 1:")),1,1)
        self.Comp1=QtWidgets.QComboBox()
        layout.addWidget(self.Comp1,1,2)
        layout.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate("equipment", "Component 2:")),1,4)
        self.Comp2=QtWidgets.QComboBox()
        layout.addWidget(self.Comp2,1,5)

        self.indices=indices
        self.nombres=nombres
        for i, nombre in enumerate(nombres):
            self.Comp1.addItem("%i - %s" %(i+1, nombre))
            self.Comp2.addItem("%i - %s" %(i+1, nombre))
        self.Comp2.setCurrentIndex(1)
        tab=QtWidgets.QTabWidget()
        layout.addWidget(tab,2,1,1,5)
        self.plot=mpl()
        tab.addTab(self.plot, QtWidgets.QApplication.translate("equipment", "Plot"))
        self.tabla=Tabla(2, horizontalHeader=["x", "y"], stretch=False, readOnly=True)
        tab.addTab(self.tabla, QtWidgets.QApplication.translate("equipment", "Table"))

        self.Comp1.currentIndexChanged.connect(self.calculo)
        self.Comp2.currentIndexChanged.connect(self.calculo)

        if x and y:
            self.rellenar(x, y)
        else:
            self.calculo()
Beispiel #2
0
    def __init__(self, equipment=None, salidas=0, parent=None):
        """
        equipment: Initial equipment instance to model
        salidas: Stream Output number to equipment
        """
        super(UI_equipment, self).__init__(Divider,
                                           entrada=False,
                                           parent=parent)

        # Calculate tab
        lyt_Calc = QtGui.QGridLayout(self.tabCalculo)
        lyt_Calc.addWidget(
            QtGui.QLabel(QtGui.QApplication.translate("pychemqt",
                                                      "Separation")), 1, 1, 1,
            1)
        self.criterio = QtGui.QComboBox()
        for txt in self.Equipment.TEXT_CRITERIO:
            self.criterio.addItem(txt)
        self.criterio.currentIndexChanged.connect(self.criterio_Changed)
        lyt_Calc.addWidget(self.criterio, 1, 2, 1, 1)

        self.fracciones = Tabla(1, horizontalHeader=[True], stretch=False)
        self.fracciones.setItemDelegateForColumn(0, CellEditor(self))
        lyt_Calc.addWidget(self.fracciones, 2, 1, 1, 2)

        lyt_Calc.addWidget(
            QtGui.QLabel(
                QtGui.QApplication.translate("pychemqt", "Pressure lost")), 3,
            1, 1, 1)
        self.deltaP = Entrada_con_unidades(Pressure, value=0)
        self.deltaP.valueChanged.connect(partial(self.changeParams, "deltaP"))
        lyt_Calc.addWidget(self.deltaP, 3, 2, 1, 1)

        if equipment and salidas:
            equipment(salidas=salidas)
        elif equipment:
            salidas = equipment.kwargs["salidas"]
        else:
            self.Equipment = Divider(salidas=salidas)

        self.fracciones.setRowCount(salidas)
        for i in range(salidas):
            self.fracciones.setItem(0, i, QtGui.QTableWidgetItem(""))
            self.fracciones.item(0,
                                 i).setTextAlignment(QtCore.Qt.AlignRight
                                                     | QtCore.Qt.AlignVCenter)
            self.fracciones.setRowHeight(i, 20)
            widget = UI_corriente.Ui_corriente(readOnly=True)
            self.Salida.addTab(widget, str(i + 1))

        self.criterio_Changed(0)
        self.fracciones.editingFinished.connect(
            partial(self.changeParams, "split"))
        self.setEquipment(equipment)
Beispiel #3
0
 def __init__(self, indices=None, nombres=None, x=None, y=None, parent=None):
     super(Binary_distillation, self).__init__(parent)
     self.setWindowTitle(self.title)
     layout=QtGui.QGridLayout(self)
     layout.addWidget(QtGui.QLabel(QtGui.QApplication.translate("equipment", "Component 1:")),1,1)
     self.Comp1=QtGui.QComboBox()
     layout.addWidget(self.Comp1,1,2)
     layout.addWidget(QtGui.QLabel(QtGui.QApplication.translate("equipment", "Component 2:")),1,4)
     self.Comp2=QtGui.QComboBox()
     layout.addWidget(self.Comp2,1,5)
     
     self.indices=indices
     self.nombres=nombres
     for i, nombre in enumerate(nombres):
         self.Comp1.addItem("%i - %s" %(i+1, nombre))
         self.Comp2.addItem("%i - %s" %(i+1, nombre))
     self.Comp2.setCurrentIndex(1)
     tab=QtGui.QTabWidget()
     layout.addWidget(tab,2,1,1,5)
     self.plot=mpl()
     tab.addTab(self.plot, QtGui.QApplication.translate("equipment", "Plot"))
     self.tabla=Tabla(2, horizontalHeader=["x", "y"], stretch=False, readOnly=True)
     tab.addTab(self.tabla, QtGui.QApplication.translate("equipment", "Table"))
     
     self.Comp1.currentIndexChanged.connect(self.calculo)
     self.Comp2.currentIndexChanged.connect(self.calculo)
     
     if x and y:
         self.rellenar(x, y)
     else:
         self.calculo()
Beispiel #4
0
    def __init__(self, equipment=None, project=None, parent=None):
        """
        equipment: Initial equipment instance to model
        """
        super().__init__(Spreadsheet, entrada=True, salida=True, calculo=False, parent=parent)
        self.project = project

        # Calculate tab
        layout = QtWidgets.QGridLayout(self.Entrada)
        label = QtWidgets.QApplication.translate("pychemqt", "Spreadsheet path") + ":"
        msg = QtWidgets.QApplication.translate("pychemqt", "Select Spreadsheet")
        patrones = []
        if os.environ["ezodf"]:
            patrones.append(QtWidgets.QApplication.translate("pychemqt", "Libreoffice spreadsheet files") + " (*.ods)")
        if os.environ["xlwt"]:
            patrones.append(
                QtWidgets.QApplication.translate("pychemqt", "Microsoft Excel 97/2000/XP/2003 XML") + " (*.xls)"
            )
        if os.environ["openpyxl"]:
            patrones.append(QtWidgets.QApplication.translate("pychemqt", "Microsoft Excel 2007/2010 XML") + " (*.xlsx)")
        patron = ";;".join(patrones)
        self.filename = PathConfig(label, msg=msg, patron=patron)
        self.filename.valueChanged.connect(self.changeSpreadsheet)
        layout.addWidget(self.filename, 1, 1)
        header = [
            QtWidgets.QApplication.translate("pychemqt", "Entity"),
            QtWidgets.QApplication.translate("pychemqt", "Variable"),
            QtWidgets.QApplication.translate("pychemqt", "Unit value"),
            QtWidgets.QApplication.translate("pychemqt", "Sheet"),
            QtWidgets.QApplication.translate("pychemqt", "Cell"),
        ]
        self.datamap = Tabla(
            5,
            filas=1,
            dinamica=True,
            horizontalHeader=header,
            verticalHeader=False,
            orientacion=QtCore.Qt.AlignLeft,
            num=False,
            delegateforRow=TableDelegate,
            parent=self,
        )
        self.datamap.setEnabled(False)
        self.datamap.cellChanged.connect(self.cellChanged)
        self.datamap.rowFinished.connect(self.addRow)
        layout.addWidget(self.datamap, 2, 1)
        layout.addItem(
            QtWidgets.QSpacerItem(10, 10, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding), 10, 1
        )

        entitys = []
        for stream in list(self.project.streams.keys()):
            entitys.append("s%i" % stream)
        for equip in list(self.project.items.keys()):
            if equip[0] == "e":
                entitys.append(equip)
        self.datamap.itemDelegateForRow(0).setItemsByIndex(0, entitys)
        self.entitys = entitys
        if equipment:
            self.setEquipment(equipment)
Beispiel #5
0
    def __init__(self, parent=None):
        super(widgetReacciones, self).__init__(parent)
        self.indices, self.nombres, M=getComponents()
        gridLayout = QtWidgets.QGridLayout(self)

        self.TablaReacciones=Tabla(5, horizontalHeader=[QtWidgets.QApplication.translate("pychemqt", "Reaction"), "ΔHr, %s" %unidades.MolarEnthalpy(None).text(), QtWidgets.QApplication.translate("pychemqt", "Type"), QtWidgets.QApplication.translate("pychemqt", "Phase"), QtWidgets.QApplication.translate("pychemqt", "Description")], dinamica=False, verticalHeader=True, orientacion=QtCore.Qt.AlignLeft)
        self.TablaReacciones.setMinimumWidth(500)
        self.TablaReacciones.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
        self.TablaReacciones.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
        self.TablaReacciones.horizontalHeader().setStretchLastSection(True)
        self.TablaReacciones.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
        self.TablaReacciones.itemSelectionChanged.connect(self.actualizarBotones)
        gridLayout.addWidget(self.TablaReacciones,1,1,6,4)

        self.botonAbrir=QtWidgets.QPushButton(QtGui.QIcon(QtGui.QPixmap(os.environ["pychemqt"]+"/images/button/fileOpen.png")), QtWidgets.QApplication.translate("pychemqt", "Open"))
        self.botonAbrir.clicked.connect(self.botonAbrirClicked)
        gridLayout.addWidget(self.botonAbrir,1,5)
        self.botonGuardar=QtWidgets.QPushButton(QtGui.QIcon(QtGui.QPixmap(os.environ["pychemqt"]+"/images/button/fileSave.png")), QtWidgets.QApplication.translate("pychemqt", "Save"))
        self.botonGuardar.clicked.connect(self.botonGuardarClicked)
        self.botonGuardar.setSizePolicy(QtWidgets.QSizePolicy.Fixed,QtWidgets.QSizePolicy.Fixed)
        self.botonGuardar.setEnabled(False)
        gridLayout.addWidget(self.botonGuardar,2,5)

        self.botonNew=QtWidgets.QPushButton(QtGui.QIcon(QtGui.QPixmap(os.environ["pychemqt"]+"/images/button/fileNew.png")), QtWidgets.QApplication.translate("pychemqt", "New"))
        self.botonNew.clicked.connect(self.botonNewClicked)
        gridLayout.addWidget(self.botonNew,3,5)
        self.botonEdit=QtWidgets.QPushButton(QtGui.QIcon(QtGui.QPixmap(os.environ["pychemqt"]+"/images/button/editor.png")), QtWidgets.QApplication.translate("pychemqt", "Edit"))
        self.botonEdit.setEnabled(False)
        self.botonEdit.setCheckable(True)
        self.botonEdit.clicked.connect(self.botonEditClicked)
        gridLayout.addWidget(self.botonEdit,4,5)
        self.botonDelete=QtWidgets.QPushButton(QtGui.QIcon(QtGui.QPixmap(os.environ["pychemqt"]+"/images/button/editDelete.png")), QtWidgets.QApplication.translate("pychemqt", "Delete"))
        self.botonDelete.setEnabled(False)
        self.botonDelete.clicked.connect(self.botonDeleteClicked)
        gridLayout.addWidget(self.botonDelete,5,5)
        self.botonClear=QtWidgets.QPushButton(QtGui.QIcon(QtGui.QPixmap(os.environ["pychemqt"]+"/images/button/clear.png")), QtWidgets.QApplication.translate("pychemqt", "Clear"))
        self.botonClear.clicked.connect(self.botonClearClicked)
        gridLayout.addWidget(self.botonClear,6,5)
        gridLayout.addItem(QtWidgets.QSpacerItem(10,10,QtWidgets.QSizePolicy.Expanding,QtWidgets.QSizePolicy.Expanding),10,1)
Beispiel #6
0
    def __init__(self, equipment=None, salidas=0, parent=None):
        """
        equipment: Initial equipment instance to model
        salidas: Stream Output number to equipment
        """
        super().__init__(Divider, entrada=False, parent=parent)

        # Calculate tab
        lyt_Calc = QtWidgets.QGridLayout(self.tabCalculo)
        lyt_Calc.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Separation")), 1, 1, 1, 1)
        self.criterio = QtWidgets.QComboBox()
        for txt in self.Equipment.TEXT_CRITERIO:
            self.criterio.addItem(txt)
        self.criterio.currentIndexChanged.connect(self.criterio_Changed)
        lyt_Calc.addWidget(self.criterio, 1, 2, 1, 1)

        self.fracciones = Tabla(1, horizontalHeader=[True], stretch=False)
        self.fracciones.setItemDelegateForColumn(0, CellEditor(self))
        lyt_Calc.addWidget(self.fracciones, 2, 1, 1, 2)

        lyt_Calc.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Pressure lost")), 3, 1, 1, 1)
        self.deltaP = Entrada_con_unidades(Pressure, value=0)
        self.deltaP.valueChanged.connect(partial(self.changeParams, "deltaP"))
        lyt_Calc.addWidget(self.deltaP, 3, 2, 1, 1)

        if equipment and salidas:
            equipment(salidas=salidas)
        elif equipment:
            salidas = equipment.kwargs["salidas"]
        else:
            self.Equipment = Divider(salidas=salidas)

        self.fracciones.setRowCount(salidas)
        for i in range(salidas):
            itm = QtWidgets.QTableWidgetItem("%i" % i)
            itm.setTextAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
            self.fracciones.setItem(0, i, itm)
            self.fracciones.setRowHeight(i, 20)
            widget = UI_corriente.Ui_corriente(readOnly=True)
            self.Salida.addTab(widget, str(i+1))

        self.criterio_Changed(0)
        self.fracciones.editingFinished.connect(
            partial(self.changeParams, "split"))
        self.setEquipment(equipment)
Beispiel #7
0
    def __init__(self, parent=None):
        super(widgetReacciones, self).__init__(parent)
        self.indices, self.nombres, M=getComponents()
        gridLayout = QtWidgets.QGridLayout(self)

        self.TablaReacciones=Tabla(5, horizontalHeader=[QtWidgets.QApplication.translate("pychemqt", "Reaction"), "ΔHr, %s" %unidades.MolarEnthalpy(None).text(), QtWidgets.QApplication.translate("pychemqt", "Type"), QtWidgets.QApplication.translate("pychemqt", "Phase"), QtWidgets.QApplication.translate("pychemqt", "Description")], dinamica=False, verticalHeader=True, orientacion=QtCore.Qt.AlignLeft)
        self.TablaReacciones.setMinimumWidth(500)
        self.TablaReacciones.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
        self.TablaReacciones.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
        self.TablaReacciones.horizontalHeader().setStretchLastSection(True)
        self.TablaReacciones.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
        self.TablaReacciones.itemSelectionChanged.connect(self.actualizarBotones)
        gridLayout.addWidget(self.TablaReacciones,1,1,6,4)

        self.botonAbrir=QtWidgets.QPushButton(QtGui.QIcon(QtGui.QPixmap(os.environ["pychemqt"]+"/images/button/fileOpen.png")), QtWidgets.QApplication.translate("pychemqt", "Open"))
        self.botonAbrir.clicked.connect(self.botonAbrirClicked)
        gridLayout.addWidget(self.botonAbrir,1,5)
        self.botonGuardar=QtWidgets.QPushButton(QtGui.QIcon(QtGui.QPixmap(os.environ["pychemqt"]+"/images/button/fileSave.png")), QtWidgets.QApplication.translate("pychemqt", "Save"))
        self.botonGuardar.clicked.connect(self.botonGuardarClicked)
        self.botonGuardar.setSizePolicy(QtWidgets.QSizePolicy.Fixed,QtWidgets.QSizePolicy.Fixed)
        self.botonGuardar.setEnabled(False)
        gridLayout.addWidget(self.botonGuardar,2,5)

        self.botonNew=QtWidgets.QPushButton(QtGui.QIcon(QtGui.QPixmap(os.environ["pychemqt"]+"/images/button/fileNew.png")), QtWidgets.QApplication.translate("pychemqt", "New"))
        self.botonNew.clicked.connect(self.botonNewClicked)
        gridLayout.addWidget(self.botonNew,3,5)
        self.botonEdit=QtWidgets.QPushButton(QtGui.QIcon(QtGui.QPixmap(os.environ["pychemqt"]+"/images/button/editor.png")), QtWidgets.QApplication.translate("pychemqt", "Edit"))
        self.botonEdit.setEnabled(False)
        self.botonEdit.setCheckable(True)
        self.botonEdit.clicked.connect(self.botonEditClicked)
        gridLayout.addWidget(self.botonEdit,4,5)
        self.botonDelete=QtWidgets.QPushButton(QtGui.QIcon(QtGui.QPixmap(os.environ["pychemqt"]+"/images/button/editDelete.png")), QtWidgets.QApplication.translate("pychemqt", "Delete"))
        self.botonDelete.setEnabled(False)
        self.botonDelete.clicked.connect(self.botonDeleteClicked)
        gridLayout.addWidget(self.botonDelete,5,5)
        self.botonClear=QtWidgets.QPushButton(QtGui.QIcon(QtGui.QPixmap(os.environ["pychemqt"]+"/images/button/clear.png")), QtWidgets.QApplication.translate("pychemqt", "Clear"))
        self.botonClear.clicked.connect(self.botonClearClicked)
        gridLayout.addWidget(self.botonClear,6,5)
        gridLayout.addItem(QtWidgets.QSpacerItem(10,10,QtWidgets.QSizePolicy.Expanding,QtWidgets.QSizePolicy.Expanding),10,1)
Beispiel #8
0
    def __init__(self, ids, EoSIndex=0, parent=None):
        """Constructor"""
        super(Ui_BIP, self).__init__(parent)
        self.setWindowTitle(QtWidgets.QApplication.translate(
            "pychemqt", "BIP (Binary interaction parameters)"))

        lyt = QtWidgets.QGridLayout(self)
        lyt.addWidget(QtWidgets.QLabel("EoS"), 1, 1)
        self.eleccion = QtWidgets.QComboBox()
        lyt.addWidget(self.eleccion, 1, 2)
        lyt.addItem(QtWidgets.QSpacerItem(
            0, 0, QtWidgets.QSizePolicy.Expanding,
            QtWidgets.QSizePolicy.Fixed), 1, 3)
        self.stacked = QtWidgets.QStackedWidget()
        lyt.addWidget(self.stacked, 2, 1, 1, 3)

        # Get component names to show in table header
        names = []
        for cmp in ids:
            databank.execute(
                "SELECT id, name FROM compuestos WHERE id==%i" % cmp)
            names.append("%4i - %s" % databank.fetchone())

        args = (len(ids), len(ids))
        kw = {"stretch": False, "readOnly": True, "horizontalHeader": names,
              "verticalHeaderLabels": names}

        title = {"WILSON": "Aij", "UNIQUAC": "ΔUij", "NRTL": "Gij"}

        # Iterate over the EoS available
        for EoS in EoSBIP:
            self.eleccion.addItem(EoS)
            k = Kij(ids, EoS)

            widget = QtWidgets.QWidget()
            lyt2 = QtWidgets.QVBoxLayout(widget)
            lyt2.addWidget(QtWidgets.QLabel(title.get(EoS, "Kij")))
            table1 = Tabla(*args, **kw)
            lyt2.addWidget(table1)

            # Special case for NRTL with two interaction parameters matrix
            if EoS == "NRTL":
                lyt2.addWidget(QtWidgets.QLabel("α"))
                table2 = Tabla(*args, **kw)
                lyt2.addWidget(table2)
                kij, aij = k
                table1.setData(kij)
                table2.setData(aij)
                table1.resizeColumnsToContents()
                table2.resizeColumnsToContents()

            else:
                table1.setData(k)
                table1.resizeColumnsToContents()

            self.stacked.addWidget(widget)

        self.eleccion.currentIndexChanged.connect(self.stacked.setCurrentIndex)
        button = QtWidgets.QDialogButtonBox(
            QtWidgets.QDialogButtonBox.Cancel | QtWidgets.QDialogButtonBox.Ok)
        button.accepted.connect(self.accept)
        button.rejected.connect(self.reject)
        lyt.addWidget(button, 3, 1, 1, 3)

        self.eleccion.setCurrentIndex(EoSIndex)
Beispiel #9
0
class UI_reacciones(QtWidgets.QDialog):
    reaction = reaction.Reaction()

    def __init__(self, reaccion=None, parent=None):
        super(UI_reacciones, self).__init__(parent)
        self.evaluate = Evaluate()
        self.evaluate.finished.connect(self.rellenar)
        self.indices, self.nombres, M = getComponents()
        gridLayout = QtWidgets.QGridLayout(self)

        lyt = QtWidgets.QHBoxLayout()
        lyt.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Key component")))
        self.key = QtWidgets.QComboBox()
        for i, nombre in enumerate(self.nombres):
            self.key.addItem("%i - %s" % (i + 1, nombre))
        self.key.currentIndexChanged.connect(partial(self.changeParams, "key"))
        lyt.addWidget(self.key)
        lyt.addItem(
            QtWidgets.QSpacerItem(10, 10, QtWidgets.QSizePolicy.Expanding,
                                  QtWidgets.QSizePolicy.Fixed))
        gridLayout.addLayout(lyt, 1, 1, 1, 5)

        lyt = QtWidgets.QHBoxLayout()
        lyt.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Phase")))
        self.fase = QtWidgets.QComboBox()
        for txt in reaction.Reaction.TEXT_PHASE:
            self.fase.addItem(txt)
        self.fase.currentIndexChanged.connect(
            partial(self.changeParams, "fase"))
        lyt.addWidget(self.fase)
        self.Formula = QtWidgets.QLabel()
        self.Formula.setAlignment(QtCore.Qt.AlignCenter)
        self.Formula.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                   QtWidgets.QSizePolicy.Fixed)
        lyt.addWidget(self.Formula)
        gridLayout.addLayout(lyt, 2, 1, 1, 5)

        lyt = QtWidgets.QVBoxLayout()
        title = self.nombres[:]
        title.append("")
        self.Estequiometria = Tabla(1,
                                    verticalHeaderLabels=title,
                                    horizontalHeader=[
                                        QtWidgets.QApplication.translate(
                                            "pychemqt", "Coefficients")
                                    ],
                                    filas=len(self.indices))
        self.Estequiometria.setFixedHeight(22 * len(self.indices) + 22 + 4 +
                                           22)
        lyt.addWidget(self.Estequiometria)
        self.Estequiometria.addRow()
        brush = QtGui.QBrush(QtGui.QColor("#eaeaea"))
        self.Estequiometria.item(len(self.indices), 0).setBackground(brush)
        self.Estequiometria.item(len(self.indices),
                                 0).setFlags(QtCore.Qt.NoItemFlags)
        self.Estequiometria.cellChanged.connect(self.reaccionCambiada)
        lyt.addItem(
            QtWidgets.QSpacerItem(10, 10, QtWidgets.QSizePolicy.Fixed,
                                  QtWidgets.QSizePolicy.Expanding))
        gridLayout.addLayout(lyt, 3, 1, 1, 2)

        lyt = QtWidgets.QGridLayout()
        lyt.addItem(
            QtWidgets.QSpacerItem(10, 10, QtWidgets.QSizePolicy.Fixed,
                                  QtWidgets.QSizePolicy.Fixed), 1, 1)
        self.formula = QtWidgets.QCheckBox(
            QtWidgets.QApplication.translate("pychemqt",
                                             "Use name in formula"))
        self.formula.toggled.connect(partial(self.changeParams, "formula"))
        lyt.addWidget(self.formula, 1, 2, 1, 2)
        self.customHr = QtWidgets.QCheckBox(
            "ΔHr " +
            QtWidgets.QApplication.translate("pychemqt", "user specified"))
        self.customHr.toggled.connect(self.changeHr)
        lyt.addWidget(self.customHr, 2, 2, 1, 2)
        lyt.addWidget(QtWidgets.QLabel("ΔHr<sup>o</sup>"), 3, 2)
        self.Hr = Entrada_con_unidades(unidades.MolarEnthalpy, readOnly=True)
        self.Hr.valueChanged.connect(partial(self.changeParams, "Hr"))
        lyt.addWidget(self.Hr, 3, 3)
        lyt.addItem(
            QtWidgets.QSpacerItem(10, 10, QtWidgets.QSizePolicy.Fixed,
                                  QtWidgets.QSizePolicy.Expanding))
        gridLayout.addLayout(lyt, 3, 3, 1, 2)

        gridLayout.addItem(
            QtWidgets.QSpacerItem(10, 10, QtWidgets.QSizePolicy.Fixed,
                                  QtWidgets.QSizePolicy.Fixed), 4, 2)

        lyt = QtWidgets.QHBoxLayout()
        lyt.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Type")))
        self.tipo = QtWidgets.QComboBox()
        for txt in reaction.Reaction.TEXT_TYPE:
            self.tipo.addItem(txt)
        self.tipo.currentIndexChanged.connect(
            partial(self.changeParams, "tipo"))
        lyt.addWidget(self.tipo)
        lyt.addItem(
            QtWidgets.QSpacerItem(20, 10, QtWidgets.QSizePolicy.Fixed,
                                  QtWidgets.QSizePolicy.Fixed))
        lyt.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Concentration")))
        self.base = QtWidgets.QComboBox()
        for txt in reaction.Reaction.TEXT_BASE:
            self.base.addItem(txt)
        self.base.currentIndexChanged.connect(
            partial(self.changeParams, "base"))
        lyt.addWidget(self.base)
        lyt.addItem(
            QtWidgets.QSpacerItem(10, 10, QtWidgets.QSizePolicy.Expanding,
                                  QtWidgets.QSizePolicy.Fixed))
        gridLayout.addLayout(lyt, 5, 1, 1, 5)

        self.stacked = QtWidgets.QStackedWidget()
        self.tipo.currentIndexChanged.connect(self.stacked.setCurrentIndex)
        gridLayout.addWidget(self.stacked, 6, 1, 1, 5)
        gridLayout.addItem(
            QtWidgets.QSpacerItem(10, 10, QtWidgets.QSizePolicy.Expanding,
                                  QtWidgets.QSizePolicy.Expanding), 7, 1, 1, 5)

        widget = QtWidgets.QWidget()
        self.stacked.addWidget(widget)
        lyt = QtWidgets.QGridLayout(widget)
        lyt.addWidget(
            QtWidgets.QLabel("<h3>" + QtWidgets.QApplication.translate(
                "pychemqt", "Estequiometric reaction") + "</h3>"), 1, 1, 1, 4)
        self.Conversion = Tabla(1, verticalHeaderModel="C", filas=3)
        self.Conversion.setConnected()
        self.Conversion.setFixedWidth(100)
        lyt.addWidget(self.Conversion, 2, 1, 3, 1)
        label = QtWidgets.QLabel()
        label.setPixmap(
            QtGui.QPixmap(os.environ["pychemqt"] +
                          "/images/equation/reaction_conversion.png"))
        lyt.addWidget(label, 2, 2, 1, 3)
        lyt.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt",
                                                 "Temperature unit")), 3, 2)
        self.unidadesTemperatura = QtWidgets.QComboBox()
        for i in unidades.Temperature.__text__:
            self.unidadesTemperatura.addItem(i)
        lyt.addWidget(self.unidadesTemperatura, 3, 3)
        lyt.addItem(
            QtWidgets.QSpacerItem(10, 10, QtWidgets.QSizePolicy.Expanding,
                                  QtWidgets.QSizePolicy.Expanding), 4, 4)
        lyt.addItem(
            QtWidgets.QSpacerItem(10, 10, QtWidgets.QSizePolicy.Expanding,
                                  QtWidgets.QSizePolicy.Expanding), 5, 1, 1, 5)

        widget = QtWidgets.QWidget()
        self.stacked.addWidget(widget)
        lyt = QtWidgets.QGridLayout(widget)
        self.check_KFijo = QtWidgets.QRadioButton(
            QtWidgets.QApplication.translate("pychemqt", "Fixed"))
        self.check_KFijo.toggled.connect(self.KeqChanged)
        lyt.addWidget(self.check_KFijo, 1, 1, 1, 2)
        lyt.addWidget(QtWidgets.QLabel("K<sub>eq</sub>"), 1, 3)
        self.Keq = Entrada_con_unidades(float)
        lyt.addWidget(self.Keq, 1, 4)
        label = QtWidgets.QLabel()
        label.setPixmap(
            QtGui.QPixmap(os.environ["pychemqt"] +
                          "/images/equation/reaction_equilibrium.png"))
        lyt.addWidget(label, 1, 5, 1, 4)

        self.check_KEq = QtWidgets.QRadioButton(
            QtWidgets.QApplication.translate("pychemqt", "Equation"))
        self.check_KEq.toggled.connect(self.KeqChanged)
        lyt.addWidget(self.check_KEq, 2, 1, 1, 2)
        self.check_KTabla = QtWidgets.QRadioButton(
            QtWidgets.QApplication.translate("pychemqt", "Table"))
        self.check_KTabla.toggled.connect(self.KeqChanged)
        lyt.addWidget(self.check_KTabla, 2, 5, 1, 2)
        self.KEq_Dat = Tabla(
            1,
            verticalHeaderLabels=["A", "B", "C", "D", "E", "F", "G", "H"],
            filas=8)
        self.KEq_Dat.setFixedHeight(22 * 8 + 4)
        self.KEq_Dat.setFixedWidth(120)
        lyt.addWidget(self.KEq_Dat, 3, 3, 1, 2)
        self.KEq_Tab = Tabla(
            4,
            horizontalHeader=["T, K", "Keq", "Kcalc", "%Error"],
            verticalHeader=False,
            columnReadOnly=[False, False, True, True])
        self.KEq_Tab.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                   QtWidgets.QSizePolicy.Expanding)
        self.KEq_Tab.setFixedWidth(400)
        self.KEq_Tab.setConnected()
        self.KEq_Tab.rowFinished.connect(self.Regresion)
        self.KEq_Tab.setAlternatingRowColors(False)
        lyt.addWidget(self.KEq_Tab, 3, 5, 1, 4)
        lyt.addWidget(QtWidgets.QLabel("r²"), 4, 5)
        self.r2 = Entrada_con_unidades(float, readOnly=True)
        lyt.addWidget(self.r2, 4, 6)
        self.botonTablaPlot = QtWidgets.QPushButton(
            QtGui.QIcon(
                QtGui.QPixmap(os.environ["pychemqt"] +
                              "/images/button/plot.png")),
            QtWidgets.QApplication.translate("pychemqt", "Plot"))
        self.botonTablaPlot.clicked.connect(self.Plot)
        lyt.addWidget(self.botonTablaPlot, 4, 7)
        self.botonTablaClear = QtWidgets.QPushButton(
            QtGui.QIcon(
                QtGui.QPixmap(os.environ["pychemqt"] +
                              "/images/button/clear.png")),
            QtWidgets.QApplication.translate("pychemqt", "Clear"))
        self.botonTablaClear.clicked.connect(self.KEq_Tab.clear)
        lyt.addWidget(self.botonTablaClear, 4, 8)
        label = QtWidgets.QLabel()
        label.setPixmap(
            QtGui.QPixmap(os.environ["pychemqt"] +
                          "/images/equation/reaction_equilibrium2.png"))
        label.setAlignment(QtCore.Qt.AlignCenter)
        lyt.addWidget(label, 5, 1, 1, 8)

        self.checkGibbs = QtWidgets.QRadioButton(
            QtWidgets.QApplication.translate(
                "pychemqt", "From Gibbs free energy minimization"))
        lyt.addWidget(self.checkGibbs, 6, 1, 1, 4)

        self.check_KFijo.setChecked(True)

        widget = QtWidgets.QWidget()
        self.stacked.addWidget(widget)
        lyt = QtWidgets.QGridLayout(widget)

        widget = QtWidgets.QWidget()
        self.stacked.addWidget(widget)
        lyt = QtWidgets.QGridLayout(widget)

        self.status = Status()
        gridLayout.addWidget(self.status, 10, 1)
        self.buttonBox = QtWidgets.QDialogButtonBox(
            QtWidgets.QDialogButtonBox.Cancel | QtWidgets.QDialogButtonBox.Ok)
        self.buttonBox.accepted.connect(self.accept)
        self.buttonBox.rejected.connect(self.reject)
        gridLayout.addWidget(self.buttonBox, 10, 2, 1, 4)

        if reaccion:
            self.setReaction(reaccion)

    def changeParams(self, parametro, valor):
        self.calculo(**{parametro: valor})

    def calculo(self, **kwargs):
        self.status.setState(4)
        self.evaluate.start(self.reaction, kwargs)

    def changeHr(self, bool):
        self.Hr.setReadOnly(not bool)
        self.changeParams("customHr", bool)

    def reaccionCambiada(self):
        kwargs = {
            "componentes": self.indices,
            "coeficientes": self.Estequiometria.getColumn(0)[:-1]
        }
        self.calculo(**kwargs)

    def setReaction(self, reaction):
        self.reaction = reaction
        self.rellenar()


#        if self.Estequiometria.getValue(0, self.Base.currentIndex()):
#            reaccion=reaction.Reaction(self.indices, self.Estequiometria.getColumn(0), base=self.Base.currentIndex(), estequiometria=[0, 0, 0.5], formulas=self.checkFormula.isChecked(), calor=self.checkCalorEspecificado.isChecked(), Hr=self.Hr.value, tipo=self.tipo.currentIndex(), conversion=self.Conversion.getColumn(0)[-1::-1])
#            self.Balance.setValue(reaccion.error)
#            if reaccion.state:
#                self.Formula.setText(reaccion._txt(self.checkFormula.isChecked()))
#                self.Hr.setValue(reaccion.Hr)
#            else:
#                self.Formula.clear()
#                self.Hr.clear()
#            self.botonAdd.setEnabled(reaccion.state and not self.botonEdit.isChecked())
#            self.reaccion=reaccion

    def rellenar(self):
        self.blockSignals(True)
        for variable in self.reaction.kwargsValue:
            self.__getattribute__(variable).setValue(
                self.reaction.kwargs[variable])
        for combo in self.reaction.kwargsList:
            self.__getattribute__(combo).setCurrentIndex(
                self.reaction.kwargs[combo])
        for check in self.reaction.kwargsCheck:
            self.__getattribute__(check).setChecked(
                self.reaction.kwargs[check])

        self.Estequiometria.setColumn(0, self.reaction.kwargs["coeficientes"])
        #        self.Conversion.setColumn(0, self.reaction.estequiometria[-1::-1])
        self.blockSignals(False)

        self.status.setState(self.reaction.status, self.reaction.msg)
        self.Estequiometria.item(len(self.indices),
                                 0).setText(str(self.reaction.error))
        if self.reaction.status:
            self.Formula.setText(self.reaction._txt())
            self.Hr.setValue(self.reaction.Hr)

    def KeqChanged(self):
        self.Keq.setReadOnly(not self.check_KFijo.isChecked())
        self.KEq_Dat.setEnabled(self.check_KEq.isChecked())
        self.KEq_Tab.setEnabled(self.check_KTabla.isChecked())
        self.botonTablaClear.setEnabled(self.check_KTabla.isChecked())
        self.botonTablaPlot.setEnabled(self.check_KTabla.isChecked())

    def Regresion(self):
        t = array(self.KEq_Tab.getColumn(0)[:-1])
        k = array(self.KEq_Tab.getColumn(1)[:-1])
        if len(t) >= 4:
            if 4 <= len(t) < 8:
                inicio = r_[0, 0, 0, 0]
                f = lambda par, T: exp(par[0] + par[1] / T + par[2] * log(T) +
                                       par[3] * T)
                resto = lambda par, T, k: k - f(par, T)
            else:
                inicio = r_[0, 0, 0, 0, 0, 0, 0, 0]
                f = lambda par, T: exp(par[0] + par[1] / T + par[2] * log(
                    T) + par[3] * T + par[4] * T**2 + par[5] * T**3 + par[6] *
                                       T**4 + par[7] * T**5)
                resto = lambda par, T, k: k - f(par, T)

            ajuste = leastsq(resto, inicio, args=(t, k))
            kcalc = f(ajuste[0], t)
            error = (k - kcalc) / k * 100
            self.KEq_Dat.setColumn(0, ajuste[0])
            self.KEq_Tab.setColumn(2, kcalc)
            self.KEq_Tab.setColumn(3, error)

            if ajuste[1] in [1, 2, 3, 4]:
                self.ajuste = ajuste[0]

    def Plot(self):
        if self.ajuste != None:
            t = array(self.KEq_Tab.getColumn(0)[:-1])
            k = array(self.KEq_Tab.getColumn(1)[:-1])
            if 4 <= len(t) < 8:
                f = lambda par, T: exp(par[0] + par[1] / T + par[2] * log(T) +
                                       par[3] * T)
            else:
                f = lambda par, T: exp(par[0] + par[1] / T + par[2] * log(
                    T) + par[3] * T + par[4] * T**2 + par[5] * T**3 + par[6] *
                                       T**4 + par[7] * T**5)

            grafico = plot.Plot()
            grafico.data(t, k, 'ro', t, f(self.ajuste, t))
            grafico.exec_()
Beispiel #10
0
class UI_equipment(UI_equip):
    """Divider equipment edition dialog"""
    Equipment = Divider()

    def __init__(self, equipment=None, salidas=0, parent=None):
        """
        equipment: Initial equipment instance to model
        salidas: Stream Output number to equipment
        """
        super().__init__(Divider, entrada=False, parent=parent)

        # Calculate tab
        lyt_Calc = QtWidgets.QGridLayout(self.tabCalculo)
        lyt_Calc.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Separation")), 1, 1, 1, 1)
        self.criterio = QtWidgets.QComboBox()
        for txt in self.Equipment.TEXT_CRITERIO:
            self.criterio.addItem(txt)
        self.criterio.currentIndexChanged.connect(self.criterio_Changed)
        lyt_Calc.addWidget(self.criterio, 1, 2, 1, 1)

        self.fracciones = Tabla(1, horizontalHeader=[True], stretch=False)
        self.fracciones.setItemDelegateForColumn(0, CellEditor(self))
        lyt_Calc.addWidget(self.fracciones, 2, 1, 1, 2)

        lyt_Calc.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Pressure lost")), 3, 1, 1, 1)
        self.deltaP = Entrada_con_unidades(Pressure, value=0)
        self.deltaP.valueChanged.connect(partial(self.changeParams, "deltaP"))
        lyt_Calc.addWidget(self.deltaP, 3, 2, 1, 1)

        if equipment and salidas:
            equipment(salidas=salidas)
        elif equipment:
            salidas = equipment.kwargs["salidas"]
        else:
            self.Equipment = Divider(salidas=salidas)

        self.fracciones.setRowCount(salidas)
        for i in range(salidas):
            itm = QtWidgets.QTableWidgetItem("%i" % i)
            itm.setTextAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
            self.fracciones.setItem(0, i, itm)
            self.fracciones.setRowHeight(i, 20)
            widget = UI_corriente.Ui_corriente(readOnly=True)
            self.Salida.addTab(widget, str(i+1))

        self.criterio_Changed(0)
        self.fracciones.editingFinished.connect(
            partial(self.changeParams, "split"))
        self.setEquipment(equipment)

    def criterio_Changed(self, int):
        if int:
            item = QtWidgets.QTableWidgetItem(QtWidgets.QApplication.translate(
                "pychemqt", "Flow")+", "+MassFlow.text())
            self.fracciones.setHorizontalHeaderItem(0, item)
            self.fracciones.item(self.fracciones.rowCount()-1, 0).setFlags(
                QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsEnabled |
                QtCore.Qt.ItemIsSelectable)
        else:
            item = QtWidgets.QTableWidgetItem(QtWidgets.QApplication.translate(
                "pychemqt", "Flow")+", "+MassFlow.text())
            self.fracciones.setHorizontalHeaderItem(0, item)
            self.fracciones.item(self.fracciones.rowCount()-1, 0).setFlags(
                QtCore.Qt.NoItemFlags)
        self.changeParams("criterio", int)

    def changeParams(self, parametro, valor=None):
        if parametro == "split":
            valor = self.fracciones.getColumn(0, False)
            if self.criterio.currentIndex() == 0:
                if len(valor)+1 < self.fracciones.rowCount():
                    return
                elif len(valor)+1 == self.fracciones.rowCount():
                    valor.append(1-sum(valor))
                elif len(valor) == self.fracciones.rowCount():
                    valor[-1] = 1-sum(valor[:-1])
        self.calculo(**{parametro: valor})

    def rellenar(self):
        UI_equip.rellenar(self)
        if self.Equipment.status == 1 and self.criterio.currentIndex() == 1:
                self.entrada.setCorriente(self.Equipment.entrada)

    def rellenarInput(self):
        UI_equip.rellenarInput(self)
        self.fracciones.setColumn(0, self.Equipment.kwargs["split"])
Beispiel #11
0
class Binary_distillation(QtGui.QDialog):
    title=QtGui.QApplication.translate("pychemqt", "x-y Distillation")
    def __init__(self, indices=None, nombres=None, x=None, y=None, parent=None):
        super(Binary_distillation, self).__init__(parent)
        self.setWindowTitle(self.title)
        layout=QtGui.QGridLayout(self)
        layout.addWidget(QtGui.QLabel(QtGui.QApplication.translate("equipment", "Component 1:")),1,1)
        self.Comp1=QtGui.QComboBox()
        layout.addWidget(self.Comp1,1,2)
        layout.addWidget(QtGui.QLabel(QtGui.QApplication.translate("equipment", "Component 2:")),1,4)
        self.Comp2=QtGui.QComboBox()
        layout.addWidget(self.Comp2,1,5)
        
        self.indices=indices
        self.nombres=nombres
        for i, nombre in enumerate(nombres):
            self.Comp1.addItem("%i - %s" %(i+1, nombre))
            self.Comp2.addItem("%i - %s" %(i+1, nombre))
        self.Comp2.setCurrentIndex(1)
        tab=QtGui.QTabWidget()
        layout.addWidget(tab,2,1,1,5)
        self.plot=mpl()
        tab.addTab(self.plot, QtGui.QApplication.translate("equipment", "Plot"))
        self.tabla=Tabla(2, horizontalHeader=["x", "y"], stretch=False, readOnly=True)
        tab.addTab(self.tabla, QtGui.QApplication.translate("equipment", "Table"))
        
        self.Comp1.currentIndexChanged.connect(self.calculo)
        self.Comp2.currentIndexChanged.connect(self.calculo)
        
        if x and y:
            self.rellenar(x, y)
        else:
            self.calculo()
        
    def rellenar(self, x, y):
        self.x=x
        self.y=y
        self.plot.axes2D.clear()
        self.plot.data([0, 1], [0, 1], x, y, 'ro')

        self.tabla.setMatrix(transpose([x, y]))

    def calculo(self):
        ind1=self.Comp1.currentIndex()
        ind2=self.Comp2.currentIndex()
        if ind1!=ind2:
            zi=arange(0.025, 1., 0.025)
            id1=self.indices[ind1]
            id2=self.indices[ind2]
            x=[0]
            y=[0]
            for z in zi:
                try:
                    fraccion=[0.]*len(self.indices)
                    fraccion[ind1]=z
                    fraccion[ind2]=1-z
                    mez=Mezcla(tipo=3, fraccionMolar=fraccion, caudalMasico=1.)
                    tb=mez.componente[0].Tb
                    corr=Corriente(T=tb, P=101325., mezcla=mez)
                    T=corr.eos._Dew_T()
                    corr=Corriente(T=T, P=101325., mezcla=mez)
                    while corr.Liquido.fraccion[0]==corr.Gas.fraccion[0] and corr.T<corr.mezcla.componente[1].Tb:
                        corr=Corriente(T=corr.T-0.1, P=101325., mezcla=mez)
                    x.append(corr.Liquido.fraccion[0])
                    y.append(corr.Gas.fraccion[0])
                except:
                    pass
            x.append(1)
            y.append(1)
            self.rellenar(x, y)

    def writeToStream(self, stream):
        stream.writeInt32(self.widget().Comp1.currentIndex())
        stream.writeInt32(self.widget().Comp2.currentIndex())
        stream.writeInt32(len(self.widget().x))
        for i in self.widget().x:
            stream.writeFloat(i)
        for i in self.widget().y:
            stream.writeFloat(i)
    
    @classmethod
    def readToStream(cls, stream):
        id1=stream.readInt32()
        id2=stream.readInt32()
        len=stream.readInt32()
        x=[]
        for i in range(len):
            x.append(stream.readFloat())
        y=[]
        for i in range(len):
            y.append(stream.readFloat())
        self.plot(0, x, y)
Beispiel #12
0
class widgetReacciones(QtWidgets.QWidget):
    """Widget con la tabla de reacciones y los botones para modificar la lista de reacciones"""
    changed = QtCore.pyqtSignal()
    reacciones=[]
    reaccion=None
    activo=None
    ajuste=None

    def __init__(self, parent=None):
        super(widgetReacciones, self).__init__(parent)
        self.indices, self.nombres, M=getComponents()
        gridLayout = QtWidgets.QGridLayout(self)

        self.TablaReacciones=Tabla(5, horizontalHeader=[QtWidgets.QApplication.translate("pychemqt", "Reaction"), "ΔHr, %s" %unidades.MolarEnthalpy(None).text(), QtWidgets.QApplication.translate("pychemqt", "Type"), QtWidgets.QApplication.translate("pychemqt", "Phase"), QtWidgets.QApplication.translate("pychemqt", "Description")], dinamica=False, verticalHeader=True, orientacion=QtCore.Qt.AlignLeft)
        self.TablaReacciones.setMinimumWidth(500)
        self.TablaReacciones.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
        self.TablaReacciones.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
        self.TablaReacciones.horizontalHeader().setStretchLastSection(True)
        self.TablaReacciones.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
        self.TablaReacciones.itemSelectionChanged.connect(self.actualizarBotones)
        gridLayout.addWidget(self.TablaReacciones,1,1,6,4)

        self.botonAbrir=QtWidgets.QPushButton(QtGui.QIcon(QtGui.QPixmap(os.environ["pychemqt"]+"/images/button/fileOpen.png")), QtWidgets.QApplication.translate("pychemqt", "Open"))
        self.botonAbrir.clicked.connect(self.botonAbrirClicked)
        gridLayout.addWidget(self.botonAbrir,1,5)
        self.botonGuardar=QtWidgets.QPushButton(QtGui.QIcon(QtGui.QPixmap(os.environ["pychemqt"]+"/images/button/fileSave.png")), QtWidgets.QApplication.translate("pychemqt", "Save"))
        self.botonGuardar.clicked.connect(self.botonGuardarClicked)
        self.botonGuardar.setSizePolicy(QtWidgets.QSizePolicy.Fixed,QtWidgets.QSizePolicy.Fixed)
        self.botonGuardar.setEnabled(False)
        gridLayout.addWidget(self.botonGuardar,2,5)

        self.botonNew=QtWidgets.QPushButton(QtGui.QIcon(QtGui.QPixmap(os.environ["pychemqt"]+"/images/button/fileNew.png")), QtWidgets.QApplication.translate("pychemqt", "New"))
        self.botonNew.clicked.connect(self.botonNewClicked)
        gridLayout.addWidget(self.botonNew,3,5)
        self.botonEdit=QtWidgets.QPushButton(QtGui.QIcon(QtGui.QPixmap(os.environ["pychemqt"]+"/images/button/editor.png")), QtWidgets.QApplication.translate("pychemqt", "Edit"))
        self.botonEdit.setEnabled(False)
        self.botonEdit.setCheckable(True)
        self.botonEdit.clicked.connect(self.botonEditClicked)
        gridLayout.addWidget(self.botonEdit,4,5)
        self.botonDelete=QtWidgets.QPushButton(QtGui.QIcon(QtGui.QPixmap(os.environ["pychemqt"]+"/images/button/editDelete.png")), QtWidgets.QApplication.translate("pychemqt", "Delete"))
        self.botonDelete.setEnabled(False)
        self.botonDelete.clicked.connect(self.botonDeleteClicked)
        gridLayout.addWidget(self.botonDelete,5,5)
        self.botonClear=QtWidgets.QPushButton(QtGui.QIcon(QtGui.QPixmap(os.environ["pychemqt"]+"/images/button/clear.png")), QtWidgets.QApplication.translate("pychemqt", "Clear"))
        self.botonClear.clicked.connect(self.botonClearClicked)
        gridLayout.addWidget(self.botonClear,6,5)
        gridLayout.addItem(QtWidgets.QSpacerItem(10,10,QtWidgets.QSizePolicy.Expanding,QtWidgets.QSizePolicy.Expanding),10,1)


    def actualizarBotones(self, bool=True):
        self.botonEdit.setEnabled(bool)
        self.botonDelete.setEnabled(bool)

    def botonAbrirClicked(self):
        fname = str(QtWidgets.QFileDialog.getOpenFileName(self, QtWidgets.QApplication.translate("pychemqt", "Open reaction file"), "./", QtWidgets.QApplication.translate("pychemqt", "reaction file")+" (*.rec);;"+QtWidgets.QApplication.translate("pychemqt", "All files")+" (*.*)")[0])
        if fname:
            with open(fname, "r") as archivo:
                reacciones=pickle.load(archivo)
            print(reacciones)
            self.reacciones=reacciones
            self.botonGuardar.setEnabled(True)
            for fila, reaccion in enumerate(reacciones):
                self.TablaReacciones.addRow()
                self.TablaReacciones.setValue(fila, 0, reaccion.text)
                self.TablaReacciones.setValue(fila, 1, "%0.4e" %reaccion.Hr.config(), QtCore.Qt.AlignRight)
                self.TablaReacciones.setValue(fila, 2, str(reaccion.tipo+1)+" - "+reaction.Reaction.TEXT_TYPE[reaccion.tipo])
                self.TablaReacciones.setValue(fila, 3, reaction.Reaction.TEXT_PHASE[reaccion.fase])
                self.TablaReacciones.item(fila, 4).setFlags(QtCore.Qt.ItemIsEditable|QtCore.Qt.ItemIsEnabled|QtCore.Qt.ItemIsSelectable)
            for i in range(4):
                self.TablaReacciones.resizeColumnToContents(i)
        self.changed.emit()

    def botonGuardarClicked(self):
        fname = str(QtWidgets.QFileDialog.getSaveFileName(self, QtWidgets.QApplication.translate("pychemqt", "Save reaction to file"), "./", QtWidgets.QApplication.translate("pychemqt", "reaction file")+" (*.rec)")[0])
        if fname:
            if fname.split(".")[-1]!="rec":
                fname+=".rec"
            pickle.dump(self.reacciones, open(fname, "w"))

    def botonNewClicked(self):
        dialog=UI_reacciones(parent=self)
        if dialog.exec_():
            pass


    def botonEditClicked(self, bool):
        if bool:
            indice=self.TablaReacciones.currentRow()
            reaccion=self.reacciones[indice]
            dialogo=UI_reacciones(reaccion, self)
            dialogo.exec_()
#            self.rellenar(self.reaccion)
#            self.activo=indice
        else:
            self.botonAddClicked(self.activo, False)
            self.reacciones[self.activo]=self.reaccion
            self.TablaReacciones.setCurrentCell(self.activo, 0)
            self.activo=-1
            self.changed.emit()

        self.botonNew.setEnabled(not bool)
        self.botonDelete.setEnabled(not bool)
        self.botonClear.setEnabled(not bool)
        self.botonAdd.setEnabled(not bool)
        self.botonAbrir.setEnabled(not bool)
        self.botonGuardar.setEnabled(not bool)


    def botonDeleteClicked(self):
        indice=self.TablaReacciones.currentRow()
        self.TablaReacciones.removeRow(indice)
        del self.reacciones[indice]
        self.TablaReacciones.clearSelection()
        self.actualizarBotones(False)
        self.changed.emit()

    def botonClearClicked(self):
        if self.reacciones:
            self.reacciones=[]
            self.TablaReacciones.setRowCount(0)
            self.botonGuardar.setEnabled(False)

    def botonAddClicked(self, fila, add=True):
        if add:
            fila=self.TablaReacciones.rowCount()
            self.TablaReacciones.addRow()
        self.TablaReacciones.setValue(fila, 0, self.Formula.text())
        self.TablaReacciones.setValue(fila, 1, "%0.4e" %self.Hr.value.config(), QtCore.Qt.AlignRight)
        self.TablaReacciones.setValue(fila, 2, str(self.tipo.currentIndex()+1)+" - "+self.tipo.currentText())
        self.TablaReacciones.setValue(fila, 3, self.Fase.currentText())
        self.TablaReacciones.item(fila, 4).setFlags(QtCore.Qt.ItemIsEditable|QtCore.Qt.ItemIsEnabled|QtCore.Qt.ItemIsSelectable)
        for i in range(4):
            self.TablaReacciones.resizeColumnToContents(i)
        self.reacciones.insert(fila, self.reaccion)
        self.botonGuardar.setEnabled(True)
        self.changed.emit()
Beispiel #13
0
    def __init__(self, parent=None):
        super(Definicion_Petro, self).__init__(parent)
        self.setWindowTitle(
            QtGui.QApplication.translate("pychemqt",
                                         "Petrol component definition"))
        layout = QtGui.QGridLayout(self)
        layout.addWidget(
            QtGui.QLabel(QtGui.QApplication.translate("pychemqt", "Name")), 1,
            1)
        self.nombre = QtGui.QLineEdit()
        self.nombre.textChanged.connect(partial(self.changeParams, "name"))
        layout.addWidget(self.nombre, 1, 2, 1, 4)
        layout.addItem(
            QtGui.QSpacerItem(10, 10, QtGui.QSizePolicy.Fixed,
                              QtGui.QSizePolicy.Fixed), 2, 1, 1, 2)
        layout.addWidget(
            QtGui.QLabel(
                QtGui.QApplication.translate("pychemqt", "Boiling point")), 3,
            1)
        self.Tb = Entrada_con_unidades(Temperature)
        self.Tb.valueChanged.connect(partial(self.changeParams, "Tb"))
        layout.addWidget(self.Tb, 3, 2)
        layout.addWidget(
            QtGui.QLabel(
                QtGui.QApplication.translate("pychemqt", "Molecular Weight")),
            4, 1)
        self.M = Entrada_con_unidades(float, textounidad="g/mol")
        self.M.valueChanged.connect(partial(self.changeParams, "M"))
        layout.addWidget(self.M, 4, 2)
        layout.addWidget(
            QtGui.QLabel(
                QtGui.QApplication.translate("pychemqt", "Specific Gravity")),
            5, 1)
        self.SG = Entrada_con_unidades(float)
        self.SG.valueChanged.connect(partial(self.changeParams, "SG"))
        layout.addWidget(self.SG, 5, 2)
        layout.addWidget(
            QtGui.QLabel(
                QtGui.QApplication.translate("pychemqt", "API gravity")), 6, 1)
        self.API = Entrada_con_unidades(float)
        self.API.valueChanged.connect(partial(self.changeParams, "API"))
        layout.addWidget(self.API, 6, 2)
        layout.addWidget(QtGui.QLabel("K watson:"), 7, 1)
        self.Kw = Entrada_con_unidades(float)
        self.Kw.valueChanged.connect(partial(self.changeParams, "Kw"))
        layout.addWidget(self.Kw, 7, 2)
        layout.addWidget(QtGui.QLabel("C/H:"), 8, 1)
        self.CH = Entrada_con_unidades(float)
        self.CH.valueChanged.connect(partial(self.changeParams, "CH"))
        layout.addWidget(self.CH, 8, 2)
        layout.addWidget(QtGui.QLabel(u"ν<sub>100F</sub>:"), 9, 1)
        self.v100 = Entrada_con_unidades(Diffusivity)
        self.v100.valueChanged.connect(partial(self.changeParams, "v100"))
        layout.addWidget(self.v100, 9, 2)
        layout.addWidget(QtGui.QLabel(u"ν<sub>210F</sub>:"), 10, 1)
        self.v210 = Entrada_con_unidades(Diffusivity)
        self.v210.valueChanged.connect(partial(self.changeParams, "v210"))
        layout.addWidget(self.v210, 10, 2)
        layout.addWidget(
            QtGui.QLabel(
                QtGui.QApplication.translate("pychemqt", "Refraction index")),
            11, 1)
        self.n = Entrada_con_unidades(float)
        self.n.valueChanged.connect(partial(self.changeParams, "n"))
        layout.addWidget(self.n, 11, 2)
        layout.addWidget(
            QtGui.QLabel(
                QtGui.QApplication.translate("pychemqt", "Huang parameter")),
            12, 1)
        self.I = Entrada_con_unidades(float)
        self.I.valueChanged.connect(partial(self.changeParams, "I"))
        layout.addWidget(self.I, 12, 2)
        layout.addWidget(QtGui.QLabel("%S"), 13, 1)
        self.S = Entrada_con_unidades(float, spinbox=True, step=1.0, max=100)
        self.S.valueChanged.connect(partial(self.changeParams, "S"))
        layout.addWidget(self.S, 13, 2)
        layout.addWidget(QtGui.QLabel("%H"), 14, 1)
        self.H = Entrada_con_unidades(float, spinbox=True, step=1.0, max=100)
        self.H.valueChanged.connect(partial(self.changeParams, "H"))
        layout.addWidget(self.H, 14, 2)
        layout.addWidget(QtGui.QLabel("%N"), 15, 1)
        self.N = Entrada_con_unidades(float, spinbox=True, step=1.0, max=100)
        self.N.valueChanged.connect(partial(self.changeParams, "N"))
        layout.addWidget(self.N, 15, 2)

        layout.addWidget(
            QtGui.QLabel(
                QtGui.QApplication.translate("pychemqt", "Carbons number")),
            19, 1)
        self.carbonos = Entrada_con_unidades(int,
                                             width=50,
                                             spinbox=True,
                                             step=1,
                                             start=7,
                                             min=5,
                                             max=100)
        self.N.valueChanged.connect(partial(self.changeParams, "Nc"))
        layout.addWidget(self.carbonos, 19, 2)

        layout.addItem(
            QtGui.QSpacerItem(10, 10, QtGui.QSizePolicy.Expanding,
                              QtGui.QSizePolicy.Expanding), 3, 3, 15, 1)
        self.checkCurva = QtGui.QCheckBox(
            QtGui.QApplication.translate("pychemqt",
                                         "Define destillation curve"))
        layout.addWidget(self.checkCurva, 3, 4, 1, 2)
        self.tipoCurva = QtGui.QComboBox()
        self.tipoCurva.addItem("ASTM D86")
        self.tipoCurva.addItem("TBP")
        self.tipoCurva.addItem("EFV")
        self.tipoCurva.addItem("ASTM D1186")
        self.tipoCurva.addItem("ASTM D2887 (SD)")
        self.tipoCurva.setEnabled(False)
        layout.addWidget(self.tipoCurva, 4, 4, 1, 2)
        self.textoPresion = QtGui.QLabel(
            QtGui.QApplication.translate("pychemqt", "Pressure"))
        self.textoPresion.setEnabled(False)
        layout.addWidget(self.textoPresion, 5, 4)
        self.presion = Entrada_con_unidades(Pressure, value=101325.)
        self.presion.setEnabled(False)
        self.presion.valueChanged.connect(partial(self.changeParams, "P_dist"))
        layout.addWidget(self.presion, 5, 5)
        self.curvaDestilacion = Tabla(
            2,
            filas=1,
            horizontalHeader=["%dist", "Tb, " + Temperature.text()],
            verticalHeader=False,
            dinamica=True)
        self.curvaDestilacion.setEnabled(False)
        self.curvaDestilacion.editingFinished.connect(self.changeCurva)
        layout.addWidget(self.curvaDestilacion, 6, 4, 13, 2)
        self.checkBlend = QtGui.QCheckBox(
            QtGui.QApplication.translate("pychemqt", "Blend if its necessary"))
        layout.addWidget(self.checkBlend, 19, 4, 1, 2)

        self.checkCurva.toggled.connect(self.tipoCurva.setEnabled)
        self.checkCurva.toggled.connect(self.presion.setEnabled)
        self.checkCurva.toggled.connect(self.textoPresion.setEnabled)
        self.checkCurva.toggled.connect(self.curvaDestilacion.setEnabled)

        layout.addItem(
            QtGui.QSpacerItem(20, 20, QtGui.QSizePolicy.Fixed,
                              QtGui.QSizePolicy.Fixed), 20, 1, 1, 2)
        self.checkCrudo = QtGui.QCheckBox(
            QtGui.QApplication.translate("pychemqt",
                                         "Use petrol fraction from list"))
        self.checkCrudo.toggled.connect(self.changeUnknown)
        layout.addWidget(self.checkCrudo, 21, 1, 1, 2)
        self.crudo = QtGui.QComboBox()
        self.crudo.setEnabled(False)
        self.crudo.addItem("")
        for i in crudo[1:]:
            self.crudo.addItem("%s (%s)  API: %s %S: %s" %
                               (i[0], i[1], i[3], i[4]))
            # i[0]+" ("+i[1]+")"+"   API: "+str(i[3])+"  %S: "+str(i[4]))
        self.crudo.currentIndexChanged.connect(
            partial(self.changeParams, "indice"))
        layout.addWidget(self.crudo, 23, 1, 1, 5)
        layout.addWidget(QtGui.QLabel("Pseudo C+"), 24, 1)
        self.Cplus = Entrada_con_unidades(int,
                                          width=50,
                                          spinbox=True,
                                          step=1,
                                          min=6)
        self.Cplus.valueChanged.connect(partial(self.changeParams, "Cplus"))
        layout.addWidget(self.Cplus, 24, 2)
        self.checkCrudo.toggled.connect(self.crudo.setEnabled)
        self.checkCrudo.toggled.connect(self.Cplus.setEnabled)
        layout.addItem(
            QtGui.QSpacerItem(5, 5, QtGui.QSizePolicy.Expanding,
                              QtGui.QSizePolicy.Expanding), 29, 1, 1, 2)

        newComponent.loadUI(self)

        self.Petroleo = Petroleo()
        self.Crudo = Crudo()
Beispiel #14
0
    def __init__(self, elemento, parent=None):
        super(ElementDialog, self).__init__(parent)
        self.setWindowTitle(
            QtWidgets.QApplication.translate("pychemqt",
                                             "Properties of " + elemento.name))
        lyt = QtWidgets.QVBoxLayout(self)
        tabWidget = QtWidgets.QTabWidget()
        lyt.addWidget(tabWidget)
        btbox = QtWidgets.QDialogButtonBox(QtWidgets.QDialogButtonBox.Close)
        btbox.rejected.connect(self.reject)
        lyt.addWidget(btbox)

        tabGeneral = QtWidgets.QWidget()
        layoutGeneral = QtWidgets.QGridLayout(tabGeneral)
        layoutGeneral.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Name:")), 1, 1)
        layoutGeneral.addWidget(QtWidgets.QLabel(elemento.name), 1, 2)
        layoutGeneral.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Serie:")), 2, 1)
        layoutGeneral.addWidget(QtWidgets.QLabel(elemento.serie), 2, 2)
        layoutGeneral.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Group")), 3, 1)
        layoutGeneral.addWidget(QtWidgets.QLabel(str(elemento.group)), 3, 2)
        layoutGeneral.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Period")), 4, 1)
        layoutGeneral.addWidget(QtWidgets.QLabel(str(elemento.period)), 4, 2)
        layoutGeneral.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Block")), 5, 1)
        layoutGeneral.addWidget(QtWidgets.QLabel(elemento.block), 5, 2)

        layoutGeneral.addItem(
            QtWidgets.QSpacerItem(20, 20, QtWidgets.QSizePolicy.Fixed,
                                  QtWidgets.QSizePolicy.Fixed), 6, 1)
        label = QtWidgets.QLabel(
            QtWidgets.QApplication.translate("pychemqt", "History"))
        font = QtGui.QFont()
        font.setWeight(75)
        font.setBold(True)
        label.setFont(font)
        layoutGeneral.addWidget(label, 7, 1, 1, 3)
        label_8 = QtWidgets.QLabel(
            QtWidgets.QApplication.translate("pychemqt", "Discovery") + ": " +
            elemento.country + "(" + elemento.country + ")" + os.linesep +
            QtWidgets.QApplication.translate("pychemqt", "Discovered by ") +
            elemento.discover + os.linesep +
            QtWidgets.QApplication.translate("pychemqt", "Etymology") + ": " +
            elemento.etymology)
        label_8.setMargin(5)
        label_8.setWordWrap(True)
        layoutGeneral.addWidget(label_8, 8, 1, 1, 3)
        self.botoncito = QtWidgets.QLabel()
        self.botoncito.setStyleSheet("background-color: %s;" % elemento.color)
        self.botoncito.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.botoncito.setFixedSize(60, 60)
        layoutGeneral.addWidget(self.botoncito, 1, 5, 3, 1)
        label = QtWidgets.QLabel()
        label.setText(str(elemento.id))
        label.setAlignment(QtCore.Qt.AlignCenter | QtCore.Qt.AlignBottom)
        layoutGeneral.addWidget(label, 1, 5)
        label = QtWidgets.QLabel(elemento.symbol)
        font.setPointSize(12)
        label.setFont(font)
        label.setAlignment(QtCore.Qt.AlignCenter | QtCore.Qt.AlignBottom)
        layoutGeneral.addWidget(label, 2, 5)
        layoutGeneral.addItem(
            QtWidgets.QSpacerItem(20, 20, QtWidgets.QSizePolicy.Expanding,
                                  QtWidgets.QSizePolicy.Expanding), 9, 3)
        tabWidget.addTab(
            tabGeneral,
            QtWidgets.QApplication.translate("pychemqt", "General"))

        tabFisica = QtWidgets.QWidget()
        lytphy = QtWidgets.QGridLayout(tabFisica)
        lytphy.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Fase:")), 1, 1)
        lytphy.addWidget(QtWidgets.QLabel(elemento.phase + " a 0ºC"), 1, 2, 1,
                         1)
        if elemento.density_Solid:
            lytphy.addWidget(
                QtWidgets.QLabel(
                    QtWidgets.QApplication.translate("pychemqt",
                                                     "Solid Density:")), 2, 1)
            lytphy.addWidget(
                self.drawData(unidades.Density,
                              elemento.density_Solid,
                              "gcc",
                              txt=" @ 20ºC"), 2, 2)
        if elemento.density_Liq:
            lytphy.addWidget(
                QtWidgets.QLabel(
                    QtWidgets.QApplication.translate("pychemqt",
                                                     "Liquid Density:")), 3, 1)
            lytphy.addWidget(
                self.drawData(unidades.Density,
                              elemento.density_Liq,
                              "gcc",
                              txt=" " + QtWidgets.QApplication.translate(
                                  "pychemqt", "at melting point")), 3, 2)
        if elemento.density_Gas:
            lytphy.addWidget(
                QtWidgets.QLabel(
                    QtWidgets.QApplication.translate("pychemqt",
                                                     "Gas Density:")), 4, 1)
            lytphy.addWidget(
                self.drawData(unidades.Density,
                              elemento.density_Gas,
                              "gl",
                              txt=" @ 0ºC"), 4, 2)
        lytphy.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Appearance:")),
            5, 1)
        label = QtWidgets.QLabel(elemento.appearance)
        label.setWordWrap(True)
        lytphy.addWidget(label, 5, 2)
        lytphy.addItem(
            QtWidgets.QSpacerItem(20, 20, QtWidgets.QSizePolicy.Fixed,
                                  QtWidgets.QSizePolicy.Fixed), 6, 1, 1, 3)
        label = QtWidgets.QLabel(
            QtWidgets.QApplication.translate("pychemqt", "Thermal properties"))
        label.setFont(font)
        lytphy.addWidget(label, 7, 1)
        lytphy.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt",
                                                 "Melting point:")), 8, 1)
        self.punto_fusion = self.drawData(unidades.Temperature, elemento.Tf)
        lytphy.addWidget(self.punto_fusion, 8, 2)
        lytphy.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt",
                                                 "Boiling point:")), 9, 1)
        self.punto_ebullicion = self.drawData(unidades.Temperature,
                                              elemento.Tb)
        lytphy.addWidget(self.punto_ebullicion, 9, 2)
        lytphy.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt",
                                                 "Heat of fusion:")), 10, 1)
        self.calor_fusion = self.drawData(unidades.MolarEnthalpy,
                                          elemento.Heat_f, "kJkmol")
        lytphy.addWidget(self.calor_fusion, 10, 2)
        lytphy.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt",
                                                 "Heat of vaporization:")), 11,
            1)
        self.calor_vaporizacion = self.drawData(unidades.MolarEnthalpy,
                                                elemento.Heat_b, "kJkmol")
        lytphy.addWidget(self.calor_vaporizacion, 11, 2)
        lytphy.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt",
                                                 "Specific heat capacity:")),
            12, 1)
        self.capacidad_calorifica = self.drawData(unidades.SpecificHeat,
                                                  elemento.Cp, "JgK")
        lytphy.addWidget(self.capacidad_calorifica, 12, 2)
        lytphy.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt",
                                                 "Thermal conductivity:")), 13,
            1)
        self.conductividad_termica = self.drawData(
            unidades.ThermalConductivity, elemento.k, txt=" @ 300K")
        lytphy.addWidget(self.conductividad_termica, 13, 2)
        lytphy.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt",
                                                 "Debye Temperature:")), 14, 1)
        self.temperatura_debye = self.drawData(unidades.Temperature,
                                               elemento.T_debye)
        lytphy.addWidget(self.temperatura_debye, 14, 2)
        lytphy.addItem(
            QtWidgets.QSpacerItem(20, 20, QtWidgets.QSizePolicy.Expanding,
                                  QtWidgets.QSizePolicy.Expanding), 15, 1, 1,
            3)
        tabWidget.addTab(
            tabFisica,
            QtWidgets.QApplication.translate("pychemqt",
                                             "Physical properties"))

        tabAtom = QtWidgets.QWidget()
        lyt_A = QtWidgets.QGridLayout(tabAtom)
        lyt_A.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Atomic mass:")),
            1, 1)
        if elemento.atomic_mass:
            self.masa_atomica = QtWidgets.QLabel(
                str(elemento.atomic_mass) + " g/mol")
        else:
            self.masa_atomica = QtWidgets.QLabel(elemento.atomic_mass)
        lyt_A.addWidget(self.masa_atomica, 1, 2)
        lyt_A.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt",
                                                 "Atomic Volume:")), 2, 1)
        self.volumen_atomico = self.drawData(unidades.MolarVolume,
                                             elemento.atomic_volume)
        lyt_A.addWidget(self.volumen_atomico, 2, 2)
        lyt_A.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt",
                                                 "Atomic radius:")), 3, 1)
        if elemento.atomic_radius:
            self.radio_atomico = QtWidgets.QLabel(
                str(elemento.atomic_radius) + " pm")
        else:
            self.radio_atomico = QtWidgets.QLabel(str(elemento.atomic_radius))
        lyt_A.addWidget(self.radio_atomico, 3, 2)
        lyt_A.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt",
                                                 "Covalent radius:")), 4, 1)
        if elemento.covalent_radius:
            self.radio_covalente = QtWidgets.QLabel(
                str(elemento.covalent_radius) + " pm")
        else:
            self.radio_covalente = QtWidgets.QLabel(
                str(elemento.covalent_radius))
        lyt_A.addWidget(self.radio_covalente, 4, 2)
        lyt_A.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt",
                                                 "Van der Waals radius:")), 5,
            1)
        if elemento.vanderWaals_radius:
            self.radio_waals = QtWidgets.QLabel(
                str(elemento.vanderWaals_radius) + " pm")
        else:
            self.radio_waals = QtWidgets.QLabel(
                str(elemento.vanderWaals_radius))
        lyt_A.addWidget(self.radio_waals, 5, 2)
        lyt_A.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Ionic radii:")),
            6, 1)
        if elemento.ionic_radii:
            self.radio_ionico = QtWidgets.QLabel(
                str(elemento.ionic_radii) + " pm")
        else:
            self.radio_ionico = QtWidgets.QLabel(str(elemento.ionic_radii))
        lyt_A.addWidget(self.radio_ionico, 6, 2)
        lyt_A.addItem(
            QtWidgets.QSpacerItem(20, 20, QtWidgets.QSizePolicy.Fixed,
                                  QtWidgets.QSizePolicy.Fixed), 7, 1, 1, 3)
        label = QtWidgets.QLabel(
            QtWidgets.QApplication.translate("pychemqt",
                                             "Electronic properties"))
        label.setFont(font)
        lyt_A.addWidget(label, 8, 1)
        lyt_A.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt",
                                                 "Electronic configuration:")),
            9, 1)
        lyt_A.addWidget(QtWidgets.QLabel(elemento.electron_configuration), 9,
                        2)
        lyt_A.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt",
                                                 "Oxidation states:")), 10, 1)
        lyt_A.addWidget(QtWidgets.QLabel(elemento.oxidation), 10, 2)
        lyt_A.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt",
                                                 "Electronegativity:")), 11, 1)
        lyt_A.addWidget(QtWidgets.QLabel(str(elemento.electronegativity)), 11,
                        2)
        lyt_A.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt",
                                                 "Electron affinity:")), 12, 1)
        self.afinidad_electronica = self.drawData(unidades.MolarEnthalpy,
                                                  elemento.electron_affinity,
                                                  "kJkmol")
        lyt_A.addWidget(self.afinidad_electronica, 12, 2)
        lyt_A.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt",
                                                 "1st ionization energy:")),
            13, 1)
        self.energia_ionizacion = self.drawData(unidades.MolarEnthalpy,
                                                elemento.first_ionization,
                                                "kJkmol")
        lyt_A.addWidget(self.energia_ionizacion, 13, 2)
        lyt_A.addItem(
            QtWidgets.QSpacerItem(20, 20, QtWidgets.QSizePolicy.Expanding,
                                  QtWidgets.QSizePolicy.Expanding), 14, 1, 1,
            3)
        tabWidget.addTab(
            tabAtom,
            QtWidgets.QApplication.translate("pychemqt", "Atomic properties"))

        tabCristal = QtWidgets.QWidget()
        lyt_C = QtWidgets.QGridLayout(tabCristal)
        lyt_C.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Lattice type:")),
            1, 1)
        lyt_C.addWidget(QtWidgets.QLabel(elemento.lattice_type), 1, 2)
        lyt_C.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Space group:")),
            2, 1)
        lyt_C.addWidget(QtWidgets.QLabel(elemento.space_group), 2, 2)
        lyt_C.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt",
                                                 "Lattice edge lengths:")), 3,
            1)
        self.lados = QtWidgets.QLabel()
        if elemento.lattice_edges:
            self.lados.setText(
                "%spm, %spm, %spm" %
                (elemento.lattice_edges[0], elemento.lattice_edges[1],
                 elemento.lattice_edges[2]))
        else:
            self.lados.setText(elemento.lattice_edges)
        lyt_C.addWidget(self.lados, 3, 2)
        lyt_C.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt",
                                                 "Lattice angles:")), 4, 1)
        self.angulos = QtWidgets.QLabel()
        if elemento.lattice_angles:
            self.angulos.setText(
                "%sº, %sº, %sº" %
                (elemento.lattice_angles[0], elemento.lattice_angles[1],
                 elemento.lattice_angles[2]))
        else:
            self.angulos.setText(elemento.lattice_angles)
        lyt_C.addWidget(self.angulos, 4, 2)
        lyt_C.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt",
                                                 "Lattice unit volume:")), 5,
            1)
        self.volumen_celda = QtWidgets.QLabel()
        if elemento.lattice_angles:
            self.volumen_celda.setText("%0.5f mm<sup>3</sup>" %
                                       elemento.lattice_volume)
        else:
            self.volumen_celda.setText(elemento.lattice_volume)
        lyt_C.addWidget(self.volumen_celda, 5, 2)
        lyt_C.addItem(
            QtWidgets.QSpacerItem(20, 20, QtWidgets.QSizePolicy.Expanding,
                                  QtWidgets.QSizePolicy.Expanding), 6, 1, 1, 3)

        label = QtWidgets.QLabel(
            QtWidgets.QApplication.translate("pychemqt", "Isotopes"))
        label.setFont(font)
        lyt_C.addWidget(label, 8, 1)
        title = [
            QtWidgets.QApplication.translate("pychemqt", "Mass Number"),
            QtWidgets.QApplication.translate("pychemqt", "Mass"),
            QtWidgets.QApplication.translate("pychemqt", "Abundance")
        ]
        self.isotopes = Tabla(3,
                              horizontalHeader=title,
                              readOnly=True,
                              stretch=True,
                              verticalHeader=False)
        self.isotopes.setSelectionBehavior(
            QtWidgets.QAbstractItemView.SelectRows)
        self.isotopes.setColumn(0, [iso[0] for iso in elemento.isotopes],
                                decimales=0)
        self.isotopes.setColumn(1, [iso[1] for iso in elemento.isotopes],
                                format=1,
                                decimales=10)
        self.isotopes.setColumn(2, [iso[2] for iso in elemento.isotopes],
                                format=1,
                                decimales=10)
        lyt_C.addWidget(self.isotopes, 9, 1, 1, 2)
        lyt_C.addItem(
            QtWidgets.QSpacerItem(20, 20, QtWidgets.QSizePolicy.Expanding,
                                  QtWidgets.QSizePolicy.Expanding), 10, 1, 1,
            3)

        tabWidget.addTab(
            tabCristal,
            QtWidgets.QApplication.translate("pychemqt", "Crystallographic"))
Beispiel #15
0
class UI_reacciones(QtWidgets.QDialog):
    reaction=reaction.Reaction()
    def __init__(self, reaccion=None, parent=None):
        super(UI_reacciones, self).__init__(parent)
        self.evaluate=Evaluate()
        self.evaluate.finished.connect(self.rellenar)
        self.indices, self.nombres, M=getComponents()
        gridLayout = QtWidgets.QGridLayout(self)

        lyt=QtWidgets.QHBoxLayout()
        lyt.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate("pychemqt", "Key component")))
        self.key=QtWidgets.QComboBox()
        for i, nombre in enumerate(self.nombres):
            self.key.addItem("%i - %s" %(i+1, nombre))
        self.key.currentIndexChanged.connect(partial(self.changeParams, "key"))
        lyt.addWidget(self.key)
        lyt.addItem(QtWidgets.QSpacerItem(10,10,QtWidgets.QSizePolicy.Expanding,QtWidgets.QSizePolicy.Fixed))
        gridLayout.addLayout(lyt,1,1,1,5)

        lyt=QtWidgets.QHBoxLayout()
        lyt.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate("pychemqt", "Phase")))
        self.fase=QtWidgets.QComboBox()
        for txt in reaction.Reaction.TEXT_PHASE:
            self.fase.addItem(txt)
        self.fase.currentIndexChanged.connect(partial(self.changeParams, "fase"))
        lyt.addWidget(self.fase)
        self.Formula=QtWidgets.QLabel()
        self.Formula.setAlignment(QtCore.Qt.AlignCenter)
        self.Formula.setSizePolicy(QtWidgets.QSizePolicy.Expanding,QtWidgets.QSizePolicy.Fixed)
        lyt.addWidget(self.Formula)
        gridLayout.addLayout(lyt,2,1,1,5)

        lyt=QtWidgets.QVBoxLayout()
        title=self.nombres[:]
        title.append("")
        self.Estequiometria=Tabla(1, verticalHeaderLabels=title, horizontalHeader=[QtWidgets.QApplication.translate("pychemqt", "Coefficients")], filas=len(self.indices))
        self.Estequiometria.setFixedHeight(22*len(self.indices)+22+4+22)
        lyt.addWidget(self.Estequiometria)
        self.Estequiometria.addRow()
        brush=QtGui.QBrush(QtGui.QColor("#eaeaea"))
        self.Estequiometria.item(len(self.indices), 0).setBackground(brush)
        self.Estequiometria.item(len(self.indices), 0).setFlags(QtCore.Qt.NoItemFlags)
        self.Estequiometria.cellChanged.connect(self.reaccionCambiada)
        lyt.addItem(QtWidgets.QSpacerItem(10,10,QtWidgets.QSizePolicy.Fixed,QtWidgets.QSizePolicy.Expanding))
        gridLayout.addLayout(lyt,3,1,1,2)

        lyt=QtWidgets.QGridLayout()
        lyt.addItem(QtWidgets.QSpacerItem(10,10,QtWidgets.QSizePolicy.Fixed,QtWidgets.QSizePolicy.Fixed),1,1)
        self.formula=QtWidgets.QCheckBox(QtWidgets.QApplication.translate("pychemqt", "Use name in formula"))
        self.formula.toggled.connect(partial(self.changeParams, "formula"))
        lyt.addWidget(self.formula,1,2,1,2)
        self.customHr=QtWidgets.QCheckBox("ΔHr "+QtWidgets.QApplication.translate("pychemqt", "user specified"))
        self.customHr.toggled.connect(self.changeHr)
        lyt.addWidget(self.customHr,2,2,1,2)
        lyt.addWidget(QtWidgets.QLabel("ΔHr<sup>o</sup>"),3,2)
        self.Hr=Entrada_con_unidades(unidades.MolarEnthalpy, readOnly=True)
        self.Hr.valueChanged.connect(partial(self.changeParams, "Hr"))
        lyt.addWidget(self.Hr,3,3)
        lyt.addItem(QtWidgets.QSpacerItem(10,10,QtWidgets.QSizePolicy.Fixed,QtWidgets.QSizePolicy.Expanding))
        gridLayout.addLayout(lyt,3,3,1,2)

        gridLayout.addItem(QtWidgets.QSpacerItem(10,10,QtWidgets.QSizePolicy.Fixed,QtWidgets.QSizePolicy.Fixed),4,2)

        lyt=QtWidgets.QHBoxLayout()
        lyt.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate("pychemqt", "Type")))
        self.tipo=QtWidgets.QComboBox()
        for txt in reaction.Reaction.TEXT_TYPE:
            self.tipo.addItem(txt)
        self.tipo.currentIndexChanged.connect(partial(self.changeParams, "tipo"))
        lyt.addWidget(self.tipo)
        lyt.addItem(QtWidgets.QSpacerItem(20,10,QtWidgets.QSizePolicy.Fixed,QtWidgets.QSizePolicy.Fixed))
        lyt.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate("pychemqt", "Concentration")))
        self.base=QtWidgets.QComboBox()
        for txt in reaction.Reaction.TEXT_BASE:
            self.base.addItem(txt)
        self.base.currentIndexChanged.connect(partial(self.changeParams, "base"))
        lyt.addWidget(self.base)
        lyt.addItem(QtWidgets.QSpacerItem(10,10,QtWidgets.QSizePolicy.Expanding,QtWidgets.QSizePolicy.Fixed))
        gridLayout.addLayout(lyt,5,1,1,5)

        self.stacked = QtWidgets.QStackedWidget()
        self.tipo.currentIndexChanged.connect(self.stacked.setCurrentIndex)
        gridLayout.addWidget(self.stacked,6,1,1,5)
        gridLayout.addItem(QtWidgets.QSpacerItem(10,10,QtWidgets.QSizePolicy.Expanding,QtWidgets.QSizePolicy.Expanding),7,1,1,5)

        widget=QtWidgets.QWidget()
        self.stacked.addWidget(widget)
        lyt=QtWidgets.QGridLayout(widget)
        lyt.addWidget(QtWidgets.QLabel("<h3>"+QtWidgets.QApplication.translate("pychemqt", "Estequiometric reaction")+"</h3>"),1,1,1,4)
        self.Conversion=Tabla(1, verticalHeaderModel="C", filas=3)
        self.Conversion.setConnected()
        self.Conversion.setFixedWidth(100)
        lyt.addWidget(self.Conversion,2,1,3,1)
        label=QtWidgets.QLabel()
        label.setPixmap(QtGui.QPixmap(os.environ["pychemqt"]+"/images/equation/reaction_conversion.png"))
        lyt.addWidget(label,2,2,1,3)
        lyt.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate("pychemqt", "Temperature unit")),3,2)
        self.unidadesTemperatura=QtWidgets.QComboBox()
        for i in unidades.Temperature.__text__:
            self.unidadesTemperatura.addItem(i)
        lyt.addWidget(self.unidadesTemperatura,3,3)
        lyt.addItem(QtWidgets.QSpacerItem(10,10,QtWidgets.QSizePolicy.Expanding,QtWidgets.QSizePolicy.Expanding),4,4)
        lyt.addItem(QtWidgets.QSpacerItem(10,10,QtWidgets.QSizePolicy.Expanding,QtWidgets.QSizePolicy.Expanding),5,1,1,5)


        widget=QtWidgets.QWidget()
        self.stacked.addWidget(widget)
        lyt=QtWidgets.QGridLayout(widget)
        self.check_KFijo=QtWidgets.QRadioButton(QtWidgets.QApplication.translate("pychemqt", "Fixed"))
        self.check_KFijo.toggled.connect(self.KeqChanged)
        lyt.addWidget(self.check_KFijo,1,1,1,2)
        lyt.addWidget(QtWidgets.QLabel("K<sub>eq</sub>"),1,3)
        self.Keq=Entrada_con_unidades(float)
        lyt.addWidget(self.Keq,1,4)
        label=QtWidgets.QLabel()
        label.setPixmap(QtGui.QPixmap(os.environ["pychemqt"]+"/images/equation/reaction_equilibrium.png"))
        lyt.addWidget(label,1,5,1,4)

        self.check_KEq=QtWidgets.QRadioButton(QtWidgets.QApplication.translate("pychemqt", "Equation"))
        self.check_KEq.toggled.connect(self.KeqChanged)
        lyt.addWidget(self.check_KEq,2,1,1,2)
        self.check_KTabla=QtWidgets.QRadioButton(QtWidgets.QApplication.translate("pychemqt", "Table"))
        self.check_KTabla.toggled.connect(self.KeqChanged)
        lyt.addWidget(self.check_KTabla,2,5,1,2)
        self.KEq_Dat=Tabla(1, verticalHeaderLabels=["A", "B", "C", "D", "E", "F", "G", "H"], filas=8)
        self.KEq_Dat.setFixedHeight(22*8+4)
        self.KEq_Dat.setFixedWidth(120)
        lyt.addWidget(self.KEq_Dat,3,3,1,2)
        self.KEq_Tab=Tabla(4, horizontalHeader=["T, K", "Keq", "Kcalc", "%Error"], verticalHeader=False, columnReadOnly=[False, False, True, True])
        self.KEq_Tab.setSizePolicy(QtWidgets.QSizePolicy.Expanding,QtWidgets.QSizePolicy.Expanding)
        self.KEq_Tab.setFixedWidth(400)
        self.KEq_Tab.setConnected()
        self.KEq_Tab.rowFinished.connect(self.Regresion)
        self.KEq_Tab.setAlternatingRowColors(False)
        lyt.addWidget(self.KEq_Tab,3,5,1,4)
        lyt.addWidget(QtWidgets.QLabel("r²"),4,5)
        self.r2=Entrada_con_unidades(float, readOnly=True)
        lyt.addWidget(self.r2,4,6)
        self.botonTablaPlot=QtWidgets.QPushButton(QtGui.QIcon(QtGui.QPixmap(os.environ["pychemqt"]+"/images/button/plot.png")), QtWidgets.QApplication.translate("pychemqt", "Plot"))
        self.botonTablaPlot.clicked.connect(self.Plot)
        lyt.addWidget(self.botonTablaPlot,4,7)
        self.botonTablaClear=QtWidgets.QPushButton(QtGui.QIcon(QtGui.QPixmap(os.environ["pychemqt"]+"/images/button/clear.png")), QtWidgets.QApplication.translate("pychemqt", "Clear"))
        self.botonTablaClear.clicked.connect(self.KEq_Tab.clear)
        lyt.addWidget(self.botonTablaClear,4,8)
        label=QtWidgets.QLabel()
        label.setPixmap(QtGui.QPixmap(os.environ["pychemqt"]+"/images/equation/reaction_equilibrium2.png"))
        label.setAlignment(QtCore.Qt.AlignCenter)
        lyt.addWidget(label,5,1,1,8)


        self.checkGibbs=QtWidgets.QRadioButton(QtWidgets.QApplication.translate("pychemqt", "From Gibbs free energy minimization"))
        lyt.addWidget(self.checkGibbs,6,1,1,4)

        self.check_KFijo.setChecked(True)


        widget=QtWidgets.QWidget()
        self.stacked.addWidget(widget)
        lyt=QtWidgets.QGridLayout(widget)

        widget=QtWidgets.QWidget()
        self.stacked.addWidget(widget)
        lyt=QtWidgets.QGridLayout(widget)

        self.status=Status()
        gridLayout.addWidget(self.status, 10,1)
        self.buttonBox = QtWidgets.QDialogButtonBox(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
        self.buttonBox.accepted.connect(self.accept)
        self.buttonBox.rejected.connect(self.reject)
        gridLayout.addWidget(self.buttonBox,10,2,1,4)

        if reaccion:
            self.setReaction(reaccion)

    def changeParams(self, parametro, valor):
        self.calculo(**{parametro: valor})

    def calculo(self, **kwargs):
        self.status.setState(4)
        self.evaluate.start(self.reaction, kwargs)

    def changeHr(self, bool):
        self.Hr.setReadOnly(not bool)
        self.changeParams("customHr", bool)

    def reaccionCambiada(self):
        kwargs={"componentes": self.indices,
                    "coeficientes": self.Estequiometria.getColumn(0)[:-1]}
        self.calculo(**kwargs)

    def setReaction(self, reaction):
        self.reaction=reaction
        self.rellenar()

#        if self.Estequiometria.getValue(0, self.Base.currentIndex()):
#            reaccion=reaction.Reaction(self.indices, self.Estequiometria.getColumn(0), base=self.Base.currentIndex(), estequiometria=[0, 0, 0.5], formulas=self.checkFormula.isChecked(), calor=self.checkCalorEspecificado.isChecked(), Hr=self.Hr.value, tipo=self.tipo.currentIndex(), conversion=self.Conversion.getColumn(0)[-1::-1])
#            self.Balance.setValue(reaccion.error)
#            if reaccion.state:
#                self.Formula.setText(reaccion._txt(self.checkFormula.isChecked()))
#                self.Hr.setValue(reaccion.Hr)
#            else:
#                self.Formula.clear()
#                self.Hr.clear()
#            self.botonAdd.setEnabled(reaccion.state and not self.botonEdit.isChecked())
#            self.reaccion=reaccion

    def rellenar(self):
        self.blockSignals(True)
        for variable in self.reaction.kwargsValue:
            self.__getattribute__(variable).setValue(self.reaction.kwargs[variable])
        for combo in self.reaction.kwargsList:
            self.__getattribute__(combo).setCurrentIndex(self.reaction.kwargs[combo])
        for check in self.reaction.kwargsCheck:
            self.__getattribute__(check).setChecked(self.reaction.kwargs[check])

        self.Estequiometria.setColumn(0, self.reaction.kwargs["coeficientes"])
#        self.Conversion.setColumn(0, self.reaction.estequiometria[-1::-1])
        self.blockSignals(False)

        self.status.setState(self.reaction.status, self.reaction.msg)
        self.Estequiometria.item(len(self.indices), 0).setText(str(self.reaction.error))
        if self.reaction.status:
            self.Formula.setText(self.reaction._txt())
            self.Hr.setValue(self.reaction.Hr)

    def KeqChanged(self):
        self.Keq.setReadOnly(not self.check_KFijo.isChecked())
        self.KEq_Dat.setEnabled(self.check_KEq.isChecked())
        self.KEq_Tab.setEnabled(self.check_KTabla.isChecked())
        self.botonTablaClear.setEnabled(self.check_KTabla.isChecked())
        self.botonTablaPlot.setEnabled(self.check_KTabla.isChecked())

    def Regresion(self):
        t=array(self.KEq_Tab.getColumn(0)[:-1])
        k=array(self.KEq_Tab.getColumn(1)[:-1])
        if len(t)>=4:
            if 4<=len(t)<8:
                inicio=r_[0, 0, 0, 0]
                f=lambda par, T: exp(par[0]+par[1]/T+par[2]*log(T)+par[3]*T)
                resto=lambda par, T, k: k-f(par, T)
            else:
                inicio=r_[0, 0, 0, 0, 0, 0, 0, 0]
                f=lambda par, T: exp(par[0]+par[1]/T+par[2]*log(T)+par[3]*T+par[4]*T**2+par[5]*T**3+par[6]*T**4+par[7]*T**5)
                resto=lambda par, T, k: k-f(par, T)

            ajuste=leastsq(resto,inicio,args=(t, k))
            kcalc=f(ajuste[0], t)
            error=(k-kcalc)/k*100
            self.KEq_Dat.setColumn(0, ajuste[0])
            self.KEq_Tab.setColumn(2, kcalc)
            self.KEq_Tab.setColumn(3, error)

            if ajuste[1] in [1, 2, 3, 4]:
                self.ajuste=ajuste[0]

    def Plot(self):
        if self.ajuste!=None:
            t=array(self.KEq_Tab.getColumn(0)[:-1])
            k=array(self.KEq_Tab.getColumn(1)[:-1])
            if 4<=len(t)<8:
                f=lambda par, T: exp(par[0]+par[1]/T+par[2]*log(T)+par[3]*T)
            else:
                f=lambda par, T: exp(par[0]+par[1]/T+par[2]*log(T)+par[3]*T+par[4]*T**2+par[5]*T**3+par[6]*T**4+par[7]*T**5)

            grafico=plot.Plot()
            grafico.data(t, k, 'ro', t, f(self.ajuste, t))
            grafico.exec_()
Beispiel #16
0
class UI_equipment(UI_equip):
    """Spreadsheet interaction equipment edition dialog"""
    Equipment = Spreadsheet()

    def __init__(self, equipment=None, project=None, parent=None):
        """
        equipment: Initial equipment instance to model
        """
        super().__init__(Spreadsheet, entrada=True, salida=True,
                         calculo=False, parent=parent)
        self.project = project

        # Calculate tab
        layout = QtWidgets.QGridLayout(self.Entrada)
        label = QtWidgets.QApplication.translate(
            "pychemqt", "Spreadsheet path")+":"
        msg = QtWidgets.QApplication.translate(
            "pychemqt", "Select Spreadsheet")
        patrones = []
        if os.environ["ezodf"]:
            patrones.append(QtWidgets.QApplication.translate(
                "pychemqt", "Libreoffice spreadsheet files")+" (*.ods)")
        if os.environ["xlwt"]:
            patrones.append(QtWidgets.QApplication.translate(
                "pychemqt", "Microsoft Excel 97/2000/XP/2003 XML")+" (*.xls)")
        if os.environ["openpyxl"]:
            patrones.append(QtWidgets.QApplication.translate(
                "pychemqt", "Microsoft Excel 2007/2010 XML")+" (*.xlsx)")
        patron = ";;".join(patrones)
        self.filename = PathConfig(label, msg=msg, patron=patron)
        self.filename.valueChanged.connect(self.changeSpreadsheet)
        layout.addWidget(self.filename, 1, 1)
        header = [QtWidgets.QApplication.translate("pychemqt", "Entity"),
                  QtWidgets.QApplication.translate("pychemqt", "Variable"),
                  QtWidgets.QApplication.translate("pychemqt", "Unit value"),
                  QtWidgets.QApplication.translate("pychemqt", "Sheet"),
                  QtWidgets.QApplication.translate("pychemqt", "Cell")]
        self.datamap = Tabla(
            5, filas=1, dinamica=True, horizontalHeader=header,
            verticalHeader=False, orientacion=QtCore.Qt.AlignLeft,
            delegate=None, delegateforRow=TableDelegate, parent=self)
        self.datamap.setEnabled(False)
        self.datamap.cellChanged.connect(self.cellChanged)
        self.datamap.rowFinished.connect(self.addRow)
        layout.addWidget(self.datamap, 2, 1)
        layout.addItem(QtWidgets.QSpacerItem(
            10, 10, QtWidgets.QSizePolicy.Expanding,
            QtWidgets.QSizePolicy.Expanding), 10, 1)

        entitys = []
        for stream in list(self.project.streams.keys()):
            entitys.append("s%i" % stream)
        for equip in list(self.project.items.keys()):
            if equip[0] == "e":
                entitys.append(equip)
        self.datamap.itemDelegateForRow(0).setItemsByIndex(0, entitys)
        self.entitys = entitys
        if equipment:
            self.setEquipment(equipment)

    def changeSpreadsheet(self, path):
        self.datamap.setEnabled(bool(path))
        self.changeParams("filename", str(path))
        self.datamap.blockSignals(True)
        self.datamap.clear()
        self.datamap.blockSignals(False)
        spreadsheet = ezodf.opendoc(path)
        sheets = [name for name in spreadsheet.sheets.names()]
        self.datamap.itemDelegateForRow(0).setItemsByIndex(3, sheets)

    def rellenarInput(self):
        self.blockSignals(True)
        self.datamap.itemDelegateForRow(
            self.datamap.rowCount()-1).setItemsByIndex(0, self.entitys)
        if self.Equipment.status:
            self.datamap.setEnabled(True)
            self.filename.setText(self.Equipment.kwargs["filename"])
            self.datamap.itemDelegateForRow(0).setItemsByIndex(
                3, self.Equipment.sheets)

        self.datamap.blockSignals(True)
        self.datamap.clear()
        if self.Equipment.kwargs["datamap"]:
            for i, data in enumerate(self.Equipment.kwargs["datamap"]):
                self.datamap.addRow()
                self.datamap.itemDelegateForRow(i).setItemsByIndex(
                    0, self.entitys)
                self.datamap.itemDelegateForRow(i).setItemsByIndex(
                    3, self.Equipment.sheets)
                self.datamap.setItem(
                    i, 0, QtWidgets.QTableWidgetItem(data["entity"]))
                self.datamap.setItem(
                    i, 1, QtWidgets.QTableWidgetItem(data["property"]))
                self.datamap.setItem(
                    i, 2, QtWidgets.QTableWidgetItem(data["unit"]))
                self.datamap.setItem(
                    i, 3, QtWidgets.QTableWidgetItem(data["sheet"]))
                self.datamap.setItem(
                    i, 4, QtWidgets.QTableWidgetItem(data["cell"]))
            self.datamap.itemDelegateForRow(
                self.datamap.rowCount()-1).setItemsByIndex(0, self.entitys)
            self.datamap.itemDelegateForRow(
                self.datamap.rowCount()-1).setItemsByIndex(
                    3, self.Equipment.sheets)
        self.datamap.blockSignals(False)
        self.blockSignals(False)

    def rellenar(self):
        self.rellenarInput()
        self.status.setState(self.Equipment.status, self.Equipment.msg)

    def cellChanged(self, i, j):
        obj = self.project.getObject(str(self.datamap.item(i, 0).text()))
        properties = [prop[0] for prop in obj.propertiesNames()]
        if j == 0:  # Entity cambiado, cambiar variables disponibles
            self.datamap.itemDelegateForRow(i).setItemsByIndex(1, properties)
            editor = QtWidgets.QComboBox()
            editor.addItems(self.datamap.itemDelegateForRow(i).items[1])
            self.datamap.setColumnWidth(1, editor.sizeHint().width())
        elif j == 1:   # Variable cambiada, cambiar unidades disponibles
            value = self.datamap.item(i, 1).text()
            ind = properties.index(value)
            if obj.propertiesUnit()[ind] == str:
                self.datamap.itemDelegateForRow(i).setItemsByIndex(2, [" "])
                self.datamap.item(i, 2).setText(" ")
            else:
                self.datamap.itemDelegateForRow(i).setItemsByIndex(
                    2, obj.propertiesNames()[ind][2].__text__)
        elif j == 3:
            self.datamap.item(i, 4).setText("")

    def addRow(self, fila):
        datamap = self.Equipment.kwargs["datamap"][:]
        data = {}
        data["entity"] = str(fila[0])
        data["property"] = str(fila[1])
        data["unit"] = str(fila[2])
        data["sheet"] = str(fila[3])
        data["cell"] = str(fila[4])
        datamap.append(data)
        self.changeParams("datamap", datamap)
Beispiel #17
0
class InputTableWidget(QtWidgets.QWidget):
    """Table data input dialog"""
    def __init__(self, columnas, data=None, t=[], property=[],
                 horizontalHeader=[], title="", DIPPR=False, hasTc=0,
                 Tc=None, eq=1, unit=[], parent=None):
        """
        data: mrray with original data
        t: values for x column, generally temperature
        property: values for 2...n columns
        horizontalHeader: List with column title
        DIPPR: boolean to show DIPPR widget
        hasTc: boolean to show critical temperature (some DIPPR eq need it)
        Tc: value for critical temperature
        eq: Value for DIPPR equation
        unit: List of unidades classes for column definition
        """
        super(InputTableWidget, self).__init__(parent)
        self.columnas = columnas
        self.title = title
        self.unit = unit
        gridLayout = QtWidgets.QGridLayout(self)
        gridLayout.setContentsMargins(0, 0, 0, 0)
        openButton = QtWidgets.QPushButton(QtGui.QIcon(QtGui.QPixmap(
            os.environ["pychemqt"]+"/images/button/fileOpen.png")), "")
        openButton.setToolTip(QtWidgets.QApplication.translate(
            "pychemqt", "Load data from a file"))
        openButton.clicked.connect(self.open)
        gridLayout.addWidget(openButton, 1, 1)
        saveButton = QtWidgets.QPushButton(QtGui.QIcon(QtGui.QPixmap(
            os.environ["pychemqt"]+"/images/button/fileSave.png")), "")
        saveButton.setToolTip(QtWidgets.QApplication.translate(
            "pychemqt", "Save data to a file"))
        saveButton.clicked.connect(self.save)
        gridLayout.addWidget(saveButton, 1, 2)
        clearButton = QtWidgets.QPushButton(QtGui.QIcon(QtGui.QPixmap(
            os.environ["pychemqt"]+"/images/button/clear.png")), "")
        clearButton.setToolTip(QtWidgets.QApplication.translate(
            "pychemqt", "Clear data"))
        clearButton.clicked.connect(self.delete)
        gridLayout.addWidget(clearButton, 1, 3)
        gridLayout.addItem(QtWidgets.QSpacerItem(
            0, 0, QtWidgets.QSizePolicy.Expanding,
            QtWidgets.QSizePolicy.Fixed), 1, 4)

        self.tabla = Tabla(self.columnas, horizontalHeader=horizontalHeader,
                           verticalHeader=False, stretch=False)
        self.tabla.setConnected()
        if unit:
            hHeader = []
            for unit, title in zip(self.unit, horizontalHeader):
                hHeader.append("%s, %s" % (title, unit.text()))
            self.tabla.setHorizontalHeaderLabels(hHeader)
            self.tabla.horizontalHeader().sectionClicked.connect(self.editUnit)

        if data:
            self.tabla.setData(data)
            self.tabla.addRow()
        elif t and property:
            self.tabla.setColumn(0, t)
            self.tabla.setColumn(1, property)
        gridLayout.addWidget(self.tabla, 2, 1, 1, 4)

        if DIPPR:
            self.eqDIPPR = eqDIPPR(eq)
            gridLayout.addWidget(self.eqDIPPR, 3, 1, 1, 4)
            self.eqDIPPR.eqDIPPR.valueChanged.connect(self.showTc)

            self.labelTc = QtWidgets.QLabel("Tc: ", self)
            gridLayout.addWidget(self.labelTc, 4, 1)
            self.tc = Entrada_con_unidades(Temperature, value=Tc)
            gridLayout.addWidget(self.tc, 4, 2, 1, 3)
            self.showTc(1)

    def showTc(self, value):
        """Show/hide Tc widget"""
        self.labelTc.setVisible(value in (7, 9))
        self.tc.setVisible(value in (7, 9))

    def open(self):
        """Load data from a test file"""
        fname, ext = QtWidgets.QFileDialog.getOpenFileName(
            self,
            QtWidgets.QApplication.translate("pychemqt", "Open text file"),
            "./")
        if fname:
            try:
                # Numpy raise error if use the fname directly and find a
                # non-latin1 character, inclusive in comment lines
                with open(fname, "rb") as file:
                    data = loadtxt(file)
                self.delete()
                self.tabla.setData(data)
            except ValueError as er:
                # Raise a error msg if the file can load by loadtxt, the user
                # can select any type of file and the input error is possible
                title = QtWidgets.QApplication.translate(
                    "pychemqt", "Failed to load file")
                msg = fname + "\n" + er.args[0]
                QtWidgets.QMessageBox.critical(self, title, msg)

    def save(self):
        """Save currend data of table to a file"""
        fname, ext = QtWidgets.QFileDialog.getSaveFileName(
            self,
            QtWidgets.QApplication.translate("pychemqt", "Save data to file"),
            "./")
        if fname:
            with open(fname, 'w') as file:
                file.write("#"+self.title+"\n")
                file.write("#")
                for i in range(self.tabla.columnCount()):
                    item = self.tabla.horizontalHeaderItem(i)
                    file.write(item.text()+"\t")
                file.write("\n")
                data = self.data
                for fila in range(len(data)):
                    for columna in range(self.tabla.columnCount()):
                        file.write(str(data[fila][columna])+"\t")
                    file.write("\n")

    def delete(self):
        """Clear table"""
        self.tabla.setRowCount(0)
        self.tabla.clearContents()
        self.tabla.addRow()

    @property
    def data(self):
        return self.tabla.getData()

    def column(self, column, magnitud=None, unit="conf"):
        """
        column: column to get
        magnitud: magnitud to get the values
        unit: unit of the values in table"""
        data = self.tabla.getColumn(column)
        if self.unit:
            magnitud = self.unit[column]
            tx = self.tabla.horizontalHeaderItem(column).text().split(", ")[-1]
            unit = magnitud.__units__[magnitud.__text__.index(tx)]

        if magnitud is not None:
            data = [magnitud(x, unit) for x in data]
        return data

    def editUnit(self, col):
        """Show dialog to config input unit"""
        unit = self.unit[col]
        widget = QtWidgets.QComboBox(self.tabla)
        for txt in unit.__text__:
            widget.addItem(txt)
        txt = self.tabla.horizontalHeaderItem(col).text().split(", ")[-1]
        widget.setCurrentText(txt)

        # Define Unit combobox geometry
        size = self.tabla.horizontalHeader().sectionSize(col)
        pos = self.tabla.horizontalHeader().sectionPosition(col)
        h = self.tabla.horizontalHeader().height()
        geometry = QtCore.QRect(pos, 0, size, h)
        widget.setGeometry(geometry)
        widget.currentIndexChanged["int"].connect(
            partial(self.updateHeader, col))
        widget.show()
        widget.showPopup()

    def updateHeader(self, col, index):
        """Change the text in header"""
        widget = self.sender()
        txt = self.tabla.horizontalHeaderItem(col).text()
        newtxt = "%s, %s" % (txt.split(",")[0], widget.currentText())
        self.tabla.setHorizontalHeaderItem(
                col, QtWidgets.QTableWidgetItem(newtxt))
        widget.close()
Beispiel #18
0
    def __init__(self, ids, EoSIndex=0, parent=None):
        """Constructor"""
        super(Ui_BIP, self).__init__(parent)
        self.setWindowTitle(
            QtWidgets.QApplication.translate(
                "pychemqt", "BIP (Binary interaction parameters)"))

        lyt = QtWidgets.QGridLayout(self)
        lyt.addWidget(QtWidgets.QLabel("EoS"), 1, 1)
        self.eleccion = QtWidgets.QComboBox()
        lyt.addWidget(self.eleccion, 1, 2)
        lyt.addItem(
            QtWidgets.QSpacerItem(0, 0, QtWidgets.QSizePolicy.Expanding,
                                  QtWidgets.QSizePolicy.Fixed), 1, 3)
        self.stacked = QtWidgets.QStackedWidget()
        lyt.addWidget(self.stacked, 2, 1, 1, 3)

        # Get component names to show in table header
        names = []
        for cmp in ids:
            databank.execute("SELECT id, name FROM compuestos WHERE id==%i" %
                             cmp)
            names.append("%4i - %s" % databank.fetchone())

        args = (len(ids), len(ids))
        kw = {
            "stretch": False,
            "readOnly": True,
            "horizontalHeader": names,
            "verticalHeaderLabels": names
        }

        title = {"WILSON": "Aij", "UNIQUAC": "ΔUij", "NRTL": "Gij"}

        # Iterate over the EoS available
        for EoS in EoSBIP:
            self.eleccion.addItem(EoS)
            k = Kij(ids, EoS)

            widget = QtWidgets.QWidget()
            lyt2 = QtWidgets.QVBoxLayout(widget)
            lyt2.addWidget(QtWidgets.QLabel(title.get(EoS, "Kij")))
            table1 = Tabla(*args, **kw)
            lyt2.addWidget(table1)

            # Special case for NRTL with two interaction parameters matrix
            if EoS == "NRTL":
                lyt2.addWidget(QtWidgets.QLabel("α"))
                table2 = Tabla(*args, **kw)
                lyt2.addWidget(table2)
                kij, aij = k
                table1.setData(kij)
                table2.setData(aij)
                table1.resizeColumnsToContents()
                table2.resizeColumnsToContents()

            else:
                table1.setData(k)
                table1.resizeColumnsToContents()

            self.stacked.addWidget(widget)

        self.eleccion.currentIndexChanged.connect(self.stacked.setCurrentIndex)
        button = QtWidgets.QDialogButtonBox(QtWidgets.QDialogButtonBox.Cancel
                                            | QtWidgets.QDialogButtonBox.Ok)
        button.accepted.connect(self.accept)
        button.rejected.connect(self.reject)
        lyt.addWidget(button, 3, 1, 1, 3)

        self.eleccion.setCurrentIndex(EoSIndex)
Beispiel #19
0
    def __init__(self, equipment=None, project=None, parent=None):
        """
        equipment: Initial equipment instance to model
        """
        super(UI_equipment, self).__init__(Spreadsheet,
                                           entrada=True,
                                           salida=True,
                                           calculo=False,
                                           parent=parent)
        self.project = project

        # Calculate tab
        layout = QtGui.QGridLayout(self.entrada)
        label = QtGui.QApplication.translate("pychemqt",
                                             "Spreadsheet path") + ":"
        msg = QtGui.QApplication.translate("pychemqt", "Select Spreadsheet")
        patrones = QtCore.QStringList()
        if os.environ["ezodf"]:
            patrones.append(
                QtGui.QApplication.translate(
                    "pychemqt", "Libreoffice spreadsheet files") + " (*.ods)")


#        if os.environ["xlwt"]:
#            patrones.append(QtGui.QApplication.translate(
#                "pychemqt", "Microsoft Excel 97/2000/XP/2003 XMLL")+ " (*.xls)")
        if os.environ["openpyxl"]:
            patrones.append(
                QtGui.QApplication.translate(
                    "pychemqt", "Microsoft Excel 2007/2010 XML") + " (*.xlsx)")
        patron = patrones.join(";;")
        self.filename = PathConfig(label, msg=msg, patron=patron)
        self.filename.valueChanged.connect(self.changeSpreadsheet)
        layout.addWidget(self.filename, 1, 1)
        header = [
            QtGui.QApplication.translate("pychemqt", "Entity"),
            QtGui.QApplication.translate("pychemqt", "Variable"),
            QtGui.QApplication.translate("pychemqt", "Unit value"),
            QtGui.QApplication.translate("pychemqt", "Sheet"),
            QtGui.QApplication.translate("pychemqt", "Cell")
        ]
        self.datamap = Tabla(5,
                             filas=1,
                             dinamica=True,
                             horizontalHeader=header,
                             verticalHeader=False,
                             orientacion=QtCore.Qt.AlignLeft,
                             num=False,
                             delegateforRow=TableDelegate,
                             parent=self)
        self.datamap.setEnabled(False)
        self.datamap.cellChanged.connect(self.cellChanged)
        self.datamap.rowFinished.connect(self.addRow)
        layout.addWidget(self.datamap, 2, 1)
        layout.addItem(
            QtGui.QSpacerItem(10, 10, QtGui.QSizePolicy.Expanding,
                              QtGui.QSizePolicy.Expanding), 10, 1)

        entitys = []
        for stream in self.project.streams.keys():
            entitys.append("s%i" % stream)
        for equip in self.project.items.keys():
            if equip[0] == "e":
                entitys.append(equip)
        self.datamap.itemDelegateForRow(0).setItemsByIndex(0, entitys)
        self.entitys = entitys
        if equipment:
            self.setEquipment(equipment)
Beispiel #20
0
class UI_equipment(UI_equip):
    """Spreadsheet interaction equipment edition dialog"""
    Equipment = Spreadsheet()

    def __init__(self, equipment=None, project=None, parent=None):
        """
        equipment: Initial equipment instance to model
        """
        super(UI_equipment, self).__init__(Spreadsheet,
                                           entrada=True,
                                           salida=True,
                                           calculo=False,
                                           parent=parent)
        self.project = project

        # Calculate tab
        layout = QtGui.QGridLayout(self.entrada)
        label = QtGui.QApplication.translate("pychemqt",
                                             "Spreadsheet path") + ":"
        msg = QtGui.QApplication.translate("pychemqt", "Select Spreadsheet")
        patrones = QtCore.QStringList()
        if os.environ["ezodf"]:
            patrones.append(
                QtGui.QApplication.translate(
                    "pychemqt", "Libreoffice spreadsheet files") + " (*.ods)")


#        if os.environ["xlwt"]:
#            patrones.append(QtGui.QApplication.translate(
#                "pychemqt", "Microsoft Excel 97/2000/XP/2003 XMLL")+ " (*.xls)")
        if os.environ["openpyxl"]:
            patrones.append(
                QtGui.QApplication.translate(
                    "pychemqt", "Microsoft Excel 2007/2010 XML") + " (*.xlsx)")
        patron = patrones.join(";;")
        self.filename = PathConfig(label, msg=msg, patron=patron)
        self.filename.valueChanged.connect(self.changeSpreadsheet)
        layout.addWidget(self.filename, 1, 1)
        header = [
            QtGui.QApplication.translate("pychemqt", "Entity"),
            QtGui.QApplication.translate("pychemqt", "Variable"),
            QtGui.QApplication.translate("pychemqt", "Unit value"),
            QtGui.QApplication.translate("pychemqt", "Sheet"),
            QtGui.QApplication.translate("pychemqt", "Cell")
        ]
        self.datamap = Tabla(5,
                             filas=1,
                             dinamica=True,
                             horizontalHeader=header,
                             verticalHeader=False,
                             orientacion=QtCore.Qt.AlignLeft,
                             num=False,
                             delegateforRow=TableDelegate,
                             parent=self)
        self.datamap.setEnabled(False)
        self.datamap.cellChanged.connect(self.cellChanged)
        self.datamap.rowFinished.connect(self.addRow)
        layout.addWidget(self.datamap, 2, 1)
        layout.addItem(
            QtGui.QSpacerItem(10, 10, QtGui.QSizePolicy.Expanding,
                              QtGui.QSizePolicy.Expanding), 10, 1)

        entitys = []
        for stream in self.project.streams.keys():
            entitys.append("s%i" % stream)
        for equip in self.project.items.keys():
            if equip[0] == "e":
                entitys.append(equip)
        self.datamap.itemDelegateForRow(0).setItemsByIndex(0, entitys)
        self.entitys = entitys
        if equipment:
            self.setEquipment(equipment)

    def changeSpreadsheet(self, path):
        self.datamap.setEnabled(bool(path))
        self.changeParams("filename", str(path))
        self.datamap.blockSignals(True)
        self.datamap.clear()
        self.datamap.blockSignals(False)
        spreadsheet = ezodf.opendoc(path)
        sheets = [name for name in spreadsheet.sheets.names()]
        self.datamap.itemDelegateForRow(0).setItemsByIndex(3, sheets)

    def rellenarInput(self):
        self.blockSignals(True)
        self.datamap.itemDelegateForRow(self.datamap.rowCount() -
                                        1).setItemsByIndex(0, self.entitys)
        if self.Equipment.status:
            self.datamap.setEnabled(True)
            self.filename.setText(self.Equipment.kwargs["filename"])
            self.datamap.itemDelegateForRow(0).setItemsByIndex(
                3, self.Equipment.sheets)

        self.datamap.blockSignals(True)
        self.datamap.clear()
        if self.Equipment.kwargs["datamap"]:
            for i, data in enumerate(self.Equipment.kwargs["datamap"]):
                self.datamap.addRow()
                self.datamap.itemDelegateForRow(i).setItemsByIndex(
                    0, self.entitys)
                self.datamap.itemDelegateForRow(i).setItemsByIndex(
                    3, self.Equipment.sheets)
                self.datamap.setItem(i, 0,
                                     QtGui.QTableWidgetItem(data["entity"]))
                self.datamap.setItem(i, 1,
                                     QtGui.QTableWidgetItem(data["property"]))
                self.datamap.setItem(i, 2,
                                     QtGui.QTableWidgetItem(data["unit"]))
                self.datamap.setItem(i, 3,
                                     QtGui.QTableWidgetItem(data["sheet"]))
                self.datamap.setItem(i, 4,
                                     QtGui.QTableWidgetItem(data["cell"]))
            self.datamap.itemDelegateForRow(self.datamap.rowCount() -
                                            1).setItemsByIndex(
                                                0, self.entitys)
            self.datamap.itemDelegateForRow(self.datamap.rowCount() -
                                            1).setItemsByIndex(
                                                3, self.Equipment.sheets)
        self.datamap.blockSignals(False)
        self.blockSignals(False)

    def rellenar(self):
        self.rellenarInput()
        self.status.setState(self.Equipment.status, self.Equipment.msg)

    def cellChanged(self, i, j):
        obj = self.project.getObject(str(self.datamap.item(i, 0).text()))
        properties = [prop[0] for prop in obj.propertiesNames()]
        if j == 0:  # Entity cambiado, cambiar variables disponibles
            self.datamap.itemDelegateForRow(i).setItemsByIndex(1, properties)
            editor = QtGui.QComboBox()
            editor.addItems(self.datamap.itemDelegateForRow(i).items[1])
            self.datamap.setColumnWidth(1, editor.sizeHint().width())
        elif j == 1:  # Variable cambiada, cambiar unidades disponibles
            value = self.datamap.item(i, 1).text()
            ind = properties.index(value)
            if obj.propertiesUnit()[ind] == str:
                self.datamap.itemDelegateForRow(i).setItemsByIndex(2, [" "])
                self.datamap.item(i, 2).setText(" ")
            else:
                self.datamap.itemDelegateForRow(i).setItemsByIndex(
                    2,
                    obj.propertiesNames()[ind][2].__text__)
        elif j == 3:
            self.datamap.item(i, 4).setText("")

    def addRow(self, fila):
        datamap = self.Equipment.kwargs["datamap"][:]
        data = {}
        data["entity"] = str(fila[0])
        data["property"] = unicode(fila[1])
        data["unit"] = unicode(fila[2])
        data["sheet"] = unicode(fila[3])
        data["cell"] = str(fila[4])
        datamap.append(data)
        self.changeParams("datamap", datamap)
Beispiel #21
0
    def __init__(self, reaccion=None, parent=None):
        super(UI_reacciones, self).__init__(parent)
        self.evaluate = Evaluate()
        self.evaluate.finished.connect(self.rellenar)
        self.indices, self.nombres, M = getComponents()
        gridLayout = QtWidgets.QGridLayout(self)

        lyt = QtWidgets.QHBoxLayout()
        lyt.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Key component")))
        self.key = QtWidgets.QComboBox()
        for i, nombre in enumerate(self.nombres):
            self.key.addItem("%i - %s" % (i + 1, nombre))
        self.key.currentIndexChanged.connect(partial(self.changeParams, "key"))
        lyt.addWidget(self.key)
        lyt.addItem(
            QtWidgets.QSpacerItem(10, 10, QtWidgets.QSizePolicy.Expanding,
                                  QtWidgets.QSizePolicy.Fixed))
        gridLayout.addLayout(lyt, 1, 1, 1, 5)

        lyt = QtWidgets.QHBoxLayout()
        lyt.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Phase")))
        self.fase = QtWidgets.QComboBox()
        for txt in reaction.Reaction.TEXT_PHASE:
            self.fase.addItem(txt)
        self.fase.currentIndexChanged.connect(
            partial(self.changeParams, "fase"))
        lyt.addWidget(self.fase)
        self.Formula = QtWidgets.QLabel()
        self.Formula.setAlignment(QtCore.Qt.AlignCenter)
        self.Formula.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                   QtWidgets.QSizePolicy.Fixed)
        lyt.addWidget(self.Formula)
        gridLayout.addLayout(lyt, 2, 1, 1, 5)

        lyt = QtWidgets.QVBoxLayout()
        title = self.nombres[:]
        title.append("")
        self.Estequiometria = Tabla(1,
                                    verticalHeaderLabels=title,
                                    horizontalHeader=[
                                        QtWidgets.QApplication.translate(
                                            "pychemqt", "Coefficients")
                                    ],
                                    filas=len(self.indices))
        self.Estequiometria.setFixedHeight(22 * len(self.indices) + 22 + 4 +
                                           22)
        lyt.addWidget(self.Estequiometria)
        self.Estequiometria.addRow()
        brush = QtGui.QBrush(QtGui.QColor("#eaeaea"))
        self.Estequiometria.item(len(self.indices), 0).setBackground(brush)
        self.Estequiometria.item(len(self.indices),
                                 0).setFlags(QtCore.Qt.NoItemFlags)
        self.Estequiometria.cellChanged.connect(self.reaccionCambiada)
        lyt.addItem(
            QtWidgets.QSpacerItem(10, 10, QtWidgets.QSizePolicy.Fixed,
                                  QtWidgets.QSizePolicy.Expanding))
        gridLayout.addLayout(lyt, 3, 1, 1, 2)

        lyt = QtWidgets.QGridLayout()
        lyt.addItem(
            QtWidgets.QSpacerItem(10, 10, QtWidgets.QSizePolicy.Fixed,
                                  QtWidgets.QSizePolicy.Fixed), 1, 1)
        self.formula = QtWidgets.QCheckBox(
            QtWidgets.QApplication.translate("pychemqt",
                                             "Use name in formula"))
        self.formula.toggled.connect(partial(self.changeParams, "formula"))
        lyt.addWidget(self.formula, 1, 2, 1, 2)
        self.customHr = QtWidgets.QCheckBox(
            "ΔHr " +
            QtWidgets.QApplication.translate("pychemqt", "user specified"))
        self.customHr.toggled.connect(self.changeHr)
        lyt.addWidget(self.customHr, 2, 2, 1, 2)
        lyt.addWidget(QtWidgets.QLabel("ΔHr<sup>o</sup>"), 3, 2)
        self.Hr = Entrada_con_unidades(unidades.MolarEnthalpy, readOnly=True)
        self.Hr.valueChanged.connect(partial(self.changeParams, "Hr"))
        lyt.addWidget(self.Hr, 3, 3)
        lyt.addItem(
            QtWidgets.QSpacerItem(10, 10, QtWidgets.QSizePolicy.Fixed,
                                  QtWidgets.QSizePolicy.Expanding))
        gridLayout.addLayout(lyt, 3, 3, 1, 2)

        gridLayout.addItem(
            QtWidgets.QSpacerItem(10, 10, QtWidgets.QSizePolicy.Fixed,
                                  QtWidgets.QSizePolicy.Fixed), 4, 2)

        lyt = QtWidgets.QHBoxLayout()
        lyt.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Type")))
        self.tipo = QtWidgets.QComboBox()
        for txt in reaction.Reaction.TEXT_TYPE:
            self.tipo.addItem(txt)
        self.tipo.currentIndexChanged.connect(
            partial(self.changeParams, "tipo"))
        lyt.addWidget(self.tipo)
        lyt.addItem(
            QtWidgets.QSpacerItem(20, 10, QtWidgets.QSizePolicy.Fixed,
                                  QtWidgets.QSizePolicy.Fixed))
        lyt.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Concentration")))
        self.base = QtWidgets.QComboBox()
        for txt in reaction.Reaction.TEXT_BASE:
            self.base.addItem(txt)
        self.base.currentIndexChanged.connect(
            partial(self.changeParams, "base"))
        lyt.addWidget(self.base)
        lyt.addItem(
            QtWidgets.QSpacerItem(10, 10, QtWidgets.QSizePolicy.Expanding,
                                  QtWidgets.QSizePolicy.Fixed))
        gridLayout.addLayout(lyt, 5, 1, 1, 5)

        self.stacked = QtWidgets.QStackedWidget()
        self.tipo.currentIndexChanged.connect(self.stacked.setCurrentIndex)
        gridLayout.addWidget(self.stacked, 6, 1, 1, 5)
        gridLayout.addItem(
            QtWidgets.QSpacerItem(10, 10, QtWidgets.QSizePolicy.Expanding,
                                  QtWidgets.QSizePolicy.Expanding), 7, 1, 1, 5)

        widget = QtWidgets.QWidget()
        self.stacked.addWidget(widget)
        lyt = QtWidgets.QGridLayout(widget)
        lyt.addWidget(
            QtWidgets.QLabel("<h3>" + QtWidgets.QApplication.translate(
                "pychemqt", "Estequiometric reaction") + "</h3>"), 1, 1, 1, 4)
        self.Conversion = Tabla(1, verticalHeaderModel="C", filas=3)
        self.Conversion.setConnected()
        self.Conversion.setFixedWidth(100)
        lyt.addWidget(self.Conversion, 2, 1, 3, 1)
        label = QtWidgets.QLabel()
        label.setPixmap(
            QtGui.QPixmap(os.environ["pychemqt"] +
                          "/images/equation/reaction_conversion.png"))
        lyt.addWidget(label, 2, 2, 1, 3)
        lyt.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt",
                                                 "Temperature unit")), 3, 2)
        self.unidadesTemperatura = QtWidgets.QComboBox()
        for i in unidades.Temperature.__text__:
            self.unidadesTemperatura.addItem(i)
        lyt.addWidget(self.unidadesTemperatura, 3, 3)
        lyt.addItem(
            QtWidgets.QSpacerItem(10, 10, QtWidgets.QSizePolicy.Expanding,
                                  QtWidgets.QSizePolicy.Expanding), 4, 4)
        lyt.addItem(
            QtWidgets.QSpacerItem(10, 10, QtWidgets.QSizePolicy.Expanding,
                                  QtWidgets.QSizePolicy.Expanding), 5, 1, 1, 5)

        widget = QtWidgets.QWidget()
        self.stacked.addWidget(widget)
        lyt = QtWidgets.QGridLayout(widget)
        self.check_KFijo = QtWidgets.QRadioButton(
            QtWidgets.QApplication.translate("pychemqt", "Fixed"))
        self.check_KFijo.toggled.connect(self.KeqChanged)
        lyt.addWidget(self.check_KFijo, 1, 1, 1, 2)
        lyt.addWidget(QtWidgets.QLabel("K<sub>eq</sub>"), 1, 3)
        self.Keq = Entrada_con_unidades(float)
        lyt.addWidget(self.Keq, 1, 4)
        label = QtWidgets.QLabel()
        label.setPixmap(
            QtGui.QPixmap(os.environ["pychemqt"] +
                          "/images/equation/reaction_equilibrium.png"))
        lyt.addWidget(label, 1, 5, 1, 4)

        self.check_KEq = QtWidgets.QRadioButton(
            QtWidgets.QApplication.translate("pychemqt", "Equation"))
        self.check_KEq.toggled.connect(self.KeqChanged)
        lyt.addWidget(self.check_KEq, 2, 1, 1, 2)
        self.check_KTabla = QtWidgets.QRadioButton(
            QtWidgets.QApplication.translate("pychemqt", "Table"))
        self.check_KTabla.toggled.connect(self.KeqChanged)
        lyt.addWidget(self.check_KTabla, 2, 5, 1, 2)
        self.KEq_Dat = Tabla(
            1,
            verticalHeaderLabels=["A", "B", "C", "D", "E", "F", "G", "H"],
            filas=8)
        self.KEq_Dat.setFixedHeight(22 * 8 + 4)
        self.KEq_Dat.setFixedWidth(120)
        lyt.addWidget(self.KEq_Dat, 3, 3, 1, 2)
        self.KEq_Tab = Tabla(
            4,
            horizontalHeader=["T, K", "Keq", "Kcalc", "%Error"],
            verticalHeader=False,
            columnReadOnly=[False, False, True, True])
        self.KEq_Tab.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                   QtWidgets.QSizePolicy.Expanding)
        self.KEq_Tab.setFixedWidth(400)
        self.KEq_Tab.setConnected()
        self.KEq_Tab.rowFinished.connect(self.Regresion)
        self.KEq_Tab.setAlternatingRowColors(False)
        lyt.addWidget(self.KEq_Tab, 3, 5, 1, 4)
        lyt.addWidget(QtWidgets.QLabel("r²"), 4, 5)
        self.r2 = Entrada_con_unidades(float, readOnly=True)
        lyt.addWidget(self.r2, 4, 6)
        self.botonTablaPlot = QtWidgets.QPushButton(
            QtGui.QIcon(
                QtGui.QPixmap(os.environ["pychemqt"] +
                              "/images/button/plot.png")),
            QtWidgets.QApplication.translate("pychemqt", "Plot"))
        self.botonTablaPlot.clicked.connect(self.Plot)
        lyt.addWidget(self.botonTablaPlot, 4, 7)
        self.botonTablaClear = QtWidgets.QPushButton(
            QtGui.QIcon(
                QtGui.QPixmap(os.environ["pychemqt"] +
                              "/images/button/clear.png")),
            QtWidgets.QApplication.translate("pychemqt", "Clear"))
        self.botonTablaClear.clicked.connect(self.KEq_Tab.clear)
        lyt.addWidget(self.botonTablaClear, 4, 8)
        label = QtWidgets.QLabel()
        label.setPixmap(
            QtGui.QPixmap(os.environ["pychemqt"] +
                          "/images/equation/reaction_equilibrium2.png"))
        label.setAlignment(QtCore.Qt.AlignCenter)
        lyt.addWidget(label, 5, 1, 1, 8)

        self.checkGibbs = QtWidgets.QRadioButton(
            QtWidgets.QApplication.translate(
                "pychemqt", "From Gibbs free energy minimization"))
        lyt.addWidget(self.checkGibbs, 6, 1, 1, 4)

        self.check_KFijo.setChecked(True)

        widget = QtWidgets.QWidget()
        self.stacked.addWidget(widget)
        lyt = QtWidgets.QGridLayout(widget)

        widget = QtWidgets.QWidget()
        self.stacked.addWidget(widget)
        lyt = QtWidgets.QGridLayout(widget)

        self.status = Status()
        gridLayout.addWidget(self.status, 10, 1)
        self.buttonBox = QtWidgets.QDialogButtonBox(
            QtWidgets.QDialogButtonBox.Cancel | QtWidgets.QDialogButtonBox.Ok)
        self.buttonBox.accepted.connect(self.accept)
        self.buttonBox.rejected.connect(self.reject)
        gridLayout.addWidget(self.buttonBox, 10, 2, 1, 4)

        if reaccion:
            self.setReaction(reaccion)
Beispiel #22
0
class UI_equipment(UI_equip):
    """Divider equipment edition dialog"""
    Equipment = Divider()

    def __init__(self, equipment=None, salidas=0, parent=None):
        """
        equipment: Initial equipment instance to model
        salidas: Stream Output number to equipment
        """
        super().__init__(Divider, entrada=False, parent=parent)

        # Calculate tab
        lyt_Calc = QtWidgets.QGridLayout(self.tabCalculo)
        lyt_Calc.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Separation")), 1, 1, 1, 1)
        self.criterio = QtWidgets.QComboBox()
        for txt in self.Equipment.TEXT_CRITERIO:
            self.criterio.addItem(txt)
        self.criterio.currentIndexChanged.connect(self.criterio_Changed)
        lyt_Calc.addWidget(self.criterio, 1, 2, 1, 1)

        self.fracciones = Tabla(1, horizontalHeader=[True], stretch=False)
        self.fracciones.setItemDelegateForColumn(0, CellEditor(self))
        lyt_Calc.addWidget(self.fracciones, 2, 1, 1, 2)

        lyt_Calc.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Pressure lost")), 3, 1, 1, 1)
        self.deltaP = Entrada_con_unidades(Pressure, value=0)
        self.deltaP.valueChanged.connect(partial(self.changeParams, "deltaP"))
        lyt_Calc.addWidget(self.deltaP, 3, 2, 1, 1)

        if equipment and salidas:
            equipment(salidas=salidas)
        elif equipment:
            salidas = equipment.kwargs["salidas"]
        else:
            self.Equipment = Divider(salidas=salidas)

        self.fracciones.setRowCount(salidas)
        for i in range(salidas):
            itm = QtWidgets.QTableWidgetItem("%i" % i)
            itm.setTextAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
            self.fracciones.setItem(0, i, itm)
            self.fracciones.setRowHeight(i, 20)
            widget = UI_corriente.Ui_corriente(readOnly=True)
            self.Salida.addTab(widget, str(i+1))

        self.criterio_Changed(0)
        self.fracciones.editingFinished.connect(
            partial(self.changeParams, "split"))
        self.setEquipment(equipment)

    def criterio_Changed(self, int):
        if int:
            item = QtWidgets.QTableWidgetItem(QtWidgets.QApplication.translate(
                "pychemqt", "Flow")+", "+MassFlow.text())
            self.fracciones.setHorizontalHeaderItem(0, item)
            self.fracciones.item(self.fracciones.rowCount()-1, 0).setFlags(
                QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsEnabled |
                QtCore.Qt.ItemIsSelectable)
        else:
            item = QtWidgets.QTableWidgetItem(QtWidgets.QApplication.translate(
                "pychemqt", "Flow")+", "+MassFlow.text())
            self.fracciones.setHorizontalHeaderItem(0, item)
            self.fracciones.item(self.fracciones.rowCount()-1, 0).setFlags(
                QtCore.Qt.NoItemFlags)
        self.changeParams("criterio", int)

    def changeParams(self, parametro, valor=None):
        if parametro == "split":
            valor = self.fracciones.getColumn(0, False)
            if self.criterio.currentIndex() == 0:
                if len(valor)+1 < self.fracciones.rowCount():
                    return
                elif len(valor)+1 == self.fracciones.rowCount():
                    valor.append(1-sum(valor))
                elif len(valor) == self.fracciones.rowCount():
                    valor[-1] = 1-sum(valor[:-1])
        self.calculo(**{parametro: valor})

    def rellenar(self):
        UI_equip.rellenar(self)
        if self.Equipment.status == 1 and self.criterio.currentIndex() == 1:
                self.entrada.setCorriente(self.Equipment.entrada)

    def rellenarInput(self):
        UI_equip.rellenarInput(self)
        self.fracciones.setColumn(0, self.Equipment.kwargs["split"])
Beispiel #23
0
class widgetReacciones(QtWidgets.QWidget):
    """Widget con la tabla de reacciones y los botones para modificar la lista de reacciones"""
    changed = QtCore.pyqtSignal()
    reacciones = []
    reaccion = None
    activo = None
    ajuste = None

    def __init__(self, parent=None):
        super(widgetReacciones, self).__init__(parent)
        self.indices, self.nombres, M = getComponents()
        gridLayout = QtWidgets.QGridLayout(self)

        self.TablaReacciones = Tabla(
            5,
            horizontalHeader=[
                QtWidgets.QApplication.translate("pychemqt", "Reaction"),
                "ΔHr, %s" % unidades.MolarEnthalpy(None).text(),
                QtWidgets.QApplication.translate("pychemqt", "Type"),
                QtWidgets.QApplication.translate("pychemqt", "Phase"),
                QtWidgets.QApplication.translate("pychemqt", "Description")
            ],
            dinamica=False,
            verticalHeader=True,
            orientacion=QtCore.Qt.AlignLeft)
        self.TablaReacciones.setMinimumWidth(500)
        self.TablaReacciones.setSelectionBehavior(
            QtWidgets.QAbstractItemView.SelectRows)
        self.TablaReacciones.setSelectionMode(
            QtWidgets.QAbstractItemView.SingleSelection)
        self.TablaReacciones.horizontalHeader().setStretchLastSection(True)
        self.TablaReacciones.setEditTriggers(
            QtWidgets.QAbstractItemView.NoEditTriggers)
        self.TablaReacciones.itemSelectionChanged.connect(
            self.actualizarBotones)
        gridLayout.addWidget(self.TablaReacciones, 1, 1, 6, 4)

        self.botonAbrir = QtWidgets.QPushButton(
            QtGui.QIcon(
                QtGui.QPixmap(os.environ["pychemqt"] +
                              "/images/button/fileOpen.png")),
            QtWidgets.QApplication.translate("pychemqt", "Open"))
        self.botonAbrir.clicked.connect(self.botonAbrirClicked)
        gridLayout.addWidget(self.botonAbrir, 1, 5)
        self.botonGuardar = QtWidgets.QPushButton(
            QtGui.QIcon(
                QtGui.QPixmap(os.environ["pychemqt"] +
                              "/images/button/fileSave.png")),
            QtWidgets.QApplication.translate("pychemqt", "Save"))
        self.botonGuardar.clicked.connect(self.botonGuardarClicked)
        self.botonGuardar.setSizePolicy(QtWidgets.QSizePolicy.Fixed,
                                        QtWidgets.QSizePolicy.Fixed)
        self.botonGuardar.setEnabled(False)
        gridLayout.addWidget(self.botonGuardar, 2, 5)

        self.botonNew = QtWidgets.QPushButton(
            QtGui.QIcon(
                QtGui.QPixmap(os.environ["pychemqt"] +
                              "/images/button/fileNew.png")),
            QtWidgets.QApplication.translate("pychemqt", "New"))
        self.botonNew.clicked.connect(self.botonNewClicked)
        gridLayout.addWidget(self.botonNew, 3, 5)
        self.botonEdit = QtWidgets.QPushButton(
            QtGui.QIcon(
                QtGui.QPixmap(os.environ["pychemqt"] +
                              "/images/button/editor.png")),
            QtWidgets.QApplication.translate("pychemqt", "Edit"))
        self.botonEdit.setEnabled(False)
        self.botonEdit.setCheckable(True)
        self.botonEdit.clicked.connect(self.botonEditClicked)
        gridLayout.addWidget(self.botonEdit, 4, 5)
        self.botonDelete = QtWidgets.QPushButton(
            QtGui.QIcon(
                QtGui.QPixmap(os.environ["pychemqt"] +
                              "/images/button/editDelete.png")),
            QtWidgets.QApplication.translate("pychemqt", "Delete"))
        self.botonDelete.setEnabled(False)
        self.botonDelete.clicked.connect(self.botonDeleteClicked)
        gridLayout.addWidget(self.botonDelete, 5, 5)
        self.botonClear = QtWidgets.QPushButton(
            QtGui.QIcon(
                QtGui.QPixmap(os.environ["pychemqt"] +
                              "/images/button/clear.png")),
            QtWidgets.QApplication.translate("pychemqt", "Clear"))
        self.botonClear.clicked.connect(self.botonClearClicked)
        gridLayout.addWidget(self.botonClear, 6, 5)
        gridLayout.addItem(
            QtWidgets.QSpacerItem(10, 10, QtWidgets.QSizePolicy.Expanding,
                                  QtWidgets.QSizePolicy.Expanding), 10, 1)

    def actualizarBotones(self, bool=True):
        self.botonEdit.setEnabled(bool)
        self.botonDelete.setEnabled(bool)

    def botonAbrirClicked(self):
        fname = str(
            QtWidgets.QFileDialog.getOpenFileName(
                self,
                QtWidgets.QApplication.translate("pychemqt",
                                                 "Open reaction file"), "./",
                QtWidgets.QApplication.translate("pychemqt", "reaction file") +
                " (*.rec);;" +
                QtWidgets.QApplication.translate("pychemqt", "All files") +
                " (*.*)")[0])
        if fname:
            with open(fname, "r") as archivo:
                reacciones = pickle.load(archivo)
            print(reacciones)
            self.reacciones = reacciones
            self.botonGuardar.setEnabled(True)
            for fila, reaccion in enumerate(reacciones):
                self.TablaReacciones.addRow()
                self.TablaReacciones.setValue(fila, 0, reaccion.text)
                self.TablaReacciones.setValue(fila, 1,
                                              "%0.4e" % reaccion.Hr.config(),
                                              QtCore.Qt.AlignRight)
                self.TablaReacciones.setValue(
                    fila, 2,
                    str(reaccion.tipo + 1) + " - " +
                    reaction.Reaction.TEXT_TYPE[reaccion.tipo])
                self.TablaReacciones.setValue(
                    fila, 3, reaction.Reaction.TEXT_PHASE[reaccion.fase])
                self.TablaReacciones.item(
                    fila, 4).setFlags(QtCore.Qt.ItemIsEditable
                                      | QtCore.Qt.ItemIsEnabled
                                      | QtCore.Qt.ItemIsSelectable)
            for i in range(4):
                self.TablaReacciones.resizeColumnToContents(i)
        self.changed.emit()

    def botonGuardarClicked(self):
        fname = str(
            QtWidgets.QFileDialog.getSaveFileName(
                self,
                QtWidgets.QApplication.translate("pychemqt",
                                                 "Save reaction to file"),
                "./",
                QtWidgets.QApplication.translate("pychemqt", "reaction file") +
                " (*.rec)")[0])
        if fname:
            if fname.split(".")[-1] != "rec":
                fname += ".rec"
            pickle.dump(self.reacciones, open(fname, "w"))

    def botonNewClicked(self):
        dialog = UI_reacciones(parent=self)
        if dialog.exec_():
            pass

    def botonEditClicked(self, bool):
        if bool:
            indice = self.TablaReacciones.currentRow()
            reaccion = self.reacciones[indice]
            dialogo = UI_reacciones(reaccion, self)
            dialogo.exec_()


#            self.rellenar(self.reaccion)
#            self.activo=indice
        else:
            self.botonAddClicked(self.activo, False)
            self.reacciones[self.activo] = self.reaccion
            self.TablaReacciones.setCurrentCell(self.activo, 0)
            self.activo = -1
            self.changed.emit()

        self.botonNew.setEnabled(not bool)
        self.botonDelete.setEnabled(not bool)
        self.botonClear.setEnabled(not bool)
        self.botonAdd.setEnabled(not bool)
        self.botonAbrir.setEnabled(not bool)
        self.botonGuardar.setEnabled(not bool)

    def botonDeleteClicked(self):
        indice = self.TablaReacciones.currentRow()
        self.TablaReacciones.removeRow(indice)
        del self.reacciones[indice]
        self.TablaReacciones.clearSelection()
        self.actualizarBotones(False)
        self.changed.emit()

    def botonClearClicked(self):
        if self.reacciones:
            self.reacciones = []
            self.TablaReacciones.setRowCount(0)
            self.botonGuardar.setEnabled(False)

    def botonAddClicked(self, fila, add=True):
        if add:
            fila = self.TablaReacciones.rowCount()
            self.TablaReacciones.addRow()
        self.TablaReacciones.setValue(fila, 0, self.Formula.text())
        self.TablaReacciones.setValue(fila, 1,
                                      "%0.4e" % self.Hr.value.config(),
                                      QtCore.Qt.AlignRight)
        self.TablaReacciones.setValue(
            fila, 2,
            str(self.tipo.currentIndex() + 1) + " - " +
            self.tipo.currentText())
        self.TablaReacciones.setValue(fila, 3, self.Fase.currentText())
        self.TablaReacciones.item(fila,
                                  4).setFlags(QtCore.Qt.ItemIsEditable
                                              | QtCore.Qt.ItemIsEnabled
                                              | QtCore.Qt.ItemIsSelectable)
        for i in range(4):
            self.TablaReacciones.resizeColumnToContents(i)
        self.reacciones.insert(fila, self.reaccion)
        self.botonGuardar.setEnabled(True)
        self.changed.emit()
Beispiel #24
0
    def __init__(self, equipment=None, parent=None):
        """
        equipment: Initial equipment instance to model
        """
        super().__init__(Baghouse, entrada=False, parent=parent)

        # Efficiency tab
        title = [
            QtWidgets.QApplication.translate("pychemqt", "Diameter") + ", " +
            Length.text("ParticleDiameter"),
            QtWidgets.QApplication.translate("pychemqt", "Efficiency")
        ]
        self.efic = Tabla(2, horizontalHeader=title, filas=1, stretch=False)
        self.efic.setColumnReadOnly(0, True)
        self.efic.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
        self.efic.editingFinished.connect(self.cambiarRendimientos)
        self.tabWidget.insertTab(
            1, self.efic,
            QtWidgets.QApplication.translate("pychemqt", "Efficiencies"))

        # Calculate tab
        lyt_Calc = QtWidgets.QGridLayout(self.tabCalculo)
        lyt_Calc.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Mode")), 1, 1)
        self.metodo = QtWidgets.QComboBox()
        for txt in self.Equipment.TEXT_TIPO:
            self.metodo.addItem(txt)
        self.metodo.currentIndexChanged.connect(self.tipoCalculoCambiado)
        lyt_Calc.addWidget(self.metodo, 1, 2, 1, 3)
        lyt_Calc.addItem(
            QtWidgets.QSpacerItem(20, 20, QtWidgets.QSizePolicy.Fixed,
                                  QtWidgets.QSizePolicy.Fixed), 2, 1, 1, 6)
        lyt_Calc.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "No cells")), 3,
            1)
        self.num_filtros = Entrada_con_unidades(int,
                                                spinbox=True,
                                                step=1,
                                                min=1,
                                                width=50,
                                                resaltado=True,
                                                start=1)
        self.num_filtros.valueChanged.connect(
            partial(self.changeParams, "num_filtros"))
        lyt_Calc.addWidget(self.num_filtros, 3, 2)
        lyt_Calc.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Time")), 4, 1)
        self.tiempo = Entrada_con_unidades(Time, resaltado=True)
        self.tiempo.valueChanged.connect(partial(self.changeParams, "tiempo"))
        lyt_Calc.addWidget(self.tiempo, 4, 2)
        lyt_Calc.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Pressure drop")),
            5, 1)
        self.deltaP = Entrada_con_unidades(Pressure, retornar=False)
        self.deltaP.setReadOnly(True)
        self.deltaP.valueChanged.connect(partial(self.changeParams, "deltaP"))
        lyt_Calc.addWidget(self.deltaP, 5, 2)
        lyt_Calc.addItem(
            QtWidgets.QSpacerItem(20, 20, QtWidgets.QSizePolicy.Fixed,
                                  QtWidgets.QSizePolicy.Fixed), 6, 1, 1, 6)
        lyt_Calc.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Bags per cell")),
            7, 1)
        self.membranasFiltro = Entrada_con_unidades(int,
                                                    spinbox=True,
                                                    step=1,
                                                    min=1)
        self.membranasFiltro.valueChanged.connect(
            partial(self.changeParams, "membranasFiltro"))
        lyt_Calc.addWidget(self.membranasFiltro, 7, 2)
        lyt_Calc.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Bag diameter")),
            8, 1)
        self.diametroMembrana = Entrada_con_unidades(Length)
        self.diametroMembrana.valueChanged.connect(
            partial(self.changeParams, "diametroMembrana"))
        lyt_Calc.addWidget(self.diametroMembrana, 8, 2)
        lyt_Calc.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Area per bag")),
            9, 1)
        self.areaMembrana = Entrada_con_unidades(Area)
        self.areaMembrana.valueChanged.connect(
            partial(self.changeParams, "areaMembrana"))
        lyt_Calc.addWidget(self.areaMembrana, 9, 2)
        lyt_Calc.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt",
                                                 "Cloth resistence")), 7, 4)
        self.resistenciaFiltro = Entrada_con_unidades(float)
        self.resistenciaFiltro.valueChanged.connect(
            partial(self.changeParams, "resistenciaFiltro"))
        lyt_Calc.addWidget(self.resistenciaFiltro, 7, 5)
        lyt_Calc.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt",
                                                 "Cake resistence")), 8, 4)
        self.resistenciaTorta = Entrada_con_unidades(float)
        self.resistenciaTorta.valueChanged.connect(
            partial(self.changeParams, "resistenciaTorta"))
        lyt_Calc.addWidget(self.resistenciaTorta, 8, 5)
        lyt_Calc.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Cells cleaned")),
            9, 4)
        self.limpieza = Entrada_con_unidades(int, spinbox=True, step=1, min=0)
        self.limpieza.valueChanged.connect(
            partial(self.changeParams, "limpieza"))
        lyt_Calc.addWidget(self.limpieza, 9, 5)
        lyt_Calc.addItem(
            QtWidgets.QSpacerItem(20, 20, QtWidgets.QSizePolicy.Expanding,
                                  QtWidgets.QSizePolicy.Expanding), 10, 1, 1,
            6)

        groupbox = QtWidgets.QGroupBox(
            QtWidgets.QApplication.translate("pychemqt", "Results"))
        lyt_Calc.addWidget(groupbox, 11, 1, 1, 5)
        lyt = QtWidgets.QGridLayout(groupbox)

        lyt.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "No cells")), 1,
            1)
        self.num_filtrosCalc = Entrada_con_unidades(int, readOnly=True)
        lyt.addWidget(self.num_filtrosCalc, 1, 2)
        lyt.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Time")), 2, 1)
        self.tiempoCalc = Entrada_con_unidades(Time, readOnly=True)
        lyt.addWidget(self.tiempoCalc, 2, 2)
        lyt.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Pressure drop")),
            3, 1)
        self.deltaPCalc = Entrada_con_unidades(Pressure, readOnly=True)
        lyt.addWidget(self.deltaPCalc, 3, 2)

        lyt.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Gas velocity")),
            1, 4)
        self.Vgas = Entrada_con_unidades(Speed, retornar=False, readOnly=True)
        lyt.addWidget(self.Vgas, 1, 5)
        lyt.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Efficiency")), 2,
            4)
        self.rendimiento = Entrada_con_unidades(float, readOnly=True)
        lyt.addWidget(self.rendimiento, 2, 5)
        lyt.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Area")), 3, 4)
        self.floorArea = Entrada_con_unidades(Area, readOnly=True)
        lyt.addWidget(self.floorArea, 3, 5)
        lyt_Calc.addItem(
            QtWidgets.QSpacerItem(20, 20, QtWidgets.QSizePolicy.Expanding,
                                  QtWidgets.QSizePolicy.Expanding), 12, 1, 1,
            6)

        # Output tab
        self.addSalida(
            QtWidgets.QApplication.translate("pychemqt", "Filtered gas"))
        self.addSalida(
            QtWidgets.QApplication.translate("pychemqt", "Collected solids"))

        if equipment:
            self.setEquipment(equipment)
Beispiel #25
0
    def __init__(self, reaccion=None, parent=None):
        super(UI_reacciones, self).__init__(parent)
        self.evaluate=Evaluate()
        self.evaluate.finished.connect(self.rellenar)
        self.indices, self.nombres, M=getComponents()
        gridLayout = QtWidgets.QGridLayout(self)

        lyt=QtWidgets.QHBoxLayout()
        lyt.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate("pychemqt", "Key component")))
        self.key=QtWidgets.QComboBox()
        for i, nombre in enumerate(self.nombres):
            self.key.addItem("%i - %s" %(i+1, nombre))
        self.key.currentIndexChanged.connect(partial(self.changeParams, "key"))
        lyt.addWidget(self.key)
        lyt.addItem(QtWidgets.QSpacerItem(10,10,QtWidgets.QSizePolicy.Expanding,QtWidgets.QSizePolicy.Fixed))
        gridLayout.addLayout(lyt,1,1,1,5)

        lyt=QtWidgets.QHBoxLayout()
        lyt.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate("pychemqt", "Phase")))
        self.fase=QtWidgets.QComboBox()
        for txt in reaction.Reaction.TEXT_PHASE:
            self.fase.addItem(txt)
        self.fase.currentIndexChanged.connect(partial(self.changeParams, "fase"))
        lyt.addWidget(self.fase)
        self.Formula=QtWidgets.QLabel()
        self.Formula.setAlignment(QtCore.Qt.AlignCenter)
        self.Formula.setSizePolicy(QtWidgets.QSizePolicy.Expanding,QtWidgets.QSizePolicy.Fixed)
        lyt.addWidget(self.Formula)
        gridLayout.addLayout(lyt,2,1,1,5)

        lyt=QtWidgets.QVBoxLayout()
        title=self.nombres[:]
        title.append("")
        self.Estequiometria=Tabla(1, verticalHeaderLabels=title, horizontalHeader=[QtWidgets.QApplication.translate("pychemqt", "Coefficients")], filas=len(self.indices))
        self.Estequiometria.setFixedHeight(22*len(self.indices)+22+4+22)
        lyt.addWidget(self.Estequiometria)
        self.Estequiometria.addRow()
        brush=QtGui.QBrush(QtGui.QColor("#eaeaea"))
        self.Estequiometria.item(len(self.indices), 0).setBackground(brush)
        self.Estequiometria.item(len(self.indices), 0).setFlags(QtCore.Qt.NoItemFlags)
        self.Estequiometria.cellChanged.connect(self.reaccionCambiada)
        lyt.addItem(QtWidgets.QSpacerItem(10,10,QtWidgets.QSizePolicy.Fixed,QtWidgets.QSizePolicy.Expanding))
        gridLayout.addLayout(lyt,3,1,1,2)

        lyt=QtWidgets.QGridLayout()
        lyt.addItem(QtWidgets.QSpacerItem(10,10,QtWidgets.QSizePolicy.Fixed,QtWidgets.QSizePolicy.Fixed),1,1)
        self.formula=QtWidgets.QCheckBox(QtWidgets.QApplication.translate("pychemqt", "Use name in formula"))
        self.formula.toggled.connect(partial(self.changeParams, "formula"))
        lyt.addWidget(self.formula,1,2,1,2)
        self.customHr=QtWidgets.QCheckBox("ΔHr "+QtWidgets.QApplication.translate("pychemqt", "user specified"))
        self.customHr.toggled.connect(self.changeHr)
        lyt.addWidget(self.customHr,2,2,1,2)
        lyt.addWidget(QtWidgets.QLabel("ΔHr<sup>o</sup>"),3,2)
        self.Hr=Entrada_con_unidades(unidades.MolarEnthalpy, readOnly=True)
        self.Hr.valueChanged.connect(partial(self.changeParams, "Hr"))
        lyt.addWidget(self.Hr,3,3)
        lyt.addItem(QtWidgets.QSpacerItem(10,10,QtWidgets.QSizePolicy.Fixed,QtWidgets.QSizePolicy.Expanding))
        gridLayout.addLayout(lyt,3,3,1,2)

        gridLayout.addItem(QtWidgets.QSpacerItem(10,10,QtWidgets.QSizePolicy.Fixed,QtWidgets.QSizePolicy.Fixed),4,2)

        lyt=QtWidgets.QHBoxLayout()
        lyt.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate("pychemqt", "Type")))
        self.tipo=QtWidgets.QComboBox()
        for txt in reaction.Reaction.TEXT_TYPE:
            self.tipo.addItem(txt)
        self.tipo.currentIndexChanged.connect(partial(self.changeParams, "tipo"))
        lyt.addWidget(self.tipo)
        lyt.addItem(QtWidgets.QSpacerItem(20,10,QtWidgets.QSizePolicy.Fixed,QtWidgets.QSizePolicy.Fixed))
        lyt.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate("pychemqt", "Concentration")))
        self.base=QtWidgets.QComboBox()
        for txt in reaction.Reaction.TEXT_BASE:
            self.base.addItem(txt)
        self.base.currentIndexChanged.connect(partial(self.changeParams, "base"))
        lyt.addWidget(self.base)
        lyt.addItem(QtWidgets.QSpacerItem(10,10,QtWidgets.QSizePolicy.Expanding,QtWidgets.QSizePolicy.Fixed))
        gridLayout.addLayout(lyt,5,1,1,5)

        self.stacked = QtWidgets.QStackedWidget()
        self.tipo.currentIndexChanged.connect(self.stacked.setCurrentIndex)
        gridLayout.addWidget(self.stacked,6,1,1,5)
        gridLayout.addItem(QtWidgets.QSpacerItem(10,10,QtWidgets.QSizePolicy.Expanding,QtWidgets.QSizePolicy.Expanding),7,1,1,5)

        widget=QtWidgets.QWidget()
        self.stacked.addWidget(widget)
        lyt=QtWidgets.QGridLayout(widget)
        lyt.addWidget(QtWidgets.QLabel("<h3>"+QtWidgets.QApplication.translate("pychemqt", "Estequiometric reaction")+"</h3>"),1,1,1,4)
        self.Conversion=Tabla(1, verticalHeaderModel="C", filas=3)
        self.Conversion.setConnected()
        self.Conversion.setFixedWidth(100)
        lyt.addWidget(self.Conversion,2,1,3,1)
        label=QtWidgets.QLabel()
        label.setPixmap(QtGui.QPixmap(os.environ["pychemqt"]+"/images/equation/reaction_conversion.png"))
        lyt.addWidget(label,2,2,1,3)
        lyt.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate("pychemqt", "Temperature unit")),3,2)
        self.unidadesTemperatura=QtWidgets.QComboBox()
        for i in unidades.Temperature.__text__:
            self.unidadesTemperatura.addItem(i)
        lyt.addWidget(self.unidadesTemperatura,3,3)
        lyt.addItem(QtWidgets.QSpacerItem(10,10,QtWidgets.QSizePolicy.Expanding,QtWidgets.QSizePolicy.Expanding),4,4)
        lyt.addItem(QtWidgets.QSpacerItem(10,10,QtWidgets.QSizePolicy.Expanding,QtWidgets.QSizePolicy.Expanding),5,1,1,5)


        widget=QtWidgets.QWidget()
        self.stacked.addWidget(widget)
        lyt=QtWidgets.QGridLayout(widget)
        self.check_KFijo=QtWidgets.QRadioButton(QtWidgets.QApplication.translate("pychemqt", "Fixed"))
        self.check_KFijo.toggled.connect(self.KeqChanged)
        lyt.addWidget(self.check_KFijo,1,1,1,2)
        lyt.addWidget(QtWidgets.QLabel("K<sub>eq</sub>"),1,3)
        self.Keq=Entrada_con_unidades(float)
        lyt.addWidget(self.Keq,1,4)
        label=QtWidgets.QLabel()
        label.setPixmap(QtGui.QPixmap(os.environ["pychemqt"]+"/images/equation/reaction_equilibrium.png"))
        lyt.addWidget(label,1,5,1,4)

        self.check_KEq=QtWidgets.QRadioButton(QtWidgets.QApplication.translate("pychemqt", "Equation"))
        self.check_KEq.toggled.connect(self.KeqChanged)
        lyt.addWidget(self.check_KEq,2,1,1,2)
        self.check_KTabla=QtWidgets.QRadioButton(QtWidgets.QApplication.translate("pychemqt", "Table"))
        self.check_KTabla.toggled.connect(self.KeqChanged)
        lyt.addWidget(self.check_KTabla,2,5,1,2)
        self.KEq_Dat=Tabla(1, verticalHeaderLabels=["A", "B", "C", "D", "E", "F", "G", "H"], filas=8)
        self.KEq_Dat.setFixedHeight(22*8+4)
        self.KEq_Dat.setFixedWidth(120)
        lyt.addWidget(self.KEq_Dat,3,3,1,2)
        self.KEq_Tab=Tabla(4, horizontalHeader=["T, K", "Keq", "Kcalc", "%Error"], verticalHeader=False, columnReadOnly=[False, False, True, True])
        self.KEq_Tab.setSizePolicy(QtWidgets.QSizePolicy.Expanding,QtWidgets.QSizePolicy.Expanding)
        self.KEq_Tab.setFixedWidth(400)
        self.KEq_Tab.setConnected()
        self.KEq_Tab.rowFinished.connect(self.Regresion)
        self.KEq_Tab.setAlternatingRowColors(False)
        lyt.addWidget(self.KEq_Tab,3,5,1,4)
        lyt.addWidget(QtWidgets.QLabel("r²"),4,5)
        self.r2=Entrada_con_unidades(float, readOnly=True)
        lyt.addWidget(self.r2,4,6)
        self.botonTablaPlot=QtWidgets.QPushButton(QtGui.QIcon(QtGui.QPixmap(os.environ["pychemqt"]+"/images/button/plot.png")), QtWidgets.QApplication.translate("pychemqt", "Plot"))
        self.botonTablaPlot.clicked.connect(self.Plot)
        lyt.addWidget(self.botonTablaPlot,4,7)
        self.botonTablaClear=QtWidgets.QPushButton(QtGui.QIcon(QtGui.QPixmap(os.environ["pychemqt"]+"/images/button/clear.png")), QtWidgets.QApplication.translate("pychemqt", "Clear"))
        self.botonTablaClear.clicked.connect(self.KEq_Tab.clear)
        lyt.addWidget(self.botonTablaClear,4,8)
        label=QtWidgets.QLabel()
        label.setPixmap(QtGui.QPixmap(os.environ["pychemqt"]+"/images/equation/reaction_equilibrium2.png"))
        label.setAlignment(QtCore.Qt.AlignCenter)
        lyt.addWidget(label,5,1,1,8)


        self.checkGibbs=QtWidgets.QRadioButton(QtWidgets.QApplication.translate("pychemqt", "From Gibbs free energy minimization"))
        lyt.addWidget(self.checkGibbs,6,1,1,4)

        self.check_KFijo.setChecked(True)


        widget=QtWidgets.QWidget()
        self.stacked.addWidget(widget)
        lyt=QtWidgets.QGridLayout(widget)

        widget=QtWidgets.QWidget()
        self.stacked.addWidget(widget)
        lyt=QtWidgets.QGridLayout(widget)

        self.status=Status()
        gridLayout.addWidget(self.status, 10,1)
        self.buttonBox = QtWidgets.QDialogButtonBox(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
        self.buttonBox.accepted.connect(self.accept)
        self.buttonBox.rejected.connect(self.reject)
        gridLayout.addWidget(self.buttonBox,10,2,1,4)

        if reaccion:
            self.setReaction(reaccion)
Beispiel #26
0
    def __init__(self,
                 data=None,
                 t=[],
                 property=[],
                 horizontalHeader=[],
                 title="",
                 help=False,
                 helpFile="",
                 DIPPR=False,
                 tc=0,
                 tcValue=None,
                 eq=1,
                 parent=None):
        """
        title: window title
        data: mrray with original data
        t: values for x column, generally temperature
        property: values for 2...n columns
        horizontalHeader: List with column title
        help: boolean to show help button
        helpFile: Path for help file, file or url
        DIPPR: boolean to show DIPPR widget
        tc: boolean to show critical temperature (same DIPPR eq need it)
        tcValue: value for critical temperature
        eq: Value for DIPPR equation
        """
        super(Entrada_Datos, self).__init__(parent)
        self.setWindowTitle(title)
        self.columnas = len(horizontalHeader)
        self.horizontalHeader = horizontalHeader
        self.title = title
        self.helpFile = helpFile
        gridLayout = QtWidgets.QGridLayout(self)
        self.botonAbrir = QtWidgets.QPushButton(
            QtGui.QIcon(
                QtGui.QPixmap(os.environ["pychemqt"] +
                              "/images/button/fileOpen.png")),
            QtWidgets.QApplication.translate("pychemqt", "Open"))
        self.botonAbrir.clicked.connect(self.Abrir)
        gridLayout.addWidget(self.botonAbrir, 1, 1)
        self.botonGuardar = QtWidgets.QPushButton(
            QtGui.QIcon(
                QtGui.QPixmap(os.environ["pychemqt"] +
                              "/images/button/fileSave.png")),
            QtWidgets.QApplication.translate("pychemqt", "Save"))
        self.botonGuardar.clicked.connect(self.Guardar)
        gridLayout.addWidget(self.botonGuardar, 1, 2)
        self.botonDelete = QtWidgets.QPushButton(
            QtGui.QIcon(
                QtGui.QPixmap(os.environ["pychemqt"] +
                              "/images/button/clear.png")),
            QtWidgets.QApplication.translate("pychemqt", "Clear"))
        self.botonDelete.clicked.connect(self.Borrar)
        gridLayout.addWidget(self.botonDelete, 1, 3)
        gridLayout.addItem(
            QtWidgets.QSpacerItem(0, 0, QtWidgets.QSizePolicy.Expanding,
                                  QtWidgets.QSizePolicy.Expanding), 1, 4)

        self.tabla = Tabla(self.columnas,
                           horizontalHeader=horizontalHeader,
                           verticalHeader=False,
                           stretch=False)
        self.tabla.setConnected()
        if data:
            self.tabla.setData(data)
            self.tabla.addRow()
        elif t and property:
            self.tabla.setColumn(0, t)
            self.tabla.setColumn(1, property)
        gridLayout.addWidget(self.tabla, 2, 1, 1, 4)

        if DIPPR:
            self.eqDIPPR = eqDIPPR(eq)
            gridLayout.addWidget(self.eqDIPPR, 3, 1, 1, 4)
            self.eqDIPPR.eqDIPPR.valueChanged.connect(self.showTc)

        if tc:
            lyt = QtWidgets.QHBoxLayout()
            self.labelTc = QtWidgets.QLabel("Tc: ", self)
            lyt.addWidget(self.labelTc)
            self.tc = Entrada_con_unidades(Temperature, value=tcValue)
            lyt.addWidget(self.tc)
            lyt.addItem(
                QtWidgets.QSpacerItem(0, 0, QtWidgets.QSizePolicy.Expanding,
                                      QtWidgets.QSizePolicy.Expanding))
            gridLayout.addItem(lyt, 4, 1, 1, 4)
            self.showTc(1)

        if help:
            botones = QtWidgets.QDialogButtonBox.Help | \
                QtWidgets.QDialogButtonBox.Cancel | \
                QtWidgets.QDialogButtonBox.Ok
        else:
            botones = QtWidgets.QDialogButtonBox.Cancel | \
                QtWidgets.QDialogButtonBox.Ok
        self.boton = QtWidgets.QDialogButtonBox(botones)
        self.boton.accepted.connect(self.accept)
        self.boton.rejected.connect(self.reject)
        self.boton.helpRequested.connect(self.ayuda)
        gridLayout.addWidget(self.boton, 5, 1, 1, 4)
Beispiel #27
0
    def __init__(self, columnas, data=None, t=[], property=[],
                 horizontalHeader=[], title="", DIPPR=False, hasTc=0,
                 Tc=None, eq=1, unit=[], parent=None):
        """
        data: mrray with original data
        t: values for x column, generally temperature
        property: values for 2...n columns
        horizontalHeader: List with column title
        DIPPR: boolean to show DIPPR widget
        hasTc: boolean to show critical temperature (some DIPPR eq need it)
        Tc: value for critical temperature
        eq: Value for DIPPR equation
        unit: List of unidades classes for column definition
        """
        super(InputTableWidget, self).__init__(parent)
        self.columnas = columnas
        self.title = title
        self.unit = unit
        gridLayout = QtWidgets.QGridLayout(self)
        gridLayout.setContentsMargins(0, 0, 0, 0)
        openButton = QtWidgets.QPushButton(QtGui.QIcon(QtGui.QPixmap(
            os.environ["pychemqt"]+"/images/button/fileOpen.png")), "")
        openButton.setToolTip(QtWidgets.QApplication.translate(
            "pychemqt", "Load data from a file"))
        openButton.clicked.connect(self.open)
        gridLayout.addWidget(openButton, 1, 1)
        saveButton = QtWidgets.QPushButton(QtGui.QIcon(QtGui.QPixmap(
            os.environ["pychemqt"]+"/images/button/fileSave.png")), "")
        saveButton.setToolTip(QtWidgets.QApplication.translate(
            "pychemqt", "Save data to a file"))
        saveButton.clicked.connect(self.save)
        gridLayout.addWidget(saveButton, 1, 2)
        clearButton = QtWidgets.QPushButton(QtGui.QIcon(QtGui.QPixmap(
            os.environ["pychemqt"]+"/images/button/clear.png")), "")
        clearButton.setToolTip(QtWidgets.QApplication.translate(
            "pychemqt", "Clear data"))
        clearButton.clicked.connect(self.delete)
        gridLayout.addWidget(clearButton, 1, 3)
        gridLayout.addItem(QtWidgets.QSpacerItem(
            0, 0, QtWidgets.QSizePolicy.Expanding,
            QtWidgets.QSizePolicy.Fixed), 1, 4)

        self.tabla = Tabla(self.columnas, horizontalHeader=horizontalHeader,
                           verticalHeader=False, stretch=False)
        self.tabla.setConnected()
        if unit:
            hHeader = []
            for unit, title in zip(self.unit, horizontalHeader):
                hHeader.append("%s, %s" % (title, unit.text()))
            self.tabla.setHorizontalHeaderLabels(hHeader)
            self.tabla.horizontalHeader().sectionClicked.connect(self.editUnit)

        if data:
            self.tabla.setData(data)
            self.tabla.addRow()
        elif t and property:
            self.tabla.setColumn(0, t)
            self.tabla.setColumn(1, property)
        gridLayout.addWidget(self.tabla, 2, 1, 1, 4)

        if DIPPR:
            self.eqDIPPR = eqDIPPR(eq)
            gridLayout.addWidget(self.eqDIPPR, 3, 1, 1, 4)
            self.eqDIPPR.eqDIPPR.valueChanged.connect(self.showTc)

            self.labelTc = QtWidgets.QLabel("Tc: ", self)
            gridLayout.addWidget(self.labelTc, 4, 1)
            self.tc = Entrada_con_unidades(Temperature, value=Tc)
            gridLayout.addWidget(self.tc, 4, 2, 1, 3)
            self.showTc(1)
Beispiel #28
0
    def __init__(self, parent=None):
        super(Definicion_Petro, self).__init__(parent)
        self.setWindowTitle(QtGui.QApplication.translate(
            "pychemqt", "Petrol component definition"))
        layout = QtGui.QGridLayout(self)
        layout.addWidget(QtGui.QLabel(QtGui.QApplication.translate(
            "pychemqt", "Name")), 1, 1)
        self.nombre = QtGui.QLineEdit()
        self.nombre.textChanged.connect(partial(self.changeParams, "name"))
        layout.addWidget(self.nombre, 1, 2, 1, 4)
        layout.addItem(QtGui.QSpacerItem(10, 10, QtGui.QSizePolicy.Fixed,
                                         QtGui.QSizePolicy.Fixed), 2, 1, 1, 2)
        layout.addWidget(QtGui.QLabel(QtGui.QApplication.translate(
            "pychemqt", "Boiling point")), 3, 1)
        self.Tb = Entrada_con_unidades(Temperature)
        self.Tb.valueChanged.connect(partial(self.changeParams, "Tb"))
        layout.addWidget(self.Tb, 3, 2)
        layout.addWidget(QtGui.QLabel(QtGui.QApplication.translate(
            "pychemqt", "Molecular Weight")), 4, 1)
        self.M = Entrada_con_unidades(float, textounidad="g/mol")
        self.M.valueChanged.connect(partial(self.changeParams, "M"))
        layout.addWidget(self.M, 4, 2)
        layout.addWidget(QtGui.QLabel(QtGui.QApplication.translate(
            "pychemqt", "Specific Gravity")), 5, 1)
        self.SG = Entrada_con_unidades(float)
        self.SG.valueChanged.connect(partial(self.changeParams, "SG"))
        layout.addWidget(self.SG, 5, 2)
        layout.addWidget(QtGui.QLabel(QtGui.QApplication.translate(
            "pychemqt", "API gravity")), 6, 1)
        self.API = Entrada_con_unidades(float)
        self.API.valueChanged.connect(partial(self.changeParams, "API"))
        layout.addWidget(self.API, 6, 2)
        layout.addWidget(QtGui.QLabel("K watson:"), 7, 1)
        self.Kw = Entrada_con_unidades(float)
        self.Kw.valueChanged.connect(partial(self.changeParams, "Kw"))
        layout.addWidget(self.Kw, 7, 2)
        layout.addWidget(QtGui.QLabel("C/H:"), 8, 1)
        self.CH = Entrada_con_unidades(float)
        self.CH.valueChanged.connect(partial(self.changeParams, "CH"))
        layout.addWidget(self.CH, 8, 2)
        layout.addWidget(QtGui.QLabel(u"ν<sub>100F</sub>:"), 9, 1)
        self.v100 = Entrada_con_unidades(Diffusivity)
        self.v100.valueChanged.connect(partial(self.changeParams, "v100"))
        layout.addWidget(self.v100, 9, 2)
        layout.addWidget(QtGui.QLabel(u"ν<sub>210F</sub>:"), 10, 1)
        self.v210 = Entrada_con_unidades(Diffusivity)
        self.v210.valueChanged.connect(partial(self.changeParams, "v210"))
        layout.addWidget(self.v210, 10, 2)
        layout.addWidget(QtGui.QLabel(QtGui.QApplication.translate(
            "pychemqt", "Refraction index")), 11, 1)
        self.n = Entrada_con_unidades(float)
        self.n.valueChanged.connect(partial(self.changeParams, "n"))
        layout.addWidget(self.n, 11, 2)
        layout.addWidget(QtGui.QLabel(QtGui.QApplication.translate(
            "pychemqt", "Huang parameter")), 12, 1)
        self.I = Entrada_con_unidades(float)
        self.I.valueChanged.connect(partial(self.changeParams, "I"))
        layout.addWidget(self.I, 12, 2)
        layout.addWidget(QtGui.QLabel("%S"), 13, 1)
        self.S = Entrada_con_unidades(float, spinbox=True, step=1.0, max=100)
        self.S.valueChanged.connect(partial(self.changeParams, "S"))
        layout.addWidget(self.S, 13, 2)
        layout.addWidget(QtGui.QLabel("%H"), 14, 1)
        self.H = Entrada_con_unidades(float, spinbox=True, step=1.0, max=100)
        self.H.valueChanged.connect(partial(self.changeParams, "H"))
        layout.addWidget(self.H, 14, 2)
        layout.addWidget(QtGui.QLabel("%N"), 15, 1)
        self.N = Entrada_con_unidades(float, spinbox=True, step=1.0, max=100)
        self.N.valueChanged.connect(partial(self.changeParams, "N"))
        layout.addWidget(self.N, 15, 2)

        layout.addWidget(QtGui.QLabel(QtGui.QApplication.translate(
            "pychemqt", "Carbons number")), 19, 1)
        self.carbonos = Entrada_con_unidades(int, width=50, spinbox=True,
                                             step=1, start=7, min=5, max=100)
        self.N.valueChanged.connect(partial(self.changeParams, "Nc"))
        layout.addWidget(self.carbonos, 19, 2)

        layout.addItem(QtGui.QSpacerItem(10, 10, QtGui.QSizePolicy.Expanding,
                                         QtGui.QSizePolicy.Expanding), 3, 3, 15, 1)
        self.checkCurva = QtGui.QCheckBox(QtGui.QApplication.translate(
            "pychemqt", "Define destillation curve"))
        layout.addWidget(self.checkCurva, 3, 4, 1, 2)
        self.tipoCurva = QtGui.QComboBox()
        self.tipoCurva.addItem("ASTM D86")
        self.tipoCurva.addItem("TBP")
        self.tipoCurva.addItem("EFV")
        self.tipoCurva.addItem("ASTM D1186")
        self.tipoCurva.addItem("ASTM D2887 (SD)")
        self.tipoCurva.setEnabled(False)
        layout.addWidget(self.tipoCurva, 4, 4, 1, 2)
        self.textoPresion = QtGui.QLabel(
            QtGui.QApplication.translate("pychemqt", "Pressure"))
        self.textoPresion.setEnabled(False)
        layout.addWidget(self.textoPresion, 5, 4)
        self.presion = Entrada_con_unidades(Pressure, value=101325.)
        self.presion.setEnabled(False)
        self.presion.valueChanged.connect(partial(self.changeParams, "P_dist"))
        layout.addWidget(self.presion, 5, 5)
        self.curvaDestilacion = Tabla(
            2, filas=1, horizontalHeader=["%dist", "Tb, "+Temperature.text()],
            verticalHeader=False, dinamica=True)
        self.curvaDestilacion.setEnabled(False)
        self.curvaDestilacion.editingFinished.connect(self.changeCurva)
        layout.addWidget(self.curvaDestilacion, 6, 4, 13, 2)
        self.checkBlend = QtGui.QCheckBox(QtGui.QApplication.translate(
            "pychemqt", "Blend if its necessary"))
        layout.addWidget(self.checkBlend, 19, 4, 1, 2)

        self.checkCurva.toggled.connect(self.tipoCurva.setEnabled)
        self.checkCurva.toggled.connect(self.presion.setEnabled)
        self.checkCurva.toggled.connect(self.textoPresion.setEnabled)
        self.checkCurva.toggled.connect(self.curvaDestilacion.setEnabled)

        layout.addItem(QtGui.QSpacerItem(20, 20, QtGui.QSizePolicy.Fixed,
                                         QtGui.QSizePolicy.Fixed), 20, 1, 1, 2)
        self.checkCrudo = QtGui.QCheckBox(QtGui.QApplication.translate(
            "pychemqt", "Use petrol fraction from list"))
        self.checkCrudo.toggled.connect(self.changeUnknown)
        layout.addWidget(self.checkCrudo, 21, 1, 1, 2)
        self.crudo = QtGui.QComboBox()
        self.crudo.setEnabled(False)
        self.crudo.addItem("")
        for i in crudo[1:]:
            self.crudo.addItem("%s (%s)  API: %s %S: %s" % (i[0], i[1], i[3], i[4]))
            # i[0]+" ("+i[1]+")"+"   API: "+str(i[3])+"  %S: "+str(i[4]))
        self.crudo.currentIndexChanged.connect(partial(
            self.changeParams, "indice"))
        layout.addWidget(self.crudo, 23, 1, 1, 5)
        layout.addWidget(QtGui.QLabel("Pseudo C+"), 24, 1)
        self.Cplus = Entrada_con_unidades(int, width=50, spinbox=True, step=1,
                                          min=6)
        self.Cplus.valueChanged.connect(partial(self.changeParams, "Cplus"))
        layout.addWidget(self.Cplus, 24, 2)
        self.checkCrudo.toggled.connect(self.crudo.setEnabled)
        self.checkCrudo.toggled.connect(self.Cplus.setEnabled)
        layout.addItem(QtGui.QSpacerItem(5, 5, QtGui.QSizePolicy.Expanding,
                                         QtGui.QSizePolicy.Expanding), 29, 1, 1, 2)

        newComponent.loadUI(self)

        self.Petroleo = Petroleo()
        self.Crudo = Crudo()
Beispiel #29
0
    def __init__(self, equipment=None, parent=None):
        """
        equipment: Initial equipment instance to model
        """
        super().__init__(Baghouse, entrada=False, parent=parent)

        # Efficiency tab
        title = [QtWidgets.QApplication.translate("pychemqt", "Diameter") +
                 ", " + Length.text("ParticleDiameter"),
                 QtWidgets.QApplication.translate("pychemqt", "Efficiency")]
        self.efic = Tabla(2, horizontalHeader=title, filas=1, stretch=False)
        self.efic.setColumnReadOnly(0, True)
        self.efic.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
        self.efic.editingFinished.connect(self.cambiarRendimientos)
        self.tabWidget.insertTab(
            1, self.efic,
            QtWidgets.QApplication.translate("pychemqt", "Efficiencies"))

        # Calculate tab
        lyt_Calc = QtWidgets.QGridLayout(self.tabCalculo)
        lyt_Calc.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Mode")), 1, 1)
        self.metodo = QtWidgets.QComboBox()
        for txt in self.Equipment.TEXT_TIPO:
            self.metodo.addItem(txt)
        self.metodo.currentIndexChanged.connect(self.tipoCalculoCambiado)
        lyt_Calc.addWidget(self.metodo, 1, 2, 1, 3)
        lyt_Calc.addItem(QtWidgets.QSpacerItem(
            20, 20, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed),
            2, 1, 1, 6)
        lyt_Calc.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "No cells")), 3, 1)
        self.num_filtros = Entrada_con_unidades(
            int, spinbox=True, step=1, min=1, width=50, resaltado=True,
            start=1)
        self.num_filtros.valueChanged.connect(
            partial(self.changeParams, "num_filtros"))
        lyt_Calc.addWidget(self.num_filtros, 3, 2)
        lyt_Calc.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Time")), 4, 1)
        self.tiempo = Entrada_con_unidades(Time, resaltado=True)
        self.tiempo.valueChanged.connect(partial(self.changeParams, "tiempo"))
        lyt_Calc.addWidget(self.tiempo, 4, 2)
        lyt_Calc.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Pressure drop")), 5, 1)
        self.deltaP = Entrada_con_unidades(Pressure, retornar=False)
        self.deltaP.setReadOnly(True)
        self.deltaP.valueChanged.connect(partial(self.changeParams, "deltaP"))
        lyt_Calc.addWidget(self.deltaP, 5, 2)
        lyt_Calc.addItem(QtWidgets.QSpacerItem(
            20, 20, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed),
            6, 1, 1, 6)
        lyt_Calc.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Bags per cell")), 7, 1)
        self.membranasFiltro = Entrada_con_unidades(int, spinbox=True, step=1,
                                                    min=1)
        self.membranasFiltro.valueChanged.connect(
            partial(self.changeParams, "membranasFiltro"))
        lyt_Calc.addWidget(self.membranasFiltro, 7, 2)
        lyt_Calc.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Bag diameter")), 8, 1)
        self.diametroMembrana = Entrada_con_unidades(Length)
        self.diametroMembrana.valueChanged.connect(
            partial(self.changeParams, "diametroMembrana"))
        lyt_Calc.addWidget(self.diametroMembrana, 8, 2)
        lyt_Calc.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Area per bag")), 9, 1)
        self.areaMembrana = Entrada_con_unidades(Area)
        self.areaMembrana.valueChanged.connect(
            partial(self.changeParams, "areaMembrana"))
        lyt_Calc.addWidget(self.areaMembrana, 9, 2)
        lyt_Calc.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Cloth resistence")), 7, 4)
        self.resistenciaFiltro = Entrada_con_unidades(float)
        self.resistenciaFiltro.valueChanged.connect(
            partial(self.changeParams, "resistenciaFiltro"))
        lyt_Calc.addWidget(self.resistenciaFiltro, 7, 5)
        lyt_Calc.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Cake resistence")), 8, 4)
        self.resistenciaTorta = Entrada_con_unidades(float)
        self.resistenciaTorta.valueChanged.connect(
            partial(self.changeParams, "resistenciaTorta"))
        lyt_Calc.addWidget(self.resistenciaTorta, 8, 5)
        lyt_Calc.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Cells cleaned")), 9, 4)
        self.limpieza = Entrada_con_unidades(int, spinbox=True, step=1, min=0)
        self.limpieza.valueChanged.connect(
            partial(self.changeParams, "limpieza"))
        lyt_Calc.addWidget(self.limpieza, 9, 5)
        lyt_Calc.addItem(QtWidgets.QSpacerItem(
            20, 20, QtWidgets.QSizePolicy.Expanding,
            QtWidgets.QSizePolicy.Expanding), 10, 1, 1, 6)

        groupbox = QtWidgets.QGroupBox(
            QtWidgets.QApplication.translate("pychemqt", "Results"))
        lyt_Calc.addWidget(groupbox, 11, 1, 1, 5)
        lyt = QtWidgets.QGridLayout(groupbox)

        lyt.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "No cells")), 1, 1)
        self.num_filtrosCalc = Entrada_con_unidades(int, readOnly=True)
        lyt.addWidget(self.num_filtrosCalc, 1, 2)
        lyt.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Time")), 2, 1)
        self.tiempoCalc = Entrada_con_unidades(Time, readOnly=True)
        lyt.addWidget(self.tiempoCalc, 2, 2)
        lyt.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Pressure drop")), 3, 1)
        self.deltaPCalc = Entrada_con_unidades(Pressure, readOnly=True)
        lyt.addWidget(self.deltaPCalc, 3, 2)

        lyt.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Gas velocity")), 1, 4)
        self.Vgas = Entrada_con_unidades(Speed, retornar=False, readOnly=True)
        lyt.addWidget(self.Vgas, 1, 5)
        lyt.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Efficiency")), 2, 4)
        self.rendimiento = Entrada_con_unidades(float, readOnly=True)
        lyt.addWidget(self.rendimiento, 2, 5)
        lyt.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Area")), 3, 4)
        self.floorArea = Entrada_con_unidades(Area, readOnly=True)
        lyt.addWidget(self.floorArea, 3, 5)
        lyt_Calc.addItem(QtWidgets.QSpacerItem(
            20, 20, QtWidgets.QSizePolicy.Expanding,
            QtWidgets.QSizePolicy.Expanding), 12, 1, 1, 6)

        # Output tab
        self.addSalida(
            QtWidgets.QApplication.translate("pychemqt", "Filtered gas"))
        self.addSalida(
            QtWidgets.QApplication.translate("pychemqt", "Collected solids"))

        if equipment:
            self.setEquipment(equipment)
Beispiel #30
0
class Binary_distillation(QtWidgets.QDialog):
    title = QtWidgets.QApplication.translate("pychemqt", "x-y Distillation")

    def __init__(self,
                 indices=None,
                 nombres=None,
                 x=None,
                 y=None,
                 parent=None):
        super(Binary_distillation, self).__init__(parent)
        self.setWindowTitle(self.title)
        layout = QtWidgets.QGridLayout(self)
        layout.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("equipment", "Component 1:")),
            1, 1)
        self.Comp1 = QtWidgets.QComboBox()
        layout.addWidget(self.Comp1, 1, 2)
        layout.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("equipment", "Component 2:")),
            1, 4)
        self.Comp2 = QtWidgets.QComboBox()
        layout.addWidget(self.Comp2, 1, 5)

        self.indices = indices
        self.nombres = nombres
        for i, nombre in enumerate(nombres):
            self.Comp1.addItem("%i - %s" % (i + 1, nombre))
            self.Comp2.addItem("%i - %s" % (i + 1, nombre))
        self.Comp2.setCurrentIndex(1)
        tab = QtWidgets.QTabWidget()
        layout.addWidget(tab, 2, 1, 1, 5)
        self.plot = mpl()
        tab.addTab(self.plot,
                   QtWidgets.QApplication.translate("equipment", "Plot"))
        self.tabla = Tabla(2,
                           horizontalHeader=["x", "y"],
                           stretch=False,
                           readOnly=True)
        tab.addTab(self.tabla,
                   QtWidgets.QApplication.translate("equipment", "Table"))

        self.Comp1.currentIndexChanged.connect(self.calculo)
        self.Comp2.currentIndexChanged.connect(self.calculo)

        if x and y:
            self.rellenar(x, y)
        else:
            self.calculo()

    def rellenar(self, x, y):
        self.x = x
        self.y = y
        self.plot.axes2D.clear()
        self.plot.data([0, 1], [0, 1], x, y, 'ro')

        self.tabla.setData(transpose([x, y]))

    def calculo(self):
        ind1 = self.Comp1.currentIndex()
        ind2 = self.Comp2.currentIndex()
        if ind1 != ind2:
            zi = arange(0.025, 1., 0.025)
            id1 = self.indices[ind1]
            id2 = self.indices[ind2]
            x = [0]
            y = [0]
            for z in zi:
                try:
                    fraccion = [0.] * len(self.indices)
                    fraccion[ind1] = z
                    fraccion[ind2] = 1 - z
                    mez = Mezcla(tipo=3,
                                 fraccionMolar=fraccion,
                                 caudalMasico=1.)
                    tb = mez.componente[0].Tb
                    corr = Corriente(T=tb, P=101325., mezcla=mez)
                    T = corr.eos._Dew_T()
                    corr = Corriente(T=T, P=101325., mezcla=mez)
                    while corr.Liquido.fraccion[0] == corr.Gas.fraccion[
                            0] and corr.T < corr.mezcla.componente[1].Tb:
                        corr = Corriente(T=corr.T - 0.1, P=101325., mezcla=mez)
                    x.append(corr.Liquido.fraccion[0])
                    y.append(corr.Gas.fraccion[0])
                except:
                    pass
            x.append(1)
            y.append(1)
            self.rellenar(x, y)

    def writeToStream(self, stream):
        stream.writeInt32(self.widget().Comp1.currentIndex())
        stream.writeInt32(self.widget().Comp2.currentIndex())
        stream.writeInt32(len(self.widget().x))
        for i in self.widget().x:
            stream.writeFloat(i)
        for i in self.widget().y:
            stream.writeFloat(i)

    @classmethod
    def readToStream(cls, stream):
        id1 = stream.readInt32()
        id2 = stream.readInt32()
        len = stream.readInt32()
        x = []
        for i in range(len):
            x.append(stream.readFloat())
        y = []
        for i in range(len):
            y.append(stream.readFloat())
        self.plot(0, x, y)
Beispiel #31
0
class Entrada_Datos(QtWidgets.QDialog):
    """Table data input dialog"""
    def __init__(self,
                 data=None,
                 t=[],
                 property=[],
                 horizontalHeader=[],
                 title="",
                 help=False,
                 helpFile="",
                 DIPPR=False,
                 tc=0,
                 tcValue=None,
                 eq=1,
                 parent=None):
        """
        title: window title
        data: mrray with original data
        t: values for x column, generally temperature
        property: values for 2...n columns
        horizontalHeader: List with column title
        help: boolean to show help button
        helpFile: Path for help file, file or url
        DIPPR: boolean to show DIPPR widget
        tc: boolean to show critical temperature (same DIPPR eq need it)
        tcValue: value for critical temperature
        eq: Value for DIPPR equation
        """
        super(Entrada_Datos, self).__init__(parent)
        self.setWindowTitle(title)
        self.columnas = len(horizontalHeader)
        self.horizontalHeader = horizontalHeader
        self.title = title
        self.helpFile = helpFile
        gridLayout = QtWidgets.QGridLayout(self)
        self.botonAbrir = QtWidgets.QPushButton(
            QtGui.QIcon(
                QtGui.QPixmap(os.environ["pychemqt"] +
                              "/images/button/fileOpen.png")),
            QtWidgets.QApplication.translate("pychemqt", "Open"))
        self.botonAbrir.clicked.connect(self.Abrir)
        gridLayout.addWidget(self.botonAbrir, 1, 1)
        self.botonGuardar = QtWidgets.QPushButton(
            QtGui.QIcon(
                QtGui.QPixmap(os.environ["pychemqt"] +
                              "/images/button/fileSave.png")),
            QtWidgets.QApplication.translate("pychemqt", "Save"))
        self.botonGuardar.clicked.connect(self.Guardar)
        gridLayout.addWidget(self.botonGuardar, 1, 2)
        self.botonDelete = QtWidgets.QPushButton(
            QtGui.QIcon(
                QtGui.QPixmap(os.environ["pychemqt"] +
                              "/images/button/clear.png")),
            QtWidgets.QApplication.translate("pychemqt", "Clear"))
        self.botonDelete.clicked.connect(self.Borrar)
        gridLayout.addWidget(self.botonDelete, 1, 3)
        gridLayout.addItem(
            QtWidgets.QSpacerItem(0, 0, QtWidgets.QSizePolicy.Expanding,
                                  QtWidgets.QSizePolicy.Expanding), 1, 4)

        self.tabla = Tabla(self.columnas,
                           horizontalHeader=horizontalHeader,
                           verticalHeader=False,
                           stretch=False)
        self.tabla.setConnected()
        if data:
            self.tabla.setData(data)
            self.tabla.addRow()
        elif t and property:
            self.tabla.setColumn(0, t)
            self.tabla.setColumn(1, property)
        gridLayout.addWidget(self.tabla, 2, 1, 1, 4)

        if DIPPR:
            self.eqDIPPR = eqDIPPR(eq)
            gridLayout.addWidget(self.eqDIPPR, 3, 1, 1, 4)
            self.eqDIPPR.eqDIPPR.valueChanged.connect(self.showTc)

        if tc:
            lyt = QtWidgets.QHBoxLayout()
            self.labelTc = QtWidgets.QLabel("Tc: ", self)
            lyt.addWidget(self.labelTc)
            self.tc = Entrada_con_unidades(Temperature, value=tcValue)
            lyt.addWidget(self.tc)
            lyt.addItem(
                QtWidgets.QSpacerItem(0, 0, QtWidgets.QSizePolicy.Expanding,
                                      QtWidgets.QSizePolicy.Expanding))
            gridLayout.addItem(lyt, 4, 1, 1, 4)
            self.showTc(1)

        if help:
            botones = QtWidgets.QDialogButtonBox.Help | \
                QtWidgets.QDialogButtonBox.Cancel | \
                QtWidgets.QDialogButtonBox.Ok
        else:
            botones = QtWidgets.QDialogButtonBox.Cancel | \
                QtWidgets.QDialogButtonBox.Ok
        self.boton = QtWidgets.QDialogButtonBox(botones)
        self.boton.accepted.connect(self.accept)
        self.boton.rejected.connect(self.reject)
        self.boton.helpRequested.connect(self.ayuda)
        gridLayout.addWidget(self.boton, 5, 1, 1, 4)

    def showTc(self, value):
        self.labelTc.setVisible(value in (7, 9))
        self.tc.setVisible(value in (7, 9))

    def Abrir(self):
        fname = QtWidgets.QFileDialog.getOpenFileName(
            self, QtWidgets.QApplication.translate("pychemqt",
                                                   "Open text file"), "./")
        if fname:
            data = loadtxt(fname)
            self.tabla.setData(data)
            self.tabla.addRow()

    def Guardar(self):
        fname = QtWidgets.QFileDialog.getSaveFileName(
            self,
            QtWidgets.QApplication.translate("pychemqt", "Save data to file"),
            "./")
        if fname:
            with open(fname, 'w') as file:
                file.write("#" + self.title + "\n")
                file.write("#")
                try:
                    for i in self.horizontalHeader:
                        file.write(i + "\t")
                except UnicodeEncodeError:
                    pass
                file.write("\n")
                data = self.data
                for fila in range(len(data)):
                    for columna in range(self.tabla.columnCount()):
                        file.write(str(data[fila][columna]) + "\t")
                    file.write("\n")

    def Borrar(self):
        """Clear table"""
        self.tabla.setRowCount(1)
        self.tabla.clearContents()

    def ayuda(self):
        """Show help file"""
        url = QtCore.QUrl(self.helpFile)
        QtGui.QDesktopServices.openUrl(url)

    @property
    def data(self):
        return self.tabla.getData()
Beispiel #32
0
    def __init__(self, elemento, parent=None):
        super(ElementDialog, self).__init__(parent)
        self.setWindowTitle(QtWidgets.QApplication.translate(
            "pychemqt", "Properties of "+elemento.name))
        lyt = QtWidgets.QVBoxLayout(self)
        tabWidget = QtWidgets.QTabWidget()
        lyt.addWidget(tabWidget)
        buttonbox = QtWidgets.QDialogButtonBox(QtWidgets.QDialogButtonBox.Close)
        buttonbox.rejected.connect(self.reject)
        lyt.addWidget(buttonbox)

        tabGeneral = QtWidgets.QWidget()
        layoutGeneral = QtWidgets.QGridLayout(tabGeneral)
        layoutGeneral.addWidget(QtWidgets.QLabel(
            QtWidgets.QApplication.translate("pychemqt", "Name:")), 1, 1)
        layoutGeneral.addWidget(QtWidgets.QLabel(elemento.name), 1, 2)
        layoutGeneral.addWidget(QtWidgets.QLabel(
            QtWidgets.QApplication.translate("pychemqt", "Serie:")), 2, 1)
        layoutGeneral.addWidget(QtWidgets.QLabel(elemento.serie), 2, 2)
        layoutGeneral.addWidget(QtWidgets.QLabel(
            QtWidgets.QApplication.translate("pychemqt", "Group")), 3, 1)
        layoutGeneral.addWidget(QtWidgets.QLabel(str(elemento.group)), 3, 2)
        layoutGeneral.addWidget(QtWidgets.QLabel(
            QtWidgets.QApplication.translate("pychemqt", "Period")), 4, 1)
        layoutGeneral.addWidget(QtWidgets.QLabel(str(elemento.period)), 4, 2)
        layoutGeneral.addWidget(QtWidgets.QLabel(
            QtWidgets.QApplication.translate("pychemqt", "Block")), 5, 1)
        layoutGeneral.addWidget(QtWidgets.QLabel(elemento.block), 5, 2)

        layoutGeneral.addItem(QtWidgets.QSpacerItem(
            20, 20, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed),
            6, 1)
        label = QtWidgets.QLabel(
            QtWidgets.QApplication.translate("pychemqt", "History"))
        font = QtGui.QFont()
        font.setWeight(75)
        font.setBold(True)
        label.setFont(font)
        layoutGeneral.addWidget(label, 7, 1, 1, 3)
        label_8 = QtWidgets.QLabel(
            QtWidgets.QApplication.translate("pychemqt", "Discovery") + ": " +
            elemento.country + "(" + elemento.country + ")" +os.linesep +
            QtWidgets.QApplication.translate("pychemqt", "Discovered by ") +
            elemento.discover + os.linesep +
            QtWidgets.QApplication.translate("pychemqt", "Etymology") + ": " +
            elemento.etymology)
        label_8.setMargin(5)
        label_8.setWordWrap(True)
        layoutGeneral.addWidget(label_8, 8, 1, 1, 3)
        self.botoncito = QtWidgets.QLabel()
        self.botoncito.setStyleSheet(
            "background-color: %s;" % elemento.color)
        self.botoncito.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.botoncito.setFixedSize(60, 60)
        layoutGeneral.addWidget(self.botoncito, 1, 5, 3, 1)
        label = QtWidgets.QLabel()
        label.setText(str(elemento.id))
        label.setAlignment(QtCore.Qt.AlignCenter | QtCore.Qt.AlignBottom)
        layoutGeneral.addWidget(label, 1, 5)
        label = QtWidgets.QLabel(elemento.symbol)
        font.setPointSize(12)
        label.setFont(font)
        label.setAlignment(QtCore.Qt.AlignCenter | QtCore.Qt.AlignBottom)
        layoutGeneral.addWidget(label, 2, 5)
        layoutGeneral.addItem(QtWidgets.QSpacerItem(
            20, 20, QtWidgets.QSizePolicy.Expanding,
            QtWidgets.QSizePolicy.Expanding), 9, 3)
        tabWidget.addTab(tabGeneral, QtWidgets.QApplication.translate(
            "pychemqt", "General"))

        tabFisica = QtWidgets.QWidget()
        lytphy = QtWidgets.QGridLayout(tabFisica)
        lytphy.addWidget(QtWidgets.QLabel(
            QtWidgets.QApplication.translate("pychemqt", "Fase:")), 1, 1)
        lytphy.addWidget(QtWidgets.QLabel(elemento.phase + " a 0ºC"),
                               1, 2, 1, 1)
        if elemento.density_Solid:
            lytphy.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
                "pychemqt", "Solid Density:")), 2, 1)
            lytphy.addWidget(self.drawData(
                unidades.Density, elemento.density_Solid, "gcc", txt=" @ 20ºC"),
                2, 2)
        if elemento.density_Liq:
            lytphy.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
                "pychemqt", "Liquid Density:")), 3, 1)
            lytphy.addWidget(self.drawData(
                unidades.Density, elemento.density_Liq, "gcc", txt=" " +
                QtWidgets.QApplication.translate("pychemqt", "at melting point")),
                3, 2)
        if elemento.density_Gas:
            lytphy.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
                "pychemqt", "Gas Density:")), 4, 1)
            lytphy.addWidget(self.drawData(
                unidades.Density, elemento.density_Gas, "gl", txt=" @ 0ºC"),
                4, 2)
        lytphy.addWidget(QtWidgets.QLabel(
            QtWidgets.QApplication.translate("pychemqt", "Appearance:")), 5, 1)
        label = QtWidgets.QLabel(elemento.appearance)
        label.setWordWrap(True)
        lytphy.addWidget(label, 5, 2)
        lytphy.addItem(QtWidgets.QSpacerItem(
            20, 20, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed),
            6, 1, 1, 3)
        label = QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Thermal properties"))
        label.setFont(font)
        lytphy.addWidget(label, 7, 1)
        lytphy.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Melting point:")), 8, 1)
        self.punto_fusion = self.drawData(
            unidades.Temperature, elemento.Tf)
        lytphy.addWidget(self.punto_fusion, 8, 2)
        lytphy.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Boiling point:")), 9, 1)
        self.punto_ebullicion = self.drawData(
            unidades.Temperature, elemento.Tb)
        lytphy.addWidget(self.punto_ebullicion, 9, 2)
        lytphy.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Heat of fusion:")), 10, 1)
        self.calor_fusion = self.drawData(
            unidades.MolarEnthalpy, elemento.Heat_f, "kJkmol")
        lytphy.addWidget(self.calor_fusion, 10, 2)
        lytphy.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Heat of vaporization:")), 11, 1)
        self.calor_vaporizacion = self.drawData(
            unidades.MolarEnthalpy, elemento.Heat_b, "kJkmol")
        lytphy.addWidget(self.calor_vaporizacion, 11, 2)
        lytphy.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Specific heat capacity:")), 12, 1)
        self.capacidad_calorifica = self.drawData(
            unidades.SpecificHeat, elemento.Cp, "JgK")
        lytphy.addWidget(self.capacidad_calorifica, 12, 2)
        lytphy.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Thermal conductivity:")), 13, 1)
        self.conductividad_termica = self.drawData(
            unidades.ThermalConductivity, elemento.k,
            txt=" @ 300K")
        lytphy.addWidget(self.conductividad_termica, 13, 2)
        lytphy.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Debye Temperature:")), 14, 1)
        self.temperatura_debye = self.drawData(
            unidades.Temperature, elemento.T_debye)
        lytphy.addWidget(self.temperatura_debye, 14, 2)
        lytphy.addItem(QtWidgets.QSpacerItem(
            20, 20, QtWidgets.QSizePolicy.Expanding,
            QtWidgets.QSizePolicy.Expanding), 15, 1, 1, 3)
        tabWidget.addTab(tabFisica, QtWidgets.QApplication.translate(
            "pychemqt", "Physical properties"))

        tabAtom = QtWidgets.QWidget()
        lyt_A = QtWidgets.QGridLayout(tabAtom)
        lyt_A.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Atomic mass:")), 1, 1)
        if elemento.atomic_mass:
            self.masa_atomica = QtWidgets.QLabel(
                str(elemento.atomic_mass) +" g/mol")
        else:
            self.masa_atomica = QtWidgets.QLabel(elemento.atomic_mass)
        lyt_A.addWidget(self.masa_atomica, 1, 2)
        lyt_A.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Atomic Volume:")), 2, 1)
        self.volumen_atomico = self.drawData(unidades.MolarVolume,
                                             elemento.atomic_volume)
        lyt_A.addWidget(self.volumen_atomico, 2, 2)
        lyt_A.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Atomic radius:")), 3, 1)
        if elemento.atomic_radius:
            self.radio_atomico = QtWidgets.QLabel(
                str(elemento.atomic_radius) + " pm")
        else:
            self.radio_atomico = QtWidgets.QLabel(elemento.atomic_radius)
        lyt_A.addWidget(self.radio_atomico, 3, 2)
        lyt_A.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Covalent radius:")), 4, 1)
        if elemento.covalent_radius:
            self.radio_covalente = QtWidgets.QLabel(
                str(elemento.covalent_radius) + " pm")
        else:
            self.radio_covalente = QtWidgets.QLabel(
                str(elemento.covalent_radius))
        lyt_A.addWidget(self.radio_covalente, 4, 2)
        lyt_A.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Van der Waals radius:")), 5, 1)
        if elemento.vanderWaals_radius:
            self.radio_waals = QtWidgets.QLabel(
                str(elemento.vanderWaals_radius) + " pm")
        else:
            self.radio_waals = QtWidgets.QLabel(
                str(elemento.vanderWaals_radius))
        lyt_A.addWidget(self.radio_waals, 5, 2)
        lyt_A.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Ionic radii:")), 6, 1)
        if elemento.ionic_radii:
            self.radio_ionico = QtWidgets.QLabel(
                str(elemento.ionic_radii) + " pm")
        else:
            self.radio_ionico = QtWidgets.QLabel(str(elemento.ionic_radii))
        lyt_A.addWidget(self.radio_ionico, 6, 2)
        lyt_A.addItem(QtWidgets.QSpacerItem(
            20, 20, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed),
            7, 1, 1, 3)
        label = QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Electronic properties"))
        label.setFont(font)
        lyt_A.addWidget(label, 8, 1)
        lyt_A.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Electronic configuration:")), 9, 1)
        lyt_A.addWidget(QtWidgets.QLabel(
            elemento.electron_configuration), 9, 2)
        lyt_A.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Oxidation states:")), 10, 1)
        lyt_A.addWidget(QtWidgets.QLabel(
            elemento.oxidation), 10, 2)
        lyt_A.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Electronegativity:")), 11, 1)
        lyt_A.addWidget(QtWidgets.QLabel(
            str(elemento.electronegativity)), 11, 2)
        lyt_A.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Electron affinity:")), 12, 1)
        self.afinidad_electronica = self.drawData(
            unidades.MolarEnthalpy, elemento.electron_affinity, "kJkmol")
        lyt_A.addWidget(self.afinidad_electronica, 12, 2)
        lyt_A.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "1st ionization energy:")), 13, 1)
        self.energia_ionizacion = self.drawData(
            unidades.MolarEnthalpy, elemento.first_ionization, "kJkmol")
        lyt_A.addWidget(self.energia_ionizacion, 13, 2)
        lyt_A.addItem(QtWidgets.QSpacerItem(
            20, 20, QtWidgets.QSizePolicy.Expanding,
            QtWidgets.QSizePolicy.Expanding), 14, 1, 1, 3)
        tabWidget.addTab(tabAtom, QtWidgets.QApplication.translate(
            "pychemqt", "Atomic properties"))

        tabCristal = QtWidgets.QWidget()
        lyt_C = QtWidgets.QGridLayout(tabCristal)
        lyt_C.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Lattice type:")), 1, 1)
        lyt_C.addWidget(QtWidgets.QLabel(
            elemento.lattice_type), 1, 2)
        lyt_C.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Space group:")), 2, 1)
        lyt_C.addWidget(QtWidgets.QLabel(
            elemento.space_group), 2, 2)
        lyt_C.addWidget(QtWidgets.QLabel(
            QtWidgets.QApplication.translate(
            "pychemqt", "Lattice edge lengths:")), 3, 1)
        self.lados = QtWidgets.QLabel()
        if elemento.lattice_edges:
            self.lados.setText("%spm, %spm, %spm" % (
                elemento.lattice_edges[0], elemento.lattice_edges[1],
                elemento.lattice_edges[2]))
        else:
            self.lados.setText(elemento.lattice_edges)
        lyt_C.addWidget(self.lados, 3, 2)
        lyt_C.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Lattice angles:")), 4, 1)
        self.angulos = QtWidgets.QLabel()
        if elemento.lattice_angles:
            self.angulos.setText("%sº, %sº, %sº" % (
                elemento.lattice_angles[0], elemento.lattice_angles[1],
                elemento.lattice_angles[2]))
        else:
            self.angulos.setText(elemento.lattice_angles)
        lyt_C.addWidget(self.angulos, 4, 2)
        lyt_C.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Lattice unit volume:")), 5, 1)
        self.volumen_celda = QtWidgets.QLabel()
        if elemento.lattice_angles:
            self.volumen_celda.setText("%0.5f mm<sup>3</sup>"
                                       % elemento.lattice_volume)
        else:
            self.volumen_celda.setText(elemento.lattice_volume)
        lyt_C.addWidget(self.volumen_celda, 5, 2)
        lyt_C.addItem(QtWidgets.QSpacerItem(
            20, 20, QtWidgets.QSizePolicy.Expanding,
            QtWidgets.QSizePolicy.Expanding), 6, 1, 1, 3)

        label = QtWidgets.QLabel(QtWidgets.QApplication.translate(
            "pychemqt", "Isotopes"))
        label.setFont(font)
        lyt_C.addWidget(label, 8, 1)
        title = [QtWidgets.QApplication.translate("pychemqt", "Mass Number"),
                 QtWidgets.QApplication.translate("pychemqt", "Mass"),
                 QtWidgets.QApplication.translate("pychemqt", "Abundance")]
        self.isotopes = Tabla(3, horizontalHeader=title, readOnly=True,
                              stretch=True, verticalHeader=False)
        self.isotopes.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
        self.isotopes.setColumn(0, [iso[0] for iso in elemento.isotopes], decimales=0)
        self.isotopes.setColumn(1, [iso[1] for iso in elemento.isotopes], format=1, decimales=10)
        self.isotopes.setColumn(2, [iso[2] for iso in elemento.isotopes], format=1, decimales=10)
        lyt_C.addWidget(self.isotopes, 9, 1, 1, 2)
        lyt_C.addItem(QtWidgets.QSpacerItem(
            20, 20, QtWidgets.QSizePolicy.Expanding,
            QtWidgets.QSizePolicy.Expanding), 10, 1, 1, 3)

        tabWidget.addTab(tabCristal,
            QtWidgets.QApplication.translate("pychemqt", "Crystallographic"))