@@ -133,10 +133,6 @@ def r_add(self, command):
133
133
else : layout .addWidget (widget )
134
134
return self .nextPC ()
135
135
136
- # Declare a checkbox variable
137
- def k_checkbox (self , command ):
138
- return self .compileVariable (command , False )
139
-
140
136
# Center one window on another
141
137
# center {window2} on {window1}
142
138
def k_center (self , command ):
@@ -158,10 +154,14 @@ def r_center(self, command):
158
154
window2 = self .getVariable (command ['window2' ])['window' ]
159
155
geo1 = window1 .geometry ()
160
156
geo2 = window2 .geometry ()
161
- geo1 .moveCenter (geo2 .center ())
162
- window1 .setGeometry (geo1 )
157
+ geo2 .moveCenter (geo1 .center ())
158
+ window2 .setGeometry (geo2 )
163
159
return self .nextPC ()
164
160
161
+ # Declare a checkbox variable
162
+ def k_checkbox (self , command ):
163
+ return self .compileVariable (command , False )
164
+
165
165
def r_checkbox (self , command ):
166
166
return self .nextPC ()
167
167
@@ -196,18 +196,26 @@ def k_createWindow(self, command):
196
196
h = self .compileConstant (480 )
197
197
while True :
198
198
token = self .peek ()
199
- if token in ['title' , 'at' , 'size' ]:
199
+ if token in ['title' , 'at' , 'size' , 'layout' ]:
200
200
self .nextToken ()
201
201
if token == 'title' : command ['title' ] = self .nextValue ()
202
202
elif token == 'at' :
203
203
x = self .nextValue ()
204
204
y = self .nextValue ()
205
205
elif token == 'size' :
206
- command ['w' ] = self .nextValue ()
207
- command ['h' ] = self .nextValue ()
206
+ w = self .nextValue ()
207
+ h = self .nextValue ()
208
+ elif token == 'layout' :
209
+ if self .nextIsSymbol ():
210
+ record = self .getSymbolRecord ()
211
+ if record ['keyword' ] == 'layout' :
212
+ command ['layout' ] = record ['name' ]
213
+ else : return False
208
214
else : break
209
215
command ['x' ] = x
210
216
command ['y' ] = y
217
+ command ['w' ] = w
218
+ command ['h' ] = h
211
219
self .add (command )
212
220
return True
213
221
@@ -360,6 +368,9 @@ def r_createWindow(self, command, record):
360
368
if y == None : y = (self .screenHeight - h ) / 2
361
369
else : y = self .getRuntimeValue (x )
362
370
window .setGeometry (x , y , w , h )
371
+ container = QWidget ()
372
+ container .setLayout (self .getVariable (command ['layout' ])['widget' ])
373
+ window .setCentralWidget (container )
363
374
record ['window' ] = window
364
375
return self .nextPC ()
365
376
@@ -384,7 +395,7 @@ def r_createLabel(self, command, record):
384
395
if 'size' in command :
385
396
fm = label .fontMetrics ()
386
397
c = label .contentsMargins ()
387
- w = fm .horizontalAdvance ('x ' ) * self .getRuntimeValue (command ['size' ]) + c .left ()+ c .right ()
398
+ w = fm .horizontalAdvance ('m ' ) * self .getRuntimeValue (command ['size' ]) + c .left ()+ c .right ()
388
399
label .setMaximumWidth (w )
389
400
record ['widget' ] = label
390
401
return self .nextPC ()
@@ -394,7 +405,7 @@ def r_createPushbutton(self, command, record):
394
405
if 'size' in command :
395
406
fm = pushbutton .fontMetrics ()
396
407
c = pushbutton .contentsMargins ()
397
- w = fm .horizontalAdvance ('x ' ) * self .getRuntimeValue (command ['size' ]) + c .left ()+ c .right ()
408
+ w = fm .horizontalAdvance ('m ' ) * self .getRuntimeValue (command ['size' ]) + c .left ()+ c .right ()
398
409
pushbutton .setMaximumWidth (w )
399
410
record ['widget' ] = pushbutton
400
411
return self .nextPC ()
@@ -644,30 +655,21 @@ def r_set(self, command):
644
655
groupbox .setFixedHeight (self .getRuntimeValue (command ['value' ]))
645
656
return self .nextPC ()
646
657
647
- # Show something
648
- # show {name} in {window}
649
- # show {dialog} giving {result}}
658
+ # show {window}
659
+ # show {dialog}
650
660
# show {messagebox} giving {result}}
651
661
def k_show (self , command ):
652
662
if self .nextIsSymbol ():
653
663
record = self .getSymbolRecord ()
654
664
keyword = record ['keyword' ]
655
- if keyword == 'layout' :
656
- command ['layout' ] = record ['name' ]
657
- if self .nextIs ('in' ):
658
- if self .nextIsSymbol ():
659
- record = self .getSymbolRecord ()
660
- if record ['keyword' ] == 'window' :
661
- command ['window' ] = record ['name' ]
662
- self .add (command )
663
- return True
665
+ if keyword == 'window' :
666
+ command ['window' ] = record ['name' ]
667
+ self .add (command )
668
+ return True
664
669
elif keyword == 'dialog' :
665
670
command ['dialog' ] = record ['name' ]
666
- if self .nextIs ('giving' ):
667
- if self .nextIsSymbol ():
668
- command ['result' ] = self .getSymbolRecord ()['name' ]
669
- self .add (command )
670
- return True
671
+ self .add (command )
672
+ return True
671
673
elif keyword == 'messagebox' :
672
674
command ['messagebox' ] = record ['name' ]
673
675
if self .nextIs ('giving' ):
@@ -698,17 +700,12 @@ def r_show(self, command):
698
700
v ['type' ] = 'text'
699
701
v ['content' ] = result
700
702
self .putSymbolValue (symbolRecord , v )
701
- elif 'dialog' in command :
702
- dialog = self .getVariable (command ['dialog' ])['dialog' ]
703
- result = dialog .exec ()
704
- print ('Result:' ,result )
705
- else :
706
- layout = self .getVariable (command ['layout' ])['widget' ]
703
+ elif 'window' in command :
707
704
window = self .getVariable (command ['window' ])['window' ]
708
- container = QWidget ()
709
- container .setLayout (layout )
710
- window .setCentralWidget (container )
711
705
window .show ()
706
+ elif 'dialog' in command :
707
+ dialog = self .getVariable (command ['dialog' ])['dialog' ]
708
+ dialog .exec ()
712
709
return self .nextPC ()
713
710
714
711
# Start the graphics
0 commit comments