-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Save entries by default in the Form Dialog (#97)
- Adds a method to `UIFormWidget` to populate the default-widget-states dictionary and a method to make default-widget-states visible. - Form dialog saves states by default when `Ok` is clicked and restores the previously-saved states or the default states when `Cancel` is clicked. - Adds example file "dialog_example_3_save_default" to demonstrate the new features. - Adds example file "utilitiesForExample" for methods recurring in the examples. - Adds `exampleState`, `set_state` and `test_dialog_buttons_default_behaviour` to the unit tests.
- Loading branch information
1 parent
cd81441
commit 05bc80d
Showing
6 changed files
with
219 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import sys | ||
|
||
import utilitiesForExamples as utex | ||
from PySide2 import QtWidgets | ||
|
||
from eqt.ui import FormDialog | ||
|
||
|
||
class MainUI(QtWidgets.QMainWindow): | ||
def __init__(self, parent=None): | ||
QtWidgets.QMainWindow.__init__(self, parent) | ||
|
||
pb = QtWidgets.QPushButton(self) | ||
pb.setText("Open Dialog with form layout") | ||
pb.clicked.connect(lambda: self.executeDialog()) | ||
|
||
layout = QtWidgets.QHBoxLayout() | ||
layout.addWidget(pb) | ||
widg = QtWidgets.QWidget() | ||
widg.setLayout(layout) | ||
|
||
self.setCentralWidget(widg) | ||
self.dialog = FormDialog(parent=self, title='Example') | ||
self.openFormDialog() | ||
|
||
self.show() | ||
|
||
def openFormDialog(self): | ||
utex.addWidgetsToExample(self.dialog) | ||
# redefine the onOk and onCancel functions | ||
self.dialog.onOk = self.accepted | ||
self.dialog.onCancel = self.rejected | ||
|
||
def accepted(self): | ||
print("States saved") | ||
|
||
def rejected(self): | ||
print("States rejected") | ||
|
||
# open dialog function when the parent button is clicked | ||
def executeDialog(self): | ||
self.dialog.open() | ||
|
||
|
||
if __name__ == "__main__": | ||
app = QtWidgets.QApplication(sys.argv) | ||
|
||
window = MainUI() | ||
|
||
sys.exit(app.exec_()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from PySide2 import QtWidgets | ||
|
||
from eqt.ui.UISliderWidget import UISliderWidget | ||
|
||
|
||
def addWidgetsToExample(form): | ||
''' | ||
Adds a spanning widget and every type of widget to a form | ||
''' | ||
# add a spanning widget | ||
form.addSpanningWidget(QtWidgets.QLabel("Input Values: "), 'input_title') | ||
# add all widgets | ||
form.addWidget(QtWidgets.QLabel('Label'), 'Label: ', 'label') | ||
form.addWidget(QtWidgets.QCheckBox('check me'), 'CheckBox: ', 'checkBox') | ||
combobox_list = ['choice 1', 'choice 2'] | ||
form.addWidget(QtWidgets.QComboBox(), 'ComboBox: ', 'comboBox') | ||
form.getWidget('comboBox').addItems(combobox_list) | ||
form.addWidget(QtWidgets.QDoubleSpinBox(), 'DoubleSpinBox: ', 'doubleSpinBox') | ||
form.addWidget(QtWidgets.QSpinBox(), 'SpinBox: ', 'spinBox') | ||
form.addWidget(QtWidgets.QSlider(), 'Slider: ', 'slider') | ||
form.addWidget(UISliderWidget(QtWidgets.QLabel()), 'UISlider: ', 'uiSliderWidget') | ||
form.addWidget(QtWidgets.QRadioButton('select me'), 'RadioButton: ', 'radioButton') | ||
form.addWidget(QtWidgets.QTextEdit('write text here'), 'TextEdit: ', 'textEdit') | ||
form.addWidget(QtWidgets.QPlainTextEdit('write text here'), 'PlainTextEdit: ', 'plainTextEdit') | ||
form.addWidget(QtWidgets.QLineEdit('write text here'), 'LineEdit: ', 'lineEdit') | ||
form.addWidget(QtWidgets.QPushButton('Click me'), 'Button: ', 'button') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters