diff --git a/examples/advanced.py b/examples/advanced.py index 491bbb7..a57bb6c 100644 --- a/examples/advanced.py +++ b/examples/advanced.py @@ -43,11 +43,17 @@ def create_datalist_example(): ] return test -def create_datagroup_example(): +def create_combogroup_example(): datalist = create_datalist_example() - return ((datalist, "Category 1", "Category 1 comment"), + return [(datalist, "Category 1", "Category 1 comment"), (datalist, "Category 2", "Category 2 comment"), - (datalist, "Category 3", "Category 3 comment")) + (datalist, "Category 3", "Category 3 comment")] + +def create_tabgroup_example(): + datalist = create_datalist_example() + return ((datalist, "Title 1", "Title 1 comment"), + (datalist, "Title 2", "Title 2 comment"), + (datalist, "Title 3", "Title 3 comment")) def apply_function(result, widgets): print('result:', result) @@ -83,14 +89,48 @@ def second_function(result, widgets): type='questions', scrollbar=True)) -#--------- datagroup example -datagroup = create_datagroup_example() +#--------- datagroup examples +datagroup = create_combogroup_example() print("result:", fedit(datagroup, "Global title", result='JSON')) -#--------- datagroup inside a datagroup example +datagroup = create_tabgroup_example() +print("result:", fedit(datagroup, "Global title", result='JSON')) + +#--------- datagroup inside a datagroup examples +datalist = create_datalist_example() +datagroup = create_tabgroup_example() +print("result:", fedit([(datagroup, "Category 1", "Category 1 comment"), + (datalist, "Category 2", "Category 2 comment"), + (datalist, "Category 3", "Category 3 comment")], + "Global title", result='XML')) + datalist = create_datalist_example() -datagroup = create_datagroup_example() +datagroup = create_combogroup_example() print("result:", fedit(((datagroup, "Title 1", "Tab 1 comment"), (datalist, "Title 2", "Tab 2 comment"), (datalist, "Title 3", "Tab 3 comment")), "Global title", result='XML')) + +datalist = create_datalist_example() +datagroup = create_combogroup_example() +print("result:", fedit([(datagroup, "Category 1", "Category 1 comment"), + (datalist, "Category 2", "Category 2 comment"), + (datalist, "Category 3", "Category 3 comment")], + "Global title", result='XML')) + +datalist = create_datalist_example() +datagroup = create_tabgroup_example() +print("result:", fedit(((datagroup, "Title 1", "Tab 1 comment"), + (datalist, "Title 2", "Tab 2 comment"), + (datalist, "Title 3", "Tab 3 comment")), + "Global title", result='XML')) + +datalist = create_datalist_example() +datagroup = create_tabgroup_example() +print("result:", fedit((([(datagroup, "Category 1", "Category 1 comment"), + (datalist, "Category 2", "Category 2 comment"), + (datalist, "Category 3", "Category 3 comment")], + "Three", "Three levels"), + (datagroup, "Two", "Two levels"), + (datalist, "One", "One level")), + "Global title", result='XML')) diff --git a/formlayout.py b/formlayout.py index 30391ab..35de4a3 100644 --- a/formlayout.py +++ b/formlayout.py @@ -779,7 +779,12 @@ def __init__(self, datalist, comment="", parent=None): self.widgetlist = [] for data, title, comment in datalist: self.combobox.addItem(title) - widget = FormWidget(data, comment=comment, parent=self) + if isinstance(data, tuple) and len(data[0]) == 3: + widget = FormTabWidget(data, comment=comment, parent=self) + elif isinstance(data, list) and len(data[0]) == 3: + widget = FormComboWidget(data, comment=comment, parent=self) + else: + widget = FormWidget(data, comment=comment, parent=self) self.stackwidget.addWidget(widget) self.widgetlist.append((title, widget)) @@ -832,7 +837,9 @@ def __init__(self, datalist, comment="", parent=None): self.type = parent.type self.widgetlist = [] for data, title, comment in datalist: - if len(data[0])==3: + if isinstance(data, tuple) and len(data[0]) == 3: + widget = FormTabWidget(data, comment=comment, parent=self) + elif isinstance(data, list) and len(data[0]) == 3: widget = FormComboWidget(data, comment=comment, parent=self) else: widget = FormWidget(data, comment=comment, parent=self) @@ -917,10 +924,10 @@ def __init__(self, data, title="", comment="", icon=None, parent=None, import xml.etree.ElementTree as ET # Form - if isinstance(data[0][0], (list, tuple)): + if isinstance(data, tuple) and len(data[0]) == 3: self.formwidget = FormTabWidget(data, comment=comment, parent=self) - elif len(data[0])==3: + elif isinstance(data, list) and len(data[0]) == 3: self.formwidget = FormComboWidget(data, comment=comment, parent=self) else: