Skip to content

Commit

Permalink
Added Select() to the widgets for the sake of completedness
Browse files Browse the repository at this point in the history
  • Loading branch information
tomio13 committed Jun 27, 2023
1 parent cc2d5b4 commit 638821c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 11 deletions.
12 changes: 3 additions & 9 deletions python/rdm_modules/form_from_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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

Expand Down
46 changes: 44 additions & 2 deletions python/rdm_modules/rdm_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 638821c

Please sign in to comment.