Skip to content

Commit

Permalink
Merge pull request #5 from dnparadice/mbp19
Browse files Browse the repository at this point in the history
Updates: readme and bugfixes
  • Loading branch information
dnparadice authored Jun 11, 2024
2 parents 941c91a + b14a4fa commit 6c789eb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
36 changes: 17 additions & 19 deletions calc.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

import numpy as np
import math as math # consistency collides with conciseness here and consistency wins
import math as math
import matplotlib.pyplot as plt
from copy import copy
import inspect
import builtins
import matplotlib.pyplot as plt

try:
from logger import Logger
Expand Down Expand Up @@ -162,6 +162,9 @@ def __init__(self):
# self._exec_globals.update(py_operators)

# finally, load up numpy, and matplotlib because they are distributed with python and supercharge the calculator
self.user_entry('import math as math')
self.user_entry('enter')

self.user_entry('import numpy as np') # you can import any installed library into the calculator like this
self.user_entry('enter')

Expand Down Expand Up @@ -305,28 +308,23 @@ def show_plot(self, plot_args=None):
if len(self._stack) > 0:
x = self._stack[0] # dont pop X, leave it on the stack for error and success
try:

# check if a plot type object is already loaded up, if so plot it
if isinstance(x, list):
if isinstance(x[0], plt.Artist):
pass # plt.show() is called below
iter(x)
if isinstance(x[0], plt.Artist):
pass # plt.show() is called below
else:
iter(x)
if plot_args is not None:
plt.plot(x, plot_args)
else:
plt.plot(x)
except Exception as ex:
self._message = f"Error: cant plot: '{x}' with error: '{ex}'"
pass # this is to catch the iter(x) error
try: # just plot whatever is loaded
plt.grid() # todo: add more built in plot options
plt.show()
self._message = f"Plot shown"
except Exception as ex:
self._message = f"Error: cant show plot with error: '{ex}'"
log(self._message)
return # ---------------------------------------------------------------------------------------------->
try:
plt.grid() # todo: add more built in plot options
plt.show()
self._message = f"Plot shown"
except Exception as ex:
self._message = f"Error: cant show plot with error: '{ex}'"
log(self._message)

def user_entry(self, user_input: any):
""" Parses the user input string and performs the appropriate action. This method is the primary interface
Expand Down Expand Up @@ -1044,8 +1042,8 @@ def _update_stack_history(self):
to the stack history list and pops the oldest stack if the list is longer than 100 (default) items """
if len(self._stack_history) > self._stack_history_length:
removed = self._stack_history.pop(0)
log(f"Stack history limit of {self._stack_history_length} achieved.")
log(f"Removed oldest stack from stack history: {removed}")
# log(f"Stack history limit of {self._stack_history_length} achieved.")
# log(f"Removed oldest stack from stack history: {removed}")
self._stack_history.append(self._stack.copy())

def _constant_press(self, constant):
Expand Down
3 changes: 2 additions & 1 deletion ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,9 +765,10 @@ def _update_stack_display(self):
else:
desired_width = self._settings.stack_value_width
stack_entry_string = str(stack_entry)
# truncate the displayed stack entry string if it is too long to fit in the table
if len(stack_entry_string) > desired_width:
stack_entry_string = stack_entry_string[:desired_width] + '...'
print(f"truncated stack entry: '{stack_entry_string}' length: {len(stack_entry_string)}")
# print(f"truncated stack entry: '{stack_entry_string}' length: {len(stack_entry_string)}")

# push the stack values to the table
self._stack_table.insert('',
Expand Down

0 comments on commit 6c789eb

Please sign in to comment.