30
30
QSpacerItem ,
31
31
QSizePolicy ,
32
32
QDialog ,
33
- QMessageBox
33
+ QMessageBox ,
34
+ QDialogButtonBox
34
35
)
35
36
36
37
class Graphics (Handler ):
@@ -136,10 +137,36 @@ def r_add(self, command):
136
137
def k_checkbox (self , command ):
137
138
return self .compileVariable (command , False )
138
139
140
+ # Center one window on another
141
+ # center {window2} on {window1}
142
+ def k_center (self , command ):
143
+ if self .nextIsSymbol ():
144
+ record = self .getSymbolRecord ()
145
+ if record ['keyword' ] == 'window' :
146
+ command ['window2' ] = record ['name' ]
147
+ if self .nextIs ('on' ):
148
+ if self .nextIsSymbol ():
149
+ record = self .getSymbolRecord ()
150
+ if record ['keyword' ] == 'window' :
151
+ command ['window1' ] = record ['name' ]
152
+ self .add (command )
153
+ return True
154
+ return False
155
+
156
+ def r_center (self , command ):
157
+ window1 = self .getVariable (command ['window1' ])['window' ]
158
+ window2 = self .getVariable (command ['window2' ])['window' ]
159
+ geo1 = window1 .geometry ()
160
+ geo2 = window2 .geometry ()
161
+ geo1 .moveCenter (geo2 .center ())
162
+ window1 .setGeometry (geo1 )
163
+ return self .nextPC ()
164
+
139
165
def r_checkbox (self , command ):
140
166
return self .nextPC ()
141
167
142
168
# Close a window
169
+ # close {window}
143
170
def k_close (self , command ):
144
171
if self .nextIsSymbol ():
145
172
record = self .getSymbolRecord ()
@@ -165,8 +192,8 @@ def k_createWindow(self, command):
165
192
command ['title' ] = 'Default'
166
193
x = None
167
194
y = None
168
- w = 640
169
- h = 480
195
+ w = self . compileConstant ( 640 )
196
+ h = self . compileConstant ( 480 )
170
197
while True :
171
198
token = self .peek ()
172
199
if token in ['title' , 'at' , 'size' ]:
@@ -179,8 +206,6 @@ def k_createWindow(self, command):
179
206
command ['w' ] = self .nextValue ()
180
207
command ['h' ] = self .nextValue ()
181
208
else : break
182
- command ['w' ] = self .compileConstant (w )
183
- command ['h' ] = self .compileConstant (h )
184
209
command ['x' ] = x
185
210
command ['y' ] = y
186
211
self .add (command )
@@ -260,38 +285,50 @@ def k_createComboBox(self, command):
260
285
return True
261
286
262
287
def k_createDialog (self , command ):
263
- if self .peek () == 'title ' :
288
+ if self .peek () == 'on ' :
264
289
self .nextToken ()
265
- title = self .nextValue ()
266
- else : title = ''
290
+ if self .nextIsSymbol ():
291
+ command ['window' ] = self .getSymbolRecord ()['name' ]
292
+ else : command ['window' ] = None
293
+ title = ''
294
+ while True :
295
+ if self .peek () == 'title' :
296
+ self .nextToken ()
297
+ title = self .nextValue ()
298
+ elif self .peek () == 'layout' :
299
+ self .nextToken ()
300
+ if self .nextIsSymbol ():
301
+ command ['layout' ] = self .getSymbolRecord ()['name' ]
302
+ else : break
267
303
command ['title' ] = title
268
304
self .add (command )
269
305
return True
270
306
271
307
def k_createMessageBox (self , command ):
272
- if self .nextIs ('on' ):
308
+ if self .peek () == 'on' :
309
+ self .nextToken ()
273
310
if self .nextIsSymbol ():
274
311
command ['window' ] = self .getSymbolRecord ()['name' ]
275
- style = 'question'
276
- title = ''
277
- message = ''
278
- while True :
279
- if self . peek () == 'style' :
280
- self .nextToken ()
281
- style = self .nextToken ()
282
- elif self .peek () == 'title' :
283
- self .nextToken ()
284
- title = self .nextValue ()
285
- elif self .peek () == 'message' :
286
- self .nextToken ()
287
- message = self .nextValue ()
288
- else : break
289
- command [ 'style' ] = style
290
- command ['title ' ] = title
291
- command ['message ' ] = message
292
- self . add ( command )
293
- return True
294
- return False
312
+ else : command [ 'window' ] = None
313
+ style = 'question '
314
+ title = ''
315
+ message = ''
316
+ while True :
317
+ if self .peek () == 'style' :
318
+ self .nextToken ()
319
+ style = self .nextToken ()
320
+ elif self .peek () == 'title' :
321
+ self .nextToken ()
322
+ title = self .nextValue ()
323
+ elif self .peek () == 'message' :
324
+ self .nextToken ()
325
+ message = self . nextValue ()
326
+ else : break
327
+ command ['style ' ] = style
328
+ command ['title ' ] = title
329
+ command [ 'message' ] = message
330
+ self . add ( command )
331
+ return True
295
332
296
333
def k_create (self , command ):
297
334
if self .nextIsSymbol ():
@@ -386,8 +423,14 @@ def r_createComboBox(self, command, record):
386
423
return self .nextPC ()
387
424
388
425
def r_createDialog (self , command , record ):
426
+ layout = self .getVariable (command ['layout' ])['widget' ]
389
427
dialog = QDialog ()
390
428
dialog .setWindowTitle (self .getRuntimeValue (command ['title' ]))
429
+ dialog .buttonBox = QDialogButtonBox ((QDialogButtonBox .Ok | QDialogButtonBox .Cancel ))
430
+ dialog .buttonBox .accepted .connect (dialog .accept )
431
+ dialog .buttonBox .rejected .connect (dialog .reject )
432
+ layout .addWidget (dialog .buttonBox )
433
+ dialog .setLayout (layout )
391
434
record ['dialog' ] = dialog
392
435
return self .nextPC ()
393
436
@@ -602,8 +645,9 @@ def r_set(self, command):
602
645
return self .nextPC ()
603
646
604
647
# Show something
605
- # show {name} in {window}}
606
- # show {dialog}/{messagebox}
648
+ # show {name} in {window}
649
+ # show {dialog} giving {result}}
650
+ # show {messagebox} giving {result}}
607
651
def k_show (self , command ):
608
652
if self .nextIsSymbol ():
609
653
record = self .getSymbolRecord ()
@@ -619,8 +663,11 @@ def k_show(self, command):
619
663
return True
620
664
elif keyword == 'dialog' :
621
665
command ['dialog' ] = record ['name' ]
622
- self .add (command )
623
- return True
666
+ if self .nextIs ('giving' ):
667
+ if self .nextIsSymbol ():
668
+ command ['result' ] = self .getSymbolRecord ()['name' ]
669
+ self .add (command )
670
+ return True
624
671
elif keyword == 'messagebox' :
625
672
command ['messagebox' ] = record ['name' ]
626
673
if self .nextIs ('giving' ):
@@ -631,13 +678,7 @@ def k_show(self, command):
631
678
return False
632
679
633
680
def r_show (self , command ):
634
- if 'dialog' in command :
635
- dialog = self .getVariable (command ['dialog' ])['dialog' ]
636
- b1 = QPushButton ("ok" ,dialog )
637
- b1 .move (50 ,50 )
638
- dialog .setWindowModality (Qt .ApplicationModal )
639
- dialog .exec_ ()
640
- elif 'messagebox' in command :
681
+ if 'messagebox' in command :
641
682
data = self .getVariable (command ['messagebox' ])['data' ]
642
683
symbolRecord = self .getVariable (command ['result' ])
643
684
window = self .getVariable (data ['window' ])['window' ]
@@ -657,12 +698,15 @@ def r_show(self, command):
657
698
v ['type' ] = 'text'
658
699
v ['content' ] = result
659
700
self .putSymbolValue (symbolRecord , v )
701
+ elif 'dialog' in command :
702
+ dialog = self .getVariable (command ['dialog' ])['dialog' ]
703
+ result = dialog .exec ()
704
+ print ('Result:' ,result )
660
705
else :
661
- layoutRecord = self .getVariable (command ['layout' ])
662
- windowRecord = self .getVariable (command ['window' ])
663
- window = windowRecord ['window' ]
706
+ layout = self .getVariable (command ['layout' ])['widget' ]
707
+ window = self .getVariable (command ['window' ])['window' ]
664
708
container = QWidget ()
665
- container .setLayout (layoutRecord [ 'widget' ] )
709
+ container .setLayout (layout )
666
710
window .setCentralWidget (container )
667
711
window .show ()
668
712
return self .nextPC ()
@@ -734,7 +778,13 @@ def modifyValue(self, value):
734
778
def v_symbol (self , symbolRecord ):
735
779
symbolRecord = self .getVariable (symbolRecord ['name' ])
736
780
keyword = symbolRecord ['keyword' ]
737
- if keyword == 'combobox' :
781
+ if keyword == 'lineinput' :
782
+ lineinput = symbolRecord ['widget' ]
783
+ v = {}
784
+ v ['type' ] = 'text'
785
+ v ['content' ] = lineinput .displayText ()
786
+ return v
787
+ elif keyword == 'combobox' :
738
788
combobox = symbolRecord ['widget' ]
739
789
v = {}
740
790
v ['type' ] = 'text'
0 commit comments