Beispiel #1
0
def test_tabtypes(porcusession, tabmanager, action_path):
    tab1 = Tab1(tabmanager)
    tab2 = Tab2(tabmanager)

    action = actions.add_yesno(action_path, False, tabtypes=[Tab2])
    assert not action.enabled

    tabmanager.add_tab(tab1)
    tabmanager.update()
    assert tabmanager.select() is tab1
    assert not action.enabled

    tabmanager.add_tab(tab2)
    tabmanager.update()
    assert tabmanager.select() is tab2
    assert action.enabled

    action2 = actions.add_yesno(action_path + '2', True, tabtypes=[Tab2, None])
    assert action2.enabled

    tabmanager.close_tab(tab2)
    assert tabmanager.select() is tab1
    tabmanager.update()
    assert not action2.enabled

    tabmanager.close_tab(tab1)
    assert tabmanager.select() is None
    tabmanager.update()       # process virtual events
    assert action2.enabled
Beispiel #2
0
def test_filetype_names(porcusession, tabmanager, action_path, filetypes):
    # make sure these filetypes exist
    filetypes.get_filetype_by_name('C')
    filetypes.get_filetype_by_name('Java')
    filetypes.get_filetype_by_name('Python')
    filetypes.get_filetype_by_name('Plain Text')

    filetab = tabs.FileTab(tabmanager)
    othertab = tabs.Tab(tabmanager)

    action = actions.add_yesno(action_path, True,
                               filetype_names=['C', 'Python'])
    assert not action.enabled

    tabmanager.add_tab(othertab)
    assert tabmanager.select() is othertab
    assert not action.enabled

    tabmanager.add_tab(filetab)
    assert tabmanager.select() is filetab
    assert not action.enabled

    filetab.filetype = filetypes.get_filetype_by_name('Java')
    assert not action.enabled
    filetab.filetype = filetypes.get_filetype_by_name('C')
    assert action.enabled

    tabmanager.close_tab(filetab)
    tabmanager.update()
    assert not action.enabled
    tabmanager.close_tab(othertab)
    tabmanager.update()
    assert not action.enabled
Beispiel #3
0
def test_add_yesno(porcusession, action_path):
    assert actions.add_yesno(action_path + '_', True).var.get()
    assert not actions.add_yesno(action_path + '__', False).var.get()
    with pytest.raises(TypeError):
        actions.add_yesno(action_path)      # needs default or var

    var = tkinter.BooleanVar()
    var.set(True)
    action = actions.add_yesno(action_path + '1', var=var)
    assert not hasattr(action, 'callback')
    assert action.var is var
    assert not hasattr(action, 'choices')

    # default and var: var should be set to the default
    assert var.get()
    assert actions.add_yesno(action_path + '2', False, var=var).var is var
    assert not var.get()

    with action_events() as (new_events, enable_events, disable_events):
        root = get_main_window()

        action = actions.add_yesno(action_path, True, '<<Test>>')
        assert new_events.pop().data == action_path
        assert action.var.get()
        root.event_generate('<<Test>>')
        assert not action.var.get()

        action.enabled = False
        assert disable_events.pop().data == action_path
        assert not action.var.get()
        root.event_generate('<<Test>>')
        assert not action.var.get()

        action.enabled = True
        assert enable_events.pop().data == action_path
        assert not action.var.get()
        root.event_generate('<<Test>>')
        assert action.var.get()

    root.unbind('<<Test>>')
Beispiel #4
0
def test_add_yesno(porcusession, action_path):
    assert actions.add_yesno(action_path + '_', True).var.get()
    assert not actions.add_yesno(action_path + '__', False).var.get()
    with pytest.raises(TypeError):
        actions.add_yesno(action_path)  # needs default or var

    var = tkinter.BooleanVar()
    var.set(True)
    action = actions.add_yesno(action_path + '1', var=var)
    assert not hasattr(action, 'callback')
    assert action.var is var
    assert not hasattr(action, 'choices')

    # default and var: var should be set to the default
    assert var.get()
    assert actions.add_yesno(action_path + '2', False, var=var).var is var
    assert not var.get()

    with action_events() as (new_events, enable_events, disable_events):
        root = get_main_window()

        # a <<Test>> virtual event doesn't work for some reason, so i chose
        # <Control-p>, where p is a somewhat randomly chosen letter
        action = actions.add_yesno(action_path, True, '<Control-p>')
        assert new_events.pop().data == action_path
        assert action.var.get()
        root.event_generate('<Control-p>')
        assert not action.var.get()

        action.enabled = False
        assert disable_events.pop().data == action_path
        assert not action.var.get()
        root.event_generate('<Control-p>')
        assert not action.var.get()

        action.enabled = True
        assert enable_events.pop().data == action_path
        assert not action.var.get()
        root.event_generate('<Control-p>')
        assert action.var.get()
Beispiel #5
0
def setup():
    action = actions.add_yesno("View/Full Screen", False, '<F11>')
    action.var.trace('w', on_var_changed)