Skip to content

Commit 4c00272

Browse files
committed
v250107.2
1 parent b6c5288 commit 4c00272

File tree

4 files changed

+117
-84
lines changed

4 files changed

+117
-84
lines changed

easycoder/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
from .ec_timestamp import *
1111
from .ec_value import *
1212

13-
__version__ = "250106.1"
13+
__version__ = "250107.2"

easycoder/ec_graphics.py

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Graphics(Handler):
99

1010
def __init__(self, compiler):
1111
Handler.__init__(self, compiler)
12+
self.windowCreated = False
1213

1314
def getName(self):
1415
return 'graphics'
@@ -31,12 +32,13 @@ def r_attach(self, command):
3132
targetRecord = self.getVariable(command['name'])
3233
keyword = targetRecord['keyword']
3334
id = self.getRuntimeValue(command['id'])
34-
element = self.ui.getElement(id)
35-
if element == None:
35+
uiElement = self.ui.getElement(id)
36+
if uiElement == None:
3637
FatalError(self.program.compiler, f'There is no screen element with id \'{id}\'')
3738
return -1
38-
if element.getType() != keyword:
39-
FatalError(self.program.compiler, f'Mismatched element type: \'{element['type']}\' and \'{keyword}\'')
39+
if uiElement.getType() != keyword:
40+
etype = uiElement['type']
41+
FatalError(self.program.compiler, f'Mismatched element type: "{etype}" and "{keyword}"')
4042
self.putSymbolValue(targetRecord, {'type': 'text', 'content': id})
4143
return self.nextPC()
4244

@@ -65,11 +67,19 @@ def k_create(self, command):
6567
r = self.compileConstant(255)
6668
g = self.compileConstant(255)
6769
b = self.compileConstant(255)
70+
fullscreen = False
71+
borderless = False
6872
while True:
6973
token = self.peek()
7074
if token == 'title':
7175
self.nextToken()
7276
t = self.nextValue()
77+
elif token == 'fullscreen':
78+
fullscreen = True
79+
self.nextToken()
80+
elif token == 'borderless':
81+
borderless = True
82+
self.nextToken()
7383
elif token == 'at':
7484
self.nextToken()
7585
left = self.nextValue()
@@ -91,9 +101,11 @@ def k_create(self, command):
91101
command['pos'] = (left, top)
92102
command['size'] = (width, height)
93103
command['fill'] = (r, g, b)
104+
command['fullscreen'] = fullscreen
105+
command['borderless'] = borderless
94106
self.add(command)
95107
return True
96-
108+
97109
elif self.isSymbol():
98110
record = self.getSymbolRecord()
99111
command['target'] = record['name']
@@ -113,7 +125,7 @@ def k_create(self, command):
113125
self.add(command)
114126
record['elementID'] = command['id']
115127
return False
116-
128+
117129
def getElementData(self, type, command):
118130
width = None
119131
height = None
@@ -170,23 +182,29 @@ def getElementData(self, type, command):
170182
command['source'] = source
171183

172184
def r_create(self, command):
185+
173186
try:
174187
type = command['type']
175188
if type == 'window':
189+
if self.windowCreated == True:
190+
RuntimeError(self.program, 'A window has already been created')
176191
self.windowSpec = Object()
177192
self.windowSpec.title = command['title']['content']
193+
self.windowSpec.fullscreen = command['fullscreen']
194+
self.windowSpec.borderless = command['borderless']
178195
self.windowSpec.flush = flush
179196
self.windowSpec.kill = self.program.kill
180197
self.windowSpec.pos = (self.getRuntimeValue(command['pos'][0]), self.getRuntimeValue(command['pos'][1]))
181198
self.windowSpec.size = (self.getRuntimeValue(command['size'][0]), self.getRuntimeValue(command['size'][1]))
182199
self.windowSpec.fill = (self.getRuntimeValue(command['fill'][0])/255, self.getRuntimeValue(command['fill'][1])/255, self.getRuntimeValue(command['fill'][2])/255)
200+
self.windowCreated = True
183201
else:
184202
element = self.ui.createWidget(self.getWidgetSpec(command))
185203
print(element)
186204
except Exception as e:
187205
RuntimeError(self.program, e)
188206
return self.nextPC()
189-
207+
190208
def getWidgetSpec(self, command):
191209
spec = Object()
192210
spec.id = self.getRuntimeValue(command['id'])
@@ -247,6 +265,7 @@ def r_moveBy(self, command):
247265
self.ui.moveElementBy(self.getRuntimeValue(command['target']), dist)
248266
return self.nextPC()
249267

268+
# on click/tap {element} {action}
250269
def k_on(self, command):
251270
token = self.nextToken()
252271
if token in ['click', 'tap']:
@@ -280,16 +299,25 @@ def k_on(self, command):
280299
return True
281300
return False
282301

302+
# Set a handler on every element
283303
def r_on(self, command):
284304
pc = command['goto']
285305
if command['type'] == 'tap':
286306
record = self.getVariable(command['target'])
307+
def oncb(data):
308+
record['index'] = data.index
309+
self.run(data.pc)
287310
keyword = record['keyword']
288311
if self.isGraphicType(keyword):
289-
id = record['value'][record['index']]['content']
290-
self.ui.setOnClick(id, lambda: self.run(pc))
312+
for index in range(0, record['elements']):
313+
id = record['value'][index]['content']
314+
data = Object()
315+
data.pc = pc
316+
data.index = index
317+
self.ui.setOnClick(id, data, oncb)
291318
else:
292-
RuntimeError(self.program, f'{record['name']} is not a clickable object')
319+
name = record['name']
320+
RuntimeError(self.program, f'{name} is not a clickable object')
293321
return self.nextPC()
294322

295323
def k_rectangle(self, command):
@@ -350,9 +378,11 @@ def k_set(self, command):
350378
self.addCommand(command)
351379
return True
352380
else:
353-
FatalError(self.program.compiler, f'Invalid type: {record['keyword']}')
381+
rtype = record['type']
382+
FatalError(self.program.compiler, f'Invalid type: {rtype}')
354383
else:
355-
FatalError(self.program.compiler, f'\'{self.getToken()}\' is not a variable')
384+
token = self.getToken()
385+
FatalError(self.program.compiler, f'{token} is not a variable')
356386
return False
357387

358388
def r_set(self, command):
@@ -388,7 +418,7 @@ def compileValue(self):
388418
value['type'] = 'symbol'
389419
return value
390420
return None
391-
421+
392422
if self.tokenIs('the'):
393423
self.nextToken()
394424
kwd = self.getToken()

easycoder/ec_program.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ def getSymbolValue(self, symbolRecord):
206206

207207
def putSymbolValue(self, symbolRecord, value):
208208
if symbolRecord['locked']:
209-
RuntimeError(self, f'Symbol \'{symbolRecord['name']}\' is locked')
209+
name = symbolRecord['name']
210+
RuntimeError(self, f'Symbol "{name}" is locked')
210211
if symbolRecord['value'] == None or symbolRecord['value'] == []:
211212
symbolRecord['value'] = [value]
212213
else:

0 commit comments

Comments
 (0)