def __init__(self, master, text_widget): self.text_widget = text_widget self.go_to_master = Toplevel(master) self.go_to_master.transient(master) self.go_to_master.grab_set() self.go_to_master.withdraw() self.go_to_master.after(0, self.go_to_master.deiconify) self.go_to_master.title('Go To Line') self.go_to_master.iconbitmap( include.resource_path('included_files\\transparent.ico')) pos_x, pos_y = master.winfo_x() + 55, master.winfo_y() + 170 self.go_to_master.geometry('{}x{}+{}+{}'.format( 250, 100, pos_x, pos_y)) self.go_to_master.focus_set() self.go_to_label_entry_frame = Frame(self.go_to_master) self.go_to_label = ttk.Label(self.go_to_label_entry_frame, text='Line Number:') self.go_to_entry = ttk.Entry(self.go_to_label_entry_frame, width=37) self.go_to_label.grid(row=0, column=0, sticky='w') self.go_to_entry.grid(row=1, column=0) self.go_to_entry.focus_set() self.go_to_label_entry_frame.place(x=10, y=7) self.buttons_frame = Frame(self.go_to_master) self.go_to_button = ttk.Button(self.buttons_frame, text='Go To', width=10, command=self.go_to) self.cancel_button = ttk.Button(self.buttons_frame, text='Cancel', width=10, command=self.go_to_master.destroy) self.go_to_button.grid(row=0, column=0, padx=8) self.cancel_button.grid(row=0, column=1) self.buttons_frame.place(x=80, y=65) self.shortcut = shortcut.ShortCut(self.go_to_master) self.go_to_entry.bind('<Control-h>', self.entry_bind) self.go_to_button.bind( '<Enter>', lambda e: self.shortcut.show_shortcut( self.go_to_button, 'Enter', True)) self.go_to_button.bind('<Leave>', lambda e: self.shortcut.destroy()) self.cancel_button.bind( '<Enter>', lambda e: self.shortcut.show_shortcut( self.cancel_button, 'Esc', True)) self.cancel_button.bind('<Leave>', lambda e: self.shortcut.destroy()) self.go_to_master.bind('<Return>', self.go_to) self.go_to_master.bind('<Escape>', lambda e: self.go_to_master.destroy()) self.go_to_master.mainloop()
def __init__(self, master, text_widget): self.changed = False self.find_index = None self.word_indexes = [] self.direction_var, self.match_case_var, self.wrap_around_var = IntVar( ), IntVar(), IntVar() self.master = master self.text_widget = text_widget self.transparent_ico = include.resource_path( 'included_files\\transparent.ico') self.find_master = Toplevel() self.find_master.transient(self.master) self.find_master.grab_set() self.dummy_text_widget = Text(self.find_master) self.find_master.withdraw() self.find_master.after(0, self.find_master.deiconify) self.find_master.title('Find') self.find_master.iconbitmap(self.transparent_ico) self.pos_x, self.pos_y = self.master.winfo_x( ) + 55, self.master.winfo_y() + 170 self.find_master.geometry('{}x{}+{}+{}'.format(355, 123, self.pos_x, self.pos_y)) self.find_master.resizable(0, 0) self.label_entry_frame = Frame(self.find_master) self.buttons_frame = Frame(self.find_master) self.find_what_label = ttk.Label(self.label_entry_frame, text='Find what:') self.find_what_entry = ttk.Entry(self.label_entry_frame, width=34) self.find_what_label.grid(row=0, column=0) self.find_what_entry.grid(row=0, column=1, padx=5) self.label_entry_frame.place(x=0, y=5) self.find_what_entry.focus_set() self.style = ttk.Style() self.style.configure('my.TButton', font=('Helvetica', 8)) self.find_next_button = ttk.Button(self.buttons_frame, text='Find Next', width=9, style='my.TButton', command=self.find) self.cancel_button = ttk.Button(self.buttons_frame, text='Cancel', width=9, style='my.TButton', command=self.exit) self.find_next_button.grid(row=0, column=0, ipadx=3) self.cancel_button.grid(row=1, column=0, pady=5, ipadx=3) self.buttons_frame.place(x=280, y=5) self.direction_var.set(2) self.ttk_label_frame = LabelFrame(self.find_master, text="Direction", padx=5, pady=5) self.up_radio_buttons = ttk.Radiobutton(self.ttk_label_frame, text='Up', takefocus=False, value=1, variable=self.direction_var) self.down_radio_buttons = ttk.Radiobutton(self.ttk_label_frame, text='Down', takefocus=False, value=2, variable=self.direction_var) self.up_radio_buttons.pack(side=LEFT) self.down_radio_buttons.pack(side=LEFT) self.ttk_label_frame.place(x=165, y=30) self.check_button_frame = Frame(self.find_master) self.match_case_check_button = ttk.Checkbutton( self.check_button_frame, text='Match case', variable=self.match_case_var, takefocus=False) self.wrap_around_case_check_button = ttk.Checkbutton( self.check_button_frame, text='Wrap around', variable=self.wrap_around_var, takefocus=False) self.match_case_check_button.pack(anchor='w') self.wrap_around_case_check_button.pack(anchor='w', pady=5) self.check_button_frame.place(x=5, y=70) self.shortcut = shortcut.ShortCut(self.find_master) self.find_next_button.bind( '<Enter>', lambda e: self.shortcut.show_shortcut(self.find_next_button, 'F3')) self.find_next_button.bind('<Leave>', lambda e: self.shortcut.destroy()) self.cancel_button.bind( '<Enter>', lambda e: self.shortcut.show_shortcut(self.cancel_button, 'ESC')) self.cancel_button.bind('<Leave>', lambda e: self.shortcut.destroy()) self.insert_selected_text() self.find_master.bind('<F3>', self.find) self.cancel_button.bind('<Return>', self.exit) self.find_next_button.bind('<Return>', self.find) self.find_master.protocol('WM_DELETE_WINDOW', self.exit) self.find_master.bind('<Escape>', self.exit) self.find_what_entry.bind('<Control-h>', self.entry_bind) self.find_master.mainloop()
def __init__(self, master, text_widget): self.find_index = None self.word_indexes = [] self.transparent_ico = include.resource_path( 'included_files\\transparent.ico') self.master = master self.text_widget = text_widget self.dummy_text_widget = Text(master) self.match_var, self.wrap_var = IntVar(), IntVar() self.wrap_var.set(1) self.replace_master = Toplevel() self.replace_master.grab_set() self.hide_show = include.hide_or_show_maximize_minimize( self.replace_master) # Hiding minimize and maximize button self.replace_master.after(0, self.hide_show.hide_minimize_maximize) self.replace_master.withdraw() self.replace_master.after(0, self.replace_master.deiconify) self.replace_master.title('Replace') self.replace_master.iconbitmap(self.transparent_ico) self.pos_x, self.pos_y = self.master.winfo_x( ) + 55, self.master.winfo_y() + 170 self.replace_master.geometry('{}x{}+{}+{}'.format( 350, 155, self.pos_x, self.pos_y)) self.replace_master.resizable(0, 0) self.find_what_frame = Frame(self.replace_master) self.find_what_label = ttk.Label(self.find_what_frame, text='Find what:') self.replace_find_what_entry = ttk.Entry(self.find_what_frame, width=31) self.find_what_label.grid(row=0, column=0) self.replace_find_what_entry.focus_set() self.replace_find_what_entry.grid(row=0, column=1, padx=18) self.find_what_frame.place(x=0, y=5) self.replace_with_frame = Frame(self.replace_master) self.replace_with_label = ttk.Label(self.replace_with_frame, text='Replace what:') self.replace_with_entry = ttk.Entry(self.replace_with_frame, width=31) self.replace_with_label.grid(row=0, column=0) self.replace_with_entry.grid(row=0, column=1, pady=5) self.replace_with_frame.place(x=0, y=30) self.buttons_frame = Frame(self.replace_master) self.style = ttk.Style() self.style.configure('my.TButton', font=('Helvetica', 8)) self.find_next_button = ttk.Button(self.buttons_frame, text='Find Next', width=9, style='my.TButton', command=self.find_next) self.replace_button = ttk.Button(self.buttons_frame, text='Replace', width=9, style='my.TButton', command=self.replace) self.replace_all_button = ttk.Button(self.buttons_frame, text='Replace All', width=9, style='my.TButton', command=self.replace_all) self.cancel_button = ttk.Button(self.buttons_frame, text='Cancel', width=9, style='my.TButton', command=self.exit) self.find_next_button.grid(row=0, column=0, ipadx=3) self.replace_button.grid(row=1, column=0, ipadx=3, pady=5) self.replace_all_button.grid(row=2, column=0, ipadx=3) self.cancel_button.grid(row=3, column=0, ipadx=3, pady=5) self.buttons_frame.place(x=275, y=5) self.check_button_frame = Frame(self.replace_master) self.match_case_checkbutton = ttk.Checkbutton(self.check_button_frame, text='Match case', variable=self.match_var, takefocus=False) self.wrap_around_case_checkbutton = ttk.Checkbutton( self.check_button_frame, text='Wrap around', variable=self.wrap_var, takefocus=False) self.match_case_checkbutton.pack(anchor='w') self.wrap_around_case_checkbutton.pack(anchor='w', pady=5) self.check_button_frame.place(x=5, y=100) self.shortcut = shortcut.ShortCut(self.replace_master) self.find_next_button.bind( '<Enter>', lambda e: self.shortcut.show_shortcut(self.find_next_button, 'F3')) self.find_next_button.bind('<Leave>', lambda e: self.shortcut.destroy()) self.replace_button.bind( '<Enter>', lambda e: self.shortcut.show_shortcut( self.replace_button, 'Ctrl+Shift+H')) self.replace_button.bind('<Leave>', lambda e: self.shortcut.destroy()) self.replace_all_button.bind( '<Enter>', lambda e: self.shortcut.show_shortcut( self.replace_all_button, 'Ctrl+Alt+Enter')) self.replace_all_button.bind('<Leave>', lambda e: self.shortcut.destroy()) self.cancel_button.bind( '<Enter>', lambda e: self.shortcut.show_shortcut(self.cancel_button, 'Esc')) self.cancel_button.bind('<Leave>', lambda e: self.shortcut.destroy()) self.insert_selected_text() self.replace_master.bind('<Control-Alt-Return>', self.replace_all) self.replace_master.bind('<Control-H>', self.replace) self.replace_master.bind('<Escape>', self.exit) self.replace_with_entry.bind('<Control-h>', self.entry_bind) self.replace_find_what_entry.bind('<Control-h>', self.entry_bind) self.find_next_button.bind('<Return>', self.find_next) self.replace_button.bind('<Return>', self.replace) self.replace_all_button.bind('<Return>', self.replace_all) self.cancel_button.bind('<Return>', self.exit) self.replace_master.protocol('WM_DELETE_WINDOW', self.exit) self.replace_master.mainloop()