@@ -54,7 +54,7 @@ def closeEvent(self):
54
54
def isWidget (self , keyword ):
55
55
return keyword in [
56
56
'layout' ,
57
- 'groupbox ' ,
57
+ 'group ' ,
58
58
'label' ,
59
59
'pushbutton' ,
60
60
'checkbox' ,
@@ -115,11 +115,12 @@ def mousePressEvent(self, event):
115
115
# (3) add stretch {widget} to {layout}
116
116
# (4) add stretch to {layout}
117
117
# (5) add spacer {size} to {layout}
118
+ # (6) add {widget} at {col} {row} in {grid layout}
118
119
def k_add (self , command ):
119
120
def addToLayout ():
120
121
if self .nextIsSymbol ():
121
122
record = self .getSymbolRecord ()
122
- if record ['keyword' ] in ['layout' , 'groupbox ' , 'element' ]:
123
+ if record ['keyword' ] in ['layout' , 'group ' , 'element' ]:
123
124
command ['layout' ] = record ['name' ]
124
125
self .add (command )
125
126
return True
@@ -155,12 +156,20 @@ def addToLayout():
155
156
record = self .getSymbolRecord ()
156
157
if record ['extra' ] == 'gui' :
157
158
if self .isWidget (record ['keyword' ]):
159
+ command ['widget' ] = record ['name' ]
158
160
if self .peek () == 'to' :
159
161
# (2)
160
162
record = self .getSymbolRecord ()
161
- command ['widget' ] = record ['name' ]
162
163
self .nextToken ()
163
164
return addToLayout ()
165
+ elif self .peek () == 'at' :
166
+ # (6)
167
+ self .nextToken ()
168
+ command ['row' ] = self .nextValue ()
169
+ command ['col' ] = self .nextValue ()
170
+ self .skip ('in' )
171
+ return addToLayout ()
172
+
164
173
else : return False
165
174
# (1)
166
175
value = self .getValue ()
@@ -180,6 +189,12 @@ def r_add(self, command):
180
189
widget = self .getVariable (command ['widget' ])
181
190
if widget ['keyword' ] in ['listbox' , 'combobox' ]:
182
191
widget ['widget' ].addItem (value )
192
+ elif 'row' in command and 'col' in command :
193
+ layout = self .getVariable (command ['layout' ])['widget' ]
194
+ widget = self .getVariable (command ['widget' ])['widget' ]
195
+ row = self .getRuntimeValue (command ['row' ])
196
+ col = self .getRuntimeValue (command ['col' ])
197
+ layout .addWidget (widget , row , col )
183
198
else :
184
199
layoutRecord = self .getVariable (command ['layout' ])
185
200
widget = command ['widget' ]
@@ -194,11 +209,11 @@ def r_add(self, command):
194
209
layout = layoutRecord ['widget' ]
195
210
stretch = 'stretch' in command
196
211
if widgetRecord ['keyword' ] == 'layout' :
197
- if layoutRecord ['keyword' ] == 'groupbox ' :
212
+ if layoutRecord ['keyword' ] == 'group ' :
198
213
if widgetRecord ['keyword' ] == 'layout' :
199
214
layout .setLayout (widget )
200
215
else :
201
- RuntimeError (self .program , 'Can only add a layout to a groupbox ' )
216
+ RuntimeError (self .program , 'Can only add a layout to a group ' )
202
217
else :
203
218
if stretch : layout .addLayout (widget , stretch = 1 )
204
219
else : layout .addLayout (widget )
@@ -363,7 +378,7 @@ def k_createCheckBox(self, command):
363
378
if self .peek () == 'text' :
364
379
self .nextToken ()
365
380
text = self .nextValue ()
366
- else : text = ''
381
+ else : text = self . compileConstant ( '' )
367
382
command ['text' ] = text
368
383
self .add (command )
369
384
return True
@@ -471,7 +486,7 @@ def k_create(self, command):
471
486
keyword = record ['keyword' ]
472
487
if keyword == 'window' : return self .k_createWindow (command )
473
488
elif keyword == 'layout' : return self .k_createLayout (command )
474
- elif keyword == 'groupbox ' : return self .k_createGroupBox (command )
489
+ elif keyword == 'group ' : return self .k_createGroupBox (command )
475
490
elif keyword == 'label' : return self .k_createLabel (command )
476
491
elif keyword == 'pushbutton' : return self .k_createPushbutton (command )
477
492
elif keyword == 'checkbox' : return self .k_createCheckBox (command )
@@ -499,19 +514,19 @@ def r_createWindow(self, command, record):
499
514
return self .nextPC ()
500
515
501
516
def r_createLayout (self , command , record ):
502
- type = command ['type' ]
503
- if type == 'QHBoxLayout' : layout = QHBoxLayout ()
504
- elif type == 'QGridLayout' : layout = QGridLayout ()
505
- elif type == 'QStackedLayout' : layout = QStackedLayout ()
517
+ layoutType = command ['type' ]
518
+ if layoutType == 'QHBoxLayout' : layout = QHBoxLayout ()
519
+ elif layoutType == 'QGridLayout' : layout = QGridLayout ()
520
+ elif layoutType == 'QStackedLayout' : layout = QStackedLayout ()
506
521
else : layout = QVBoxLayout ()
507
- layout .setContentsMargins (5 ,0 ,5 ,0 )
522
+ layout .setContentsMargins (5 ,5 ,5 ,5 )
508
523
record ['widget' ] = layout
509
524
return self .nextPC ()
510
525
511
526
def r_createGroupBox (self , command , record ):
512
- groupbox = QGroupBox (self .getRuntimeValue (command ['title' ]))
513
- groupbox .setAlignment (Qt .AlignLeft )
514
- record ['widget' ] = groupbox
527
+ group = QGroupBox (self .getRuntimeValue (command ['title' ]))
528
+ group .setAlignment (Qt .AlignLeft )
529
+ record ['widget' ] = group
515
530
return self .nextPC ()
516
531
517
532
def r_createLabel (self , command , record ):
@@ -548,6 +563,7 @@ def r_createPushbutton(self, command, record):
548
563
549
564
def r_createCheckBox (self , command , record ):
550
565
checkbox = QCheckBox (self .getRuntimeValue (command ['text' ]))
566
+ checkbox .setSizePolicy (QSizePolicy .Fixed , QSizePolicy .Preferred )
551
567
record ['widget' ] = checkbox
552
568
return self .nextPC ()
553
569
@@ -625,7 +641,7 @@ def r_create(self, command):
625
641
keyword = record ['keyword' ]
626
642
if keyword == 'window' : return self .r_createWindow (command , record )
627
643
elif keyword == 'layout' : return self .r_createLayout (command , record )
628
- elif keyword == 'groupbox ' : return self .r_createGroupBox (command , record )
644
+ elif keyword == 'group ' : return self .r_createGroupBox (command , record )
629
645
elif keyword == 'label' : return self .r_createLabel (command , record )
630
646
elif keyword == 'pushbutton' : return self .r_createPushbutton (command , record )
631
647
elif keyword == 'checkbox' : return self .r_createCheckBox (command , record )
@@ -669,10 +685,10 @@ def r_enable(self, command):
669
685
return self .nextPC ()
670
686
671
687
# Create a group box
672
- def k_groupbox (self , command ):
688
+ def k_group (self , command ):
673
689
return self .compileVariable (command , 'gui' )
674
690
675
- def r_groupbox (self , command ):
691
+ def r_group (self , command ):
676
692
return self .nextPC ()
677
693
678
694
# Initialize the graphics environment
@@ -953,6 +969,29 @@ def k_set(self, command):
953
969
command ['value' ] = self .nextValue ()
954
970
self .add (command )
955
971
return True
972
+ elif token == 'alignment' :
973
+ self .skip ('of' )
974
+ if self .nextIsSymbol ():
975
+ record = self .getSymbolRecord ()
976
+ if record ['extra' ] == 'gui' :
977
+ command ['name' ] = record ['name' ]
978
+ self .skip ('to' )
979
+ flags = []
980
+ while self .peek () in ['left' , 'hcenter' , 'right' , 'top' , 'vcenter' , 'bottom' , 'center' ]:
981
+ flags .append (self .nextToken ())
982
+ command ['value' ] = flags
983
+ self .add (command )
984
+ return True
985
+ elif token == 'style' :
986
+ self .skip ('of' )
987
+ if self .nextIsSymbol ():
988
+ record = self .getSymbolRecord ()
989
+ if record ['keyword' ] == 'label' :
990
+ command ['name' ] = record ['name' ]
991
+ self .skip ('to' )
992
+ command ['value' ] = self .nextValue ()
993
+ self .add (command )
994
+ return True
956
995
elif token == 'color' :
957
996
self .skip ('of' )
958
997
if self .nextIsSymbol ():
@@ -1021,6 +1060,23 @@ def r_set(self, command):
1021
1060
widget = self .getVariable (command ['name' ])['widget' ]
1022
1061
state = self .getRuntimeValue (command ['value' ])
1023
1062
widget .setChecked (state )
1063
+ elif what == 'alignment' :
1064
+ widget = self .getVariable (command ['name' ])['widget' ]
1065
+ flags = command ['value' ]
1066
+ alignment = 0
1067
+ for flag in flags :
1068
+ if flag == 'left' : alignment |= Qt .AlignLeft
1069
+ elif flag == 'hcenter' : alignment |= Qt .AlignHCenter
1070
+ elif flag == 'right' : alignment |= Qt .AlignRight
1071
+ elif flag == 'top' : alignment |= Qt .AlignTop
1072
+ elif flag == 'vcenter' : alignment |= Qt .AlignVCenter
1073
+ elif flag == 'bottom' : alignment |= Qt .AlignBottom
1074
+ elif flag == 'center' : alignment |= Qt .AlignCenter
1075
+ widget .setAlignment (alignment )
1076
+ elif what == 'style' :
1077
+ widget = self .getVariable (command ['name' ])['widget' ]
1078
+ styles = self .getRuntimeValue (command ['value' ])
1079
+ widget .setStyleSheet (styles )
1024
1080
elif what == 'color' :
1025
1081
widget = self .getVariable (command ['name' ])['widget' ]
1026
1082
color = self .getRuntimeValue (command ['value' ])
0 commit comments