Example #1
0
def buttons_with_icon():
    return Stack(horizontal=True,
                 controls=[
                     Button("Create account", icon='AddFriend', primary=True),
                     Button("New item", icon='Add'),
                     Button("Delete", icon='Delete')
                 ])
def test_dialog_add():
    d = Dialog(open=True,
               title='Hello',
               sub_text='sub_text1',
               large_header=False,
               auto_dismiss=True,
               width=100,
               max_width=200,
               height=100,
               fixed_top=True,
               blocking=False,
               data='data1',
               controls=[Text(value='Are you sure?')],
               footer=[Button(text='OK'),
                       Button(text="Cancel")])

    assert isinstance(d, pglet.Control)
    assert isinstance(d, pglet.Dialog)
    assert d.get_cmd_str() == (
        'dialog autoDismiss="true" blocking="false" data="data1" fixedTop="true" '
        'height="100" largeHeader="false" maxWidth="200" open="true" subText="sub_text1" '
        'title="Hello" width="100"\n'
        '  text value="Are you sure?"\n'
        '  footer\n'
        '    button text="OK"\n'
        '    button text="Cancel"'), "Test failed"
Example #3
0
def main(page):
    page.update(Page(title="Counter"))
    page.clean()

    def on_click(e):
        try:
            count = int(page.get_value('number'))
            #if we get here the number is int
            page.send('set number errorMessage=""')

            if e.data == '+':
                page.set_value('number', count + 1)

            elif e.data == '-':
                page.set_value('number', count - 1)

        except ValueError:
            page.send('set number errorMessage="Please enter a number"')

    page.add(
        Stack(horizontal=True,
              controls=[
                  Button(text='-', onclick=on_click, data='-'),
                  Textbox(id='number', value='0', align='right'),
                  Button(text='+', onclick=on_click, data='+'),
              ]))
Example #4
0
 def __init__(self, app, name):
     self.app = app
     self.display_task = Checkbox(value=False,
                                  label=name,
                                  on_change=self.status_changed)
     self.edit_name = Textbox(width='100%')
     self.display_view = Stack(
         horizontal=True,
         horizontal_align='space-between',
         vertical_align='center',
         controls=[
             self.display_task,
             Stack(horizontal=True,
                   gap='0',
                   controls=[
                       Button(icon='Edit',
                              title='Edit todo',
                              on_click=self.edit_clicked),
                       Button(icon='Delete',
                              title='Delete todo',
                              on_click=self.delete_clicked)
                   ]),
         ])
     self.edit_view = Stack(visible=False,
                            horizontal=True,
                            horizontal_align='space-between',
                            vertical_align='center',
                            controls=[
                                self.edit_name,
                                Button(text='Save',
                                       on_click=self.save_clicked)
                            ])
     self.view = Stack(controls=[self.display_view, self.edit_view])
Example #5
0
def main(page):
    page.title = "Counter"
    page.update()

    def on_click(e):
        try:
            count = int(txt_number.value)

            txt_number.error_message = ""

            if e.data == "+":
                txt_number.value = count + 1

            elif e.data == "-":
                txt_number.value = count - 1

        except ValueError:
            txt_number.error_message = "Please enter a number"

        page.update()

    txt_number = Textbox(value="0", align="right")

    page.add(
        Stack(
            horizontal=True,
            controls=[
                Button("-", on_click=on_click, data="-"),
                txt_number,
                Button("+", on_click=on_click, data="+"),
            ],
        ))
Example #6
0
def test_panel_add():
    p = Panel(
        open=True,
        title="Hello",
        type="small",
        auto_dismiss=True,
        light_dismiss=False,
        width=100,
        blocking=False,
        data="data1",
        controls=[Text(value="Are you sure?")],
        footer=[Button(text="OK"), Button(text="Cancel")],
    )

    assert isinstance(p, pglet.Control)
    assert isinstance(p, pglet.Panel)
    assert p.get_cmd_str() == [
        Command(
            indent=0,
            name=None,
            values=["panel"],
            attrs={
                "autodismiss": "true",
                "blocking": "false",
                "data": "data1",
                "lightdismiss": "false",
                "open": "true",
                "title": "Hello",
                "type": "small",
                "width": "100",
            },
            lines=[],
            commands=[],
        ),
        Command(indent=2,
                name=None,
                values=["text"],
                attrs={"value": "Are you sure?"},
                lines=[],
                commands=[]),
        Command(indent=2,
                name=None,
                values=["footer"],
                attrs={},
                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=[]),
    ], "Test failed"
