def addEntrada(self, title, key, **kw): widget = Ui_corriente(**kw) widget.Changed.connect(partial(self.changeParams, key)) self.Entrada.addTab(widget, title)
def addSalida(self, title, **kw): widget = Ui_corriente(readOnly=True, **kw) self.Salida.addTab(widget, title)
def __init__(self, equipment, entrada=True, salida=True, calculo=True, parent=None): """ equipment: name of equipment to model entrada: boolean to create or not the input tab salida: boolean to create or not the input tab - True para equipos con varias entradas/salidas, create de tab, the child must define the UI_corriente - False para equipos con una, create UI_corriente - None: Not create nothing calculo: boolean to create or not the calcule tab """ super(UI_equip, self).__init__(parent) self.setWindowTitle(equipment.title) icono = os.path.join(IMAGE_PATH, "equipment", "%s.png" % equipment.__name__.lower()) self.setWindowIcon(QtGui.QIcon(QtGui.QPixmap(icono))) self.evaluate = Evaluate() self.evaluate.finished.connect(self.rellenar) layout = QtWidgets.QGridLayout(self) self.tabWidget = QtWidgets.QTabWidget() layout.addWidget(self.tabWidget, 0, 0, 1, 3) self.status = Status() layout.addWidget(self.status, 1, 0, 1, 1) self.checkIgnorar = QtWidgets.QCheckBox() self.checkIgnorar.setText( QtWidgets.QApplication.translate("pychemqt", "Ignore")) self.checkIgnorar.toggled.connect(self.ignorar) layout.addWidget(self.checkIgnorar, 1, 1, 1, 1) self.buttonBox = QtWidgets.QDialogButtonBox( QtWidgets.QDialogButtonBox.Cancel | QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Help) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) self.buttonBox.helpRequested.connect(self.ayuda) layout.addWidget(self.buttonBox, 1, 2, 1, 1) if not equipment.help: button = self.buttonBox.button(QtWidgets.QDialogButtonBox.Help) button.setVisible(False) # Input tab if entrada: self.Entrada = QtWidgets.QTabWidget() self.tabWidget.addTab( self.Entrada, QtGui.QIcon(os.path.join(IMAGE_PATH, "equipment", "in.svg")), QtWidgets.QApplication.translate("pychemqt", "Input")) elif entrada is None: pass else: self.Entrada = Ui_corriente() self.Entrada.Changed.connect(partial(self.changeParams, "entrada")) self.tabWidget.addTab( self.Entrada, QtGui.QIcon(os.path.join(IMAGE_PATH, "equipment", "in.svg")), QtWidgets.QApplication.translate("pychemqt", "Input")) # Calcule tab if calculo: self.tabCalculo = QtWidgets.QWidget() self.tabWidget.addTab( self.tabCalculo, QtGui.QIcon(os.path.join( IMAGE_PATH, "button", "calculator.png")), QtWidgets.QApplication.translate("pychemqt", "Calculation")) # Cost tab if equipment.indiceCostos is not None: self.tabCostos = QtWidgets.QWidget() self.tabWidget.addTab( self.tabCostos, QtGui.QIcon(os.path.join( IMAGE_PATH, "button", "currency.png")), QtWidgets.QApplication.translate("pychemqt", "Cost")) # Output tab if salida: self.Salida = QtWidgets.QTabWidget() self.tabWidget.addTab( self.Salida, QtGui.QIcon(os.path.join(IMAGE_PATH, "equipment", "out.svg")), QtWidgets.QApplication.translate("pychemqt", "Output")) elif salida is None: pass else: self.Salida = Ui_corriente(readOnly=True) self.tabWidget.addTab( self.Salida, QtGui.QIcon(os.path.join(IMAGE_PATH, "equipment", "out.svg")), QtWidgets.QApplication.translate("pychemqt", "Output")) # Notes tab self.tabNotas = TextEditor() self.tabWidget.addTab( self.tabNotas, QtGui.QIcon(os.path.join(IMAGE_PATH, "button", "editor.png")), QtWidgets.QApplication.translate("pychemqt", "Notes")) self.tabNotas.notas.textChanged.connect(self.cambiar_notas)
class UI_equip(QtWidgets.QDialog): """UI general for equipments, each child class must define specifics""" def __init__(self, equipment, entrada=True, salida=True, calculo=True, parent=None): """ equipment: name of equipment to model entrada: boolean to create or not the input tab salida: boolean to create or not the input tab - True para equipos con varias entradas/salidas, create de tab, the child must define the UI_corriente - False para equipos con una, create UI_corriente - None: Not create nothing calculo: boolean to create or not the calcule tab """ super(UI_equip, self).__init__(parent) self.setWindowTitle(equipment.title) icono = os.path.join(IMAGE_PATH, "equipment", "%s.png" % equipment.__name__.lower()) self.setWindowIcon(QtGui.QIcon(QtGui.QPixmap(icono))) self.evaluate = Evaluate() self.evaluate.finished.connect(self.rellenar) layout = QtWidgets.QGridLayout(self) self.tabWidget = QtWidgets.QTabWidget() layout.addWidget(self.tabWidget, 0, 0, 1, 3) self.status = Status() layout.addWidget(self.status, 1, 0, 1, 1) self.checkIgnorar = QtWidgets.QCheckBox() self.checkIgnorar.setText( QtWidgets.QApplication.translate("pychemqt", "Ignore")) self.checkIgnorar.toggled.connect(self.ignorar) layout.addWidget(self.checkIgnorar, 1, 1, 1, 1) self.buttonBox = QtWidgets.QDialogButtonBox( QtWidgets.QDialogButtonBox.Cancel | QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Help) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) self.buttonBox.helpRequested.connect(self.ayuda) layout.addWidget(self.buttonBox, 1, 2, 1, 1) if not equipment.help: button = self.buttonBox.button(QtWidgets.QDialogButtonBox.Help) button.setVisible(False) # Input tab if entrada: self.Entrada = QtWidgets.QTabWidget() self.tabWidget.addTab( self.Entrada, QtGui.QIcon(os.path.join(IMAGE_PATH, "equipment", "in.svg")), QtWidgets.QApplication.translate("pychemqt", "Input")) elif entrada is None: pass else: self.Entrada = Ui_corriente() self.Entrada.Changed.connect(partial(self.changeParams, "entrada")) self.tabWidget.addTab( self.Entrada, QtGui.QIcon(os.path.join(IMAGE_PATH, "equipment", "in.svg")), QtWidgets.QApplication.translate("pychemqt", "Input")) # Calcule tab if calculo: self.tabCalculo = QtWidgets.QWidget() self.tabWidget.addTab( self.tabCalculo, QtGui.QIcon(os.path.join( IMAGE_PATH, "button", "calculator.png")), QtWidgets.QApplication.translate("pychemqt", "Calculation")) # Cost tab if equipment.indiceCostos is not None: self.tabCostos = QtWidgets.QWidget() self.tabWidget.addTab( self.tabCostos, QtGui.QIcon(os.path.join( IMAGE_PATH, "button", "currency.png")), QtWidgets.QApplication.translate("pychemqt", "Cost")) # Output tab if salida: self.Salida = QtWidgets.QTabWidget() self.tabWidget.addTab( self.Salida, QtGui.QIcon(os.path.join(IMAGE_PATH, "equipment", "out.svg")), QtWidgets.QApplication.translate("pychemqt", "Output")) elif salida is None: pass else: self.Salida = Ui_corriente(readOnly=True) self.tabWidget.addTab( self.Salida, QtGui.QIcon(os.path.join(IMAGE_PATH, "equipment", "out.svg")), QtWidgets.QApplication.translate("pychemqt", "Output")) # Notes tab self.tabNotas = TextEditor() self.tabWidget.addTab( self.tabNotas, QtGui.QIcon(os.path.join(IMAGE_PATH, "button", "editor.png")), QtWidgets.QApplication.translate("pychemqt", "Notes")) self.tabNotas.notas.textChanged.connect(self.cambiar_notas) def addSalida(self, title, **kw): widget = Ui_corriente(readOnly=True, **kw) self.Salida.addTab(widget, title) def addEntrada(self, title, key, **kw): widget = Ui_corriente(**kw) widget.Changed.connect(partial(self.changeParams, key)) self.Entrada.addTab(widget, title) def ignorar(self, bool): """Ignore the equipment""" if bool: self.status.setState(2) else: self.status.restaurar() self.tabWidget.setEnabled(not bool) def cambiar_notas(self): """Change notes properties""" htm = self.tabNotas.notas.toHtml() txt = self.tabNotas.notas.toPlainText() self.Equipment.setNotas(htm, txt) def ayuda(self): """Show help page""" url = QtCore.QUrl(self.Equipment.help) QtGui.QDesktopServices.openUrl(url) def setEquipment(self, equipment): self.Equipment = equipment self.rellenar() def changeParams(self, key, value): """Change any kwargs value""" self.calculo(**{key: value}) def changeParamsCoste(self, parametro, valor): """Change any cost kwarg value, separate of normal calcule to improve performance""" self.Equipment.cleanOldValues(**{str(parametro): valor}) if self.Equipment.status: self.Equipment.coste() self.rellenar() def calculo(self, **kwargs): """Start equipment calcule use a different thread to improve UI response""" self.status.setState(4) self.evaluate.start(self.Equipment, kwargs) def rellenar(self): """Fill widget with equipment values""" self.rellenarInput() if self.Equipment.status in [1, 3]: self.tabNotas.setText(self.Equipment.notas) for variable in self.Equipment.calculateValue: self.__getattribute__(variable).setValue( self.Equipment.__getattribute__(variable)) if len(self.Equipment.salida) == 1: self.Salida.setCorriente(self.Equipment.salida[0]) else: for i, salida in enumerate(self.Equipment.salida): self.Salida.widget(i).setCorriente(salida) if self.Equipment.indiceCostos is not None and \ self.Equipment.statusCoste: for variable in self.Equipment.calculateCostos: self.__getattribute__(variable).setValue( self.Equipment.__getattribute__(variable)) self.status.setState(self.Equipment.status, self.Equipment.msg) def rellenarInput(self): """Fill widget with input value of equipment""" self.blockSignals(True) if len(self.Equipment.kwargsInput) == 1: self.Entrada.blockSignals(True) entrada = self.Equipment.kwargsInput[0] self.Entrada.setCorriente(self.Equipment.kwargs[entrada]) self.Entrada.blockSignals(False) else: for i, entrada in enumerate(self.Equipment.kwargsInput): widget = self.Entrada.widget(i) widget.blockSignals(True) widget.setCorriente(self.Equipment.kwargs[entrada]) widget.blockSignals(False) for variable in self.Equipment.kwargsValue: self.__getattribute__(variable).setValue( self.Equipment.kwargs[variable]) for combo in self.Equipment.kwargsList: self.__getattribute__(combo).setCurrentIndex( self.Equipment.kwargs[combo]) for chck in self.Equipment.kwargsCheck: self.__getattribute__(chck).setChecked(self.Equipment.kwargs[chck]) if self.Equipment.indiceCostos is not None: self.Costos.setFactor(self.Equipment.kwargs["f_install"]) self.Costos.setBase(self.Equipment.kwargs["Base_index"]) self.Costos.setActual(self.Equipment.kwargs["Current_index"]) self.blockSignals(False)