Esempio n. 1
0
def _test_boxlayout(orientation):
    import_pymt_no_window()
    from pymt import MTBoxLayout, MTWidget

    # note: this test act always if orientation
    # is a horizontal one. use sw() around pos or size
    # to ensure that the swap is done.

    # note: default spacing is 1
    # default padding is 0

    def sw(tpl):
        if orientation == 'vertical':
            return tpl[1], tpl[0]
        return tpl

    # default add
    m = MTBoxLayout(orientation=orientation)
    for x in xrange(10):
        m.add_widget(MTWidget(size=(10,10)))
    print m.size
    test(sw(m.size) == (109, 10))

    # spacing to 10
    m = MTBoxLayout(orientation=orientation, spacing=10)
    for x in xrange(10):
        m.add_widget(MTWidget(size=(10,10)))
    test(sw(m.size) == (190, 10))
Esempio n. 2
0
def unittest_coordinate_transform():
    import_pymt_no_window()
    from pymt import MTWidget

    # child 2 inside child 1 inside child0
    child0 = MTWidget(pos=(100, 100))
    child1 = MTWidget(pos=(200, 200))
    child2 = MTWidget(pos=(300, 300))

    child0.add_widget(child1)
    child1.add_widget(child2)

    test(child0.pos == (100, 100))
    test(child1.pos == (200, 200))
    test(child2.pos == (300, 300))

    # screen coordinate is default
    test(child0.to_local(*child1.pos) == (200, 200))

    # using the relative attribute,
    # we should have relative coordinate
    test(child0.to_local(*child1.pos, relative=True) == (100, 100))
    test(child1.to_local(*child2.pos, relative=True) == (100, 100))

    # screen coordinate 400,400 is 100,100 in relative coordinate from child2
    test(child2.to_widget(400, 400, relative=True) == (100, 100))

    # 100, 100 relative coordinate from child2 is 400, 400 in screen coordinate
    test(child2.to_window(100, 100, relative=True) == (400, 400))
Esempio n. 3
0
def unittest_coordinate_transform():
    import_pymt_no_window()
    from pymt import MTWidget

    # child 2 inside child 1 inside child0
    child0 = MTWidget(pos=(100, 100))
    child1 = MTWidget(pos=(200, 200))
    child2 = MTWidget(pos=(300, 300))

    child0.add_widget(child1)
    child1.add_widget(child2)

    test(child0.pos == (100, 100))
    test(child1.pos == (200, 200))
    test(child2.pos == (300, 300))

    # screen coordinate is default
    test(child0.to_local(*child1.pos) == (200, 200))

    # using the relative attribute,
    # we should have relative coordinate
    test(child0.to_local(*child1.pos, relative=True) == (100, 100))
    test(child1.to_local(*child2.pos, relative=True) == (100, 100))

    # screen coordinate 400,400 is 100,100 in relative coordinate from child2
    test(child2.to_widget(400, 400, relative=True) == (100, 100))

    # 100, 100 relative coordinate from child2 is 400, 400 in screen coordinate
    test(child2.to_window(100, 100, relative=True) == (400, 400))
Esempio n. 4
0
def unittest_defaults():
    import_pymt_no_window()
    from pymt import MTWidget
    w = MTWidget()
    test(w.x == 0)
    test(w.y == 0)
    test(w.width == 100)
    test(w.height == 100)
Esempio n. 5
0
def unittest_visible_methods():
    import_pymt_no_window()
    from pymt import MTWidget
    w = MTWidget()
    w.hide()
    test(w.visible == False)
    w.show()
    test(w.visible == True)
Esempio n. 6
0
def unittest_visible_methods():
    import_pymt_no_window()
    from pymt import MTWidget
    w = MTWidget()
    w.hide()
    test(w.visible == False)
    w.show()
    test(w.visible == True)
Esempio n. 7
0
def unittest_methods():
    import_pymt_no_window()
    from pymt import Vector

    a = Vector(0, 10)
    test(a.length() == 10)

    b = Vector(0, 20)
    test(b.distance(a) == 10)
Esempio n. 8
0
def instance():
    import_pymt_no_window()
    from pymt import MTTextInput
    from pymt import css_add_sheet, css_reload

    try:
        t = MTTextInput()
        return True
    except:
        return False
Esempio n. 9
0
def unittest_css_label():
    import_pymt_no_window()
    from pymt import MTLabel, css_add_sheet
    css_add_sheet('''
    .style {
        color: rgba(0, 255, 0, 255);
    }
    ''')
    l = MTLabel(label='test', cls='style')
    test(l.style['color'] == [0.0, 1.0, 0.0, 1.0])
