Skip to content

Commit dcbe545

Browse files
committed
250420.1
1 parent 20bad86 commit dcbe545

12 files changed

+353
-11
lines changed
-33.4 KB
Binary file not shown.
-33.4 KB
Binary file not shown.

dist/easycoder-250403.2.tar.gz

-3.1 MB
Binary file not shown.

dist/easycoder-250404.1.tar.gz

-3.1 MB
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__ = "250404.1"
12+
__version__ = "250406.1"

easycoder/ec_core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,7 @@ def r_set(self, command):
13371337
newValue[index] = value
13381338
symbolRecord['elements'] = elements
13391339
symbolRecord['value'] = newValue
1340+
symbolRecord['index'] = 0
13401341
return self.nextPC()
13411342

13421343
elif cmdType == 'element':

plugins/ec_pyside6.py

Lines changed: 295 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,295 @@
1+
import sys
2+
from easycoder import Handler, FatalError, RuntimeError
3+
from PySide6.QtCore import QTimer
4+
from PySide6.QtWidgets import (
5+
QApplication,
6+
QCheckBox,
7+
QComboBox,
8+
QDateEdit,
9+
QDateTimeEdit,
10+
QDial,
11+
QDoubleSpinBox,
12+
QFontComboBox,
13+
QLabel,
14+
QLCDNumber,
15+
QLineEdit,
16+
QMainWindow,
17+
QProgressBar,
18+
QPushButton,
19+
QRadioButton,
20+
QSlider,
21+
QSpinBox,
22+
QTimeEdit,
23+
QVBoxLayout,
24+
QHBoxLayout,
25+
QGridLayout,
26+
QStackedLayout,
27+
QWidget
28+
)
29+
30+
class Graphics(Handler):
31+
32+
class MainWindow(QMainWindow):
33+
34+
def __init__(self):
35+
super().__init__()
36+
37+
def __init__(self, compiler):
38+
Handler.__init__(self, compiler)
39+
40+
def getName(self):
41+
return 'pyside6'
42+
43+
def closeEvent(self):
44+
print('window closed')
45+
46+
#############################################################################
47+
# Keyword handlers
48+
49+
# Add a widget to a layout
50+
def k_add(self, command):
51+
if self.nextIsSymbol():
52+
record = self.getSymbolRecord()
53+
command['widget'] = record['name']
54+
if self.nextIs('to'):
55+
if self.nextIsSymbol():
56+
record = self.getSymbolRecord()
57+
command['layout'] = record['name']
58+
self.add(command)
59+
return True
60+
return False
61+
62+
def r_add(self, command):
63+
widgetRecord = self.getVariable(command['widget'])
64+
layoutRecord = self.getVariable(command['layout'])
65+
if widgetRecord['keyword'] == 'layout':
66+
layoutRecord['widget'].addLayout(widgetRecord['widget'])
67+
else:
68+
layoutRecord['widget'].addWidget(widgetRecord['widget'])
69+
return self.nextPC()
70+
71+
# Create a window
72+
def k_createWindow(self, command):
73+
command['title'] = 'Default'
74+
command['x'] = 100
75+
command['y'] = 100
76+
command['w'] = 640
77+
command['h'] = 480
78+
while True:
79+
token = self.peek()
80+
if token in ['title', 'at', 'size']:
81+
self.nextToken()
82+
if token == 'title': command['title'] = self.nextValue()
83+
elif token == 'at':
84+
command['x'] = self.nextValue()
85+
command['y'] = self.nextValue()
86+
elif token == 'size':
87+
command['w'] = self.nextValue()
88+
command['h'] = self.nextValue()
89+
else: break
90+
self.add(command)
91+
return True
92+
93+
# Create a widget
94+
def k_createLayout(self, command):
95+
if self.nextIs('type'):
96+
command['type'] = self.nextToken()
97+
self.add(command)
98+
return True
99+
return False
100+
101+
def k_createLabel(self, command):
102+
if self.peek() == 'text':
103+
self.nextToken()
104+
text = self.nextValue()
105+
else: text = ''
106+
command['text'] = text
107+
self.add(command)
108+
return True
109+
110+
def k_createPushbutton(self, command):
111+
if self.peek() == 'text':
112+
self.nextToken()
113+
text = self.nextValue()
114+
else: text = ''
115+
command['text'] = text
116+
self.add(command)
117+
return True
118+
119+
def k_create(self, command):
120+
if self.nextIsSymbol():
121+
record = self.getSymbolRecord()
122+
command['name'] = record['name']
123+
keyword = record['keyword']
124+
if keyword == 'window': return self.k_createWindow(command)
125+
elif keyword == 'layout': return self.k_createLayout(command)
126+
elif keyword == 'label': return self.k_createLabel(command)
127+
elif keyword == 'pushbutton': return self.k_createPushbutton(command)
128+
return False
129+
130+
def r_createWindow(self, command, record):
131+
window = self.MainWindow()
132+
window.setWindowTitle(self.getRuntimeValue(command['title']))
133+
x = self.getRuntimeValue(command['x'])
134+
y = self.getRuntimeValue(command['y'])
135+
w = self.getRuntimeValue(command['w'])
136+
h = self.getRuntimeValue(command['h'])
137+
if x != None and y != None and w != None and h != None:
138+
window.setGeometry(x, y, w, h)
139+
record['window'] = window
140+
return self.nextPC()
141+
142+
def r_createLayout(self, command, record):
143+
type = command['type']
144+
if type == 'QHBoxLayout': layout = QHBoxLayout()
145+
elif type == 'QGridLayout': layout = QGridLayout()
146+
elif type == 'QStackedLayout': layout = QStackedLayout()
147+
else: layout = QVBoxLayout()
148+
record['widget'] = layout
149+
return self.nextPC()
150+
151+
def r_createLabel(self, command, record):
152+
label = QLabel(self.getRuntimeValue(command['text']))
153+
record['widget'] = label
154+
return self.nextPC()
155+
156+
def r_createPushbutton(self, command, record):
157+
pushbutton = QPushButton(self.getRuntimeValue(command['text']))
158+
record['widget'] = pushbutton
159+
return self.nextPC()
160+
161+
def r_create(self, command):
162+
record = self.getVariable(command['name'])
163+
keyword = record['keyword']
164+
if keyword == 'window': return self.r_createWindow(command, record)
165+
elif keyword == 'layout': return self.r_createLayout(command, record)
166+
elif keyword == 'label': return self.r_createLabel(command, record)
167+
elif keyword == 'pushbutton': return self.r_createPushbutton(command, record)
168+
return None
169+
170+
# Initialize the graphics environment
171+
def k_init(self, command):
172+
if self.nextIs('graphics'):
173+
self.add(command)
174+
return True
175+
return False
176+
177+
def r_init(self, command):
178+
self.app = QApplication(sys.argv)
179+
return self.nextPC()
180+
181+
# Declare a label variable
182+
def k_label(self, command):
183+
return self.compileVariable(command, False)
184+
185+
def r_label(self, command):
186+
return self.nextPC()
187+
188+
# Declare a layout variable
189+
def k_layout(self, command):
190+
return self.compileVariable(command, False)
191+
192+
def r_layout(self, command):
193+
return self.nextPC()
194+
195+
# Declare a pushbutton variable
196+
def k_pushbutton(self, command):
197+
return self.compileVariable(command, False)
198+
199+
def r_pushbutton(self, command):
200+
return self.nextPC()
201+
202+
# Clean exit
203+
def on_last_window_closed(self):
204+
print("Last window closed! Performing cleanup...")
205+
self.program.kill()
206+
207+
# This is called every 10ms to keep the main application running
208+
def flush(self):
209+
self.program.flushCB()
210+
211+
# Resume execution at the line following 'start graphics'
212+
def resume(self):
213+
self.program.flush(self.nextPC())
214+
215+
# Show a window with a specified layout
216+
# show {name} in {window}}
217+
def k_show(self, command):
218+
if self.nextIsSymbol():
219+
record = self.getSymbolRecord()
220+
if record['keyword'] == 'layout':
221+
command['layout'] = record['name']
222+
if self.nextIs('in'):
223+
if self.nextIsSymbol():
224+
record = self.getSymbolRecord()
225+
if record['keyword'] == 'window':
226+
command['window'] = record['name']
227+
self.add(command)
228+
return True
229+
return False
230+
231+
def r_show(self, command):
232+
layoutRecord = self.getVariable(command['layout'])
233+
windowRecord = self.getVariable(command['window'])
234+
window = windowRecord['window']
235+
container = QWidget()
236+
container.setLayout(layoutRecord['widget'])
237+
window.setCentralWidget(container)
238+
window.show()
239+
return self.nextPC()
240+
241+
# Start the graphics
242+
def k_start(self, command):
243+
if self.nextIs('graphics'):
244+
self.add(command)
245+
return True
246+
return False
247+
248+
def r_start(self, command):
249+
timer = QTimer()
250+
timer.timeout.connect(self.flush)
251+
timer.start(10)
252+
QTimer.singleShot(500, self.resume)
253+
self.app.lastWindowClosed.connect(self.on_last_window_closed)
254+
self.app.exec()
255+
256+
# Declare a window variable
257+
def k_window(self, command):
258+
return self.compileVariable(command, False)
259+
260+
def r_window(self, command):
261+
return self.nextPC()
262+
263+
#############################################################################
264+
# Compile a value in this domain
265+
def compileValue(self):
266+
value = {}
267+
value['domain'] = 'rbr'
268+
if self.tokenIs('the'):
269+
self.nextToken()
270+
token = self.getToken()
271+
if token == 'xxxxx':
272+
return value
273+
274+
return None
275+
276+
#############################################################################
277+
# Modify a value or leave it unchanged.
278+
def modifyValue(self, value):
279+
return value
280+
281+
#############################################################################
282+
# Value handlers
283+
284+
def v_xxxxx(self, v):
285+
value = {}
286+
return value
287+
288+
#############################################################################
289+
# Compile a condition
290+
def compileCondition(self):
291+
condition = {}
292+
return condition
293+
294+
#############################################################################
295+
# Condition handlers

