diff --git a/python/rdm_modules/form_from_dict.py b/python/rdm_modules/form_from_dict.py index 014aec8..b04264c 100644 --- a/python/rdm_modules/form_from_dict.py +++ b/python/rdm_modules/form_from_dict.py @@ -19,7 +19,7 @@ from .rdm_help import rdmHelp from .rdm_widgets import (EntryBox, MultilineText, - FilePickerTextField, CheckBox, MultiSelect, DateRoller) + FilePickerTextField, CheckBox, MultiSelect, Select, DateRoller) class FormBuilder(): @@ -261,20 +261,14 @@ def add_content(self) -> None: entry.set(v['value']) elif v['type'] == 'select': - entry = ttk.Combobox(frame) - # two parameters we need, they do not have: - entry.required = False - entry.error= False + entry = Select(frame, v['options']) - entry['values'] = v['options'] # make it read only, so user cannot insert new values # alternative would be state 'normal' - entry['state'] = 'readonly' if 'value' in v: entry.set(v['value']) - else: - entry.set(v['options'][0]) + # required makes no sense here, but let it be: if 'required' in v and v['required']: entry.required = True diff --git a/python/rdm_modules/rdm_widgets.py b/python/rdm_modules/rdm_widgets.py index f072e43..f87e100 100644 --- a/python/rdm_modules/rdm_widgets.py +++ b/python/rdm_modules/rdm_widgets.py @@ -422,12 +422,54 @@ def set(self, selected:list)->None: # this will throw a value error if the value is # not in the option list self.select.select_set(self.options.index(i)) - # end set - # end class MultiSelect +class Select(): + """ a simple class to select an item from a list. + Basically for the sake of completedness, + a combo box. + """ + + def __init__(self, + parent:tk.Misc, + options:list) -> None: + """ Create a combo box with the list of options + in it. + Required is kind of unimportant here, since the + selector always stands on a value... so, it is + always set to something. + """ + self.options = options + self.parent = parent + self.required= False + self.error = False + + if self.parent is None: + self.parent = tk.Tk() + # end empty window + self.select = ttk.Combobox(self.parent) + self.select['values'] = options + self.select['state'] = 'readonly' + self.set(options[0]) + # end __init__ + + def set(self, value): + self.select.set(value) + # end of set + + def get(self): + return self.select.get() + # end of get + + def grid(self, **kwargs): + self.select.grid(**kwargs) + + +#end of class Select + + class DateRoller(): """ a simple widget to set up a date using spin boxes