def __init__(self, menu_delegate, editor_delegate, flist=None, root=None, filename=None, online=False): # Support for Python >= 2.7.7 (TODO find a better way) if hasattr(macosxSupport, "_initializeTkVariantTests") and macosxSupport._tk_type is None: macosxSupport._initializeTkVariantTests(root) super().__init__(root=root, filename=filename) self.io = TutorIOBinding(self) self.io.set_filename_change_hook(self.filename_change_hook) assert isinstance(menu_delegate, TutorialMenuDelegate) self.menu_delegate = menu_delegate assert isinstance(editor_delegate, TutorEditorDelegate) self.editor_delegate = editor_delegate self.root = root # TODO: previously, a number of these events broke out of the event # TODO: loop, by returning 'break' # TODO: this has been removed; if bugs appear, that's probably why noevt = lambda f: lambda e=None: f() self.text.bind("<<load-from>>", self.load_from) self.text.bind("<<revert>>", self.revert) self.text.bind("<<check>>", noevt(editor_delegate.check_solution)) self.text.bind("<<login>>", noevt(menu_delegate.login)) self.text.bind("<<logout>>", noevt(menu_delegate.logout)) self.text.bind("<<submit_answer>>", noevt(menu_delegate.submit)) self.text.bind("<<show_submit>>", noevt(menu_delegate.show_submissions)) self.text.bind("<<sync_solutions>>", noevt(menu_delegate.synchronise)) self.text.bind("<<about-tutor>>", noevt(menu_delegate.show_about_dialog)) self.text.bind("<<help-tutor>>", noevt(menu_delegate.show_help_dialog)) # it's less than ideal to have to bind these here, but it's proved to # be the safest approach in practice # ideally, we'd just .bind_all on tk.Tk, and capture and 'break' all # key bindings here, but that seems to interfere with idlelib; it # doesn't grab all the bindings as it should # my best guess (without wishing to delve too deeply) is that something # other than self.text is doing some of the event handling # anyway, we hard-code these bindings here :( self.text.bind("<F5>", noevt(editor_delegate.check_solution)) self.text.bind("<F6>", noevt(menu_delegate.submit)) self.text.config(font=FIXED_FONT) self.text.tag_config("orange", background="orange") self.tutorial = None self.menudict['file'].delete(0, 1) # TODO: huh?
def __init__(self, menu_delegate, editor_delegate, flist=None, root=None, filename=None, online=False): # Support for Python >= 2.7.7 (TODO find a better way) if hasattr(macosxSupport, "_initializeTkVariantTests") and macosxSupport._tk_type is None: macosxSupport._initializeTkVariantTests(root) super().__init__(root=root, filename=filename) self.io = TutorIOBinding(self) self.io.set_filename_change_hook(self.filename_change_hook) assert isinstance(menu_delegate, TutorialMenuDelegate) self.menu_delegate = menu_delegate assert isinstance(editor_delegate, TutorEditorDelegate) self.editor_delegate = editor_delegate self.root = root # TODO: previously, a number of these events broke out of the event # TODO: loop, by returning 'break' # TODO: this has been removed; if bugs appear, that's probably why noevt = lambda f: lambda e=None: f() self.text.bind("<<load-from>>", self.load_from) self.text.bind("<<revert>>", self.revert) self.text.bind("<<check>>", noevt(editor_delegate.check_solution)) self.text.bind("<<login>>", noevt(menu_delegate.login)) self.text.bind("<<logout>>", noevt(menu_delegate.logout)) self.text.bind("<<submit_answer>>", noevt(menu_delegate.submit)) self.text.bind("<<show_submit>>", noevt(menu_delegate.show_submissions)) self.text.bind("<<sync_solutions>>", noevt(menu_delegate.synchronise)) self.text.bind("<<about-tutor>>", noevt(menu_delegate.show_about_dialog)) self.text.bind("<<help-tutor>>", noevt(menu_delegate.show_help_dialog)) # it's less than ideal to have to bind these here, but it's proved to # be the safest approach in practice # ideally, we'd just .bind_all on tk.Tk, and capture and 'break' all # key bindings here, but that seems to interfere with idlelib; it # doesn't grab all the bindings as it should # my best guess (without wishing to delve too deeply) is that something # other than self.text is doing some of the event handling # anyway, we hard-code these bindings here :( self.text.bind("<F5>", noevt(editor_delegate.check_solution)) self.text.bind("<F6>", noevt(menu_delegate.submit)) self.text.tag_config("orange", background="orange") self.tutorial = None self.menudict['file'].delete(0, 1) # TODO: huh?
def __init__(self, parent, flist=None, root=None, filename=None, online=False): # Support for Python >= 2.7.7 (TODO find a better way) if hasattr(macosxSupport, "_initializeTkVariantTests" ) and macosxSupport._tk_type is None: macosxSupport._initializeTkVariantTests(root) tut_bindings.initialise() if online: self.menu_specs.insert(4, ("online", "_Online")) EditorWindow.EditorWindow.__init__( self, # flist = flist, root=root, filename=filename) self.io = io = tut_iobinding.TutorIOBinding(self) io.set_filename_change_hook(self.filename_change_hook) self.parent = parent self.root = root self.fill_menus(menudefs=tut_bindings.menudefs ) # ,keydefs={'<F5>':self.check_event}) #self.load_extensions() self.text.bind("<<load-from>>", self.load_from_event) self.text.bind("<<revert>>", self.revert_event) self.text.bind("<<check>>", self.check_event) self.text.bind("<<about-tutor>>", self.about) self.text.bind("<<help-tutor>>", self.help) self.text.bind("<F5>", self.check_event) self.text.bind("<F6>", self.submit_answer_event) if online: self.text.bind("<<login>>", self.login_event) self.text.bind("<<logout>>", self.logout_event) self.text.bind("<<change_password>>", self.change_password_event) self.text.bind("<<upload_answer>>", self.upload_answer_event) self.text.bind("<<download_answer>>", self.download_answer_event) self.text.bind("<<submit_answer>>", self.submit_answer_event) self.text.bind("<<show_submit>>", self.show_submit_event) self.text.tag_config("orange", background="orange") self.filename = '' self.dirname = '' self.opendialog = None self.menudict['file'].delete(0, 1) #self.top = top = WindowList.ListedToplevel(root, menu=self.menubar) #self.set_close_hook(self.quit) self.top.protocol("WM_DELETE_WINDOW", self.close_event)
def __init__(self, parent, flist=None, root=None, filename=None, online=False): # Support for Python >= 2.7.7 (TODO find a better way) if hasattr(macosxSupport, "_initializeTkVariantTests") and macosxSupport._tk_type is None: macosxSupport._initializeTkVariantTests(root) tut_bindings.initialise() if online: self.menu_specs.insert(4, ("online", "_Online")) EditorWindow.EditorWindow.__init__(self, # flist = flist, root=root, filename=filename) self.io = io = tut_iobinding.TutorIOBinding(self) io.set_filename_change_hook(self.filename_change_hook) self.parent = parent self.root = root self.fill_menus(menudefs=tut_bindings.menudefs) # ,keydefs={'<F5>':self.check_event}) #self.load_extensions() self.text.bind("<<load-from>>", self.load_from_event) self.text.bind("<<revert>>", self.revert_event) self.text.bind("<<check>>", self.check_event) self.text.bind("<<about-tutor>>", self.about) self.text.bind("<<help-tutor>>", self.help) self.text.bind("<F5>", self.check_event) self.text.bind("<F6>", self.submit_answer_event) if online: self.text.bind("<<login>>", self.login_event) self.text.bind("<<logout>>", self.logout_event) self.text.bind("<<change_password>>", self.change_password_event) self.text.bind("<<upload_answer>>", self.upload_answer_event) self.text.bind("<<download_answer>>", self.download_answer_event) self.text.bind("<<submit_answer>>", self.submit_answer_event) self.text.bind("<<show_submit>>", self.show_submit_event) self.text.tag_config("orange", background="orange") self.filename = '' self.dirname = '' self.opendialog = None self.menudict['file'].delete(0, 1) #self.top = top = WindowList.ListedToplevel(root, menu=self.menubar) #self.set_close_hook(self.quit) self.top.protocol("WM_DELETE_WINDOW", self.close_event)
def __init__(self, parent, root, save_method=None): # Support for Python >= 2.7.7 (TODO find a better way) if hasattr(macosxSupport, "_initializeTkVariantTests") and macosxSupport._tk_type is None: macosxSupport._initializeTkVariantTests(root) ProblemBindings.initialise() FileList.FileList(self) self.title = None EditorWindow.EditorWindow.__init__(self, root=root) self.io = io = ProblemIOBinding.ProblemIOBinding(self) io.set_filename_change_hook(self.filename_change_hook) self.save_method = save_method self.parent = parent self.root = root self.menubar.entryconfig(1, state=DISABLED) self.fill_menus(menudefs=ProblemBindings.menudefs, keydefs={}) self.text.tag_config("orange", background="orange") self.filename = '' self.dirname = '' self.opendialog = None self.top.protocol("WM_DELETE_WINDOW", self.close_event)
def __init__(self, parent, root, save_method=None): # Support for Python >= 2.7.7 (TODO find a better way) if hasattr(macosxSupport, "_initializeTkVariantTests" ) and macosxSupport._tk_type is None: macosxSupport._initializeTkVariantTests(root) ProblemBindings.initialise() FileList.FileList(self) self.title = None EditorWindow.EditorWindow.__init__(self, root=root) self.io = io = ProblemIOBinding.ProblemIOBinding(self) io.set_filename_change_hook(self.filename_change_hook) self.save_method = save_method self.parent = parent self.root = root self.menubar.entryconfig(1, state=DISABLED) self.fill_menus(menudefs=ProblemBindings.menudefs, keydefs={}) self.text.tag_config("orange", background="orange") self.filename = '' self.dirname = '' self.opendialog = None self.top.protocol("WM_DELETE_WINDOW", self.close_event)
def setUpClass(cls): requires('gui') cls.root = Tk() cls.root.withdraw() _initializeTkVariantTests(cls.root)
def run(*tests): root = tk.Tk() root.title('IDLE htest') root.resizable(0, 0) _initializeTkVariantTests(root) # a scrollable Label like constant width text widget. frameLabel = tk.Frame(root, padx=10) frameLabel.pack() text = tk.Text(frameLabel, wrap='word') text.configure(bg=root.cget('bg'), relief='flat', height=4, width=70) scrollbar = tk.Scrollbar(frameLabel, command=text.yview) text.config(yscrollcommand=scrollbar.set) scrollbar.pack(side='right', fill='y', expand=False) text.pack(side='left', fill='both', expand=True) test_list = [] # List of tuples of the form (spec, callable widget) if tests: for test in tests: test_spec = globals()[test.__name__ + '_spec'] test_spec['name'] = test.__name__ test_list.append((test_spec, test)) else: for k, d in globals().items(): if k.endswith('_spec'): test_name = k[:-5] test_spec = d test_spec['name'] = test_name mod = import_module('idlelib.' + test_spec['file']) test = getattr(mod, test_name) test_list.append((test_spec, test)) test_name = tk.StringVar('') callable_object = None test_kwds = None def next(): nonlocal test_name, callable_object, test_kwds if len(test_list) == 1: next_button.pack_forget() test_spec, callable_object = test_list.pop() test_kwds = test_spec['kwds'] test_kwds['parent'] = root test_name.set('Test ' + test_spec['name']) text.configure(state='normal') # enable text editing text.delete('1.0','end') text.insert("1.0",test_spec['msg']) text.configure(state='disabled') # preserve read-only property def run_test(): widget = callable_object(**test_kwds) try: print(widget.result) except AttributeError: pass button = tk.Button(root, textvariable=test_name, command=run_test) button.pack() next_button = tk.Button(root, text="Next", command=next) next_button.pack() next() root.mainloop()
def setUpClass(cls): requires('gui') cls.root = Tk() _initializeTkVariantTests(cls.root)
def setUpClass(cls): cls.root = Tk() cls.root.withdraw() macosx._initializeTkVariantTests(cls.root)
def run(*tests): root = tk.Tk() root.title('IDLE htest') root.resizable(0, 0) _initializeTkVariantTests(root) # a scrollable Label like constant width text widget. frameLabel = tk.Frame(root, padx=10) frameLabel.pack() text = tk.Text(frameLabel, wrap='word') text.configure(bg=root.cget('bg'), relief='flat', height=4, width=70) scrollbar = tk.Scrollbar(frameLabel, command=text.yview) text.config(yscrollcommand=scrollbar.set) scrollbar.pack(side='right', fill='y', expand=False) text.pack(side='left', fill='both', expand=True) test_list = [] # List of tuples of the form (spec, callable widget) if tests: for test in tests: test_spec = globals()[test.__name__ + '_spec'] test_spec['name'] = test.__name__ test_list.append((test_spec, test)) else: for k, d in globals().items(): if k.endswith('_spec'): test_name = k[:-5] test_spec = d test_spec['name'] = test_name mod = import_module('idlelib.' + test_spec['file']) test = getattr(mod, test_name) test_list.append((test_spec, test)) test_name = [tk.StringVar('')] callable_object = [None] test_kwds = [None] def next(): if len(test_list) == 1: next_button.pack_forget() test_spec, callable_object[0] = test_list.pop() test_kwds[0] = test_spec['kwds'] test_kwds[0]['parent'] = root test_name[0].set('Test ' + test_spec['name']) text.configure(state='normal') # enable text editing text.delete('1.0', 'end') text.insert("1.0", test_spec['msg']) text.configure(state='disabled') # preserve read-only property def run_test(): widget = callable_object[0](**test_kwds[0]) try: print(widget.result) except AttributeError: pass button = tk.Button(root, textvariable=test_name[0], command=run_test) button.pack() next_button = tk.Button(root, text="Next", command=next) next_button.pack() next() root.mainloop()
def run(*tests): root = tk.Tk() root.title("IDLE htest") root.resizable(0, 0) _initializeTkVariantTests(root) # a scrollable Label like constant width text widget. frameLabel = tk.Frame(root, padx=10) frameLabel.pack() text = tk.Text(frameLabel, wrap="word") text.configure(bg=root.cget("bg"), relief="flat", height=4, width=70) scrollbar = tk.Scrollbar(frameLabel, command=text.yview) text.config(yscrollcommand=scrollbar.set) scrollbar.pack(side="right", fill="y", expand=False) text.pack(side="left", fill="both", expand=True) test_list = [] # List of tuples of the form (spec, callable widget) if tests: for test in tests: test_spec = globals()[test.__name__ + "_spec"] test_spec["name"] = test.__name__ test_list.append((test_spec, test)) else: for k, d in globals().items(): if k.endswith("_spec"): test_name = k[:-5] test_spec = d test_spec["name"] = test_name mod = import_module("idlelib." + test_spec["file"]) test = getattr(mod, test_name) test_list.append((test_spec, test)) test_name = tk.StringVar("") callable_object = None test_kwds = None def next(): nonlocal test_name, callable_object, test_kwds if len(test_list) == 1: next_button.pack_forget() test_spec, callable_object = test_list.pop() test_kwds = test_spec["kwds"] test_kwds["parent"] = root test_name.set("Test " + test_spec["name"]) text.configure(state="normal") # enable text editing text.delete("1.0", "end") text.insert("1.0", test_spec["msg"]) text.configure(state="disabled") # preserve read-only property def run_test(): widget = callable_object(**test_kwds) try: print(widget.result) except AttributeError: pass button = tk.Button(root, textvariable=test_name, command=run_test) button.pack() next_button = tk.Button(root, text="Next", command=next) next_button.pack() next() root.mainloop()
def __init__(self, *args, **kw): tk.Tk.__init__(self, *args, **kw) macosxSupport._initializeTkVariantTests(self) self.title('Password Manager') self.database = Database(self.password_file) self.paned_window = tk.PanedWindow(self) self.paned_window.pack(fill= tk.BOTH, expand = True) self.password_list_frame = tk.Frame(self.paned_window) self.paned_window.add(self.password_list_frame) self.password_list = ScrolledList.ScrolledList(self.password_list_frame) self.password_list.fill_menu = self.fill_menu self.password_list.on_select = self.on_select self.password_list.on_double = self.on_double self.last_pressed_variable = tk.StringVar(master = self) self.choose_list_entry = None self.subset_removal_after_id = None self.password_list.listbox.bind('<Any-KeyPress>', self.select_by_letter) self.password_list.listbox.bind('<Return>', self.copy_current_password_to_clipboard) self.selected_count = 0 self.info_frame = info_frame = tk.Frame(self.paned_window) self.paned_window.add(self.info_frame) self.name_frame = tk.Frame(info_frame) self.name_frame.pack(fill = tk.X) self.entry_name_entry = tk.Entry(self.name_frame) self.entry_name_entry.pack(fill = tk.X, side = tk.LEFT, expand = True) self.save_info_button = tk.Button(self.name_frame, text = "save", command = self.save_info) self.save_info_button.pack(side = tk.LEFT) self.entry_text = tk.Text(info_frame, height = 1, width = 30) self.entry_text.pack(fill = tk.BOTH, expand = True) self.entry_show_password_frame = tk.Frame(info_frame) self.entry_show_password_frame.pack(fill = tk.X) self.entry_toggle_password_frame = tk.Frame(self.entry_show_password_frame) self.entry_toggle_password_frame.pack(fill = tk.BOTH, side = tk.LEFT, expand = True) self.entry_password_button = tk.Button(self.entry_toggle_password_frame, text = 'show password') self.entry_password_entry = tk.Entry(self.entry_toggle_password_frame) def enter(event = None): self.entry_password_entry.selection_range(0, tk.END) self.entry_password_entry.bind('<FocusIn>', enter) self.entry_password_entry.pack(fill = tk.X, expand = True, side = tk.LEFT) self.entry_new_password = tk.Button(self.entry_show_password_frame, text = 'new', command = self.replace_password) self.entry_new_password.pack(side = tk.RIGHT) self.show_deleted_entries = tk.BooleanVar(self) self.show_deleted_entries.set(False) self.bind('<Control-n>', self.new_password) self.bind('<Double-Escape>', self.minimize) self.bind('<KeyPress-Escape>', self.reset_last_pressed) self.database_updated() self.hide_password() self.reset_last_pressed() self.select(0)