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_methods():
    from pymt import Vector

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

    b = Vector(0, 20)
    test(b.distance(a) == 10)
Esempio n. 3
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. 4
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. 5
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. 6
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. 7
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. 8
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. 9
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. 10
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. 11
0
def unittest_defaults():
    from pymt import MTWidget
    w = MTWidget()
    test(w.x == 0)
    test(w.y == 0)
    test(w.width == 100)
    test(w.height == 100)

    test_runpymt(w)
    test_image()
Esempio n. 12
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. 13
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. 14
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. 15
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. 16
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. 17
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. 18
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. 19
0
def unittest_mttextinput():
    test(instance())
Esempio n. 20
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. 21
0
def unittest_mttextinput():
    test(instance())
Esempio n. 22
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. 23
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. 24
0
def unittest_mttextarea_basics():
    '''Test  driver'''

    # Test defaults
    t = instance()
    test(t is not None)
    if t is None: return
    test(t.height == 100)
    test(t.width == 100)
    test(t.value == '')
    test(len(t.lines) == 1)

    # Test operations with a single line in widget
    tline1 = 'This is a single line'
    t.value = tline1
    test(tline1 == t.value)
    test(len(t.lines) == 3)
    test(t.height == 100)
    test(t.width == 100)

    # Replace text with an empty string
    t.value = ''
    test(t.value == '')
    test(len(t.lines) == 1)
    test(t.height == 100)
    test(t.width == 100)

    # Now lets put in a string of 12 lines and see what happens
    tline2 = [
        '', 'Line 1',
        ('Line 2 which is rather long and should overflow'
         ' horizontally ........................'), 'Line 3', 'Line 4',
        'Line 5   ', 'Line 6', '   Line 7', 'Line 8', '', 'Line 10', ''
    ]
    tline2b = '\n'.join(tline2)
    t.value = tline2b
    # Among other things, make sure leading and trailing white space
    # are not lost
    test(tline2b == t.value)
    test(len(t.lines) == 21)
    test(t.height == 100)
    test(t.width == 100)

    # Lets replace line 8
    '''This is now deprecated.
    lt1 = 'Replacement text for line 8'
    tline2[7] = lt1
    tline2c = '\n'.join(tline2)
    t.set_line_text(7, lt1)
    test(tline2c == t.value)
    test(len(t.lines) == 12)
    test(t.height == 100)
    test(t.width == 100)
    '''

    # Test full auto-sizing
    del t
    t = instance(autosize=True)
    test(t is not None)
    if t is None: return

    # Test defaults
    test(int(t.height) == 25)
    test(int(t.width) == 1)
    test(t.value == '')
    test(len(t._glyph_size) == 0)
    test(len(t.lines) == 1)

    # Test operations with a single line in widget
    # This test assumes the default font and Pygame as text manager running
    # on Ubuntu 10.04.
    # Other text managers may give slightly different results for dimensions
    # and different fonts could cause larger variations
    t.value = tline1
    test(tline1 == t.value)
    test(len(t.lines) == 1)
    test(int(t.height) == 25)
    test(int(t.width) == 203)

    # Replace text with an empty string
    t.value = ''
    test(t.value == '')
    test(len(t.lines) == 1)
    test(int(t.height) == 25)
    test(int(t.width) == 1)

    # Now lets put in a string of 12 lines and see what happens
    t.value = tline2b
    # Among other things, make sure leading and trailing white space
    # are not lost
    test(tline2b == t.value)
    test(len(t.lines) == 12)
    test(int(t.height) == 322)
    test(int(t.width) == 809)