Example #7
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"
Example #8
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"
Example #9
0
def compound_buttons():
    return Stack(horizontal=True,
                 controls=[
                     Button("Compound",
                            secondary_text='This is a secondary text',
                            compound=True),
                     Button("Primary compound",
                            secondary_text='This is a secondary text',
                            compound=True,
                            primary=True)
                 ])
Example #10
0
def link_buttons():
    return Stack(horizontal=True,
                 controls=[
                     Button(action=True,
                            icon='Globe',
                            text='Pglet website',
                            url='https://pglet.io',
                            new_window=True),
                     Button(icon='MyMoviesTV',
                            text='Go to Disney',
                            url='https://disney.com',
                            new_window=True)
                 ])
Example #11
0
def toolbar_buttons():
    return Stack(horizontal=True,
                 controls=[
                     Button(text="New item", toolbar=True, icon='Add'),
                     Button(text="Send", toolbar=True, icon='Mail'),
                     Button(text="Show example",
                            toolbar=True,
                            icon='ChevronDown'),
                     Button(text="Delete",
                            toolbar=True,
                            icon_color='red',
                            icon='Delete')
                 ])
Example #12
0
def regular_buttons():
    return Stack(controls=[
        Stack(horizontal=True,
              controls=[
                  Button("Standard"),
                  Button("Standard disabled", disabled=True)
              ]),
        Stack(horizontal=True,
              controls=[
                  Button("Primary", primary=True),
                  Button("Primary disabled", primary=True, disabled=True)
              ]),
        Stack(horizontal=True, controls=[button_with_on_click()])
    ])
Example #13
0
def test_add_text_inside_stack():
    text = Text(id="txt1", value='Hello, "world!"')
    button = Button(text="Super button")
    stack = Stack(id="header", controls=[text, button])

    assert stack.get_cmd_str() == [
        Command(indent=0,
                name=None,
                values=["stack"],
                attrs={"id": ("header", True)},
                lines=[],
                commands=[]),
        Command(
            indent=2,
            name=None,
            values=["text"],
            attrs={
                "value": 'Hello, "world!"',
                "id": ("txt1", True)
            },
            lines=[],
            commands=[],
        ),
        Command(indent=2,
                name=None,
                values=["button"],
                attrs={"text": "Super button"},
                lines=[],
                commands=[]),
    ], "Test failed"
Example #14
0
def test_nested_stacks_update():
    stack = Stack(controls=[
        Textbox(id="firstName"),
        Textbox(id="lastName"),
        Stack(horizontal=True, controls=[
            Button(id="ok", text="OK"),
            Button(id="cancel", text="Cancel")
        ])
    ])

    # open page
    p = pglet.page(no_window=True)
    ctrls = p.add(stack)

    assert ['_1', 'firstName', 'lastName', '_2', 'ok', 'cancel'] == [ctrls[0].id, ctrls[1].id, ctrls[2].id, ctrls[3].id, ctrls[4].id, ctrls[5].id], "Test failed"

    # empty update
    assert stack.get_cmd_str(update=True) == "", "Test failed"

    # update stack element
    ctrls[0].horizontal=True
    assert stack.get_cmd_str(update=True) == '"_1" horizontal="true"', "Test failed"

    # update inner elements
    ctrls[1].value = "John"
    ctrls[2].value = "Smith"
    ctrls[4].primary = True

    #raise Exception(stack.get_cmd_str(update=True))

    assert stack.get_cmd_str(update=True) == (
        '"firstName" value="John"\n'
        '"lastName" value="Smith"\n'
        '"ok" primary="true"'
    ), "Test failed"    

    

    # assert stack.get_cmd_str(update=True) == (
    #     'stack\n'
    #     '  textbox id="firstName"\n'
    #     '  textbox id="lastName"\n'
    #     '  stack horizontal="true"\n'
    #     '    button id="ok" text="OK"\n'
    #     '    button id="cancel" text="Cancel"'
    # ), "Test failed"
