def checkboxes(): return Stack(gap=20, controls=[ Text("Checkboxes", size="xLarge"), Checkbox(label='Unchecked checkbox', value=False), Checkbox(label='Checked checkbox', value=True), Checkbox(label='Disabled checkbox', disabled=True), Checkbox(label="Checkbox with rendered box_side='End'", box_side='End'), checkbox_with_on_change() ])
def test_checkbox_add(): c = Checkbox(label="Do you agree?", value=True, visible=True, box_side='side1', data='data1') assert isinstance(c, pglet.Control) assert isinstance(c, pglet.Checkbox) #raise Exception(s.get_cmd_str()) assert c.get_cmd_str() == ( 'checkbox boxSide="side1" data="data1" label="Do you agree?" ' 'value="true" visible="true"'), "Test failed"
def test_checkbox_add(): c = Checkbox(label="Do you agree?", value=True, visible=True, box_side="start", data="data1") assert isinstance(c, pglet.Control) assert isinstance(c, pglet.Checkbox) assert c.get_cmd_str() == [ Command( indent=0, name=None, values=["checkbox"], attrs={"boxside": "start", "data": "data1", "label": "Do you agree?", "value": "true", "visible": "true"}, lines=[], commands=[], ) ], "Test failed"
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])
def checkbox_with_on_change(): def checkbox_changed(e): t.value = f"Checkbox value changed to {c.value}" stack.update() c = Checkbox('Checkbox with on_change event', on_change=checkbox_changed) t = Text() stack = Stack(controls=[c, t]) return stack
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])
def add_clicked(self, e): self.tasks_view.controls.append(Checkbox(label=self.new_task.value)) self.tasks_view.update()
def main(page): page.title = "Grid example" page.update() # Basic grid page.add( Text("Basic grid", size="large"), Stack( width="50%", controls=[ Grid( columns=[ Column(name="First name", field_name="first_name"), Column(name="Last name", field_name="last_name"), Column(name="Age", field_name="age"), ], items=[ Person(first_name="John", last_name="Smith", age=30), Person(first_name="Samantha", last_name="Fox", age=43), Person(first_name="Alice", last_name="Brown", age=25), ], ) ], ), ) # Sortable grid page.add( Text("Sortable grid with resizable columns and selectable rows", size="large"), Grid( selection_mode="single", preserve_selection=True, columns=[ Column( resizable=True, sortable="string", name="First name", field_name="first_name", ), Column( resizable=True, sortable="string", sorted="asc", name="Last name", field_name="last_name", ), Column(resizable=True, sortable="number", name="Age", field_name="age"), ], items=[ Person(first_name="John", last_name="Smith", age=30), Person(first_name="Samantha", last_name="Fox", age=43), Person(first_name="Alice", last_name="Brown", age=25), ], ), ) # Compact grid page.add( Text("Compact grid with no header and multiple selection", size="large"), Grid( compact=True, header_visible=False, selection_mode="multiple", preserve_selection=True, columns=[ Column(max_width=100, field_name="first_name"), Column(max_width=100, field_name="last_name"), Column(max_width=100, field_name="age"), ], items=[ Person(first_name="John", last_name="Smith", age=30), Person(first_name="Samantha", last_name="Fox", age=43), Person(first_name="Alice", last_name="Brown", age=25), ], ), ) # Dynamic grid grid = None def delete_records(e): for r in grid.selected_items: grid.items.remove(r) page.update() delete_records = toolbar.Item(text="Delete records", icon="Delete", disabled=True, on_click=delete_records) grid_toolbar = Toolbar(items=[delete_records]) def grid_items_selected(e): delete_records.disabled = len(e.control.selected_items) == 0 delete_records.update() grid = Grid( selection_mode="multiple", compact=True, header_visible=True, columns=[ Column(name="First name", template_controls=[Textbox(value="{first_name}")]), Column(name="Last name", template_controls=[Textbox(value="{last_name}")]), Column(name="Age", template_controls=[Text(value="{age}")]), Column( name="Favorite color", template_controls=[ Dropdown( value="{color}", options=[ dropdown.Option("red", "Red"), dropdown.Option("green", "Green"), dropdown.Option("blue", "Blue"), ], ) ], ), Column(name="Is employee", template_controls=[Checkbox(value_field="employee")]), ], items=[ Person( first_name="John", last_name="Smith", age=30, employee=False, color="blue", ), Person( first_name="Jack", last_name="Brown", age=43, employee=True, color="green", ), Person(first_name="Alice", last_name="Fox", age=25, employee=False), ], margin=0, on_select=grid_items_selected, ) first_name = Textbox("First name") last_name = Textbox("Last name") age = Textbox("Age") def add_record(e): grid.items.append( Person( first_name=first_name.value, last_name=last_name.value, age=age.value, employee=True, )) first_name.value = "" last_name.value = "" age.value = "" page.update() page.add( Text("Dynamic grid with template columns", size="large"), grid_toolbar, grid, Text("Add new employee record", size="medium"), Stack(horizontal=True, controls=[first_name, last_name, age]), Button("Add record", on_click=add_record), )
def main(page): page.title = "Grid example" page.update() # Basic grid page.add( Text("Basic grid", size='large'), Stack(width='50%', controls=[ Grid(columns=[ Column(name="First name", field_name="first_name"), Column(name="Last name", field_name="last_name"), Column(name="Age", field_name="age") ], items=[ Person(first_name='John', last_name='Smith', age=30), Person(first_name='Samantha', last_name='Fox', age=43), Person(first_name='Alice', last_name='Brown', age=25) ]) ])) # Sortable grid page.add( Text("Sortable grid with resizable columns and selectable rows", size='large'), Grid(selection_mode='single', preserve_selection=True, columns=[ Column(resizable=True, sortable='string', name="First name", field_name="first_name"), Column(resizable=True, sortable='string', sorted='asc', name="Last name", field_name="last_name"), Column(resizable=True, sortable='number', name="Age", field_name="age") ], items=[ Person(first_name='John', last_name='Smith', age=30), Person(first_name='Samantha', last_name='Fox', age=43), Person(first_name='Alice', last_name='Brown', age=25) ])) # Compact grid page.add( Text("Compact grid with no header and multiple selection", size='large'), Grid(compact=True, header_visible=False, selection_mode='multiple', preserve_selection=True, columns=[ Column(max_width=100, field_name="first_name"), Column(max_width=100, field_name="last_name"), Column(max_width=100, field_name="age") ], items=[ Person(first_name='John', last_name='Smith', age=30), Person(first_name='Samantha', last_name='Fox', age=43), Person(first_name='Alice', last_name='Brown', age=25) ])) # Dynamic grid grid = None def delete_records(e): for r in grid.selected_items: grid.items.remove(r) page.update() delete_records = toolbar.Item(text="Delete records", icon='Delete', disabled=True, on_click=delete_records) grid_toolbar = Toolbar(items=[delete_records]) def grid_items_selected(e): delete_records.disabled = (len(e.control.selected_items) == 0) delete_records.update() grid = Grid( selection_mode='multiple', compact=True, header_visible=True, columns=[ Column(name='First name', template_controls=[Textbox(value="{first_name}")]), Column(name='Last name', template_controls=[Textbox(value="{last_name}")]), Column(name='Age', template_controls=[Text(value="{age}")]), Column(name='Is employee', template_controls=[Checkbox(value_field="employee")]) ], items=[ Person(first_name='John', last_name='Smith', age=30, employee=False), Person(first_name='Jack', last_name='Brown', age=43, employee=True), Person(first_name='Alice', last_name='Fox', age=25, employee=False) ], margin=0, on_select=grid_items_selected) first_name = Textbox('First name') last_name = Textbox('Last name') age = Textbox('Age') def add_record(e): grid.items.append( Person(first_name=first_name.value, last_name=last_name.value, age=age.value, employee=True)) first_name.value = '' last_name.value = '' age.value = '' page.update() page.add(Text("Dynamic grid with template columns", size='large'), grid_toolbar, grid, Text("Add new employee record", size='medium'), Stack(horizontal=True, controls=[first_name, last_name, age]), Button("Add record", on_click=add_record))
inline=True, onchange=toggle_change)) page.add( Message(value='This is message', dismiss=True, ondismiss=message_dismissed, buttons=[ MessageButton(text='Yes, I agree', action='Yes'), MessageButton(text='No, I disagree', action='No') ])) page.add( Checkbox(value=True, label='I am a human', box_side='start', data='data to pass', onchange=checkbox_changed)) page.add( ChoiceGroup(value='colour', label='Select a colour:', data='data to pass', options=[ choicegroup.Option(key='Green', icon='Shop', icon_color='Green'), choicegroup.Option(key='Yellow') ], onchange=choicegroup_changed))
with pglet.page("panel-custom") as page: def button_clicked(e): p.light_dismiss = light_dismiss.value p.auto_dismiss = auto_dismiss.value p.blocking = blocking.value values.value = ( f"Panel properties are: {p.light_dismiss}, {p.auto_dismiss}, {p.blocking}." ) p.open = True page.update() values = Text() light_dismiss = Checkbox(label="Light dismiss", value=False) auto_dismiss = Checkbox(label="Auto-dismiss", value=True) blocking = Checkbox(label="Blocking", value=True) b = Button(text="Open panel", on_click=button_clicked) page.add(light_dismiss, auto_dismiss, blocking, b, values) t = Text("Content goes here") p = Panel( title="Panel with dismiss options", controls=[t], ) page.add(p) input()