Skip to content

Commit 8b7b190

Browse files
committed
UI development
1 parent 94a3d9b commit 8b7b190

25 files changed

+313
-226
lines changed

py/ec_graphics.py

Lines changed: 60 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from ec_classes import FatalError, RuntimeError
22
from ec_handler import Handler
3-
from graphson import createScreen, renderSpec, renderScreen, getElement, closeScreen, setOnClick
3+
from graphson import createScreen, render, showScreen, getElement, closeScreen, setOnClick
4+
import json
45

56
class Graphics(Handler):
67

@@ -45,24 +46,44 @@ def k_close(self, command):
4546
return True
4647

4748
def r_close(self, command):
48-
closeScreen(self.screen)
49-
self.screen = None
49+
closeScreen()
5050
return self.nextPC()
5151

5252
def k_create(self, command):
5353
if self.nextToken() == 'screen':
54+
while True:
55+
token = self.peek()
56+
if token == 'at':
57+
self.nextToken()
58+
command['left'] = self.nextValue()
59+
command['top'] = self.nextValue()
60+
elif token == 'size':
61+
self.nextToken()
62+
command['width'] = self.nextValue()
63+
command['height'] = self.nextValue()
64+
elif token == 'fill':
65+
self.nextToken()
66+
command['fill'] = self.nextValue()
67+
else:
68+
break
5469
self.add(command)
5570
return True
5671
return False
5772

5873
def r_create(self, command):
59-
self.screen = createScreen()
74+
createScreen(command)
6075
return self.nextPC()
6176

62-
def k_label(self, command):
63-
return self.compileVariable(command, 'label', False)
77+
def k_ellipse(self, command):
78+
return self.compileVariable(command, 'ellipse', False)
6479

65-
def r_label(self, command):
80+
def r_ellipse(self, command):
81+
return self.nextPC()
82+
83+
def k_image(self, command):
84+
return self.compileVariable(command, 'image', False)
85+
86+
def r_image(self, command):
6687
return self.nextPC()
6788

6889
def k_on(self, command):
@@ -91,6 +112,12 @@ def k_on(self, command):
91112
cmd['debug'] = False
92113
self.addCommand(cmd)
93114
self.compileOne()
115+
cmd = {}
116+
cmd['domain'] = 'core'
117+
cmd['lino'] = command['lino']
118+
cmd['keyword'] = 'stop'
119+
cmd['debug'] = False
120+
self.addCommand(cmd)
94121
# Fixup the link
95122
self.getCommandAt(pcNext)['goto'] = self.getPC()
96123
return True
@@ -109,36 +136,27 @@ def r_on(self, command):
109136
setOnClick(value['content'], lambda: self.run(pc))
110137
return self.nextPC()
111138

112-
def k_oval(self, command):
113-
return self.compileVariable(command, 'oval', False)
114-
115-
def r_oval(self, command):
116-
return self.nextPC()
117-
118139
def k_rectangle(self, command):
119140
return self.compileVariable(command, 'rectangle', False)
120141

121142
def r_rectangle(self, command):
122143
return self.nextPC()
123144

124145
def k_render(self, command):
125-
if self.nextIs('screen'):
126-
command['name'] = None
127-
self.add(command)
128-
return True
129-
elif self.isSymbol():
146+
if self.nextIsSymbol():
130147
record = self.getSymbolRecord()
131148
name = record['name']
132149
type = record['type']
133150
command['type'] = type
134151
if type == 'variable':
135152
command['name'] = name
136153
if self.peek() == 'in':
154+
self.nextToken()
137155
if self.nextIsSymbol():
138156
record = self.getSymbolRecord()
139157
type = record['type']
140158
name = record['name']
141-
if type in ['rect', 'oval']:
159+
if type in ['rectangle', 'ellipse']:
142160
command['parent'] = record['name']
143161
self.add(command)
144162
return True
@@ -154,15 +172,29 @@ def k_render(self, command):
154172
return False
155173

156174
def r_render(self, command):
157-
if command['name'] == None:
158-
renderScreen(self.screen)
159-
else:
160-
variable = self.getVariable(command['name'])
161-
spec = self.getRuntimeValue(variable)
162-
offset = {'dx': 0, 'dy': 0}
163-
result = renderSpec(self.screen, spec, offset)
164-
if result != None:
165-
RuntimeError(f'Rendering error: {result}')
175+
variable = self.getVariable(command['name'])
176+
parent = command['parent']
177+
value = self.getRuntimeValue(variable)
178+
result = render(value, parent)
179+
if result != None:
180+
RuntimeError(f'Rendering error: {result}')
181+
return self.nextPC()
182+
183+
def k_show(self, command):
184+
if self.nextIs('screen'):
185+
command['name'] = None
186+
self.add(command)
187+
return True
188+
return False
189+
190+
def r_show(self, command):
191+
showScreen()
192+
return self.nextPC()
193+
194+
def k_text(self, command):
195+
return self.compileVariable(command, 'text', False)
196+
197+
def r_text(self, command):
166198
return self.nextPC()
167199

168200
#############################################################################

py/ec_program.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def doValue(self, value):
6161
result = {}
6262
valType = value['type']
6363
if valType in ['boolean', 'int', 'text', 'object']:
64-
result = value
64+
return value
6565
elif valType == 'cat':
6666
content = ''
6767
for part in value['parts']:
@@ -74,29 +74,28 @@ def doValue(self, value):
7474
content += val
7575
result['type'] = 'text'
7676
result['content'] = content
77-
# elif valType == 'symbol':
78-
# name = value['name']
79-
# symbolRecord = self.getSymbolRecord(name)
80-
# if symbolRecord['value'] == [None]:
81-
# RuntimeError(f'Variable "{name}" has no value')
82-
# return None
83-
# handler = self.domainIndex[symbolRecord['domain']].valueHandler('symbol')
84-
# result = handler(symbolRecord)
85-
elif value['isSymbol']:
77+
return result
78+
elif valType == 'symbol':
79+
name = value['name']
80+
symbolRecord = self.getSymbolRecord(name)
81+
if symbolRecord['value'] == [None]:
82+
RuntimeError(f'Variable "{name}" has no value')
83+
return None
84+
handler = self.domainIndex[symbolRecord['domain']].valueHandler('symbol')
85+
return handler(symbolRecord)
86+
elif 'isSymbol' in value:
8687
if value['value'] == [None]:
8788
name = value['name']
8889
RuntimeError(f'Variable "{name}" has no value')
8990
return None
9091
handler = self.domainIndex[value['domain']].valueHandler('symbol')
91-
result = handler(value)
92+
return handler(value)
9293
else:
9394
# Call the given domain to handle a value
9495
domain = self.domainIndex[value['domain']]
9596
handler = domain.valueHandler(value['type'])
9697
if handler:
97-
result = handler(value)
98-
99-
return result
98+
return handler(value)
10099

101100
def constant(self, content, numeric):
102101
result = {}

py/ec_value.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def compileValue(self):
5858
token = self.getToken()
5959
item = self.getItem()
6060
if item == None:
61-
self.warning(f'Cannot get the value of "{token}"')
61+
self.compiler.warning(f'Cannot get the value of "{token}"')
6262
return None
6363

6464
value = {}

0 commit comments

Comments
 (0)