Esempio n. 10
0
def unittest_css_label():
    import_pymt_no_window()
    from pymt import MTLabel, css_add_sheet
    css_add_sheet('''
    .style {
        color: rgba(0, 255, 0, 255);
    }
    ''')
    l = MTLabel(label='test', cls='style')
    test(l.style['color'] == [0.0, 1.0, 0.0, 1.0])
Esempio n. 11
0
def unittest_defaults():
    import_pymt_no_window()
    from pymt import MTWidget
    w = MTWidget()
    test(w.x == 0)
    test(w.y == 0)
    test(w.width == 100)
    test(w.height == 100)
    test(w.visible == True)
    test(w.draw_children == True)
    test(w.cls == '')
Esempio n. 12
0
def unittest_defaults():
    import_pymt_no_window()
    from pymt import BaseObject
    a = BaseObject()
    test(a.x == 0)
    test(a.y == 0)
    test(a.width == 0)
    test(a.height == 0)
    test(a.pos == (0, 0))
    test(a.size == (0, 0))

    # test every accessor
    a.x = 2
    test(a.x == 2)
    test(a.pos == (2, 0))
    test(a.center == (2, 0))

    a.y = 2
    test(a.y == 2)
    test(a.pos == (2, 2))
    test(a.center == (2, 2))

    a.pos = (0, 0)
    test(a.x == 0)
    test(a.y == 0)
    test(a.pos == (0, 0))
    test(a.center == (0, 0))

    a.width = 2
    test(a.width == 2)
    test(a.size == (2, 0))
    test(a.center == (1, 0))

    a.height = 2
    test(a.height == 2)
    test(a.size == (2, 2))
    test(a.center == (1, 1))

    a.size = (0, 0)
    test(a.width == 0)
    test(a.height == 0)
    test(a.size == (0, 0))
    test(a.center == (0, 0))

    a.center = (5, 5)
    test(a.x == 5)
    test(a.y == 5)
    test(a.pos == (5, 5))
    test(a.width == 0)
    test(a.height == 0)
    test(a.size == (0, 0))

    a.size = (20, 20)
    test(a.center == (15, 15))
Esempio n. 13
0
def unittest_defaults():
    import_pymt_no_window()
    from pymt import MTWidget
    w = MTWidget()
    test(w.x == 0)
    test(w.y == 0)
    test(w.width == 100)
    test(w.height == 100)
    test(w.visible == True)
    test(w.draw_children == True)
    test(w.cls == '')
Esempio n. 14
0
def unittest_defaults():
    import_pymt_no_window()
    from pymt import BaseObject
    a = BaseObject()
    test(a.x == 0)
    test(a.y == 0)
    test(a.width == 0)
    test(a.height == 0)
    test(a.pos == (0, 0))
    test(a.size == (0, 0))

    # test every accessor
    a.x = 2
    test(a.x == 2)
    test(a.pos == (2, 0))
    test(a.center == (2, 0))

    a.y = 2
    test(a.y == 2)
    test(a.pos == (2, 2))
    test(a.center == (2, 2))

    a.pos = (0, 0)
    test(a.x == 0)
    test(a.y == 0)
    test(a.pos == (0, 0))
    test(a.center == (0, 0))

    a.width = 2
    test(a.width == 2)
    test(a.size == (2, 0))
    test(a.center == (1, 0))

    a.height = 2
    test(a.height == 2)
    test(a.size == (2, 2))
    test(a.center == (1, 1))

    a.size = (0, 0)
    test(a.width == 0)
    test(a.height == 0)
    test(a.size == (0, 0))
    test(a.center == (0, 0))

    a.center = (5, 5)
    test(a.x == 5)
    test(a.y == 5)
    test(a.pos == (5, 5))
    test(a.width == 0)
    test(a.height == 0)
    test(a.size == (0, 0))

    a.size = (20, 20)
    test(a.center == (15, 15))
Esempio n. 15
0
def unittest_css_multiclass():
    import_pymt_no_window()
    from pymt import MTLabel, css_add_sheet
    css_add_sheet('''
    .test1 {
        font-color : rgba(255,255,255,255);
    }
    .test2 {
        font-size: 24;
    }
    ''')
    l = MTLabel(label = 'test', cls=('test1', 'test2'))
    test(l.style['font-size'] == 24)
Esempio n. 16
0
def unittest_css_multiclass():
    import_pymt_no_window()
    from pymt import MTLabel, css_add_sheet
    css_add_sheet('''
    .test1 {
        font-color : rgba(255,255,255,255);
    }
    .test2 {
        font-size: 24;
    }
    ''')
    l = MTLabel(label='test', cls=('test1', 'test2'))
    test(l.style['font-size'] == 24)
