예제 #1
0
 def __init__(self, ctx, **kwargs):
     kwargs.setdefault('do_y', False)
     super(BookmarkBar, self).__init__(**kwargs)
     self.ctx = ctx
     self.layout = MTBoxLayout(spacing=2, padding=4)
     self.add_widget(self.layout)
     self.bookmarks_buttons = {}
     self.bookmarks_keys = []
     self._current = None
예제 #2
0
파일: test_layout.py 프로젝트: bernt/pymt
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))
예제 #3
0
class BookmarkBar(MTList):
    def __init__(self, ctx, **kwargs):
        kwargs.setdefault('do_y', False)
        super(BookmarkBar, self).__init__(**kwargs)
        self.ctx = ctx
        self.layout = MTBoxLayout(spacing=2, padding=4)
        self.add_widget(self.layout)
        self.bookmarks_buttons = {}
        self.bookmarks_keys = []
        self._current = None

    def create_bookmark(self):
        self.add_bookmark(ViewBookMark(self.ctx.capture_current_view()))

    def on_touch_down(self, touch):
        ret = super(BookmarkBar, self).on_touch_down(touch)
        if self.collide_point(*touch.pos):
            return True
        return ret

    def on_touch_move(self, touch):
        ret = super(BookmarkBar, self).on_touch_move(touch)
        if self.collide_point(*touch.pos):
            return True
        return ret

    def on_touch_up(self, touch):
        ret = super(BookmarkBar, self).on_touch_up(touch)
        if self.collide_point(*touch.pos):
            return True
        return ret

    def add_bookmark(self, bookmark):
        bookmark_btn = MTImageButton(image=bookmark.screenshot)
        @bookmark_btn.event
        def on_press(touch):
            if self.ctx.mode in ('layout', 'edit') and touch.is_double_tap:
                self.layout.remove_widget(bookmark_btn)
                # remove current, set to next
                if self._current == bookmark:
                    self.next()
                del self.bookmarks_buttons[bookmark]
                self.bookmarks_keys.remove(bookmark)
            else:
                self.goto(self.bookmarks_keys.index(bookmark))
            return True

        self.bookmarks_buttons[bookmark] = bookmark_btn
        self.bookmarks_keys.append(bookmark)
        self.layout.add_widget(bookmark_btn)
        self.layout.do_layout()
        self._current = bookmark

    def update_screenshot(self, bookmark):
        if not bookmark in self.bookmarks_buttons:
            return
        bookmark.update_screenshot()
        self.bookmarks_buttons[bookmark].image = bookmark.screenshot

    def goto(self, idx):
        try:
            self._current = self.bookmarks_keys[idx % len(self.bookmarks_keys)]
            self.parent.goto_view(self._current)
        except:
            pass

    def previous(self):
        if self._current is None:
            return
        self.goto(self.bookmarks_keys.index(self._current) - 1)

    def next(self):
        if self._current is None:
            return
        self.goto(self.bookmarks_keys.index(self._current) + 1)

    def _get_state(self):
        data = []
        for x in self.bookmarks_keys:
            data.append({
                'scale': x.view_transform[0],
                'pos': x.view_transform[1],
                'quat': serialize_numpy(x.view_transform[2]),
                'info': x.info
            })
        return data
    def _set_state(self, state):
        for x in state:
            bookmark = ViewBookMark(None, info=x.get('info'))
            bookmark.view_transform = (x.get('scale'), x.get('pos'), x.get('quat'))
            self.add_bookmark(bookmark)
    state = property(_get_state, _set_state)
예제 #4
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))
예제 #5
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))