def textChangeTrigger(self): self.enableInteraction = True self.clearButtons() if self.textedit.toPlainText() == "": self.enableQSolver = True self.enableInteraction = False try: if self.textedit.toPlainText()[:4] != 'mat_': if self.enableQSolver and self.showQSolver: self.qSol, self.enableInteraction, self.simul = quickSimplify(self) if self.qSol is None: self.qSol = "" if not self.simul: renderQuickSol(self, self.qSol, self.showQSolver) elif self.showQSolver is False: self.qSol = "" renderQuickSol(self, self.qSol, self.showQSolver) else: self.matrix = True self.enableInteraction = True except Exception: logger.error('Invalid Expression') self.enableInteraction = False if self.enableInteraction: self.interactionModeButton.setEnabled(True) else: self.interactionModeButton.setEnabled(False)
def textChangeTrigger(self): self.enableInteraction = True self.clearButtons() if self.textedit.toPlainText() == "": self.enableQSolver = True self.enableInteraction = False try: if self.enableQSolver and self.showQSolver: self.qSol, self.enableInteraction = quickSimplify(self) if self.qSol is None: self.qSol = "" renderQuickSol(self, self.showQSolver) elif self.showQSolver is False: self.qSol = "" renderQuickSol(self, self.showQSolver) except ZeroDivisionError: self.enableInteraction = False if self.enableInteraction: self.interactionModeButton.setEnabled(True) else: self.interactionModeButton.setEnabled(False)
def interactionMode(self): self.enableQSolver = False renderQuickSol(self, self.enableQSolver) cursor = self.textedit.textCursor() interactionText = cursor.selectedText() if str(interactionText) == '': self.mode = 'normal' self.input = str(self.textedit.toPlainText()) else: self.input = str(interactionText) self.mode = 'interaction' showbuttons = True if len(self.input) == 0: return self.warning("No input given!") self.tokens = tokenizer(self.input) # DBP: print(self.tokens) self.addEquation() lhs, rhs = getLHSandRHS(self.tokens) self.lTokens = lhs self.rTokens = rhs operations, self.solutionType = checkTypes(lhs, rhs) if isinstance(operations, list) and showbuttons: opButtons = [] if len(operations) > 0: if len(operations) == 1: if operations[0] not in ['integrate', 'differentiate', 'find roots', 'factorize']: opButtons = ['simplify'] else: opButtons = ['simplify'] for operation in operations: if operation == '+': opButtons.append("addition") elif operation == '-': opButtons.append("subtraction") elif operation == '*': opButtons.append("multiplication") elif operation == '/': opButtons.append("division") else: opButtons.append(operation) if self.buttonSet: for i in reversed(range(self.solutionOptionsBox.count())): self.solutionOptionsBox.itemAt(i).widget().setParent(None) for i in range(int(len(opButtons) / 2) + 1): for j in range(2): if len(opButtons) > (i * 2 + j): self.solutionButtons[(i, j)] = QtWidgets.QPushButton( opButtons[i * 2 + j]) self.solutionButtons[(i, j)].resize(100, 100) self.solutionButtons[(i, j)].clicked.connect( self.onSolvePress(opButtons[i * 2 + j])) self.solutionOptionsBox.addWidget( self.solutionButtons[(i, j)], i, j) else: self.bottomButton.setParent(None) self.solutionWidget = QWidget() for i in range(int(len(opButtons) / 2) + 1): for j in range(2): if len(opButtons) > (i * 2 + j): self.solutionButtons[(i, j)] = QtWidgets.QPushButton( opButtons[i * 2 + j]) self.solutionButtons[(i, j)].resize(100, 100) self.solutionButtons[(i, j)].clicked.connect( self.onSolvePress(opButtons[i * 2 + j])) self.solutionOptionsBox.addWidget( self.solutionButtons[(i, j)], i, j) self.solutionWidget.setLayout(self.solutionOptionsBox) self.buttonSplitter.addWidget(self.solutionWidget) self.buttonSet = True
def calluser(): availableOperations = [] tokenString = '' equationTokens = [] self.input = str(self.textedit.toPlainText()) if varName == 'back': if self.input[0:4] == 'mat_': self.input = self.input[4:] self.input = self.input[0:-1] self.input = self.input[1:] if ';' in self.input: self.simul = True if (self.input.count(';') == 2): afterSplit = self.input.split(';') eqStr1 = afterSplit[0] eqStr2 = afterSplit[1] eqStr3 = afterSplit[2] elif (self.input.count(';') == 1): afterSplit = self.input.split(';') eqStr1 = afterSplit[0] eqStr2 = afterSplit[1] eqStr3 = '' if self.simul: self.tokens = [tokenizer(eqStr1), tokenizer(eqStr2), tokenizer(eqStr3)] else: self.tokens = tokenizer(self.input) # DBP: print(self.tokens) self.addEquation() lhs, rhs = getLHSandRHS(self.tokens) self.lTokens = lhs self.rTokens = rhs operations, self.solutionType = checkTypes(lhs, rhs) self.refreshButtons(operations) else: if operation == 'solve': if not self.simul: self.lTokens, self.rTokens, availableOperations, tokenString, equationTokens, comments = solveFor(self.lTokens, self.rTokens, varName) else: tokenString, equationTokens, comments = simulSolver(self.tokens[0], self.tokens[1], self.tokens[2], varName) elif operation == 'integrate': self.lTokens, availableOperations, tokenString, equationTokens, comments = integrate(self.lTokens, varName) elif operation == 'differentiate': self.lTokens, availableOperations, tokenString, equationTokens, comments = differentiate(self.lTokens, varName) self.eqToks = equationTokens renderQuickSol(self, tokenString, self.showQSolver) self.output = resultLatex(equationTokens, operation, comments, self.solutionType, self.simul, varName) if len(availableOperations) == 0: self.clearButtons() else: self.refreshButtons(availableOperations) if self.mode == 'normal': self.textedit.setText(tokenString) elif self.mode == 'interaction': cursor = self.textedit.textCursor() cursor.insertText(tokenString) if self.showStepByStep is True: showSteps(self) if self.showPlotter is True: plot(self)
def interactionMode(self): if not self.matrix: self.enableQSolver = False renderQuickSol(self, self.qSol, self.enableQSolver) cursor = self.textedit.textCursor() interactionText = cursor.selectedText() if str(interactionText) == '': self.mode = 'normal' self.input = str(self.textedit.toPlainText()) else: self.input = str(interactionText) self.mode = 'interaction' showbuttons = True if len(self.input) == 0: return self.warning("No input given!") self.simul = False self.combi = False self.matrix = False self.dualOperandMatrix = False self.scalarOperationsMatrix = False self.nonMatrixResult = False if self.input[0:4] == 'mat_': self.input = self.input[4:] self.input = self.input[0:-1] self.input = self.input[1:] self.matrix = True if not self.matrix: if ';' in self.input: self.simul = True if (self.input.count(';') == 2): afterSplit = self.input.split(';') eqStr1 = afterSplit[0] eqStr2 = afterSplit[1] eqStr3 = afterSplit[2] elif (self.input.count(';') == 1): self.combi = True afterSplit = self.input.split(';') eqStr1 = afterSplit[0] eqStr2 = afterSplit[1] eqStr3 = '' if self.simul: self.tokens = [tokenizer(eqStr1), tokenizer(eqStr2), tokenizer(eqStr3)] self.addEquation() operations = ['solve'] if self.combi: operations.extend(['combination', 'permutation']) self.solutionType = 'equation' else: self.tokens = tokenizer(self.input) # DBP: print(self.tokens) self.addEquation() lhs, rhs = getLHSandRHS(self.tokens) self.lTokens = lhs self.rTokens = rhs operations, self.solutionType = checkTypes(lhs, rhs) if isinstance(operations, list) and showbuttons: opButtons = [] if len(operations) > 0: if len(operations) == 1: if (operations[0] not in ['integrate', 'differentiate', 'find roots', 'factorize']) and (not self.simul): opButtons = ['simplify'] else: opButtons = ['simplify'] for operation in operations: if operation == '+': opButtons.append("addition") elif operation == '-': opButtons.append("subtraction") elif operation == '*': opButtons.append("multiplication") elif operation == '/': opButtons.append("division") else: opButtons.append(operation) else: if ',' in self.input: self.dualOperandMatrix = True [inputEquation1, inputEquation2] = self.input.split(', ') if '[' in inputEquation1: inputEquation1 = inputEquation1[1:][:-1] inputEquation1 = inputEquation1.split('; ') matrixOperand1 = [] for row in inputEquation1: row1 = row.split(' ') for i, _ in enumerate(row1): row1[i] = tokenizer(row1[i]) matrixOperand1.append(row1) self.Matrix1 = Matrix() self.Matrix1.value = matrixOperand1 inputEquation2 = inputEquation2[1:][:-1] inputEquation2 = inputEquation2.split('; ') matrixOperand2 = [] for row in inputEquation2: row1 = row.split(' ') for i, _ in enumerate(row1): row1[i] = tokenizer(row1[i]) matrixOperand2.append(row1) self.Matrix2 = Matrix() self.Matrix2.value = matrixOperand2 else: self.scalarOperationsMatrix = True inputEquation2 = inputEquation2[1:][:-1] inputEquation2 = inputEquation2.split('; ') matrixOperand2 = [] for row in inputEquation2: row1 = row.split(' ') for i, _ in enumerate(row1): row1[i] = tokenizer(row1[i]) matrixOperand2.append(row1) self.Matrix2 = Matrix() self.Matrix2.value = matrixOperand2 else: self.dualOperandMatrix = False inputEquation = self.input[:-2] inputEquation = inputEquation[:-1][1:] inputEquation = inputEquation.split('; ') matrixOperand = [] for row in inputEquation: row1 = row.split(' ') for i, _ in enumerate(row1): row1[i] = tokenizer(row1[i]) matrixOperand.append(row1) self.Matrix0 = Matrix() self.Matrix0.value = matrixOperand opButtons = [] if ',' in self.input: opButtons.extend(['Addition', 'Subtraction', 'Multiply']) else: opButtons.extend(['Determinant', 'Trace', 'Inverse']) if self.buttonSet: for i in reversed(range(self.solutionOptionsBox.count())): self.solutionOptionsBox.itemAt(i).widget().setParent(None) for i in range(int(len(opButtons) / 2) + 1): for j in range(2): if len(opButtons) > (i * 2 + j): self.solutionButtons[(i, j)] = QtWidgets.QPushButton( opButtons[i * 2 + j]) self.solutionButtons[(i, j)].resize(100, 100) self.solutionButtons[(i, j)].clicked.connect( self.onSolvePress(opButtons[i * 2 + j])) self.solutionOptionsBox.addWidget( self.solutionButtons[(i, j)], i, j) else: self.bottomButton.setParent(None) self.solutionWidget = QWidget() for i in range(int(len(opButtons) / 2) + 1): for j in range(2): if len(opButtons) > (i * 2 + j): self.solutionButtons[(i, j)] = QtWidgets.QPushButton( opButtons[i * 2 + j]) self.solutionButtons[(i, j)].resize(100, 100) self.solutionButtons[(i, j)].clicked.connect( self.onSolvePress(opButtons[i * 2 + j])) self.solutionOptionsBox.addWidget( self.solutionButtons[(i, j)], i, j) self.solutionWidget.setLayout(self.solutionOptionsBox) self.buttonSplitter.addWidget(self.solutionWidget) self.buttonSet = True