test.ecs

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,57 @@
1-
! Test
1+
! test.ecs
22

33
script Test
44

5-
variable Text
5+
import plugin Graphics from plugins/ec_pyside6.py
66

7-
debug step
7+
window Window
8+
layout MainPanel
9+
layout LeftPanel
10+
layout RightPanel
11+
label Label
12+
pushbutton Button1
13+
pushbutton Button2
14+
pushbutton Button3
15+
pushbutton Button4
16+
pushbutton Button5
17+
variable N
818

9-
put `12345jj6789 S Room1` into Text
10-
! split Text on ` `
11-
! index Text to 2
12-
print Text
13-
put `junk` into Text
14-
if file Text does not exist print `Yes`
15-
exit
19+
! debug step
20+
21+
log `Starting`
22+
init graphics
23+
create Window title `My window` at 100 100 size 400 300
24+
create MainPanel type QHBoxLayout
25+
26+
create LeftPanel type QVBoxLayout
27+
add LeftPanel to MainPanel
28+
create Button1 text `Button 1`
29+
add Button1 to LeftPanel
30+
create Button2 text `Button 2`
31+
add Button2 to LeftPanel
32+
create Button3 text `Button 3`
33+
add Button3 to LeftPanel
34+
create Button4 text `Button 4`
35+
add Button4 to LeftPanel
36+
create Button5 text `Button 5`
37+
add Button5 to LeftPanel
38+
39+
create RightPanel type QVBoxLayout
40+
add RightPanel to MainPanel
41+
create Label text `Hello, world!`
42+
add Label to RightPanel
43+
44+
show MainPanel in Window
45+
46+
start graphics
47+
log `Graphics running`
48+
49+
put 0 into N
50+
while true
51+
begin
52+
log N
53+
increment N
54+
wait 1
55+
end
56+
57+
! exit

test.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"Kitchen": {"status": "good", "errors": 0}}

test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from easycoder import Program
2+
3+
Program('test.ecs').start()

0 commit comments

Comments
 (0)