3333OTHER DEALINGS IN THE SOFTWARE.
3434"""
3535
36- __version__ = '1.0.5'
36+ # History:
37+ # 1.0.7: added support for "Apply" button
38+ # 1.0.6: code cleaning
39+
40+ __version__ = '1.0.7'
3741__license__ = __doc__
3842
3943DEBUG = False
@@ -67,29 +71,29 @@ def __init__(self, parent=None):
6771 QPushButton .__init__ (self , parent )
6872 self .setFixedSize (20 , 20 )
6973 self .setIconSize (QSize (12 , 12 ))
70- self .connect (self , SIGNAL ("clicked()" ), self .chooseColor )
74+ self .connect (self , SIGNAL ("clicked()" ), self .choose_color )
7175 self ._color = QColor ()
7276
73- def chooseColor (self ):
77+ def choose_color (self ):
7478 rgba , valid = QColorDialog .getRgba (self ._color .rgba (),
7579 self .parentWidget ())
7680 if valid :
7781 color = QColor .fromRgba (rgba )
78- self .setColor (color )
82+ self .set_color (color )
7983
80- def color (self ):
84+ def get_color (self ):
8185 return self ._color
8286
8387 @pyqtSignature ("QColor" )
84- def setColor (self , color ):
88+ def set_color (self , color ):
8589 if color != self ._color :
8690 self ._color = color
8791 self .emit (SIGNAL ("colorChanged(QColor)" ), self ._color )
8892 pixmap = QPixmap (self .iconSize ())
8993 pixmap .fill (color )
9094 self .setIcon (QIcon (pixmap ))
9195
92- color = pyqtProperty ("QColor" , color , setColor )
96+ color = pyqtProperty ("QColor" , get_color , set_color )
9397
9498
9599def text_to_qcolor (text ):
@@ -369,8 +373,10 @@ def get(self):
369373class FormDialog (QDialog ):
370374 """Form Dialog"""
371375 def __init__ (self , data , title = "" , comment = "" ,
372- icon = None , parent = None ):
376+ icon = None , parent = None , apply = None ):
373377 super (FormDialog , self ).__init__ (parent )
378+
379+ self .apply_callback = apply
374380
375381 # Form
376382 if isinstance (data [0 ][0 ], (list , tuple )):
@@ -387,6 +393,9 @@ def __init__(self, data, title="", comment="",
387393
388394 # Button box
389395 bbox = QDialogButtonBox (QDialogButtonBox .Ok | QDialogButtonBox .Cancel )
396+ if self .apply_callback is not None :
397+ apply_btn = bbox .addButton (QDialogButtonBox .Apply )
398+ self .connect (apply_btn , SIGNAL ("clicked()" ), self .apply )
390399 self .connect (bbox , SIGNAL ("accepted()" ), SLOT ("accept()" ))
391400 self .connect (bbox , SIGNAL ("rejected()" ), SLOT ("reject()" ))
392401 layout .addWidget (bbox )
@@ -406,17 +415,25 @@ def reject(self):
406415 self .data = None
407416 QDialog .reject (self )
408417
418+ def apply (self ):
419+ self .apply_callback (self .formwidget .get ())
420+
409421 def get (self ):
410422 """Return form result"""
411423 return self .data
412424
413425
414- def fedit (data , title = "" , comment = "" , icon = None , parent = None ):
426+ def fedit (data , title = "" , comment = "" , icon = None , parent = None , apply = None ):
415427 """
416428 Create form dialog and return result
417429 (if Cancel button is pressed, return None)
418430
419431 data: datalist, datagroup
432+ title: string
433+ comment: string
434+ icon: QIcon instance
435+ parent: parent QWidget
436+ apply: apply callback (function)
420437
421438 datalist: list/tuple of (field_name, field_value)
422439 datagroup: list/tuple of (datalist *or* datagroup, title, comment)
@@ -440,7 +457,7 @@ def fedit(data, title="", comment="", icon=None, parent=None):
440457 if QApplication .startingUp ():
441458 QApplication ([])
442459
443- dialog = FormDialog (data , title , comment , icon , parent )
460+ dialog = FormDialog (data , title , comment , icon , parent , apply )
444461 if dialog .exec_ ():
445462 return dialog .get ()
446463
@@ -471,8 +488,11 @@ def create_datagroup_example():
471488
472489 #--------- datalist example
473490 datalist = create_datalist_example ()
491+ def apply_test (data ):
492+ print "data:" , data
474493 print "result:" , fedit (datalist , title = "Example" ,
475- comment = "This is just an <b>example</b>." )
494+ comment = "This is just an <b>example</b>." ,
495+ apply = apply_test )
476496
477497 #--------- datagroup example
478498 datagroup = create_datagroup_example ()
0 commit comments