@@ -413,10 +413,11 @@ def get(self):
413
413
class FormDialog (QtWidgets .QDialog ):
414
414
"""Form Dialog"""
415
415
def __init__ (self , data , title = "" , comment = "" ,
416
- icon = None , parent = None , apply = None ):
416
+ icon = None , parent = None , apply = None , modal = True ):
417
417
super ().__init__ (parent )
418
418
419
419
self .apply_callback = apply
420
+ self .modal = modal
420
421
421
422
# Form
422
423
if isinstance (data [0 ][0 ], (list , tuple )):
@@ -469,6 +470,8 @@ def update_buttons(self):
469
470
btn .setEnabled (valid )
470
471
471
472
def accept (self ):
473
+ if not self .modal :
474
+ self .apply_callback (self .formwidget .get ())
472
475
self .data = self .formwidget .get ()
473
476
super ().accept ()
474
477
@@ -484,7 +487,8 @@ def get(self):
484
487
return self .data
485
488
486
489
487
- def fedit (data , title = "" , comment = "" , icon = None , parent = None , apply = None ):
490
+ def fedit (data , title = "" , comment = "" , icon = None , parent = None , apply = None ,
491
+ modal = True ):
488
492
"""
489
493
Create form dialog and return result
490
494
(if Cancel button is pressed, return None)
@@ -495,6 +499,7 @@ def fedit(data, title="", comment="", icon=None, parent=None, apply=None):
495
499
icon: QIcon instance
496
500
parent: parent QWidget
497
501
apply: apply callback (function)
502
+ modal: modality of dialog
498
503
499
504
datalist: list/tuple of (field_name, field_value)
500
505
datagroup: list/tuple of (datalist *or* datagroup, title, comment)
@@ -511,13 +516,19 @@ def fedit(data, title="", comment="", icon=None, parent=None, apply=None):
511
516
- list/tuple:
512
517
* the first element will be the selected index (or value)
513
518
* the other elements can be couples (key, value) or only values
519
+
520
+ If modal is True, the application will block until the result is selected.
521
+ If modal is false, the dialog will be shown and the function returns None.
514
522
"""
515
523
516
524
# Create a QApplication instance if no instance currently exists
517
525
# (e.g., if the module is used directly from the interpreter)
518
526
if QtWidgets .QApplication .startingUp ():
519
527
_app = QtWidgets .QApplication ([])
520
- dialog = FormDialog (data , title , comment , icon , parent , apply )
528
+ dialog = FormDialog (data , title , comment , icon , parent , apply , modal )
529
+ if not modal :
530
+ dialog .show ()
531
+ return
521
532
if dialog .exec_ ():
522
533
return dialog .get ()
523
534
0 commit comments