Esempio n. 17
0
def unittest_css():
    import_pymt_no_window()
    from pymt import MTWidget, Label
    from pymt import css_add_sheet
    css_add_sheet('''
    .style {
        bg-color: rgba(255, 255, 255, 255);
        }
    #my { bg-color : rgba(255, 0, 255, 0);}
    ''')
    w = MTWidget(cls='style')
    x = MTWidget(id='my',cls='style')
    test(w.style['bg-color'] == [1.0 ,1.0 ,1.0 ,1.0])
    test(x.style['bg-color'] == [1.0 ,0.0 ,1.0 ,0.0])
    x.style['bg-color'] = [0, 0, 0, 0]
    test(x.style['bg-color'] == [0 ,0 ,0 ,0])
Esempio n. 18
0
def unittest_css():
    import_pymt_no_window()
    from pymt import MTWidget, Label
    from pymt import css_add_sheet
    css_add_sheet('''
    .style {
        bg-color: rgba(255, 255, 255, 255);
        }
    #my { bg-color : rgba(255, 0, 255, 0);}
    ''')
    w = MTWidget(cls='style')
    x = MTWidget(id='my', cls='style')
    test(w.style['bg-color'] == [1.0, 1.0, 1.0, 1.0])
    test(x.style['bg-color'] == [1.0, 0.0, 1.0, 0.0])
    x.style['bg-color'] = [0, 0, 0, 0]
    test(x.style['bg-color'] == [0, 0, 0, 0])
Esempio n. 19
0
def unittest_visible_events():
    import_pymt_no_window()
    from pymt import MTWidget

    global on_update_called
    on_update_called = 0

    def on_update():
        global on_update_called
        on_update_called += 1

    # by default, visible is True
    w = MTWidget()
    w.connect('on_update', on_update)
    w.dispatch_event('on_update')
    test(on_update_called == 1)

    # make it invisible
    w.visible = False
    w.dispatch_event('on_update')
    test(on_update_called == 1)

    # make it visible
    w.visible = True
    w.dispatch_event('on_update')
    test(on_update_called == 2)

    # create a new widget, visible default to False
    on_update_called = 0
    w = MTWidget(visible=False)
    try:
        # XXX FIXME unable to connect to default on_update
        # since it's not yet register.
        w.connect('on_update', on_update)
    except:
        pass
    w.dispatch_event('on_update')
    test(on_update_called == 0)

    w.visible = True
    w.connect('on_update', on_update)
    w.dispatch_event('on_update')
    test(on_update_called == 1)
Esempio n. 20
0
def unittest_visible_events():
    import_pymt_no_window()
    from pymt import MTWidget

    global on_update_called
    on_update_called = 0

    def on_update():
        global on_update_called
        on_update_called += 1

    # by default, visible is True
    w = MTWidget()
    w.connect('on_draw', on_draw)
    w.dispatch_event('on_draw')
    test(on_draw_called == 1)

    # make it invisible
    w.visible = False
    w.dispatch_event('on_draw')
    test(on_draw_called == 1)

    # make it visible
    w.visible = True
    w.dispatch_event('on_draw')
    test(on_draw_called == 2)

    # create a new widget, visible default to False
    on_draw_called = 0
    w = MTWidget(visible=False)
    try:
        # XXX FIXME unable to connect to default on_draw
        # since it's not yet register.
        w.connect('on_draw', on_draw)
    except:
        pass
    w.dispatch_event('on_draw')
    test(on_draw_called == 0)

    w.visible = True
    w.connect('on_draw', on_draw)
    w.dispatch_event('on_draw')
    test(on_draw_called == 1)
Esempio n. 21
0
def unittest_basics():
    import_pymt_no_window()
    from pymt import Vector
    v = Vector(10, 10)
    test(v.x == 10)
    test(v.y == 10)

    a = Vector(1, 1)
    b = Vector(2, 2)

    test(a != b)

    # add
    c = a + b
    test(c.x == 3)
    test(c.y == 3)
    test(c[0] == 3)
    test(c[1] == 3)

    # sub
    c = a - b
    test(c.x == -1)
    test(c.y == -1)

    # mul
    c = b * 2
    test(c.x == 4)
    test(c.y == 4)

    # add with tuple
    c = b + (5, 6)
    test(c.x == 7)
    test(c.y == 8)

    # add with list
    c = b + [5, 6]
    test(c.x == 7)
    test(c.y == 8)