Example #15
0
def context_menu_buttons():
    return Stack(
        horizontal=True,
        controls=[
            Button(icon='Add',
                   text='New item',
                   menu_items=[
                       button.MenuItem(text='Email message', icon='Mail'),
                       button.MenuItem(text='Calendar event', icon='Calendar')
                   ]),
            Button(text='Button with sub-menus',
                   menu_items=[
                       button.MenuItem(
                           text='New',
                           icon='Add',
                           sub_menu_items=[
                               button.MenuItem(text='Email message',
                                               icon='Mail'),
                               button.MenuItem(text='Calendar event',
                                               icon='Calendar')
                           ]),
                       button.MenuItem(
                           text='Share',
                           icon='Share',
                           split=True,
                           sub_menu_items=[
                               button.MenuItem(text='Share to Twitter'),
                               button.MenuItem(text='Share to Facebook'),
                               button.MenuItem('Share to Somewhere'),
                               button.MenuItem(
                                   'Share to email',
                                   sub_menu_items=[
                                       button.MenuItem('Share to Outlook'),
                                       button.MenuItem('Share to Gmail')
                                   ])
                           ]),
                       button.MenuItem(divider=True),
                       button.MenuItem(text='To Pglet',
                                       icon='Globe',
                                       icon_color='green',
                                       url='https://pglet.io',
                                       new_window=True,
                                       secondary_text='New Window')
                   ]),
        ])
Example #16
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 == ""
Example #17
0
def main(page):
    def btn_click(e):
        name = txt_name.value
        page.clean(True)
        page.add(Text(f"Hello, {name}!"))

    txt_name = Textbox("Your name")

    page.add(txt_name, Button("Say hello!", on_click=btn_click))
Example #18
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"
Example #19
0
def split_buttons():
    return Stack(horizontal=True,
                 controls=[
                     Button(split=True,
                            text='Standard',
                            menu_items=[
                                button.MenuItem('Email message', icon='Mail'),
                                button.MenuItem('Calendar event',
                                                icon='Calendar')
                            ]),
                     Button(split=True,
                            primary=True,
                            text='Primary',
                            menu_items=[
                                button.MenuItem('Email message', icon='Mail'),
                                button.MenuItem('Calendar event',
                                                icon='Calendar')
                            ])
                 ])
Example #20
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
                             ),
                         ],
                     ),
                 ],
             ),
         ],
     )
Example #21
0
def test_nested_stacks_add():
    s = Stack(controls=[
        Textbox(id="firstName"),
        Textbox(id="lastName"),
        Stack(horizontal=True, controls=[
            Button(id="ok", text="OK", primary=True),
            Button(id="cancel", text="Cancel")
        ])
    ])
    assert isinstance(s, pglet.Control)
    assert isinstance(s, pglet.Stack)
    #raise Exception(s.get_cmd_str())
    assert s.get_cmd_str() == (
        'stack\n'
        '  textbox id="firstName"\n'
        '  textbox id="lastName"\n'
        '  stack horizontal="true"\n'
        '    button id="ok" primary="true" text="OK"\n'
        '    button id="cancel" text="Cancel"'
    ), "Test failed"
def change_items_in_choicegroup():
    def add_clicked(e):
        cg.options.append(choicegroup.Option(new_option.value))
        new_option.value = ''
        stack.update()

    cg = ChoiceGroup()
    new_option = Textbox(placeholder='Enter new item name')
    add = Button("Add", on_click=add_clicked)
    stack = Stack(
        controls=[cg, Stack(horizontal=True, controls=[new_option, add])])
    return stack
