working search window
This commit is contained in:
parent
ad7754b38b
commit
90c44ff2a2
54
main.py
54
main.py
@ -14,6 +14,8 @@ image_label = None
|
||||
desc_label = None
|
||||
img = None
|
||||
fViewHelp = False
|
||||
fViewSearch = False
|
||||
current_select = None
|
||||
|
||||
|
||||
def load_config():
|
||||
@ -62,14 +64,59 @@ def key_pressed(event):
|
||||
if event.keysym == 'F4':
|
||||
update_record_window()
|
||||
|
||||
def search_window():
|
||||
global listbox, fViewSearch
|
||||
|
||||
def on_search():
|
||||
search_term = search_entry.get()
|
||||
listbox.delete(0, END)
|
||||
for item in original_list:
|
||||
if search_term.lower() in item.lower():
|
||||
listbox.insert(END, item)
|
||||
|
||||
|
||||
|
||||
def on_cancel():
|
||||
global fViewSearch
|
||||
search_window.destroy()
|
||||
listbox.delete(0, END)
|
||||
for item in original_list:
|
||||
listbox.insert(END, item)
|
||||
fViewSearch = False
|
||||
|
||||
if not fViewSearch:
|
||||
fViewSearch = True
|
||||
|
||||
search_window = Toplevel()
|
||||
|
||||
search_label = Label(search_window, text="Поиск: ")
|
||||
search_label.pack()
|
||||
|
||||
search_button = Button(search_window, text="Найти", command=on_search)
|
||||
search_button.pack()
|
||||
|
||||
original_list = listbox.get(0, END)
|
||||
|
||||
search_entry = Entry(search_window)
|
||||
search_entry.pack()
|
||||
|
||||
cancel_button = Button(search_window, text="Отмена", command=on_cancel)
|
||||
cancel_button.pack()
|
||||
search_window.protocol("WM_DELETE_WINDOW", on_cancel)
|
||||
|
||||
search_window.mainloop()
|
||||
|
||||
|
||||
def selected(event):
|
||||
global listbox, image_label, desc_label, img
|
||||
global listbox, image_label, desc_label, img, current_select
|
||||
selected_indices = listbox.curselection()
|
||||
selected = ''.join([listbox.get(i) for i in selected_indices])
|
||||
record = database.get_record_by_name(selected)
|
||||
if record != None and current_select != selected:
|
||||
current_select = selected
|
||||
img = ImageTk.PhotoImage(Image.open(io.BytesIO(record.img)))
|
||||
image_label.config(image=img)
|
||||
desc_label.delete(1.0, END)
|
||||
desc_label.insert(1.0, record.description)
|
||||
|
||||
|
||||
@ -188,7 +235,6 @@ def load_listbox():
|
||||
|
||||
def open_help_window():
|
||||
global fViewHelp
|
||||
print(fViewHelp)
|
||||
|
||||
def close_help():
|
||||
global fViewHelp
|
||||
@ -270,13 +316,13 @@ def main():
|
||||
main_menu = Menu()
|
||||
|
||||
fond_menu = Menu(tearoff=0)
|
||||
fond_menu.add_command(label="Найти...")
|
||||
fond_menu.add_command(label="Найти...", command=search_window)
|
||||
fond_menu.add_separator()
|
||||
fond_menu.add_command(label="Добавить", accelerator="F2", command=add_record_window)
|
||||
fond_menu.add_command(label="Удалить", accelerator="F3", command=confirm_delete)
|
||||
fond_menu.add_command(label="Изменить", accelerator="F4", command=update_record_window)
|
||||
fond_menu.add_separator()
|
||||
fond_menu.add_command(label="Выход", accelerator="ctrl+X", command=close_prog)
|
||||
fond_menu.add_command(label="Выход", accelerator="Ctrl+X", command=close_prog)
|
||||
|
||||
help_menu = Menu(tearoff=0)
|
||||
help_menu.add_command(label="Содержание", command=open_help_window)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user