diff options
Diffstat (limited to 'lib/gui/edit_json/combo_prompt.py')
| -rw-r--r-- | lib/gui/edit_json/combo_prompt.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/gui/edit_json/combo_prompt.py b/lib/gui/edit_json/combo_prompt.py new file mode 100644 index 00000000..bebb1947 --- /dev/null +++ b/lib/gui/edit_json/combo_prompt.py @@ -0,0 +1,49 @@ +import wx + + +class PromptingComboBox(wx.ComboBox): + def __init__(self, parent, choices=[], style=0, **kwargs): + if choices is None: + choices = [] + wx.ComboBox.__init__(self, parent, wx.ID_ANY, style=style, choices=choices, **kwargs) + self.choices = choices + self.Bind(wx.EVT_KEY_DOWN, self.on_button_down) + self.Bind(wx.EVT_TEXT, self.on_text_edit) + self.Bind(wx.EVT_TEXT_ENTER, self.on_text_edit) + self.ignore_text_event = False + self.delete_key = False + self.found_choice = False + self.parent = parent + + def update_choices(self, choices): + self.choices = choices + + def on_button_down(self, event): + if event.GetKeyCode() == 8: + self.delete_key = True + event.Skip() + + def on_text_edit(self, event): + current_text = event.GetString() + if len(current_text) == 0 or current_text == " ": + self.delete_key = False + self.parent.on_combobox_change(event) + return + if self.ignore_text_event: + self.ignore_text_event = False + return + if self.delete_key: + self.delete_key = False + if self.found_choice: + current_text = current_text[:-1] + + self.found_choice = False + for i, choice in enumerate(self.choices): + if choice.startswith(current_text.strip()): + self.ignore_text_event = True + self.SetValue(choice) + self.SetInsertionPoint(len(current_text)) + self.SetTextSelection(len(current_text), len(choice)) + self.found_choice = True + self.parent.on_combobox_change(event) + break |
