Skip to content

Commit 829d36f

Browse files
added web browser features
1 parent dc53a4b commit 829d36f

File tree

4 files changed

+250
-2
lines changed

4 files changed

+250
-2
lines changed

src/.VisualScript.py.swp

20 KB
Binary file not shown.

src/.VisualScript.py.un~

53.2 KB
Binary file not shown.

src/VisualScript.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import matplotlib.pyplot as plt
88
import sys
99
from statistics import *
10+
fro flask import *
11+
import webbrowser
1012

1113
tur = turtle
1214

@@ -157,8 +159,36 @@ def returnMean(list):
157159
sortedlist = sorted(list)
158160
meannum = sum(sortedlist) / len(sortedlist)
159161
return meannum
162+
def webPage(title, header, content, contentt=None, contenttr=None, contentb=None, contenth=None, contentcb=None, cssfile=None, filename="index.html"):
163+
filenamecustom = filename
164+
structure = f"""
165+
<!DOCTOTYPE html>
166+
<html>
167+
<head>
168+
<titiel>{title}</title>
169+
<link rel="stylesheet" type="text/css" href="{cssfile}">
170+
</head>
171+
<body>
172+
<h1>{header}</h1>
173+
<p>{content}</p>
174+
<p>{contentt}</p>
175+
<p>{contenttr}</p>
176+
<p>{contenttb}</p>
177+
<p>{contenth}</p>
178+
<p>{contentcb}</p>
179+
</body>
180+
</html>
181+
"""
182+
183+
with open(filename, "w") as html:
184+
html.write(structure)
185+
webbrowser.open(filename)
186+
187+
def webPageStart(filename):
188+
# opens html files only
189+
webbrowser.open(filename)
160190

161-
191+
162192

163193

164194

@@ -216,4 +246,4 @@ def returnMean(list):
216246
pass
217247
else:
218248
print(f"An error occurred: {e}")
219-
249+

