nanopyx.core.utils.easy_gui
A module to help simplify the create of GUIs in Jupyter notebooks using ipywidgets.
1""" 2A module to help simplify the create of GUIs in Jupyter notebooks using ipywidgets. 3""" 4 5import os 6import yaml 7import platform 8import numpy as np 9from ipyfilechooser import FileChooser 10from skimage.exposure import rescale_intensity 11 12# import cache if python >= 3.9, otherwise import lru_cache 13if platform.python_version_tuple() >= ("3", "9"): 14 from functools import cache 15else: 16 from functools import lru_cache as cache 17 18try: 19 import ipywidgets as widgets 20 from IPython import display as dp 21 from IPython.display import display, clear_output 22 from matplotlib import pyplot as plt 23except ImportError: 24 print("jupyter optional-dependencies not installed, conside installing with 'pip install nanopyx[jupyter]'") 25 raise ImportError 26 27 28class EasyGui: 29 """ 30 A class to simplify the creation of GUIs in Jupyter notebooks using ipywidgets. 31 32 Args: 33 title (str): The title of the GUI. 34 width (str): The width of the widget container (e.g., "50%"). 35 36 Attributes: 37 _layout (ipywidgets.Layout): The layout for widgets. 38 _style (dict): Style configuration for widgets. 39 _widgets (dict): A dictionary to store widgets. 40 _nLabels (int): The number of labels added to the GUI. 41 _main_display (ipywidgets.VBox): The main output widget for the GUI. 42 _title (str): The title of the GUI. 43 _cfg (dict): Configuration dictionary to store widget values. 44 cfg (dict): Alias for the _cfg dictionary associated with the GUI. 45 46 Methods: 47 add_label: Add a label widget to the GUI. 48 add_button: Add a button widget to the GUI. 49 add_text: Add a text widget to the GUI. 50 add_int_slider: Add an integer slider widget to the GUI. 51 add_float_slider: Add a float slider widget to the GUI. 52 add_checkbox: Add a checkbox widget to the GUI. 53 add_int_text: Add an integer text widget to the GUI. 54 add_float_text: Add a float text widget to the GUI. 55 add_dropdown: Add a dropdown widget to the GUI. 56 add_file_upload: Add a file upload widget to the GUI. 57 save_settings: Save widget values to a configuration file. 58 show: Display the GUI with its widgets. 59 clear: Clear all widgets from the GUI. 60 61 Note: 62 This class simplifies the creation of GUIs in Jupyter notebooks using ipywidgets. It provides a variety of methods for adding different types of widgets to the GUI, and it allows for saving and loading widget values to maintain user settings across sessions. 63 """ 64 65 def __init__(self, title="basic_gui", width="50%"): 66 """ 67 Container for widgets. 68 :param width: width of the widget container 69 """ 70 self._layout = widgets.Layout(width=width) 71 self._style = {"description_width": "initial"} 72 self._widgets = {} 73 self._nLabels = 0 74 self._main_display = widgets.VBox() 75 self._title = title 76 self._cfg = {title: {}} 77 self.cfg = self._cfg[title] 78 79 # Get the user's home folder 80 self._home_folder = os.path.expanduser("~") 81 self._config_folder = os.path.join(self._home_folder, ".nanopyx") 82 if not os.path.exists(self._config_folder): 83 os.makedirs(self._config_folder) 84 85 self._config_file = os.path.join(self._config_folder, "easy_gui.yml") 86 if os.path.exists(self._config_file): 87 with open(self._config_file, "r") as f: 88 self._cfg = yaml.load(f, Loader=yaml.FullLoader) 89 if title in self._cfg: 90 self.cfg = self._cfg[title] 91 92 def __getitem__(self, tag: str) -> widgets.Widget: 93 return self._widgets[tag] 94 95 def __len__(self) -> int: 96 return len(self._widgets) 97 98 def add_label(self, *args, **kwargs): 99 """ 100 Add a label widget to the container. 101 :param args: args for the widget 102 :param kwargs: kwargs for the widget 103 """ 104 self._nLabels += 1 105 self._widgets[f"label_{self._nLabels}"] = widgets.Label(*args, **kwargs, layout=self._layout, style=self._style) 106 107 def add_button(self, tag, *args, **kwargs): 108 """ 109 Add a button widget to the container. 110 :param tag: tag to identify the widget 111 :param args: args for the widget 112 :param kwargs: kwargs for the widget 113 """ 114 self._widgets[tag] = widgets.Button(*args, **kwargs, layout=self._layout, style=self._style) 115 116 def add_text(self, tag, *args, **kwargs): 117 """ 118 Add a text widget to the container. 119 :param tag: tag to identify the widget 120 :param args: args for the widget 121 :param kwargs: kwargs for the widget 122 """ 123 self._widgets[tag] = widgets.Text(*args, **kwargs, layout=self._layout, style=self._style) 124 125 def add_int_slider(self, tag, *args, remember_value=False, **kwargs): 126 """ 127 Add a integer slider widget to the container. 128 :param tag: tag to identify the widget 129 :param args: args for the widget 130 :param remember_value: remember the last value 131 :param kwargs: kwargs for the widget 132 """ 133 if remember_value and tag in self.cfg and kwargs["min"] <= self.cfg[tag] <= kwargs["max"]: 134 kwargs["value"] = self.cfg[tag] 135 self._widgets[tag] = widgets.IntSlider(*args, **kwargs, layout=self._layout, style=self._style) 136 137 def add_float_slider(self, tag, *args, remember_value=False, **kwargs): 138 """ 139 Add a float slider widget to the container. 140 :param tag: tag to identify the widget 141 :param args: args for the widget 142 :param remember_value: remember the last value 143 :param kwargs: kwargs for the widget 144 """ 145 if remember_value and tag in self.cfg: 146 kwargs["value"] = self.cfg[tag] 147 self._widgets[tag] = widgets.FloatSlider(*args, **kwargs, layout=self._layout, style=self._style) 148 149 def add_checkbox(self, tag, *args, remember_value=False, **kwargs): 150 """ 151 Add a checkbox widget to the container. 152 :param tag: tag to identify the widget 153 :param args: args for the widget 154 :param remember_value: remember the last value 155 :param kwargs: kwargs for the widget 156 """ 157 if remember_value and tag in self.cfg: 158 kwargs["value"] = self.cfg[tag] 159 self._widgets[tag] = widgets.Checkbox(*args, **kwargs, layout=self._layout, style=self._style) 160 161 def add_int_text(self, tag, *args, remember_value=False, **kwargs): 162 """ 163 Add a integer text widget to the container. 164 :param tag: tag to identify the widget 165 :param args: args for the widget 166 :param remember_value: remember the last value 167 :param kwargs: kwargs for the widget 168 """ 169 if remember_value and tag in self.cfg: 170 kwargs["value"] = self.cfg[tag] 171 172 self._widgets[tag] = widgets.IntText(*args, **kwargs, layout=self._layout, style=self._style) 173 174 def add_float_text(self, tag, *args, remember_value=False, **kwargs): 175 """ 176 Add a float text widget to the container. 177 :param tag: tag to identify the widget 178 :param args: args for the widget 179 :param remember_value: remember the last value 180 :param kwargs: kwargs for the widget 181 """ 182 if remember_value and tag in self.cfg: 183 kwargs["value"] = self.cfg[tag] 184 self._widgets[tag] = widgets.FloatText(*args, **kwargs, layout=self._layout, style=self._style) 185 186 def add_dropdown(self, tag, *args, remember_value=False, **kwargs): 187 """ 188 Add a dropdown widget to the container. 189 :param tag: tag to identify the widget 190 :param args: args for the widget 191 :param remember_value: remember the last value 192 :param kwargs: kwargs for the widget 193 """ 194 if remember_value and tag in self.cfg and self.cfg[tag] in kwargs["options"]: 195 kwargs["value"] = self.cfg[tag] 196 self._widgets[tag] = widgets.Dropdown(*args, **kwargs, layout=self._layout, style=self._style) 197 198 def add_file_upload(self, tag, *args, accept=None, multiple=False, **kwargs): 199 """ 200 Add a file upload widget to the container. 201 :param tag: tag to identify the widget 202 :param args: args for the widget 203 :param accept: file types to accept 204 :param multiple: allow multiple files to be uploaded 205 :param kwargs: kwargs for the widget 206 """ 207 self._widgets[tag] = FileChooser() 208 if accept is not None: 209 self._widgets[tag].filter_pattern = accept 210 211 def save_settings(self): 212 # remember widget values for next time and store them in a config file 213 for tag in self._widgets: 214 if tag.startswith("label_"): 215 pass 216 elif hasattr(self._widgets[tag], "value"): 217 self.cfg[tag] = self._widgets[tag].value 218 self._cfg[self._title] = self.cfg 219 with open(self._config_file, "w") as f: 220 yaml.dump(self._cfg, f) 221 222 def show(self): 223 """ 224 Show the widgets in the container. 225 """ 226 # display the widgets 227 self._main_display.children = (tuple(self._widgets.values())) 228 clear_output() 229 display(self._main_display) 230 231 def clear(self): 232 """ 233 Clear the widgets in the container. 234 """ 235 self._widgets = {} 236 self._nLabels = 0 237 self._main_display.children = ()
29class EasyGui: 30 """ 31 A class to simplify the creation of GUIs in Jupyter notebooks using ipywidgets. 32 33 Args: 34 title (str): The title of the GUI. 35 width (str): The width of the widget container (e.g., "50%"). 36 37 Attributes: 38 _layout (ipywidgets.Layout): The layout for widgets. 39 _style (dict): Style configuration for widgets. 40 _widgets (dict): A dictionary to store widgets. 41 _nLabels (int): The number of labels added to the GUI. 42 _main_display (ipywidgets.VBox): The main output widget for the GUI. 43 _title (str): The title of the GUI. 44 _cfg (dict): Configuration dictionary to store widget values. 45 cfg (dict): Alias for the _cfg dictionary associated with the GUI. 46 47 Methods: 48 add_label: Add a label widget to the GUI. 49 add_button: Add a button widget to the GUI. 50 add_text: Add a text widget to the GUI. 51 add_int_slider: Add an integer slider widget to the GUI. 52 add_float_slider: Add a float slider widget to the GUI. 53 add_checkbox: Add a checkbox widget to the GUI. 54 add_int_text: Add an integer text widget to the GUI. 55 add_float_text: Add a float text widget to the GUI. 56 add_dropdown: Add a dropdown widget to the GUI. 57 add_file_upload: Add a file upload widget to the GUI. 58 save_settings: Save widget values to a configuration file. 59 show: Display the GUI with its widgets. 60 clear: Clear all widgets from the GUI. 61 62 Note: 63 This class simplifies the creation of GUIs in Jupyter notebooks using ipywidgets. It provides a variety of methods for adding different types of widgets to the GUI, and it allows for saving and loading widget values to maintain user settings across sessions. 64 """ 65 66 def __init__(self, title="basic_gui", width="50%"): 67 """ 68 Container for widgets. 69 :param width: width of the widget container 70 """ 71 self._layout = widgets.Layout(width=width) 72 self._style = {"description_width": "initial"} 73 self._widgets = {} 74 self._nLabels = 0 75 self._main_display = widgets.VBox() 76 self._title = title 77 self._cfg = {title: {}} 78 self.cfg = self._cfg[title] 79 80 # Get the user's home folder 81 self._home_folder = os.path.expanduser("~") 82 self._config_folder = os.path.join(self._home_folder, ".nanopyx") 83 if not os.path.exists(self._config_folder): 84 os.makedirs(self._config_folder) 85 86 self._config_file = os.path.join(self._config_folder, "easy_gui.yml") 87 if os.path.exists(self._config_file): 88 with open(self._config_file, "r") as f: 89 self._cfg = yaml.load(f, Loader=yaml.FullLoader) 90 if title in self._cfg: 91 self.cfg = self._cfg[title] 92 93 def __getitem__(self, tag: str) -> widgets.Widget: 94 return self._widgets[tag] 95 96 def __len__(self) -> int: 97 return len(self._widgets) 98 99 def add_label(self, *args, **kwargs): 100 """ 101 Add a label widget to the container. 102 :param args: args for the widget 103 :param kwargs: kwargs for the widget 104 """ 105 self._nLabels += 1 106 self._widgets[f"label_{self._nLabels}"] = widgets.Label(*args, **kwargs, layout=self._layout, style=self._style) 107 108 def add_button(self, tag, *args, **kwargs): 109 """ 110 Add a button widget to the container. 111 :param tag: tag to identify the widget 112 :param args: args for the widget 113 :param kwargs: kwargs for the widget 114 """ 115 self._widgets[tag] = widgets.Button(*args, **kwargs, layout=self._layout, style=self._style) 116 117 def add_text(self, tag, *args, **kwargs): 118 """ 119 Add a text widget to the container. 120 :param tag: tag to identify the widget 121 :param args: args for the widget 122 :param kwargs: kwargs for the widget 123 """ 124 self._widgets[tag] = widgets.Text(*args, **kwargs, layout=self._layout, style=self._style) 125 126 def add_int_slider(self, tag, *args, remember_value=False, **kwargs): 127 """ 128 Add a integer slider widget to the container. 129 :param tag: tag to identify the widget 130 :param args: args for the widget 131 :param remember_value: remember the last value 132 :param kwargs: kwargs for the widget 133 """ 134 if remember_value and tag in self.cfg and kwargs["min"] <= self.cfg[tag] <= kwargs["max"]: 135 kwargs["value"] = self.cfg[tag] 136 self._widgets[tag] = widgets.IntSlider(*args, **kwargs, layout=self._layout, style=self._style) 137 138 def add_float_slider(self, tag, *args, remember_value=False, **kwargs): 139 """ 140 Add a float slider widget to the container. 141 :param tag: tag to identify the widget 142 :param args: args for the widget 143 :param remember_value: remember the last value 144 :param kwargs: kwargs for the widget 145 """ 146 if remember_value and tag in self.cfg: 147 kwargs["value"] = self.cfg[tag] 148 self._widgets[tag] = widgets.FloatSlider(*args, **kwargs, layout=self._layout, style=self._style) 149 150 def add_checkbox(self, tag, *args, remember_value=False, **kwargs): 151 """ 152 Add a checkbox widget to the container. 153 :param tag: tag to identify the widget 154 :param args: args for the widget 155 :param remember_value: remember the last value 156 :param kwargs: kwargs for the widget 157 """ 158 if remember_value and tag in self.cfg: 159 kwargs["value"] = self.cfg[tag] 160 self._widgets[tag] = widgets.Checkbox(*args, **kwargs, layout=self._layout, style=self._style) 161 162 def add_int_text(self, tag, *args, remember_value=False, **kwargs): 163 """ 164 Add a integer text widget to the container. 165 :param tag: tag to identify the widget 166 :param args: args for the widget 167 :param remember_value: remember the last value 168 :param kwargs: kwargs for the widget 169 """ 170 if remember_value and tag in self.cfg: 171 kwargs["value"] = self.cfg[tag] 172 173 self._widgets[tag] = widgets.IntText(*args, **kwargs, layout=self._layout, style=self._style) 174 175 def add_float_text(self, tag, *args, remember_value=False, **kwargs): 176 """ 177 Add a float text widget to the container. 178 :param tag: tag to identify the widget 179 :param args: args for the widget 180 :param remember_value: remember the last value 181 :param kwargs: kwargs for the widget 182 """ 183 if remember_value and tag in self.cfg: 184 kwargs["value"] = self.cfg[tag] 185 self._widgets[tag] = widgets.FloatText(*args, **kwargs, layout=self._layout, style=self._style) 186 187 def add_dropdown(self, tag, *args, remember_value=False, **kwargs): 188 """ 189 Add a dropdown widget to the container. 190 :param tag: tag to identify the widget 191 :param args: args for the widget 192 :param remember_value: remember the last value 193 :param kwargs: kwargs for the widget 194 """ 195 if remember_value and tag in self.cfg and self.cfg[tag] in kwargs["options"]: 196 kwargs["value"] = self.cfg[tag] 197 self._widgets[tag] = widgets.Dropdown(*args, **kwargs, layout=self._layout, style=self._style) 198 199 def add_file_upload(self, tag, *args, accept=None, multiple=False, **kwargs): 200 """ 201 Add a file upload widget to the container. 202 :param tag: tag to identify the widget 203 :param args: args for the widget 204 :param accept: file types to accept 205 :param multiple: allow multiple files to be uploaded 206 :param kwargs: kwargs for the widget 207 """ 208 self._widgets[tag] = FileChooser() 209 if accept is not None: 210 self._widgets[tag].filter_pattern = accept 211 212 def save_settings(self): 213 # remember widget values for next time and store them in a config file 214 for tag in self._widgets: 215 if tag.startswith("label_"): 216 pass 217 elif hasattr(self._widgets[tag], "value"): 218 self.cfg[tag] = self._widgets[tag].value 219 self._cfg[self._title] = self.cfg 220 with open(self._config_file, "w") as f: 221 yaml.dump(self._cfg, f) 222 223 def show(self): 224 """ 225 Show the widgets in the container. 226 """ 227 # display the widgets 228 self._main_display.children = (tuple(self._widgets.values())) 229 clear_output() 230 display(self._main_display) 231 232 def clear(self): 233 """ 234 Clear the widgets in the container. 235 """ 236 self._widgets = {} 237 self._nLabels = 0 238 self._main_display.children = ()
A class to simplify the creation of GUIs in Jupyter notebooks using ipywidgets.
Args: title (str): The title of the GUI. width (str): The width of the widget container (e.g., "50%").
Attributes: _layout (ipywidgets.Layout): The layout for widgets. _style (dict): Style configuration for widgets. _widgets (dict): A dictionary to store widgets. _nLabels (int): The number of labels added to the GUI. _main_display (ipywidgets.VBox): The main output widget for the GUI. _title (str): The title of the GUI. _cfg (dict): Configuration dictionary to store widget values. cfg (dict): Alias for the _cfg dictionary associated with the GUI.
Methods: add_label: Add a label widget to the GUI. add_button: Add a button widget to the GUI. add_text: Add a text widget to the GUI. add_int_slider: Add an integer slider widget to the GUI. add_float_slider: Add a float slider widget to the GUI. add_checkbox: Add a checkbox widget to the GUI. add_int_text: Add an integer text widget to the GUI. add_float_text: Add a float text widget to the GUI. add_dropdown: Add a dropdown widget to the GUI. add_file_upload: Add a file upload widget to the GUI. save_settings: Save widget values to a configuration file. show: Display the GUI with its widgets. clear: Clear all widgets from the GUI.
Note: This class simplifies the creation of GUIs in Jupyter notebooks using ipywidgets. It provides a variety of methods for adding different types of widgets to the GUI, and it allows for saving and loading widget values to maintain user settings across sessions.
66 def __init__(self, title="basic_gui", width="50%"): 67 """ 68 Container for widgets. 69 :param width: width of the widget container 70 """ 71 self._layout = widgets.Layout(width=width) 72 self._style = {"description_width": "initial"} 73 self._widgets = {} 74 self._nLabels = 0 75 self._main_display = widgets.VBox() 76 self._title = title 77 self._cfg = {title: {}} 78 self.cfg = self._cfg[title] 79 80 # Get the user's home folder 81 self._home_folder = os.path.expanduser("~") 82 self._config_folder = os.path.join(self._home_folder, ".nanopyx") 83 if not os.path.exists(self._config_folder): 84 os.makedirs(self._config_folder) 85 86 self._config_file = os.path.join(self._config_folder, "easy_gui.yml") 87 if os.path.exists(self._config_file): 88 with open(self._config_file, "r") as f: 89 self._cfg = yaml.load(f, Loader=yaml.FullLoader) 90 if title in self._cfg: 91 self.cfg = self._cfg[title]
Container for widgets.
Parameters
- width: width of the widget container
99 def add_label(self, *args, **kwargs): 100 """ 101 Add a label widget to the container. 102 :param args: args for the widget 103 :param kwargs: kwargs for the widget 104 """ 105 self._nLabels += 1 106 self._widgets[f"label_{self._nLabels}"] = widgets.Label(*args, **kwargs, layout=self._layout, style=self._style)
Add a label widget to the container.
Parameters
- args: args for the widget
- kwargs: kwargs for the widget
117 def add_text(self, tag, *args, **kwargs): 118 """ 119 Add a text widget to the container. 120 :param tag: tag to identify the widget 121 :param args: args for the widget 122 :param kwargs: kwargs for the widget 123 """ 124 self._widgets[tag] = widgets.Text(*args, **kwargs, layout=self._layout, style=self._style)
Add a text widget to the container.
Parameters
- tag: tag to identify the widget
- args: args for the widget
- kwargs: kwargs for the widget
126 def add_int_slider(self, tag, *args, remember_value=False, **kwargs): 127 """ 128 Add a integer slider widget to the container. 129 :param tag: tag to identify the widget 130 :param args: args for the widget 131 :param remember_value: remember the last value 132 :param kwargs: kwargs for the widget 133 """ 134 if remember_value and tag in self.cfg and kwargs["min"] <= self.cfg[tag] <= kwargs["max"]: 135 kwargs["value"] = self.cfg[tag] 136 self._widgets[tag] = widgets.IntSlider(*args, **kwargs, layout=self._layout, style=self._style)
Add a integer slider widget to the container.
Parameters
- tag: tag to identify the widget
- args: args for the widget
- remember_value: remember the last value
- kwargs: kwargs for the widget
138 def add_float_slider(self, tag, *args, remember_value=False, **kwargs): 139 """ 140 Add a float slider widget to the container. 141 :param tag: tag to identify the widget 142 :param args: args for the widget 143 :param remember_value: remember the last value 144 :param kwargs: kwargs for the widget 145 """ 146 if remember_value and tag in self.cfg: 147 kwargs["value"] = self.cfg[tag] 148 self._widgets[tag] = widgets.FloatSlider(*args, **kwargs, layout=self._layout, style=self._style)
Add a float slider widget to the container.
Parameters
- tag: tag to identify the widget
- args: args for the widget
- remember_value: remember the last value
- kwargs: kwargs for the widget
150 def add_checkbox(self, tag, *args, remember_value=False, **kwargs): 151 """ 152 Add a checkbox widget to the container. 153 :param tag: tag to identify the widget 154 :param args: args for the widget 155 :param remember_value: remember the last value 156 :param kwargs: kwargs for the widget 157 """ 158 if remember_value and tag in self.cfg: 159 kwargs["value"] = self.cfg[tag] 160 self._widgets[tag] = widgets.Checkbox(*args, **kwargs, layout=self._layout, style=self._style)
Add a checkbox widget to the container.
Parameters
- tag: tag to identify the widget
- args: args for the widget
- remember_value: remember the last value
- kwargs: kwargs for the widget
162 def add_int_text(self, tag, *args, remember_value=False, **kwargs): 163 """ 164 Add a integer text widget to the container. 165 :param tag: tag to identify the widget 166 :param args: args for the widget 167 :param remember_value: remember the last value 168 :param kwargs: kwargs for the widget 169 """ 170 if remember_value and tag in self.cfg: 171 kwargs["value"] = self.cfg[tag] 172 173 self._widgets[tag] = widgets.IntText(*args, **kwargs, layout=self._layout, style=self._style)
Add a integer text widget to the container.
Parameters
- tag: tag to identify the widget
- args: args for the widget
- remember_value: remember the last value
- kwargs: kwargs for the widget
175 def add_float_text(self, tag, *args, remember_value=False, **kwargs): 176 """ 177 Add a float text widget to the container. 178 :param tag: tag to identify the widget 179 :param args: args for the widget 180 :param remember_value: remember the last value 181 :param kwargs: kwargs for the widget 182 """ 183 if remember_value and tag in self.cfg: 184 kwargs["value"] = self.cfg[tag] 185 self._widgets[tag] = widgets.FloatText(*args, **kwargs, layout=self._layout, style=self._style)
Add a float text widget to the container.
Parameters
- tag: tag to identify the widget
- args: args for the widget
- remember_value: remember the last value
- kwargs: kwargs for the widget
187 def add_dropdown(self, tag, *args, remember_value=False, **kwargs): 188 """ 189 Add a dropdown widget to the container. 190 :param tag: tag to identify the widget 191 :param args: args for the widget 192 :param remember_value: remember the last value 193 :param kwargs: kwargs for the widget 194 """ 195 if remember_value and tag in self.cfg and self.cfg[tag] in kwargs["options"]: 196 kwargs["value"] = self.cfg[tag] 197 self._widgets[tag] = widgets.Dropdown(*args, **kwargs, layout=self._layout, style=self._style)
Add a dropdown widget to the container.
Parameters
- tag: tag to identify the widget
- args: args for the widget
- remember_value: remember the last value
- kwargs: kwargs for the widget
199 def add_file_upload(self, tag, *args, accept=None, multiple=False, **kwargs): 200 """ 201 Add a file upload widget to the container. 202 :param tag: tag to identify the widget 203 :param args: args for the widget 204 :param accept: file types to accept 205 :param multiple: allow multiple files to be uploaded 206 :param kwargs: kwargs for the widget 207 """ 208 self._widgets[tag] = FileChooser() 209 if accept is not None: 210 self._widgets[tag].filter_pattern = accept
Add a file upload widget to the container.
Parameters
- tag: tag to identify the widget
- args: args for the widget
- accept: file types to accept
- multiple: allow multiple files to be uploaded
- kwargs: kwargs for the widget
212 def save_settings(self): 213 # remember widget values for next time and store them in a config file 214 for tag in self._widgets: 215 if tag.startswith("label_"): 216 pass 217 elif hasattr(self._widgets[tag], "value"): 218 self.cfg[tag] = self._widgets[tag].value 219 self._cfg[self._title] = self.cfg 220 with open(self._config_file, "w") as f: 221 yaml.dump(self._cfg, f)