16
16
QLabel ,
17
17
QLCDNumber ,
18
18
QLineEdit ,
19
+ QPlainTextEdit ,
19
20
QListWidget ,
20
21
QMainWindow ,
21
22
QProgressBar ,
@@ -52,7 +53,20 @@ def closeEvent(self):
52
53
print ('window closed' )
53
54
54
55
def isWidget (self , keyword ):
55
- return keyword in ['layout' , 'groupbox' , 'label' , 'pushbutton' , 'checkbox' , 'lineinput' , 'listbox' , 'combobox' ]
56
+ return keyword in [
57
+ 'layout' ,
58
+ 'groupbox' ,
59
+ 'label' ,
60
+ 'pushbutton' ,
61
+ 'checkbox' ,
62
+ 'lineinput' ,
63
+ 'multiline' ,
64
+ 'listbox' ,
65
+ 'combobox'
66
+ ]
67
+
68
+ def dialogTypes (self ):
69
+ return ['confirm' , 'lineedit' , 'multiline' ]
56
70
57
71
class ECDialog (QDialog ):
58
72
def __init__ (self , parent , record ):
@@ -334,6 +348,23 @@ def k_createLineEdit(self, command):
334
348
self .add (command )
335
349
return True
336
350
351
+ def k_createMultiLineEdit (self , command ):
352
+ cols = self .compileConstant (30 )
353
+ rows = self .compileConstant (5 )
354
+ while True :
355
+ next = self .peek ()
356
+ if next == 'cols' :
357
+ self .nextToken ()
358
+ cols = self .nextValue ()
359
+ elif next == 'rows' :
360
+ self .nextToken ()
361
+ rows = self .nextValue ()
362
+ else : break ;
363
+ command ['cols' ] = cols
364
+ command ['rows' ] = rows
365
+ self .add (command )
366
+ return True
367
+
337
368
def k_createListWidget (self , command ):
338
369
self .add (command )
339
370
return True
@@ -351,7 +382,9 @@ def k_createDialog(self, command):
351
382
while True :
352
383
if self .peek () == 'type' :
353
384
self .nextToken ()
354
- command ['type' ] = self .nextToken ()
385
+ dialogType = self .nextToken ()
386
+ if dialogType in self .dialogTypes (): command ['type' ] = dialogType
387
+ else : return False
355
388
elif self .peek () == 'title' :
356
389
self .nextToken ()
357
390
command ['title' ] = self .nextValue ()
@@ -406,6 +439,7 @@ def k_create(self, command):
406
439
elif keyword == 'pushbutton' : return self .k_createPushbutton (command )
407
440
elif keyword == 'checkbox' : return self .k_createCheckBox (command )
408
441
elif keyword == 'lineinput' : return self .k_createLineEdit (command )
442
+ elif keyword == 'multiline' : return self .k_createMultiLineEdit (command )
409
443
elif keyword == 'listbox' : return self .k_createListWidget (command )
410
444
elif keyword == 'combobox' : return self .k_createComboBox (command )
411
445
elif keyword == 'dialog' : return self .k_createDialog (command )
@@ -486,6 +520,16 @@ def r_createLineEdit(self, command, record):
486
520
record ['widget' ] = lineinput
487
521
return self .nextPC ()
488
522
523
+ def r_createMultiLineEdit (self , command , record ):
524
+ textinput = QPlainTextEdit ()
525
+ fontMetrics = textinput .fontMetrics ()
526
+ charWidth = fontMetrics .horizontalAdvance ('x' )
527
+ charHeight = fontMetrics .height ()
528
+ textinput .setFixedWidth (charWidth * self .getRuntimeValue (command ['cols' ]))
529
+ textinput .setFixedHeight (charHeight * self .getRuntimeValue (command ['rows' ]))
530
+ record ['widget' ] = textinput
531
+ return self .nextPC ()
532
+
489
533
def r_createListWidget (self , command , record ):
490
534
record ['widget' ] = QListWidget ()
491
535
return self .nextPC ()
@@ -504,18 +548,22 @@ def r_createDialog(self, command, record):
504
548
dialogType = command ['type' ].lower ()
505
549
dialog .dialogType = dialogType
506
550
prompt = self .getRuntimeValue (command ['prompt' ])
507
- if dialogType in ['confirm' , 'lineedit' ]:
508
- if dialogType == 'confirm' :
509
- mainLayout .addWidget (QLabel (prompt ))
510
- elif dialogType == 'lineedit' :
511
- mainLayout .addWidget (QLabel (prompt ))
512
- dialog .lineEdit = QLineEdit (dialog )
513
- dialog .value = self .getRuntimeValue (command ['value' ])
514
- dialog .lineEdit .setText (dialog .value )
515
- mainLayout .addWidget (dialog .lineEdit )
516
- buttonBox = QDialogButtonBox (QDialogButtonBox .Ok | QDialogButtonBox .Cancel , dialog )
517
- buttonBox .accepted .connect (dialog .accept )
518
- buttonBox .rejected .connect (dialog .reject )
551
+ if dialogType == 'confirm' :
552
+ mainLayout .addWidget (QLabel (prompt ))
553
+ elif dialogType == 'lineedit' :
554
+ mainLayout .addWidget (QLabel (prompt ))
555
+ dialog .lineEdit = QLineEdit (dialog )
556
+ dialog .value = self .getRuntimeValue (command ['value' ])
557
+ dialog .lineEdit .setText (dialog .value )
558
+ mainLayout .addWidget (dialog .lineEdit )
559
+ elif dialogType == 'multiline' :
560
+ mainLayout .addWidget (QLabel (prompt ))
561
+ dialog .textEdit = QPlainTextEdit (self )
562
+ dialog .textEdit .setText (dialog .value )
563
+ mainLayout .addWidget (dialog .textEdit )
564
+ buttonBox = QDialogButtonBox (QDialogButtonBox .Ok | QDialogButtonBox .Cancel )
565
+ buttonBox .accepted .connect (self .accept )
566
+ buttonBox .rejected .connect (self .reject )
519
567
mainLayout .addWidget (buttonBox , alignment = Qt .AlignHCenter )
520
568
record ['dialog' ] = dialog
521
569
return self .nextPC ()
@@ -540,6 +588,7 @@ def r_create(self, command):
540
588
elif keyword == 'pushbutton' : return self .r_createPushbutton (command , record )
541
589
elif keyword == 'checkbox' : return self .r_createCheckBox (command , record )
542
590
elif keyword == 'lineinput' : return self .r_createLineEdit (command , record )
591
+ elif keyword == 'multiline' : return self .r_createMultiLineEdit (command , record )
543
592
elif keyword == 'listbox' : return self .r_createListWidget (command , record )
544
593
elif keyword == 'combobox' : return self .r_createComboBox (command , record )
545
594
elif keyword == 'dialog' : return self .r_createDialog (command , record )
@@ -634,6 +683,13 @@ def k_messagebox(self, command):
634
683
def r_messagebox (self , command ):
635
684
return self .nextPC ()
636
685
686
+ # Declare a multiline input variable
687
+ def k_multiline (self , command ):
688
+ return self .compileVariable (command , 'gui' )
689
+
690
+ def r_multiline (self , command ):
691
+ return self .nextPC ()
692
+
637
693
# on click {pushbutton}
638
694
# on select {combobox}/{listbox}
639
695
# on tick
@@ -794,8 +850,8 @@ def r_select(self, command):
794
850
# set [the] width/height [of] {widget} [to] {value}
795
851
# set [the] layout of {window} to {layout}
796
852
# set [the] spacing of {layout} to {value}
797
- # set [the] text [of] {label}/{button}/{lineinput} [to] {text}
798
- # set [the] color [of] {label}/{button}/{lineinput} [to] {color}
853
+ # set [the] text [of] {label}/{button}/{lineinput}/{multiline} [to] {text}
854
+ # set [the] color [of] {label}/{button}/{lineinput}/{multiline} [to] {color}
799
855
# set [the] state [of] {checkbox} [to] {color}
800
856
# set {listbox} to {list}
801
857
# set blocked true/false
@@ -839,7 +895,7 @@ def k_set(self, command):
839
895
self .skip ('of' )
840
896
if self .nextIsSymbol ():
841
897
record = self .getSymbolRecord ()
842
- if record ['keyword' ] in ['label' , 'pushbutton' , 'lineinput' ]:
898
+ if record ['keyword' ] in ['label' , 'pushbutton' , 'lineinput' , 'multiline' ]:
843
899
command ['name' ] = record ['name' ]
844
900
self .skip ('to' )
845
901
command ['value' ] = self .nextValue ()
@@ -870,7 +926,7 @@ def k_set(self, command):
870
926
self .skip ('of' )
871
927
if self .nextIsSymbol ():
872
928
record = self .getSymbolRecord ()
873
- if record ['keyword' ] in ['label' , 'pushbutton' , 'lineinput' ]:
929
+ if record ['keyword' ] in ['label' , 'pushbutton' , 'lineinput' , 'multiline' ]:
874
930
command ['name' ] = record ['name' ]
875
931
self .skip ('to' )
876
932
command ['value' ] = self .nextValue ()
@@ -911,7 +967,10 @@ def r_set(self, command):
911
967
record = self .getVariable (command ['name' ])
912
968
widget = self .getVariable (command ['name' ])['widget' ]
913
969
text = self .getRuntimeValue (command ['value' ])
914
- widget .setText (text )
970
+ if isinstance (widget , QLineEdit ):
971
+ widget .setText (text )
972
+ elif isinstance (widget , QPlainTextEdit ):
973
+ widget .setPlainText (text )
915
974
if record ['keyword' ] == 'pushbutton' :
916
975
widget .setAccessibleName (text )
917
976
elif what == 'state' :
@@ -996,13 +1055,16 @@ def r_show(self, command):
996
1055
elif 'dialog' in command :
997
1056
record = self .getVariable (command ['dialog' ])
998
1057
dialog = record ['dialog' ]
999
- if dialog .dialogType in ['confirm' , 'lineedit' ]:
1000
- if dialog .dialogType == 'confirm' :
1001
- record ['result' ] = True if dialog .exec () == QDialog .Accepted else False
1002
- elif dialog .dialogType == 'lineedit' :
1003
- if dialog .exec () == QDialog .Accepted :
1004
- record ['result' ] = dialog .lineEdit .text ()
1005
- else : record ['result' ] = dialog .value
1058
+ if dialog .dialogType == 'confirm' :
1059
+ record ['result' ] = True if dialog .exec () == QDialog .Accepted else False
1060
+ elif dialog .dialogType == 'lineedit' :
1061
+ if dialog .exec () == QDialog .Accepted :
1062
+ record ['result' ] = dialog .lineEdit .text ()
1063
+ else : record ['result' ] = dialog .value
1064
+ elif dialog .dialogType == 'multiline' :
1065
+ if dialog .exec () == QDialog .Accepted :
1066
+ record ['result' ] = dialog .textEdit .toPlainText ()
1067
+ else : record ['result' ] = dialog .value
1006
1068
return self .nextPC ()
1007
1069
1008
1070
# Start the graphics
@@ -1101,6 +1163,12 @@ def v_symbol(self, symbolRecord):
1101
1163
v ['type' ] = 'text'
1102
1164
v ['content' ] = lineinput .displayText ()
1103
1165
return v
1166
+ elif keyword == 'multiline' :
1167
+ multiline = symbolRecord ['widget' ]
1168
+ v = {}
1169
+ v ['type' ] = 'text'
1170
+ v ['content' ] = multiline .toPlainText ()
1171
+ return v
1104
1172
elif keyword == 'combobox' :
1105
1173
combobox = symbolRecord ['widget' ]
1106
1174
v = {}
0 commit comments