src/VisualScript.py~

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
# change python syntax and define functions
2+
import tokenize
3+
from io import BytesIO
4+
import tkinter
5+
from tkinter import *
6+
import turtle
7+
import matplotlib.pyplot as plt
8+
import sys
9+
from statistics import *
10+
fro flask import *
11+
12+
tur = turtle
13+
14+
window = tkinter
15+
16+
17+
18+
19+
def process_code(file):
20+
keys = {
21+
22+
"log":"print",
23+
"ask": "input",
24+
"convertInt":"int",
25+
"convertStr":"str",
26+
"else if":"elif",
27+
"//":"#",
28+
"get":"import",
29+
"size":"len",
30+
"f":"format",
31+
"x=":"!=",
32+
"delete":"del",
33+
"with_name":"as",
34+
"function":"def",
35+
"toLowerCase":"lower",
36+
"toUpperCase":"upper",
37+
"firstLetterUpper":"title",
38+
"skip":"pass"
39+
40+
41+
42+
43+
44+
}
45+
46+
def __init__():
47+
pass
48+
def add(num1, num2):
49+
x = num1+num2
50+
return x
51+
def window(title):
52+
window.Tk()
53+
window.title(title)
54+
window.mainloop()
55+
return
56+
57+
def subtract(num1, num2):
58+
yx = num1-num2
59+
return yx
60+
def multiply(num1, num2):
61+
xy = num1*num2
62+
return xy
63+
def divide(num1, num2):
64+
xyx = num1/num2
65+
return xyx
66+
def artboard(color):
67+
tur.turtle = turtle.Turtle()
68+
screen = turtle.Screen()
69+
screen.title("VisualScript Art Window")
70+
tur.turtle.color(color)
71+
return
72+
def artColor(color):
73+
tur.turtle.color(color)
74+
return
75+
def artLeft(amount):
76+
tur.turtle.left(amount)
77+
return
78+
def artRight(amount):
79+
tur.turtle.right(amount)
80+
return
81+
def artForward(amount):
82+
tur.turtle.forward(amount)
83+
return
84+
def artBackward(amount):
85+
tur.turtle.backward(amount)
86+
return
87+
def artClose():
88+
tur.turtle.exitonclick()
89+
return
90+
def artSpeed(speed):
91+
tur.turtle.speed(speed)
92+
return
93+
def artColor(color):
94+
tur.turtle.color(color)
95+
return
96+
def artKey(function, key):
97+
tur.turtle.onkey(function, key)
98+
tur.turtle.listen()
99+
return
100+
def artStatic(feature):
101+
if feature == "stamp":
102+
tur.turtle.stamp()
103+
elif feature == "dot":
104+
tur.turtle.dot()
105+
def ForeverRun():
106+
while True:
107+
pass
108+
def chartLine(datasetx, datasety, ytitle, xtitle):
109+
plt.plot(datasetx, datasety)
110+
plt.ylabel(ytitle)
111+
plt.xlabel(xtitle)
112+
plt.show()
113+
def chartDot(datasetx, datasety, ytitle, xtitle):
114+
plt.scatter(datasetx, datasety)
115+
plt.xlabel(xtitle)
116+
plt.ylabel(ytitle)
117+
def chartScatter(datasetx, datasety, xtitle, ytitle):
118+
timesx = len(datasetx)
119+
for i in range(timesx):
120+
plt.scatter(datasetx[i], datasety[i])
121+
plt.xlabel(xtitle)
122+
plt.ylabel(ytitle)
123+
plt.show
124+
def chartTheme(theme):
125+
plt.style(theme)
126+
return
127+
def windowTitle(title):
128+
window.title(title)
129+
return
130+
def ArtBoardTitle(name):
131+
screen = turtle.Screen()
132+
screen.title(name)
133+
return
134+
135+
def ChartShow():
136+
plt.show()
137+
return
138+
def logf(value, formatedvalue):
139+
print(value+"{}".format(formatedvalue))
140+
return
141+
def returnMedian(list, chart):
142+
sortedlist = sorted(list)
143+
middle_value = len(sortedlist) // 2
144+
final = (sortedlist[middle_value] + sortedlist[~middle_value]) / 2
145+
if chart.lower() == 'y':
146+
plt.scatter(final, final)
147+
plt.show()
148+
else:
149+
pass
150+
return final
151+
def exit():
152+
sys.exit()
153+
def returnMode(list):
154+
sortedlist = sorted(list)
155+
avg = mode(sortedlist)
156+
return avg
157+
def returnMean(list):
158+
sortedlist = sorted(list)
159+
meannum = sum(sortedlist) / len(sortedlist)
160+
return meannum
161+
def
162+
163+
164+
165+
166+
167+
168+
169+
170+
171+
172+
173+
174+
175+
176+
177+
178+
custom_features = {
179+
180+
}
181+
182+
with open(file, "rb") as source:
183+
tokens = []
184+
for token in tokenize.tokenize(source.readline):
185+
if token.string in keys:
186+
t = (token.type, keys[token.string])
187+
elif token.string in custom_features:
188+
t = (token.type, token.string)
189+
else:
190+
t = (token.type, token.string)
191+
tokens.append(t)
192+
193+
code = tokenize.untokenize(tokens).decode("utf-8")
194+
exec(code)
195+
196+
for feature_name, feature_func in custom_features.items():
197+
if feature_name in globals():
198+
feature_func()
199+
200+
201+
print("VisualScipt\nEnter a filename or license for license or help() for help or exit() to exit")
202+
if __name__ == "__main__":
203+
while True:
204+
filename = input(">>> ")
205+
if filename.lower() == 'exit()':
206+
break
207+
elif filename.lower() == 'help()':
208+
print("\nexit() to exit or enter to go back\n")
209+
elif filename.lower() == 'license':
210+
print("\nVisualScript is lisensed under a MIT license.\nRead the terms here:\nhttps://github.com/Bruceli-iscool/VisualScript/blob/main/LICENSE\n")
211+
try:
212+
process_code(filename)
213+
except Exception as e:
214+
if len(filename) < 1 or filename == 'help()' or filename == 'license':
215+
pass
216+
else:
217+
print(f"An error occurred: {e}")
218+

0 commit comments

Comments
 (0)