Esempio n. 25
0
def unittest_mttextarea():
    '''Test  driver'''
    
    # Test defaults
    t = instance()
    test(t is not None)
    if t is None: return
    test(t.height == 100)
    test(t.width == 100)
    test(t.value == '')
    test(len(t._glyph_size) == 0)
    test(len(t.lines) == 1)
    
    # Test operations with a single line in widget
    tline1 = 'This is a single line'
    t.value =tline1
    test(tline1 == t.value)
    test(len(t.lines) == 1)
    test(t.height == 100)
    test(t.width == 100)
    
    # Replace text with an empty string
    emptyline = ''
    t.value = emptyline
    test(emptyline == t.value)
    test(len(t.lines) == 1)
    test(t.height == 100)
    test(t.width == 100)
    
    # Now lets put in a string of 12 lines and see what happens
    tline2 = ['', 'Line 1', ('Line 2 which is rather long and should overflow'
              ' horizontally ........................'),
              'Line 3', 'Line 4', 'Line 5   ', 'Line 6', '   Line 7',
              'Line 8', '', 'Line 10', '']
    tline2b = '\n'.join(tline2)
    t.value = tline2b
    # Among other things, make sure leading and trailing white space
    # are not lost
    test(tline2b == t.value)
    test(len(t.lines) == 12)
    test(t.height == 100)
    test(t.width == 100)
    
    # Lets replace line 8
    lt1 = 'Replacement text for line 8'
    tline2[7] = lt1
    tline2c = '\n'.join(tline2)
    t.set_line_text(7, lt1)
    test(tline2c == t.value)
    test(len(t.lines) == 12)
    test(t.height == 100)
    test(t.width == 100)
    
    # Test full auto-sizing
    del t
    t = instance(autosize=True)
    test(t is not None)
    if t is None: return
    
    # Test defaults
    test(int(t.height) == 25)
    test(int(t.width) == 1)
    test(t.value == '')
    test(len(t._glyph_size) == 0)
    test(len(t.lines) == 1)
    
    # Test operations with a single line in widget
    # This test assumes the default font and Pygame as text manager running
    # on Ubuntu 10.04.
    # Other text managers may give slightly different results for dimensions
    # and different fonts could cause larger variations
    t.value =tline1
    test(tline1 == t.value)
    test(len(t.lines) == 1)
    test(int(t.height) == 25)
    test(int(t.width) == 203)
    
    # Replace text with an empty string
    t.value = emptyline
    test(emptyline == t.value)
    test(len(t.lines) == 1)
    test(int(t.height) == 25)
    test(int(t.width) == 1)

    # Now lets put in a string of 12 lines and see what happens
    t.value = tline2b
    # Among other things, make sure leading and trailing white space
    # are not lost
    test(tline2b == t.value)
    test(len(t.lines) == 12)
    test(int(t.height) == 322)
    test(int(t.width) == 809)
Esempio n. 26
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. 27
0
def unittest_mttextarea_basics():
    """Test  driver"""

    # Test defaults
    t = instance()
    test(t is not None)
    if t is None:
        return
    test(t.height == 100)
    test(t.width == 100)
    test(t.value == "")
    test(len(t.lines) == 1)

    # Test operations with a single line in widget
    tline1 = "This is a single line"
    t.value = tline1
    test(tline1 == t.value)
    test(len(t.lines) == 3)
    test(t.height == 100)
    test(t.width == 100)

    # Replace text with an empty string
    t.value = ""
    test(t.value == "")
    test(len(t.lines) == 1)
    test(t.height == 100)
    test(t.width == 100)

    # Now lets put in a string of 12 lines and see what happens
    tline2 = [
        "",
        "Line 1",
        ("Line 2 which is rather long and should overflow" " horizontally ........................"),
        "Line 3",
        "Line 4",
        "Line 5   ",
        "Line 6",
        "   Line 7",
        "Line 8",
        "",
        "Line 10",
        "",
    ]
    tline2b = "\n".join(tline2)
    t.value = tline2b
    # Among other things, make sure leading and trailing white space
    # are not lost
    test(tline2b == t.value)
    test(len(t.lines) == 21)
    test(t.height == 100)
    test(t.width == 100)

    # Lets replace line 8
    """This is now deprecated.
    lt1 = 'Replacement text for line 8'
    tline2[7] = lt1
    tline2c = '\n'.join(tline2)
    t.set_line_text(7, lt1)
    test(tline2c == t.value)
    test(len(t.lines) == 12)
    test(t.height == 100)
    test(t.width == 100)
    """

    # Test full auto-sizing
    del t
    t = instance(autosize=True)
    test(t is not None)
    if t is None:
        return

    # Test defaults
    test(int(t.height) == 25)
    test(int(t.width) == 1)
    test(t.value == "")
    test(len(t._glyph_size) == 0)
    test(len(t.lines) == 1)

    # Test operations with a single line in widget
    # This test assumes the default font and Pygame as text manager running
    # on Ubuntu 10.04.
    # Other text managers may give slightly different results for dimensions
    # and different fonts could cause larger variations
    t.value = tline1
    test(tline1 == t.value)
    test(len(t.lines) == 1)
    test(int(t.height) == 25)
    test(int(t.width) == 203)

    # Replace text with an empty string
    t.value = ""
    test(t.value == "")
    test(len(t.lines) == 1)
    test(int(t.height) == 25)
    test(int(t.width) == 1)

    # Now lets put in a string of 12 lines and see what happens
    t.value = tline2b
    # Among other things, make sure leading and trailing white space
    # are not lost
    test(tline2b == t.value)
    test(len(t.lines) == 12)
    test(int(t.height) == 322)
    test(int(t.width) == 809)
