-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e5e4478
commit 34c5f5a
Showing
9 changed files
with
384 additions
and
362 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
[MESSAGES CONTROL] | ||
disable=import-error | ||
disable=import-error,too-few-public-methods |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[Desktop Entry] | ||
Name=Pebbles | ||
GenericName=Pebbles Calculator App | ||
Comment=Perform advanced calculations with ease | ||
Categories=Utility;Calculator;GTK; | ||
Exec=com.github.subhadeepjasu.pebbles | ||
Icon=com.github.subhadeepjasu.pebbles | ||
Terminal=false | ||
Type=Application | ||
Keywords=calculator;scientific;programmer;statistics;converter;convert;calculate;boolean; | ||
X-GNOME-Gettext-Domain=com.github.subhadeepjasu.pebbles | ||
Actions=MiniMode;NewWindow; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,43 @@ | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# SPDX-FileCopyrightText: 2024 Subhadeep Jasu <[email protected]> | ||
|
||
""" | ||
Contextual Memory Store | ||
""" | ||
|
||
class ContextualMemory: | ||
"""Contextual memory for storing arbitrary values for user.""" | ||
|
||
def __init__(self): | ||
self._memory = dict() | ||
self._last_ans = dict() | ||
self._memory = {} | ||
self._last_ans = {} | ||
|
||
for k in ["global", "sci", "calc", "prog", "stat", "conv"]: | ||
self._memory[k] = 0 | ||
self._last_ans[k] = 0 | ||
|
||
|
||
def add(self, value: int | float | complex, context="global"): | ||
""" | ||
Add the entered value or result to the value in memory. | ||
""" | ||
self._memory[context] += value | ||
|
||
|
||
def subtract(self, value: int | float | complex, context="global"): | ||
""" | ||
Subtract the entered value or result from the value in memory. | ||
""" | ||
self._memory[context] -= value | ||
|
||
|
||
def recall(self, context="global"): | ||
""" | ||
Reveal the value in memory. | ||
""" | ||
value = self._memory[context] | ||
if context not in ["sci", "calc"]: | ||
if type(value) == complex: | ||
if isinstance(value, complex): | ||
value = float(value.imag) | ||
|
||
if context == "prog": | ||
|
@@ -33,22 +46,31 @@ def recall(self, context="global"): | |
return value | ||
|
||
def clear(self, context="global"): | ||
""" | ||
Clear memory. | ||
""" | ||
value = self._memory[context] | ||
self._memory[context] = 0 | ||
return value | ||
|
||
|
||
def set_last_ans(self, value: float | complex, context="global"): | ||
""" | ||
Save the last answer in memory. | ||
""" | ||
self._last_ans[context] = value | ||
if context != "global": | ||
self._last_ans["global"] = value | ||
|
||
|
||
def get_last_ans(self, context="global"): | ||
""" | ||
Fetch the last answer in memory. | ||
""" | ||
value = self._last_ans[context] | ||
|
||
if context not in ["sci", "calc"]: | ||
if type(value) == complex: | ||
if isinstance(value, complex): | ||
value = float(value.imag) | ||
|
||
if context == "prog": | ||
|
@@ -58,13 +80,19 @@ def get_last_ans(self, context="global"): | |
|
||
|
||
def peek(self): | ||
""" | ||
Print the memory data. | ||
""" | ||
print('Memory: ', self._memory) | ||
print('Last Answer: ', self._last_ans) | ||
|
||
|
||
def any(self, context='global') -> bool: | ||
""" | ||
Returns True is anything is present in memory for the given context. | ||
""" | ||
value = self._memory[context] | ||
if type(value) == complex: | ||
if isinstance(value, complex): | ||
return value.imag != 0 or value.real != 0 | ||
|
||
return value != 0 |
Oops, something went wrong.