Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ def second_function(result, widgets):
print("result:", fedit(datalist, title="Example",
comment="This is just an <b>example</b>.",
apply=('Custom &Apply button', apply_function),
ok='Custom &OK button',
ok='',
cancel='Custom &Cancel button',
buttonicon=True,
result='dict',
type='questions',
scrollbar=True))
Expand Down
3 changes: 2 additions & 1 deletion examples/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@
]

print("result:", fedit(datalist, title="Describe yourself",
comment="This is just an <b>example</b>."))
comment="This is just an <b>example</b>.",
buttonicon=True))
41 changes: 27 additions & 14 deletions formlayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,8 +881,8 @@ def get_widgets(self):
class FormDialog(QDialog):
"""Form Dialog"""
def __init__(self, data, title="", comment="", icon=None, parent=None,
apply=None, ok=None, cancel=None, result=None, outfile=None,
type=None, scrollbar=None):
apply=None, ok=None, cancel=None, buttonicon=None,
result=None, outfile=None, type=None, scrollbar=None):
QDialog.__init__(self, parent)

# Destroying the C++ object right after closing the dialog box,
Expand Down Expand Up @@ -942,20 +942,29 @@ def __init__(self, data, title="", comment="", icon=None, parent=None,
self.formwidget.setup()

# Button box
self.bbox = bbox = QDialogButtonBox()
if buttonicon == True:
self.setStyleSheet("QDialogButtonBox { "\
"dialogbuttonbox-buttons-have-icons: 1; }")
self.bbox = bbox = QDialogButtonBox(self)
if self.ok == True:
bbox.addButton(QDialogButtonBox.Ok)
elif self.ok:
elif self.ok or self.ok == '':
ok_btn = QPushButton(self.ok)
bbox.addButton(ok_btn, QDialogButtonBox.AcceptRole)
if buttonicon == True:
ok_btn.setIcon(qApp.style().standardIcon(
QStyle.SP_DialogOkButton))
if self.cancel == True:
bbox.addButton(QDialogButtonBox.Cancel)
elif self.cancel:
elif self.cancel or self.cancel == '':
cancel_btn = QPushButton(self.cancel)
bbox.addButton(cancel_btn, QDialogButtonBox.RejectRole)
if buttonicon == True:
cancel_btn.setIcon(qApp.style().standardIcon(
QStyle.SP_DialogCancelButton))

if self.apply_callback is not None:
if self.apply_:
if self.apply_ or self.apply_ == '':
apply_btn = QPushButton(self.apply_)
bbox.addButton(apply_btn, QDialogButtonBox.ApplyRole)
else:
Expand All @@ -964,15 +973,18 @@ def __init__(self, data, title="", comment="", icon=None, parent=None,
apply_btn.clicked.connect(self.apply)
else:
self.connect(apply_btn, SIGNAL("clicked()"), self.apply)
if buttonicon == True:
apply_btn.setIcon(qApp.style().standardIcon(
QStyle.SP_DialogApplyButton))
if SIGNAL is None:
if self.ok:
if self.ok or self.ok == '':
bbox.accepted.connect(self.accept)
if self.cancel:
if self.cancel or self.cancel == '':
bbox.rejected.connect(self.reject)
else:
if self.ok:
if self.ok or self.ok == '':
self.connect(bbox, SIGNAL("accepted()"), SLOT("accept()"))
if self.cancel:
if self.cancel or self.cancel == '':
self.connect(bbox, SIGNAL("rejected()"), SLOT("reject()"))
layout.addWidget(bbox)
self.required_valid()
Expand Down Expand Up @@ -1061,8 +1073,8 @@ def get(self):


def fedit(data, title="", comment="", icon=None, parent=None, apply=None,
ok=True, cancel=True, result='list', outfile=None, type='form',
scrollbar=False):
ok=True, cancel=True, buttonicon=False, result='list', outfile=None,
type='form', scrollbar=False):
"""
Create form dialog and return result
(if Cancel button is pressed, return None)
Expand All @@ -1074,6 +1086,7 @@ def fedit(data, title="", comment="", icon=None, parent=None, apply=None,
:param QWidget parent: parent widget
:param str ok: customized ok button label
:param str cancel: customized cancel button label
:param bool buttonicon: buttons with standard icons
:param tuple apply: (label, function) customized button label and callback
:param function apply: function taking two arguments (result, widgets)
:param str result: result serialization ('list', 'dict', 'OrderedDict',
Expand Down Expand Up @@ -1130,8 +1143,8 @@ def fedit(data, title="", comment="", icon=None, parent=None, apply=None,
(type, ', '.join(layouts)), file=sys.stderr)
type = 'form'

dialog = FormDialog(data, title, comment, icon, parent,
apply, ok, cancel, result, outfile, type, scrollbar)
dialog = FormDialog(data, title, comment, icon, parent, apply, ok, cancel,
buttonicon, result, outfile, type, scrollbar)
if dialog.exec_():
return dialog.get()

Expand Down