easycoder 260110.1__py2.py3-none-any.whl → 260118.3__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of easycoder might be problematic. Click here for more details.
- easycoder/__init__.py +2 -1
- easycoder/ec_classes.py +11 -2
- easycoder/ec_compiler.py +1 -0
- easycoder/ec_core.py +100 -50
- easycoder/ec_gclasses.py +36 -9
- easycoder/ec_graphics.py +65 -12
- easycoder/ec_mqtt.py +435 -0
- easycoder/ec_program.py +30 -13
- easycoder/ec_value.py +4 -3
- easycoder/pre/ec_core.py +8 -9
- easycoder/pre/ec_program.py +1 -1
- easycoder/pre/ec_value.py +1 -1
- {easycoder-260110.1.dist-info → easycoder-260118.3.dist-info}/METADATA +2 -1
- {easycoder-260110.1.dist-info → easycoder-260118.3.dist-info}/RECORD +17 -16
- {easycoder-260110.1.dist-info → easycoder-260118.3.dist-info}/WHEEL +0 -0
- {easycoder-260110.1.dist-info → easycoder-260118.3.dist-info}/entry_points.txt +0 -0
- {easycoder-260110.1.dist-info → easycoder-260118.3.dist-info}/licenses/LICENSE +0 -0
easycoder/__init__.py
CHANGED
|
@@ -9,9 +9,10 @@ from .ec_gclasses import *
|
|
|
9
9
|
from .ec_graphics import *
|
|
10
10
|
from .ec_handler import *
|
|
11
11
|
from .ec_keyboard import *
|
|
12
|
+
from .ec_mqtt import *
|
|
12
13
|
from .ec_program import *
|
|
13
14
|
from .ec_psutil import *
|
|
14
15
|
from .ec_timestamp import *
|
|
15
16
|
from .ec_value import *
|
|
16
17
|
|
|
17
|
-
__version__ = "
|
|
18
|
+
__version__ = "260118.3"
|
easycoder/ec_classes.py
CHANGED
|
@@ -312,6 +312,12 @@ class ECValueHolder(ECObject):
|
|
|
312
312
|
# Reset the object to empty state
|
|
313
313
|
def reset(self):
|
|
314
314
|
self.setValue(ECValue(content=None))
|
|
315
|
+
|
|
316
|
+
def textify(self):
|
|
317
|
+
v = self.getValue()
|
|
318
|
+
if v is None:
|
|
319
|
+
return ""
|
|
320
|
+
return json.dumps(v.getContent())
|
|
315
321
|
|
|
316
322
|
###############################################################################
|
|
317
323
|
# A string or int variable
|
|
@@ -351,7 +357,7 @@ class ECDictionary(ECValueHolder):
|
|
|
351
357
|
if types_equal(varType, str):
|
|
352
358
|
try:
|
|
353
359
|
if content in ('', {}, None): content = {}
|
|
354
|
-
|
|
360
|
+
elif content[0] in ('{', '['): content = json.loads(content) # type: ignore
|
|
355
361
|
except:
|
|
356
362
|
raise RuntimeError(None, 'ECDictionary string value is not valid JSON') # type: ignore
|
|
357
363
|
elif varType == None:
|
|
@@ -387,7 +393,10 @@ class ECDictionary(ECValueHolder):
|
|
|
387
393
|
content = self.getValue()
|
|
388
394
|
if content is None:
|
|
389
395
|
return None
|
|
390
|
-
|
|
396
|
+
if key in content:
|
|
397
|
+
return content[key]
|
|
398
|
+
else:
|
|
399
|
+
return None
|
|
391
400
|
|
|
392
401
|
# Delete an entry from the dictionary
|
|
393
402
|
def deleteEntry(self, key):
|
easycoder/ec_compiler.py
CHANGED
easycoder/ec_core.py
CHANGED
|
@@ -2,6 +2,7 @@ import json, math, hashlib, threading, os, subprocess, time
|
|
|
2
2
|
import base64, binascii, random, requests, paramiko, uuid
|
|
3
3
|
from copy import deepcopy
|
|
4
4
|
from datetime import datetime
|
|
5
|
+
from pathlib import Path
|
|
5
6
|
from .ec_classes import (
|
|
6
7
|
FatalError,
|
|
7
8
|
RuntimeWarning,
|
|
@@ -70,7 +71,7 @@ class Core(Handler):
|
|
|
70
71
|
if not isinstance(self.getObject(record), ECVariable): return False
|
|
71
72
|
# If 'giving' comes next, this variable is the second value
|
|
72
73
|
if self.peek() == 'giving':
|
|
73
|
-
v2 = ECValue(type='symbol',
|
|
74
|
+
v2 = ECValue(type='symbol', name=record['name'])
|
|
74
75
|
command['value2'] = v2
|
|
75
76
|
self.nextToken()
|
|
76
77
|
# Now get the target variable
|
|
@@ -165,12 +166,32 @@ class Core(Handler):
|
|
|
165
166
|
return self.compileFromHere(['end'])
|
|
166
167
|
|
|
167
168
|
# clear {variable}
|
|
169
|
+
# clear entry {name} of {dictionary}
|
|
170
|
+
# clear item {index} of {list}
|
|
168
171
|
def k_clear(self, command):
|
|
169
172
|
token = self.nextToken()
|
|
170
173
|
if token == 'breakpoint':
|
|
171
174
|
command['breakpoint'] = True
|
|
172
175
|
self.add(command)
|
|
173
176
|
return True
|
|
177
|
+
elif token == 'entry':
|
|
178
|
+
command['key'] = self.nextValue()
|
|
179
|
+
self.skip('of')
|
|
180
|
+
if self.nextIsSymbol():
|
|
181
|
+
record = self.getSymbolRecord()
|
|
182
|
+
self.checkObjectType(self.getObject(record), ECDictionary)
|
|
183
|
+
command['target'] = record['name']
|
|
184
|
+
self.add(command)
|
|
185
|
+
return True
|
|
186
|
+
elif token == 'item':
|
|
187
|
+
command['index'] = self.nextValue()
|
|
188
|
+
self.skip('of')
|
|
189
|
+
if self.nextIsSymbol():
|
|
190
|
+
record = self.getSymbolRecord()
|
|
191
|
+
self.checkObjectType(self.getObject(record), ECList)
|
|
192
|
+
command['target'] = record['name']
|
|
193
|
+
self.add(command)
|
|
194
|
+
return True
|
|
174
195
|
elif self.isSymbol():
|
|
175
196
|
record = self.getSymbolRecord()
|
|
176
197
|
command['target'] = record['name']
|
|
@@ -186,6 +207,14 @@ class Core(Handler):
|
|
|
186
207
|
def r_clear(self, command):
|
|
187
208
|
if 'breakpoint' in command:
|
|
188
209
|
self.program.breakpoint = False
|
|
210
|
+
elif 'key' in command:
|
|
211
|
+
key = self.textify(command['key'])
|
|
212
|
+
record = self.getVariable(command['target'])
|
|
213
|
+
self.getObject(record).setEntry(key, ECValue(type=bool, content=False))
|
|
214
|
+
elif 'index' in command:
|
|
215
|
+
index = self.textify(command['index'])
|
|
216
|
+
record = self.getVariable(command['target'])
|
|
217
|
+
self.getObject(record).setItem(index, ECValue(type=bool, content=False))
|
|
189
218
|
else:
|
|
190
219
|
target = self.getVariable(command['target'])
|
|
191
220
|
if target['keyword'] == 'ssh':
|
|
@@ -199,10 +228,10 @@ class Core(Handler):
|
|
|
199
228
|
def k_close(self, command):
|
|
200
229
|
if self.nextIsSymbol():
|
|
201
230
|
fileRecord = self.getSymbolRecord()
|
|
202
|
-
self.
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
231
|
+
if isinstance(self.getObject(fileRecord), ECFile):
|
|
232
|
+
command['file'] = fileRecord['name']
|
|
233
|
+
self.add(command)
|
|
234
|
+
return True
|
|
206
235
|
return False
|
|
207
236
|
|
|
208
237
|
def r_close(self, command):
|
|
@@ -794,6 +823,7 @@ class Core(Handler):
|
|
|
794
823
|
ssh = self.getVariable(command['ssh'])
|
|
795
824
|
path = self.textify(command['path'])
|
|
796
825
|
sftp = ssh['sftp']
|
|
826
|
+
print(f'Loading from path: {Path(path).expanduser()}')
|
|
797
827
|
try:
|
|
798
828
|
with sftp.open(path, 'r') as remote_file: content = remote_file.read().decode()
|
|
799
829
|
except:
|
|
@@ -806,7 +836,7 @@ class Core(Handler):
|
|
|
806
836
|
else:
|
|
807
837
|
filename = self.textify(command['file'])
|
|
808
838
|
try:
|
|
809
|
-
with open(filename) as f: content = f.read()
|
|
839
|
+
with open(Path(filename).expanduser()) as f: content = f.read()
|
|
810
840
|
except:
|
|
811
841
|
errorReason = f'Unable to read from {filename}'
|
|
812
842
|
|
|
@@ -1335,7 +1365,7 @@ class Core(Handler):
|
|
|
1335
1365
|
content = json.dumps(content)
|
|
1336
1366
|
elif not isinstance(content, str):
|
|
1337
1367
|
content = self.textify(content)
|
|
1338
|
-
with open(filename, 'w') as f: f.write(content)
|
|
1368
|
+
with open(Path(filename).expanduser(), 'w') as f: f.write(content)
|
|
1339
1369
|
except Exception as e:
|
|
1340
1370
|
errorReason = f'Unable to write to {filename}: {str(e)}'
|
|
1341
1371
|
|
|
@@ -1371,8 +1401,9 @@ class Core(Handler):
|
|
|
1371
1401
|
return self.nextPC()
|
|
1372
1402
|
|
|
1373
1403
|
# Set a value
|
|
1374
|
-
# set {variable}
|
|
1375
|
-
# set {
|
|
1404
|
+
# set {variable} [to {value}]
|
|
1405
|
+
# set entry {key} of {dictionary} [to {value}]
|
|
1406
|
+
# set item {index} of {list} [to {value}]
|
|
1376
1407
|
# set {ssh} host {host} user {user} password {password}
|
|
1377
1408
|
# set the items/elements in/of {variable} to {value}
|
|
1378
1409
|
# set item/entry/property of {variable} to {value}
|
|
@@ -1403,16 +1434,15 @@ class Core(Handler):
|
|
|
1403
1434
|
command['type'] = 'ssh'
|
|
1404
1435
|
self.add(command)
|
|
1405
1436
|
return True
|
|
1406
|
-
elif isinstance(self.getObject(record), ECVariable):
|
|
1407
|
-
self.
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
if value != None:
|
|
1437
|
+
elif isinstance(self.getObject(record), (ECVariable, ECDictionary, ECList)):
|
|
1438
|
+
if self.peek() == 'to':
|
|
1439
|
+
self.nextToken()
|
|
1440
|
+
value = self.nextValue()
|
|
1411
1441
|
command['type'] = 'setValue'
|
|
1412
1442
|
command['value'] = value
|
|
1413
|
-
|
|
1414
|
-
self.rewindTo(mark)
|
|
1443
|
+
elif isinstance(self.getObject(record), ECVariable):
|
|
1415
1444
|
command['type'] = 'set'
|
|
1445
|
+
else: return False
|
|
1416
1446
|
self.add(command)
|
|
1417
1447
|
return True
|
|
1418
1448
|
return False
|
|
@@ -1440,19 +1470,30 @@ class Core(Handler):
|
|
|
1440
1470
|
self.add(command)
|
|
1441
1471
|
return True
|
|
1442
1472
|
|
|
1443
|
-
elif token in ('entry', 'property'):
|
|
1473
|
+
elif token in ('entry', 'item', 'property'):
|
|
1444
1474
|
command['key'] = self.nextValue()
|
|
1445
1475
|
if self.nextIs('of'):
|
|
1446
1476
|
if self.nextIsSymbol():
|
|
1447
1477
|
record = self.getSymbolRecord()
|
|
1448
1478
|
if token == 'entry':
|
|
1449
1479
|
self.checkObjectType(self.getObject(record), ECDictionary)
|
|
1480
|
+
elif token == 'item':
|
|
1481
|
+
self.checkObjectType(self.getObject(record), ECList)
|
|
1450
1482
|
command['target'] = record['name']
|
|
1451
|
-
if self.
|
|
1452
|
-
|
|
1453
|
-
if
|
|
1454
|
-
|
|
1455
|
-
|
|
1483
|
+
if self.peek() == 'to':
|
|
1484
|
+
self.nextToken()
|
|
1485
|
+
if self.nextIsSymbol():
|
|
1486
|
+
record = self.getSymbolRecord()
|
|
1487
|
+
command['name'] = record['name']
|
|
1488
|
+
else:
|
|
1489
|
+
value = self.getValue()
|
|
1490
|
+
if value == None:
|
|
1491
|
+
FatalError(self.compiler, 'Unable to get a value')
|
|
1492
|
+
command['value'] = value
|
|
1493
|
+
self.add(command)
|
|
1494
|
+
return True
|
|
1495
|
+
else: # Set True
|
|
1496
|
+
command['value'] = ECValue(type=bool, content=True)
|
|
1456
1497
|
self.add(command)
|
|
1457
1498
|
return True
|
|
1458
1499
|
|
|
@@ -1499,6 +1540,18 @@ class Core(Handler):
|
|
|
1499
1540
|
object.setElements(elements)
|
|
1500
1541
|
return self.nextPC()
|
|
1501
1542
|
|
|
1543
|
+
elif cmdType == 'entry':
|
|
1544
|
+
key = self.textify(command['key'])
|
|
1545
|
+
if 'name' in command:
|
|
1546
|
+
value = self.textify(self.getVariable(command['name']))
|
|
1547
|
+
elif 'value' in command:
|
|
1548
|
+
value = self.textify(command['value'])
|
|
1549
|
+
record = self.getVariable(command['target'])
|
|
1550
|
+
self.checkObjectType(self.getObject(record), ECDictionary)
|
|
1551
|
+
variable = self.getObject(record)
|
|
1552
|
+
variable.setEntry(key, value)
|
|
1553
|
+
return self.nextPC()
|
|
1554
|
+
|
|
1502
1555
|
elif cmdType == 'item':
|
|
1503
1556
|
index = self.textify(command['index'])
|
|
1504
1557
|
value = self.textify(command['value'])
|
|
@@ -1517,15 +1570,6 @@ class Core(Handler):
|
|
|
1517
1570
|
os.chdir(path)
|
|
1518
1571
|
return self.nextPC()
|
|
1519
1572
|
|
|
1520
|
-
elif cmdType == 'entry':
|
|
1521
|
-
key = self.textify(command['key'])
|
|
1522
|
-
value = self.textify(command['value'])
|
|
1523
|
-
record = self.getVariable(command['target'])
|
|
1524
|
-
self.checkObjectType(self.getObject(record), ECDictionary)
|
|
1525
|
-
variable = self.getObject(record)
|
|
1526
|
-
variable.setEntry(key, value)
|
|
1527
|
-
return self.nextPC()
|
|
1528
|
-
|
|
1529
1573
|
elif cmdType == 'property':
|
|
1530
1574
|
key = self.textify(command['key'])
|
|
1531
1575
|
value = self.evaluate(command['value'])
|
|
@@ -1686,8 +1730,7 @@ class Core(Handler):
|
|
|
1686
1730
|
self.checkObjectType(record, ECObject)
|
|
1687
1731
|
# If 'giving' comes next, this variable is the second value
|
|
1688
1732
|
if self.peek() == 'giving':
|
|
1689
|
-
v2 = ECValue(type='symbol')
|
|
1690
|
-
v2.setContent(record['name'])
|
|
1733
|
+
v2 = ECValue(type='symbol', name=record['name'])
|
|
1691
1734
|
command['value2'] = v2
|
|
1692
1735
|
self.nextToken()
|
|
1693
1736
|
# Now get the target variable
|
|
@@ -1815,7 +1858,7 @@ class Core(Handler):
|
|
|
1815
1858
|
token = self.nextToken()
|
|
1816
1859
|
if token == 'graphics':
|
|
1817
1860
|
return self.program.useGraphics()
|
|
1818
|
-
|
|
1861
|
+
if token == 'mqtt':
|
|
1819
1862
|
return self.program.useMQTT()
|
|
1820
1863
|
elif token == 'psutil':
|
|
1821
1864
|
return self.program.usePSUtil()
|
|
@@ -1950,8 +1993,12 @@ class Core(Handler):
|
|
|
1950
1993
|
value = ECValue()
|
|
1951
1994
|
token = self.getToken()
|
|
1952
1995
|
if self.isSymbol():
|
|
1953
|
-
|
|
1954
|
-
|
|
1996
|
+
record = self.getSymbolRecord()
|
|
1997
|
+
if self.isObjectType(record, (ECVariable, ECDictionary, ECList, ECStack, ECSSH, ECFile, ECModule)):
|
|
1998
|
+
value.setType('symbol')
|
|
1999
|
+
value.name = record['name']
|
|
2000
|
+
return value
|
|
2001
|
+
else: return None
|
|
1955
2002
|
|
|
1956
2003
|
value.setType(token)
|
|
1957
2004
|
|
|
@@ -1990,7 +2037,7 @@ class Core(Handler):
|
|
|
1990
2037
|
if self.nextIsSymbol():
|
|
1991
2038
|
record = self.getSymbolRecord()
|
|
1992
2039
|
self.checkObjectType(record['object'], ECList)
|
|
1993
|
-
value.target = ECValue(type='symbol',
|
|
2040
|
+
value.target = ECValue(type='symbol', name=record['name'])
|
|
1994
2041
|
return value
|
|
1995
2042
|
return None
|
|
1996
2043
|
|
|
@@ -2049,7 +2096,7 @@ class Core(Handler):
|
|
|
2049
2096
|
record = self.getSymbolRecord()
|
|
2050
2097
|
object = record['object']
|
|
2051
2098
|
if isinstance(object, ECList):
|
|
2052
|
-
value.
|
|
2099
|
+
value.setName(record['name'])
|
|
2053
2100
|
return value
|
|
2054
2101
|
return None
|
|
2055
2102
|
|
|
@@ -2194,6 +2241,13 @@ class Core(Handler):
|
|
|
2194
2241
|
|
|
2195
2242
|
return value
|
|
2196
2243
|
|
|
2244
|
+
#############################################################################
|
|
2245
|
+
# Get the value of an unknown item
|
|
2246
|
+
def getUnknownValue(self, value):
|
|
2247
|
+
if self.isObjectType(value, (ECVariable, ECDictionary, ECList)):
|
|
2248
|
+
return value.getContent() # type: ignore
|
|
2249
|
+
return None # Unable to get value
|
|
2250
|
+
|
|
2197
2251
|
#############################################################################
|
|
2198
2252
|
# Value handlers
|
|
2199
2253
|
|
|
@@ -2218,7 +2272,7 @@ class Core(Handler):
|
|
|
2218
2272
|
return ECValue(type=int, content=round(math.cos(angle * 0.01745329) * radius))
|
|
2219
2273
|
|
|
2220
2274
|
def v_count(self, v):
|
|
2221
|
-
variable = self.getObject(self.getVariable(v.
|
|
2275
|
+
variable = self.getObject(self.getVariable(v.getName()))
|
|
2222
2276
|
return ECValue(type=int, content=variable.getItemCount())
|
|
2223
2277
|
|
|
2224
2278
|
def v_datime(self, v):
|
|
@@ -2352,7 +2406,7 @@ class Core(Handler):
|
|
|
2352
2406
|
def v_item(self, v):
|
|
2353
2407
|
index = self.textify(v.index)
|
|
2354
2408
|
targetName = v.target
|
|
2355
|
-
target = self.getVariable(targetName.
|
|
2409
|
+
target = self.getVariable(targetName.getName())
|
|
2356
2410
|
variable = self.getObject(target)
|
|
2357
2411
|
self.checkObjectType(variable, ECList)
|
|
2358
2412
|
if index >= variable.getItemCount():
|
|
@@ -2461,14 +2515,10 @@ class Core(Handler):
|
|
|
2461
2515
|
|
|
2462
2516
|
# This is used by the expression evaluator to get the value of a symbol
|
|
2463
2517
|
def v_symbol(self, v):
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
keyword = record['keyword']
|
|
2467
|
-
if keyword == 'object':
|
|
2468
|
-
return record['object'].getValue()
|
|
2469
|
-
elif keyword == 'variable':
|
|
2518
|
+
record = self.program.getSymbolRecord(v.name)
|
|
2519
|
+
if self.isObjectType(record, (ECVariable, ECDictionary, ECList)):
|
|
2470
2520
|
return self.getSymbolValue(record)
|
|
2471
|
-
elif
|
|
2521
|
+
elif self.isObjectType(record, ECSSH):
|
|
2472
2522
|
return ECValue(type=bool, content=True if 'ssh' in record and record['ssh'] != None else False)
|
|
2473
2523
|
else:
|
|
2474
2524
|
return None
|
|
@@ -2532,7 +2582,7 @@ class Core(Handler):
|
|
|
2532
2582
|
return ECValue(type=str, content=content.upper())
|
|
2533
2583
|
|
|
2534
2584
|
def v_uuid(self, v):
|
|
2535
|
-
return ECValue(type=str, content=str(uuid.uuid4())
|
|
2585
|
+
return ECValue(type=str, content=str(uuid.uuid4()))
|
|
2536
2586
|
|
|
2537
2587
|
def v_valueOf(self, v):
|
|
2538
2588
|
v = self.textify(v.getContent())
|
|
@@ -2712,7 +2762,7 @@ class Core(Handler):
|
|
|
2712
2762
|
|
|
2713
2763
|
def c_empty(self, condition):
|
|
2714
2764
|
if condition.value1.getType() == 'symbol':
|
|
2715
|
-
record = self.getVariable(condition.value1.
|
|
2765
|
+
record = self.getVariable(condition.value1.name)
|
|
2716
2766
|
variable = self.getObject(record)
|
|
2717
2767
|
if isinstance(variable, (ECList, ECDictionary)):
|
|
2718
2768
|
comparison = variable.isEmpty()
|
|
@@ -2739,7 +2789,7 @@ class Core(Handler):
|
|
|
2739
2789
|
|
|
2740
2790
|
def c_exists(self, condition):
|
|
2741
2791
|
path = self.textify(condition.path)
|
|
2742
|
-
comparison = os.path.exists(path)
|
|
2792
|
+
comparison = os.path.exists(Path(path).expanduser())
|
|
2743
2793
|
return not comparison if condition.negate else comparison
|
|
2744
2794
|
|
|
2745
2795
|
def c_greater(self, condition):
|
easycoder/ec_gclasses.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from .ec_classes import ECObject
|
|
1
|
+
from .ec_classes import ECValue, ECObject
|
|
2
2
|
|
|
3
3
|
###############################################################################
|
|
4
4
|
# A generic graphic element
|
|
@@ -75,6 +75,13 @@ class ECLabel(ECTextWidget):
|
|
|
75
75
|
# This is a core class
|
|
76
76
|
def isCoreClass(self):
|
|
77
77
|
return True
|
|
78
|
+
|
|
79
|
+
def getContent(self):
|
|
80
|
+
return self.getValue().text() # type: ignore
|
|
81
|
+
|
|
82
|
+
# Get the text of the widget
|
|
83
|
+
def textify(self):
|
|
84
|
+
return self.getContent()
|
|
78
85
|
|
|
79
86
|
###############################################################################
|
|
80
87
|
# A pushbutton variable
|
|
@@ -100,7 +107,7 @@ class ECCheckBox(ECCoreWidget):
|
|
|
100
107
|
def getContent(self):
|
|
101
108
|
v = self.getValue()
|
|
102
109
|
if v is None: return None
|
|
103
|
-
return v.
|
|
110
|
+
return v.isChecked() # type: ignore
|
|
104
111
|
|
|
105
112
|
###############################################################################
|
|
106
113
|
# A line input widget
|
|
@@ -112,6 +119,32 @@ class ECLineInput(ECTextWidget):
|
|
|
112
119
|
def hasRuntimeValue(self):
|
|
113
120
|
return True
|
|
114
121
|
|
|
122
|
+
# Set the text of the widget
|
|
123
|
+
def setText(self, text):
|
|
124
|
+
v = self.getValue()
|
|
125
|
+
if v is None: return
|
|
126
|
+
v.getContent().setText(str(text)) # type: ignore
|
|
127
|
+
|
|
128
|
+
# Get the content of the value at the current index
|
|
129
|
+
def getContent(self):
|
|
130
|
+
content = self.getValue()
|
|
131
|
+
if content is None: return None
|
|
132
|
+
return content.text()
|
|
133
|
+
|
|
134
|
+
# Get the text of the widget
|
|
135
|
+
def textify(self):
|
|
136
|
+
return self.getContent()
|
|
137
|
+
|
|
138
|
+
###############################################################################
|
|
139
|
+
# A multiline widget
|
|
140
|
+
class ECMultiline(ECTextWidget):
|
|
141
|
+
def __init__(self):
|
|
142
|
+
super().__init__()
|
|
143
|
+
|
|
144
|
+
# This object has a runtime value
|
|
145
|
+
def hasRuntimeValue(self):
|
|
146
|
+
return True
|
|
147
|
+
|
|
115
148
|
# Set the text of the widget
|
|
116
149
|
def setText(self, text):
|
|
117
150
|
v = self.getValue()
|
|
@@ -120,7 +153,7 @@ class ECLineInput(ECTextWidget):
|
|
|
120
153
|
|
|
121
154
|
# Get the text of the widget
|
|
122
155
|
def getText(self):
|
|
123
|
-
return self.getValue().getContent().
|
|
156
|
+
return self.getValue().getContent().toPlainText() # type: ignore
|
|
124
157
|
|
|
125
158
|
# Get the content of the value at the current index
|
|
126
159
|
def getContent(self):
|
|
@@ -128,12 +161,6 @@ class ECLineInput(ECTextWidget):
|
|
|
128
161
|
if v is None: return None
|
|
129
162
|
return v.getContent().text()
|
|
130
163
|
|
|
131
|
-
###############################################################################
|
|
132
|
-
# A multiline widget
|
|
133
|
-
class ECMultiline(ECTextWidget):
|
|
134
|
-
def __init__(self):
|
|
135
|
-
super().__init__()
|
|
136
|
-
|
|
137
164
|
###############################################################################
|
|
138
165
|
# A listbox variable
|
|
139
166
|
class ECListBox(ECCoreWidget):
|
easycoder/ec_graphics.py
CHANGED
|
@@ -337,6 +337,23 @@ class Graphics(Handler):
|
|
|
337
337
|
layout.addWidget(widget) # type: ignore
|
|
338
338
|
return self.nextPC()
|
|
339
339
|
|
|
340
|
+
# adjust {window}
|
|
341
|
+
def k_adjust(self, command):
|
|
342
|
+
if self.nextIsSymbol():
|
|
343
|
+
record = self.getSymbolRecord()
|
|
344
|
+
if self.isObjectType(record, ECWindow):
|
|
345
|
+
command['window'] = record['name']
|
|
346
|
+
self.add(command)
|
|
347
|
+
return True
|
|
348
|
+
return False
|
|
349
|
+
|
|
350
|
+
def r_adjust(self, command):
|
|
351
|
+
object = self.getVariable(command['window'])['object']
|
|
352
|
+
self.checkObjectType(object, ECWindow)
|
|
353
|
+
window = self.getInnerObject(object)
|
|
354
|
+
window.adjustSize()
|
|
355
|
+
return self.nextPC()
|
|
356
|
+
|
|
340
357
|
# Center one window on another
|
|
341
358
|
# center {window2} on {window1}
|
|
342
359
|
def k_center(self, command):
|
|
@@ -518,6 +535,9 @@ class Graphics(Handler):
|
|
|
518
535
|
elif token == 'size':
|
|
519
536
|
self.nextToken()
|
|
520
537
|
command['size'] = self.nextValue()
|
|
538
|
+
elif token == 'width':
|
|
539
|
+
self.nextToken()
|
|
540
|
+
command['width'] = self.nextValue()
|
|
521
541
|
elif token == 'expand':
|
|
522
542
|
self.nextToken()
|
|
523
543
|
command['expand'] = True
|
|
@@ -723,6 +743,8 @@ class Graphics(Handler):
|
|
|
723
743
|
c = label.contentsMargins()
|
|
724
744
|
w = fm.horizontalAdvance('m') * self.textify(command['size']) +c.left()+c.right()
|
|
725
745
|
label.setMaximumWidth(w)
|
|
746
|
+
if 'width' in command:
|
|
747
|
+
label.setFixedWidth(self.textify(command['width']))
|
|
726
748
|
if 'align' in command:
|
|
727
749
|
alignment = command['align']
|
|
728
750
|
if alignment == 'left': label.setAlignment(Qt.AlignmentFlag.AlignLeft)
|
|
@@ -1514,7 +1536,7 @@ class Graphics(Handler):
|
|
|
1514
1536
|
value = ECValue(domain=self.getName())
|
|
1515
1537
|
token = self.getToken()
|
|
1516
1538
|
if self.isSymbol():
|
|
1517
|
-
value.
|
|
1539
|
+
value.setName(token)
|
|
1518
1540
|
record = self.getSymbolRecord()
|
|
1519
1541
|
object = self.getObject(record)
|
|
1520
1542
|
if isinstance(object, ECCoreWidget) and object.hasRuntimeValue():
|
|
@@ -1536,14 +1558,14 @@ class Graphics(Handler):
|
|
|
1536
1558
|
if self.nextIsSymbol():
|
|
1537
1559
|
record = self.getSymbolRecord()
|
|
1538
1560
|
if self.isObjectType(record, ECListBox) or self.isObjectType(record, ECComboBox): # type: ignore
|
|
1539
|
-
value.setContent(ECValue(domain=self.getName(), type='object',
|
|
1561
|
+
value.setContent(ECValue(domain=self.getName(), type='object', name=record['name']))
|
|
1540
1562
|
return value
|
|
1541
1563
|
elif token == 'count':
|
|
1542
1564
|
self.skip('of')
|
|
1543
1565
|
if self.nextIsSymbol():
|
|
1544
1566
|
record = self.getSymbolRecord()
|
|
1545
1567
|
if self.isObjectType(record, ECListBox) or self.isObjectType(record, ECComboBox): # type: ignore
|
|
1546
|
-
value.setContent(ECValue(domain=self.getName(), type='object',
|
|
1568
|
+
value.setContent(ECValue(domain=self.getName(), type='object', name=record['name']))
|
|
1547
1569
|
return value
|
|
1548
1570
|
elif token == 'text':
|
|
1549
1571
|
self.skip('of')
|
|
@@ -1552,7 +1574,7 @@ class Graphics(Handler):
|
|
|
1552
1574
|
if (
|
|
1553
1575
|
self.isObjectType(record, (ECLabel, ECPushButton, ECMultiline, ECLineInput))
|
|
1554
1576
|
): # type: ignore
|
|
1555
|
-
value.setContent(ECValue(domain=self.getName(), type='object',
|
|
1577
|
+
value.setContent(ECValue(domain=self.getName(), type='object', name=record['name']))
|
|
1556
1578
|
return value
|
|
1557
1579
|
elif token == 'index':
|
|
1558
1580
|
self.skip('of')
|
|
@@ -1560,7 +1582,14 @@ class Graphics(Handler):
|
|
|
1560
1582
|
if self.nextIsSymbol():
|
|
1561
1583
|
record = self.getSymbolRecord()
|
|
1562
1584
|
if self.isObjectType(record, (ECListBox, ECComboBox)): # type: ignore
|
|
1563
|
-
value.setContent(ECValue(domain=self.getName(), type='object',
|
|
1585
|
+
value.setContent(ECValue(domain=self.getName(), type='object', name=record['name']))
|
|
1586
|
+
return value
|
|
1587
|
+
elif token in ['width', 'height']:
|
|
1588
|
+
self.skip('of')
|
|
1589
|
+
if self.nextIsSymbol():
|
|
1590
|
+
record = self.getSymbolRecord()
|
|
1591
|
+
if self.isObjectType(record, ECWindow): # type: ignore
|
|
1592
|
+
value.target = record['name']
|
|
1564
1593
|
return value
|
|
1565
1594
|
return None
|
|
1566
1595
|
|
|
@@ -1598,7 +1627,7 @@ class Graphics(Handler):
|
|
|
1598
1627
|
v = ECValue(domain=self.getName(), type=str, content=content)
|
|
1599
1628
|
return v
|
|
1600
1629
|
elif self.isObjectType(record, ECCheckBox):
|
|
1601
|
-
checkbox =self.getInnerObject(record)
|
|
1630
|
+
checkbox = self.getInnerObject(record)
|
|
1602
1631
|
content = checkbox.isChecked() # type: ignore
|
|
1603
1632
|
v = ECValue(domain=self.getName(), type=bool, content=content)
|
|
1604
1633
|
return v
|
|
@@ -1611,7 +1640,7 @@ class Graphics(Handler):
|
|
|
1611
1640
|
def v_count(self, v):
|
|
1612
1641
|
content = v.getContent()
|
|
1613
1642
|
if isinstance(content, ECValue) and content.getType() == 'object':
|
|
1614
|
-
record = self.getVariable(content.
|
|
1643
|
+
record = self.getVariable(content.getName())
|
|
1615
1644
|
object = self.getObject(record)
|
|
1616
1645
|
if isinstance(object, (ECListBox, ECComboBox)):
|
|
1617
1646
|
widget = self.getInnerObject(object)
|
|
@@ -1622,7 +1651,7 @@ class Graphics(Handler):
|
|
|
1622
1651
|
def v_current(self, v):
|
|
1623
1652
|
content = v.getContent()
|
|
1624
1653
|
if isinstance(content, ECValue) and content.getType() == 'object':
|
|
1625
|
-
record = self.getVariable(content.
|
|
1654
|
+
record = self.getVariable(content.getName())
|
|
1626
1655
|
object = self.getObject(record)
|
|
1627
1656
|
option = v.option
|
|
1628
1657
|
if isinstance(object, (ECListBox)):
|
|
@@ -1641,28 +1670,52 @@ class Graphics(Handler):
|
|
|
1641
1670
|
|
|
1642
1671
|
def v_empty(self, v):
|
|
1643
1672
|
if v.type == 'object':
|
|
1644
|
-
record = self.getVariable(v.
|
|
1673
|
+
record = self.getVariable(v.getName())
|
|
1645
1674
|
object = self.getObject(record)
|
|
1646
1675
|
value = object.isEmpty()
|
|
1647
1676
|
return ECValue(domain=self.getName(), type=bool, content=value) # type: ignore
|
|
1648
1677
|
return None
|
|
1678
|
+
|
|
1679
|
+
def v_height(self, v):
|
|
1680
|
+
targetName = v.target
|
|
1681
|
+
record = self.getVariable(targetName)
|
|
1682
|
+
object = self.getObject(record)
|
|
1683
|
+
if isinstance(object, ECWindow):
|
|
1684
|
+
widget = self.getInnerObject(object)
|
|
1685
|
+
value = widget.height() # type: ignore
|
|
1686
|
+
return ECValue(domain=self.getName(), type=int, content=value) # type: ignore
|
|
1687
|
+
return None
|
|
1649
1688
|
|
|
1650
1689
|
def v_selected(self, v): return self.v_current(v)
|
|
1651
1690
|
|
|
1652
1691
|
def v_text(self, v):
|
|
1653
1692
|
content = v.getContent()
|
|
1654
1693
|
if isinstance(content, ECValue) and content.getType() == 'object':
|
|
1655
|
-
record = self.getVariable(content.
|
|
1694
|
+
record = self.getVariable(content.getName())
|
|
1656
1695
|
object = self.getObject(record)
|
|
1657
1696
|
value = object.getText()
|
|
1658
1697
|
return ECValue(domain=self.getName(), type=int, content=value) # type: ignore
|
|
1698
|
+
|
|
1699
|
+
def v_width(self, v):
|
|
1700
|
+
targetName = v.target
|
|
1701
|
+
record = self.getVariable(targetName)
|
|
1702
|
+
object = self.getObject(record)
|
|
1703
|
+
if isinstance(object, ECWindow):
|
|
1704
|
+
widget = self.getInnerObject(object)
|
|
1705
|
+
value = widget.width() # type: ignore
|
|
1706
|
+
return ECValue(domain=self.getName(), type=int, content=value) # type: ignore
|
|
1707
|
+
return None
|
|
1659
1708
|
|
|
1660
1709
|
#############################################################################
|
|
1661
|
-
# Get the value of an unknown item
|
|
1710
|
+
# Get the value of an unknown item
|
|
1662
1711
|
def getUnknownValue(self, value):
|
|
1663
1712
|
if self.isObjectType(value, (ECLabelWidget, ECPushButtonWidget, ECLineEditWidget, ECListBoxWidget, ECComboBoxWidget)):
|
|
1664
1713
|
return value.text() # type: ignore
|
|
1665
|
-
if self.isObjectType(value, (
|
|
1714
|
+
if self.isObjectType(value, (ECPlainTextEditWidget)):
|
|
1715
|
+
return value.toPlainText() # type: ignore
|
|
1716
|
+
if self.isObjectType(value, (ECCheckBoxWidget)):
|
|
1717
|
+
return value.isChecked() # type: ignore
|
|
1718
|
+
if self.isObjectType(value, (ECDialogWindow)):
|
|
1666
1719
|
return value.result() # type: ignore
|
|
1667
1720
|
return None # Unable to get value
|
|
1668
1721
|
|