Skip to content

Commit

Permalink
Find linked files by typing in project list
Browse files Browse the repository at this point in the history
  • Loading branch information
octimot committed Feb 22, 2024
1 parent e4969d0 commit 57df89d
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 6 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ clip @ git+https://github.com/openai/CLIP.git@a9b1bf5920416aaeaec965c25dd9e8f98c
opencv-python
patchify
darkdetect
customtkinter @ git+https://github.com/octimot/CustomTkinter.git@32dacb3200534656a755ec8218b2725fa01b699f
customtkinter @ git+https://github.com/octimot/CustomTkinter.git@a2a8c37dd8dac1dee30133476596a5128adb0530
ftfy
moviepy
scikit-image
Expand Down
83 changes: 78 additions & 5 deletions storytoolkitai/ui/toolkit_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2739,7 +2739,6 @@ def open_on_click(event, path):

has_video.grid(row=0, column=3, sticky='e', **self.ctk_small_label_paddings)


# add on_click event
file_frame.bind(
'<Button-1>',
Expand Down Expand Up @@ -2780,12 +2779,19 @@ def open_on_click(event, path):
self._project_file_context_menu(e, l_item)
)

# add a reference to the label for easier access
setattr(file_frame, 'label', file_name)

# add the project to the grid
file_frame.grid(row=row_num, column=0, sticky='ew', **self.ctk_form_paddings)

file_frame.grid_columnconfigure(0, weight=1)

# expand project frames on the x axis
# add the find_name to the file_frame as an attribute
# - this will help us find files by their name
setattr(file_frame, 'find_name', file_name_var.get())

# expand project frames on the x-axis
main_window.middle_frame.grid_columnconfigure(0, weight=1)

# show the middle frame
Expand All @@ -2798,6 +2804,26 @@ def open_on_click(event, path):
# make window resizable
self.root.resizable(True, True)

def memorize_file_frame_positions():

# ensure the layout is updated
main_window.update_idletasks()

main_window.find_file_frame_positions = {}

# iterate through all children of main_window.middle_frame
for child in main_window.middle_frame.winfo_children():

# assuming all children are placed using the grid manager
child_x = child.winfo_x()
child_y = child.winfo_y()

# memorize the position of the child
main_window.find_file_frame_positions[child.find_name] = (child_x, child_y, child)

# schedule the report_file_frame_positions function to execute 50ms after the window is shown
main_window.after(50, memorize_file_frame_positions)

else:
# hide the middle frame
main_window.middle_frame.grid_remove()
Expand Down Expand Up @@ -3043,9 +3069,12 @@ def change_project_wrapper(project_name):
main_window.bind("<Button-2>", lambda event: self._focused_window('main'))
main_window.bind("<Button-3>", lambda event: self._focused_window('main'))

# add key bindings to the main window
# key t for the transcription window
main_window.bind("t", lambda event: self.button_ingest())
# capture any single key with the find_file_or_project feature
main_window.bind("<Key>", lambda event: self.find_file_or_project(event))

# we use these for the find function in the main window
main_window._search_string = ''
main_window._last_key_press = None

# load menubar items
self.main_menu.load_menubar()
Expand All @@ -3055,6 +3084,50 @@ def change_project_wrapper(project_name):

return

def find_file_or_project(self, event):
"""
This function is called when a key is pressed in the main window.
"""

# we need the main window
main_window = self.windows['main']

# abort if the main window doesn't have the find_file_frame_positions attribute
if not hasattr(main_window, 'find_file_frame_positions'):
return

# if the key is a letter or a number, add it to the search string
if not event.char.isalnum() and event.char not in ['.', ' ']:

# reset the search string
main_window._last_key_press = None
main_window._search_string = ''
return

# if the last key press was less than 0.8 seconds ago, add the key to the search string
if main_window._last_key_press is not None and time.time() - main_window._last_key_press < 0.8:
main_window._search_string += event.char

# otherwise reset the search string
else:
main_window._search_string = event.char

# set the last key press time
main_window._last_key_press = time.time()

# get the first item on the main window that starts with the search string
# use main_window.find_file_frame_positions to find the closest item to the search string
for name in main_window.find_file_frame_positions:

if main_window._search_string.lower() in name.lower().strip():

# get the position of the frame
x, y, child = main_window.find_file_frame_positions[name]

main_window.middle_frame.scroll_to_y(y_pos=y)

break

def create_new_project(self, project_name=None):
"""
This function creates a project
Expand Down

0 comments on commit 57df89d

Please sign in to comment.