def default(self, inp): '''Directs to CommandExec and performs operations thereafter''' try: commandExec(inp) except Exception: logger.error('Invalid Expression: ' + inp) print('Invalid Expression: ' + inp + '\n')
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 scalarDiv(const, mat): """Divides constant terms with Matrix Arguments: const {string}--- constant value mat {visma.matrix.structure.Matrix} -- matrix token Returns: matRes {visma.matrix.structure.Matrix} -- result matrix token """ if const != 0: matRes = Matrix() matRes.empty([mat.dim[0], mat.dim[1]]) for i in range(mat.dim[0]): for j in range(mat.dim[1]): if len(mat.value[i][j]) != 1: matRes.value[i][j].append(Expression(mat.value[i][j])) else: matRes.value[i][j].extend(mat.value[i][j]) matRes.value[i][j].append(Binary('/')) matRes.value[i][j].append(Constant(int(const))) matRes = simplifyMatrix(matRes) return matRes else: logger.error("ZeroDivisionError: Cannot divide matrix by zero")
def quickSimplify(workspace): """Dynamic simplifier for simplifying expression as it is being typed Arguments: workspace {QtWidgets.QWidget} -- main layout Returns: qSolution/log {string} -- quick solution or error log enableInteraction {bool} -- if False disables 'visma'(interaction) button """ # FIXME: Crashes for some cases. Find and fix. logger.setLogName('qsolver') logger.setLevel(0) qSolution = "" strIn = workspace.textedit.toPlainText() cleanInput = removeSpaces(strIn) if ';' in cleanInput: return "", True, True terms = getTerms(cleanInput) normalizedTerms = normalize(terms) symTokens = tokenizeSymbols(normalizedTerms) normalizedTerms, symTokens = removeUnary(normalizedTerms, symTokens) if checkEquation(normalizedTerms, symTokens) is True and strIn != "": if symTokens and symTokens[-1] is not False: tokens = getToken(normalizedTerms, symTokens) tokens = tokens.tokens lhs, rhs = getLHSandRHS(tokens) _, solutionType = checkTypes(lhs, rhs) lhs, rhs = getLHSandRHS(tokens) if solutionType == 'expression': _, _, _, equationTokens, _ = simplify(tokens) qSolution = r'$ ' + '= \ ' else: _, _, _, _, equationTokens, _ = simplifyEquation(lhs, rhs) qSolution = r'$ ' + '\Rightarrow \ ' qSolution += tokensToLatex(equationTokens[-1]) + ' $' # workspace.eqToks = equationTokens # plot(workspace) return qSolution, True, False elif symTokens: log = "Invalid Expression" workspace.logBox.append(logger.error(log)) return log, False, _ else: log = "" workspace.logBox.append(logger.error(log)) return log, False, _ else: log = "" if strIn != "": _, log = checkEquation(normalizedTerms, symTokens) workspace.logBox.append(logger.error(log)) return log, 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: logger.setLogName('window-gui') logger.error('Zero division error') self.enableInteraction = False if self.enableInteraction: self.interactionModeButton.setEnabled(True) else: self.interactionModeButton.setEnabled(False)
class WorkSpace(QWidget): inputGreek = ['x', 'y', 'z', '(', ')', '7', '8', '9', 'DEL', 'C', 'f', 'g', 'h', '{', '}', '4', '5', '6', '/', '*', 'sin', 'cos', 'tan', '[', ']', '1', '2', '3', '+', '-', 'log', 'exp', '^', 'i', u'\u03C0', '.', '0', '=', '<', '>'] inputLaTeX = ['x', 'y', 'z', '(', ')', '7', '8', '9', 'DEL', 'C', 'f', 'g', 'h', '{', '}', '4', '5', '6', '\\div', '\\times', '\\sin', '\\cos', '\\tan', '[', ']', '1', '2', '3', '+', '-', 'log', 'exp', '^', 'i', '\\pi', '.', '0', '=', '<', '>'] mode = 'interaction' showQSolver = True showStepByStep = True showPlotter = False enableQSolver = True enableInteraction = False buttons = {} solutionOptionsBox = QGridLayout() solutionButtons = {} inputBox = QGridLayout() selectedCombo = "Greek" equations = [] stepsFontSize = 1 axisRange = [10, 10, 10, 30] # axisRange[-1] --> MeshDensity in 3D graphs resultOut = False try: with open('local/eqn-list.vis', 'r+') as fp: for line in fp: line = line.replace(' ', '').replace('\n', '') if not (line.isspace() or line == ''): equations.insert( 0, ('Equation No.' + str(len(equations) + 1), line)) fp.close() except IOError: logger.setLogName('window-gui') logger.error('IO error in opening %s', 'local/eqn-list.vis') if not os.path.exists('local'): os.mkdir('local') file = open('local/eqn-list.vis', 'w') file.close() if len(equations) == 0: equations = [('No equations stored', '')] equationListVbox = QVBoxLayout() tokens = [] lTokens = [] rTokens = [] buttonSet = False solutionType = "" def __init__(self): super().__init__() self.initUI() def initUI(self): hbox = QHBoxLayout(self) self.equationList = QTabWidget() self.equationList.tab1 = QWidget() # self.equationList.tab2 = QWidget() self.equationList.addTab(self.equationList.tab1, "History") # self.equationList.addTab(self.equationList.tab2, "favourites") self.equationList.tab1.setLayout(self.equationsLayout()) self.equationList.tab1.setStatusTip("Track of old equations") self.equationList.setFixedWidth(300) inputSpace = QTabWidget() inputSpace.tab1 = QWidget() inputSpace.tab2 = QWidget() inputSpace.addTab(inputSpace.tab1, "Input") inputSpace.addTab(inputSpace.tab2, "Settings") inputSpace.tab1.setLayout(self.inputsLayout()) inputSpace.tab2.setLayout(preferenceLayout(self)) inputSpace.tab1.setStatusTip("Input characters") inputSpace.setFixedHeight(200) buttonSpace = QWidget() buttonSpace.setLayout(self.buttonsLayout()) buttonSpace.setFixedWidth(300) buttonSpace.setStatusTip("Interact") self.tabPlot = QTabWidget() self.tabPlot.tab1 = QWidget() self.tabPlot.tab2 = QWidget() self.tabPlot.addTab(self.tabPlot.tab1, "2D-plot") self.tabPlot.addTab(self.tabPlot.tab2, "3D-plot") self.tabPlot.tab1.setLayout(plotFigure2D(self)) self.tabPlot.tab1.setStatusTip("Visualize equation in 2D") self.tabPlot.tab2.setLayout(plotFigure3D(self)) self.tabPlot.tab2.setStatusTip("Visualize equation in 3D") tabStepsLogs = QTabWidget() tabStepsLogs.tab1 = QWidget() tabStepsLogs.tab2 = QWidget() tabStepsLogs.addTab(tabStepsLogs.tab1, "Step-by-Step") # tabStepsLogs.addTab(tabStepsLogs.tab2, "logger") tabStepsLogs.tab1.setLayout(stepsFigure(self)) tabStepsLogs.tab1.setStatusTip("Step-by-step solver") # tabStepsLogs.tab2.setLayout(logger.logTextBox(self)) # tabStepsLogs.tab2.setStatusTip("Logger") font = QtGui.QFont() font.setPointSize(16) self.textedit = QTextEdit() self.textedit.setFont(font) self.textedit.textChanged.connect(self.textChangeTrigger) self.textedit.setFixedHeight(60) self.textedit.setStatusTip("Input equation") quickSolve = QWidget() quickSolve.setLayout(qSolveFigure(self)) quickSolve.setFixedHeight(45) quickSolve.setStatusTip("Quick solver") splitter4 = QSplitter(Qt.Vertical) splitter4.addWidget(self.textedit) splitter4.addWidget(quickSolve) splitter4.addWidget(inputSpace) splitter3 = QSplitter(Qt.Horizontal) splitter3.addWidget(splitter4) splitter3.addWidget(buttonSpace) splitter2 = QSplitter(Qt.Horizontal) splitter2.addWidget(tabStepsLogs) splitter2.addWidget(self.tabPlot) splitter2.addWidget(self.equationList) splitter1 = QSplitter(Qt.Vertical) splitter1.addWidget(splitter3) splitter1.addWidget(splitter2) hbox.addWidget(splitter1) self.setLayout(hbox) 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: logger.setLogName('window-gui') logger.error('Zero division error') self.enableInteraction = False if self.enableInteraction: self.interactionModeButton.setEnabled(True) else: self.interactionModeButton.setEnabled(False) def clearAll(self): self.textedit.clear() self.eqToks = [[]] self.output = "" showSteps(self) plot(self) def equationsLayout(self): self.myQListWidget = QtWidgets.QListWidget(self) for index, name in self.equations: myQCustomQWidget = QCustomQWidget() myQCustomQWidget.setTextUp(index) myQCustomQWidget.setTextDown(name) myQListWidgetItem = QtWidgets.QListWidgetItem(self.myQListWidget) myQListWidgetItem.setSizeHint(myQCustomQWidget.sizeHint()) self.myQListWidget.addItem(myQListWidgetItem) self.myQListWidget.setItemWidget( myQListWidgetItem, myQCustomQWidget) self.myQListWidget.resize(400, 300) self.equationListVbox.addWidget(self.myQListWidget) self.myQListWidget.itemClicked.connect(self.Clicked) self.clearButton = QtWidgets.QPushButton('Clear equations') self.clearButton.clicked.connect(self.clearHistory) self.clearButton.setStatusTip("Clear history") self.equationListVbox.addWidget(self.clearButton) return self.equationListVbox def clearHistory(self): for i in reversed(range(self.equationListVbox.count())): self.equationListVbox.itemAt(i).widget().setParent(None) self.equations = [('No equations stored', '')] file = open('local/eqn-list.vis', 'r+') file.truncate() self.myQListWidget = QtWidgets.QListWidget(self) i = 0 for index, name in self.equations: if i != 0: file.write("\n") file.write(name) myQCustomQWidget = QCustomQWidget() myQCustomQWidget.setTextUp(index) myQCustomQWidget.setTextDown(name) myQListWidgetItem = QtWidgets.QListWidgetItem(self.myQListWidget) myQListWidgetItem.setSizeHint(myQCustomQWidget.sizeHint()) self.myQListWidget.addItem(myQListWidgetItem) self.myQListWidget.setItemWidget( myQListWidgetItem, myQCustomQWidget) i += 1 file.close() self.myQListWidget.resize(400, 300) self.myQListWidget.itemClicked.connect(self.Clicked) self.equationListVbox.addWidget(self.myQListWidget) self.clearButton = QtWidgets.QPushButton('Clear equations') self.clearButton.clicked.connect(self.clearHistory) self.equationListVbox.addWidget(self.clearButton) return self.equationListVbox def Clicked(self, item): _, name = self.equations[self.myQListWidget.currentRow()] self.textedit.setText(name) def buttonsLayout(self): vbox = QVBoxLayout() interactionModeLayout = QVBoxLayout() self.interactionModeButton = QtWidgets.QPushButton('visma') self.interactionModeButton.clicked.connect(self.interactionMode) interactionModeLayout.addWidget(self.interactionModeButton) interactionModeWidget = QWidget(self) interactionModeWidget.setLayout(interactionModeLayout) interactionModeWidget.setFixedSize(275, 50) topButtonSplitter = QSplitter(Qt.Horizontal) topButtonSplitter.addWidget(interactionModeWidget) permanentButtons = QWidget(self) topButtonSplitter.addWidget(permanentButtons) self.bottomButton = QFrame() self.buttonSplitter = QSplitter(Qt.Vertical) self.buttonSplitter.addWidget(topButtonSplitter) self.buttonSplitter.addWidget(self.bottomButton) vbox.addWidget(self.buttonSplitter) return vbox 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 refreshButtons(self, operations): if isinstance(operations, list): opButtons = [] if len(operations) > 0: if len(operations) == 1: if operations[0] == 'solve': 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) 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) def clearButtons(self): for i in reversed(range(self.solutionOptionsBox.count())): self.solutionOptionsBox.itemAt(i).widget().setParent(None) def wrtVariableButtons(self, variables, operation): if isinstance(variables, list): varButtons = [] if len(variables) > 0: for variable in variables: varButtons.append(variable) varButtons.append("back") for i in reversed(range(self.solutionOptionsBox.count())): self.solutionOptionsBox.itemAt(i).widget().setParent(None) for i in range(int(len(varButtons) / 2) + 1): for j in range(2): if len(varButtons) > (i * 2 + j): self.solutionButtons[(i, j)] = QtWidgets.QPushButton( varButtons[i * 2 + j]) self.solutionButtons[(i, j)].resize(100, 100) self.solutionButtons[(i, j)].clicked.connect( self.onWRTVariablePress(varButtons[i * 2 + j], operation)) self.solutionOptionsBox.addWidget( self.solutionButtons[(i, j)], i, j) def addEquation(self): eqn = str(self.textedit.toPlainText()).replace(' ', '') if any(eqn in item for item in self.equations): return self.equationListVbox for i in reversed(range(self.equationListVbox.count())): self.equationListVbox.itemAt(i).widget().setParent(None) if len(self.equations) == 1: index, name = self.equations[0] if index == "No equations stored": self.equations[0] = ("Equation No. 1", eqn) else: self.equations.insert(0, ("Equation No. 2", eqn)) elif eqn != "": self.equations.insert(0, ("Equation No. " + str(len(self.equations) + 1), eqn)) file = open('local/eqn-list.vis', 'r+') self.myQListWidget = QtWidgets.QListWidget(self) i = 0 file.truncate() for index, name in self.equations: if i != 0: file.write("\n") file.write(name) myQCustomQWidget = QCustomQWidget() myQCustomQWidget.setTextUp(index) myQCustomQWidget.setTextDown(name) myQListWidgetItem = QtWidgets.QListWidgetItem(self.myQListWidget) myQListWidgetItem.setSizeHint(myQCustomQWidget.sizeHint()) self.myQListWidget.addItem(myQListWidgetItem) self.myQListWidget.setItemWidget( myQListWidgetItem, myQCustomQWidget) i += 1 file.close() self.myQListWidget.resize(400, 300) self.myQListWidget.itemClicked.connect(self.Clicked) self.equationListVbox.addWidget(self.myQListWidget) self.myQListWidget.itemClicked.connect(self.Clicked) self.clearButton = QtWidgets.QPushButton('Clear equations') self.clearButton.clicked.connect(self.clearHistory) self.equationListVbox.addWidget(self.clearButton) return self.equationListVbox def inputsLayout(self, loadList="Greek"): inputLayout = QHBoxLayout(self) inputWidget = QWidget() self.selectedCombo = str(loadList) for i in range(4): for j in range(10): if str(loadList) in "Greek": if (i * 10 + j) < len(self.inputGreek): self.buttons[(i, j)] = QtWidgets.QPushButton( self.inputGreek[i * 10 + j]) self.buttons[(i, j)].resize(100, 100) self.buttons[(i, j)].clicked.connect( self.onInputPress(self.inputGreek[i * 10 + j])) self.inputBox.addWidget(self.buttons[(i, j)], i, j) elif str(loadList) in "LaTeX": if (i * 10 + j) < len(self.inputLaTeX): self.buttons[(i, j)] = QtWidgets.QPushButton( self.inputLaTeX[i * 10 + j]) self.buttons[(i, j)].resize(100, 100) self.buttons[(i, j)].clicked.connect( self.onInputPress(self.inputLaTeX[i * 10 + j])) # (self.inputLaTeX[i * 3 + j]) self.inputBox.addWidget(self.buttons[(i, j)], i, j) inputWidget.setLayout(self.inputBox) # inputSplitter.addWidget(inputTypeSplitter) # inputSplitter.addWidget(inputWidget) inputLayout.addWidget(inputWidget) return inputLayout def onActivated(self, text): for i in reversed(range(self.inputBox.count())): self.inputBox.itemAt(i).widget().setParent(None) for i in range(4): for j in range(10): if str(text) in "Greek": if (i * 10 + j) < len(self.inputGreek): self.buttons[(i, j)] = QtWidgets.QPushButton( self.inputGreek[i * 10 + j]) self.buttons[(i, j)].resize(100, 100) self.buttons[(i, j)].clicked.connect( self.onInputPress(self.inputGreek[i * 10 + j])) self.inputBox.addWidget(self.buttons[(i, j)], i, j) elif str(text) in "LaTeX": if (i * 10 + j) < len(self.inputLaTeX): self.buttons[(i, j)] = QtWidgets.QPushButton( self.inputLaTeX[i * 10 + j]) self.buttons[(i, j)].resize(100, 100) self.buttons[(i, j)].clicked.connect( self.onInputPress(self.inputLaTeX[i * 10 + j])) self.inputBox.addWidget(self.buttons[(i, j)], i, j) self.selectedCombo = str(text) def onInputPress(self, name): def calluser(): if name == 'C': self.clearAll() elif name == 'DEL': cursor = self.textedit.textCursor() cursor.deletePreviousChar() else: self.textedit.insertPlainText(str(name)) return calluser def onSolvePress(self, name): def calluser(): availableOperations = [] tokenString = '' equationTokens = [] self.resultOut = True if name == 'addition': if self.solutionType == 'expression': self.tokens, availableOperations, tokenString, equationTokens, comments = addition( self.tokens, True) else: self.lTokens, self.rTokens, availableOperations, tokenString, equationTokens, comments = additionEquation( self.lTokens, self.rTokens, True) elif name == 'subtraction': if self.solutionType == 'expression': self.tokens, availableOperations, tokenString, equationTokens, comments = subtraction( self.tokens, True) else: self.lTokens, self.rTokens, availableOperations, tokenString, equationTokens, comments = subtractionEquation( self.lTokens, self.rTokens, True) elif name == 'multiplication': if self.solutionType == 'expression': self.tokens, availableOperations, tokenString, equationTokens, comments = multiplication( self.tokens, True) else: self.lTokens, self.rTokens, availableOperations, tokenString, equationTokens, comments = multiplicationEquation( self.lTokens, self.rTokens, True) elif name == 'division': if self.solutionType == 'expression': self.tokens, availableOperations, tokenString, equationTokens, comments = division( self.tokens, True) else: self.lTokens, self.rTokens, availableOperations, tokenString, equationTokens, comments = divisionEquation( self.lTokens, self.rTokens, True) elif name == 'simplify': if self.solutionType == 'expression': self.tokens, availableOperations, tokenString, equationTokens, comments = simplify(self.tokens) else: self.lTokens, self.rTokens, availableOperations, tokenString, equationTokens, comments = simplifyEquation(self.lTokens, self.rTokens) elif name == 'factorize': self.tokens, availableOperations, tokenString, equationTokens, comments = factorize(self.tokens) elif name == 'find roots': self.lTokens, self.rTokens, availableOperations, tokenString, equationTokens, comments = quadraticRoots(self.lTokens, self.rTokens) elif name == 'solve': lhs, rhs = getLHSandRHS(self.tokens) variables = getVariables(lhs, rhs) self.wrtVariableButtons(variables, name) self.resultOut = False elif name == 'integrate': lhs, rhs = getLHSandRHS(self.tokens) variables = getVariables(lhs, rhs) self.wrtVariableButtons(variables, name) self.resultOut = False elif name == 'differentiate': lhs, rhs = getLHSandRHS(self.tokens) variables = getVariables(lhs, rhs) self.wrtVariableButtons(variables, name) self.resultOut = False if self.resultOut: self.eqToks = equationTokens self.output = resultLatex(name, equationTokens, comments) 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) return calluser def onWRTVariablePress(self, varName, operation): def calluser(): availableOperations = [] tokenString = '' equationTokens = [] if varName == 'back': self.input = str(self.textedit.toPlainText()) self.tokens = tokenizer(self.input) # print(self.tokens) lhs, rhs = getLHSandRHS(self.tokens) operations, self.solutionType = checkTypes( lhs, rhs) self.refreshButtons(operations) else: if operation == 'solve': self.lTokens, self.rTokens, availableOperations, tokenString, equationTokens, comments = solveFor(self.lTokens, self.rTokens, 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 self.output = resultLatex(operation, equationTokens, comments, 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) return calluser @classmethod def warning(self, warningstr): warning = QMessageBox() warning.setWindowTitle('Warning') warning.setIcon(QMessageBox.Warning) warning.setText(warningstr) warning.setStandardButtons(QMessageBox.Ok) return warning.exec_()
def emptyline(self): logger.error('Empty line received as input') print('Empty line received as input\n')