Skip to content

Commit 6e78362

Browse files
committed
250401.1
1 parent c575efb commit 6e78362

8 files changed

+119
-37
lines changed
-32.8 KB
Binary file not shown.
46 KB
Binary file not shown.
Binary file not shown.

easycoder/__init__.py

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

12-
__version__ = "250317.1"
12+
__version__ = "250403.1"

easycoder/ec_core.py

Lines changed: 63 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import json, math, hashlib, threading, os, subprocess, sys, requests, time, numbers, base64, binascii
1+
import json, math, hashlib, threading, os, subprocess, sys, requests, time, numbers, base64, binascii, random
22
from psutil import Process
33
from datetime import datetime, timezone
44
from random import randrange
@@ -144,7 +144,7 @@ def k_begin(self, command):
144144
else:
145145
return self.compileFromHere(['end'])
146146

147-
# Clear (set False)
147+
# Clear (set false)
148148
# clear {variable}
149149
def k_clear(self, command):
150150
if self.nextIsSymbol():
@@ -405,36 +405,40 @@ def k_get(self, command):
405405
else:
406406
FatalError(self.compiler, f'Variable "{symbolRecord["name"]}" does not hold a value')
407407
if self.nextIs('from'):
408-
command['url'] = self.nextValue()
409-
command['or'] = None
410-
get = self.getPC()
411-
if self.peek() == 'timeout':
412-
self.nextToken()
413-
command['timeout'] = self.nextValue()
414-
else:
415-
timeout = {}
416-
timeout['type'] = 'int'
417-
timeout['content'] = 5
418-
command['timeout'] = timeout
419-
self.addCommand(command)
420-
if self.peek() == 'or':
421-
self.nextToken()
422-
self.nextToken()
423-
# Add a 'goto' to skip the 'or'
424-
cmd = {}
425-
cmd['lino'] = command['lino']
426-
cmd['domain'] = 'core'
427-
cmd['keyword'] = 'gotoPC'
428-
cmd['goto'] = 0
429-
cmd['debug'] = False
430-
skip = self.getPC()
431-
self.addCommand(cmd)
432-
# Process the 'or'
433-
self.getCommandAt(get)['or'] = self.getPC()
434-
self.compileOne()
435-
# Fixup the skip
436-
self.getCommandAt(skip)['goto'] = self.getPC()
437-
return True
408+
if self.nextIs('url'):
409+
url = self.nextValue()
410+
if url != None:
411+
command['url'] = url
412+
command['or'] = None
413+
get = self.getPC()
414+
if self.peek() == 'timeout':
415+
self.nextToken()
416+
command['timeout'] = self.nextValue()
417+
else:
418+
timeout = {}
419+
timeout['type'] = 'int'
420+
timeout['content'] = 5
421+
command['timeout'] = timeout
422+
self.addCommand(command)
423+
if self.peek() == 'or':
424+
self.nextToken()
425+
self.nextToken()
426+
# Add a 'goto' to skip the 'or'
427+
cmd = {}
428+
cmd['lino'] = command['lino']
429+
cmd['domain'] = 'core'
430+
cmd['keyword'] = 'gotoPC'
431+
cmd['goto'] = 0
432+
cmd['debug'] = False
433+
skip = self.getPC()
434+
self.addCommand(cmd)
435+
# Process the 'or'
436+
self.getCommandAt(get)['or'] = self.getPC()
437+
self.compileOne()
438+
# Fixup the skip
439+
self.getCommandAt(skip)['goto'] = self.getPC()
440+
return True
441+
return False
438442

439443
def r_get(self, command):
440444
global errorCode, errorReason
@@ -1414,6 +1418,33 @@ def r_split(self, command):
14141418

14151419
return self.nextPC()
14161420