Example #23
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"
Example #24
0
def test_panel_add():
    p = Panel(open=True,
              title='Hello',
              type='small',
              auto_dismiss=True,
              light_dismiss=False,
              width=100,
              blocking=False,
              data='data1',
              controls=[Text(value='Are you sure?')],
              footer=[Button(text='OK'),
                      Button(text="Cancel")])

    assert isinstance(p, pglet.Control)
    assert isinstance(p, pglet.Panel)
    assert p.get_cmd_str() == (
        'panel Width="100" autoDismiss="true" blocking="false" data="data1" lightDismiss="false" '
        'open="true" title="Hello" type="small"\n'
        '  text value="Are you sure?"\n'
        '  footer\n'
        '    button text="OK"\n'
        '    button text="Cancel"'), "Test failed"
Example #25
0
def test_nested_stacks_add():
    s = Stack(
        controls=[
            Textbox(id="firstName"),
            Textbox(id="lastName"),
            Stack(
                horizontal=True,
                controls=[
                    Button(id="ok", text="OK", primary=True),
                    Button(id="cancel", text="Cancel"),
                ],
            ),
        ]
    )
    assert isinstance(s, pglet.Control)
    assert isinstance(s, pglet.Stack)
    # raise Exception(s.get_cmd_str())
    assert s.get_cmd_str() == [
        Command(indent=0, name=None, values=["stack"], attrs={}, lines=[], commands=[]),
        Command(indent=2, name=None, values=["textbox"], attrs={"id": ("firstName", True)}, lines=[], commands=[]),
        Command(indent=2, name=None, values=["textbox"], attrs={"id": ("lastName", True)}, lines=[], commands=[]),
        Command(indent=2, name=None, values=["stack"], attrs={"horizontal": "true"}, lines=[], commands=[]),
        Command(
            indent=4,
            name=None,
            values=["button"],
            attrs={"primary": "true", "text": "OK", "id": ("ok", True)},
            lines=[],
            commands=[],
        ),
        Command(
            indent=4,
            name=None,
            values=["button"],
            attrs={"text": "Cancel", "id": ("cancel", True)},
            lines=[],
            commands=[],
        ),
    ], "Test failed"
def change_items_in_dropdown():
    def add_clicked(e):
        d.options.append(dropdown.Option(new_option.value))
        d.value = new_option.value
        new_option.value = ''
        stack.update()

    d = Dropdown()
    new_option = Textbox(placeholder='Enter new item name')
    add = Button("Add", on_click=add_clicked)
    stack = Stack(
        controls=[d, Stack(horizontal=True, controls=[new_option, add])])
    return stack
Example #27
0
def test_button_add():
    b = Button(id="button1",
               text="My button",
               primary=True,
               data="this is data")
    assert isinstance(b, pglet.Control)
    assert isinstance(b, pglet.Button)
    assert b.get_cmd_str() == [
        Command(
            indent=0,
            name=None,
            values=["button"],
            attrs={
                "data": "this is data",
                "primary": "true",
                "text": "My button",
                "id": ("button1", True)
            },
            lines=[],
            commands=[],
        )
    ], "Test failed"
Example #28
0
def button_with_on_click():
    def button_clicked(e):
        #print(e)
        b.data += 1
        t.value = f"Button clicked {b.data} time(s)"
        stack.update()

    b = Button('Button with on_click event',
               on_click=button_clicked,
               title='Click me!',
               data=0)
    t = Text()
    stack = Stack(controls=[b, t])
    return stack
Example #29
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)
                             ])
                   ])
         ])
Example #30
0
 def __init__(self, app, name):
     self.app = app
     self.display_task = Checkbox(
         value=False, label=name, on_change=self.status_changed
     )
     self.edit_name = Textbox(width="100%")
     self.display_view = Stack(
         horizontal=True,
         horizontal_align="space-between",
         vertical_align="center",
         controls=[
             self.display_task,
             Stack(
                 horizontal=True,
                 gap="0",
                 controls=[
                     Button(
                         icon="Edit", title="Edit todo", on_click=self.edit_clicked
                     ),
                     Button(
                         icon="Delete",
                         title="Delete todo",
                         on_click=self.delete_clicked,
                     ),
                 ],
             ),
         ],
     )
     self.edit_view = Stack(
         visible=False,
         horizontal=True,
         horizontal_align="space-between",
         vertical_align="center",
         controls=[self.edit_name, Button(text="Save", on_click=self.save_clicked)],
     )
     self.view = Stack(controls=[self.display_view, self.edit_view])