From 3b650fad615d8e5a30e8d4bfa268fd2b291a2802 Mon Sep 17 00:00:00 2001 From: Nenotriple <70049990+Nenotriple@users.noreply.github.com> Date: Mon, 27 Nov 2023 04:31:05 -0800 Subject: [PATCH] Cursor position changes after inserting a suggestion A space character is now inserted after positioning the cursor. This brings the cursor position "out in the open", so now it's faster to keep typing another tag. + Some minor code formatting changes to help organize things. --- img-txt_viewer.pyw | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/img-txt_viewer.pyw b/img-txt_viewer.pyw index 63103ee..7496b8c 100644 --- a/img-txt_viewer.pyw +++ b/img-txt_viewer.pyw @@ -237,13 +237,9 @@ class ImgTxtViewer: def __init__(self, master): self.master = master - # Used to create a new ID separate from Python to properly set the app icon. - myappid = 'ImgTxtViewer.Nenotriple' - ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid) - # Window settings - master.minsize(965, 300) # Width x Height - master.geometry("1290x645") + self.set_appid() + self.set_window_size(master) self.set_icon() # Variables @@ -715,6 +711,7 @@ class ImgTxtViewer: else: offset = len(selected_suggestion) + 1 self.text_box.mark_set("insert", "{}+{}c".format(start_of_current_word, offset)) + self.text_box.insert("insert", " ") def insert_newline_listmode(self, event=None, called_from_insert=False): if self.list_mode.get(): @@ -1458,13 +1455,13 @@ class ImgTxtViewer: if messagebox.askokcancel("Warning", "This will move the img-txt pair to a local trash folder.\n\nThe trash folder will be created in the selected directory."): trash_dir = os.path.join(os.path.dirname(self.image_files[self.current_index]), "Trash") os.makedirs(trash_dir, exist_ok=True) - os.rename(self.image_files[self.current_index], os.path.join(trash_dir, os.path.basename(self.image_files[self.current_index]))) - os.rename(self.text_files[self.current_index], os.path.join(trash_dir, os.path.basename(self.text_files[self.current_index]))) - del self.image_files[self.current_index] - del self.text_files[self.current_index] + for file_list in [self.image_files, self.text_files]: + os.rename(file_list[self.current_index], os.path.join(trash_dir, os.path.basename(file_list[self.current_index]))) + del file_list[self.current_index] self.total_images_label.config(text=f"/{len(self.image_files)}") self.show_pair() + #endregion ################################################################################################################################################ ################################################################################################################################################ @@ -1472,6 +1469,14 @@ class ImgTxtViewer: #region - Framework # # # + def set_appid(self): + myappid = 'ImgTxtViewer.Nenotriple' + ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid) + + def set_window_size(self, master): + master.minsize(965, 300) # Width x Height + master.geometry("1290x645") + root = Tk() app = ImgTxtViewer(root) app.toggle_always_on_top() @@ -1507,6 +1512,7 @@ root.mainloop() - Fix autosave for first and last index navigation. - List mode: The cursor is now placed at the end of the text file on a newline when navigating between pairs. - App icon now displays properly in the taskbar. + - Further improvements to cursor positioning after inserting a suggestion. '''