示例#1
0
 def test_init_sets_tktype(self):
     "Test that _init_tk_type sets _tk_type according to platform."
     for root in (None, self.root):
         with self.subTest(root=root):
             macosx._tk_type == None
             macosx._init_tk_type(root)
             self.assertIn(macosx._tk_type, mactypes if MAC else nontypes)
示例#2
0
 def test_init_sets_tktype(self):
     "Test that _init_tk_type sets _tk_type according to platform."
     for platform, types in ('darwin', alltypes), ('other', nontypes):
         with self.subTest(platform=platform):
             macosx.platform = platform
             macosx._tk_type == None
             macosx._init_tk_type()
             self.assertIn(macosx._tk_type, types)
示例#3
0
 def test_init_sets_tktype(self):
     "Test that _init_tk_type sets _tk_type according to platform."
     for platform, types in ('darwin', alltypes), ('other', nontypes):
         with self.subTest(platform=platform):
             macosx.platform = platform
             macosx._tk_type == None
             macosx._init_tk_type()
             self.assertIn(macosx._tk_type, types)
示例#4
0
 def test_init_sets_tktype(self):
     "Test that _init_tk_type sets _tk_type according to platform."
     for root in (None, self.root):
         with self.subTest(root=root):
             macosx._tk_type == None
             macosx._init_tk_type(root)
             self.assertIn(macosx._tk_type,
                           mactypes if MAC else nontypes)
示例#5
0
    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)
		# Changes for Python 3.6
		# The library macosxSupport was changed to macosx
		# _initializeTkVariantTests was changed to _init_tk_type
        if hasattr(macosx, "_init_tk_type") and macosx._tk_type is None:
            macosx._init_tk_type()

        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)  # TODO: huh?
示例#6
0
文件: htest.py 项目: dsedivec/cpython
def run(*tests):
    root = tk.Tk()
    root.title('IDLE htest')
    root.resizable(0, 0)
    _init_tk_type(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()
示例#7
0
文件: htest.py 项目: hemio-ev/cpython
def run(*tests):
    root = tk.Tk()
    root.title('IDLE htest')
    root.resizable(0, 0)
    _init_tk_type(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 = 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()