コード例 #1
0
    def test_anchors_multiple(self):
        view1 = View()
        view2 = View()

        view2.left = view1.right, portrait & view1.left

        assert self.constraints(view2) == 'left=id1.right;portrait?left=id1.left'
コード例 #2
0
    def setup(root):
        rootlike = View(parent=root, center=root.center, width=600, height=400, background_color='#f0f7da')

        views.component = View(dock=rootlike.all, background_color='#c9df8a')
        views.component.container = View(dock=views.component.all, background_color='#77ab59')

        views.contained = View(parent=views.component, dock=views.component.all, background_color='#36802d')
コード例 #3
0
    def setup(root):
        rootlike = View(parent=root, center=root.center, width=600, height=400)

        views.top = View(dock=rootlike.top + 0)
        views.below = View(dock=views.top.below + 4)

        views._apply(text=True, background_color='darkseagreen', height=100)
コード例 #4
0
    def test_properties__font(self):
        view = View()
        view.font = 'Roboto', 'Arial', 'Verdana'

        assert view._render_props() == {
            'style': 'font-family:Roboto,Arial,Verdana',
        }
コード例 #5
0
    def test_anchors_docking_center(self):
        view1 = View()
        view2 = View()

        view2.dock = view1.center
        assert view2.parent == view1
        assert self.constraints(view2) == 'centerX=id1.centerX;centerY=id1.centerY'
コード例 #6
0
    def test_composite_properties(self):
        view1 = View()
        view2 = View(center=view1.center, size=(100,view1.height))
        view3 = View(position=view1.position)
        view4 = View(size=view1.size)
        view5 = View(frame=view1.frame)

        assert self.constraints(view2) == 'centerX=id1.centerX;centerY=id1.centerY;width=100;height=id1.height'
        assert self.constraints(view3) == 'left=id1.left;top=id1.top'
        assert self.constraints(view4) == 'width=id1.width;height=id1.height'
        assert self.constraints(view5) == 'left=id1.left;top=id1.top;width=id1.width;height=id1.height'
コード例 #7
0
def setup(root):
    root.background_color = DefaultTheme.tinted

    # center_area = View(background_color='white', dock=root.center, fit=True)

    left_column = View(
        border_width=1,
        border_color=DefaultTheme.primary,
        background_color='white',
        fit=True,
        parent=root,
        right=root.center_x,
        center_y=root.center_y,
    )
    right_column = View(
        border_width=1,
        border_color=DefaultTheme.primary,
        background_color='white',
        fit=True,
        parent=root,
        left=root.center_x,
        center_y=root.center_y,
        size=left_column.size,
    )

    field_text = TextField(placeholder='Text',
                           dock=left_column.top_left,
                           width=200)
    field_number = TextField(field_type=TextField.NUMBER,
                             placeholder='Number',
                             dock=field_text.below)
    field_email = TextField(field_type=TextField.EMAIL,
                            placeholder='Email',
                            dock=field_number.below)
    field_password = TextField(field_type=TextField.PASSWORD,
                               placeholder='Password',
                               dock=field_email.below)
    field_phone = TextField(field_type=TextField.PHONE,
                            placeholder='Phone number',
                            dock=field_password.below)
    field_url = TextField(field_type=TextField.URL,
                          placeholder='URL',
                          dock=field_phone.below)
    field_date = TextField(field_type=TextField.DATE, dock=field_url.below)
    field_time = TextField(field_type=TextField.TIME, dock=field_date.below)
    field_datetime = TextField(field_type=TextField.DATETIME,
                               dock=field_time.below)
    field_month = TextField(field_type=TextField.MONTH,
                            dock=field_datetime.below)
    field_week = TextField(field_type=TextField.WEEK, dock=field_month.below)
    field_color = TextField(field_type=TextField.COLOR, dock=field_week.below)

    button = Button(text='Button', dock=right_column.top_left)
コード例 #8
0
    def setup(root):
        rootlike = View(parent=root, center=root.center, width=600, height=400)

        views.middle = View(parent=rootlike, center=rootlike.center, width=200, height=100)
        views.on_the_left = View(
            parent=rootlike,
            center_y=views.middle.center_y,
            right=views.middle.left,
            left=rootlike.left,
            height=views.middle.height - gap,
        )

        views._apply(text=True, background_color='darkseagreen')
コード例 #9
0
    def setup(root):
        rootlike = View(dock=root.center, width=600, height=400)

        views.textfield = TextField(placeholder='Enter text',
                                    dock=rootlike.center)

        @views.textfield
        def on_change(view):
            pass
コード例 #10
0
    def test_anchors_conditions(self):
        view1 = View()
        view2 = View()
        view3 = View()

        view2.left = portrait & view1.left
        assert self.constraints(view2) == 'portrait?left=id1.left'

        view3.left = portrait(view1) & view1.left
        assert self.constraints(view3) == 'portrait(id1)?left=id1.left'
コード例 #11
0
    def setup(root):
        rootlike = View(parent=root, center=root.center, width=600, height=400)

        views.all = View(dock=rootlike.all, background_color='#f0f7da')
        views.top = View(dock=rootlike.top, height=50, background_color=(119, 171, 89, 100))
        views.bottom = View(dock=rootlike.bottom, height=50, background_color=(119, 171, 89, 100))
        views.left = View(dock=rootlike.left, width=50, background_color=(201, 223, 138, 100))
        views.right = View(dock=rootlike.right, width=50, background_color=(201, 223, 138, 100))
コード例 #12
0
    def test_anchors_fit_both(self):
        view1 = View()
        view2 = View()

        view1.fit = 'both'
        assert self.constraints(view1) == 'width=id1.fitWidth+0;height=id1.fitHeight+0'

        view2.fit = True
        assert self.constraints(view2) == 'width=id2.fitWidth+0;height=id2.fitHeight+0'
