示例#1
0
def test_tabs_add():
    t = Tabs(tabs=[Tab(text="Tab1"), Tab("Tab2"), Tab("Tab3")])

    assert isinstance(t, pglet.Control)
    assert isinstance(t, pglet.Tabs)
    assert t.get_cmd_str() == [
        Command(indent=0,
                name=None,
                values=["tabs"],
                attrs={"value": "Tab1"},
                lines=[],
                commands=[]),
        Command(indent=2,
                name=None,
                values=["tab"],
                attrs={"text": "Tab1"},
                lines=[],
                commands=[]),
        Command(indent=2,
                name=None,
                values=["tab"],
                attrs={"text": "Tab2"},
                lines=[],
                commands=[]),
        Command(indent=2,
                name=None,
                values=["tab"],
                attrs={"text": "Tab3"},
                lines=[],
                commands=[]),
    ], "Test failed"
示例#2
0
def test_value__can_be_set_to_valid_tab_key_only_when_tabs():
    t = Tabs(tabs=[
        Tab(text="Tab1", key="first_tab_key", controls=[Button(text="OK")])
    ])

    t.value = "Tab1"
    t.value = "first_tab_key"
    with pytest.raises(AssertionError):
        t.value = "Unknown value"
示例#3
0
def test_tabs_with_controls_add():
    t = Tabs(tabs=[
        Tab(text="Tab1", controls=[Button(
            text="OK"), Button(text="Cancel")]),
        Tab(
            "Tab2",
            controls=[Textbox(label="Textbox 1"),
                      Textbox(label="Textbox 2")],
        ),
    ])
    assert isinstance(t, pglet.Control)
    assert isinstance(t, pglet.Tabs)
    assert t.get_cmd_str() == [
        Command(indent=0,
                name=None,
                values=["tabs"],
                attrs={"value": "Tab1"},
                lines=[],
                commands=[]),
        Command(indent=2,
                name=None,
                values=["tab"],
                attrs={"text": "Tab1"},
                lines=[],
                commands=[]),
        Command(indent=4,
                name=None,
                values=["button"],
                attrs={"text": "OK"},
                lines=[],
                commands=[]),
        Command(indent=4,
                name=None,
                values=["button"],
                attrs={"text": "Cancel"},
                lines=[],
                commands=[]),
        Command(indent=2,
                name=None,
                values=["tab"],
                attrs={"text": "Tab2"},
                lines=[],
                commands=[]),
        Command(indent=4,
                name=None,
                values=["textbox"],
                attrs={"label": "Textbox 1"},
                lines=[],
                commands=[]),
        Command(indent=4,
                name=None,
                values=["textbox"],
                attrs={"label": "Textbox 2"},
                lines=[],
                commands=[]),
    ], "Test failed"
示例#4
0
def test_tabs_add():
    t = Tabs(tabs=[
            Tab(text='Tab1'),
            Tab('Tab2'),
            Tab('Tab3')])

    assert isinstance(t, pglet.Control)
    assert isinstance(t, pglet.Tabs)
    assert t.get_cmd_str() == (
        'tabs\n'
        '  tab text="Tab1"\n'
        '  tab text="Tab2"\n'
        '  tab text="Tab3"'
    ), "Test failed"
示例#5
0
def test_value__can_be_set_on_initialization():
    t = Tabs(
        value="Tab2",
        tabs=[
            Tab("Tab1", controls=[Button(text="OK")]),
            Tab("Tab2", controls=[Button(text="Not OK")]),
        ],
    )
    assert t.value == "Tab2"
示例#6
0
def test_tabs_with_controls_add():
    t = Tabs(tabs=[
            Tab(text='Tab1', controls=[
                Button(text='OK'),
                Button(text='Cancel')
            ]),
            Tab('Tab2', controls=[
                Textbox(label='Textbox 1'),
                Textbox(label='Textbox 2')
            ])
    ])
    assert isinstance(t, pglet.Control)
    assert isinstance(t, pglet.Tabs)
    assert t.get_cmd_str() == (
        'tabs\n'
        '  tab text="Tab1"\n'
        '    button text="OK"\n'
        '    button text="Cancel"\n'
        '  tab text="Tab2"\n'
        '    textbox label="Textbox 1"\n'
        '    textbox label="Textbox 2"'
    ), "Test failed"
示例#7
0
def test_value__setting_value_to_empty_only_allowed_when_no_tabs():
    t = Tabs(tabs=[Tab(text="Tab1", controls=[Button(text="OK")])])
    with pytest.raises(AssertionError):
        t.value = ""

    t = Tabs()
    t.value = ""

    assert t.value == ""