1421+
# Shuffle a list
1422+
def k_shuffle(self, command):
1423+
if self.nextIsSymbol():
1424+
symbolRecord = self.getSymbolRecord()
1425+
if symbolRecord['valueHolder']:
1426+
command['target'] = self.getToken()
1427+
self.add(command)
1428+
return True
1429+
self.warning(f'Core.negate: Variable "{symbolRecord["name"]}" does not hold a value')
1430+
return False
1431+
1432+
def r_shuffle(self, command):
1433+
symbolRecord = self.getVariable(command['target'])
1434+
if not symbolRecord['valueHolder']:
1435+
RuntimeError(self.program, f'{symbolRecord["name"]} does not hold a value')
1436+
return None
1437+
value = self.getSymbolValue(symbolRecord)
1438+
if value == None:
1439+
RuntimeError(self.program, f'{symbolRecord["name"]} has not been initialised')
1440+
content = value['content']
1441+
if isinstance(content, list):
1442+
random.shuffle(content)
1443+
value['content'] = content
1444+
self.putSymbolValue(symbolRecord, value)
1445+
return self.nextPC()
1446+
RuntimeError(self.program, f'{symbolRecord["name"]} is not a list')
1447+
14171448
# Declare a stack variable
14181449
def k_stack(self, command):
14191450
return self.compileVariable(command)

easycoder/ec_graphics.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,41 @@ def k_frame(self, command):
161161
def r_frame(self, command):
162162
return self.nextPC()
163163

164+
# get {variable} from popup {type} {message} {title}
165+
def k_get(self, command):
166+
if self.nextIsSymbol():
167+
symbolRecord = self.getSymbolRecord()
168+
if symbolRecord['valueHolder']:
169+
command['target'] = self.getToken()
170+
else:
171+
FatalError(self.compiler, f'Variable "{symbolRecord["name"]}" does not hold a value')
172+
if symbolRecord['valueHolder']:
173+
if self.nextIs('from'):
174+
if self.nextIs('popup'):
175+
command['ptype'] = self.nextToken()
176+
command['message'] = self.nextValue()
177+
command['title'] = self.nextValue()
178+
self.addCommand(command)
179+
return True
180+
return False
181+
182+
def r_get(self, command):
183+
target = self.getVariable(command['target'])
184+
ptype = command['ptype']
185+
if ptype == 'text':
186+
text = psg.popup_get_text(self.getRuntimeValue(command['message']), title=self.getRuntimeValue(command['title']))
187+
elif ptype == 'ok-cancel':
188+
text = psg.popup_ok_cancel(self.getRuntimeValue(command['message']), title=self.getRuntimeValue(command['title']))
189+
elif ptype == 'yes-no':
190+
text = psg.popup_yes_no(self.getRuntimeValue(command['message']), title=self.getRuntimeValue(command['title']))
191+
else:
192+
return None
193+
v = {}
194+
v['type'] = 'text'
195+
v['content'] = text
196+
self.program.putSymbolValue(target, v)
197+
return self.nextPC()
198+
164199
def k_init(self, command):
165200
if self.nextIsSymbol():
166201
symbolRecord = self.getSymbolRecord()
@@ -219,13 +254,15 @@ def r_on(self, command):
219254
window['eventHandlers'][key] = lambda: self.run(command['goto'])
220255
return self.nextPC()
221256

257+
# popup {message} {title}
222258
def k_popup(self, command):
223259
command['message'] = self.nextValue()
260+
command['title'] = self.nextValue()
224261
self.addCommand(command)
225262
return True
226263

227264
def r_popup(self, command):
228-
psg.popup(self.getRuntimeValue(command['message']))
265+
psg.popup(self.getRuntimeValue(command['message']), title=self.getRuntimeValue(command['title']))
229266
return self.nextPC()
230267

231268
def k_refresh(self, command):

easycoder/ec_program.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,6 @@ def compare(self, value1, value2):
375375
if type(v2) == int:
376376
if type(v1) != int:
377377
v2 = f'{v2}'
378-
if type(v1) == dict and type(v2) == dict:
379-
v1 = json.dumps(v1)
380-
v2 = json.dumps(v2)
381378
if v1 > v2:
382379
return 1
383380
if v1 < v2:

test.ecg

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
! Test
2+
3+
script Test
4+
5+
variable Text
6+
7+
debug step
8+
9+
get Text from popup text `Type something` `Input test`
10+
popup `You typed ` cat Text `Test`
11+
12+
get Text from popup ok-cancel `I'm going to explode!` `OK Cancel test`
13+
popup `You replied ` cat Text `Test`
14+
15+
get Text from popup yes-no `Go ahead?` `Yes No test`
16+
popup `You replied ` cat Text `Test`
17+
exit

0 commit comments

Comments
 (0)