Esempio n. 28
0
def unittest_mttextarea_cursor():
    t = instance()
    test(t is not None)
    if t is None:
        return

    test(t.cursor == (0, 0))
    test(t.cursor_index == 0)

    t.value = 'abc\ndef\nghi'
    test(len(t.value) == 11)
    test(t.cursor == (3, 2))
    test(t.cursor_index == 11)

    # test some cursor position from text index
    test(t.get_cursor_from_index(0) == (0, 0))
    test(t.get_cursor_from_index(1) == (1, 0))
    test(t.get_cursor_from_index(2) == (2, 0))
    test(t.get_cursor_from_index(3) == (3, 0))
    test(t.get_cursor_from_index(4) == (0, 1))
    test(t.get_cursor_from_index(5) == (1, 1))
    test(t.get_cursor_from_index(6) == (2, 1))
    test(t.get_cursor_from_index(7) == (3, 1))
    test(t.get_cursor_from_index(8) == (0, 2))
    test(t.get_cursor_from_index(9) == (1, 2))
    test(t.get_cursor_from_index(10) == (2, 2))
    test(t.get_cursor_from_index(11) == (3, 2))

    # now, set the cursor, and check the index
    t.cursor = (0, 0)
    test(t.cursor_index == 0)
    t.cursor = (1, 0)
    test(t.cursor_index == 1)
    t.cursor = (2, 0)
    test(t.cursor_index == 2)
    t.cursor = (3, 0)
    test(t.cursor_index == 3)
    t.cursor = (0, 1)
    test(t.cursor_index == 4)
    t.cursor = (1, 1)
    test(t.cursor_index == 5)
    t.cursor = (2, 1)
    test(t.cursor_index == 6)
    t.cursor = (3, 1)
    test(t.cursor_index == 7)
    t.cursor = (0, 2)
    test(t.cursor_index == 8)
    t.cursor = (1, 2)
    test(t.cursor_index == 9)
    t.cursor = (2, 2)
    test(t.cursor_index == 10)
    t.cursor = (3, 2)
    test(t.cursor_index == 11)

    # test bounds
    test(t.get_cursor_from_index(-1) == (0, 0))
    test(t.get_cursor_from_index(-100) == (0, 0))
    print t.get_cursor_from_index(12)
    test(t.get_cursor_from_index(12) == (3, 2))
    test(t.get_cursor_from_index(100) == (3, 2))
Esempio n. 29
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. 30
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. 31
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. 32
0
def unittest_mttextarea_cursor():
    t = instance()
    test(t is not None)
    if t is None:
        return

    test(t.cursor == (0, 0))
    test(t.cursor_index == 0)

    t.value = "abc\ndef\nghi"
    test(len(t.value) == 11)
    test(t.cursor == (3, 2))
    test(t.cursor_index == 11)

    # test some cursor position from text index
    test(t.get_cursor_from_index(0) == (0, 0))
    test(t.get_cursor_from_index(1) == (1, 0))
    test(t.get_cursor_from_index(2) == (2, 0))
    test(t.get_cursor_from_index(3) == (3, 0))
    test(t.get_cursor_from_index(4) == (0, 1))
    test(t.get_cursor_from_index(5) == (1, 1))
    test(t.get_cursor_from_index(6) == (2, 1))
    test(t.get_cursor_from_index(7) == (3, 1))
    test(t.get_cursor_from_index(8) == (0, 2))
    test(t.get_cursor_from_index(9) == (1, 2))
    test(t.get_cursor_from_index(10) == (2, 2))
    test(t.get_cursor_from_index(11) == (3, 2))

    # now, set the cursor, and check the index
    t.cursor = (0, 0)
    test(t.cursor_index == 0)
    t.cursor = (1, 0)
    test(t.cursor_index == 1)
    t.cursor = (2, 0)
    test(t.cursor_index == 2)
    t.cursor = (3, 0)
    test(t.cursor_index == 3)
    t.cursor = (0, 1)
    test(t.cursor_index == 4)
    t.cursor = (1, 1)
    test(t.cursor_index == 5)
    t.cursor = (2, 1)
    test(t.cursor_index == 6)
    t.cursor = (3, 1)
    test(t.cursor_index == 7)
    t.cursor = (0, 2)
    test(t.cursor_index == 8)
    t.cursor = (1, 2)
    test(t.cursor_index == 9)
    t.cursor = (2, 2)
    test(t.cursor_index == 10)
    t.cursor = (3, 2)
    test(t.cursor_index == 11)

    # test bounds
    test(t.get_cursor_from_index(-1) == (0, 0))
    test(t.get_cursor_from_index(-100) == (0, 0))
    print t.get_cursor_from_index(12)
    test(t.get_cursor_from_index(12) == (3, 2))
    test(t.get_cursor_from_index(100) == (3, 2))