Skip to content

Commit

Permalink
Improved click_bind and key_bind functinos
Browse files Browse the repository at this point in the history
  • Loading branch information
ghanteyyy committed Jan 15, 2021
1 parent a2e36bd commit ad7efc5
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions PROJECT GUIs/ZPAD/select_font.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
class Bindings:
def __init__(self, master, frame):
self.master = master
self.click_bind_value = None
self.listbox = frame.listbox
self.entry_widget = frame.entry
self.entry_var = frame.entry_var
self.list_box_values = frame.values
self.click_bind()
self.listbox.bind('<<ListboxSelect>>', self.click_bind)

def key_bind(self, *args):
'''Filter the value in listbox as per given in entry widget'''
Expand All @@ -20,34 +19,27 @@ def key_bind(self, *args):
check_list = [value.lower() for value in self.list_box_values]
starting_value = [fv for fv in check_list if fv.startswith(var_get.lower())]

if len(starting_value) < 100:
index = check_list.index(starting_value[0])
self.listbox.yview(index)
index = check_list.index(starting_value[0])
self.listbox.see(index)

if var_get.lower() == starting_value[0].lower():
self.listbox.selection_set(index)
if var_get.lower() == starting_value[0].lower():
self.listbox.selection_set(index)

else:
now = self.listbox.curselection()
self.listbox.selection_clear(now[0])
else:
now = self.listbox.curselection()
self.listbox.selection_clear(now[0])

except IndexError:
pass

def click_bind(self):
def click_bind(self, event=None):
'''Insert value of selected text from the listbox in entry widget'''

now = self.listbox.curselection()
selection_index = self.listbox.curselection()[0]
data = self.listbox.get(selection_index)

if now != self.click_bind_value:
self.click_bind_value = now

if self.click_bind_value and self.listbox.get(self.click_bind_value[0]):
value = self.listbox.get(self.click_bind_value[0])
self.entry_var.set(value)
self.master.after(10, lambda: set_selection(self.entry_widget, self.entry_var))

self.master.after(10, self.click_bind)
self.entry_var.set(data)
self.master.after(10, lambda: set_selection(self.entry_widget, self.entry_var))


class Commands:
Expand Down

0 comments on commit ad7efc5

Please sign in to comment.