def __init__(self, flex): """Initialize box.""" super().__init__(style=Pack(direction=COLUMN, flex=flex)) self.__title_input = self.__add_column_option("Title:") self.__residuals_title_input = self.__add_column_option( "Residuals title:") self.__xlabel_input = self.__add_column_option("X label:") self.__ylabel_input = self.__add_column_option("Y label:") self.__grid_switch = toga.Switch(label="Grid") self.__legend_switch = toga.Switch(label="Legend") self.add(LineBox(children=[self.__grid_switch, self.__legend_switch])) self.__x_domain_switch = toga.Switch( label="Custom X domain", on_toggle=lambda _: self.x_domain_switch_handler()) self.__x_min_title = toga.Label("X minimum:", style=Pack(visibility=HIDDEN)) self.__x_min_input = toga.TextInput(style=Pack(visibility=HIDDEN)) self.__x_max_title = toga.Label("X maximum:", style=Pack(visibility=HIDDEN)) self.__x_max_input = toga.TextInput(style=Pack(visibility=HIDDEN)) self.add( LineBox(children=[ self.__x_domain_switch, self.__x_min_title, self.__x_min_input, self.__x_max_title, self.__x_max_input, ]))
def startup(self): # Window class # Main window of the application with title and size self.main_window = toga.MainWindow(title=self.name, size=(300, 150)) switch_style = Pack(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=Pack(padding_top=24)), # Switch with label and enable option toga.Switch('Disabled', enabled=False, style=Pack(padding_top=24)) ], style=Pack(direction=COLUMN, padding=24)) # Show the main window self.main_window.show()
def startup(self): box = toga.Box() box.style.direction = COLUMN box.style.padding = 10 self.scroller = toga.ScrollContainer(horizontal=self.hscrolling, vertical=self.vscrolling) switch_box = toga.Box(style=Pack(direction=ROW)) switch_box.add( toga.Switch('vertical scrolling', is_on=self.vscrolling, on_toggle=self.handle_vscrolling)) switch_box.add( toga.Switch('horizontal scrolling', is_on=self.hscrolling, on_toggle=self.handle_hscrolling)) box.add(switch_box) for x in range(100): label_text = 'Label {}'.format(x) box.add(Item(label_text)) self.scroller.content = box self.main_window = toga.MainWindow(self.name, size=(400, 700)) self.main_window.content = self.scroller self.main_window.show()
def startup(self): box = toga.Box() box.style.direction = COLUMN box.style.padding = 10 self.scroller = toga.ScrollContainer(horizontal=self.hscrolling, vertical=self.vscrolling) switch_box = toga.Box(style=Pack(direction=ROW)) switch_box.add( toga.Switch('vertical scrolling', is_on=self.vscrolling, on_toggle=self.handle_vscrolling)) switch_box.add( toga.Switch('horizontal scrolling', is_on=self.hscrolling, on_toggle=self.handle_hscrolling)) box.add(switch_box) for x in range(100): label_text = 'Label {}'.format(x) box.add(Item(label_text)) self.scroller.content = box self.main_window = toga.MainWindow(self.name, size=(400, 700)) self.main_window.content = self.scroller self.main_window.show() self.commands.add( toga.Command(self.toggle_up, "Toggle Up", shortcut=toga.Key.MOD_1 + toga.Key.UP, group=toga.Group.VIEW, order=1), toga.Command(self.toggle_down, "Toggle Down", shortcut=toga.Key.MOD_1 + toga.Key.DOWN, group=toga.Group.VIEW, order=2), toga.Command(self.toggle_left, "Toggle Left", shortcut=toga.Key.MOD_1 + toga.Key.LEFT, group=toga.Group.VIEW, order=3), toga.Command(self.toggle_right, "Toggle Right", shortcut=toga.Key.MOD_1 + toga.Key.RIGHT, group=toga.Group.VIEW, order=4), )
def startup(self): # Main window of the application with title and size self.main_window = toga.MainWindow(title=self.name, size=(500, 500)) # the user may change the value with +/- buttons self.progress_adder = toga.ProgressBar() # the user may switch between "running" mode and a set value self.progress_runner = toga.ProgressBar(max=None) # set up common styles label_style = Pack(flex=1, padding_right=24) row_box_style = Pack(direction=ROW, padding=24) col_box_style = Pack(direction=COLUMN, padding=24) # Add the content on the main window self.main_window.content = toga.Box(style=col_box_style, children=[ toga.Box(style=col_box_style, children=[ toga.Label("Use the +/- buttons to change the progress", style=label_style), self.progress_adder, toga.Box(children=[ toga.Button("+", on_press=self.increase_progress, style=Pack(flex=1)), toga.Button("-", on_press=self.decrease_progress, style=Pack(flex=1)), ]), toga.Switch("Toggle running mode", on_toggle=self.toggle_running) ]), toga.Box(style=row_box_style, children=[ toga.Label("default ProgressBar", style=label_style), toga.ProgressBar(), ]), toga.Box(style=row_box_style, children=[ toga.Label("disabled ProgressBar", style=label_style), toga.ProgressBar(max=None, running=False), ]), toga.Box(style=row_box_style, children=[ toga.Label("indeterminate ProgressBar", style=label_style), toga.ProgressBar(max=None, running=True), ]), toga.Box(style=row_box_style, children=[ toga.Label("determinate ProgressBar", style=label_style), toga.ProgressBar(max=1, running=False, value=0.5), ]), toga.Box(style=row_box_style, children=[ toga.Label("running determinate ProgressBar", style=label_style), toga.ProgressBar(max=1, running=True, value=0.5), ]), ]) self.main_window.show()
def startup(self): # Controls self.index_stats_label = toga.Label('No tracks loaded, please index.', style=Pack(padding=10)) self.reindex_button = toga.Button('Index Collection', on_press=self.re_index) self.reindex_button.style.padding = 10 self.reindex_button.style.flex = 1 self.mock_switch = toga.Switch('Enable mock Sender', on_toggle=self.mock_switch_handler) self.mock_switch.style.padding = 10 self.mock_switch.style.flex = 1 top_box = toga.Box(style=Pack(direction=ROW), children=[self.reindex_button, self.mock_switch]) # Cover Art Image Preview self.img = toga.Image(os.getcwd() + "/resources/testcard720.png") self.img_view = toga.ImageView(id='img_view', image=self.img, style=Pack(flex=1)) self.img_label = toga.Label('Waiting for mock information...', style=Pack(padding=10)) bottom_box = toga.Box(children=[self.img_label, self.img_view], style=Pack(flex=1, direction=COLUMN)) main_box = toga.Box( style=Pack(direction=COLUMN), children=[self.index_stats_label, top_box, bottom_box]) self.main_window = toga.MainWindow(title=self.name, size=(400, 500)) self.main_window.content = main_box self.main_window.show() self.cache_file = os.getcwd() + "/tracks.p" self.mapping = { "A": { "play": False, "updated_at": 0 }, "B": { "play": False, "updated_at": 0 }, "C": { "play": False, "updated_at": 0 }, "D": { "play": False, "updated_at": 0 } }
def _library_section(self) -> toga.Widget: desc = "Choose HumbleBundle game types to be shown in your GOG Galaxy library." source_help = { SOURCE.DRM_FREE: "Games from www.humblebundle.com/home/library that have direct download for Windows, Mac or Linux", SOURCE.TROVE: "Games from Humble Trove games (requires to be an active or past subscriber).", SOURCE.KEYS: "Game keys to be redeemed in foreign services like Steam or Origin." } show_revealed_help = 'Check to show all game keys as separate games.\n' \ 'Uncheck to show only game keys that are already revealed\n' \ '(redeemed keys are usually reported by other Galaxy plugins).' description = toga.Label(desc, style=Pack(font_size=self.TEXT_SIZE_BIG, padding_bottom=12)) rows = [description] self.show_revealed_sw = toga.Switch( 'show_revealed_keys', on_toggle=self._on_revealed_switch, is_on=self._cfg.library.show_revealed_keys, enabled=SOURCE.KEYS in self._cfg.library.sources, style=Pack(padding_left=20, padding_top=2)) for s in SOURCE: sw = toga.Switch(s.value, on_toggle=self._on_source_switch, is_on=(s in self._cfg.library.sources)) sw.style.padding_bottom = 2 set_tooltip(sw, source_help[s]) rows.append(sw) set_tooltip(self.show_revealed_sw, show_revealed_help) rows.append(self.show_revealed_sw) if IS_MAC: # workaround for not working tooltip inp = toga.MultilineTextInput(readonly=True, style=Pack(padding_top=10)) inp.MIN_WIDTH = self.SIZE[0] - 50 for k, v in source_help.items(): inp.value += f'{k.value}: {v}\n' inp.value += f'show_revealed_help: {show_revealed_help}' rows.append(inp) lib_box = toga.Box(children=rows) lib_box.style.direction = 'column' lib_box.style.padding_bottom = 15 return lib_box
def __init__(self, plot_method, suffix, has_legend=True): """Initialize box.""" super().__init__(style=Pack(direction=COLUMN)) self.__base_name = None self.__ycolumn = None self.__xcolumn = None self.plot_method = plot_method self.suffix = suffix self.__title_input = self.__add_column_option("Title:") self.__x_log_scale = toga.Switch( label="X log scale", style=Pack(padding_left=SMALL_PADDING)) self.__y_log_scale = toga.Switch( label="Y log scale", style=Pack(padding_left=SMALL_PADDING)) self.__xlabel_input = self.__add_column_option("X label:", self.__x_log_scale) self.__ylabel_input = self.__add_column_option("Y label:", self.__y_log_scale) self.__grid_switch = toga.Switch(label="Grid") switches = [self.__grid_switch] self.__has_legend = has_legend if has_legend: self.__legend_switch = toga.Switch(label="Legend") switches.append(self.__legend_switch) self.add(LineBox(children=switches)) self.__x_domain_switch = toga.Switch( label="Custom X domain", on_toggle=lambda _: self.x_domain_switch_handler()) self.__x_min_title = toga.Label("X minimum:", style=Pack(visibility=HIDDEN)) self.__x_min_input = toga.TextInput(style=Pack(visibility=HIDDEN), validators=[Number()]) self.__x_max_title = toga.Label("X maximum:", style=Pack(visibility=HIDDEN)) self.__x_max_input = toga.TextInput(style=Pack(visibility=HIDDEN), validators=[Number()]) self.add( LineBox(children=[ self.__x_domain_switch, self.__x_min_title, self.__x_min_input, self.__x_max_title, self.__x_max_input, ]))
def setUp(self): self.switch = toga.Switch(label='A switch') # make a shortcut for easy use self.gtk_switch = self.switch._impl self.window = Gtk.Window() self.window.add(self.switch._impl.native)
def startup(self): # Window class # Main window of the application with title and size # Also make the window non-resizable and non-minimizable. self.main_window = toga.MainWindow(title=self.name, size=(800, 500), resizeable=False, minimizable=False) self.a_button = toga.Button("A", on_press=self.on_button_press) self.b_button = toga.Button("B", on_press=self.on_button_press) self.c_button = toga.Button("C", on_press=self.on_button_press) self.text_input = toga.TextInput( placeholder="I get focused on startup.", style=Pack(height=25, width=200, font_size=10)) self.switch = toga.Switch("Switch", on_toggle=self.on_switch_toggle) self.info_label = toga.Label( "Use keyboard shortcuts to focus on the different widgets", style=Pack(font_size=10)) # Add the content on the main window self.main_window.content = toga.Box( style=Pack(direction=COLUMN), children=[ toga.Box( children=[self.a_button, self.b_button, self.c_button]), toga.Box(children=[self.text_input]), toga.Box(children=[self.switch]), toga.Box(children=[self.info_label]) ]) self.commands.add( toga.Command(lambda widget: self.focus_with_label(self.a_button), label="Focus on A", shortcut=toga.Key.MOD_1 + "a", group=WIDGETS_GROUP), toga.Command(lambda widget: self.focus_with_label(self.b_button), label="Focus on B", shortcut=toga.Key.MOD_1 + "b", group=WIDGETS_GROUP), toga.Command(lambda widget: self.focus_with_label(self.c_button), label="Focus on C", shortcut=toga.Key.MOD_1 + "c", group=WIDGETS_GROUP), toga.Command( lambda widget: self.focus_on(self.text_input, "TextInput"), label="Focus on text input", shortcut=toga.Key.MOD_1 + "t", group=WIDGETS_GROUP), toga.Command(lambda widget: self.focus_with_label(self.switch), label="Focus on switch", shortcut=toga.Key.MOD_1 + "s", group=WIDGETS_GROUP)) # Show the main window self.main_window.show() self.text_input.focus()
def startup(self): """ Construct and show the Toga application. Usually, you would add your application to a main content box. We then create a main window (with a name matching the app), and show the main window. """ main_box = toga.Box(style=Pack(direction=COLUMN)) message_label = toga.Label("Message to be placed on image: ", style=Pack(padding=(0, 5))) self.message_input = toga.TextInput(style=Pack(flex=1)) message_box = toga.Box(style=Pack(direction=ROW, padding=5)) message_box.add(message_label) message_box.add(self.message_input) # Whether text shadow should be added or not shadow_box = toga.Box(style=Pack(direction=ROW, padding=5)) shadow_label = toga.Label("Add shadow to text ", style=Pack(padding=(5))) self.shadow_check = toga.Switch("", style=Pack(padding=5)) shadow_box.add(shadow_label) shadow_box.add(self.shadow_check) main_box.add(shadow_box) noise_box = toga.Box(style=Pack(direction=ROW, padding=5)) main_box.add(noise_box) # The amount of graphics to be overlaid on the image noise_modifier_label = toga.Label("Amount of background images ", style=Pack(padding=(20, 5))) self.noise_modifier = toga.NumberInput(min_value=0, max_value=4, default=2, style=Pack(padding=(20, 5))) noise_box.add(noise_modifier_label) noise_box.add(self.noise_modifier) self.main_window = toga.MainWindow(title=self.formal_name) submit_button = toga.Button("Submit!", on_press=self.submit, style=Pack(padding=5)) main_box.add(message_box) main_box.add(submit_button) self.main_window.content = main_box self.main_window.show()
def startup(self): # Window class # Main window of the application with title and size # Also make the window non-resizable and non-minimizable. self.main_window = toga.MainWindow( title=self.name, size=(800, 500), resizeable=False, minimizable=False ) self.yellow_button = toga.Button( label="Set yellow color", on_press=self.set_yellow_color, style=Pack(background_color=YELLOW), ) self.inner_box = toga.Box( style=Pack(direction=ROW), children=[ toga.Button( label="Set red color", on_press=self.set_red_color, style=Pack(background_color=RED), ), self.yellow_button, toga.Button( label="Set blue color", on_press=self.set_blue_color, style=Pack(background_color=BLUE), ), toga.Button( label="Set green color", on_press=self.set_green_color, style=Pack(background_color=GREEN), ), toga.Button( label="Reset color", on_press=self.reset_color, style=Pack(background_color=WHITE), ), ], ) # Create the outer box with 2 rows self.outer_box = toga.Box( style=Pack(direction=COLUMN, flex=1), children=[ self.inner_box, toga.Label(text="Hello to my world!", style=Pack(text_align=CENTER)), toga.Switch( "Enable yellow", is_on=True, on_toggle=self.toggle_yellow_button ), ], ) # Add the content on the main window self.main_window.content = self.outer_box # Show the main window self.main_window.show()
def __init__(self, on_save_output): """Initialize box.""" super().__init__(style=Pack(direction=COLUMN)) self.output_directory_input = toga.TextInput(style=Pack(flex=1)) self.add( LineBox( children=[ toga.Label(text="Output directory:"), self.output_directory_input, toga.Button( label="Choose directory", on_press=self.choose_output_dir, style=Pack(padding_left=SMALL_PADDING), ), toga.Button( label="Save", on_press=on_save_output, style=Pack( padding_left=SMALL_PADDING, padding_right=SMALL_PADDING ), ), ] ) ) self.plot_data_checkbox = toga.Switch(label="Data", is_on=False) self.plot_fitting_checkbox = toga.Switch(label="Fitting", is_on=True) self.plot_residuals_checkbox = toga.Switch(label="Residuals", is_on=True) self.result_text_checkbox = toga.Switch(label="Result text", is_on=True) self.result_json_checkbox = toga.Switch(label="Result json", is_on=False) self.add( LineBox( children=[ self.plot_data_checkbox, self.plot_fitting_checkbox, self.plot_residuals_checkbox, self.result_text_checkbox, self.result_json_checkbox, ] ) )
def startup(self): # Main window of the application with title and size self.main_window = toga.MainWindow(self.name, size=(400, 400)) self.main_window.app = self # the user may change the value with +/- buttons self.progress2 = toga.ProgressBar(value=0) # the user may switch between "running" mode and a set value self.progress3 = toga.ProgressBar(value=3) # 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 ProgressBar", style=label_style), toga.ProgressBar(), ]), toga.Box(style=CSS(padding=24), children=[ toga.Label("Use the +/- buttons to change the progress", style=label_style), self.progress2, toga.Box( children=[ toga.Button("+", on_press=self.increase_progress2, style=CSS(margin=8, flex=1)), toga.Button("-", on_press=self.decrease_progress2, style=CSS(margin=8, flex=1)), ], style=CSS(flex=1, flex_direction="row") ), ]), toga.Box(style=box_style, children=[ toga.Switch("Toggle running mode") self.progress3 ]) ], style=CSS(padding=24) ) self.main_window.show()
def __init__(self, fitting_data: FittingData, app: toga.App): """Initialize window.""" super().__init__(title="Choose Records", size=RECORD_WINDOW_SIZE) main_box = toga.Box(style=Pack(direction=COLUMN)) data_box = toga.Box() self.__checkboxes = [ toga.Switch( label="", is_on=fitting_data.is_selected(i), style=Pack(height=LINE_HEIGHT), ) for i in range(1, fitting_data.length + 1) ] data_box.add( toga.Box( style=Pack( flex=1, direction=COLUMN, padding_left=SMALL_PADDING, padding_right=SMALL_PADDING, ), children=[ toga.Label(text="Chosen", style=Pack(height=LINE_HEIGHT)) ] + self.__checkboxes, # noqa: W503 )) for header, column in fitting_data.data.items(): data_box.add( toga.Box( style=Pack( flex=1, direction=COLUMN, padding_left=SMALL_PADDING, padding_right=SMALL_PADDING, ), children=[ toga.Label(text=header, style=Pack(height=LINE_HEIGHT)) ] + [ # noqa: W503 toga.Label(text=element, style=Pack(height=LINE_HEIGHT)) for element in column ], )) main_box.add(data_box) main_box.add( LineBox(children=[ toga.Button(label="Save", on_press=self.save_action(fitting_data)) ], )) scroller = toga.ScrollContainer(content=main_box) self.content = scroller self.app = app
def setUp(self): super().setUp() self.label = 'Test Label' def callback(widget): pass self.on_toggle = callback self.is_on = True self.enabled = True self.switch = toga.Switch(self.label, on_toggle=self.on_toggle, is_on=self.is_on, enabled=self.enabled, factory=toga_dummy.factory)
def __init__(self, flex): """Initialize box.""" super(PlotConfigurationBox, self).__init__(style=Pack(direction=COLUMN, flex=flex)) self.__title_input = self.__add_column_option("Title:") self.__residuals_title_input = self.__add_column_option( "Residuals title:") self.__xlabel_input = self.__add_column_option("X label:") self.__ylabel_input = self.__add_column_option("Y label:") self.__grid_switch = toga.Switch( label="Grid", on_toggle=lambda _: self.reset_plot_configuration(), ) self.add(LineBox(children=[self.__grid_switch]))
def setUp(self): self.factory = MagicMock() self.factory.Switch = MagicMock(return_value=MagicMock( spec=toga_dummy.factory.Switch)) self.label = 'Test Label' def callback(widget): pass self.on_toggle = callback self.is_on = True self.enabled = True self.switch = toga.Switch(self.label, on_toggle=self.on_toggle, is_on=self.is_on, enabled=self.enabled, factory=self.factory)
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 day_switch(day): return toga.Switch(day, on_toggle=toggle_day, style=switch_font)
def startup(self): self.main_window = toga.MainWindow(title=self.name, size=(640, 400)) label_style = Pack(flex=1, padding_right=24) box_style_horiz = Pack(direction=ROW, padding=15) box_style_verti = Pack(direction=COLUMN, padding=15) #selections self.portselect = toga.Selection(items=serial_ports()) self.chipselect = toga.Selection(items=["ESP8266", "ESP32"], on_select=self.update_selections) self.verselect = toga.Selection(items=[ "v1.8.7", "v1.9.0", "v1.9.1", "v1.9.2", "v1.9.3", "v1.9.4", "v1.10.0" ]) #puerto self.port = None self.port_open = False #switchs self.switchdio = toga.Switch('DIO', is_on=False, style=Pack(padding_left=10, padding_top=5)) #textinputs self.textfile = toga.TextInput(style=Pack(flex=1, width=200)) self.commandesp = toga.TextInput(style=Pack(flex=1, width=450)) #intento de terminal self.textterminal = toga.MultilineTextInput(id='terminal') #textoutputs self.textoutputs = toga.MultilineTextInput(id='output') self.filelabel = toga.Label("No ha seleccionado ningun archivo", style=Pack(padding=2)) self.fname = None # definir los hijos del main box afuera del main box left_box = toga.Box(style=box_style_verti) left_box.add( toga.Box(style=Pack(direction=ROW, padding_left=25), children=[ self.portselect, self.chipselect, self.verselect, self.switchdio ])) left_box.add( toga.Box(style=Pack(direction=COLUMN, padding_top=7), children=[ toga.Button("Ver archivos en ESP", on_press=self.read_files, style=Pack(padding_top=15, padding_left=2)), toga.Button("Seleccionar archivo", on_press=self.action_open_file_dialog, style=Pack(padding=2)), self.filelabel, toga.Button("Ejecutar archivo en ESP", on_press=self.run_in_esp, style=Pack(padding=2)), toga.Button("Grabar archivo en ESP", on_press=self.save_to_esp, style=Pack(padding=2)), self.textfile, toga.Button("Borrar archivo de ESP", on_press=self.erase_from_esp, style=Pack(padding=2)), toga.Button("Obtener archivo de ESP", on_press=self.get_file_esp, style=Pack(padding=2)), self.textoutputs ])) # Cambio en la estructura de los boxes para que funcione el rendering de los hijos en Windows, el bug es propio de toga al momento de presentar los boxes # Agregar hijos de right_box # right_box = toga.Box(style=box_style_verti) # right_box.add(toga.Button("Flashear",on_press=self.flash, style=Pack(padding=2))) # right_box.add(toga.Button("Borrar flash/firmware",on_press=self.eraseflash, style=Pack(padding=2))) # right_box.add(toga.Button("Actualizar puertos",on_press=self.update_ports, style=Pack(padding=2))) # right_box.add(toga.Button("Abrir puerto", on_press=self.open_port, style=Pack(padding=2))) # right_box.add(self.textterminal) # right_box.add(toga.Box(style=Pack(direction=ROW,padding_top=7), children=[ # self.commandesp, # toga.Button("Enviar comando", on_press=self.send_command, style=Pack(padding=2)) # ]) # ) left_box.add( toga.Button("Flashear", on_press=self.flash, style=Pack(padding=2))) left_box.add( toga.Button("Borrar flash/firmware", on_press=self.eraseflash, style=Pack(padding=2))) left_box.add( toga.Button("Actualizar puertos", on_press=self.update_ports, style=Pack(padding=2))) left_box.add( toga.Button("Abrir puerto", on_press=self.open_port, style=Pack(padding=2))) left_box.add(self.textterminal) left_box.add( toga.Box(style=Pack(direction=ROW, padding_top=7), children=[ self.commandesp, toga.Button("Enviar comando", on_press=self.send_command, style=Pack(padding=2)) ])) container = toga.Box() container.add(left_box) # container.add(right_box) self.main_window.content = container self.main_window.show()
def startup(self): self.main_window = toga.MainWindow(title=self.name, size=(640, 400)) label_style = Pack(flex=1, padding_right=24) box_style_horiz = Pack(direction=ROW, padding=15) box_style_verti = Pack(direction=COLUMN, padding=15) #selections self.portselect = toga.Selection(items=serial_ports()) self.chipselect = toga.Selection(items=["ESP8266", "ESP32"], on_select=self.update_selections) self.verselect = toga.Selection(items=[ "v1.8.7", "v1.9.0", "v1.9.1", "v1.9.2", "v1.9.3", "v1.9.4", "v1.10.0" ]) #puerto self.port = None self.port_open = False #switchs self.switchdio = toga.Switch('DIO', is_on=False, style=Pack(padding_left=10, padding_top=5)) #textinputs self.textfile = toga.TextInput(style=Pack(flex=1, width=200)) self.commandesp = toga.TextInput(style=Pack(flex=1, width=450)) #intento de terminal self.textterminal = toga.MultilineTextInput(readonly=False, style=Pack(flex=1, width=600, height=600)) #textoutputs self.textoutputs = toga.MultilineTextInput(readonly=True, style=Pack(flex=1, width=200, height=200)) #botones self.btnport = toga.Button("Abrir puerto", on_press=self.open_port, style=Pack(padding=2)) self.filelabel = toga.Label("No ha seleccionado ningun archivo", style=Pack(padding=2)) self.fname = None self.main_window.content = toga.Box(children=[ toga.Box( style=box_style_verti, children=[ toga.Box(style=Pack(direction=ROW, padding_left=25), children=[ self.portselect, self.chipselect, self.verselect, self.switchdio ]), toga.Box( style=Pack(direction=COLUMN, padding_top=7), children=[ toga.Button("Ver archivos en ESP", on_press=self.read_files, style=Pack(padding_top=15, padding_left=2)), toga.Button("Seleccionar archivo", on_press=self.action_open_file_dialog, style=Pack(padding=2)), self.filelabel, toga.Button("Ejecutar archivo en ESP", on_press=self.run_in_esp, style=Pack(padding=2)), toga.Button("Grabar archivo en ESP", on_press=self.save_to_esp, style=Pack(padding=2)), self.textfile, toga.Button("Borrar archivo de ESP", on_press=self.erase_from_esp, style=Pack(padding=2)), toga.Button("Obtener archivo de ESP", on_press=self.get_file_esp, style=Pack( padding=2)), self.textoutputs ]) ]), toga.Box(style=box_style_verti, children=[ toga.Button("Flashear", on_press=self.flash), toga.Button("Borrar flash/firmware", on_press=self.eraseflash), toga.Button("Actualizar puertos", on_press=self.update_ports), self.btnport, self.textterminal, toga.Box(style=Pack(direction=ROW, padding_top=7), children=[ self.commandesp, toga.Button("Enviar comando", on_press=self.send_command, style=Pack(padding=2)) ]) ]) ]) self.main_window.show()
def build(app): # EVENT HANDLERS def generate_seed(widget): random_seed = random.getrandbits(64) seed_input.value = random_seed # Creates two copies of the folder containing all the levels, one for backup and one which has # every core removed which is used whenever the randomizer is going to insert the cores. def init(widget): copy_tree(os.path.join(ots_path, 'level'), os.path.join(ots_path, 'level (backup)')) copy_tree(os.path.join(ots_path, 'level'), os.path.join(ots_path, 'level (cleaned)')) for level in vanilla_levels: removeCore(os.path.join(ots_path, 'level (cleaned)', level)) # Copies over the "clean" version of the levels, picks eleven random levels and a core # within each of them and then adds them to that level. def randomize(widget): copy_tree(os.path.join(ots_path,'level (cleaned)'), os.path.join(ots_path, 'level')) if seed_input.value: random.seed(seed_input.value) potential_levels = sorted([level for level in levels_and_cores.keys()]) if exclude_switch.is_on: potential_levels.remove('4_5.oel') random_levels = random.sample(potential_levels, 11) for level in random_levels: core = random.choice(levels_and_cores[level]) insertCore(os.path.join(ots_path, 'level', level), core) # Copies the backup folder to the normal level folder to restore the levels to normal def restore(widget): copy_tree(os.path.join(ots_path, 'level (backup)'), os.path.join(ots_path, 'level')) # GUI ELEMENTS # # INIT BUTTON # init_button = toga.Button('Initialize files (run only once)', on_press=init, style=Pack(height=30)) # RANDOM SEED # random_seed_box = toga.Box() seed_button = toga.Button('Generate seed', on_press=generate_seed,style=Pack(height=30, padding_top=5)) seed_input = toga.TextInput(style=Pack(padding=10, flex=1)) random_seed_box.add(seed_input) random_seed_box.add(seed_button) # EXCLUDE CHECKBOX # exclude_switch = toga.Switch('Exclude 4_5.oel (A New Hope)', is_on=True, style=Pack(padding=(5,10,5,10), flex=1)) # RANDOMIZE BUTTON # rand_button = toga.Button('Randomize collectibles', on_press=randomize, style=Pack(height=40, padding_top=10)) # RESTORE FROM BACKUP BUTTON # restore_button = toga.Button('Restore levels to normal', on_press=restore, style=Pack(height=40)) # MAIN LAYOUT main_box = toga.Box(style=Pack(direction=COLUMN, padding=10)) main_box.add(init_button) main_box.add(random_seed_box) main_box.add(exclude_switch) main_box.add(rand_button) main_box.add(restore_button) app.main_window.size = (350, 240) return main_box
def startup(self): """ Construct and show the Toga application. Usually, you would add your application to a main content box. We then create a main window (with a name matching the app), and show the main window. """ self.logger.info( "Starting Application\n------------------------------------------------" ) self.logger.info(str(self.paths.app)) self.facepack_dirs = set([ "African", "Asian", "Caucasian", "Central European", "EECA", "Italmed", "MENA", "MESA", "SAMed", "Scandinavian", "Seasian", "South American", "SpanMed", "YugoGreek" ]) self.mode_info = { "Overwrite": "Overwrites already replaced faces", "Preserve": "Preserves already replaced faces", "Generate": "Generates mapping from scratch." } os.makedirs(str(self.paths.app) + "/.config", exist_ok=True) if not os.path.isfile(str(self.paths.app) + "/.user/cfg.json"): shutil.copyfile( str(self.paths.app) + "/.user/default_cfg.json", str(self.paths.app) + "/.user/cfg.json") self.logger.info("Loading current profile") self.profile_manager = Profile_Manager( Config_Manager().get_latest_prf( str(self.paths.app) + "/.user/cfg.json"), str(self.paths.app)) self.profile_manager.migrate_config() self.logger.info("Creating GUI") self.main_box = toga.Box() self.logger.info("Created main box") self.hook = "https://discord.com/api/webhooks/796137178328989768/ETMNtPVb-PHuZPayC5G5MZD24tdDi5jmG6jAgjZXg0FDOXjy-VIabATXPco05qLIr4ro" # CREATE MENUBAR troubleshooting = toga.Command( lambda e=None, u= "https://github.com/Maradonna90/NewGAN-Manager/wiki/Troubleshooting": self.open_link(u), label='Troubleshooting', group=toga.Group.HELP, section=1) usage = toga.Command( lambda e=None, u="https://www.youtube.com/watch?v=iJqZNp0nomM": self.open_link(u), label='User Guide', group=toga.Group.HELP, section=0) faq = toga.Command( lambda e=None, u= "https://github.com/Maradonna90/NewGAN-Manager/wiki/FAQ": self. open_link(u), label='FAQ', group=toga.Group.HELP, section=2) discord = toga.Command( lambda e=None, u="https://discord.gg/UfRpJVc": self.open_link(u), label='Discord', group=toga.Group.HELP, section=3) self.commands.add(discord, faq, troubleshooting, usage) label_width = 125 # TOP Profiles prf_box = toga.Box() self.logger.info("Created prf_box") prf_inp = toga.TextInput() self.logger.info("Created prf_inp") self.prfsel_box = toga.Box() prf_lab = toga.Label(text="Create Profile: ") prf_lab.style.update(width=label_width) prfsel_lab = toga.Label(text="Select Profile: ") prfsel_lab.style.update(width=label_width) self.prfsel_lst = SourceSelection(items=list( self.profile_manager.config["Profile"].keys()), on_select=self._set_profile_status) self.prfsel_lst.value = self.profile_manager.cur_prf prfsel_btn = toga.Button( label="Delete", on_press=lambda e=None, c=self.prfsel_lst: self._delete_profile(c)) prf_btn = toga.Button(label="Create", on_press=lambda e=None, d=prf_inp, c=self. prfsel_lst: self._create_profile(d, c)) self.main_box.add(prf_box) prf_box.add(prf_lab) prf_box.add(prf_inp) prf_box.add(prf_btn) prf_lab.style.update(padding_top=7) prf_inp.style.update(direction=ROW, padding=(0, 20), flex=1) self.main_box.add(self.prfsel_box) self.prfsel_box.add(prfsel_lab) self.prfsel_box.add(self.prfsel_lst) self.prfsel_box.add(prfsel_btn) self.prfsel_lst.style.update(direction=ROW, padding=(0, 20), flex=1) prfsel_lab.style.update(padding_top=7) # MID Path selections dir_box = toga.Box() dir_lab = toga.Label(text="Select Image Directory: ") dir_lab.style.update(width=label_width) self.dir_inp = toga.TextInput( readonly=True, initial=self.profile_manager.prf_cfg['img_dir']) self.dir_inp.style.update(direction=ROW, padding=(0, 20), flex=1) self.dir_btn = toga.Button(label="...", on_press=self.action_select_folder_dialog, enabled=False) rtf_box = toga.Box() rtf_lab = toga.Label(text="RTF File: ") rtf_lab.style.update(width=label_width) self.rtf_inp = toga.TextInput( readonly=True, initial=self.profile_manager.prf_cfg['rtf']) self.rtf_inp.style.update(direction=ROW, padding=(0, 20), flex=1) self.rtf_btn = toga.Button(label="...", on_press=self.action_open_file_dialog, enabled=False) self.main_box.add(dir_box) self.main_box.add(rtf_box) dir_box.add(dir_lab) dir_box.add(self.dir_inp) dir_box.add(self.dir_btn) rtf_box.add(rtf_lab) rtf_box.add(self.rtf_inp) rtf_box.add(self.rtf_btn) dir_lab.style.update(padding_top=7) rtf_lab.style.update(padding_top=7) gen_mode_box = toga.Box() self.genmde_lab = toga.Label(text="Mode: ") self.genmde_lab.style.update(width=label_width) self.genmdeinfo_lab = toga.Label(text=self.mode_info["Generate"]) self.gendup = toga.Switch(label="Allow Duplicates?") self.genmde_lst = SourceSelection(items=list(self.mode_info.keys()), on_select=self.update_label) self.genmde_lst.value = "Generate" self.genmde_lst.style.update(direction=ROW, padding=(0, 20), flex=1) self.genmde_lab.style.update(padding_top=7) self.genmdeinfo_lab.style.update(padding_top=7) self.gendup.style.update(padding_top=7, padding_left=20) gen_mode_box.add(self.genmde_lab) gen_mode_box.add(self.genmde_lst) gen_mode_box.add(self.genmdeinfo_lab) gen_mode_box.add(self.gendup) self.main_box.add(gen_mode_box) # BOTTOM Generation gen_box = toga.Box() self.gen_btn = toga.Button(label="Replace Faces", on_press=self._replace_faces, enabled=False) self.gen_btn.style.update(padding_bottom=20) self.gen_lab = toga.Label(text="") # self.gen_prg = toga.ProgressBar(max=110) self.gen_prg = Progressbar(label=self.gen_lab) gen_box.add(self.gen_btn) gen_box.add(self.gen_lab) gen_box.add(self.gen_prg) self.main_box.add(gen_box) self.gen_prg.style.update(width=570, alignment="center") self.gen_lab.style.update(padding_top=20, padding_bottom=20, width=100, alignment="center") # Report bad image rep_box = toga.Box() self.rep_lab = toga.Label(text="Player UID: ") self.rep_lab.style.update(width=label_width) self.rep_inp = toga.TextInput(on_change=self.change_image) self.rep_img = toga.ImageView(toga.Image("resources/logo.png")) self.rep_img.style.update(height=180) self.rep_img.style.update(width=180) self.rep_btn = toga.Button(label="Report", on_press=self.send_report, enabled=False) rep_box.add(self.rep_lab) rep_box.add(self.rep_inp) rep_box.add(self.rep_img) rep_box.add(self.rep_btn) self.main_box.add(rep_box) self.rep_lab.style.update(padding_top=10) self.rep_inp.style.update(direction=ROW, padding=(0, 20), flex=1) # END config self.prfsel_box.style.update(padding_bottom=20) dir_box.style.update(padding_bottom=20) prf_box.style.update(padding_bottom=20) rtf_box.style.update(padding_bottom=20) gen_mode_box.style.update(padding_bottom=20) rep_box.style.update(padding_top=20) gen_box.style.update(direction=COLUMN, alignment='center') self.main_box.style.update(direction=COLUMN, padding=30, alignment='center') self.main_window = toga.MainWindow(title=self.formal_name, size=(1000, 600)) self.main_window.content = self.main_box self.main_window.show() self.check_for_update()
def __init__(self, fitting_data: FittingData, font_size: FontSize, app: toga.App): """Initialize window.""" super().__init__(title="Choose Records", size=RECORD_WINDOW_SIZE) self.__fitting_data = fitting_data main_box = toga.Box(style=Pack(direction=COLUMN)) data_box = toga.Box() statistics_box = toga.Box() font_size_value = FontSize.get_font_size(font_size) self.__update_on_check = True self.__statistics_labels = { (column, parameter): toga.Label( text=to_relevant_precision_string( getattr(fitting_data.statistics(column), parameter, 0)), style=Pack(height=LINE_HEIGHT, width=COLUMN_WIDTH, font_size=font_size_value), ) for column, parameter in itertools.product( fitting_data.all_columns, Statistics.parameters()) } self.__checkboxes = [ toga.Switch( label="", is_on=fitting_data.is_selected(i), on_toggle=self.select_records, style=Pack(height=LINE_HEIGHT, width=COLUMN_WIDTH, font_size=font_size_value), ) for i in range(1, fitting_data.length + 1) ] self.__all_checkbox = toga.Switch( label="", is_on=self.are_all_selected(), on_toggle=self.select_all, style=Pack(height=TITLES_LINE_HEIGHT, font_size=font_size_value), ) self.__selected_records_label = toga.Label( text="", style=Pack(font_size=font_size_value, width=COLUMN_WIDTH, height=TITLES_LINE_HEIGHT), ) data_box.add( toga.Box( style=Pack( flex=1, direction=COLUMN, padding_left=SMALL_PADDING, padding_right=SMALL_PADDING, ), children=[ toga.Box( style=Pack( height=TITLES_LINE_HEIGHT, font_size=font_size_value, ), children=[ self.__all_checkbox, self.__selected_records_label ], ), *self.__checkboxes, ], )) for header, column in fitting_data.data.items(): data_box.add( toga.Box( style=Pack( flex=1, direction=COLUMN, padding_left=SMALL_PADDING, padding_right=SMALL_PADDING, ), children=[ toga.Label( text=header, style=Pack( height=TITLES_LINE_HEIGHT, width=COLUMN_WIDTH, font_size=font_size_value, font_weight=BOLD, ), ), *[ toga.Label( text=to_relevant_precision_string(element), style=Pack( height=LINE_HEIGHT, width=COLUMN_WIDTH, font_size=font_size_value, ), ) for element in column ], ], )) main_box.add(data_box) main_box.add(toga.Divider()) statistics_box.add( toga.Box( style=Pack( flex=1, direction=COLUMN, padding_left=SMALL_PADDING, padding_right=SMALL_PADDING, ), children=[ toga.Label( text=parameter.replace("_", " ").title(), style=Pack( height=LINE_HEIGHT, width=COLUMN_WIDTH, font_size=font_size_value, font_weight=BOLD, ), ) for parameter in Statistics.parameters() ], )) for header, column in fitting_data.data.items(): statistics_box.add( toga.Box( style=Pack( flex=1, direction=COLUMN, padding_left=SMALL_PADDING, padding_right=SMALL_PADDING, ), children=[ self.__statistics_labels[(header, parameter)] for parameter in Statistics.parameters() ], )) main_box.add(statistics_box) main_box.add( LineBox(children=[ toga.Button(label="Close", on_press=lambda _: self.close()) ], )) scroller = toga.ScrollContainer(content=main_box) self.content = scroller self.app = app self.update()
def browser_switch(browser): return toga.Switch(browser, on_toggle=toggle_browser, style=switch_font)
def domain_switch(self, domain): return toga.Switch(label=domain, on_toggle=self.toggle_domain, style=switch_font)
def startup(self): # Set up main window self.main_window = toga.MainWindow(title=self.name, size=(750, 500)) self.canvas = toga.Canvas( style=Pack(flex=1), on_resize=self.refresh_canvas, on_press=self.on_press, on_drag=self.on_drag, on_release=self.on_release, on_alt_press=self.on_alt_press, on_alt_drag=self.on_alt_drag, on_alt_release=self.on_alt_release ) self.context_selection = toga.Selection(items=[STROKE, FILL], on_select=self.refresh_canvas) self.drawing_shape_instructions = { INSTRUCTIONS: self.draw_instructions, TRIANGLE: self.draw_triangle, TRIANGLES: self.draw_triangles, RECTANGLE: self.draw_rectangle, ELLIPSE: self.draw_ellipse, HALF_ELLIPSE: self.draw_half_ellipse, ICE_CREAM: self.draw_ice_cream, SMILE: self.draw_smile, SEA: self.draw_sea, STAR: self.draw_star, } self.dash_patterns = { CONTINUOUS: None, DASH_1_1: [1, 1], DASH_1_2: [1, 2], DASH_2_3_1: [2, 3, 1] } self.shape_selection = toga.Selection( items=list(self.drawing_shape_instructions.keys()), on_select=self.on_shape_change ) self.color_selection = toga.Selection( items=[BLACK, BLUE, GREEN, RED, YELLOW], on_select=self.refresh_canvas ) self.fill_rule_selection = toga.Selection( items=[value.name.lower() for value in FillRule], on_select=self.refresh_canvas ) self.line_width_slider = toga.Slider( range=(1, 10), default=1, on_slide=self.refresh_canvas ) self.dash_pattern_selection = toga.Selection( items=list(self.dash_patterns.keys()), on_select=self.refresh_canvas ) self.clicked_point = None self.translation = None self.rotation = 0 self.scale_x_slider = toga.Slider( range=(0, 2), default=1, tick_count=10, on_slide=self.refresh_canvas ) self.scale_y_slider = toga.Slider( range=(0, 2), default=1, tick_count=10, on_slide=self.refresh_canvas ) self.font_selection = toga.Selection( items=[ SYSTEM, MESSAGE, SERIF, SANS_SERIF, CURSIVE, FANTASY, MONOSPACE ], on_select=self.refresh_canvas ) self.font_size = toga.NumberInput( min_value=10, max_value=72, default=20, on_change=self.refresh_canvas ) self.italic_switch = toga.Switch( label="italic", on_toggle=self.refresh_canvas ) self.bold_switch = toga.Switch( label="bold", on_toggle=self.refresh_canvas ) label_style = Pack(font_size=10, padding_left=5) # Add the content on the main window box = toga.Box( style=Pack(direction=COLUMN), children=[ toga.Box( style=Pack(direction=ROW, padding=5), children=[ self.context_selection, self.shape_selection, self.color_selection, self.fill_rule_selection ] ), toga.Box( style=Pack(direction=ROW, padding=5), children=[ toga.Label("Line Width:", style=label_style), self.line_width_slider, self.dash_pattern_selection ] ), toga.Box( style=Pack(direction=ROW, padding=5), children=[ toga.Label("X Scale:", style=label_style), self.scale_x_slider, toga.Label("Y Scale:", style=label_style), self.scale_y_slider, toga.Button( label="Reset transform", on_press=self.reset_transform ) ] ), toga.Box( style=Pack(direction=ROW, padding=5), children=[ toga.Label("Font Family:", style=label_style), self.font_selection, toga.Label("Font Size:", style=label_style), self.font_size, self.bold_switch, self.italic_switch ] ), self.canvas ] ) self.main_window.content = box self.change_shape() self.render_drawing() # Show the main window self.main_window.show()
def startup(self): # Paths and files ospath = os.path.dirname(sys.argv[0]) self.CONFIG_FILE = ospath + '\\config' # Constants self.CHECKUP_TIME = 20 * 60 self.BREAK_TIME = 20 # Activity box activity_box = toga.Box( style=Pack(direction=COLUMN, background_color='aqua')) self.timer_running = False title_label = toga.Label('Eye Help', style=Pack(padding_left=50, padding_right=50, padding_top=20, font_family='monospace', font_size=30, font_weight='bold')) instruction = 'Start and stop timer to track your screen use and eye blinks' instructions_box = MultilineLabel(instruction, box_style=Pack(direction=COLUMN, padding_left=50, padding_top=10), label_style=Pack( padding_bottom=10, font_family='monospace', font_size=12), char_line=35) self.start_button = toga.Button('Start Timer!', on_press=self.begin_timer, style=Pack(padding_left=50, padding_right=50, padding_top=20, background_color='violet', height=50, font_family='monospace', font_size=20)) self.stop_button = toga.Button('Stop Timer!', on_press=self.stop_timer, style=Pack(padding_left=50, padding_right=50, padding_top=20, padding_bottom=10, background_color='violet', height=50, font_family='monospace', font_size=20), enabled=False) # https://www.healthline.com/health/how-many-times-do-you-blink-a-day blinks_label = MultilineLabel( 'It is recommended to blink 15 - 20 times in a minute', box_style=Pack(direction=COLUMN, padding_bottom=10, background_color='aqua'), label_style=Pack(padding_left=50, background_color='aqua', font_family='monospace', font_size=12), char_line=35) activity_box.add(title_label) activity_box.add(self.start_button) activity_box.add(self.stop_button) activity_box.add(instructions_box) activity_box.add(blinks_label) # Eye tips box # https://www.mayoclinic.org/diseases-conditions/eyestrain/diagnosis-treatment/drc-20372403 # https://www.health.ny.gov/prevention/tobacco_control/smoking_can_lead_to_vision_loss_or_blindness # https://www.health.harvard.edu/blog/will-blue-light-from-electronic-devices-increase-my-risk-of-macular-degeneration-and-blindness-2019040816365 self.eye_tips = [ 'Try to not to use very bright lighting as the glare can strain your eyes and make the screen harder to look at', 'Try to put light sources in places that do not directly shine on your eyes', 'Using non-prescripted eye drops can help relieve dry eyes. Try to get ones recommended by your doctor', 'Make sure you screens are at least an arms length away from your eyes', 'Improve the air quality the air by getting a humidifier or adjusting the thermostat', 'If you smoke, try to stop as it can lead to diseases related to vision loss', 'Low levels of blue light (emitted froms screens and most lights) do not affect your eyes, but high levels can be hazardous to your eyes', 'Blue light affects your biological clock (sleep cycle) so try to avoid screens and bright lights before or while you sleep', '20-20-20 Every 20 minutes focus at an object 20 feet far for at least 20 seconds', # done by timer '...' ] eye_tips_box = toga.Box(style=Pack( direction=COLUMN, padding_bottom=10, background_color='aqua')) for tip in self.eye_tips: tip_box = MultilineLabel(tip, box_style=Pack(direction=COLUMN, padding_bottom=10, background_color='wheat'), label_style=Pack(background_color='aqua', font_family='monospace', font_size=15), char_line=28) eye_tips_box.add(tip_box) eye_tips_scroll = toga.ScrollContainer(style=Pack( direction=COLUMN, padding=(5, 5), background_color='red')) eye_tips_scroll.content = eye_tips_box # Calibrate box calibrate_box = toga.Box( style=Pack(direction=COLUMN, background_color='aqua')) calibrate_info = toga.Label('You will be given instructions', style=Pack(padding_left=10, padding_top=10, font_family='monospace', font_size=15)) calibrate_button = toga.Button('Calibrate', style=Pack(padding_left=50, padding_right=50, padding_top=20, padding_bottom=20, background_color='violet', font_family='monospace', font_size=20), on_press=self.start_calibrate) calibrate_when = MultilineLabel( 'Use this if you feel that blinks are not being counted correctly', box_style=Pack(direction=COLUMN, padding_bottom=10, background_color='aqua'), label_style=Pack(padding_left=10, font_family='monospace', font_size=15)) graph_button = toga.Button('Graph Eye Aspect Ratio', style=Pack(padding_left=50, padding_right=50, padding_top=10, padding_bottom=10, background_color='violet', font_family='monospace', font_size=15), on_press=self.start_graph) EAR_definition = MultilineLabel( '*Eye aspect ratio is lower the more your eyes close', box_style=Pack(direction=COLUMN, padding_bottom=10, background_color='aqua'), label_style=Pack(padding_left=10, font_family='monospace', font_size=13)) # manual calibration is a work in progress manual_label = toga.Label('Manually calibrate (pick EAR) here', style=Pack(padding_left=10, padding_top=10, font_family='monospace', font_size=15)) manual_label2 = toga.Label('Pick a value that seems like a blink', style=Pack(padding_left=10, padding_top=10, font_family='monospace', font_size=15)) manual_input = toga.NumberInput(min_value=1, max_value=99, style=Pack(padding=(10, 50), width=50)) calibrate_box.add(calibrate_when) calibrate_box.add(calibrate_button) calibrate_box.add(calibrate_info) calibrate_box.add(graph_button) calibrate_box.add(EAR_definition) # Config box config_box = toga.Box( style=Pack(direction=COLUMN, background_color='aqua')) self.video_switch = toga.Switch('Show Video', style=Pack(padding_left=50, padding_right=50, padding_top=20, padding_bottom=20, font_family='monospace', font_size=20), is_on=self.tobool( self.read_config()[1])) save_button = toga.Button('Save Configuration', style=Pack(padding_left=50, padding_right=50, padding_top=20, padding_bottom=20, background_color='violet', font_family='monospace', font_size=20), on_press=self.save_config) reset_button = toga.Button('Reset Configuration', style=Pack(padding_left=50, padding_right=50, padding_top=20, padding_bottom=20, background_color='red', font_family='monospace', font_size=20), on_press=self.reset_config) config_box.add(self.video_switch) config_box.add(save_button) config_box.add(reset_button) # options - toolbar options = toga.OptionContainer(style=Pack(direction=ROW, background_color='snow', font_family='monospace', font_size=15)) options.add('Activity', activity_box) options.add('Eye tips', eye_tips_scroll) options.add('Calibrate', calibrate_box) options.add('Configure', config_box) main_box = toga.Box(style=Pack( padding=(10, 10), direction=COLUMN, background_color='snow')) main_box.add(options) # Create and show main window self.main_window = toga.MainWindow(title=self.formal_name, size=(640, 480), resizeable=False) self.main_window.content = main_box self.main_window.show()
def startup(self): """ Construct and show the Toga application. """ self.daw_project_name_title = toga.Label(text="Project name:", style=Pack(color="#808080")) self.daw_project_name = toga.Label('Waiting for data...') self.daw_project_name_container = toga.Box( children=[self.daw_project_name_title, self.daw_project_name], style=Pack(direction=ROW, padding=10)) hostname = socket.gethostname() local_ip = socket.gethostbyname(hostname) self.hostname_title = toga.Label(text="Listening on:", style=Pack(color="#808080")) self.hostname = toga.Label(local_ip + ":9000") self.hostname_container = toga.Box( children=[self.hostname_title, self.hostname], style=Pack(direction=ROW, padding=10)) self.twitch_input_label = toga.Label(text="Twitch settings") # Sets initial values from environment variables TWITCH_USER TWITCH_CHAN TWITCH_OAUTH # TODO Store from user input for next launch # BUG on Mac 11.1: the input values get erased if input focus changes to another input field # WORKAROUND: focus other application window after input self.twitch_user_input = toga.TextInput(initial=environ.get( 'TWITCH_USER', None), placeholder='username') self.twitch_channel_input = toga.TextInput(initial=environ.get( 'TWITCH_CHAN', None), placeholder='channel') self.twitch_key_input = toga.PasswordInput(initial=environ.get( 'TWITCH_OAUTH', None), placeholder="auth token") self.twitch_settings_container = toga.Box( style=Pack(direction=COLUMN, padding=10), children=[ self.twitch_input_label, self.twitch_user_input, self.twitch_channel_input, self.twitch_key_input ]) self.twitch_connect_button = toga.Button('Connect', on_press=self.twitch_connect, style=Pack(flex=0.5, padding_right=5)) self.send_button = toga.Button('Send current project name', on_press=self.send_button_fuction, style=Pack(flex=1)) self.on_switch = toga.Switch('Enable automatic sending', on_toggle=self.on_switch_handler, style=Pack(flex=1, padding_left=10, padding_top=3)) self.twitch_controls_container = toga.Box( style=Pack(direction=ROW, padding=10), children=[ self.twitch_connect_button, self.send_button, self.on_switch ]) main_box = toga.Box(style=Pack(direction=COLUMN, padding=10, flex=1), children=[ self.hostname_container, self.daw_project_name_container, self.twitch_settings_container, self.twitch_controls_container ]) self.main_window = toga.MainWindow(title=self.formal_name) self.main_window.content = main_box ### HACK Running background tasks # aiosc is uses lover level functions for running the example code # self.add_background_task( Coroutine ) -> equals under the hood: # self.loop.call_soon(wrapped_handler(self, handler), self) loop = self._impl.loop # equals asyncio.get_event_loop() osc_coro = loop.create_datagram_endpoint(OscServer, local_addr=('0.0.0.0', 9000)) osc_task = loop.create_task(osc_coro, name="osc_coro") # Connect Twitch automatically if credentials are set if environ.get('TWITCH_USER', None) and environ.get( 'TWITCH_CHAN', None) and environ.get('TWITCH_OAUTH', None): self.twitch_connect(self.twitch_connect_button) ### Startup GUI self.main_window.show()