Esempio n. 22
0
def unittest_dispatcher():
    import_pymt_no_window()
    from pymt import EventDispatcher

    class MyEventDispatcher(EventDispatcher):
        def on_test(self, *largs):
            pass

    global testpass, testargs
    testpass = False
    testargs = None

    def callbacktest(*largs):
        global testpass, testargs
        testpass = True
        testargs = largs

    def resettest():
        global testpass, testargs
        testpass = False
        testargs = None

    a = MyEventDispatcher()

    # test unknown event
    resettest()
    try:
        a.connect('on_test', callbacktest)
    except:
        testpass = True

    test('no register' and testpass)

    # register event + test
    resettest()
    a.register_event_type('on_test')
    try:
        a.connect('on_test', callbacktest)
        testpass = True
    except:
        pass

    test('register' and testpass)

    # test dispatch
    resettest()
    a.dispatch_event('on_test')
    test('dispatch' and testpass)
    test(testargs == ())

    resettest()
    a.dispatch_event('on_test', 123)
    test('disp+arg' and testpass)
    test(testargs == (123,))

    resettest()
    a.dispatch_event('on_test', 123, 'blhe')
    test('disp+2args' and testpass)
    test(testargs == (123, 'blhe'))

    # remove handler
    resettest()
    a.remove_handler('on_test', callbacktest)
    a.dispatch_event('on_test')
    test('nohandler' and not testpass)
Esempio n. 23
0
def _test_boxlayout(orientation):
    import_pymt_no_window()
    from pymt import MTBoxLayout, MTWidget

    # note: this test act always if orientation
    # is a horizontal one. use sw() around pos or size
    # to ensure that the swap is done.

    def sw(tpl):
        tpl = tuple(map(int, tpl))
        if orientation == 'vertical':
            return tpl[1], tpl[0]
        return tpl


    # note: default spacing is 1
    # default padding is 0

    # default add
    m = MTBoxLayout(orientation=orientation)
    for x in xrange(10):
        m.add_widget(MTWidget(size=(10,10)))
    test(sw(m.size) == (109, 10))

    #
    # spacing to 10
    #
    m = MTBoxLayout(orientation=orientation, spacing=10)
    for x in xrange(10):
        m.add_widget(MTWidget(size=(10,10)))
    test(sw(m.size) == (190, 10))

    #
    # padding to 10
    #
    m = MTBoxLayout(orientation=orientation, padding=10, spacing=0)
    for x in xrange(10):
        m.add_widget(MTWidget(size=(10,10)))
    m.do_layout()

    # size should be 10 (number of widget) * width (10) + 2 * padding
    test(sw(m.size) == (120, 30))
    for x in xrange(10):
        if orientation == 'vertical':
            test(sw(m.children[x].pos) == (10 + x * 10, 10))
        else:
            test(sw(m.children[x].pos) == (10 + (9 - x) * 10, 10))


    #
    # testing size_hint with padding
    #
    m = MTBoxLayout(orientation=orientation, padding=10, spacing=0,
                    size_hint=(None, None), size=(500, 500))
    m.add_widget(MTWidget(size_hint=(1, 1)))
    m.do_layout()
    test(sw(m.size) == (500, 500))
    test(sw(m.children[0].size) == (480, 480))

    #
    # testing size_hint with spacing
    #
    m = MTBoxLayout(orientation=orientation, spacing=10,
                    size_hint=(None, None), size=(500, 500))
    m.add_widget(MTWidget(size_hint=(1, 1)))
    m.do_layout()

    # only one should have no impact
    test(sw(m.size) == (500, 500))
    test(sw(m.children[0].size) == (500, 500))

    # add a second widget
    m.add_widget(MTWidget(size_hint=(1, 1)))
    m.do_layout()

    # now, we should see difference
    test(sw(m.size) == (500, 500))
    test(sw(m.children[0].size) == (245, 500))
    test(sw(m.children[1].size) == (245, 500))


    #
    # testing with padding + spacing
    #
    m = MTBoxLayout(orientation=orientation, spacing=10, padding=10)
    for x in xrange(10):
        m.add_widget(MTWidget(size=(10,10)))
    m.do_layout()

    test(sw(m.size) == (210, 30))
    for x in xrange(10):
        if orientation == 'vertical':
            test(sw(m.children[x].pos) == (10 + x * 20, 10))
        else:
            test(sw(m.children[x].pos) == (10 + (9 - x) * 20, 10))


    #
    # testing with padding + spacing + size_hint
    #
    m = MTBoxLayout(orientation=orientation, spacing=10, padding=10,
                    size_hint=(None, None), size=(500, 500))
    m.add_widget(MTWidget(size_hint=(1, 1)))
    m.add_widget(MTWidget(size_hint=(1, 1)))
    m.do_layout()

    # now, we should see difference
    test(sw(m.size) == (500, 500))
    test(sw(m.children[0].size) == (235, 480))
    test(sw(m.children[1].size) == (235, 480))
    if orientation == 'vertical':
        test(sw(m.children[0].pos) == (10, 10))
        test(sw(m.children[1].pos) == (255, 10))
    else:
        test(sw(m.children[0].pos) == (255, 10))
        test(sw(m.children[1].pos) == (10, 10))
