def create_label(self): style = Pack(text_align=CENTER) self.pokemon_name = toga.Label(TITLE, style=style) self.pokemon_description = toga.Label("Description", style=style) self.pokemon_name.style.font_size = 20 self.pokemon_name.style.padding_bottom = 10
def show_final_statistic(self, stat): profit = int(stat.total_profit) lost = stat.total_lost couriers = [ round(c / stat.courier_max_load, 2) for c in stat.delivered_history ] self.st_window = toga.Window(title='итоговая статистика') self.drugs_daily_table = toga.Table( headings=['загруженность курьеров'], data=couriers) right_container = toga.Box() right_container.style.update(direction=COLUMN, padding_top=50) self.cur_couriers_label = toga.Label('прибыль ' + str(profit), style=Pack(text_align=RIGHT)) cur_couriers_box = toga.Box(children=[self.cur_couriers_label]) cur_couriers_box.style.padding = 50 right_container.add(cur_couriers_box) self.max_couriers_label = toga.Label( 'потеряно из-за списания и скидок ' + str(lost), style=Pack(text_align=RIGHT)) max_couriers_box = toga.Box(children=[self.max_couriers_label]) max_couriers_box.style.padding = 50 right_container.add(max_couriers_box) split = toga.SplitContainer() split.content = [self.drugs_daily_table, right_container] self.st_window.content = split self.st_window.show()
def __init__(self): """Initialize box.""" logo_path = Path(__file__).parent.parent / "resources" / "eddington_gui.png" logo = toga.Image(str(logo_path)) super(HeaderBox, self).__init__( alignment=TOP, children=[ toga.Label( text=f"Version: {__version__}", style=Pack( font_size=SMALL_FONT_SIZE, font_family=HEADER_FONT_FAMILY ), ), toga.Box(style=Pack(flex=1)), toga.ImageView( image=logo, style=Pack(height=LOGO_SIZE, width=LOGO_SIZE) ), toga.Box(style=Pack(flex=1)), toga.Label( text=f"Author: {__author__}", style=Pack( font_size=SMALL_FONT_SIZE, font_family=HEADER_FONT_FAMILY ), ), ], )
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 products(self, widget): main_box = toga.Box(style=Pack( padding=250, padding_top=50, direction=COLUMN, alignment=CENTER)) name_label = toga.Label('Product Name: ', style=Pack(padding=(10, 2))) self.product_name_input = toga.TextInput(style=Pack(flex=1)) name_box = toga.Box(style=Pack(direction=ROW, padding=5)) name_box.add(name_label) name_box.add(self.product_name_input) # Phone number phone_label = toga.Label('Model Number: ', style=Pack(padding=(10, 5))) self.model_input = toga.TextInput(style=Pack(flex=1)) phone_box = toga.Box(style=Pack(direction=ROW, padding=5)) phone_box.add(phone_label) phone_box.add(self.model_input) button = toga.Button('Show', on_press=self.get_product, style=Pack(padding_top=25, width=100, alignment=CENTER)) main_box.add(name_box) main_box.add(phone_box) main_box.add(button) self.prooduct_window = toga.Window(title="Products") self.prooduct_window.content = main_box self.prooduct_window.show()
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)) style = Pack(padding_top=24) substyle = Pack(padding_right=12, padding_left=12, flex=1) # Add the content on the main window self.main_window.content = toga.Box(children=[ toga.Label('Section 1'), toga.Divider(style=style), toga.Label('Section 2', style=style), toga.Divider(style=style), toga.Label('Section 3', style=style), toga.Box( children=[ toga.TextInput(placeholder="First textbox"), toga.Divider(direction=toga.Divider.VERTICAL, style=substyle), toga.TextInput(placeholder="Second textbox"), ], style=Pack(direction=ROW, padding=24, flex=1), ), ], style=Pack(direction=COLUMN, padding=24)) # Show the main window self.main_window.show()
def __init__(self, on_fitting_function_load): """Initialize box.""" super().__init__() self.__fitting_function = None self.on_fitting_function_load = None self.__polynomial_is_set = False self.add(toga.Label(text="Fitting function:")) self.fitting_function_selection = toga.Selection( on_select=self.load_select_fitting_function_name, ) self.fitting_function_syntax = toga.TextInput( readonly=True, style=Pack(flex=1, padding_left=BIG_PADDING, padding_right=BIG_PADDING), ) self.add(self.fitting_function_selection, self.fitting_function_syntax) self.polynomial_degree_title = toga.Label("Degree:") self.polynomial_degree_input = toga.NumberInput( min_value=1, max_value=5, default=1, on_change=lambda widget: self.set_polynomial_degree(), ) self.update_fitting_function_options() self.on_fitting_function_load = on_fitting_function_load
def build(app): def installHandle(widget): packageToInstall = packageInput.value resultInput.value = runScript(where_is_scripts + packageToInstall + ".sh") packages = get_packages(where_is_scripts, "test.sh", "updateYapiScripts.sh") box = toga.Box() listBox = toga.Box() listLabel = toga.Label('Packages Available: ') packageBox = toga.Box() packageLabel = toga.Label('Package To Install:') packageInput = toga.TextInput() submitBox = toga.Box() install = toga.Button('Install Package', on_press=installHandle) resultBox = toga.Box() resultInput = toga.TextInput(readonly=True) listBox.add(listLabel) packageBox.add(packageLabel) packageBox.add(packageInput) submitBox.add(install) resultBox.add(resultInput) box.add(listBox) box.add(packageBox) box.add(submitBox) box.add(resultBox) box.style.update(direction=COLUMN, padding_top=10) listBox.style.update(direction=ROW, padding=5) packageBox.style.update(direction=ROW, padding=5) submitBox.style.update(direction=ROW, padding=5) return box
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)) style = Pack(padding_top=24) substyle = Pack(padding_right=24, flex=1) # Add the content on the main window self.main_window.content = toga.Box( children=[ toga.Label('Section 1'), toga.Divider(style=style), toga.Label('Section 2', style=style), toga.Divider(style=style), toga.Label('Section 3', style=style), toga.Box( children=[ toga.DetailedList(['List 1'], style=substyle), toga.Divider(direction=toga.Divider.VERTICAL, style=substyle), toga.DetailedList(['List 2'], style=substyle), ], style=Pack(direction=ROW, padding=24, flex=1), ), ], style=Pack(direction=COLUMN, padding=24) ) # Show the main window self.main_window.show()
def _installed_section(self) -> toga.Widget: desc = "Choose directories for installed games lookup. The lookup is based on child directory names." description = toga.Label(desc, style=Pack(font_size=self.TEXT_SIZE_BIG, padding_bottom=12)) if IS_MAC: desc_os = "If nothing selected, '/Applications' will be used." if IS_WINDOWS: desc_os = "e.g. 'C:/Humble' to detect 'C:/Humble/Torchlight/torch.exe' ('Torchlight' matches game name)." description_os = toga.Label(desc_os, style=Pack(font_size=self.TEXT_SIZE_BIG, padding_bottom=12)) self._paths_table = OneColumnTable( 'Path', data=[str(p) for p in self._cfg.installed.search_dirs]) select_btn = toga.Button('Add path', on_press=self._add_path) select_btn.style.flex = 1 select_btn.style.padding_bottom = 4 self._remove_btn = toga.Button('Remove path', on_press=self._remove_paths, enabled=self._paths_table.not_empty) self._remove_btn.style.flex = 1 config_panel = toga.Box(children=[select_btn, self._remove_btn]) config_panel.style.direction = 'row' config_panel.style.padding_top = 15 paths_container = toga.Box(children=[ description, description_os, self._paths_table, config_panel ]) paths_container.style.direction = 'column' return paths_container
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 __init__(self, on_choose_record): """Initialize box.""" super().__init__() self.__sheet_selection_enabled = False self.on_input_file_change = None self.on_csv_read = None self.on_excel_read = None self.on_select_excel_file = None self.__input_file_path = toga.TextInput(readonly=True, style=Pack(flex=1)) self.__select_file_button = toga.Button( label="Choose file", on_press=self.select_file, style=Pack(padding_left=SMALL_PADDING), ) self.add( toga.Label(text="Input file:"), self.__input_file_path, self.__select_file_button, toga.Button( label="Choose records", on_press=on_choose_record, style=Pack(padding_left=SMALL_PADDING), ), ) self.__sheet_label = toga.Label(text="Sheet:") self.__sheet_selection = toga.Selection(on_select=self.select_sheet)
def create_display(self, state): super().__init__(style=Pack(padding=50, direction=COLUMN)) self.add(toga.Label("Castaway Community")) cast_box = toga.Box(style=Pack(direction=COLUMN)) # cast_scroll = toga.widgets.scrollcontainer.ScrollContainer( # content=cast_box, # style=Pack(height=200) # ) for cast in state.get_cast(): info_box = toga.Box(style=Pack(direction=ROW)) cast_box.add(info_box) left_box = toga.Box(style=Pack(direction=COLUMN, padding=5)) right_box = toga.Box(style=Pack(direction=COLUMN, padding=5)) info_box.add(left_box) info_box.add(right_box) img = cast['img'] left_box.add(toga.Label('Name: {}'.format(cast['name']))) left_box.add( toga.widgets.imageview.ImageView( toga.Image('resources/images/'+img), style=Pack(width=48, height=48, direction=COLUMN) ) ) right_box.add(toga.Label('Stats')) right_box.add(toga.Label('Age: {}'.format(cast['age']))) self.add(cast_box) super().create_display(state)
def __init__(self, flex): """Initialize box.""" super(FittingFunctionBox, self).__init__( style=Pack(direction=COLUMN, flex=flex) ) fit_function_box = LineBox() fit_function_box.add(toga.Label(text="Fitting function:")) self.fitting_function_selection = toga.Selection( on_select=self.load_select_fit_function_name, ) fit_function_box.add(self.fitting_function_selection) self.fitting_function_syntax = toga.TextInput( readonly=True, style=Pack(flex=1, padding_left=BIG_PADDING, padding_right=BIG_PADDING), ) fit_function_box.add(self.fitting_function_syntax) self.load_module_button = toga.Button( label="Load module", on_press=self.load_module ) fit_function_box.add(self.load_module_button) self.add(fit_function_box) self.parameters_box = LineBox() self.parameters_box.add(toga.Label("Parameters:")) self.parameter_inputs = toga.TextInput( readonly=True, style=Pack(width=PARAMETER_WIDTH), on_change=lambda widget: self.reset_fit_function(), ) self.parameters_box.add(self.parameter_inputs) self.add(self.parameters_box) self.update_fitting_function_options()
def __init__(self, flex): """Initialize box.""" super().__init__(style=Pack(direction=COLUMN, flex=flex)) self.fitting_function_box = LineBox() self.fitting_function_box.add(toga.Label(text="Fitting function:")) self.fitting_function_selection = toga.Selection( on_select=self.load_select_fitting_function_name, ) self.fitting_function_box.add(self.fitting_function_selection) self.fitting_function_syntax = toga.TextInput( readonly=True, style=Pack(flex=1, padding_left=BIG_PADDING, padding_right=BIG_PADDING), ) self.fitting_function_box.add(self.fitting_function_syntax) self.load_module_button = toga.Button(label="Load module", on_press=self.load_module) self.fitting_function_box.add(self.load_module_button) self.add(self.fitting_function_box) self.polynomial_degree_title = toga.Label("Degree:") self.polynomial_degree_input = toga.NumberInput( min_value=1, max_value=5, default=1, on_change=lambda widget: self.set_polynomial_degree(), ) self.update_fitting_function_options()
def startup(self): # Main window of the application with title and size self.main_window = toga.MainWindow(title=self.name, size=(1000, 500)) # set up common styls label_style = Pack(flex=1, padding_right=24) box_style = Pack(direction=ROW, padding=10) slider_style = Pack(flex=1) self.discreteSliderValueLabel = toga.Label("slide me", style=label_style) self.continuousSliderValueLabel = toga.Label( "Default Slider is a continuous range between 0 to 1", style=label_style) # Add the content on the main window self.main_window.content = toga.Box(children=[ toga.Box(style=box_style, children=[ self.continuousSliderValueLabel, toga.Slider(on_slide=self.my_continuous_on_slide, style=slider_style), ]), toga.Box( style=box_style, children=[ toga.Label( "On a scale of 1 to 10, how easy is building a Toga GUI?", style=label_style), toga.Slider(range=(1, 10), default=10, style=Pack(width=150), tick_count=10), ]), toga.Box(style=box_style, children=[ toga.Label("Sliders can be disabled", style=label_style), toga.Slider(enabled=False, style=slider_style), ]), toga.Box(style=box_style, children=[ toga.Label("Give a Slider some style!", style=label_style), toga.Slider(style=slider_style) ]), toga.Box(style=box_style, children=[ self.discreteSliderValueLabel, toga.Slider(on_slide=self.my_discrete_on_slide, range=(MIN_VAL, MAX_VAL), tick_count=MAX_VAL - MIN_VAL + 1, style=slider_style), ]), ], style=Pack(direction=COLUMN, padding=24)) self.main_window.show()
def button_handler(self, button): main_box = self.main_window.content if 0 <= self.textEntry.value.find('0x'): value = int(self.textEntry.value, 0) virtual_address = bin(value)[2:] address_len = len(virtual_address) # Check length of bit string if address_len < int(self.textEntry1.value) or int( self.textEntry1.value) < address_len: n = 13 - address_len virtual_address = ('0' * n) + virtual_address # Calculate VPN, TLB index, TLB tag # Firstly get offset (Where VPN starts) vpn_offset = int(math.log2(int(self.textEntry3.value))) vpn_bits = virtual_address[:-vpn_offset] vpn_value = hex(int(vpn_bits, 2)) TLB_index_length = int(math.log2(int(self.textEntry2.value))) TLB_index_bits = virtual_address[-(vpn_offset + TLB_index_length):-vpn_offset] TLB_index_value = hex(int(TLB_index_bits, 2)) TLB_tag_offset = vpn_offset + TLB_index_length TLB_tag_bits = virtual_address[:-TLB_tag_offset] TLB_tag_value = hex(int(TLB_tag_bits, 2)) # Add the results to window # Labels label = toga.Label('Bits of virtual address', style=Pack(flex=1, text_align='center')) label.style.font_size = 18 label.style.font_family = 'monospace' label.style.font_weight = 'bold' address_label = toga.Label(virtual_address, style=Pack(flex=1, text_align='center')) address_label.style.font_size = 15 address_label.style.font_family = 'monospace' address_label.style.font_weight = 'bold' headings = ['VPN', 'TLB index', 'TLB tag', 'VPO/PPO bits'] table = toga.Table(headings=headings, data=[(vpn_value, TLB_index_value, TLB_tag_value, vpn_offset)], style=Pack(flex=1, height=50, padding=(10, 10, 10, 10))) main_box.add(label) main_box.add(address_label) main_box.add(table) self.main_window.content = main_box
def __init__(self, **kwargs): super(Form, self).__init__() """ validation availables: - notnull example: fields = [ {'name': 'account_id', 'label': 'Account ID:', validate: ['notnull'] }, {'name': 'access_key', 'label': 'Access Key:' }, ] initial = {'account_id': '213123'} confirm = {'label': 'Save credentials', 'callback': function } form = Form(fields=fields, confirm=confirm) """ field_style = Pack(padding=5) confirm_style = Pack(padding=5, alignment='right') self.label_error = toga.Label('', style=field_style) # add form fields if 'fields' in kwargs.keys(): for field in kwargs['fields']: # extract data from fields name = field['name'] label = field['label'] value = '' if 'value' in field.keys(): value = field['value'] if 'validate' in field.keys(): self.validation = {name: field['validate']} # create controls label_control = toga.Label(label, style=field_style) input_control = toga.TextInput(placeholder='',style=field_style) self.getcontrols().add('FormContainer_Label' + name.capitalize() + '', label_control.id) self.getcontrols().add('FormContainer_Input' + name.capitalize() + '', input_control.id) # add to box self.fields[name] = { 'label': label_control, 'input': input_control} self.basebox.add(self.fields[name]['label']) self.basebox.add(self.fields[name]['input']) # Add confirm button if 'confirm' in kwargs.keys(): label, callback = kwargs['confirm'].values() self.callback_confirm = callback self.confirm_btn = toga.Button(label, on_press=self._process_callback, style=confirm_style) self.getcontrols().add('FormContainer_ConfirmButton', self.confirm_btn.id) self.basebox.add(self.confirm_btn) if 'initial' in kwargs: self.set_values(kwargs['initial']) # Todo: add cancel button self.basebox.add(self.label_error)
def startup(self): main_box = toga.Box() w_box = toga.Box() m_box = toga.Box() f_box = toga.Box() w_input = toga.TextInput() m_input = toga.PasswordInput() f_input = toga.TextInput(readonly=True) w_label = toga.Label('Website:', style=Pack(text_align=CENTER)) m_label = toga.Label('Master Password:'******'Your Password:'******'Generate Password', on_press=genPasswd) w_box.add(w_label) w_box.add(w_input) m_box.add(m_label) m_box.add(m_input) f_box.add(f_label) f_box.add(f_input) main_box.add(w_box) main_box.add(m_box) main_box.add(f_box) main_box.add(button) main_box.style.update(direction=COLUMN, padding_top=10) w_box.style.update(direction=ROW, padding=5, padding_bottom=50) m_box.style.update(direction=ROW, padding=5, padding_bottom=50) f_box.style.update(direction=ROW, padding=5) w_input.style.update(flex=1, padding_right=10) m_input.style.update(flex=1, padding_right=10) f_input.style.update(flex=1, padding_right=10) w_label.style.update(flex=1) m_label.style.update(flex=1) f_label.style.update(flex=1) button.style.update(padding=15, flex=1) self.main_window = toga.MainWindow(title=self.formal_name, size=(446, 308)) self.main_window.content = main_box self.main_window.show()
def create_description_content(self, title, text): style = Pack(font_family=MONOSPACE, text_align=CENTER) self.title = toga.Label(title, style=style) self.description = toga.Label(text, style=style) self.title.style.font_size = 20 self.title.style.padding_bottom = 10 self.description.style.font_size = 18
def startup(self): # Main window of the application with title and size self.main_window = toga.MainWindow(title=self.name, size=(640, 400)) # set up common styles label_style = Pack(flex=1, padding_right=24) box_style = Pack(direction=ROW, padding=10) # 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=Pack(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( items=['Helium', 'Neon', 'Argon', 'Krypton', 'Xenon', 'Radon', 'Oganesson'], enabled=False ) ]), ], style=Pack(direction=COLUMN, padding=24) ) self.main_window.show()
def details_form(self): license_chooser_label = toga.Label( text="Choose your CC license:", style=Pack(padding_bottom=5) ) self.license_chooser = toga.widgets.selection.Selection( id='license', on_select=self.on_input_change, items=['CC0 1.0', 'CC BY 4.0', 'CC BY-NC 4.0', 'CC BY-ND 4.0', 'CC BY-SA 4.0', 'CC BY-NC-ND 4.0', 'CC BY-NC-SA 4.0'] ) license = toga.Box( children=[license_chooser_label, self.license_chooser], style=Pack(direction=COLUMN, padding_bottom=20) ) details_data = [ { 'label': 'Title of work', 'placeholder': 'The title of your work', 'id': 'title_of_work' }, { 'label': 'Creator of work', 'placeholder': 'Jane Doe', 'id': 'creator' }, { 'label': 'Link to work', 'placeholder': 'https://janedoe.com/image.jpg', 'id': 'link_to_work' }, { 'label': 'Link to Creator Profile', 'placeholder': 'https://janedoe.com', 'id': 'link_to_creator_profile' } ] fields = [license] for detail in details_data: label = toga.Label(text=detail['label'], style=Pack(padding_bottom=5)) input = toga.widgets.textinput.TextInput( placeholder=detail['placeholder'], id=detail['id'], on_change=self.on_input_change, on_lose_focus=self.on_input_blur ) field = toga.Box( children=[label, input], style=Pack(direction=COLUMN, padding_bottom=20) ) fields.append(field) details_form = toga.Box( style=Pack(direction=COLUMN), children=fields ) return details_form
def startup(self): # Set up main window self.main_window = toga.MainWindow(title=self.name) # Labels to show responses. self.label = toga.Label( 'Enter some values and press extract.', style=Pack(padding=10) ) self.text_label = toga.Label('Ready.', style=Pack(padding=10)) self.password_label = toga.Label('Ready.', style=Pack(padding=10)) self.password_content_label = toga.Label( EMPTY_PASSWORD, style=Pack(padding_bottom=10, font_size=9) ) self.number_label = toga.Label('Ready.', style=Pack(padding=10)) # Text inputs and a button self.text_input = toga.TextInput( placeholder='Type something...', style=Pack(padding=10) ) self.password_input = toga.PasswordInput( placeholder='Password...', style=Pack(padding=10), on_change=self.on_password_change ) self.number_input = toga.NumberInput(style=Pack(padding=10)) btn_extract = toga.Button( 'Extract values', on_press=self.do_extract_values, style=Pack(flex=1) ) # Outermost box box = toga.Box( children=[ self.label, self.text_input, self.password_input, self.password_content_label, self.number_input, self.text_label, self.password_label, self.number_label, btn_extract, ], style=Pack( flex=1, direction=COLUMN, padding=10, ) ) # Add the content on the main window self.main_window.content = box # Show the main window self.main_window.show()
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 create_description_area(self, text): self.title = toga.Label('Description', style=Pack(font_family=FANTASY, font_size=20)) self.description = toga.Label(text, style=Pack(font_family=FANTASY, font_size=15)) box = toga.Box(children=[self.title, self.description], style=Pack(direction=COLUMN, )) return box
def get_about_window(self): """Return the "About" native window. This is a Toga window with the DativeTop icon and the versions of DativeTop, Dative and the OLD displayed. TODO: it would be nice if the text could be center-aligned underneath the DativeTop icon. Unfortunately, I found it difficult to do this using Toga's box model and ``Pack`` layout engine. """ if self._about_window: return self._about_window dativetop_label = toga.Label('DativeTop {}'.format( dtutils.get_dativetop_version())) dative_label = toga.Label('Dative {}'.format( dtutils.get_dative_version())) old_label = toga.Label('OLD {}'.format( dtutils.get_old_version())) image_from_path = toga.Image(c.OLD_LOGO_PNG_PATH) logo = toga.ImageView(image_from_path) logo.style.update(height=72) logo.style.update(width=72) logo.style.update(direction=COLUMN) text_box = toga.Box( children=[ dativetop_label, dative_label, old_label, ] ) text_box.style.update(direction=COLUMN) text_box.style.update(alignment=CENTER) text_box.style.update(padding_left=20) text_box.style.update(padding_top=20) outer_box = toga.Box( children=[ logo, text_box, ] ) outer_box.style.update(direction=COLUMN) outer_box.style.update(alignment=CENTER) outer_box.style.update(padding=10) about_window = toga.Window( title=' ', id='about DativeTop window', minimizable=False, # resizeable = False, # messes up layout size=(300, 150), position=(500, 200), ) about_window.content = outer_box self._about_window = about_window return self._about_window
def time_select(name): box = toga.Box(style=Pack(direction=ROW)) box.add(toga.Label(f'Üblicher {name} um ', style=small_font_flex), ) box.add( toga.Selection(id=name, items=[''] + [str(time) for time in range(24)], on_select=select_time, style=small_font_flex)) box.add(toga.Label(' Uhr.', style=small_font_flex)) return box
def startup(self): # Main window of the application with title and size self.main_window = toga.MainWindow(self.name, size=(700, 500)) # set up common styls label_style = Pack(flex=1, padding_right=24) box_style = Pack(direction=ROW, padding=10) slider_style = Pack(flex=1) self.sliderValueLabel = toga.Label("slide me", style=label_style) # 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(style=slider_style), ]), 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, style=Pack(width=150)), ]), toga.Box(style=box_style, children=[ toga.Label("Sliders can be disabled", style=label_style), toga.Slider(enabled=False, style=slider_style), ]), toga.Box(style=box_style, children=[ toga.Label("give a Slider some style!", style=label_style), toga.Slider(style=slider_style) ]), toga.Box(style=box_style, children=[ self.sliderValueLabel, toga.Slider(on_slide=self.my_on_slide, range=(-40, 58), style=slider_style), ]), ], style=Pack(direction=COLUMN, padding=24)) self.main_window.show()
def _create_options(self): label_box0 = toga.Label('This is Box 0 ', style=Pack(padding=10)) label_box1 = toga.Label('This is Box 1 ', style=Pack(padding=10)) label_box2 = toga.Label('This is Box 2 ', style=Pack(padding=10)) box0 = toga.Box(children=[label_box0]) box1 = toga.Box(children=[label_box1]) box2 = toga.Box(children=[label_box2]) self.optioncontainer.add('Option 0', box0) self.optioncontainer.add('Option 1', box1) self.optioncontainer.add('Option 2', box2) self._refresh_select()
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()