|
11 | 11 | * Enables easy data interchange, storage, and transmission of DataSet configurations |
12 | 12 | * Example usage: |
13 | 13 |
|
14 | | - ```python |
15 | | - from guidata.dataset import dataset_to_json, json_to_dataset |
| 14 | +```python |
| 15 | +from guidata.dataset import dataset_to_json, json_to_dataset |
16 | 16 |
|
17 | | - # Serialize to JSON |
18 | | - json_str = dataset_to_json(my_dataset) |
| 17 | +# Serialize to JSON |
| 18 | +json_str = dataset_to_json(my_dataset) |
19 | 19 |
|
20 | | - # Deserialize from JSON |
21 | | - restored_dataset = json_to_dataset(json_str) |
22 | | - ``` |
| 20 | +# Deserialize from JSON |
| 21 | +restored_dataset = json_to_dataset(json_str) |
| 22 | +``` |
23 | 23 |
|
24 | 24 | * **DataSet Class-Level Configuration**: Added support for configuring DataSet metadata at the class definition level using `__init_subclass__`: |
25 | 25 | * DataSet title, comment, icon, and readonly state can now be configured directly in the class inheritance declaration |
|
30 | 30 | * Backward compatibility: When no title is set at all, docstring first line is still used as title (old behavior) |
31 | 31 | * Example usage: |
32 | 32 |
|
33 | | - ```python |
34 | | - class MyParameters(DataSet, |
35 | | - title="Analysis Parameters", |
36 | | - comment="Configure your analysis options", |
37 | | - icon="params.png"): |
38 | | - """This docstring is for developer documentation only""" |
| 33 | +```python |
| 34 | +class MyParameters(DataSet, |
| 35 | + title="Analysis Parameters", |
| 36 | + comment="Configure your analysis options", |
| 37 | + icon="params.png"): |
| 38 | + """This docstring is for developer documentation only""" |
39 | 39 |
|
40 | | - threshold = FloatItem("Threshold", default=0.5) |
41 | | - method = StringItem("Method", default="auto") |
| 40 | + threshold = FloatItem("Threshold", default=0.5) |
| 41 | + method = StringItem("Method", default="auto") |
42 | 42 |
|
43 | | - # No need to pass title when instantiating |
44 | | - params = MyParameters() |
| 43 | +# No need to pass title when instantiating |
| 44 | +params = MyParameters() |
45 | 45 |
|
46 | | - # Can still override at instance level if needed |
47 | | - params_custom = MyParameters(title="Custom Title") |
48 | | - ``` |
| 46 | +# Can still override at instance level if needed |
| 47 | +params_custom = MyParameters(title="Custom Title") |
| 48 | +``` |
49 | 49 |
|
50 | 50 | * Priority order: instance parameter > class-level config > empty/default |
51 | 51 | * Makes it explicit when title is intentionally set vs. accidentally left empty |
|
58 | 58 | * Separators don't store any data - they are purely visual elements for organizing forms |
59 | 59 | * Example usage: |
60 | 60 |
|
61 | | - ```python |
62 | | - class PersonDataSet(DataSet): |
63 | | - name = StringItem("Name", default="John Doe") |
64 | | - age = IntItem("Age", default=30) |
| 61 | +```python |
| 62 | +class PersonDataSet(DataSet): |
| 63 | + name = StringItem("Name", default="John Doe") |
| 64 | + age = IntItem("Age", default=30) |
65 | 65 |
|
66 | | - # Visual separator with label |
67 | | - sep1 = SeparatorItem("Contact Information") |
| 66 | + # Visual separator with label |
| 67 | + sep1 = SeparatorItem("Contact Information") |
68 | 68 |
|
69 | | - email = StringItem( "Email", default="[email protected]") |
70 | | - phone = StringItem("Phone", default="123-456-7890") |
| 69 | + email = StringItem( "Email", default="[email protected]") |
| 70 | + phone = StringItem("Phone", default="123-456-7890") |
71 | 71 |
|
72 | | - # Visual separator without label |
73 | | - sep2 = SeparatorItem() |
| 72 | + # Visual separator without label |
| 73 | + sep2 = SeparatorItem() |
74 | 74 |
|
75 | | - notes = StringItem("Notes", default="Additional notes") |
76 | | - ``` |
| 75 | + notes = StringItem("Notes", default="Additional notes") |
| 76 | +``` |
77 | 77 |
|
78 | 78 | * Improves readability and visual organization of complex datasets |
79 | 79 | * Fully integrated with existing DataSet serialization/deserialization (separators are ignored during save/load) |
|
85 | 85 | * Computed items are automatically read-only and update in real-time when their dependencies change |
86 | 86 | * Example usage: |
87 | 87 |
|
88 | | - ```python |
89 | | - class DataSet(gdt.DataSet): |
| 88 | +```python |
| 89 | +class DataSet(gdt.DataSet): |
90 | 90 |
|
91 | | - def compute_sum(self) -> float: |
92 | | - return self.x + self.y |
| 91 | + def compute_sum(self) -> float: |
| 92 | + return self.x + self.y |
93 | 93 |
|
94 | | - x = gdt.FloatItem("X", default=1.0) |
95 | | - y = gdt.FloatItem("Y", default=2.0) |
96 | | - sum_xy = gdt.FloatItem("Sum", default=0.0).set_computed(compute_sum) |
97 | | - ``` |
| 94 | + x = gdt.FloatItem("X", default=1.0) |
| 95 | + y = gdt.FloatItem("Y", default=2.0) |
| 96 | + sum_xy = gdt.FloatItem("Sum", default=0.0).set_computed(compute_sum) |
| 97 | +``` |
98 | 98 |
|
99 | 99 | * Computed items automatically display with visual distinction (neutral background color) in GUI forms |
100 | 100 | * Supports complex calculations and can access any other items in the dataset |
|
115 | 115 | * Proper handling of None values (displayed as "-") and nested ObjectItem datasets |
116 | 116 | * Example usage: |
117 | 117 |
|
118 | | - ```python |
119 | | - class PersonDataSet(DataSet): |
120 | | - """Personal Information Dataset |
| 118 | +```python |
| 119 | +class PersonDataSet(DataSet): |
| 120 | + """Personal Information Dataset |
121 | 121 |
|
122 | | - This dataset collects basic personal information. |
123 | | - """ |
124 | | - name = StringItem("Full Name", default="John Doe") |
125 | | - age = IntItem("Age", default=30) |
126 | | - active = BoolItem("Account Active", default=True) |
| 122 | + This dataset collects basic personal information. |
| 123 | + """ |
| 124 | + name = StringItem("Full Name", default="John Doe") |
| 125 | + age = IntItem("Age", default=30) |
| 126 | + active = BoolItem("Account Active", default=True) |
127 | 127 |
|
128 | | - dataset = PersonDataSet() |
129 | | - html_output = dataset.to_html() # Generate HTML representation |
130 | | - ``` |
| 128 | +dataset = PersonDataSet() |
| 129 | +html_output = dataset.to_html() # Generate HTML representation |
| 130 | +``` |
131 | 131 |
|
132 | 132 | * Ideal for reports, documentation, and web-based dataset visualization |
133 | 133 | * Comprehensive unit test coverage ensures reliability across all item types |
|
147 | 147 | * The `readonly` property is now respected in the corresponding widgets (see `guidata.dataset.qtitemwidgets`). |
148 | 148 | * Example usage: |
149 | 149 |
|
150 | | - ```python |
151 | | - text = gds.TextItem("Text", default="Multi-line text", readonly=True) |
152 | | - string = gds.StringItem("String", readonly=True) |
153 | | - ``` |
| 150 | +```python |
| 151 | +text = gds.TextItem("Text", default="Multi-line text", readonly=True) |
| 152 | +string = gds.StringItem("String", readonly=True) |
| 153 | +``` |
154 | 154 |
|
155 | 155 | * Note: Any other item type can also be turned into read-only mode by using `set_prop("display", readonly=True)`. This is a generic mechanism, but the main use case is for `StringItem` and `TextItem` (hence the dedicated input parameter for convenience). |
156 | 156 |
|
|
171 | 171 | * `ValidationMode.STRICT`: validation is performed, and exceptions are raised if the value is invalid |
172 | 172 | * To use these validation modes, you need to set the option: |
173 | 173 |
|
174 | | - ```python |
175 | | - from guidata.config import set_validation_mode, ValidationMode |
| 174 | +```python |
| 175 | +from guidata.config import set_validation_mode, ValidationMode |
176 | 176 |
|
177 | | - set_validation_mode(ValidationMode.STRICT) |
178 | | - ``` |
| 177 | +set_validation_mode(ValidationMode.STRICT) |
| 178 | +``` |
179 | 179 |
|
180 | 180 | * New `check_callback` parameter for `FloatArrayItem`: |
181 | 181 | * The `check_callback` parameter allows you to specify a custom validation function for the item. |
|
214 | 214 | * This enables API flexibility while maintaining type safety, allowing users to pass either enum instances or their string representations interchangeably |
215 | 215 | * Example usage: |
216 | 216 |
|
217 | | - ```python |
218 | | - class ProcessingMode(LabeledEnum): |
219 | | - FAST = ("fast_mode", "Fast Processing") |
220 | | - ACCURATE = ("accurate_mode", "Accurate Processing") |
221 | | - |
222 | | - def process_data(mode): |
223 | | - if mode == ProcessingMode.FAST: # Works with both enum and string |
224 | | - return "fast_processing" |
225 | | - # ... |
226 | | - |
227 | | - # Both calls work identically: |
228 | | - result1 = process_data(ProcessingMode.FAST) # Using enum |
229 | | - result2 = process_data("fast_mode") # Using string |
230 | | - # result1 == result2 is True! |
231 | | - ``` |
| 217 | +```python |
| 218 | +class ProcessingMode(LabeledEnum): |
| 219 | + FAST = ("fast_mode", "Fast Processing") |
| 220 | + ACCURATE = ("accurate_mode", "Accurate Processing") |
| 221 | + |
| 222 | +def process_data(mode): |
| 223 | + if mode == ProcessingMode.FAST: # Works with both enum and string |
| 224 | + return "fast_processing" |
| 225 | + # ... |
| 226 | + |
| 227 | +# Both calls work identically: |
| 228 | +result1 = process_data(ProcessingMode.FAST) # Using enum |
| 229 | +result2 = process_data("fast_mode") # Using string |
| 230 | +# result1 == result2 is True! |
| 231 | +``` |
232 | 232 |
|
233 | 233 | * `StringItem` behavior change: |
234 | 234 | * The `StringItem` class now uses the new validation modes (see above). |
|
0 commit comments