From 2b827e609b4e06ac85888c9eec55e1adc58d175a Mon Sep 17 00:00:00 2001 From: TabulateJarl8 Date: Thu, 8 Jul 2021 17:32:35 -0400 Subject: [PATCH] add turbo draw option --- README.md | 3 ++- ti842py/__version__.py | 2 +- ti842py/main.py | 14 ++++++++++---- ti842py/tiParser.py | 6 +++++- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 1586e8d..684949d 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,7 @@ optional arguments: Do not attempt to fix implicit multiplication. For example, AB -> A*B and A(1) -> A*(1) --no-fix-floating-point Do not attempt to fix floating point arithmetic errors. For example, 1.1 * 3 would normally say 3.3000000000000003 instead of 3.3 + --turbo-draw Remove the 0.1 second delay between drawing actions -r, --run Runs the program after it's done transpiling. Will not print to stdout -V, --version show program's version number and exit ``` @@ -87,7 +88,7 @@ from ti842py import transpile transpile("tiprogram.txt", "tiprogram.py") ``` -Again, if the second argument is not supplied, the program will be written to `stdout`. The `transpile` command can be supplied with 4 optional arguments, `decompileFile`, `forceDecompile`, `multiplication`, `floating_point`, and `run`. `decompileFile`, `multiplication`, and `floating_point` default to `True`, and `forceDecompile` and `run` default to `False` +Again, if the second argument is not supplied, the program will be written to `stdout`. The `transpile` command can be supplied with optional arguments. `decompileFile`, `multiplication`, and `floating_point` default to `True`, and `forceDecompile`, `run`, and `turbo_draw` default to `False` The last way that ti842py can be ran is by running the main python file. After cloning the repository, cd into the repository and run `python ti842py/main.py inputfile.txt`. You can supply any arguments that you would supply with the `ti842py` command. diff --git a/ti842py/__version__.py b/ti842py/__version__.py index 2384181..4239233 100644 --- a/ti842py/__version__.py +++ b/ti842py/__version__.py @@ -1,7 +1,7 @@ __title__ = "ti842py" __description__ = "TI-BASIC to Python 3 Transpiler" __url__ = "https://github.com/TabulateJarl8/ti842py" -__version__ = "0.7.2" +__version__ = "0.7.3" __author__ = "Tabulate" __author_email__ = "tabulatejarl8@gmail.com" __license__ = "GPLv3" diff --git a/ti842py/main.py b/ti842py/main.py index 3b2b19f..97be226 100644 --- a/ti842py/main.py +++ b/ti842py/main.py @@ -27,7 +27,7 @@ def isUTF8(file): return True -def transpile(infile, outfile="stdout", decompileFile=True, forceDecompile=False, multiplication=True, floating_point=True, run=False): +def transpile(infile, outfile="stdout", decompileFile=True, forceDecompile=False, multiplication=True, floating_point=True, turbo_draw=False, run=False): decode = not isUTF8(infile) and decompileFile is True @@ -36,7 +36,7 @@ def transpile(infile, outfile="stdout", decompileFile=True, forceDecompile=False with tempfile.NamedTemporaryFile() as f: btb.decompile_file(infile, f.name) with open(f.name, 'r') as fp: - pythonCode = TIBasicParser([line.strip() for line in fp.readlines()], multiplication, floating_point).toPython() + pythonCode = TIBasicParser([line.strip() for line in fp.readlines()], multiplication, floating_point, turbo_draw).toPython() else: # Dont decompile @@ -45,7 +45,7 @@ def transpile(infile, outfile="stdout", decompileFile=True, forceDecompile=False with open(infile, 'r') as f: file_lines = [line.strip() for line in f.readlines()] - pythonCode = TIBasicParser(file_lines, multiplication, floating_point).toPython() + pythonCode = TIBasicParser(file_lines, multiplication, floating_point, turbo_draw).toPython() # Write to outfile if outfile == "stdout": @@ -114,6 +114,12 @@ def main(): dest='floating_point' ) + parser.add_argument( + '--turbo-draw', + action='store_true', + help='Remove the 0.1 second delay between drawing actions' + ) + parser.add_argument( '-r', '--run', @@ -130,7 +136,7 @@ def main(): ) args = parser.parse_args() - transpile(args.infile[0], args.outfile, args.n, args.d, args.multiplication, args.floating_point, args.run) + transpile(args.infile[0], args.outfile, args.n, args.d, args.multiplication, args.floating_point, args.turbo_draw, args.run) if __name__ == "__main__": diff --git a/ti842py/tiParser.py b/ti842py/tiParser.py index b6d9c8d..f55a0af 100644 --- a/ti842py/tiParser.py +++ b/ti842py/tiParser.py @@ -13,7 +13,7 @@ class TIBasicParser: - def __init__(self, basic, multiplication, floating_point): + def __init__(self, basic, multiplication, floating_point, turbo_draw): if isinstance(basic, list): self.basic = basic elif isinstance(basic, str): @@ -23,6 +23,7 @@ def __init__(self, basic, multiplication, floating_point): self.multiplication = multiplication self.floating_point = floating_point + self.turbo_draw = turbo_draw # Utility Functions self.UTILS = {"wait": {"code": [""], "imports": ["import time"], "enabled": False}, "menu": {"code": [""], "imports": ["import dialog"], "enabled": False}, "math": {"code": [""], "imports": ["import math"], "enabled": False}, 'random': {'code': [''], 'imports': ['import random'], 'enabled': False}} @@ -38,6 +39,9 @@ def __init__(self, basic, multiplication, floating_point): if self.floating_point: self.UTILS['fix_floating_point']['enabled'] = True + if self.turbo_draw: + self.UTILS['draw']['code'] = [line for line in self.UTILS['draw']['code'] if '@_slow' not in line] + self.drawLock = False def convertLine(self, index, line):