-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathti_system.py
182 lines (136 loc) · 6.42 KB
/
ti_system.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
"""
TI SYSTEM
----------
----------
All the classes and functions from the Texas Instruments System Module.
"""
from ti_python_module.err import withConsole as err
from ti_python_module.err import onlyCheck as cerr
from ti_python_module.file_handler import create_log as log
import random as rng
import time
###########################################################################################
def recall_value(name:str):
"""
Recalls a predefined OS variable (value) named "name".
args:
name (str): The name of the variable from which to recall the value.
Returns:
None: Due to being unable to cache value
"""
if cerr.type_error(str, name) == False: log("Argument 'name' has to be type string", "ERROR", "TI System", "Recall Value")
err.type_error(str, "str", name)
log("Fetchint the value stored in the system variable with the name '" + name + "'", "INFO", "TI System", "Recall Value")
print("Fetching value of system variable '" + name + "'")
return None
###########################################################################################
def store_value(name:str, value):
"""
Stores a Python variable (value) to an OS variable named "name".
args:
name (str): The name of the variable from which to recall the value.
value (any): The value to store.
Returns:
None: Due to being unable to cache value
"""
if cerr.type_error(str, name) == False: log("Argument 'name' has to be type string", "ERROR", "TI System", "Store Value")
err.type_error(str, "str", name)
log("Storing data '" + str(value) + "' to variable '" + name + "'", "INFO", "TI System", "Store Value")
print("Storing data '" + str(value) + "' to variable '" + name + "'")
return None
###########################################################################################
def recall_list(name:str):
"""
Recalls a predefined OS list (list) named "name".
args:
name (str): The name of the list from which to recall the value.
Returns:
None: Due to being unable to cache list
"""
if cerr.type_error(str, name) == False: log("Argument 'name' has to be type string", "ERROR", "TI System", "Recall List")
err.type_error(str, "str", name)
log("Recalling values of system list '" + name + "'", "INFO", "TI System", "Recall List")
print("Fetching value of system list '" + name + "'")
return None
###########################################################################################
def store_list(name:str, list:list):
"""
Stores a Python list (list) to an OS variable named "name".
args:
name (str): The name of the variable from which to recall the value.
list (list): The values to store int the list.
Returns:
None: Due to being unable to cache list
"""
if cerr.type_error(str, name) == False: log("Argument 'name' has to be type string", "ERROR", "TI System", "Store List")
err.type_error(str, "str", name)
log("Storing the data from the given list to system list '" + name + "'", "INFO", "TI System", "Store List")
print("Storing data '" + str(list) + "' to variable '" + name + "'")
return None
###########################################################################################
def eval_function(name:str, value):
"""
Evaluates a predefined OS function at the specified value
args:
name (str): The name of the function.
value (any): The value to use for the function
Returns:
None: Due to being unable to see predefined OS functions
"""
if cerr.type_error(str, name) == False: log("Argument 'name' has to be type string", "ERROR", "TI System", "Evaluate Function")
err.type_error(str, "str", name)
log("Evaluating the result of using the function '" + name +"' with the value '" + str(value) + "'", "INFO", "TI System", "Evaluate Function")
print("Evaluating result of '" + name + "' for value '" + str(value) + "'")
return None
###########################################################################################
def get_platform():
"""
Returns 'hh' for handeld and 'dt' for desktop
Returns
str: The platform type shortcut
"""
log("Fetching current platform type", "INFO", "TI System", "Get Platform")
print("Fetching platform type")
return rng.choice(['hh', 'dt'])
###########################################################################################
def get_key(parameter = None):
"""
Returns a string representing the key pressed. The '1' key returns "1", 'esc' returns "esc", and so on. When called without any parameters - get_key() - it returns immediately. When called with a parameter - get_key(1) - it waits until a key is pressed.
Args:
parameter (any, optional): Optional Parameter. If given, waits until key is pressed. Defaults to None.
Returns:
str: The pressed key
"""
log("Fetching Key-String fot '" + str(parameter) + "'", "INFO", "TI System", "Get Key")
print("Fetching Key-String for '" + str(parameter) + "'")
return input("Requesting Key input: ")
###########################################################################################
def get_mouse():
"""
Returns mouse coordinates as a two element tuple, either the canvas pixel position or (-1,-1) if outside the canvas.
Returns
None: Due to being unable to fetch mouse position
"""
log("Fetching the position of the mouse cursor", "INFO", "TI System", "Get Mouse")
print("Fetching position of mouse cursor")
return None
###########################################################################################
def clear_history():
"""
Clears the shell history.
Returns
None: None
"""
log("Clearing the content and history of the output shell", "INFO", "TI System", "Clear History")
print("Clearing Shell history")
return None
###########################################################################################
def get_time_ms():
"""
Returns time in milliseconds with millisecond precision. This functionality can be used to calculate a duration rather than determine the actual clock time.
Returns
float: The time in milliseconds
"""
log("Fetching the time in milliseconds", "INFO", "TI System", "Get Time Milliseconds")
print("Fetching time in milliseconds")
return time.time()