summaryrefslogtreecommitdiff
path: root/lib/gui/edit_json/combo_prompt.py
diff options
context:
space:
mode:
authorKaalleen <36401965+kaalleen@users.noreply.github.com>2025-02-12 16:58:26 +0100
committerGitHub <noreply@github.com>2025-02-12 16:58:26 +0100
commit9ac55934fa18748f84dd69e980cc370291a1976b (patch)
tree7979a38c6a6aea90fdc0bbbb7c156f2404d3f62b /lib/gui/edit_json/combo_prompt.py
parent81c1fd834f6e7da658f14f1ba695d79e694ff6bc (diff)
Edit-json: add kerning filter (#3499)
* edit-json: add kerning filter * fix missing kerning pairs
Diffstat (limited to 'lib/gui/edit_json/combo_prompt.py')
-rw-r--r--lib/gui/edit_json/combo_prompt.py49
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