-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial version - split from ModularCalculator repo
- Loading branch information
Showing
54 changed files
with
2,614 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
**/__pycache__ | ||
.flatpak-builder/ |
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,15 @@ | ||
Copyright (C) 2020 Jordan Leppert | ||
|
||
This library is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public | ||
License as published by the Free Software Foundation; either | ||
version 2.1 of the License, or (at your option) any later version. | ||
|
||
This library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
|
||
You should have received a copy of the GNU Lesser General Public | ||
License along with this library; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
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,6 @@ | ||
[Desktop Entry] | ||
Name=Modular Calculator | ||
Exec=modularcalculator | ||
Type=Application | ||
Icon=io.github.jordanl2.ModularCalculator | ||
Categories=Office; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,14 @@ | ||
#!/bin/sh | ||
|
||
PREFIX=$1 | ||
if [ $# -lt 1 ]; then | ||
PREFIX=/usr | ||
fi | ||
|
||
pip3 install --prefix=${PREFIX} . | ||
for r in 16x16 24x24 48x48 64x64 128x128 256x256 | ||
do | ||
install -Dm644 icons/$r.png $PREFIX/share/icons/hicolor/$r/apps/io.github.jordanl2.ModularCalculator.png | ||
done | ||
install -D ModularCalculator.desktop $PREFIX/share/applications/io.github.jordanl2.ModularCalculator.desktop | ||
install -D io.github.jordanl2.ModularCalculator.appdata.xml $PREFIX/share/metainfo/io.github.jordanl2.ModularCalculator.metainfo.xml |
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,33 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- Copyright 2020 Jordan Leppert --> | ||
<component type="desktop-application"> | ||
<id>io.github.jordanl2.ModularCalculator</id> | ||
<metadata_license>FSFAP</metadata_license> | ||
<project_license>LGPL-2.1</project_license> | ||
<name>Modular Calculator</name> | ||
<summary>A powerful, modular calculator written in Python</summary> | ||
|
||
<description> | ||
<p>A powerful, modular calculator written in Python</p> | ||
</description> | ||
|
||
<url type="homepage">https://github.com/JordanL2/ModularCalculator</url> | ||
|
||
<content_rating type="oars-1.1" /> | ||
|
||
<launchable type="desktop-id">io.github.jordanl2.ModularCalculator.desktop</launchable> | ||
|
||
<screenshots> | ||
<screenshot> | ||
<image>https://user-images.githubusercontent.com/42909496/76239734-fca3dd00-6229-11ea-8e2b-6b394d1ba13c.png</image> | ||
</screenshot> | ||
</screenshots> | ||
|
||
<provides> | ||
<id>io.github.jordanl2.ModularCalculator</id> | ||
</provides> | ||
|
||
<releases> | ||
<release version="1.0.2-SNAPSHOT" date="2021-01-08"/> | ||
</releases> | ||
</component> |
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,32 @@ | ||
{ | ||
"app-id": "io.github.jordanl2.ModularCalculator", | ||
"runtime": "org.kde.Platform", | ||
"runtime-version": "5.15", | ||
"sdk": "org.kde.Sdk", | ||
"default-branch": "stable", | ||
"command": "modularcalculator", | ||
"finish-args": [ | ||
"--share=network", | ||
"--share=ipc", | ||
"--socket=x11", | ||
"--socket=wayland", | ||
"--device=dri", | ||
"--filesystem=home" | ||
], | ||
"modules": [ | ||
"pyqt.json", | ||
{ | ||
"name": "modularcalculator", | ||
"buildsystem": "simple", | ||
"build-commands": [ | ||
"./install $FLATPAK_DEST" | ||
], | ||
"sources": [ | ||
{ | ||
"type": "dir", | ||
"path": "." | ||
} | ||
] | ||
} | ||
] | ||
} |
Empty file.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+6.65 KB
modularcalculatorinterface/__pycache__/calculatormanager.cpython-38.pyc
Binary file not shown.
Binary file added
BIN
+6.64 KB
modularcalculatorinterface/__pycache__/calculatormanager.cpython-39.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+15.6 KB
modularcalculatorinterface/__pycache__/modularcalculatorinterface.cpython-38.pyc
Binary file not shown.
Binary file added
BIN
+3.36 KB
modularcalculatorinterface/__pycache__/statefulapplication.cpython-38.pyc
Binary file not shown.
Binary file added
BIN
+3.36 KB
modularcalculatorinterface/__pycache__/statefulapplication.cpython-39.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,181 @@ | ||
#!/usr/bin/python3 | ||
|
||
from modularcalculator.modularcalculator import * | ||
from modularcalculator.objects.exceptions import * | ||
from modularcalculatorinterface.tools import * | ||
|
||
from PyQt5.QtWidgets import QMessageBox | ||
|
||
|
||
class CalculatorManager(): | ||
|
||
def __init__(self, interface): | ||
self.interface = interface | ||
self.entry = self.interface.entry | ||
self.display = self.interface.display | ||
self.initCalculator() | ||
|
||
|
||
def initCalculator(self): | ||
calculator = ModularCalculator() | ||
calculator.enable_units() | ||
self.setCalculator(calculator) | ||
|
||
def setCalculator(self, calculator): | ||
self.calculator = calculator | ||
self.entry.setCalculator(self.calculator) | ||
|
||
def importFeature(self, filePath): | ||
try: | ||
featureIds = self.calculator.import_feature_file(filePath) | ||
self.importedFeatures.append(filePath) | ||
except Exception as err: | ||
return e | ||
|
||
def replaceCalculator(self, calculator): | ||
calculator.number_prec_set(self.calculator.number_prec_get()) | ||
calculator.unit_simplification_set(self.calculator.unit_simplification_get()) | ||
calculator.unit_normaliser.systems_preference = self.calculator.unit_normaliser.systems_preference | ||
for featureId, featureOptions in self.calculator.feature_options.items(): | ||
if featureId in calculator.feature_options: | ||
calculator.feature_options[featureId] = featureOptions | ||
self.setCalculator(calculator) | ||
self.updateInsertOptions() | ||
|
||
def updateInsertOptions(self): | ||
self.interface.insertConstantAction.setVisible('state.constants' in self.calculator.installed_features) | ||
self.interface.insertDateAction.setVisible('dates.dates' in self.calculator.installed_features) | ||
self.interface.insertUnitAction.setVisible('units.units' in self.calculator.installed_features) | ||
self.interface.insertOperatorAction.setVisible('structure.operators' in self.calculator.installed_features) | ||
self.interface.insertFunctionAction.setVisible('structure.functions' in self.calculator.installed_features) | ||
self.interface.insertUserDefinedFunctionAction.setVisible('structure.externalfunctions' in self.calculator.installed_features) | ||
|
||
def initEmptyState(self): | ||
self.importedFeatures = [] | ||
self.calculator.load_preset('Computing') | ||
self.setPrecision(30) | ||
self.setUnitSimplification(True) | ||
self.setAutoExecute(True, False) | ||
self.setShortUnits(False) | ||
|
||
def restoreState(self, state): | ||
defaultState(state, { | ||
"importedFeatures": [], | ||
"calculatorFeatures": None, | ||
"precision": 30, | ||
"simplifyUnits": True, | ||
"unitSystemsPreference": None, | ||
"calculatorFeatureOptions": {}, | ||
"viewSyntaxParsingAutoExecutes": True, | ||
"viewShortUnits": False, | ||
}) | ||
|
||
self.importedFeatures = state["importedFeatures"] | ||
foundImportedFeatures = [] | ||
for featureFile in self.importedFeatures: | ||
try: | ||
self.calculator.import_feature_file(featureFile) | ||
foundImportedFeatures.append(featureFile) | ||
except Exception as err: | ||
print("!!! Couldn't import {} - {} !!!".format(featureFile, err)) | ||
self.importedFeatures = foundImportedFeatures | ||
|
||
features = state["calculatorFeatures"] | ||
if features is not None: | ||
self.calculator.install_features(features, False, True) | ||
else: | ||
self.calculator.load_preset('Computing') | ||
|
||
self.setPrecision(state["precision"]) | ||
|
||
self.setUnitSimplification(state["simplifyUnits"]) | ||
|
||
unitSystems = state["unitSystemsPreference"] | ||
if unitSystems is not None: | ||
self.calculator.unit_normaliser.systems_preference = unitSystems | ||
|
||
featureOptions = state["calculatorFeatureOptions"] | ||
for featureId, featuresOptions in featureOptions.items(): | ||
for field, value in featuresOptions.items(): | ||
if field in self.calculator.feature_list[featureId].default_options(): | ||
self.calculator.feature_options[featureId][field] = value | ||
|
||
self.setAutoExecute(state["viewSyntaxParsingAutoExecutes"], False) | ||
|
||
self.setShortUnits(state["viewShortUnits"], False) | ||
|
||
def saveState(self): | ||
state = {} | ||
|
||
state["importedFeatures"] = list(set(self.importedFeatures)) | ||
|
||
state["calculatorFeatures"] = self.calculator.installed_features | ||
state["precision"] = self.interface.precisionSpinBox.spinbox.value() | ||
state["simplifyUnits"] = self.interface.optionsSimplifyUnits.isChecked() | ||
state["unitSystemsPreference"] = self.calculator.unit_normaliser.systems_preference | ||
|
||
state["calculatorFeatureOptions"] = self.calculator.feature_options | ||
|
||
state["viewShortUnits"] = self.interface.viewShortUnits.isChecked() | ||
state["viewSyntaxParsingAutoExecutes"] = self.interface.viewSyntaxParsingAutoExecutes.isChecked() | ||
|
||
return state | ||
|
||
|
||
def calc(self): | ||
question = self.entry.getContents().rstrip() | ||
response = None | ||
err = None | ||
pos = None | ||
try: | ||
self.calculator.vars = {} | ||
response = self.calculator.calculate(question) | ||
except CalculatingException as theErr: | ||
err = theErr | ||
pos = err.find_pos(question) | ||
response = err.response | ||
if response is not None: | ||
self.display.clear() | ||
for i, result in enumerate(response.results): | ||
if result.has_result(): | ||
result_value = result.value | ||
result_value = self.calculator.number_to_string(result_value) | ||
self.display.addAnswer(result.expression, result_value, result.unit) | ||
if err is not None: | ||
self.display.addError(err, pos, question) | ||
self.display.refresh() | ||
|
||
|
||
def setUnitSimplification(self, value): | ||
self.interface.optionsSimplifyUnits.setChecked(value) | ||
self.calculator.unit_simplification_set(value) | ||
|
||
def setPrecision(self, value): | ||
self.interface.precisionSpinBox.spinbox.setValue(value) | ||
self.calculator.number_prec_set(value) | ||
|
||
def setShortUnits(self, value, refresh=True): | ||
self.interface.viewShortUnits.setChecked(value) | ||
self.display.options['shortunits'] = value | ||
if refresh: | ||
self.display.refresh() | ||
|
||
def setAutoExecute(self, value, refresh=True): | ||
self.interface.viewSyntaxParsingAutoExecutes.setChecked(value) | ||
self.entry.autoExecute = value | ||
if refresh: | ||
self.entry.refresh() | ||
|
||
def updateUnitSystemPreference(self, systemNames): | ||
self.calculator.unit_normaliser.systems_preference = [s for n in systemNames for s in [s for s in self.calculator.unit_normaliser.systems if self.calculator.unit_normaliser.systems[s].name == n]] | ||
|
||
def commitFeatureConfig(self, calculator, importedFeatures): | ||
try: | ||
self.replaceCalculator(calculator) | ||
self.importedFeatures = importedFeatures | ||
except Exception: | ||
errorMessage = QMessageBox(self.interface) | ||
errorMessage.setText("Could not instantiate calculator with selected features") | ||
errorMessage.exec() | ||
print(traceback.format_exc()) | ||
self.entry.refresh() |
Oops, something went wrong.