示例#8
0
 def __init__(self):
     self.tasks = []
     self.new_task = Textbox(placeholder="Whats needs to be done?", width="100%")
     self.tasks_view = Stack()
     self.filter = Tabs(
         value="all",
         on_change=self.tabs_changed,
         tabs=[Tab(text="all"), Tab(text="active"), Tab(text="completed")],
     )
     self.items_left = Text("0 items left")
     self.view = Stack(
         width="70%",
         controls=[
             Text(value="Todos", size="large", align="center"),
             Stack(
                 horizontal=True,
                 on_submit=self.add_clicked,
                 controls=[
                     self.new_task,
                     Button(primary=True, text="Add", on_click=self.add_clicked),
                 ],
             ),
             Stack(
                 gap=25,
                 controls=[
                     self.filter,
                     self.tasks_view,
                     Stack(
                         horizontal=True,
                         horizontal_align="space-between",
                         vertical_align="center",
                         controls=[
                             self.items_left,
                             Button(
                                 text="Clear completed", on_click=self.clear_clicked
                             ),
                         ],
                     ),
                 ],
             ),
         ],
     )
示例#9
0
    def __init__(self):
        self.tasks = []
        self.new_task = Textbox(placeholder='Whats needs to be done?', width='100%')
        self.tasks_view = Stack()

        self.filter = Tabs(value='all', on_change=self.tabs_changed, tabs=[
                Tab(text='all'),
                Tab(text='active'),
                Tab(text='completed')])

        self.view = Stack(width='70%', controls=[
            Text(value='Todos', size='large', align='center'),
            Stack(horizontal=True, on_submit=self.add_clicked, controls=[
                self.new_task,
                Button(primary=True, text='Add', on_click=self.add_clicked)]),
            Stack(gap=25, controls=[
                self.filter,
                self.tasks_view
            ])
        ])
示例#10
0
def tabs(page):

    message = Message(dismiss=True, visible=False)

    def tabs_changed(e):
        message.visible = True
        message.value = f'Tabs changed to "{e.control.value}", count increased'
        e.control.tabs[2].count += 1
        page.update()

    link_tabs = Tabs(margin=10,
                     on_change=tabs_changed,
                     tabs=[
                         Tab(text='Regular tab',
                             controls=[
                                 Stack(horizontal=True,
                                       controls=[
                                           Text('This is tab1'),
                                           Text('This is tab1 - line2')
                                       ])
                             ]),
                         Tab(icon='Globe',
                             text='Tab with icon',
                             controls=[
                                 Stack(gap=10,
                                       controls=[
                                           Text(value='This is tab2'),
                                           Text(value='This is tab2 - line2')
                                       ])
                             ]),
                         Tab(text='Tab with icon and count',
                             icon='Ringer',
                             count=0,
                             controls=[
                                 Stack(gap=10,
                                       controls=[
                                           Text('This is tab3'),
                                           Text('This is tab3 - line2')
                                       ])
                             ])
                     ])

    solid_tabs = Tabs(solid=True,
                      margin='10px',
                      tabs=[
                          Tab(text='JavaScript',
                              icon='Code',
                              count=10,
                              controls=[Textbox(label='Some textbox')]),
                          Tab(text='C#',
                              count=30,
                              controls=[Button(text='Hello button!')]),
                          Tab(text='Python',
                              count=0,
                              controls=[Text(value='Just text...')])
                      ])

    return Stack(
        gap=30,
        width='50%',
        controls=[
            message,
            Stack(controls=[
                Text("Link tabs with Change event", size="xLarge"), link_tabs
            ]),
            Stack(controls=[Text("Solid tabs", size="xLarge"), solid_tabs])
        ])
示例#11
0
def test_value__initialized_as_empty():
    t = Tabs()

    assert t.value == ""
示例#12
0
def test_value__emptying_tabs_after_initialization_clears_value_as_well():
    t = Tabs(tabs=[Tab(text="Tab1", controls=[Button(text="OK")])])
    t.tabs = None

    assert t.tabs == []
    assert t.value == ""
示例#13
0
def test_value__key_is_preferred():
    t = Tabs(tabs=[
        Tab(text="Tab1", key="first_tab_key", controls=[Button(text="OK")])
    ])

    assert t.value == "first_tab_key"
示例#14
0
def test_value__has_an_initial_value():
    t = Tabs(tabs=[Tab(text="Tab1", controls=[Button(text="OK")])])

    assert t.value == "Tab1"
示例#15
0
page.add(
    SpinButton(value=1,
               label='Level of satisfaction',
               min=0,
               max=10,
               step=1,
               icon='mail',
               width=200,
               onchange=spinbutton_changed))

page.add(
    Tabs(id='t1',
         value='Tabs101',
         tabs=[
             Tab(text='Tab1', controls=[Button(text='hello')]),
             Tab(text='Tab2', controls=[Text(value='this is text')]),
             Tab(text='Tab3')
         ],
         onchange=tabs_changed))

d = Dialog(title='Hello',
           open=True,
           controls=[Text(value='Are you sure?')],
           footer=[Button(text='OK'), Button(text="Cancel")])

d.footer.id = "myfooter"

#page.add(d)

id = d.footer.id
print(id)