コード例 #13
0
class Slider(View):
    _tag = 'input'
    style = ButtonStyle

    def __init__(self, min_value=0, max_value=1, **kwargs):
        super().__init__(self)
        self.min_value = min_value
        self.max_value = max_value
        self.apply(kwargs)

    value = View._prop('value')
    min_value = View._prop('min_value')
    max_value = View._prop('max_value')

    def _additional_attributes(self):
        attributes = super()._additional_attributes()
        attributes.update({
            'type': 'range',
            'step': 'any',
            'min': self.min_value,
            'max': self.max_value,
            'value': self.value or '',
        })
        return attributes
コード例 #14
0
    def setup(root):
        rootlike = View(dock=root.center, width=600, height=400)

        # Baseline fitted label
        views.basic = Label(text='Label with text', dock=rootlike.center, background_color='darkseagreen')

        # Docking
        views.docked = Label(text='Label with text', dock=rootlike.top, background_color='darkseagreen')

        # Fixing width flexes height
        views.fixed_width = Label(
            text='A little more text to make things interesting',
            background_color='darkseagreen',
            dock=rootlike.bottom_center,
            width=150,
        )

        # Limiting (capping) works as well
        views.limited = Label(text='Label with text', dock=rootlike.right_center, background_color='darkseagreen')
        views.limited.width = at_most(80)

        # For height, it essentially just fixes the height
        views.fixed_height = Label(
            text='A little more text to fit',
            background_color='darkseagreen',
            dock=rootlike.left_center,
            height=50,
        )

        # Fixing both dimensions truncates the text if needed, but no ellipsis :-(
        views.truncated_text = Label(
            text='Just too much text that gets neatly cut at the end',
            background_color='darkseagreen',
            dock=rootlike.bottom_right,
            width=150,
            height=50,
        )

        # Different text alignment
        views.aligned_top_right = Label(
            text='Top right corner',
            alignment=('top', 'right'),
            background_color='darkseagreen',
            dock=rootlike.bottom_left,
            width=150,
            height=150,
        )
コード例 #15
0
    def setup(root):
        rootlike = View(parent=root, center=root.center, width=600, height=400)

        views.middle = View(
            parent=rootlike, center=rootlike.center, width=200, height=100)
        views.on_the_left = View(parent=rootlike,
            center_y=views.middle.center_y, right=views.middle.left, left=rootlike.left, height=views.middle.height)
        views.on_the_right = View(parent=rootlike,
            center_y=views.middle.center_y, left=views.middle.right, right=rootlike.right, height=views.middle.height)
        views.above = View(parent=rootlike,
            center_x=views.middle.center_x, bottom=views.middle.top, top=rootlike.top, width=views.middle.width)
        views.below = View(parent=rootlike,
            center_x=views.middle.center_x, top=views.middle.bottom, bottom=rootlike.bottom, width=views.middle.width)

        views._apply(text=True, background_color='darkseagreen')
コード例 #16
0
    def setup(root):
        rootlike = View(parent=root, center=root.center, width=600, height=400)

        views.center = View(dock=rootlike.center)

        views.top_left = View(dock=rootlike.top_left)
        views.top_center = View(dock=rootlike.top_center)
        views.top_right = View(dock=rootlike.top_right)
        views.left_center = View(dock=rootlike.left_center)
        views.right_center = View(dock=rootlike.right_center)
        views.bottom_left = View(dock=rootlike.bottom_left)
        views.bottom_center = View(dock=rootlike.bottom_center)
        views.bottom_right = View(dock=rootlike.bottom_right)

        views.above = View(dock=views.center.above)
        views.below = View(dock=views.center.below)
        views.left_of = View(dock=views.center.left_of)
        views.right_of = View(dock=views.center.right_of)

        views._apply(text=True, width=100, height=50, background_color='darkseagreen')
コード例 #17
0
    def test_anchors_fit_extra(self):
        view1 = View()

        view1.fit = 16
        assert self.constraints(view1) == 'width=id1.fitWidth+16;height=id1.fitHeight+16'
コード例 #18
0
    def test_anchors_fit_width(self):
        view1 = View()

        view1.fit = 'width'
        assert self.constraints(view1) == 'width=id1.fitWidth+0'
コード例 #19
0
    def setup(root):
        rootlike = View(dock=root.center, width=600, height=400)

        # Baseline fitted label
        views.basic = Table(content=[['One', 'Two'], ['Three', 'Four']],
                            dock=rootlike.center)
コード例 #20
0
    def test_anchors_dock(self):
        view1 = View()
        view2 = View()
        view3 = View()
        view4 = View()
        view5 = View()

        view1.dock = view2.top_left
        assert view1.parent == view2
        assert self.constraints(view1) == 'top=id2.top;left=id2.left'

        view4.dock = view1.top
        view4.height = 100
        assert self.constraints(view4) == 'top=id1.top;left=id1.left;right=id1.right;height=100'

        view2.dock = view3.top + 16
        assert self.constraints(view2) == 'top=id3.top+16;left=id3.left+16;right=id3.right-16'

        view4.parent = view1
        view3.dock = view4.below
        assert view3.parent == view1
        assert self.constraints(view3) == 'top=id4.bottom;centerX=id4.centerX;width=id4.width'

        view5.dock = view4.above + 4
        assert self.constraints(view5) == 'bottom=id4.top-4;centerX=id4.centerX;width=id4.width'
コード例 #21
0
    def setup(root):
        rootlike = View(dock=root.center, width=600, height=400)

        views.button = Button(text='Button', dock=rootlike.center)