def chainEvaluation(network, chaine, knownFunctions, stringDict): (elementList, elementType) = decomposition.decompo(chaine) i = 0 decomposition.doublePoint(elementList, elementType, network) while i < len(elementList): if elementType[i] == 'cell': try: elementList[i] = str(network.getCellByName(elementList[i]).value) except decomposition.Error as e: raise decomposition.Error(e.reason) elif elementType[i] == 'function' and elementList[i] not in stringDict: try: value = eval_function(network, elementList, elementType, i, knownFunctions) except decomposition.Error as e: raise decomposition.Error(e.reason) if decomposition.isError(str(value)): return value end = decomposition.endOfFunction(elementList, i) elementList[i:end + 1] = [str(value)] elementType[i:end + 1] = ['nombre'] i += 1 try: return eval(''.join(elementList), None, stringDict) except SyntaxError as e: print("Error de syntaxe: {}".format(elementList)) raise decomposition.Error('Syntaxe ({})'.format(e.msg)) except ZeroDivisionError: raise decomposition.Error('Division par 0') except NameError as e: stringDict[str(e).split("'")[1]] = str(e).split("'")[1] return chainEvaluation(network, ''.join(elementList), knownFunctions, stringDict) except Exception as e: print("Can't evaluate '{0}'".format(''.join(elementList)), end='') raise decomposition.Error(str(e))
def formuleExpanse(cells_selected, network, ui_mainwindow): if cells_selected.leftColumn() == cells_selected.rightColumn(): column = cells_selected.rightColumn() r0 = cells_selected.topRow() # Ligne initiale input = network.getCell(r0, column).input if len(input) == 0: pass elif input[0] != '=': for i in range(r0 + 1, cells_selected.bottomRow() + 1): if ui_mainwindow.tableWidget.item(i, column) is None: ui_mainwindow.tableWidget.setItem(i, column, QtWidgets.QTableWidgetItem()) ui_mainwindow.tableWidget.read_input.emit(i, column, input) else: decomposition0 = decomposition.decompo(input) for i in range(r0 + 1, cells_selected.bottomRow() + 1): rows = i - r0 newinput = verticalPull(decomposition0, rows) if ui_mainwindow.tableWidget.item(i, column) is None: ui_mainwindow.tableWidget.setItem(i, column, QtWidgets.QTableWidgetItem()) ui_mainwindow.tableWidget.read_input.emit(i, column, newinput) elif cells_selected.topRow() == cells_selected.bottomRow(): row = cells_selected.bottomRow() c0 = cells_selected.leftColumn() # Colonne intiale input = network.getCell(row, c0).input if len(input) == 0: pass elif input[0] != '=': for i in range(c0 + 1, cells_selected.rightColumn() + 1): if ui_mainwindow.tableWidget.item(row, i) is None: ui_mainwindow.tableWidget.setItem(row, i, QtWidgets.QTableWidgetItem()) ui_mainwindow.tableWidget.read_input.emit(row, i, input) else: decomposition0 = decomposition.decompo(input) for i in range(c0 + 1, cells_selected.rightColumn() + 1): columns = i - c0 newinput = horizontalPull(decomposition0, columns, ui_mainwindow.tableWidget.columnsLabels) if ui_mainwindow.tableWidget.item(row, i) is None: ui_mainwindow.tableWidget.setItem(row, i, QtWidgets.QTableWidgetItem()) ui_mainwindow.tableWidget.read_input.emit(row, i, newinput)