From 5adf37d41671a5684f88522eda4527f75a7a9fc4 Mon Sep 17 00:00:00 2001 From: Daniel Acosta <82424308+RocketBlaster05@users.noreply.github.com> Date: Sun, 17 Mar 2024 22:54:02 +0000 Subject: [PATCH 01/33] Initial commit From a420a68026d588107ae1ef1696a1015e71a25be3 Mon Sep 17 00:00:00 2001 From: jnazario17 <151779220+jnazario17@users.noreply.github.com> Date: Sun, 17 Mar 2024 19:01:36 -0400 Subject: [PATCH 02/33] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bf4b1a5..1a20ad5 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@

visma - VISual MAth

- +

A math equation solver and visualizer

From a91b78d5e8c07e151dc2972d40b273cc64ee36b9 Mon Sep 17 00:00:00 2001 From: LukaMSF <150500440+LukaMSF@users.noreply.github.com> Date: Sun, 17 Mar 2024 19:06:45 -0400 Subject: [PATCH 03/33] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 1a20ad5..50ed8fa 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ visma - VISual MAth +

A math equation solver and visualizer

From 797bff2dfe3f9dbfb279d78d1f9d20b678cca56d Mon Sep 17 00:00:00 2001 From: Daniel Acosta Date: Sun, 17 Mar 2024 21:38:25 -0400 Subject: [PATCH 04/33] Fixed basic input conversion to float error with GUI buttons --- visma/gui/steps.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/visma/gui/steps.py b/visma/gui/steps.py index 3adf3a7..c05735e 100644 --- a/visma/gui/steps.py +++ b/visma/gui/steps.py @@ -37,7 +37,7 @@ def showSteps(workspace): verticalalignment='top', size=qApp.font().pointSize()*workspace.stepsFontSize) workspace.stepscanvas.draw() hbar = workspace.scroll.horizontalScrollBar() - hbar.setValue((hbar.minimum()+hbar.maximum())/2) + hbar.setValue((hbar.minimum()+hbar.maximum())//2) ############### From 017a1a6805eda37a3c0648bc19fd2b5dec24655c Mon Sep 17 00:00:00 2001 From: Daniel Acosta Date: Sat, 20 Apr 2024 13:52:05 -0400 Subject: [PATCH 05/33] Switched old unparseable input on keyboard to Ans key with previous answer functionality --- visma/gui/window.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/visma/gui/window.py b/visma/gui/window.py index 8454172..bc9c98b 100644 --- a/visma/gui/window.py +++ b/visma/gui/window.py @@ -113,7 +113,7 @@ def loadEquations(self): 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', '=', '<', '>'] + inputGreek = ['x', 'y', 'z', '(', ')', '7', '8', '9', 'DEL', 'C', 'f', 'g', 'h', '{', '}', '4', '5', '6', '/', '*', 'sin', 'cos', 'tan', '[', ']', '1', '2', '3', '+', '-', 'log', 'exp', '^', '<', '>', '.', '0', '=', 'i', 'Ans'] 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' @@ -244,6 +244,8 @@ def initUI(self): hbox.addWidget(splitter1) self.setLayout(hbox) + self.previousAnswer = '' + self.logBox.append(logger.info('UI Initialised...')) def textChangeTrigger(self): @@ -679,6 +681,9 @@ def calluser(): elif name == 'DEL': cursor = self.textedit.textCursor() cursor.deletePreviousChar() + elif name == 'Ans': + print("Get previous answer") + self.textedit.insertPlainText(self.previousAnswer) else: self.textedit.insertPlainText(str(name)) return calluser @@ -761,6 +766,7 @@ def calluser(): variables = getVariables(lhs, rhs) self.wrtVariableButtons(variables, name) self.resultOut = False + self.previousAnswer = tokenString else: """ This part handles the cases when VisMa is dealing with matrices. @@ -824,6 +830,7 @@ def calluser(): showSteps(self) if self.showPlotter is True: plot(self) + self.previousAnswer = tokenString else: if self.dualOperandMatrix: if not self.scalarOperationsMatrix: @@ -844,6 +851,7 @@ def calluser(): cursor.insertText(tokenString) if self.showStepByStep is True: showSteps(self) + self.previousAnswer = tokenString return calluser def onWRTVariablePress(self, varName, operation): From f3ffcdff12e1296dcdbf9935c5281d0f6f9e40fc Mon Sep 17 00:00:00 2001 From: Daniel Acosta Date: Sat, 20 Apr 2024 16:31:47 -0400 Subject: [PATCH 06/33] Stopped gui from crashing when hitting visma button on empty text field; Started code for rounding decimal answers in step-by-step solution. --- visma/gui/window.py | 3 +-- visma/io/parser.py | 32 +++++++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/visma/gui/window.py b/visma/gui/window.py index bc9c98b..f347bd0 100644 --- a/visma/gui/window.py +++ b/visma/gui/window.py @@ -346,6 +346,7 @@ def buttonsLayout(self): interactionModeLayout = QVBoxLayout() self.interactionModeButton = QtWidgets.QPushButton('visma') self.interactionModeButton.clicked.connect(self.interactionMode) + self.interactionModeButton.setEnabled(False) interactionModeLayout.addWidget(self.interactionModeButton) interactionModeWidget = QWidget(self) interactionModeWidget.setLayout(interactionModeLayout) @@ -682,7 +683,6 @@ def calluser(): cursor = self.textedit.textCursor() cursor.deletePreviousChar() elif name == 'Ans': - print("Get previous answer") self.textedit.insertPlainText(self.previousAnswer) else: self.textedit.insertPlainText(str(name)) @@ -889,7 +889,6 @@ def calluser(): self.rTokens = rhs operations, self.solutionType = checkTypes(lhs, rhs) self.refreshButtons(operations) - else: if operation == 'solve': if not self.simul: diff --git a/visma/io/parser.py b/visma/io/parser.py index f6120cc..09726f8 100644 --- a/visma/io/parser.py +++ b/visma/io/parser.py @@ -36,22 +36,48 @@ def resultLatex(equationTokens, operation, comments, solutionType, simul=False, else: finalSteps = 'INPUT: ' + '(Multiple ' + r'$' + ' equations)' + r'$' + '\n' finalSteps += 'OPERATION: ' + operation + '\n' - finalSteps += 'OUTPUT: ' + r'$' + equationLatex[-1] + r'$' + 2*'\n' + rounded_step = round_equation_latex_output(equationLatex, -1, 6) + finalSteps += 'OUTPUT: ' + r'$' + rounded_step + r'$' + 2*'\n' for i, _ in enumerate(equationLatex): if comments[i] != [] and equationLatex[i] != '': finalSteps += '(' + str(comments[i][0]) + ')' + '\n' - finalSteps += r'$' + equationLatex[i] + r'$' + 2*"\n" + if i == len(equationLatex) - 1: + # print(equationLatex[i]) + # rounded_step = round_equation_latex_output(equationLatex, i, 6) + pass + else: + # rounded_step = round_equation_latex_output(equationLatex, i, 2) + pass + finalSteps += r'$' + rounded_step + r'$' + 2*"\n" elif comments[i] != [] and equationLatex[i] == '': finalSteps += '\n' + '[' + str(comments[i][0]) + ']' + '\n' elif comments[i] == [] and equationLatex[i] != '': - finalSteps += '\n' + r'$' + equationLatex[i] + r'$' + 2*'\n' + if i == len(equationLatex) - 1: + # rounded_step = round_equation_latex_output(equationLatex, i, 6) + pass + else: + # rounded_step = round_equation_latex_output(equationLatex, i, 2) + pass + finalSteps += '\n' + r'$' + rounded_step + r'$' + 2*'\n' if mathError(equationTokens[-1]) and (not simul): finalSteps += 'Math Error: LHS not equal to RHS' + "\n" return finalSteps +def round_equation_latex_output(equationLatex, index, round_length): + print(equationLatex[index]) + starting_index = 0 + equationSlice = equationLatex[index][starting_index:] + while '{' in equationSlice: + open_bracket_index = equationSlice.index("{") + close_bracket_index = equationSlice.index("}") + value = round(float(equationSlice[open_bracket_index + 1:close_bracket_index]), round_length) + equationLatex[index] = equationLatex[index][0:starting_index] + equationSlice[0: open_bracket_index] + '{' + str(value) + '}' + equationSlice[close_bracket_index + 1:] + equationSlice = equationSlice[close_bracket_index + 1:] + starting_index = close_bracket_index + 1 + return equationLatex[index] def resultStringCLI(equationTokens, operation, comments, solutionType, simul=False, mat=False): """Converts tokens to final string format for displaying in terminal in CLI From de9c6aee3c023160910e6818edc549e7251b0fe4 Mon Sep 17 00:00:00 2001 From: Daniel Acosta Date: Sat, 20 Apr 2024 17:09:09 -0400 Subject: [PATCH 07/33] finished decimal rounding in step by step solution --- visma/io/parser.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/visma/io/parser.py b/visma/io/parser.py index 09726f8..eca97ff 100644 --- a/visma/io/parser.py +++ b/visma/io/parser.py @@ -38,28 +38,30 @@ def resultLatex(equationTokens, operation, comments, solutionType, simul=False, finalSteps += 'OPERATION: ' + operation + '\n' rounded_step = round_equation_latex_output(equationLatex, -1, 6) finalSteps += 'OUTPUT: ' + r'$' + rounded_step + r'$' + 2*'\n' + # finalSteps += 'OUTPUT: ' + r'$' + equationLatex[-1] + r'$' + 2*'\n' for i, _ in enumerate(equationLatex): if comments[i] != [] and equationLatex[i] != '': finalSteps += '(' + str(comments[i][0]) + ')' + '\n' if i == len(equationLatex) - 1: - # print(equationLatex[i]) - # rounded_step = round_equation_latex_output(equationLatex, i, 6) + rounded_step = round_equation_latex_output(equationLatex, i, 6) pass else: - # rounded_step = round_equation_latex_output(equationLatex, i, 2) + rounded_step = round_equation_latex_output(equationLatex, i, 2) pass finalSteps += r'$' + rounded_step + r'$' + 2*"\n" + # finalSteps += '\n' + r'$' + equationLatex[-1] + r'$' + 2*'\n' elif comments[i] != [] and equationLatex[i] == '': finalSteps += '\n' + '[' + str(comments[i][0]) + ']' + '\n' elif comments[i] == [] and equationLatex[i] != '': if i == len(equationLatex) - 1: - # rounded_step = round_equation_latex_output(equationLatex, i, 6) + rounded_step = round_equation_latex_output(equationLatex, i, 6) pass else: - # rounded_step = round_equation_latex_output(equationLatex, i, 2) + rounded_step = round_equation_latex_output(equationLatex, i, 2) pass finalSteps += '\n' + r'$' + rounded_step + r'$' + 2*'\n' + # finalSteps += '\n' + r'$' + equationLatex[i] + r'$' + 2*'\n' if mathError(equationTokens[-1]) and (not simul): finalSteps += 'Math Error: LHS not equal to RHS' + "\n" @@ -67,16 +69,16 @@ def resultLatex(equationTokens, operation, comments, solutionType, simul=False, return finalSteps def round_equation_latex_output(equationLatex, index, round_length): - print(equationLatex[index]) - starting_index = 0 - equationSlice = equationLatex[index][starting_index:] + equationSlice = equationLatex[index][0:] while '{' in equationSlice: open_bracket_index = equationSlice.index("{") close_bracket_index = equationSlice.index("}") value = round(float(equationSlice[open_bracket_index + 1:close_bracket_index]), round_length) - equationLatex[index] = equationLatex[index][0:starting_index] + equationSlice[0: open_bracket_index] + '{' + str(value) + '}' + equationSlice[close_bracket_index + 1:] + print(equationLatex[index]) + equationLatex[index] = equationLatex[index][0:equationLatex[index].index(equationSlice)] \ + + equationSlice[0: open_bracket_index] + '{' + str(value) + '}' + equationSlice[close_bracket_index + 1:] + print(equationLatex[index]) equationSlice = equationSlice[close_bracket_index + 1:] - starting_index = close_bracket_index + 1 return equationLatex[index] def resultStringCLI(equationTokens, operation, comments, solutionType, simul=False, mat=False): From a2e9ccb1dba7ab74c142b72aa984aa20465e6576 Mon Sep 17 00:00:00 2001 From: Daniel Acosta Date: Sat, 20 Apr 2024 17:43:06 -0400 Subject: [PATCH 08/33] Fixed variable parsing error with rounding step by step solution --- visma/io/parser.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/visma/io/parser.py b/visma/io/parser.py index eca97ff..082be94 100644 --- a/visma/io/parser.py +++ b/visma/io/parser.py @@ -70,15 +70,25 @@ def resultLatex(equationTokens, operation, comments, solutionType, simul=False, def round_equation_latex_output(equationLatex, index, round_length): equationSlice = equationLatex[index][0:] + print(equationSlice) while '{' in equationSlice: open_bracket_index = equationSlice.index("{") close_bracket_index = equationSlice.index("}") - value = round(float(equationSlice[open_bracket_index + 1:close_bracket_index]), round_length) - print(equationLatex[index]) - equationLatex[index] = equationLatex[index][0:equationLatex[index].index(equationSlice)] \ - + equationSlice[0: open_bracket_index] + '{' + str(value) + '}' + equationSlice[close_bracket_index + 1:] - print(equationLatex[index]) - equationSlice = equationSlice[close_bracket_index + 1:] + if not equationSlice[close_bracket_index - 1].isnumeric(): + value = round(float(equationSlice[:open_bracket_index]), round_length) + print(equationLatex[index]) + equationLatex[index] = equationLatex[index][0:equationLatex[index].index(equationSlice)] \ + + str(value) + equationSlice[open_bracket_index:] + print(equationLatex[index]) + equationSlice = equationSlice[close_bracket_index + 1:] + pass + else: + value = round(float(equationSlice[open_bracket_index + 1:close_bracket_index]), round_length) + print(equationLatex[index]) + equationLatex[index] = equationLatex[index][0:equationLatex[index].index(equationSlice)] \ + + equationSlice[0: open_bracket_index] + '{' + str(value) + '}' + equationSlice[close_bracket_index + 1:] + print(equationLatex[index]) + equationSlice = equationSlice[close_bracket_index + 1:] return equationLatex[index] def resultStringCLI(equationTokens, operation, comments, solutionType, simul=False, mat=False): From e5ea4a3e2919e8e2ac229ad2400e68fd84415178 Mon Sep 17 00:00:00 2001 From: Daniel Acosta Date: Sat, 20 Apr 2024 17:45:48 -0400 Subject: [PATCH 09/33] updated case for when variable has no coefficient on rounding values --- visma/io/parser.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/visma/io/parser.py b/visma/io/parser.py index 082be94..2b21790 100644 --- a/visma/io/parser.py +++ b/visma/io/parser.py @@ -75,7 +75,11 @@ def round_equation_latex_output(equationLatex, index, round_length): open_bracket_index = equationSlice.index("{") close_bracket_index = equationSlice.index("}") if not equationSlice[close_bracket_index - 1].isnumeric(): - value = round(float(equationSlice[:open_bracket_index]), round_length) + value = '' + try: + value = round(float(equationSlice[:open_bracket_index]), round_length) + except ValueError: + pass print(equationLatex[index]) equationLatex[index] = equationLatex[index][0:equationLatex[index].index(equationSlice)] \ + str(value) + equationSlice[open_bracket_index:] From 30a707cbdb2708fb73a97f04abb9e80e376c2ad0 Mon Sep 17 00:00:00 2001 From: Daniel Acosta Date: Sat, 20 Apr 2024 18:06:54 -0400 Subject: [PATCH 10/33] removed unnecessary print statements --- visma/io/parser.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/visma/io/parser.py b/visma/io/parser.py index 2b21790..e6e1f95 100644 --- a/visma/io/parser.py +++ b/visma/io/parser.py @@ -70,7 +70,6 @@ def resultLatex(equationTokens, operation, comments, solutionType, simul=False, def round_equation_latex_output(equationLatex, index, round_length): equationSlice = equationLatex[index][0:] - print(equationSlice) while '{' in equationSlice: open_bracket_index = equationSlice.index("{") close_bracket_index = equationSlice.index("}") @@ -80,18 +79,14 @@ def round_equation_latex_output(equationLatex, index, round_length): value = round(float(equationSlice[:open_bracket_index]), round_length) except ValueError: pass - print(equationLatex[index]) equationLatex[index] = equationLatex[index][0:equationLatex[index].index(equationSlice)] \ + str(value) + equationSlice[open_bracket_index:] - print(equationLatex[index]) equationSlice = equationSlice[close_bracket_index + 1:] pass else: value = round(float(equationSlice[open_bracket_index + 1:close_bracket_index]), round_length) - print(equationLatex[index]) equationLatex[index] = equationLatex[index][0:equationLatex[index].index(equationSlice)] \ + equationSlice[0: open_bracket_index] + '{' + str(value) + '}' + equationSlice[close_bracket_index + 1:] - print(equationLatex[index]) equationSlice = equationSlice[close_bracket_index + 1:] return equationLatex[index] From cbc5e35df644060bd75224149e64d21f639004b3 Mon Sep 17 00:00:00 2001 From: WhetBoi Date: Sat, 20 Apr 2024 18:11:12 -0400 Subject: [PATCH 11/33] Added graph button, works for expressions but not equations (at least I think so) --- visma/gui/window.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/visma/gui/window.py b/visma/gui/window.py index f347bd0..f301761 100644 --- a/visma/gui/window.py +++ b/visma/gui/window.py @@ -419,12 +419,14 @@ def interactionMode(self): operations, self.solutionType = checkTypes(lhs, rhs) if isinstance(operations, list) and showbuttons: opButtons = [] + if 'differentiate' in operations: + opButtons.append('graph') if len(operations) > 0: if len(operations) == 1: if (operations[0] not in ['integrate', 'differentiate', 'find roots', 'factorize']) and (not self.simul): - opButtons = ['simplify'] + opButtons.append('simplify') else: - opButtons = ['simplify'] + opButtons.append('simplify') for operation in operations: if operation == '+': opButtons.append("addition") @@ -526,12 +528,14 @@ def interactionMode(self): def refreshButtons(self, operations): if isinstance(operations, list): opButtons = [] + if 'differentiate' in operations: + opButtons.append('graph') if len(operations) > 0: if len(operations) == 1: if operations[0] == 'solve': - opButtons = ['simplify'] + opButtons.append('simplify') else: - opButtons = ['simplify'] + opButtons.append('simplify') for operation in operations: if operation == '+': opButtons.append("addition") @@ -766,6 +770,12 @@ def calluser(): variables = getVariables(lhs, rhs) self.wrtVariableButtons(variables, name) self.resultOut = False + elif name == 'graph': + 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) + self.showPlotter = True self.previousAnswer = tokenString else: """ From 8e914680a3dccf69eb1e6de9dc4b26e2555d9da1 Mon Sep 17 00:00:00 2001 From: Daniel Acosta Date: Sat, 20 Apr 2024 19:37:11 -0400 Subject: [PATCH 12/33] Added manual text to show user how to input matrices into gui --- main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index e51e48b..67c46a4 100644 --- a/main.py +++ b/main.py @@ -14,7 +14,7 @@ def init(): class VisMa_Prompt(Cmd): '''This inititates the main VisMa Prompt from where user may move to CLI/GUI''' - userManual = "|_________________________________________________________________________________________________|\n"\ + userManual = " _________________________________________________________________________________________________ \n"\ "| gui ->> opens Visma in GUI mode. |\n"\ "| Ctrl + D ->> Closes the prompt. |\n"\ "| exit ->> Closes the prompt. |\n"\ @@ -31,6 +31,10 @@ class VisMa_Prompt(Cmd): "|-------------------------------------------------------------------------------------------------|\n"\ "| integrate( expression , variable ) ->> Integrates the expression by the given variable. |\n"\ "| differentiate( expression , variable ) ->> Differentiates the expression by the given variable. |\n"\ + "|-------------------------------------------------------------------------------------------------|\n"\ + "| Matrices should be input in the following format: |\n"\ + "| Single: mat_([x00 x01; x10 x11]) |\n"\ + "| Double: mat_([x00 x01; x10 x11], [y00 y01; y10 y11]) |\n"\ "|_________________________________________________________________________________________________|\n"\ prompt = '>>> ' From 79c7b77ec468376b69a7820877c2f96bca50364f Mon Sep 17 00:00:00 2001 From: Daniel Acosta <82424308+RocketBlaster05@users.noreply.github.com> Date: Sat, 20 Apr 2024 20:13:55 -0400 Subject: [PATCH 13/33] Update CONTRIBUTING.md --- CONTRIBUTING.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index daeb4c2..f43730b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,6 +11,7 @@ This is a brief guide on using **visma(VISualMAth)** and for making any contribu * **Integration** - integrate a polynomial expression wrt a chosen variable * **Differentiation** - differentiate a polynomial expression wrt a chosen variable * **Plot** - plots an interactive 2D or 3D graph +* **Matrix Operations** - This feature will allow you to add, subtract, and multiply two matrices. Can also perform various simplifications on an individual matrix. ![visma](https://raw.githubusercontent.com/wiki/aerospaceresearch/visma/assets/demo.gif) From caef3971a7cd164de9bdd7453b994ea3a04b0717 Mon Sep 17 00:00:00 2001 From: Daniel Acosta Date: Sun, 21 Apr 2024 13:34:32 -0400 Subject: [PATCH 14/33] Fixed parsing issue for integration/differentiation with value rounding in step-by-step solution --- visma/io/parser.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/visma/io/parser.py b/visma/io/parser.py index e6e1f95..960806d 100644 --- a/visma/io/parser.py +++ b/visma/io/parser.py @@ -36,7 +36,9 @@ def resultLatex(equationTokens, operation, comments, solutionType, simul=False, else: finalSteps = 'INPUT: ' + '(Multiple ' + r'$' + ' equations)' + r'$' + '\n' finalSteps += 'OPERATION: ' + operation + '\n' + print(equationLatex[-1]) rounded_step = round_equation_latex_output(equationLatex, -1, 6) + print(equationLatex[-1]) finalSteps += 'OUTPUT: ' + r'$' + rounded_step + r'$' + 2*'\n' # finalSteps += 'OUTPUT: ' + r'$' + equationLatex[-1] + r'$' + 2*'\n' @@ -44,10 +46,14 @@ def resultLatex(equationTokens, operation, comments, solutionType, simul=False, if comments[i] != [] and equationLatex[i] != '': finalSteps += '(' + str(comments[i][0]) + ')' + '\n' if i == len(equationLatex) - 1: + print(equationLatex[i]) rounded_step = round_equation_latex_output(equationLatex, i, 6) + print(equationLatex[i]) pass else: + print(equationLatex[i]) rounded_step = round_equation_latex_output(equationLatex, i, 2) + print(equationLatex[i]) pass finalSteps += r'$' + rounded_step + r'$' + 2*"\n" # finalSteps += '\n' + r'$' + equationLatex[-1] + r'$' + 2*'\n' @@ -55,10 +61,14 @@ def resultLatex(equationTokens, operation, comments, solutionType, simul=False, finalSteps += '\n' + '[' + str(comments[i][0]) + ']' + '\n' elif comments[i] == [] and equationLatex[i] != '': if i == len(equationLatex) - 1: + print(equationLatex[i]) rounded_step = round_equation_latex_output(equationLatex, i, 6) + print(equationLatex[i]) pass else: + print(equationLatex[i]) rounded_step = round_equation_latex_output(equationLatex, i, 2) + print(equationLatex[i]) pass finalSteps += '\n' + r'$' + rounded_step + r'$' + 2*'\n' # finalSteps += '\n' + r'$' + equationLatex[i] + r'$' + 2*'\n' @@ -73,6 +83,11 @@ def round_equation_latex_output(equationLatex, index, round_length): while '{' in equationSlice: open_bracket_index = equationSlice.index("{") close_bracket_index = equationSlice.index("}") + temp_open_bracket_index = open_bracket_index + while '{' in equationSlice[temp_open_bracket_index + 1: close_bracket_index]: + temp_open_bracket_index = equationSlice[open_bracket_index + 1: close_bracket_index].index('{') + open_bracket_index + 1 + close_bracket_index = equationSlice[close_bracket_index + 1:].index('}') + close_bracket_index + 1 + print(open_bracket_index, close_bracket_index) if not equationSlice[close_bracket_index - 1].isnumeric(): value = '' try: From 7bbbdceda48c5dff99d6cfb81d65f85093dc1593 Mon Sep 17 00:00:00 2001 From: Daniel Acosta Date: Sun, 21 Apr 2024 13:47:58 -0400 Subject: [PATCH 15/33] More rounding parser error fixes --- visma/io/parser.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/visma/io/parser.py b/visma/io/parser.py index 960806d..9938039 100644 --- a/visma/io/parser.py +++ b/visma/io/parser.py @@ -84,10 +84,10 @@ def round_equation_latex_output(equationLatex, index, round_length): open_bracket_index = equationSlice.index("{") close_bracket_index = equationSlice.index("}") temp_open_bracket_index = open_bracket_index - while '{' in equationSlice[temp_open_bracket_index + 1: close_bracket_index]: + while '{' in equationSlice[temp_open_bracket_index + 1: close_bracket_index] and close_bracket_index != len(equationLatex[index]) - 1: temp_open_bracket_index = equationSlice[open_bracket_index + 1: close_bracket_index].index('{') + open_bracket_index + 1 close_bracket_index = equationSlice[close_bracket_index + 1:].index('}') + close_bracket_index + 1 - print(open_bracket_index, close_bracket_index) + print(open_bracket_index, close_bracket_index) if not equationSlice[close_bracket_index - 1].isnumeric(): value = '' try: From 432fe383339bdbf0c98ddeb848baa6f054fe0134 Mon Sep 17 00:00:00 2001 From: Daniel Acosta Date: Sun, 21 Apr 2024 13:51:44 -0400 Subject: [PATCH 16/33] Removed unnecessary print statements --- visma/io/parser.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/visma/io/parser.py b/visma/io/parser.py index 9938039..2a3345c 100644 --- a/visma/io/parser.py +++ b/visma/io/parser.py @@ -36,9 +36,9 @@ def resultLatex(equationTokens, operation, comments, solutionType, simul=False, else: finalSteps = 'INPUT: ' + '(Multiple ' + r'$' + ' equations)' + r'$' + '\n' finalSteps += 'OPERATION: ' + operation + '\n' - print(equationLatex[-1]) + # print(equationLatex[-1]) rounded_step = round_equation_latex_output(equationLatex, -1, 6) - print(equationLatex[-1]) + # print(equationLatex[-1]) finalSteps += 'OUTPUT: ' + r'$' + rounded_step + r'$' + 2*'\n' # finalSteps += 'OUTPUT: ' + r'$' + equationLatex[-1] + r'$' + 2*'\n' @@ -46,14 +46,14 @@ def resultLatex(equationTokens, operation, comments, solutionType, simul=False, if comments[i] != [] and equationLatex[i] != '': finalSteps += '(' + str(comments[i][0]) + ')' + '\n' if i == len(equationLatex) - 1: - print(equationLatex[i]) + # print(equationLatex[i]) rounded_step = round_equation_latex_output(equationLatex, i, 6) - print(equationLatex[i]) + # print(equationLatex[i]) pass else: - print(equationLatex[i]) + # print(equationLatex[i]) rounded_step = round_equation_latex_output(equationLatex, i, 2) - print(equationLatex[i]) + # print(equationLatex[i]) pass finalSteps += r'$' + rounded_step + r'$' + 2*"\n" # finalSteps += '\n' + r'$' + equationLatex[-1] + r'$' + 2*'\n' @@ -61,14 +61,14 @@ def resultLatex(equationTokens, operation, comments, solutionType, simul=False, finalSteps += '\n' + '[' + str(comments[i][0]) + ']' + '\n' elif comments[i] == [] and equationLatex[i] != '': if i == len(equationLatex) - 1: - print(equationLatex[i]) + # print(equationLatex[i]) rounded_step = round_equation_latex_output(equationLatex, i, 6) - print(equationLatex[i]) + # print(equationLatex[i]) pass else: - print(equationLatex[i]) + # print(equationLatex[i]) rounded_step = round_equation_latex_output(equationLatex, i, 2) - print(equationLatex[i]) + # print(equationLatex[i]) pass finalSteps += '\n' + r'$' + rounded_step + r'$' + 2*'\n' # finalSteps += '\n' + r'$' + equationLatex[i] + r'$' + 2*'\n' @@ -87,7 +87,6 @@ def round_equation_latex_output(equationLatex, index, round_length): while '{' in equationSlice[temp_open_bracket_index + 1: close_bracket_index] and close_bracket_index != len(equationLatex[index]) - 1: temp_open_bracket_index = equationSlice[open_bracket_index + 1: close_bracket_index].index('{') + open_bracket_index + 1 close_bracket_index = equationSlice[close_bracket_index + 1:].index('}') + close_bracket_index + 1 - print(open_bracket_index, close_bracket_index) if not equationSlice[close_bracket_index - 1].isnumeric(): value = '' try: From b40863e89aebcf254b6bbd357aa36d5ec83344b0 Mon Sep 17 00:00:00 2001 From: WhetBoi Date: Sun, 21 Apr 2024 15:21:57 -0400 Subject: [PATCH 17/33] Added graph button, works for expressions but not equations (at least I think so) --- visma/simplify/simplify.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/visma/simplify/simplify.py b/visma/simplify/simplify.py index 2b951ac..ccc7ad2 100644 --- a/visma/simplify/simplify.py +++ b/visma/simplify/simplify.py @@ -250,18 +250,21 @@ def expressionSimplification(tokens_now, scope, tokens1): if len(tokens1[i + 1].tokens) == 1 and isinstance(tokens1[i + 1].tokens[0], Constant): tokens1[i + 1] = Constant(tokens1[i + 1].tokens[0].calculate(), 1, 1) if (isinstance(tokens1[i], Binary) and tokens1[i].value == '^') and isinstance(tokens1[i + 1], Constant): - if float(tokens1[i + 1].calculate()).is_integer(): - rep = int(tokens1[i + 1].calculate()) - for _ in range(rep - 1): - pfTokens.extend([Binary('*'), tokens1[i - 1]]) - i += 1 - else: - pfTokens.append(tokens1[i]) + value = str(tokens1[i - 1])[1:len(str(tokens1[i - 1])) - 1] + value = float(value) + value **= tokens1[i + 1].calculate() + tokens1[i + 1] = Constant(value, 1, 1) + + del pfTokens[len(pfTokens) - 1] + pfTokens.append(tokens1[i + 1]) + del tokens1[i] + del tokens1[i - 1] else: pfTokens.append(tokens1[i]) else: pfTokens.append(tokens1[i]) i += 1 + tokens1 = copy.deepcopy(pfTokens) animation.append(pfTokens) comments.append(['Expanding the powers of expressions']) From a53d17bb5b1b952b382735c4cd27b48ad55d099c Mon Sep 17 00:00:00 2001 From: Daniel Acosta Date: Sun, 21 Apr 2024 15:30:20 -0400 Subject: [PATCH 18/33] Fixed parser exponential rounding error :) --- visma/io/parser.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/visma/io/parser.py b/visma/io/parser.py index 2a3345c..5218148 100644 --- a/visma/io/parser.py +++ b/visma/io/parser.py @@ -36,9 +36,9 @@ def resultLatex(equationTokens, operation, comments, solutionType, simul=False, else: finalSteps = 'INPUT: ' + '(Multiple ' + r'$' + ' equations)' + r'$' + '\n' finalSteps += 'OPERATION: ' + operation + '\n' - # print(equationLatex[-1]) + print(equationLatex[-1]) rounded_step = round_equation_latex_output(equationLatex, -1, 6) - # print(equationLatex[-1]) + print(equationLatex[-1]) finalSteps += 'OUTPUT: ' + r'$' + rounded_step + r'$' + 2*'\n' # finalSteps += 'OUTPUT: ' + r'$' + equationLatex[-1] + r'$' + 2*'\n' @@ -46,14 +46,14 @@ def resultLatex(equationTokens, operation, comments, solutionType, simul=False, if comments[i] != [] and equationLatex[i] != '': finalSteps += '(' + str(comments[i][0]) + ')' + '\n' if i == len(equationLatex) - 1: - # print(equationLatex[i]) + print(equationLatex[i]) rounded_step = round_equation_latex_output(equationLatex, i, 6) - # print(equationLatex[i]) + print(equationLatex[i]) pass else: - # print(equationLatex[i]) + print(equationLatex[i]) rounded_step = round_equation_latex_output(equationLatex, i, 2) - # print(equationLatex[i]) + print(equationLatex[i]) pass finalSteps += r'$' + rounded_step + r'$' + 2*"\n" # finalSteps += '\n' + r'$' + equationLatex[-1] + r'$' + 2*'\n' @@ -61,14 +61,14 @@ def resultLatex(equationTokens, operation, comments, solutionType, simul=False, finalSteps += '\n' + '[' + str(comments[i][0]) + ']' + '\n' elif comments[i] == [] and equationLatex[i] != '': if i == len(equationLatex) - 1: - # print(equationLatex[i]) + print(equationLatex[i]) rounded_step = round_equation_latex_output(equationLatex, i, 6) - # print(equationLatex[i]) + print(equationLatex[i]) pass else: - # print(equationLatex[i]) + print(equationLatex[i]) rounded_step = round_equation_latex_output(equationLatex, i, 2) - # print(equationLatex[i]) + print(equationLatex[i]) pass finalSteps += '\n' + r'$' + rounded_step + r'$' + 2*'\n' # finalSteps += '\n' + r'$' + equationLatex[i] + r'$' + 2*'\n' @@ -84,9 +84,11 @@ def round_equation_latex_output(equationLatex, index, round_length): open_bracket_index = equationSlice.index("{") close_bracket_index = equationSlice.index("}") temp_open_bracket_index = open_bracket_index - while '{' in equationSlice[temp_open_bracket_index + 1: close_bracket_index] and close_bracket_index != len(equationLatex[index]) - 1: + while '{' in equationSlice[temp_open_bracket_index + 1: close_bracket_index] and close_bracket_index != len(equationSlice) - 1: temp_open_bracket_index = equationSlice[open_bracket_index + 1: close_bracket_index].index('{') + open_bracket_index + 1 close_bracket_index = equationSlice[close_bracket_index + 1:].index('}') + close_bracket_index + 1 + print(equationSlice[open_bracket_index:close_bracket_index + 1]) + print(open_bracket_index, close_bracket_index) if not equationSlice[close_bracket_index - 1].isnumeric(): value = '' try: From b31a90cc99bd637d04c6e3b06b47ee0885577236 Mon Sep 17 00:00:00 2001 From: Daniel Acosta Date: Sun, 21 Apr 2024 15:31:36 -0400 Subject: [PATCH 19/33] Removed unnecessary print statements --- visma/io/parser.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/visma/io/parser.py b/visma/io/parser.py index 5218148..bcfd9f9 100644 --- a/visma/io/parser.py +++ b/visma/io/parser.py @@ -36,9 +36,9 @@ def resultLatex(equationTokens, operation, comments, solutionType, simul=False, else: finalSteps = 'INPUT: ' + '(Multiple ' + r'$' + ' equations)' + r'$' + '\n' finalSteps += 'OPERATION: ' + operation + '\n' - print(equationLatex[-1]) + # print(equationLatex[-1]) rounded_step = round_equation_latex_output(equationLatex, -1, 6) - print(equationLatex[-1]) + # print(equationLatex[-1]) finalSteps += 'OUTPUT: ' + r'$' + rounded_step + r'$' + 2*'\n' # finalSteps += 'OUTPUT: ' + r'$' + equationLatex[-1] + r'$' + 2*'\n' @@ -46,14 +46,14 @@ def resultLatex(equationTokens, operation, comments, solutionType, simul=False, if comments[i] != [] and equationLatex[i] != '': finalSteps += '(' + str(comments[i][0]) + ')' + '\n' if i == len(equationLatex) - 1: - print(equationLatex[i]) + # print(equationLatex[i]) rounded_step = round_equation_latex_output(equationLatex, i, 6) - print(equationLatex[i]) + # print(equationLatex[i]) pass else: - print(equationLatex[i]) + # print(equationLatex[i]) rounded_step = round_equation_latex_output(equationLatex, i, 2) - print(equationLatex[i]) + # print(equationLatex[i]) pass finalSteps += r'$' + rounded_step + r'$' + 2*"\n" # finalSteps += '\n' + r'$' + equationLatex[-1] + r'$' + 2*'\n' @@ -61,14 +61,14 @@ def resultLatex(equationTokens, operation, comments, solutionType, simul=False, finalSteps += '\n' + '[' + str(comments[i][0]) + ']' + '\n' elif comments[i] == [] and equationLatex[i] != '': if i == len(equationLatex) - 1: - print(equationLatex[i]) + # print(equationLatex[i]) rounded_step = round_equation_latex_output(equationLatex, i, 6) - print(equationLatex[i]) + # print(equationLatex[i]) pass else: - print(equationLatex[i]) + # print(equationLatex[i]) rounded_step = round_equation_latex_output(equationLatex, i, 2) - print(equationLatex[i]) + # print(equationLatex[i]) pass finalSteps += '\n' + r'$' + rounded_step + r'$' + 2*'\n' # finalSteps += '\n' + r'$' + equationLatex[i] + r'$' + 2*'\n' @@ -87,8 +87,8 @@ def round_equation_latex_output(equationLatex, index, round_length): while '{' in equationSlice[temp_open_bracket_index + 1: close_bracket_index] and close_bracket_index != len(equationSlice) - 1: temp_open_bracket_index = equationSlice[open_bracket_index + 1: close_bracket_index].index('{') + open_bracket_index + 1 close_bracket_index = equationSlice[close_bracket_index + 1:].index('}') + close_bracket_index + 1 - print(equationSlice[open_bracket_index:close_bracket_index + 1]) - print(open_bracket_index, close_bracket_index) + # print(equationSlice[open_bracket_index:close_bracket_index + 1]) + # print(open_bracket_index, close_bracket_index) if not equationSlice[close_bracket_index - 1].isnumeric(): value = '' try: From b41fbc93de6011f844a1bcb4e42da5e1bd678ff4 Mon Sep 17 00:00:00 2001 From: AceShooter Date: Sun, 21 Apr 2024 15:41:58 -0400 Subject: [PATCH 20/33] Colors in windows! --- tests/test_simplify.py | 3 ++ visma/gui/cli.py | 1 + visma/gui/window.py | 52 ++++++++++++++++++-- visma/io/checks.py | 108 ++++++++++++++++++++++++++++++++++++++++- 4 files changed, 158 insertions(+), 6 deletions(-) diff --git a/tests/test_simplify.py b/tests/test_simplify.py index f6983f6..54f9261 100644 --- a/tests/test_simplify.py +++ b/tests/test_simplify.py @@ -10,6 +10,9 @@ def test_simplify(): + assert quickTest("4 + (3/(3-4)*3)", simplify) == "-5" + + assert quickTest("1 + 2 - 3", simplify) == "0" assert quickTest("1 + 2 - 4", simplify) == "-1.0" assert quickTest("0 + 0 + 1", simplify) == "1.0" diff --git a/visma/gui/cli.py b/visma/gui/cli.py index 0532e4d..cdf01f6 100644 --- a/visma/gui/cli.py +++ b/visma/gui/cli.py @@ -1,6 +1,7 @@ import copy import sys from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget, QTabWidget, QVBoxLayout +from PyQt5.QtCore import Qt from visma.calculus.differentiation import differentiate from visma.calculus.integration import integrate from visma.discreteMaths.combinatorics import factorial, combination, permutation diff --git a/visma/gui/window.py b/visma/gui/window.py index f301761..9cb52ea 100644 --- a/visma/gui/window.py +++ b/visma/gui/window.py @@ -164,13 +164,24 @@ def __init__(self): def initUI(self): hbox = QHBoxLayout(self) + #self.setStyleSheet("background-color: rgb(120, 120, 120);") # changes color of nearly everything to blue + #self.setStyleSheet("color: lightblue") # changes color of all text to blue + #self.setStyleSheet("border: black") # removes button colors + #self.setStyleSheet("border-color: blue") # changes nothing basically 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.setStyleSheet("background-color: rgb(120, 120, 120)") # colors whole widget + self.equationList.tab1.setLayout(self.equationsLayout()) # color modified + self.myQListWidget.setStyleSheet("background-color: rgb(210, 210, 210);") # colors inside of widget + self.clearButton.setStyleSheet("background-color: rgb(210, 210, 210)") # colors button + + self.equationList.tab1.setStatusTip("Track of old equations") self.equationList.setFixedWidth(300) @@ -183,12 +194,14 @@ def initUI(self): inputSpace.tab2.setLayout(preferenceLayout(self)) inputSpace.tab1.setStatusTip("Input characters") inputSpace.setFixedHeight(200) + inputSpace.tab1.setStyleSheet("background-color: rgb(120, 120, 120)") + inputSpace.tab2.setStyleSheet("background-color: rgb(210, 210, 210)") buttonSpace = QWidget() buttonSpace.setLayout(self.buttonsLayout()) buttonSpace.setFixedWidth(300) buttonSpace.setStatusTip("Interact") - + self.tabPlot = QTabWidget() self.tabPlot.tab1 = QWidget() self.tabPlot.tab2 = QWidget() @@ -248,6 +261,8 @@ def initUI(self): self.logBox.append(logger.info('UI Initialised...')) + + def textChangeTrigger(self): self.enableInteraction = True self.clearButtons() @@ -285,6 +300,7 @@ def clearAll(self): def equationsLayout(self): self.myQListWidget = QtWidgets.QListWidget(self) + for index, name in self.equations: myQCustomQWidget = QCustomQWidget() myQCustomQWidget.setTextUp(index) @@ -327,6 +343,7 @@ def clearHistory(self): self.myQListWidget.setItemWidget( myQListWidgetItem, myQCustomQWidget) i += 1 + myQCustomQWidget.setStyleSheet("background-color: rgb(210, 210, 210);") # colors equation border on every iteration file.close() self.myQListWidget.resize(400, 300) self.myQListWidget.itemClicked.connect(self.Clicked) @@ -334,6 +351,8 @@ def clearHistory(self): self.clearButton = QtWidgets.QPushButton('Clear equations') self.clearButton.clicked.connect(self.clearHistory) self.equationListVbox.addWidget(self.clearButton) + self.myQListWidget.setStyleSheet("background-color: rgb(210, 210, 210);") # colors inside of widget again + self.clearButton.setStyleSheet("background-color: rgb(210, 210, 210)") # colors button again return self.equationListVbox def Clicked(self, item): @@ -637,6 +656,7 @@ def inputsLayout(self, loadList="Greek"): if (i * 10 + j) < len(self.inputGreek): self.buttons[(i, j)] = QtWidgets.QPushButton( self.inputGreek[i * 10 + j]) + self.checkForColorChange(self.buttons[(i, j)]) self.buttons[(i, j)].resize(100, 100) self.buttons[(i, j)].clicked.connect( self.onInputPress(self.inputGreek[i * 10 + j])) @@ -654,8 +674,32 @@ def inputsLayout(self, loadList="Greek"): # inputSplitter.addWidget(inputTypeSplitter) # inputSplitter.addWidget(inputWidget) inputLayout.addWidget(inputWidget) + inputWidget.setStyleSheet("background-color: rgb(120, 120, 120);") # colors the space around input buttons + return inputLayout + def checkForColorChange(self, button): # changes button color + match button.text(): + case "Ans": + button.setStyleSheet("font-weight: bold;") + button.setStyleSheet("background-color: green;") + case "C" | "DEL": + button.setStyleSheet("font-weight: bold;") + button.setStyleSheet("background-color: red;") #rgb(34, 34, 34) + case "+" | "*" | "/" | "-": + button.setStyleSheet("font-weight: bold;") + button.setStyleSheet("background-color: orange;") + case _: + button.setStyleSheet("background-color: rgb(210, 210, 210)") + + + """if self.button.text() == "Ans": + self.button.setStyleSheet("background-color: green;") + else: + self.buttons[(i, j)].setStyleSheet("background-color: orange;")""" + + + def onActivated(self, text): for i in reversed(range(self.inputBox.count())): self.inputBox.itemAt(i).widget().setParent(None) @@ -955,10 +999,10 @@ def __init__(self, parent=None): self.setLayout(self.allQHBoxLayout) self.textUpQLabel.setStyleSheet(''' color: black; - ''') + ''') # Colors the text in history tab: the equation number self.textDownQLabel.setStyleSheet(''' color: black; - ''') + ''') # Colors the text in history tab: the input def setTextUp(self, text): self.textUpQLabel.setText(text) diff --git a/visma/io/checks.py b/visma/io/checks.py index 5faa405..4486c1a 100644 --- a/visma/io/checks.py +++ b/visma/io/checks.py @@ -1,11 +1,13 @@ import math import copy from visma.config.values import ROUNDOFF +from visma.functions.exponential import Logarithm from visma.functions.structure import Function, Expression from visma.functions.constant import Constant +from visma.functions.trigonometry import Trigonometric from visma.functions.variable import Variable -from visma.functions.operator import Operator, Binary - +from visma.functions.operator import Operator, Binary, Sqrt +from visma.matrix.structure import Matrix greek = [u'\u03B1', u'\u03B2', u'\u03B3'] @@ -94,6 +96,105 @@ def isEquation(lTokens, rTokens): return False +def tokensToString(tokens): + """Converts tokens to text string + + Arguments: + tokens {list} -- list of function tokens + + Returns: + tokenString {string} -- equation string + """ + # FIXME: tokensToString method + tokenString = '' + for token in tokens: + if isinstance(token, Constant): + if isinstance(token.value, list): + for j, val in token.value: + if token['power'][j] != 1: + tokenString += (str(val) + '^(' + str(token.power[j]) + ')') + else: + tokenString += str(val) + elif isNumber(token.value): + if token.power != 1: + tokenString += (str(token.value) + '^(' + str(token.power) + ')') + else: + tokenString += str(token.value) + elif isinstance(token, Variable): + if token.coefficient == 1: + pass + elif token.coefficient == -1: + tokenString += '-' + else: + tokenString += str(token.coefficient) + for j, val in enumerate(token.value): + if token.power[j] != 1: + tokenString += (str(val) + '^(' + str(token.power[j]) + ')') + else: + tokenString += str(val) + elif isinstance(token, Binary): + tokenString += ' ' + str(token.value) + ' ' + elif isinstance(token, Expression): + if token.coefficient != 1: + tokenString += str(token.coefficient) + '*' + tokenString += '(' + tokenString += tokensToString(token.tokens) + tokenString += ')' + if token.power != 1: + tokenString += '^(' + str(token.power) + ')' + elif isinstance(token, Sqrt): + tokenString += 'sqrt[' + if isinstance(token.power, Constant): + tokenString += tokensToString([token.power]) + elif isinstance(token.power, Variable): + tokenString += tokensToString([token.power]) + elif isinstance(token.power, Expression): + tokenString += tokensToString(token.power.tokens) + tokenString += '](' + if isinstance(token.operand, Constant): + tokenString += tokensToString([token.operand]) + elif isinstance(token.operand, Variable): + tokenString += tokensToString([token.operand]) + elif isinstance(token.operand, Expression): + tokenString += tokensToString(token.operand.tokens) + tokenString += ')' + elif isinstance(token, Logarithm): + if token.coefficient == 1: + pass + elif token.coefficient == -1: + tokenString += '-' + else: + tokenString += str(token.coefficient) + if token.operand is not None: + tokenString += token.value + if token.power != 1: + tokenString += "^" + "(" + str(token.power) + ")" + tokenString += "(" + tokensToString([token.operand]) + ")" + elif isinstance(token, Trigonometric): + if token.coefficient == 1: + pass + elif token.coefficient == -1: + tokenString += '-' + else: + tokenString += str(token.coefficient) + if token.operand is not None: + tokenString += token.value + if token.power != 1: + tokenString += "^" + "(" + str(token.power) + ")" + tokenString += "(" + tokensToString([token.operand]) + ")" + elif isinstance(token, Matrix): + tokenString += "[" + for i in range(token.dim[0]): + for j in range(token.dim[1]): + tokenString += tokensToString(token.value[i][j]) + tokenString += "," + tokenString = tokenString[:-1] + ";" + tokenString = tokenString[:-1] + "]" + + return tokenString + + + def getVariables(lTokens, rTokens=None, variables=None): """Finds all the variables present in the expression @@ -107,6 +208,7 @@ def getVariables(lTokens, rTokens=None, variables=None): Returns: variables {list} -- list of variables """ + #print("Alpha: "+tokensToString(lTokens)) if rTokens is None: rTokens = [] if variables is None: @@ -126,6 +228,8 @@ def getVariables(lTokens, rTokens=None, variables=None): variables.append(val) elif isinstance(token, Expression): variables.extend(getVariables(token.tokens, [], variables)) + #print("Beta: "+str(variables)) + #print() return variables From 90e0c7bc46814f670d6c738ee08614b637c6a9f4 Mon Sep 17 00:00:00 2001 From: Daniel Acosta Date: Sun, 21 Apr 2024 16:00:22 -0400 Subject: [PATCH 21/33] fixed visma button recoloring equation history box --- visma/gui/window.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/visma/gui/window.py b/visma/gui/window.py index 9cb52ea..3165046 100644 --- a/visma/gui/window.py +++ b/visma/gui/window.py @@ -636,6 +636,7 @@ def addEquation(self): self.myQListWidget.setItemWidget( myQListWidgetItem, myQCustomQWidget) i += 1 + myQCustomQWidget.setStyleSheet("background-color: rgb(210, 210, 210);") file.close() self.myQListWidget.resize(400, 300) self.myQListWidget.itemClicked.connect(self.Clicked) @@ -644,6 +645,8 @@ def addEquation(self): self.clearButton = QtWidgets.QPushButton('Clear equations') self.clearButton.clicked.connect(self.clearHistory) self.equationListVbox.addWidget(self.clearButton) + self.myQListWidget.setStyleSheet("background-color: rgb(210, 210, 210);") # colors inside of widget + self.clearButton.setStyleSheet("background-color: rgb(210, 210, 210)") # colors button return self.equationListVbox def inputsLayout(self, loadList="Greek"): From 2e16c5d92073f9ef65423051adfd7c422d2cc67b Mon Sep 17 00:00:00 2001 From: AceShooter Date: Sun, 21 Apr 2024 16:59:07 -0400 Subject: [PATCH 22/33] Colors in windows! --- visma/gui/logger.py | 1 + visma/gui/plotter.py | 1 + visma/gui/window.py | 7 ++++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/visma/gui/logger.py b/visma/gui/logger.py index 8f550d4..395ff16 100644 --- a/visma/gui/logger.py +++ b/visma/gui/logger.py @@ -16,6 +16,7 @@ def logTextBox(workspace): workspace.logBox = QTextEdit() workspace.logBox.setReadOnly(True) + workspace.logBox.setStyleSheet("background-color: rgb(210, 210, 210)") textLayout = QVBoxLayout() textLayout.addWidget(workspace.logBox) return textLayout diff --git a/visma/gui/plotter.py b/visma/gui/plotter.py index 562964b..7395e64 100644 --- a/visma/gui/plotter.py +++ b/visma/gui/plotter.py @@ -307,6 +307,7 @@ def plot(workspace, tokens=None): renderPlot(workspace, graphVars, func, variables, tokens) + def selectAdditionalVariable(var1): if var1 == 'z': var2 = 'a' diff --git a/visma/gui/window.py b/visma/gui/window.py index 3165046..52350d5 100644 --- a/visma/gui/window.py +++ b/visma/gui/window.py @@ -164,7 +164,7 @@ def __init__(self): def initUI(self): hbox = QHBoxLayout(self) - #self.setStyleSheet("background-color: rgb(120, 120, 120);") # changes color of nearly everything to blue + #self.setStyleSheet("background-color: rgb(210, 210, 210);") # changes color of nearly everything to blue #self.setStyleSheet("color: lightblue") # changes color of all text to blue #self.setStyleSheet("border: black") # removes button colors #self.setStyleSheet("border-color: blue") # changes nothing basically @@ -211,6 +211,8 @@ def initUI(self): self.tabPlot.tab1.setStatusTip("Visualize equation in 2D") self.tabPlot.tab2.setLayout(plotFigure3D(self)) self.tabPlot.tab2.setStatusTip("Visualize equation in 3D") + self.tabPlot.setStyleSheet("background-color: rgb(120, 120, 120)") + tabStepsLogs = QTabWidget() tabStepsLogs.tab1 = QWidget() @@ -221,6 +223,9 @@ def initUI(self): tabStepsLogs.tab1.setStatusTip("Step-by-step solver") tabStepsLogs.tab2.setLayout(logger.logTextBox(self)) tabStepsLogs.tab2.setStatusTip("Logger") + tabStepsLogs.tab1.setStyleSheet("background-color: rgb(120, 120, 120)") + tabStepsLogs.tab2.setStyleSheet("background-color: rgb(120, 120, 120)") + #tabStepsLogs.tab2. font = QtGui.QFont() font.setPointSize(16) From 4f101fc85fc45d68e4d7a7fc2ab299d66d65615f Mon Sep 17 00:00:00 2001 From: Daniel Acosta Date: Sun, 21 Apr 2024 17:04:31 -0400 Subject: [PATCH 23/33] messing with backgroung colors --- visma/gui/steps.py | 2 ++ visma/gui/window.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/visma/gui/steps.py b/visma/gui/steps.py index c05735e..41f7c80 100644 --- a/visma/gui/steps.py +++ b/visma/gui/steps.py @@ -18,9 +18,11 @@ def stepsFigure(workspace): """ workspace.stepsfigure = Figure() workspace.stepscanvas = FigureCanvas(workspace.stepsfigure) + workspace.stepsfigure.set_facecolor("none") workspace.stepsfigure.clear() workspace.scroll = QScrollArea() workspace.scroll.setWidget(workspace.stepscanvas) + workspace.scroll.setStyleSheet("background-color: rgb(210, 210, 210)") stepslayout = QVBoxLayout() stepslayout.addWidget(workspace.scroll) return stepslayout diff --git a/visma/gui/window.py b/visma/gui/window.py index 52350d5..7ca04f4 100644 --- a/visma/gui/window.py +++ b/visma/gui/window.py @@ -211,7 +211,7 @@ def initUI(self): self.tabPlot.tab1.setStatusTip("Visualize equation in 2D") self.tabPlot.tab2.setLayout(plotFigure3D(self)) self.tabPlot.tab2.setStatusTip("Visualize equation in 3D") - self.tabPlot.setStyleSheet("background-color: rgb(120, 120, 120)") + # self.tabPlot.setStyleSheet("background-color: rgb(120, 120, 120)") tabStepsLogs = QTabWidget() From 1859464d0936193dd84d55e7eb408dd5abcbb35c Mon Sep 17 00:00:00 2001 From: AceShooter Date: Sun, 21 Apr 2024 17:19:56 -0400 Subject: [PATCH 24/33] Colors in windows! --- visma/gui/window.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/visma/gui/window.py b/visma/gui/window.py index 7ca04f4..ccdc403 100644 --- a/visma/gui/window.py +++ b/visma/gui/window.py @@ -164,7 +164,7 @@ def __init__(self): def initUI(self): hbox = QHBoxLayout(self) - #self.setStyleSheet("background-color: rgb(210, 210, 210);") # changes color of nearly everything to blue + #self.setStyleSheet("background-color: blue;") # changes color of nearly everything to blue #self.setStyleSheet("color: lightblue") # changes color of all text to blue #self.setStyleSheet("border: black") # removes button colors #self.setStyleSheet("border-color: blue") # changes nothing basically @@ -176,7 +176,7 @@ def initUI(self): # self.equationList.addTab(self.equationList.tab2, "favourites") - self.equationList.setStyleSheet("background-color: rgb(120, 120, 120)") # colors whole widget + self.equationList.tab1.setStyleSheet("background-color: rgb(120, 120, 120)") # colors border of history widget self.equationList.tab1.setLayout(self.equationsLayout()) # color modified self.myQListWidget.setStyleSheet("background-color: rgb(210, 210, 210);") # colors inside of widget self.clearButton.setStyleSheet("background-color: rgb(210, 210, 210)") # colors button @@ -194,8 +194,8 @@ def initUI(self): inputSpace.tab2.setLayout(preferenceLayout(self)) inputSpace.tab1.setStatusTip("Input characters") inputSpace.setFixedHeight(200) - inputSpace.tab1.setStyleSheet("background-color: rgb(120, 120, 120)") - inputSpace.tab2.setStyleSheet("background-color: rgb(210, 210, 210)") + inputSpace.tab1.setStyleSheet("background-color: rgb(120, 120, 120)") # colors border of step by step + inputSpace.tab2.setStyleSheet("background-color: rgb(210, 210, 210)") # colors border of logger buttonSpace = QWidget() buttonSpace.setLayout(self.buttonsLayout()) @@ -211,7 +211,8 @@ def initUI(self): self.tabPlot.tab1.setStatusTip("Visualize equation in 2D") self.tabPlot.tab2.setLayout(plotFigure3D(self)) self.tabPlot.tab2.setStatusTip("Visualize equation in 3D") - # self.tabPlot.setStyleSheet("background-color: rgb(120, 120, 120)") + self.tabPlot.tab1.setStyleSheet("background-color: rgb(120, 120, 120)") + self.tabPlot.tab2.setStyleSheet("background-color: rgb(120, 120, 120)") tabStepsLogs = QTabWidget() @@ -315,6 +316,7 @@ def equationsLayout(self): self.myQListWidget.addItem(myQListWidgetItem) self.myQListWidget.setItemWidget( myQListWidgetItem, myQCustomQWidget) + myQCustomQWidget.setStyleSheet("background-color: rgb(210, 210, 210);") # colors border around equations self.myQListWidget.resize(400, 300) self.equationListVbox.addWidget(self.myQListWidget) self.myQListWidget.itemClicked.connect(self.Clicked) From a4145bbf13a0120f30380eaf4ba71660b7e1a2c6 Mon Sep 17 00:00:00 2001 From: Daniel Acosta Date: Sun, 21 Apr 2024 17:22:05 -0400 Subject: [PATCH 25/33] messed with background colors --- visma/gui/steps.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/visma/gui/steps.py b/visma/gui/steps.py index 41f7c80..e438acb 100644 --- a/visma/gui/steps.py +++ b/visma/gui/steps.py @@ -18,11 +18,11 @@ def stepsFigure(workspace): """ workspace.stepsfigure = Figure() workspace.stepscanvas = FigureCanvas(workspace.stepsfigure) - workspace.stepsfigure.set_facecolor("none") + workspace.stepsfigure.set_facecolor("none") # make figure transparent so that background of scrollbar is visible workspace.stepsfigure.clear() workspace.scroll = QScrollArea() workspace.scroll.setWidget(workspace.stepscanvas) - workspace.scroll.setStyleSheet("background-color: rgb(210, 210, 210)") + workspace.scroll.setStyleSheet("background-color: rgb(210, 210, 210)") # color background of scrollbar stepslayout = QVBoxLayout() stepslayout.addWidget(workspace.scroll) return stepslayout From 2838acdec989f6a2277bcf3cc77ecb2f2c5b8d40 Mon Sep 17 00:00:00 2001 From: AceShooter Date: Sun, 21 Apr 2024 18:11:43 -0400 Subject: [PATCH 26/33] Colors in windows! --- visma/gui/logger.py | 2 +- visma/gui/plotter.py | 5 +++++ visma/gui/window.py | 42 ++++++++++++++++++++++++++++++++---------- 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/visma/gui/logger.py b/visma/gui/logger.py index 395ff16..f4ee87e 100644 --- a/visma/gui/logger.py +++ b/visma/gui/logger.py @@ -16,7 +16,7 @@ def logTextBox(workspace): workspace.logBox = QTextEdit() workspace.logBox.setReadOnly(True) - workspace.logBox.setStyleSheet("background-color: rgb(210, 210, 210)") + workspace.logBox.setStyleSheet("background-color: rgb(210, 210, 210)") # colors inside of logger textLayout = QVBoxLayout() textLayout.addWidget(workspace.logBox) return textLayout diff --git a/visma/gui/plotter.py b/visma/gui/plotter.py index 7395e64..06c7631 100644 --- a/visma/gui/plotter.py +++ b/visma/gui/plotter.py @@ -193,6 +193,8 @@ class NavigationCustomToolbar(NavigationToolbar): layout = QVBoxLayout() layout.addWidget(workspace.canvas2D) layout.addWidget(workspace.toolbar2D) + workspace.figure2D.set_facecolor("none") # makes color transparent + workspace.canvas2D.setStyleSheet("background-color: rgb(210, 210, 210)") return layout @@ -216,6 +218,9 @@ class NavigationCustomToolbar(NavigationToolbar): layout = QVBoxLayout() layout.addWidget(workspace.canvas3D) layout.addWidget(workspace.toolbar3D) + workspace.figure3D.set_facecolor("none") # makes color transparent + workspace.canvas3D.setStyleSheet("background-color: rgb(210, 210, 210)") + return layout diff --git a/visma/gui/window.py b/visma/gui/window.py index ccdc403..5e80d75 100644 --- a/visma/gui/window.py +++ b/visma/gui/window.py @@ -35,7 +35,7 @@ from visma.solvers.simulEqn import simulSolver from visma.transform.factorization import factorize from visma.gui import logger - +from PyQt5.QtGui import QPalette, QColor class Window(QtWidgets.QMainWindow): @@ -164,10 +164,14 @@ def __init__(self): def initUI(self): hbox = QHBoxLayout(self) - #self.setStyleSheet("background-color: blue;") # changes color of nearly everything to blue + #self.setStyleSheet("border-color: rgb(60, 60, 60);") # changes color of nearly everything to blue #self.setStyleSheet("color: lightblue") # changes color of all text to blue #self.setStyleSheet("border: black") # removes button colors - #self.setStyleSheet("border-color: blue") # changes nothing basically + # self.setStyleSheet(""" + # background-color: rgb(90, 90, 90); + # border-color: rgb(90, 90, 90); + # """ + # ) # changes nothing basically self.equationList = QTabWidget() self.equationList.tab1 = QWidget() @@ -265,6 +269,15 @@ def initUI(self): self.previousAnswer = '' + self.textedit.setStyleSheet("background-color: rgb(210, 210, 210)") + + self.setStyleSheet( + """ + background-color: rgb(90, 90, 90); + border-color: rgb(90, 90, 90); + """ + ) + self.logBox.append(logger.info('UI Initialised...')) @@ -386,6 +399,11 @@ def buttonsLayout(self): self.buttonSplitter.addWidget(topButtonSplitter) self.buttonSplitter.addWidget(self.bottomButton) vbox.addWidget(self.buttonSplitter) + self.interactionModeButton.setStyleSheet(""" + background-color: rgb(210, 210, 210); + font-size: 16px; + """ + ) return vbox def interactionMode(self): @@ -534,6 +552,11 @@ def interactionMode(self): self.onSolvePress(opButtons[i * 2 + j])) self.solutionOptionsBox.addWidget( self.solutionButtons[(i, j)], i, j) + self.solutionButtons[(i, j)].setStyleSheet(""" + background-color: rgb(210, 210, 210); + font-size: 16px; + """ + ) else: self.bottomButton.setParent(None) self.solutionWidget = QWidget() @@ -547,6 +570,11 @@ def interactionMode(self): self.onSolvePress(opButtons[i * 2 + j])) self.solutionOptionsBox.addWidget( self.solutionButtons[(i, j)], i, j) + self.solutionButtons[(i, j)].setStyleSheet(""" + background-color: rgb(210, 210, 210); + font-size: 16px; + """ + ) self.solutionWidget.setLayout(self.solutionOptionsBox) self.buttonSplitter.addWidget(self.solutionWidget) self.buttonSet = True @@ -666,7 +694,7 @@ def inputsLayout(self, loadList="Greek"): if (i * 10 + j) < len(self.inputGreek): self.buttons[(i, j)] = QtWidgets.QPushButton( self.inputGreek[i * 10 + j]) - self.checkForColorChange(self.buttons[(i, j)]) + self.checkForColorChange(self.buttons[(i, j)]) # color change function self.buttons[(i, j)].resize(100, 100) self.buttons[(i, j)].clicked.connect( self.onInputPress(self.inputGreek[i * 10 + j])) @@ -703,12 +731,6 @@ def checkForColorChange(self, button): # changes button color button.setStyleSheet("background-color: rgb(210, 210, 210)") - """if self.button.text() == "Ans": - self.button.setStyleSheet("background-color: green;") - else: - self.buttons[(i, j)].setStyleSheet("background-color: orange;")""" - - def onActivated(self, text): for i in reversed(range(self.inputBox.count())): From 86d07bcb6b84f19959b1701d2c34e2d7fad04c57 Mon Sep 17 00:00:00 2001 From: WhetBoi Date: Sun, 21 Apr 2024 18:26:23 -0400 Subject: [PATCH 27/33] DOIASBFIEASB --- visma/gui/window.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/visma/gui/window.py b/visma/gui/window.py index 5e80d75..72c2c54 100644 --- a/visma/gui/window.py +++ b/visma/gui/window.py @@ -77,6 +77,8 @@ def initUI(self): helpMenu = menubar.addMenu('&Help') helpMenu.addAction(wikiAction) self.workSpace = WorkSpace() + self.setStyleSheet('background-color: rgb(90, 90, 90);') + menubar.setStyleSheet("background-color: rgb(210, 210, 210)") self.setCentralWidget(self.workSpace) self.GUIwidth = 1300 self.GUIheight = 900 @@ -188,6 +190,7 @@ def initUI(self): self.equationList.tab1.setStatusTip("Track of old equations") self.equationList.setFixedWidth(300) + self.equationList.setDocumentMode(True) # removes white borders inputSpace = QTabWidget() inputSpace.tab1 = QWidget() @@ -200,6 +203,7 @@ def initUI(self): inputSpace.setFixedHeight(200) inputSpace.tab1.setStyleSheet("background-color: rgb(120, 120, 120)") # colors border of step by step inputSpace.tab2.setStyleSheet("background-color: rgb(210, 210, 210)") # colors border of logger + inputSpace.setDocumentMode(True) # removes white borders buttonSpace = QWidget() buttonSpace.setLayout(self.buttonsLayout()) @@ -215,9 +219,10 @@ def initUI(self): self.tabPlot.tab1.setStatusTip("Visualize equation in 2D") self.tabPlot.tab2.setLayout(plotFigure3D(self)) self.tabPlot.tab2.setStatusTip("Visualize equation in 3D") - self.tabPlot.tab1.setStyleSheet("background-color: rgb(120, 120, 120)") + self.tabPlot.tab1.setStyleSheet("background-color: rgb(120, 120, 120)") # colors plots self.tabPlot.tab2.setStyleSheet("background-color: rgb(120, 120, 120)") + self.tabPlot.setDocumentMode(True) # removes white borders tabStepsLogs = QTabWidget() tabStepsLogs.tab1 = QWidget() @@ -230,7 +235,8 @@ def initUI(self): tabStepsLogs.tab2.setStatusTip("Logger") tabStepsLogs.tab1.setStyleSheet("background-color: rgb(120, 120, 120)") tabStepsLogs.tab2.setStyleSheet("background-color: rgb(120, 120, 120)") - #tabStepsLogs.tab2. + + tabStepsLogs.setDocumentMode(True) # removes white borders font = QtGui.QFont() font.setPointSize(16) From ac6429af649f13346544d94af6739283af5a9efa Mon Sep 17 00:00:00 2001 From: WhetBoi Date: Sun, 21 Apr 2024 18:40:51 -0400 Subject: [PATCH 28/33] Fixed colors n shit --- visma/gui/qsolver.py | 3 +-- visma/gui/window.py | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/visma/gui/qsolver.py b/visma/gui/qsolver.py index adfccaf..a4c8152 100644 --- a/visma/gui/qsolver.py +++ b/visma/gui/qsolver.py @@ -81,8 +81,7 @@ def qSolveFigure(workspace): """ bg = workspace.palette().window().color() - bgcolor = (bg.redF(), bg.greenF(), bg.blueF()) - workspace.qSolveFigure = Figure(edgecolor=bgcolor, facecolor=bgcolor) + workspace.qSolveFigure = Figure(edgecolor="none", facecolor="none") workspace.solcanvas = FigureCanvas(workspace.qSolveFigure) workspace.qSolveFigure.clear() qSolLayout = QtWidgets.QVBoxLayout() diff --git a/visma/gui/window.py b/visma/gui/window.py index 72c2c54..3c1f9e6 100644 --- a/visma/gui/window.py +++ b/visma/gui/window.py @@ -251,6 +251,7 @@ def initUI(self): quickSolve.setLayout(qSolveFigure(self)) quickSolve.setFixedHeight(45) quickSolve.setStatusTip("Quick solver") + quickSolve.setStyleSheet("background-color: rgb(150, 150, 150)") splitter4 = QSplitter(Qt.Vertical) splitter4.addWidget(self.textedit) @@ -723,18 +724,25 @@ def inputsLayout(self, loadList="Greek"): return inputLayout def checkForColorChange(self, button): # changes button color + color = "rgb(210, 210, 210)" + bold = "normal" match button.text(): case "Ans": - button.setStyleSheet("font-weight: bold;") - button.setStyleSheet("background-color: green;") + color = "green" + bold = "bold" case "C" | "DEL": - button.setStyleSheet("font-weight: bold;") - button.setStyleSheet("background-color: red;") #rgb(34, 34, 34) + color = "red" + bold = "bold" case "+" | "*" | "/" | "-": - button.setStyleSheet("font-weight: bold;") - button.setStyleSheet("background-color: orange;") - case _: - button.setStyleSheet("background-color: rgb(210, 210, 210)") + color = "orange" + bold = "bold" + + button.setStyleSheet(f""" + background-color: {color}; + font-weight: {bold}; + font-size: 16px; + """ + ) From c0d00a94a6993454c53e7e1f2c780a28bee65e91 Mon Sep 17 00:00:00 2001 From: Daniel Acosta Date: Sun, 21 Apr 2024 18:42:52 -0400 Subject: [PATCH 29/33] Added comments --- visma/gui/window.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/visma/gui/window.py b/visma/gui/window.py index 72c2c54..e6dee0e 100644 --- a/visma/gui/window.py +++ b/visma/gui/window.py @@ -219,8 +219,8 @@ def initUI(self): self.tabPlot.tab1.setStatusTip("Visualize equation in 2D") self.tabPlot.tab2.setLayout(plotFigure3D(self)) self.tabPlot.tab2.setStatusTip("Visualize equation in 3D") - self.tabPlot.tab1.setStyleSheet("background-color: rgb(120, 120, 120)") # colors plots - self.tabPlot.tab2.setStyleSheet("background-color: rgb(120, 120, 120)") + self.tabPlot.tab1.setStyleSheet("background-color: rgb(120, 120, 120)") # colors 2D plots + self.tabPlot.tab2.setStyleSheet("background-color: rgb(120, 120, 120)") # colors 3D plots self.tabPlot.setDocumentMode(True) # removes white borders From c4d0e1b7bf8ec53669619688b854ee4774207376 Mon Sep 17 00:00:00 2001 From: Daniel Acosta Date: Sun, 21 Apr 2024 18:43:27 -0400 Subject: [PATCH 30/33] Added comments --- visma/gui/qsolver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/visma/gui/qsolver.py b/visma/gui/qsolver.py index a4c8152..9a6e36f 100644 --- a/visma/gui/qsolver.py +++ b/visma/gui/qsolver.py @@ -81,7 +81,7 @@ def qSolveFigure(workspace): """ bg = workspace.palette().window().color() - workspace.qSolveFigure = Figure(edgecolor="none", facecolor="none") + workspace.qSolveFigure = Figure(edgecolor="none", facecolor="none") # Make transparent so parent can override background workspace.solcanvas = FigureCanvas(workspace.qSolveFigure) workspace.qSolveFigure.clear() qSolLayout = QtWidgets.QVBoxLayout() From 174bd1060ea6eb9c346115ab9d2ed0738e30b295 Mon Sep 17 00:00:00 2001 From: AceShooter Date: Sun, 21 Apr 2024 21:14:06 -0400 Subject: [PATCH 31/33] Colors in windows! --- visma/functions/structure.py | 98 ++++++++++++++++++++++++++++++++++++ visma/gui/window.py | 9 ++-- visma/io/tokenize.py | 2 - visma/simplify/simplify.py | 65 ------------------------ 4 files changed, 104 insertions(+), 70 deletions(-) diff --git a/visma/functions/structure.py b/visma/functions/structure.py index 8e389ab..521f7e9 100644 --- a/visma/functions/structure.py +++ b/visma/functions/structure.py @@ -1,6 +1,104 @@ import copy +def tokensToString(tokens): + """Converts tokens to text string + + Arguments: + tokens {list} -- list of function tokens + + Returns: + tokenString {string} -- equation string + """ + # FIXME: tokensToString method + tokenString = '' + for token in tokens: + if isinstance(token, Constant): + if isinstance(token.value, list): + for j, val in token.value: + if token['power'][j] != 1: + tokenString += (str(val) + '^(' + str(token.power[j]) + ')') + else: + tokenString += str(val) + elif isNumber(token.value): + if token.power != 1: + tokenString += (str(token.value) + '^(' + str(token.power) + ')') + else: + tokenString += str(token.value) + elif isinstance(token, Variable): + if token.coefficient == 1: + pass + elif token.coefficient == -1: + tokenString += '-' + else: + tokenString += str(token.coefficient) + for j, val in enumerate(token.value): + if token.power[j] != 1: + tokenString += (str(val) + '^(' + str(token.power[j]) + ')') + else: + tokenString += str(val) + elif isinstance(token, Binary): + tokenString += ' ' + str(token.value) + ' ' + elif isinstance(token, Expression): + if token.coefficient != 1: + tokenString += str(token.coefficient) + '*' + tokenString += '(' + tokenString += tokensToString(token.tokens) + tokenString += ')' + if token.power != 1: + tokenString += '^(' + str(token.power) + ')' + elif isinstance(token, Sqrt): + tokenString += 'sqrt[' + if isinstance(token.power, Constant): + tokenString += tokensToString([token.power]) + elif isinstance(token.power, Variable): + tokenString += tokensToString([token.power]) + elif isinstance(token.power, Expression): + tokenString += tokensToString(token.power.tokens) + tokenString += '](' + if isinstance(token.operand, Constant): + tokenString += tokensToString([token.operand]) + elif isinstance(token.operand, Variable): + tokenString += tokensToString([token.operand]) + elif isinstance(token.operand, Expression): + tokenString += tokensToString(token.operand.tokens) + tokenString += ')' + elif isinstance(token, Logarithm): + if token.coefficient == 1: + pass + elif token.coefficient == -1: + tokenString += '-' + else: + tokenString += str(token.coefficient) + if token.operand is not None: + tokenString += token.value + if token.power != 1: + tokenString += "^" + "(" + str(token.power) + ")" + tokenString += "(" + tokensToString([token.operand]) + ")" + elif isinstance(token, Trigonometric): + if token.coefficient == 1: + pass + elif token.coefficient == -1: + tokenString += '-' + else: + tokenString += str(token.coefficient) + if token.operand is not None: + tokenString += token.value + if token.power != 1: + tokenString += "^" + "(" + str(token.power) + ")" + tokenString += "(" + tokensToString([token.operand]) + ")" + elif isinstance(token, Matrix): + tokenString += "[" + for i in range(token.dim[0]): + for j in range(token.dim[1]): + tokenString += tokensToString(token.value[i][j]) + tokenString += "," + tokenString = tokenString[:-1] + ";" + tokenString = tokenString[:-1] + "]" + + return tokenString + + class Function(object): """Basis function class for all functions diff --git a/visma/gui/window.py b/visma/gui/window.py index bc806f4..8cb0ebc 100644 --- a/visma/gui/window.py +++ b/visma/gui/window.py @@ -406,7 +406,8 @@ def buttonsLayout(self): self.buttonSplitter.addWidget(topButtonSplitter) self.buttonSplitter.addWidget(self.bottomButton) vbox.addWidget(self.buttonSplitter) - self.interactionModeButton.setStyleSheet(""" + self.interactionModeButton.setStyleSheet( + """ background-color: rgb(210, 210, 210); font-size: 16px; """ @@ -559,7 +560,8 @@ def interactionMode(self): self.onSolvePress(opButtons[i * 2 + j])) self.solutionOptionsBox.addWidget( self.solutionButtons[(i, j)], i, j) - self.solutionButtons[(i, j)].setStyleSheet(""" + self.solutionButtons[(i, j)].setStyleSheet( + """ background-color: rgb(210, 210, 210); font-size: 16px; """ @@ -577,7 +579,8 @@ def interactionMode(self): self.onSolvePress(opButtons[i * 2 + j])) self.solutionOptionsBox.addWidget( self.solutionButtons[(i, j)], i, j) - self.solutionButtons[(i, j)].setStyleSheet(""" + self.solutionButtons[(i, j)].setStyleSheet( + """ background-color: rgb(210, 210, 210); font-size: 16px; """ diff --git a/visma/io/tokenize.py b/visma/io/tokenize.py index d0a0ac7..49dffbc 100644 --- a/visma/io/tokenize.py +++ b/visma/io/tokenize.py @@ -25,7 +25,6 @@ from visma.matrix.structure import Matrix from visma.matrix.checks import isMatrix from visma.io.parser import latexToTerms -# from visma.gui import logger symbols = ['+', '-', '*', '/', '(', ')', '{', '}', '[', ']', '^', '=', '<', '>', '<=', '>=', ',', ';', '$'] greek = [u'\u03B1', u'\u03B2', u'\u03B3'] @@ -1379,7 +1378,6 @@ def tokenizer(eqnString): _, tokens = constantConversion(preprocess(eqnString)) return tokens - def changeToken(tokens, variables, scope_times=0): if len(variables) != 0: diff --git a/visma/simplify/simplify.py b/visma/simplify/simplify.py index ccc7ad2..9ea3253 100644 --- a/visma/simplify/simplify.py +++ b/visma/simplify/simplify.py @@ -443,68 +443,3 @@ def simplifification(tokens): tokens, animation = postSimplification(tokens, animation) token_string = tokensToString(tokens) return tokens, availableOperations, token_string, animation, comments - - -''' -def defineScopeVariable(variable, scope): - token = copy.deepcopy(variable) - local_scope = copy.deepcopy(scope) - if isinstance(token.value, list): - for j, val in enumerate(token.value): - if val.__class__ in [Binary, Variable, Constant, Expression]: - local_scope_value = copy.deepcopy(local_scope) - local_scope_value.extend(-1) - local_scope_value.extend(j) - val.scope = local_scope_value - - if isinstance(token.power, list): - for j, val in enumerate(token.value): - if val.__class__ in [Binary, Variable, Constant, Expression]: - local_scope_value = copy.deepcopy(local_scope) - local_scope_value.extend(-2) - local_scope_value.extend(j) - val.scope = local_scope_value - - return token - - -def defineScopeConstant(constant, scope): - token = copy.deepcopy(constant) - local_scope = copy.deepcopy(scope) - if isinstance(token.value, list): - for j, val in enumerate(token.value): - if val.__class__ in [Binary, Variable, Constant, Expression]: - local_scope_value = copy.deepcopy(local_scope) - local_scope_value.extend(-1) - local_scope_value.extend(j) - val.scope = local_scope_value - - if isinstance(token.power, list): - for j, val in enumerate(token.value): - if val.__class__ in [Binary, Variable, Constant, Expression]: - local_scope_value = copy.deepcopy(local_scope) - local_scope_value.extend(-2) - local_scope_value.extend(j) - val.scope = local_scope_value - return token - - -def defineScope(tokens, scope=None): - if scope is None: - scope = [] - i = 0 - for token in tokens: - local_scope = copy.deepcopy(scope) - local_scope.extend(i) - token.scope = local_scope - if isinstance(token, Variable): - token = defineScopeVariable(token, copy.deepcopy(local_scope)) - elif isinstance(token, Constant): - token = defineScopeConstant(token, copy.deepcopy(local_scope)) - elif isinstance(token, Expression): - token.tokens = defineScope(token.tokens, local_scope) - elif isinstance(token, Binary): - pass - i += 1 - return tokens -''' From 99cfebd17ddefc1196481a6f6dc8e9a5380b25cb Mon Sep 17 00:00:00 2001 From: AceShooter Date: Sun, 21 Apr 2024 21:15:27 -0400 Subject: [PATCH 32/33] Refactoring shennanigans --- visma/functions/structure.py | 172 +++++++++++++++++------------------ 1 file changed, 86 insertions(+), 86 deletions(-) diff --git a/visma/functions/structure.py b/visma/functions/structure.py index 521f7e9..4ef7624 100644 --- a/visma/functions/structure.py +++ b/visma/functions/structure.py @@ -11,92 +11,92 @@ def tokensToString(tokens): tokenString {string} -- equation string """ # FIXME: tokensToString method - tokenString = '' - for token in tokens: - if isinstance(token, Constant): - if isinstance(token.value, list): - for j, val in token.value: - if token['power'][j] != 1: - tokenString += (str(val) + '^(' + str(token.power[j]) + ')') - else: - tokenString += str(val) - elif isNumber(token.value): - if token.power != 1: - tokenString += (str(token.value) + '^(' + str(token.power) + ')') - else: - tokenString += str(token.value) - elif isinstance(token, Variable): - if token.coefficient == 1: - pass - elif token.coefficient == -1: - tokenString += '-' - else: - tokenString += str(token.coefficient) - for j, val in enumerate(token.value): - if token.power[j] != 1: - tokenString += (str(val) + '^(' + str(token.power[j]) + ')') - else: - tokenString += str(val) - elif isinstance(token, Binary): - tokenString += ' ' + str(token.value) + ' ' - elif isinstance(token, Expression): - if token.coefficient != 1: - tokenString += str(token.coefficient) + '*' - tokenString += '(' - tokenString += tokensToString(token.tokens) - tokenString += ')' - if token.power != 1: - tokenString += '^(' + str(token.power) + ')' - elif isinstance(token, Sqrt): - tokenString += 'sqrt[' - if isinstance(token.power, Constant): - tokenString += tokensToString([token.power]) - elif isinstance(token.power, Variable): - tokenString += tokensToString([token.power]) - elif isinstance(token.power, Expression): - tokenString += tokensToString(token.power.tokens) - tokenString += '](' - if isinstance(token.operand, Constant): - tokenString += tokensToString([token.operand]) - elif isinstance(token.operand, Variable): - tokenString += tokensToString([token.operand]) - elif isinstance(token.operand, Expression): - tokenString += tokensToString(token.operand.tokens) - tokenString += ')' - elif isinstance(token, Logarithm): - if token.coefficient == 1: - pass - elif token.coefficient == -1: - tokenString += '-' - else: - tokenString += str(token.coefficient) - if token.operand is not None: - tokenString += token.value - if token.power != 1: - tokenString += "^" + "(" + str(token.power) + ")" - tokenString += "(" + tokensToString([token.operand]) + ")" - elif isinstance(token, Trigonometric): - if token.coefficient == 1: - pass - elif token.coefficient == -1: - tokenString += '-' - else: - tokenString += str(token.coefficient) - if token.operand is not None: - tokenString += token.value - if token.power != 1: - tokenString += "^" + "(" + str(token.power) + ")" - tokenString += "(" + tokensToString([token.operand]) + ")" - elif isinstance(token, Matrix): - tokenString += "[" - for i in range(token.dim[0]): - for j in range(token.dim[1]): - tokenString += tokensToString(token.value[i][j]) - tokenString += "," - tokenString = tokenString[:-1] + ";" - tokenString = tokenString[:-1] + "]" - - return tokenString + # tokenString = '' + # for token in tokens: + # if isinstance(token, Constant): + # if isinstance(token.value, list): + # for j, val in token.value: + # if token['power'][j] != 1: + # tokenString += (str(val) + '^(' + str(token.power[j]) + ')') + # else: + # tokenString += str(val) + # elif isNumber(token.value): + # if token.power != 1: + # tokenString += (str(token.value) + '^(' + str(token.power) + ')') + # else: + # tokenString += str(token.value) + # elif isinstance(token, Variable): + # if token.coefficient == 1: + # pass + # elif token.coefficient == -1: + # tokenString += '-' + # else: + # tokenString += str(token.coefficient) + # for j, val in enumerate(token.value): + # if token.power[j] != 1: + # tokenString += (str(val) + '^(' + str(token.power[j]) + ')') + # else: + # tokenString += str(val) + # elif isinstance(token, Binary): + # tokenString += ' ' + str(token.value) + ' ' + # elif isinstance(token, Expression): + # if token.coefficient != 1: + # tokenString += str(token.coefficient) + '*' + # tokenString += '(' + # tokenString += tokensToString(token.tokens) + # tokenString += ')' + # if token.power != 1: + # tokenString += '^(' + str(token.power) + ')' + # elif isinstance(token, Sqrt): + # tokenString += 'sqrt[' + # if isinstance(token.power, Constant): + # tokenString += tokensToString([token.power]) + # elif isinstance(token.power, Variable): + # tokenString += tokensToString([token.power]) + # elif isinstance(token.power, Expression): + # tokenString += tokensToString(token.power.tokens) + # tokenString += '](' + # if isinstance(token.operand, Constant): + # tokenString += tokensToString([token.operand]) + # elif isinstance(token.operand, Variable): + # tokenString += tokensToString([token.operand]) + # elif isinstance(token.operand, Expression): + # tokenString += tokensToString(token.operand.tokens) + # tokenString += ')' + # elif isinstance(token, Logarithm): + # if token.coefficient == 1: + # pass + # elif token.coefficient == -1: + # tokenString += '-' + # else: + # tokenString += str(token.coefficient) + # if token.operand is not None: + # tokenString += token.value + # if token.power != 1: + # tokenString += "^" + "(" + str(token.power) + ")" + # tokenString += "(" + tokensToString([token.operand]) + ")" + # elif isinstance(token, Trigonometric): + # if token.coefficient == 1: + # pass + # elif token.coefficient == -1: + # tokenString += '-' + # else: + # tokenString += str(token.coefficient) + # if token.operand is not None: + # tokenString += token.value + # if token.power != 1: + # tokenString += "^" + "(" + str(token.power) + ")" + # tokenString += "(" + tokensToString([token.operand]) + ")" + # elif isinstance(token, Matrix): + # tokenString += "[" + # for i in range(token.dim[0]): + # for j in range(token.dim[1]): + # tokenString += tokensToString(token.value[i][j]) + # tokenString += "," + # tokenString = tokenString[:-1] + ";" + # tokenString = tokenString[:-1] + "]" + # + # return tokenString class Function(object): From 1cbc908b8391b74a8ace4b6de2b377240466ff8d Mon Sep 17 00:00:00 2001 From: Daniel Acosta Date: Sun, 21 Apr 2024 21:37:29 -0400 Subject: [PATCH 33/33] Replaced snake_case entities with camelCase entities --- visma/io/parser.py | 48 +++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/visma/io/parser.py b/visma/io/parser.py index bcfd9f9..6bcf94a 100644 --- a/visma/io/parser.py +++ b/visma/io/parser.py @@ -37,9 +37,9 @@ def resultLatex(equationTokens, operation, comments, solutionType, simul=False, finalSteps = 'INPUT: ' + '(Multiple ' + r'$' + ' equations)' + r'$' + '\n' finalSteps += 'OPERATION: ' + operation + '\n' # print(equationLatex[-1]) - rounded_step = round_equation_latex_output(equationLatex, -1, 6) + roundedStep = roundEquationLatexOutput(equationLatex, -1, 6) # print(equationLatex[-1]) - finalSteps += 'OUTPUT: ' + r'$' + rounded_step + r'$' + 2*'\n' + finalSteps += 'OUTPUT: ' + r'$' + roundedStep + r'$' + 2*'\n' # finalSteps += 'OUTPUT: ' + r'$' + equationLatex[-1] + r'$' + 2*'\n' for i, _ in enumerate(equationLatex): @@ -47,30 +47,30 @@ def resultLatex(equationTokens, operation, comments, solutionType, simul=False, finalSteps += '(' + str(comments[i][0]) + ')' + '\n' if i == len(equationLatex) - 1: # print(equationLatex[i]) - rounded_step = round_equation_latex_output(equationLatex, i, 6) + roundedStep = roundEquationLatexOutput(equationLatex, i, 6) # print(equationLatex[i]) pass else: # print(equationLatex[i]) - rounded_step = round_equation_latex_output(equationLatex, i, 2) + roundedStep = roundEquationLatexOutput(equationLatex, i, 2) # print(equationLatex[i]) pass - finalSteps += r'$' + rounded_step + r'$' + 2*"\n" + finalSteps += r'$' + roundedStep + r'$' + 2*"\n" # finalSteps += '\n' + r'$' + equationLatex[-1] + r'$' + 2*'\n' elif comments[i] != [] and equationLatex[i] == '': finalSteps += '\n' + '[' + str(comments[i][0]) + ']' + '\n' elif comments[i] == [] and equationLatex[i] != '': if i == len(equationLatex) - 1: # print(equationLatex[i]) - rounded_step = round_equation_latex_output(equationLatex, i, 6) + roundedStep = roundEquationLatexOutput(equationLatex, i, 6) # print(equationLatex[i]) pass else: # print(equationLatex[i]) - rounded_step = round_equation_latex_output(equationLatex, i, 2) + roundedStep = roundEquationLatexOutput(equationLatex, i, 2) # print(equationLatex[i]) pass - finalSteps += '\n' + r'$' + rounded_step + r'$' + 2*'\n' + finalSteps += '\n' + r'$' + roundedStep + r'$' + 2*'\n' # finalSteps += '\n' + r'$' + equationLatex[i] + r'$' + 2*'\n' if mathError(equationTokens[-1]) and (not simul): @@ -78,32 +78,32 @@ def resultLatex(equationTokens, operation, comments, solutionType, simul=False, return finalSteps -def round_equation_latex_output(equationLatex, index, round_length): +def roundEquationLatexOutput(equationLatex, index, roundLength): equationSlice = equationLatex[index][0:] while '{' in equationSlice: - open_bracket_index = equationSlice.index("{") - close_bracket_index = equationSlice.index("}") - temp_open_bracket_index = open_bracket_index - while '{' in equationSlice[temp_open_bracket_index + 1: close_bracket_index] and close_bracket_index != len(equationSlice) - 1: - temp_open_bracket_index = equationSlice[open_bracket_index + 1: close_bracket_index].index('{') + open_bracket_index + 1 - close_bracket_index = equationSlice[close_bracket_index + 1:].index('}') + close_bracket_index + 1 - # print(equationSlice[open_bracket_index:close_bracket_index + 1]) - # print(open_bracket_index, close_bracket_index) - if not equationSlice[close_bracket_index - 1].isnumeric(): + openBracketIndex = equationSlice.index("{") + closeBracketIndex = equationSlice.index("}") + temp_openBracketIndex = openBracketIndex + while '{' in equationSlice[temp_openBracketIndex + 1: closeBracketIndex] and closeBracketIndex != len(equationSlice) - 1: + temp_openBracketIndex = equationSlice[openBracketIndex + 1: closeBracketIndex].index('{') + openBracketIndex + 1 + closeBracketIndex = equationSlice[closeBracketIndex + 1:].index('}') + closeBracketIndex + 1 + # print(equationSlice[openBracketIndex:closeBracketIndex + 1]) + # print(openBracketIndex, closeBracketIndex) + if not equationSlice[closeBracketIndex - 1].isnumeric(): value = '' try: - value = round(float(equationSlice[:open_bracket_index]), round_length) + value = round(float(equationSlice[:openBracketIndex]), roundLength) except ValueError: pass equationLatex[index] = equationLatex[index][0:equationLatex[index].index(equationSlice)] \ - + str(value) + equationSlice[open_bracket_index:] - equationSlice = equationSlice[close_bracket_index + 1:] + + str(value) + equationSlice[openBracketIndex:] + equationSlice = equationSlice[closeBracketIndex + 1:] pass else: - value = round(float(equationSlice[open_bracket_index + 1:close_bracket_index]), round_length) + value = round(float(equationSlice[openBracketIndex + 1:closeBracketIndex]), roundLength) equationLatex[index] = equationLatex[index][0:equationLatex[index].index(equationSlice)] \ - + equationSlice[0: open_bracket_index] + '{' + str(value) + '}' + equationSlice[close_bracket_index + 1:] - equationSlice = equationSlice[close_bracket_index + 1:] + + equationSlice[0: openBracketIndex] + '{' + str(value) + '}' + equationSlice[closeBracketIndex + 1:] + equationSlice = equationSlice[closeBracketIndex + 1:] return equationLatex[index] def resultStringCLI(equationTokens, operation, comments, solutionType, simul=False, mat=False):