Ejemplo n.º 1
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)
Ejemplo n.º 2
0
    def __init__(self, config=None, parent=None):
        super(ConfApplications, self).__init__(parent)
        layout = QtWidgets.QGridLayout(self)
        l = QtWidgets.QApplication.translate("pychemqt", "External Calculator")
        msg = QtWidgets.QApplication.translate(
            "pychemqt", "Select External Calculator Application")
        self.calculadora = PathConfig(l + ":", msg=msg, patron="exe")
        layout.addWidget(self.calculadora, 1, 1)
        l = QtWidgets.QApplication.translate("pychemqt", "Text viewer")
        msg = QtWidgets.QApplication.translate(
            "pychemqt", "Select External Text Viewer Application")
        self.textViewer = PathConfig(l + ":", msg=msg, patron="exe")
        layout.addWidget(self.textViewer, 2, 1)

        terminal = QtWidgets.QGroupBox()
        layout.addWidget(terminal, 3, 1)
        layoutTerminal = QtWidgets.QGridLayout(terminal)
        msg = QtWidgets.QApplication.translate(
            "pychemqt", "Select External shell")
        self.terminal = PathConfig("", msg=msg, patron="exe")
        layoutTerminal.addWidget(self.terminal, 1, 1, 1, 3)
        layoutTerminal.addWidget(QtWidgets.QLabel(
            QtWidgets.QApplication.translate("pychemqt", "Foreground color:")),
            2, 1)
        self.ForegroundColor = ColorSelector()
        layoutTerminal.addWidget(self.ForegroundColor, 2, 2, 1, 2)
        layoutTerminal.addWidget(QtWidgets.QLabel(
            QtWidgets.QApplication.translate("pychemqt", "Background color:")),
            3, 1)
        self.BackgroundColor = ColorSelector()
        layoutTerminal.addWidget(self.BackgroundColor, 3, 2, 1, 2)
        self.ipython = QtWidgets.QCheckBox(QtWidgets.QApplication.translate(
            "pychemqt", "Use ipython if its available"))
        layoutTerminal.addWidget(self.ipython, 4, 1, 1, 3)
        self.maximized = QtWidgets.QCheckBox(
            QtWidgets.QApplication.translate("pychemqt", "Show maximized"))
        layoutTerminal.addWidget(self.maximized, 5, 1, 1, 3)
        layout.addItem(QtWidgets.QSpacerItem(
            10, 0, QtWidgets.QSizePolicy.Expanding,
            QtWidgets.QSizePolicy.Expanding), 10, 1)

        terminalTitle = QtWidgets.QApplication.translate("pychemqt", "Shell")
        if sys.platform == "win32":
            terminal.setEnabled(False)
            terminalTitle += " (" + QtWidgets.QApplication.translate(
                "pychemqt", "Only Available on linux") + ")"
        terminal.setTitle(terminalTitle)

        if config.has_section("Applications"):
            self.calculadora.setText(config.get("Applications", 'Calculator'))
            self.textViewer.setText(config.get("Applications", 'TextViewer'))
            self.terminal.setText(config.get("Applications", 'Shell'))
            self.ipython.setChecked(
                config.getboolean("Applications", 'ipython'))
            self.maximized.setChecked(
                config.getboolean("Applications", 'maximized'))
            self.ForegroundColor.setColor(
                config.get("Applications", 'foregroundColor'))
            self.BackgroundColor.setColor(
                config.get("Applications", 'backgroundColor'))

        self.ipython.setEnabled(bool(which("ipython3")))

        # TODO: Habilitar cuando añada soporte para otras terminales
        self.terminal.setEnabled(False)
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
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)