def customers(self, widget): self.cust_window = toga.Window(title="Customer Details") # Data to populate the table. data = [] for x in range(5): data.append(tuple(str(x) for x in range(5))) self.table1 = toga.Table( headings=headings, data=customers[:4], style=Pack(flex=1), multiple_select=False, ) tablebox = toga.Box(children=[self.table1], style=Pack(flex=1)) # Most outer box outer_box = toga.Box(children=[tablebox], style=Pack( flex=1, direction=COLUMN, padding=10, )) # Add the content on the main window self.cust_window.content = outer_box # Show the main window self.cust_window.show()
def open_file(self, widget, **kwargs): # TODO: This causes a blank window to be shown. # Is there a way to open a file dialog without having a window? m = toga.Window() file_name = m.select_folder_dialog(self.interface.name, None, False)[0] self.open_document(file_name)
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 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, filename, app): super().__init__(filename=filename, document_type='Jupyter Notebook', app=app) self.window = toga.Window(title=filename, size=(768, 768)) self.window.on_close = self.close_window self.webview = toga.WebView(style=Pack(flex=1)) self.window.content = self.webview
def startup(self): self.webview = WebView(style=toga.style.Pack(flex=1)) self.webview.url = f"http://localhost:{self.port}/" self.webview.on_key_down = self.on_key_down self.webview.on_webview_load = self.invoke_js self.main_window = toga.Window() self.main_window.content = self.webview self.on_mount() self.main_window.show()
def on_about(self): self.about_window = toga.Window(title="About", size=(200,100)) text = "League Friend\n\nVersion: {}".format(__VERSION__) textbox = toga.Label(text=text, style=Pack(flex=1, padding_left="30")) self.about_window.content = toga.Box(children=[ textbox ], style=Pack(direction=COLUMN, flex=1, padding="10")) self.about_window.show()
def show_figure_window(self, plot_method, title): """Open a window with matplotlib window.""" figure_window = toga.Window(title=title, size=FIGURE_WINDOW_SIZE) figure_box = FigureBox(plot_method=plot_method) figure_box.add(SaveFigureButton("save", plot_method=plot_method)) figure_window.content = figure_box figure_window.app = self figure_window.content.set_font_size(self.__font_size) figure_window.content.draw() figure_window.show()
def open_create_spell(self, widget): spell_creator = toga.Box(style=Pack(direction=COLUMN)) elements1 = [ 'Water', 'Earth', 'Wind', 'Fire', 'Light', 'Healing', 'Lightning', 'Illusion', 'Chaos' ] elements2 = [ 'Water', 'Earth', 'Wind', 'Fire', 'Light', 'Healing', 'Lightning', 'Illusion', 'Chaos' ] forms = [ 'point', 'line', 'wall', 'random', 'chain', 'sphere', 'cube', 'projectile', 'cone', 'ally' ] effects = [ 'attack', 'buff', 'debuff', 'enchantment', 'restoration', 'defense', 'area control' ] self.firstused = 0 self.secondused = 0 self.firsteffectused = 0 self.secondeffectused = 0 firstelement = toga.Selection(items=elements1, on_select=self.UpdateFirst) secondelement = toga.Selection(items=elements1, on_select=self.UpdateSecond) form = toga.Selection(items=forms, on_select=self.UpdateForm) firsteffect = toga.Selection(items=effects, on_select=self.UpdateFirstEffect) secondeffect = toga.Selection(items=effects, on_select=self.UpdateSecondEffect) self.eleratio = toga.TextInput(style=Pack(flex=1)) spell_box = toga.Box(style=Pack(direction=ROW, padding=5)) spell_box.add(firstelement) spell_box.add(secondelement) spell_box.add(form) spell_box.add(firsteffect) spell_box.add(secondeffect) spell_box.add(self.eleratio) spell_score_button = toga.Button('Score your spell', on_press=self.say_hello, style=Pack(padding=5)) spell_creator.add(spell_box) spell_creator.add(spell_score_button) #self.main_box.remove(self.create_spell_button) #self.main_box.add(spell_creator) self.new_window = toga.Window(title=None) self.new_window.content = spell_creator self.new_window.show()
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 gtk_startup(self, data=None): super().gtk_startup(data=data) try: # Look for a filename specified on the command line file_name = os.path.abspath(sys.argv[1]) except IndexError: # Nothing on the command line; open a file dialog instead. # TODO: This causes a blank window to be shown. # Is there a way to open a file dialog without having a window? m = toga.Window() file_name = m.select_folder_dialog(self.interface.name, None, False)[0] self.open_document(file_name)
def on_create_vault(self, widget): self.create_vault_dialog = toga.Window(title='Create New Vault', resizeable=False, size=(300, 120)) self.input_vault_name = toga.TextInput(style=Pack(padding=3)) lbl_vaultname = toga.Label("Vault Name", style=Pack(padding=3)) btn_create = toga.Button("Create New", on_press=self.on_create_vault_dialog, style=Pack(padding=3)) box = toga.Box(style=Pack(direction=COLUMN, flex=1, padding=15)) box.add(lbl_vaultname) box.add(self.input_vault_name) box.add(btn_create) self.create_vault_dialog.content = box self.create_vault_dialog.show()
def action_open_secondary_window(self, widget): self.window_counter += 1 window = toga.Window(title=f"New Window {self.window_counter}") # Both self.windows.add() and self.windows += work: self.windows += window self.set_window_label_text(len(self.windows) - 1) secondary_label = toga.Label(text="You are in a secondary window!") window.content = toga.Box( children=[ secondary_label ], style=Pack( flex=1, direction=COLUMN, padding=10 ) ) window.on_close = self.window_close_handler window.show()
def on_update(self): global __VERSION__ latest = updater.getLatestRelease() if latest['version'] <= __VERSION__: self.main_window.info_dialog(title="Information", message="No update available.") return self.update_window = toga.Window(title="Update", size=(400,100)) textbox = toga.MultilineTextInput(readonly=True, style=Pack(flex=1)) textbox.value = latest['notes'] progress_bar = toga.ProgressBar(max=latest['size'], value=0) btn_update_now = None def on_btn_click_later(e): self.update_window._impl.close() def on_btn_click_now(e): btn_update_now.enabled = False def addBarValue(v): progress_bar.value += v def thread_update_task(): bundlePath = updater.getBundlePath() response = requests.get(latest['url'], verify=False, stream=True) progress_value = 0 tempFolder = tempfile.TemporaryDirectory() with open(tempFolder.name + "/patch.zip", "wb") as f: for chunk in response.iter_content(chunk_size=1024): if chunk: f.write(chunk) PyObjCTools.AppHelper.callAfter(addBarValue, 1024) zip_ref = updater.MyZipFile(tempFolder.name + "/patch.zip", 'r') zip_ref.extractall(tempFolder.name + "/patches/") zip_ref.close() shutil.rmtree(bundlePath) shutil.copytree(tempFolder.name + "/patches/LeagueFriend.app", bundlePath) tempFolder.cleanup() os.system('open -n "{}"'.format(bundlePath)) self.exit() t = threading.Thread(target=thread_update_task) t.start() btn_update_now = toga.Button(label="Update Now", on_press=on_btn_click_now, style=Pack(padding_left="50")) btn_update_later = toga.Button(label="Later", on_press=on_btn_click_later, style=Pack(padding_left="10")) self.update_window.content = toga.Box(children=[ toga.Box(children=[ toga.Label(text="New update available.", style=Pack(padding_bottom="20", padding_left="5")), btn_update_now, btn_update_later ], style=Pack(direction=ROW, flex=1)), toga.Label(text="Release Notes:", style=Pack(padding_bottom="5", padding_left="5")), textbox, progress_bar ], style=Pack(direction=COLUMN, flex=1, padding="10")) self.update_window.show()
def setUp(self): super().setUp() self.window = toga.Window(factory=toga_dummy.factory) self.app = toga.App('test_name', 'id.app', factory=toga_dummy.factory)
def startup(self): # Create main window self.main_window = toga.MainWindow(self.name) icons = os.path.join(os.path.dirname(__file__), 'icons') # dice number window self.roll_dice = '' self.die_window = toga.Window('die_num', title='How many dice to roll', closeable=False, minimizable=False) self.dice_number = toga.Slider(range=(1,10), window=self.die_window) # Character Attributes on the left self.left_content = toga.Slider() self.left_container = toga.ScrollContainer(content=self.left_content, horizontal=False) # Other attributes on the right self.right_container = toga.OptionContainer() self.right_table = toga.Table(headings=['Throws', 'Values']) self.right_tree = toga.Tree(headings=['Spells', 'Equipment']) self.right_container.add('Table', self.right_table) self.right_container.add('Tree', self.right_tree) # Split left and right boxes formed above self.split = toga.SplitContainer() self.split.content = [self.left_container, self.right_container] # Make dice toolbar cmd4 = toga.Command(self.dice4, 'Roll D4', tooltip='Roll a four sided die', icon=os.path.join(icons, 'd4.png'), order=1) cmd6 = toga.Command(self.dice6, 'Roll D6', tooltip='Roll a six sided die', icon=os.path.join(icons, 'd6.png'), order=2) cmd8 = toga.Command(self.dice8, 'Roll D8', tooltip='Roll a eight sided die', icon=os.path.join(icons, 'd8.png'), order=3) cmd10 = toga.Command(self.dice10, 'Roll D10', tooltip='Roll a 10 sided die', icon=os.path.join(icons, 'd10.png'), order=4) cmd12 = toga.Command(self.dice12, 'Roll D12', tooltip='Roll a twelve sided die', icon=os.path.join(icons, 'd12.png'), order=5) cmd20 = toga.Command(self.dice20, 'Roll D20', tooltip='Roll a twenty sided die', icon=os.path.join(icons, 'd20.png'), order=6) # Show main window self.main_window.toolbar.add(cmd4, cmd6, cmd8, cmd10, cmd12, cmd20) self.main_window.toolbar.add(die_slider) self.main_window.content = self.split self.main_window.show()
def setUp(self): super().setUp() self.window = toga.Window(factory=toga_dummy.factory)
def enter_cust_details(self, widget): name_label = toga.Label('Customer name: ', style=Pack(padding=(10, 2))) self.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.name_input) # Phone number phone_label = toga.Label('Phone Number: ', style=Pack(padding=(10, 5))) self.phone_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.phone_input) # Email email_label = toga.Label('Email: ', style=Pack(padding=(10, 5))) self.email_input = toga.TextInput(style=Pack(flex=1)) email_box = toga.Box(style=Pack(direction=ROW, padding=5)) email_box.add(email_label) email_box.add(self.email_input) # City city_label = toga.Label('City: ', style=Pack(padding=(10, 5))) self.city_input = toga.TextInput(style=Pack(flex=1)) # Country country_label = toga.Label('Country: ', style=Pack(padding=(10, 5))) self.country_input = toga.TextInput(style=Pack(flex=1)) country_box = toga.Box(style=Pack(direction=ROW, padding=5)) country_box.add(city_label) country_box.add(self.city_input) country_box.add(country_label) country_box.add(self.country_input) # Adress address_label = toga.Label('Address: ', style=Pack(padding=(10, 5))) self.add_input = toga.MultilineTextInput(style=Pack(flex=1)) add_box = toga.Box(style=Pack(direction=ROW, padding=5)) add_box.add(address_label) add_box.add(self.add_input) # Requirement req_label = toga.Label('Requirement: ', style=Pack(padding=(10, 5))) self.req_input = toga.MultilineTextInput(style=Pack(flex=1)) req_box = toga.Box(style=Pack(direction=ROW, padding=5)) req_box.add(req_label) req_box.add(self.req_input) # Nature of Business nob_label = toga.Label('Nature of Business: ', style=Pack(padding=(10, 5))) self.nob_input = toga.MultilineTextInput(style=Pack(flex=1)) nob_box = toga.Box(style=Pack(direction=ROW, padding=5)) nob_box.add(nob_label) nob_box.add(self.nob_input) # Notes note_label = toga.Label('Notes: ', style=Pack(padding=(10, 5))) self.note_input = toga.MultilineTextInput(style=Pack(flex=1)) note_box = toga.Box(style=Pack(direction=ROW, padding=5)) note_box.add(note_label) note_box.add(self.note_input) # Follow Up followup_label = toga.Label('Follow Up: ', style=Pack(padding=(10, 5))) self.followup_input = toga.TextInput(style=Pack(flex=1)) followup_box = toga.Box(style=Pack(direction=ROW, padding=5)) followup_box.add(followup_label) followup_box.add(self.followup_input) button = toga.Button('Save', on_press=self.save, style=Pack(padding_top=25, width=100, alignment=CENTER)) main_box = toga.Box( children=[ name_box, phone_box, email_box, add_box, country_box, req_box, nob_box, note_box, button ], style=Pack(padding=50, padding_top=50, direction=COLUMN, alignment=CENTER), ) self.secondary_window = toga.Window(title="New Customer details") self.secondary_window.content = main_box self.secondary_window.show()
def startup(self): location.location_use() self.outputFolder = packages.get_config_param_value(5)[0][0] if not self.outputFolder or self.outputFolder == '%temp%': self.outputFolder = tempfile.gettempdir() packages.set_config_param(5, self.outputFolder, iscommit=True) self.pid = None # contenedor principal de la aplicacion self.main_box = toga.Box(style=Pack(direction=COLUMN, padding=10)) # contenedor primario para carga de url self.first_box = toga.Box(style=Pack(direction=ROW)) self.second_box = toga.Box(style=Pack(direction=ROW)) # Input text de la url del servicio self.url_input = toga.TextInput(placeholder=_TX_URL_PLACEHOLDER, style=Pack(flex=3)) self.url_added = None # Boton que permite cargar la url self.url_load = toga.Button(_TX_LOADURL_BUTTON, on_press=self.load_metadata, style=Pack(width=100, height=36, background_color='#fbceb5')) # Se agregan los elementos al contenedor primario self.first_box.add(self.url_input) self.first_box.add(self.url_load) # Contenedor de metadata # self.metadata = toga.MultilineTextInput(id=_ID_MULTILINETEXTINPUT_METADATA) # self.metadata.readonly = True self.web = toga.WebView(style=Pack(flex=1)) # Contenedor para seleccionar el folder self.window = toga.Window() # Input text que almacenara el folder donde se almacenara el resultado self.output_folder = toga.TextInput(style=Pack(flex=1)) self.output_folder.readonly = True self.output_folder.value = self.outputFolder # Abre ventana para seleccionar un folder de almacenamiento self.savefolder = toga.Button(_TC_OUTPUT_BUTTON, on_press=self.saveAs, style=Pack(background_color='#52de97', width=100, height=36)) self.config = toga.Button(_TC_CONFIG_BUTTON, on_press=self.openConfigWindow, style=Pack(background_color='#52de97', width=100, height=36)) self.second_box.add(self.output_folder) self.second_box.add(self.savefolder) self.second_box.add(self.config) # self.updateurl = toga.Button(_TC_UPDATEURL_BUTTON, on_press=self.updateUrl) # Boton de decarga self.downloadBtn = toga.Button(_TC_DOWNLOAD_BUTTON, on_press=self.download, style=Pack(background_color='#52de97', height=36)) # Boton para abril la descarga self.openfolder = toga.Button(_TC_OPENFOLDER_BUTTON, on_press=self.openSaveAs, style=Pack(background_color='#52de97', height=36)) # self.openfolder.enabled = False self.donate = toga.Button(_TC_DONATE_BUTTON, on_press=self.load_yape_html_widget, style=Pack(background_color='#FF6363', height=36)) self.main_box.add(self.first_box) # self.main_box.add(self.metadata) self.main_box.add(self.web) self.main_box.add(self.second_box) # self.main_box.add(self.savefolder) # self.main_box.add(self.output_folder) # self.main_box.add(self.updateurl) self.main_box.add(self.downloadBtn) self.main_box.add(self.openfolder) self.main_box.add(self.donate) self.main_window = toga.MainWindow(title=self.formal_name + ' by DanielGIS', size=(600, 700)) self.main_window.content = self.main_box self.main_window.show() self.response_pool = list() self.inputsConfig = dict() self.load_yape_html() # Ventana de configuracion self.config_window = toga.Window(title='Config parameters', size=(900, 500))