<commit_before>from Tkinter import *

class Ask(Toplevel):
    def __init__(self, area, title, default_data ='', *args, **kwargs):
        self.area = area
        Toplevel.__init__(self, area, *args, **kwargs)

        # self.protocol("WM_DELETE_WINDOW", self.destroy())
        self.bind('<Escape>', lambda event: self.destroy())
        self.bind('<Return>', lambda event: self.ok())
        
        self.title(title)
        self.transient(area)
        self.resizable(width=False, height=False)
        self.frame = Frame(self, relief='raised', border=1,  padx=3, pady=3)
        
        self.entry = Entry(self.frame)

        self.frame.pack(side='top', expand=True, fill=BOTH)
        self.entry.pack(side='left', expand=True, fill=BOTH)

        self.entry.focus_set()

        # It seems that if i put self.data = default_data
        # after self.area.wait_window(self) it sets self.data
        # after it has being set in self.ok then i get
        # the insert mark being reset to insert again.

        self.entry.insert('end', default_data)
        self.data = default_data

        self.grab_set()
        self.area.wait_window(self)

    def ok(self):
        self.data = self.entry.get()
        self.destroy()
    
if __name__ == '__main__':
    area = Tk()
    search_dialog = Ask(area, 'Ask')
    area.mainloop()






<commit_msg>Adding a restore_focus_scheme functioin in Ask class.<commit_after>from Tkinter import *

class Ask(Toplevel):
    def __init__(self, area, title, default_data ='', *args, **kwargs):
        self.area = area
        Toplevel.__init__(self, area, *args, **kwargs)

        # self.protocol("WM_DELETE_WINDOW", self.destroy())
        self.bind('<Escape>', lambda event: self.restore_focus_scheme())
        self.bind('<Return>', lambda event: self.ok())
        
        self.title(title)
        self.transient(area)
        self.resizable(width=False, height=False)
        self.frame = Frame(self, relief='raised', border=1,  padx=3, pady=3)
        
        self.entry = Entry(self.frame)

        self.frame.pack(side='top', expand=True, fill=BOTH)
        self.entry.pack(side='left', expand=True, fill=BOTH)

        self.entry.focus_set()

        # It seems that if i put self.data = default_data
        # after self.area.wait_window(self) it sets self.data
        # after it has being set in self.ok then i get
        # the insert mark being reset to insert again.

        self.entry.insert('end', default_data)
        self.data = default_data

        self.grab_set()
        self.area.wait_window(self)

    def ok(self):
        self.data = self.entry.get()
        self.restore_focus_scheme()

    def restore_focus_scheme(self):
        self.area.focus_set()
        self.destroy()
            
if __name__ == '__main__':
    area = Tk()
    search_dialog = Ask(area, 'Ask')
    area.mainloop()








{'fraction_non_alphanumeric': 0.1297391304347826, 'fraction_numerical': 0.0020869565217391303, 'mean_word_length': 2.460890493381468, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4573034', 'n_tokens_mistral': 930, 'n_tokens_neox': 898, 'n_words': 206}