Skip to content

Commit

Permalink
Change example insert widget with adaptFormToStates
Browse files Browse the repository at this point in the history
  • Loading branch information
DanicaSTFC committed Jan 18, 2024
1 parent a098fc9 commit 918fa26
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions examples/insert_widgets_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def __init__(self, parent=None):
QtWidgets.QMainWindow.__init__(self, parent)

# dialog form
self.dialog = FormDialog(parent=self, title='Example insert widget')
self.dialog = FormDialog(parent=self, title='Form Dialog example insert widget')
self.addWidgetsToExampleForm(self.dialog)
buttoninsertvertical = QtWidgets.QPushButton()
buttoninsertvertical.setText("Insert widget in vertical layout")
Expand All @@ -19,12 +19,9 @@ def __init__(self, parent=None):

# create a FormDockWidget
dock = UIFormWidget.FormDockWidget(parent=self)
dock.setWindowTitle('Example insert widget')
dock.setWindowTitle('Dock Widget Example insert widget')
self.addWidgetsToExampleForm(dock)




# create button for Form Dialog
pb = QtWidgets.QPushButton(self)
pb.setText("Open Form Dialog")
Expand All @@ -38,19 +35,10 @@ def __init__(self, parent=None):
widg.setLayout(layout)
self.setCentralWidget(widg)

# print dictionary of all widgets in dock
#print("\nDictionary of widgets in the Form Dock Widget:\n" + str(dock.getWidgets()))

self.dialog.onCancel = self.onCancel

self.show()

def openFormDialog(self):

# print dictionary of all widgets in dialog
#print("\nDictionary of widgets in Form Dialog:\n" + str(self.dialog.getWidgets()))
#print("\nDictionary of widget number in Form Dialog:\n" + str(self.dialog.getWidgetNumberDictionary()))

self.dialog.open()

def addWidgetsToExampleForm(self, form):
Expand Down Expand Up @@ -78,23 +66,23 @@ def insert_form(self, form, button):
qlabel.setText("Widget inserted in row 0: ")
qwidget = QtWidgets.QLineEdit(form)
form.insertWidgetToFormLayout(0, 'inserted widget', qwidget, qlabel)

buttonspanning = QtWidgets.QPushButton(self)
buttonspanning.setText("Spanning widget inserted in row 2")
form.insertWidgetToFormLayout(2, 'inserted spanning widget', buttonspanning)

print('\nDictionary of widgets after insertion in the form layout:\n' +
str(form.getWidgets()))
print("\nDictionary of widget number in the form layout:\n" + str(form.getWidgetNumberDictionary()))
button.setEnabled(False)

def onCancel(self):
if not hasattr(self.dialog.formWidget, 'widget_states'):
if self.dialog.getWidget('Button insert vertical').isEnabled() == False:
self.dialog.removeWidgetFromVerticalLayout(self.dialog.getWidgetFromVerticalLayout(1))
if self.dialog.getWidget('Button insert widgets').isEnabled() == False:
self.dialog.formWidget._popWidgetFromDictionary(self.dialog.formWidget.default_widget_states,'inserted widget')
self.dialog.formWidget._popWidgetFromDictionary(self.dialog.formWidget.default_widget_states,'inserted spanning widget')
if self.dialog.getWidget('Button insert vertical').isEnabled() == False:
self.dialog.removeWidgetFromVerticalLayout(self.dialog.getWidgetFromVerticalLayout(1))
self.dialog.formWidget.adaptFormToStates(self.dialog.formWidget.default_widget_states)


if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
Expand Down

0 comments on commit 918fa26

Please sign in to comment.