当前位置: 首页>>代码示例>>Python>>正文


Python Tabla.setRowCount方法代码示例

本文整理汇总了Python中UI.widgets.Tabla.setRowCount方法的典型用法代码示例。如果您正苦于以下问题:Python Tabla.setRowCount方法的具体用法?Python Tabla.setRowCount怎么用?Python Tabla.setRowCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UI.widgets.Tabla的用法示例。


在下文中一共展示了Tabla.setRowCount方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: widgetReacciones

# 需要导入模块: from UI.widgets import Tabla [as 别名]
# 或者: from UI.widgets.Tabla import setRowCount [as 别名]

#.........这里部分代码省略.........
        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()
开发者ID:bkt92,项目名称:pychemqt,代码行数:104,代码来源:UI_reactor.py

示例2: UI_equipment

# 需要导入模块: from UI.widgets import Tabla [as 别名]
# 或者: from UI.widgets.Tabla import setRowCount [as 别名]
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"])
开发者ID:ChEsolve,项目名称:pychemqt,代码行数:90,代码来源:UI_divider.py

示例3: InputTableWidget

# 需要导入模块: from UI.widgets import Tabla [as 别名]
# 或者: from UI.widgets.Tabla import setRowCount [as 别名]

#.........这里部分代码省略.........
    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()
开发者ID:bkt92,项目名称:pychemqt,代码行数:104,代码来源:inputTable.py


注:本文中的UI.widgets.Tabla.setRowCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。