Skip to content

Commit e123644

Browse files
committed
v250116.2
1 parent 6e17194 commit e123644

File tree

5 files changed

+60
-91
lines changed

5 files changed

+60
-91
lines changed
31.1 KB
Binary file not shown.
3.09 MB
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__ = "250116.1"
12+
__version__ = "250116.2"

easycoder/ec_graphics.py

Lines changed: 48 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,18 @@ def getName(self):
1818

1919
def k_add(self, command):
2020
elements = []
21-
while True:
22-
if self.nextIsSymbol():
23-
symbolRecord = self.getSymbolRecord()
24-
name = symbolRecord['name']
25-
if 'iselement' in symbolRecord:
26-
elements.append(name)
27-
if self.peek() != 'and': break
28-
else: FatalError(self.program.compiler, f'"{name}" is not a graphic element')
29-
else: FatalError(self.program.compiler, f'Element expected; got "{self.getToken()}"')
30-
self.nextToken()
31-
command['elements'] = json.dumps(elements)
21+
token = self.nextToken()
22+
if self.isSymbol():
23+
symbolRecord = self.getSymbolRecord()
24+
name = symbolRecord['name']
25+
if symbolRecord['keyword'] == 'layout':
26+
elements.append(name)
27+
command['args'] = name
28+
else: FatalError(self.compiler.program, f'\'{name}\' is not a layout')
29+
elif token[0:2] == 'g_':
30+
command['type'] = token
31+
command['args'] = self.utils.getArgs(self)
32+
else: return False
3233
if self.nextIs('to'):
3334
if self.nextIsSymbol():
3435
symbolRecord = self.getSymbolRecord()
@@ -40,11 +41,18 @@ def k_add(self, command):
4041

4142
def r_add(self, command):
4243
target = self.getVariable(command['target'])
43-
elements = json.loads(command['elements'])
44+
type = command['type']
45+
args = command['args']
4446
if not 'layout' in target:
4547
target['layout'] = []
46-
for element in elements:
47-
v = self.getVariable(element)
48+
if args[0] == '{':
49+
layout = json.loads(self.getRuntimeValue(json.loads(args)))
50+
default = self.utils.getDefaultArgs(type)
51+
for n in range(0, len(layout)):
52+
args = self.utils.decode(default, layout[n])
53+
target['layout'].append(self.utils.createElement(type, args))
54+
else:
55+
v = self.getVariable(args)
4856
target['layout'].append(v['layout'])
4957
return self.nextPC()
5058

@@ -108,65 +116,6 @@ def r_create(self, command):
108116
else:
109117
RuntimeError(self.program, 'Variable is not a window or an element')
110118

111-
def k_g_button(self, command):
112-
command['iselement'] = True
113-
return self.compileVariable(command)
114-
115-
def r_g_button(self, command):
116-
return self.nextPC()
117-
118-
def k_g_input(self, command):
119-
command['iselement'] = True
120-
return self.compileVariable(command)
121-
122-
def r_g_input(self, command):
123-
return self.nextPC()
124-
125-
def k_g_text(self, command):
126-
command['iselement'] = True
127-
return self.compileVariable(command)
128-
129-
def r_g_text(self, command):
130-
return self.nextPC()
131-
132-
def k_init(self, command):
133-
if self.nextIsSymbol():
134-
record = self.getSymbolRecord()
135-
if record['keyword'] == 'layout':
136-
command['target'] = record['name']
137-
if self.peek() == 'with':
138-
self.nextToken()
139-
if self.nextIsSymbol():
140-
record = self.getSymbolRecord()
141-
name = record['name']
142-
if record['iselement']:
143-
command['args'] = name
144-
else: FatalError(self.program.compiler, f'\'{name}\' is not a graphic element')
145-
else:
146-
command['type'] = self.getToken()
147-
command['args'] = self.utils.getArgs(self)
148-
else: command['args'] = None
149-
self.addCommand(command)
150-
return True
151-
return False
152-
153-
def r_init(self, command):
154-
record = self.getVariable(command['target'])
155-
record['layout'] = []
156-
type = command['type']
157-
args = command['args']
158-
if args != None:
159-
if args[0] == '{':
160-
layout = json.loads(self.getRuntimeValue(json.loads(args)))
161-
args = self.utils.getDefaultArgs(type)
162-
for n in range(0, len(layout)):
163-
args = self.utils.decode(args, layout[n])
164-
record['layout'].append(self.utils.createElement(type, args))
165-
else:
166-
v = self.getVariable(args)
167-
record['layout'].append(v['layout'])
168-
return self.nextPC()
169-
170119
def k_layout(self, command):
171120
command['iselement'] = True
172121
return self.compileVariable(command)
@@ -259,9 +208,34 @@ def r_popup(self, command):
259208
return self.nextPC()
260209

261210
def k_set(self, command):
262-
return True
211+
if self.nextIsSymbol():
212+
record = self.getSymbolRecord()
213+
if record['keyword'] == 'layout':
214+
command['target'] = record['name']
215+
if self.peek() == 'to':
216+
self.nextToken()
217+
command['type'] = self.nextToken()
218+
command['args'] = self.utils.getArgs(self)
219+
else: command['args'] = None
220+
self.addCommand(command)
221+
return True
222+
return False
263223

264224
def r_set(self, command):
225+
target = self.getVariable(command['target'])
226+
target['layout'] = []
227+
type = command['type']
228+
args = command['args']
229+
if args != None:
230+
if args[0] == '{':
231+
layout = json.loads(self.getRuntimeValue(json.loads(args)))
232+
default = self.utils.getDefaultArgs(type)
233+
for n in range(0, len(layout)):
234+
args = self.utils.decode(default, layout[n])
235+
target['layout'].append(self.utils.createElement(type, args))
236+
else:
237+
v = self.getVariable(args)
238+
target['layout'].append(v['layout'])
265239
return self.nextPC()
266240

267241
def k_window(self, command):

scripts/testg.ecg

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,24 @@
55
layout Row
66
layout Layout
77
window Window
8-
g_input Input
9-
g_button Button
108
variable N
119

12-
init Layout
13-
14-
! popup `Hello!`
10+
popup `Hello!`
1511
! debug step
1612

17-
init Row with g_text text `Date (YYYY-MM-DD):` and expand_x true
18-
create Input key `-DATE-` and size `20 1`
19-
add Input to Row
13+
set Row to g_text text `Date (YYYY-MM-DD):` and expand_x true
14+
add g_input key `-DATE-` and size `20 1` to Row
2015
add Row to Layout
21-
init Row with g_text text `Time (HH:MM):` and expand_x true
22-
create Input key `-TIME-` and size `20 1`
23-
add Input to Row
16+
17+
set Row to g_text text `Time (HH:MM):` and expand_x true
18+
add g_input key `-TIME-` and size `20 1` to Row
2419
add Row to Layout
25-
init Row with g_text text `Your name:` and expand_x true
26-
create Input key `-NAME-` and size `20 1`
27-
add Input to Row
20+
21+
set Row to g_text text `Your name:` and expand_x true
22+
add g_input key `-NAME-` and size `20 1` to Row
2823
add Row to Layout
29-
create Button button_text `Click me`
30-
init Row with Button
24+
25+
set Row to g_button button_text `Click me`
3126
add Row to Layout
3227

3328
create Window `Graphics Test`

0 commit comments

Comments
 (0)