Esempio n. 24
0
def _test_boxlayout(orientation):
    import_pymt_no_window()
    from pymt import MTBoxLayout, MTWidget

    # note: this test act always if orientation
    # is a horizontal one. use sw() around pos or size
    # to ensure that the swap is done.

    def sw(tpl):
        tpl = tuple(map(int, tpl))
        if orientation == 'vertical':
            return tpl[1], tpl[0]
        return tpl

    # note: default spacing is 1
    # default padding is 0

    # default add
    m = MTBoxLayout(orientation=orientation)
    for x in xrange(10):
        m.add_widget(MTWidget(size=(10, 10)))
    test(sw(m.size) == (109, 10))

    #
    # spacing to 10
    #
    m = MTBoxLayout(orientation=orientation, spacing=10)
    for x in xrange(10):
        m.add_widget(MTWidget(size=(10, 10)))
    test(sw(m.size) == (190, 10))

    #
    # padding to 10
    #
    m = MTBoxLayout(orientation=orientation, padding=10, spacing=0)
    for x in xrange(10):
        m.add_widget(MTWidget(size=(10, 10)))
    m.do_layout()

    # size should be 10 (number of widget) * width (10) + 2 * padding
    test(sw(m.size) == (120, 30))
    for x in xrange(10):
        if orientation == 'vertical':
            test(sw(m.children[x].pos) == (10 + x * 10, 10))
        else:
            test(sw(m.children[x].pos) == (10 + (9 - x) * 10, 10))

    #
    # testing size_hint with padding
    #
    m = MTBoxLayout(orientation=orientation,
                    padding=10,
                    spacing=0,
                    size_hint=(None, None),
                    size=(500, 500))
    m.add_widget(MTWidget(size_hint=(1, 1)))
    m.do_layout()
    test(sw(m.size) == (500, 500))
    test(sw(m.children[0].size) == (480, 480))

    #
    # testing size_hint with spacing
    #
    m = MTBoxLayout(orientation=orientation,
                    spacing=10,
                    size_hint=(None, None),
                    size=(500, 500))
    m.add_widget(MTWidget(size_hint=(1, 1)))
    m.do_layout()

    # only one should have no impact
    test(sw(m.size) == (500, 500))
    test(sw(m.children[0].size) == (500, 500))

    # add a second widget
    m.add_widget(MTWidget(size_hint=(1, 1)))
    m.do_layout()

    # now, we should see difference
    test(sw(m.size) == (500, 500))
    test(sw(m.children[0].size) == (245, 500))
    test(sw(m.children[1].size) == (245, 500))

    #
    # testing with padding + spacing
    #
    m = MTBoxLayout(orientation=orientation, spacing=10, padding=10)
    for x in xrange(10):
        m.add_widget(MTWidget(size=(10, 10)))
    m.do_layout()

    test(sw(m.size) == (210, 30))
    for x in xrange(10):
        if orientation == 'vertical':
            test(sw(m.children[x].pos) == (10 + x * 20, 10))
        else:
            test(sw(m.children[x].pos) == (10 + (9 - x) * 20, 10))

    #
    # testing with padding + spacing + size_hint
    #
    m = MTBoxLayout(orientation=orientation,
                    spacing=10,
                    padding=10,
                    size_hint=(None, None),
                    size=(500, 500))
    m.add_widget(MTWidget(size_hint=(1, 1)))
    m.add_widget(MTWidget(size_hint=(1, 1)))
    m.do_layout()

    # now, we should see difference
    test(sw(m.size) == (500, 500))
    test(sw(m.children[0].size) == (235, 480))
    test(sw(m.children[1].size) == (235, 480))
    if orientation == 'vertical':
        test(sw(m.children[0].pos) == (10, 10))
        test(sw(m.children[1].pos) == (255, 10))
    else:
        test(sw(m.children[0].pos) == (255, 10))
        test(sw(m.children[1].pos) == (10, 10))