Ejemplo n.º 1
0
def bind_scroll(
    control: DirectGuiBase.DirectGuiBase,
    scroll_up: typing.Callable[[typing.Any], None],
    scroll_down: typing.Callable[[typing.Any], None],
):
    control.bind(constants.DIRECT_GUI_WHEELUP, scroll_up)
    control.bind(constants.DIRECT_GUI_WHEELDOWN, scroll_down)
Ejemplo n.º 2
0
def test_options():
    baseitem = DirectGuiBase()
    testoptiondefs = (
        ('test-1', 0, DGG.INITOPT),
        ('test-2', 0, None),
    )
    baseitem.defineoptions({}, testoptiondefs)
    assert len(baseitem.options()) == 2
Ejemplo n.º 3
0
def test_postInitialiseFunc():
    baseitem = DirectGuiBase()

    def func_a():
        global test_value_a
        test_value_a = 1

    def func_b():
        global test_value_b
        test_value_b = 1

    baseitem.postInitialiseFuncList.append(func_a)
    baseitem.postInitialiseFuncList.append(func_b)

    baseitem.postInitialiseFunc()

    global test_value_a
    assert test_value_a == 1

    global test_value_b
    assert test_value_b == 1
Ejemplo n.º 4
0
def test_bindings():
    baseitem = DirectGuiBase()

    # Our test function and variable to check
    global commandCalled
    commandCalled = False

    def command(**kw):
        global commandCalled
        commandCalled = True
        assert True

    # Bind an event to our item
    baseitem.bind(DGG.B1CLICK, command)

    # The function should be called now. Note that the guiId will be
    # automatically appended by the bind command!
    messenger.send(DGG.B1CLICK + baseitem.guiId)
    assert commandCalled

    # Try to unbind the event again
    baseitem.unbind(DGG.B1CLICK)

    # Now it shouldn't be called anymore
    commandCalled = False
    messenger.send(DGG.B1CLICK + baseitem.guiId)
    assert not commandCalled
Ejemplo n.º 5
0
def test_destroy():
    baseitem = DirectGuiBase()
    testoptiondefs = (('test-1', 0, None), )
    baseitem.defineoptions({}, testoptiondefs)
    baseitem.destroy()
    # check if things got correctly removed
    assert not hasattr(baseitem, '_optionInfo')
    assert not hasattr(baseitem, '__componentInfo')
    assert not hasattr(baseitem, 'postInitialiseFuncList')
Ejemplo n.º 6
0
def test_addoptions():
    baseitem = DirectGuiBase()
    testoptiondefs = (('test', 0, None), )

    # Those two will usually be set in the defineoptions function
    baseitem._optionInfo = {}
    baseitem._constructorKeywords = {}

    baseitem.addoptions(testoptiondefs, {})
    assert baseitem['test'] == 0
Ejemplo n.º 7
0
def test_get_options():
    baseitem = DirectGuiBase()
    testoptiondefs = (('test-1', 0, None), )
    baseitem.defineoptions({}, testoptiondefs)

    # Using the configure function
    # check if configuration have been set correctly
    assert baseitem.configure() == {
        'test-1': ('test-1', 0, 0),
    }
    # check for specific configurations
    assert baseitem.configure('test-1') == ('test-1', 0, 0)

    # using index style references __getItem__ and cget
    assert baseitem['test-1'] == 0
    assert baseitem.cget('test-1') == 0
Ejemplo n.º 8
0
def test_initialiseoptions():
    baseitem = DirectGuiBase()

    class testWidget(DirectGuiBase):
        def __init__(self):
            pass

    tw = testWidget()
    baseitem.initialiseoptions(tw)

    testoptiondefs = (('test', 0, None), )
    tw.defineoptions({}, testoptiondefs)
    baseitem.initialiseoptions(tw)

    assert tw['test'] == 0
Ejemplo n.º 9
0
def test_set_options():
    baseitem = DirectGuiBase()

    testoptiondefs = (('test-1', 0, DGG.INITOPT), ('test-2', 0, None))
    baseitem.defineoptions({}, testoptiondefs)

    # try to set a value of an initopt option (shouldn't be possible)
    baseitem.configure('test-1', **{'test-1': 1})
    # check it's value. It shouldn't have changed
    assert baseitem['test-1'] == 0

    baseitem['test-1'] = 1
    # check it's value. It shouldn't have changed
    assert baseitem['test-1'] == 0

    # try changing using the configure function. As test-2 isn't an
    # initopt option, this should work fine
    baseitem.configure('test-2', **{'test-2': 2})
    # check it's value. It should be 2 now
    assert baseitem['test-2'] == 2

    # try changing using index style referencing
    baseitem['test-2'] = 1
    assert baseitem['test-2'] == 1
Ejemplo n.º 10
0
def bind_gui_for_focus(control: DirectGuiBase.DirectGuiBase):
    control["state"] = DirectGuiGlobals.NORMAL
    control.bind(DirectGuiGlobals.WITHIN, dispatch_has_focus)
    control.bind(DirectGuiGlobals.WITHOUT, dispatch_lost_focus)
Ejemplo n.º 11
0
def test_isinitoption():
    baseitem = DirectGuiBase()
    testoptiondefs = (('test-true', 0, DGG.INITOPT), ('test-false', 0, None))
    baseitem.defineoptions({}, testoptiondefs)
    assert baseitem.isinitoption('test-true') == True
    assert baseitem.isinitoption('test-false') == False
Ejemplo n.º 12
0
def test_defineoptions():
    baseitem = DirectGuiBase()
    testoptiondefs = (('test', 0, None), )
    baseitem.defineoptions({}, testoptiondefs)
    assert baseitem['test'] == 0
Ejemplo n.º 13
0
def test_component_handling():
    baseitem = DirectGuiBase()
    testoptiondefs = (('test-1', 0, None), )
    baseitem.defineoptions({}, testoptiondefs)

    assert len(baseitem.components()) == 0

    baseitem.createcomponent(
        'componentName',  # componentName
        (),  # componentAliases
        'componentGroup',  # componentGroup
        OnscreenText,  # widgetClass
        (),  # *widgetArgs
        text='Test',  # **kw
        parent=core.NodePath())

    # check if we have exactly one component now
    assert len(baseitem.components()) == 1
    # check if we have a component named like the one we just created
    assert baseitem.hascomponent('componentName')

    # get our new component
    component = baseitem.component('componentName')
    # check some of its values
    assert component.text == 'Test'

    # destroy our recently created component
    baseitem.destroycomponent('componentName')
    # check if it really is gone
    assert baseitem.hascomponent('componentName') == False
Ejemplo n.º 14
0
def test_create_DirectGuiBase():
    baseitem = DirectGuiBase()