def startup(self): # Window class # Main window of the application with title and size self.main_window = toga.MainWindow(self.name, size=(300, 150)) self.main_window.app = self switch_style = CSS(padding=24) # Add the content on the main window self.main_window.content = toga.Box( children=[ # Simple switch with label and callback function called toggled toga.Switch('Change Label', on_toggle=self.callbackLabel), # Switch with initial state toga.Switch('Initial state', is_on=True, style=CSS(margin_top=24)), # Switch with label and enable option toga.Switch('Disabled', enabled=False, style=CSS(margin_top=24)) ], style=CSS(padding=24)) # Show the main window self.main_window.show()
def build(app): item_set_1 = [ 'other selection 1', 'other selection 2', 'other selection 3', 'new item 4' ] item_set_2 = ['selection 1', 'selection 2', 'selection 3'] selection = toga.Selection( items=['selection 1', 'selection 2', 'selection 3'], style=CSS(margin=20)) def swap_selection(widget): selection.items = item_set_2 if selection.items == item_set_1 else item_set_1 def get_selection(widget): print(selection.value) def set_selection(widget): selection.value = 'selection 1' box = toga.Box(style=CSS(padding=20)) box.add(selection) box.add( toga.Box(children=[ toga.Button('Swap Items', on_press=swap_selection), toga.Button('Get Selected Item', on_press=get_selection), toga.Button('Set Selected Item', on_press=set_selection) ])) return box
def build(app): data = [] for x in range(5): data.append([str(x) for x in range(5)]) label = toga.Label('No row selected.') def selection_handler(widget, row): label.text = 'You selected row: {}'.format(row) if row is not None else 'No row selected' table = toga.Table(headings=['heading_{}'.format(x) for x in range(5)], data=data, style=CSS(flex=1), on_select=selection_handler) def insert_handler(widget): table.data.insert(0, [str(round(random() * 100)) for _ in range(5)]) table._impl.refresh() print('Rows', len(table.data.data)) def delete_handler(widget): if len(table.data.data) > 0: table.data.remove(table.data.data[0]) table._impl.refresh() else: print('Table is empty!') btn_style = CSS(flex=1) btn_insert = toga.Button('Insert Row', on_press=insert_handler, style=btn_style) btn_delete = toga.Button('Delete Row', on_press=delete_handler, style=btn_style) btn_box = toga.Box(children=[btn_insert, btn_delete], style=CSS(flex_direction='row')) box = toga.Box(children=[table, btn_box, label], style=CSS(flex=1, flex_direction='column', padding=10)) return box
def build(app): def on_load(widget): print('Finished loading!') print(widget.dom) def on_key(event, flag): print('Key down: ', event, ' Flag: ', flag) webview = toga.WebView(on_key_down=on_key, on_webview_load=on_load, style=CSS(flex=1)) url_input = toga.TextInput(initial='https://github.com/', style=CSS(flex=1, margin=5)) def load_page(widget): print('loading: ', url_input.value) webview.url = url_input.value def print_dom(widget): print(webview.dom) box = toga.Box(children=[ toga.Box(children=[ url_input, toga.Button('Go', on_press=load_page, style=CSS(width=50)), ], style=CSS(flex_direction='row', padding_top=25)), webview, toga.Box(children=[toga.Button('Print DOM', on_press=print_dom)]) ], style=CSS(flex_direction='column')) webview.url = url_input.value # Show the main window return box
def startup(self): # Window class # Main window of the application with title and size self.main_window = toga.MainWindow(self.name, size=(200, 200)) self.main_window.app = self # Common style of the inner boxes style_inner_box = CSS(flex_direction=ROW) # Button class # Simple button with label and callback function called when # hit the button button1 = toga.Button('Change Label', on_press=self.callbackLabel) # Button with label and enable option button2 = toga.Button('Disabled', enabled=False) # Button with label and style option button3 = toga.Button('Bigger', style=CSS(width=200)) # Button with label and callback function called when # hit the button button4 = toga.Button('Resize Window', on_press=self.callbackResize) # Box class # Container of components # Add components for the first row of the outer box inner_box1 = toga.Box(style=style_inner_box, children=[button1, button2, button3, button4]) # Button with label and margin style button5 = toga.Button('Far from home', style=CSS(margin=50)) # Button with label and RGB color button6 = toga.Button('RGB : Fashion') # , style=CSS(background_color='red')) # Button with label and string color button7 = toga.Button('String : Fashion') # , style=CSS(background_color='blue')) # Add components for the second row of the outer box inner_box2 = toga.Box(style=style_inner_box, children=[button5, button6, button7]) # Create the outer box with 2 rows outer_box = toga.Box(style=CSS(flex_direction=COLUMN, height=10), children=[inner_box1, inner_box2]) # Add the content on the main window self.main_window.content = outer_box # Show the main window self.main_window.show()
def build(app): content_left = toga.Box(style=CSS(padding=20)) content_right = toga.Box(style=CSS(padding=20)) for _ in range(10): content_left.add(toga.Button('Button {}'.format(_))) content_right.add(toga.Button('Button {}'.format(_))) split_container = toga.SplitContainer( content=[content_left, content_right]) return split_container
def build(app): left_container = toga.Table(['Hello', 'World']) left_container.insert(None, 'root1', 'value1') left_container.insert(None, 'root2', 'value2') left_container.insert(None, 'root3', 'value3') left_container.insert(1, 'root4', 'value4') for i in range(0, 100): left_container.insert(None, 'root%s' % (i + 5), 'value%s' % (i + 5)) right_content = toga.Box( style=CSS(flex_direction='column', padding_top=50)) for b in range(0, 10): right_content.add( toga.Button('Hello world %s' % b, on_press=button_handler, style=CSS(width=200, margin=20))) right_container = toga.ScrollContainer(horizontal=False) right_container.content = right_content split = toga.SplitContainer() split.content = [left_container, right_container] cmd1 = toga.Command(action1, 'Action 1', tooltip='Perform action 1', icon='icons/brutus.icns') cmd2 = toga.Command(action2, 'Action 2', tooltip='Perform action 2', icon=toga.TIBERIUS_ICON) cmd3 = toga.Command(action3, 'Action 3', tooltip='Perform action 3', icon='icons/cricket-72.png') def action4(widget): print("CALLING Action 4") cmd3.enabled = not cmd3.enabled cmd4 = toga.Command(action4, 'Action 4', tooltip='Perform action 4', icon='icons/brutus.icns') app.main_window.toolbar = [ cmd1, toga.SEPARATOR, cmd2, toga.SPACER, cmd3, toga.EXPANDING_SPACER, cmd4 ] return split
def make_codebox(): code_box = toga.Box(style=CSS(flex=1)) with open('make_a_window.py') as f: code_text = toga.MultilineTextInput( initial=f.read(), readonly=True, style=CSS(flex=1), ) code_box.add(code_text) return code_box
def startup(self): # Main window of the application with title and size self.main_window = toga.MainWindow(self.name, size=(700, 500)) self.main_window.app = self self.sliderValueLabel = toga.Label("slide me") # set up common styls label_style = CSS(flex=1, padding_right=24) box_style = CSS(flex_direction="row", padding=24) # Add the content on the main window self.main_window.content = toga.Box(children=[ toga.Box(style=box_style, children=[ toga.Label("default Slider -- range is 0 to 1", style=label_style), toga.Slider(), ]), toga.Box( style=box_style, children=[ toga.Label( "on a scale of 1 to 10, how easy is GUI with Toga?", style=label_style), toga.Slider(range=(1, 10), default=10), ]), toga.Box(style=box_style, children=[ toga.Label("Sliders can be disabled", style=label_style), toga.Slider(enabled=False), ]), toga.Box(style=box_style, children=[ toga.Label("give a Slider some style!", style=label_style), toga.Slider(style=CSS(margin=16, width=300)) ]), toga.Box( style=box_style, children=[ toga.Label( "use the 'on_slide' callback to respond to changes", style=label_style), toga.Slider(on_slide=self.my_on_slide, range=(-40, 58)), self.sliderValueLabel ]), ], style=CSS(padding=24)) self.main_window.show()
def startup(self): # Main window of the application with title and size self.main_window = toga.MainWindow(self.name, size=(640, 400)) self.main_window.app = self # set up common styls label_style = CSS(flex=1, padding_right=24) box_style = CSS(flex_direction="row", padding=24) # Add the content on the main window self.main_window.content = toga.Box(children=[ toga.Box( style=box_style, children=[ toga.Label("Select an element", style=label_style), toga.Selection(items=["Carbon", "Ytterbium", "Thulium"]) ]), toga.Box( style=box_style, children=[ toga.Label( "use the 'on_select' callback to respond to changes", style=label_style), toga.Selection(on_select=self.my_on_select, items=["Dubnium", "Holmium", "Zirconium"]) ]), toga.Box(style=box_style, children=[ toga.Label("Long lists of items should scroll", style=label_style), toga.Selection(items=dir(toga)), ]), toga.Box(style=box_style, children=[ toga.Label("use some style!", style=label_style), toga.Selection( style=CSS(width=200, padding=24), items=["Curium", "Titanium", "Copernicium"]) ]), toga.Box(style=box_style, children=[ toga.Label("Selection widgets can be disabled", style=label_style), toga.Selection(enabled=False) ]), ], style=CSS(padding=24)) self.main_window.show()
def build(app): #self.main_window = toga.MainWindow(self.name) # self.main_window.app = self box = toga.Box() table = toga.Table(headings=['Navigate', 'Size'], style=CSS(width=200,height=200)) # table.style = CSS(height=50, width=614) table.insert(None, 'root1', '5mb') table.insert(None, 'root2', '5mb') table.insert(None, 'root2.1', '5mb') table.insert(None, 'root2.2', "12") table.insert(None, 'root2.2.1', "1212") table.insert(None, 'root2.2.3', '23') table.insert(None, 'root2.2.2', '23') # box.add(toga.Label("Hello")) box.add(table) # box.add(toga.Label("World")) # self.main_window.content = box # self.main_window.show() return box
def build(app): box = toga.Box(style=CSS(flex=1, padding=20)) def on_select(widget, selection): print(widget) print(selection) def on_refresh(widget): print('refreshing this shit!') def on_delete(widget, row): print('deleting someting', widget, 'row', row) print(widget) dl = toga.DetailedList(data=['Item 0', 'Item 1', 'Item 2'], on_select=on_select, on_delete=on_delete) btn = toga.Button('My Button') dl.on_refresh = on_refresh dl.data = '1 2 3 4 5 6'.split(' ') box.add(dl) box.add(btn) return dl
def startup(self): # Set up main window self.main_window = toga.MainWindow(title=self.name) self.main_window.app = self self.partner = Eliza() self.chat = toga.DetailedList( data=[ { 'icon': toga.Icon('resources/brutus.png'), 'title': 'Brutus', 'subtitle': 'Hello. How are you feeling today?', } ], style=CSS(flex=1) ) # Buttons self.text_input = toga.TextInput(style=CSS(flex=1)) send_button = toga.Button('Send', on_press=self.handle_input, style=CSS(margin_left=10)) input_box = toga.Box( children=[ self.text_input, send_button ], style=CSS( flex_direction='row', padding=10, ) ) # Outermost box outer_box = toga.Box( children=[self.chat, input_box], style=CSS( flex=1, flex_direction='column' ) ) # Add the content on the main window self.main_window.content = outer_box # Show the main window self.main_window.show()
def build(app): box = toga.Box(style=CSS(flex=1, padding=20)) number_input = toga.NumberInput(min_value=100, max_value=200, step=1) box.add(number_input) def set_range(widget): number_input.range = (0, 10) btn = toga.Button('Set Range', on_press=set_range, style=CSS()) box.add(btn) def toggle_enabled(widget): number_input.enabled = not number_input.enabled toggle_btn = toga.Button('Toggle Enabled', on_press=toggle_enabled) box.add(toggle_btn) return box
def __init__(self, id=None, style=None, **config): self._id = id if id else identifier(self) self._parent = None self._children = None self._window = None self._app = None self._impl = None self.__container = None self._layout_in_progress = False self._config = config self.layout = Layout(self) if style: self.style = style.copy() else: self.style = CSS()
def build(app): label = toga.Label(text='Value: ') def on_slide(widget): label.text = 'Value: ' + str(widget.value) slider = toga.Slider(range=(0, 100), default=30, on_slide=on_slide, style=CSS()) box = toga.Box(style=CSS(padding=20)) box.add(slider) box.add(label) def toggle_enable(widget): slider.enabled = not slider.enabled box.add(toga.Button('Toggle Enabled', on_press=toggle_enable)) return box
def setUp(self): super().setUp() self.id = 'widget_id' self.style = CSS(padding=666) self.widget = toga.Widget(id=self.id, style=self.style, factory=toga_dummy.factory)
def setUp(self): self.id = 'widget_id' self.style = CSS(padding=666) self.factory = MagicMock(spec=toga_dummy.factory) self.widget = toga.Widget(id=self.id, style=self.style, factory=self.factory) self.widget._impl = MagicMock(spec=toga_dummy.widgets.base.Widget)
def __init__(self, id=None, style=None, factory=None): self._id = id if id else identifier(self) self._parent = None self._children = None self._window = None self._app = None self._impl = None self._layout_in_progress = False self.layout = Layout(self) if style: self.style = style.copy() else: self.style = CSS() self._font = None self.factory = get_platform_factory(factory)
def build(app): password_input = toga.PasswordInput() def callback(widget): print(password_input.value) password_input.clear() btn = toga.Button('Print Password & Clear', on_press=callback) return toga.Box(style=CSS(flex=1, padding=20), children=[password_input, btn])
def build(app): img_01 = toga.Image(path='icons/brutus-256.png') img_02 = toga.Image( path='https://dict.leo.org/img/leo/160x60/schriftzug-222990a1.png') image_view_01 = toga.ImageView(image=img_01) image_view_02 = toga.ImageView(image=img_02) box = toga.Box(style=CSS(flex=1)) box.add(image_view_01) box.add(image_view_02) return box
def create(self): super().create() self.html_view = toga.WebView( style=CSS( flex=1, width=984 if self.deck.aspect == '16:9' else 738, height=576 ), on_key_down=self.deck.on_key_press ) self.content = self.html_view
def startup(self): # Set up main window self.main_window = toga.MainWindow(self.name) self.main_window.app = self # Label to show responses. self.label = toga.Label('Ready.') widget = toga.DetailedList( data=[ { 'icon': toga.Icon('resources/brutus.png'), 'title': translation['string'], 'subtitle': translation['country'], } for translation in bee_translations ], on_select=self.on_select_handler, # on_delete=self.on_delete_handler, on_refresh=self.on_refresh_handler, style=CSS(flex=1) ) # Outermost box outer_box = toga.Box( children=[widget, self.label], style=CSS( flex=1, flex_direction='column', padding=10, min_width=500, min_height=300 ) ) # Add the content on the main window self.main_window.content = outer_box # Show the main window self.main_window.show()
def startup(self): # Set up main window self.main_window = toga.MainWindow(self.name) self.main_window.app = self # Label to show responses. label = toga.Label('Ready.') widget = toga.{{ cookiecutter.widget_name }}() # Buttons btn_style = CSS(flex=1) btn_do_stuff = toga.Button('Do stuff', on_press=self.do_stuff, style=btn_style) btn_clear = toga.Button('Clear', on_press=do_clear, style=btn_style) btn_box = toga.Box( children=[ btn_do_stuff, btn_clear ], style=CSS(flex_direction='row') ) # Outermost box outer_box = toga.Box( children=[btn_box, widget, label], style=CSS( flex=1, flex_direction='column', padding=10, min_width=500, min_height=300 ) ) # Add the content on the main window self.main_window.content = outer_box # Show the main window self.main_window.show()
def startup(self): self.main_window = toga.MainWindow(self.name) self.main_window.app = self self.webview = toga.WebView(style=CSS(flex=1)) self.url_input = toga.TextInput(initial='https://github.com/', style=CSS(flex=1, margin=5)) container = toga.Container(children=[ toga.Container(children=[ self.url_input, toga.Button('Go', on_press=self.load_page, style=CSS(width=50)) ], style=CSS(flex_direction='row')), self.webview ], style=CSS(flex_direction='column')) self.main_window.content = container self.webview.url = self.url_input.value # Show the main window self.main_window.show()
def make_toolbar(): toolbar_box = toga.Box(style=CSS( flex_direction='row', justify_content='space-between', padding=5, )) refresh_btn = toga.Button('Refresh') summary_label = toga.Label('???%', alignment=toga.RIGHT_ALIGNED) toolbar_box.add(refresh_btn) toolbar_box.add(summary_label) return toolbar_box
def startup(self): # Set up main window self.main_window = toga.MainWindow(self.name) self.main_window.app = self # Label to show responses. self.label = toga.Label('Ready.') self.tree = toga.Tree( headings=['Year', 'Title', 'Rating', 'Genre'], data=DecadeSource(), on_select=self.on_select_handler, style=CSS(flex=1) ) # Buttons btn_style = CSS(flex=1) btn_insert = toga.Button('Insert Row', on_press=self.insert_handler, style=btn_style) btn_box = toga.Box(children=[btn_insert], style=CSS(flex_direction='row')) # Outermost box outer_box = toga.Box( children=[btn_box, self.tree, self.label], style=CSS( flex=1, flex_direction='column', padding=10, min_width=500, min_height=300 ) ) # Add the content on the main window self.main_window.content = outer_box # Show the main window self.main_window.show()
def build(app): box = toga.Box(style=CSS(flex=1, padding=0)) root = {'root': []} data_source = toga.DictionaryDataSource(dict({'root': []})) # for _ in range(10): # data_source.insert(root, None, 'text {}'.format(_)) tree = toga.Tree(['Name'], data=data_source, style=CSS(flex=1)) root_node = data_source.root(0) root_node.icon = 'icons/cricket-72.png' for _ in reversed(range(100)): node = data_source.insert(parent=data_source.root(0), index=0, data=['Job_{}'.format(_)], icon='icons/cricket-72.png') if _ % 2 == 0: data_source.insert(parent=node, index=0, data='data', icon='icons/cricket-72.png') else: for _ in range(3): node2 = data_source.insert(parent=node, index=0, data='child', icon='icons/cricket-72.png') for x in range(3): node3 = data_source.insert(parent=node2, index=0, data='child', icon='icons/cricket-72.png') root_node.expanded = True box.add(tree) # box.add(toga.Button('Button')) return box
def build(app): def callback(widget): label.text = 'Switch State: {}'.format(widget.is_on) def btn_callback(widget): switch.label = str('Update Label: {}'.format(time.strftime('%H:%M:%S'))) switch.is_on = True if switch.is_on is False else False label.text = 'Switch State: {}'.format(switch.is_on) def enable_callback(widget): switch.enabled = True if switch.enabled is False else False switch = toga.Switch('My Switch', on_toggle=callback) button = toga.Button('Check/Uncheck Switch', on_press=btn_callback, style=CSS(width=200)) enable_btn = toga.Button('Enable/Disable Switch', on_press=enable_callback, style=CSS(width=200)) label = toga.Label('Switch State: {}'.format(switch.is_on)) style = CSS(flex=1, padding=20) box = toga.Box(style=style) box.add(switch) box.add(button) box.add(enable_btn) box.add(label) return box
def build(app): box = toga.Box(style=CSS(flex=1, padding=20)) def on_press(widget): print('Button: ', widget, ' was pressed!') btn = toga.Button('My Button', on_press=on_press) def activate(widget): btn.enabled = not btn.enabled btn_enabled = toga.Button('Enable/Disable Button', on_press=activate) box.add(btn) box.add(btn_enabled) return box