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, msg_title: str = "Progress", icon: toga.Icon = None, callback: Callable | None = None, app: toga.App | None = None, ) -> None: self.progress_bar = toga.ProgressBar( max=0, style=Pack( width=self.CONTENT_WIDTH, padding=(0, 0, 10, 0), background_color=TRANSPARENT, ), ) self.progress_bar.start() super().__init__( title=msg_title, button_labels=("Cancel",), icon=icon, callback=callback, accessory_view=self.progress_bar, app=app, ) # save some space... self.content_box.remove(self.msg_content)
def test_disabled_cases(self): # Start with a default progress bar self.progress_bar = toga.ProgressBar(factory=toga_dummy.factory) self.assertTrue(self.progress_bar.enabled) # It should be disabled if it is stopped and max is None self.progress_bar.max = None self.progress_bar.stop() self.progress_bar.value = 0 self.assertFalse(self.progress_bar.enabled) # Starting the progress bar should enable it again # self.progress_bar.max = None self.progress_bar.start() # self.progress_bar.value = 0 self.assertTrue(self.progress_bar.enabled) # Stopping AND providing a max will cause it to display the percentage. self.progress_bar.max = 1 self.progress_bar.stop() # self.progress_bar.value = 0 self.assertTrue(self.progress_bar.enabled)
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 test_already_running(self): # Creating a new progress bar with running=True so it is already running self.progress_bar = toga.ProgressBar(factory=toga_dummy.factory, running=True) # Asserting that start() function is invoked on the underlying widget self.assertActionPerformed(self.progress_bar, 'start') # The constructor which is __init__ function will call the function start if running=True # which will make enabled=True # Asserting is_running to be True self.assertTrue(self.progress_bar.is_running) # Asserting enabled to be True self.assertTrue(self.progress_bar.enabled)
def _setup_status_bar(self): '''The bottom frame to inform the user about the status of the tests that are running. ''' self.run_status = toga.Label('Not running', style=Pack(padding_left=10)) self.run_summary = toga.Label('T:0 P:0 F:0 E:0 X:0 U:0 S:0', style=Pack(flex=1, text_align=RIGHT)) # Test progress self.progress = toga.ProgressBar(max=100, value=0, style=Pack(padding_left=10, padding_right=10, width=200)) self.statusbar = toga.Box(style=Pack(direction=ROW)) self.statusbar.add(self.run_status) self.statusbar.add(self.run_summary) self.statusbar.add(self.progress)
def build(app): progressbar = toga.ProgressBar(max=100.3, value=40, style=CSS(flex=1, margin=20)) def start_progress(widget): progressbar._impl.start() def stop_progress(widget): progressbar.running = False def set_progress(widget): progressbar.value = random() * 100 print('Current value: {}'.format(progressbar.value)) print('Max value: ', progressbar.max) box = toga.Box() box.add(progressbar) start_btn = toga.Button('Start', on_press=start_progress) stop_btn = toga.Button('Stop', on_press=stop_progress) set_btn = toga.Button('Set Random', on_press=set_progress) box.add(toga.Box(children=[start_btn, stop_btn, set_btn])) return box
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 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.mode_info = {"Overwrite": "Overwrites already replaced faces", "Preserve": "Preserves already replaced faces", "Generate": "Generates mapping from scratch."} os.makedirs(".config", exist_ok=True) self.cfg_path = ".config/cfg.json" self.logger.info("Loading cfg.json") self.config = self._load_config(self.cfg_path) for k, v in self.config["Profile"].items(): if v: self.cur_prf = k break self.logger.info("Loading current profile") self.prf_cfg = self._load_config(".config/"+self.cur_prf+".json") self.logger.info("Creating GUI") self.main_box = toga.Box() self.logger.info("Created main box") # 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: ") prfsel_lab = toga.Label(text="Select Profile: ") self.prfsel_lst = SourceSelection(items=list(self.config["Profile"].keys()), on_select=self._set_profile_status) self.prfsel_lst.value = self.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=0.5) 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=0.5) prfsel_lab.style.update(padding_top=7) # MID Path selections dir_box = toga.Box() dir_lab = toga.Label(text="Select Image Directory: ") self.dir_inp = toga.TextInput(readonly=True, initial=self.prf_cfg['img_dir']) self.dir_inp.style.update(direction=ROW, padding=(0, 20), flex=0.5) 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: ") self.rtf_inp = toga.TextInput(readonly=True, initial=self.prf_cfg['rtf']) self.rtf_inp.style.update(direction=ROW, padding=(0, 20), flex=0.5) 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.genmdeinfo_lab = toga.Label(text=self.mode_info["Generate"]) 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=0.5) self.genmde_lab.style.update(padding_top=7) self.genmdeinfo_lab.style.update(padding_top=7) gen_mode_box.add(self.genmde_lab) gen_mode_box.add(self.genmde_lst) gen_mode_box.add(self.genmdeinfo_lab) 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) 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_lab.style.update(padding_top=20) # Report bad image rep_box = toga.Box() self.rep_lab = toga.Label(text="Player UID: ") 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=0.5) # END configs rep_box.style.update(direction=ROW, padding=20) gen_mode_box.style.update(direction=ROW, padding=20) prf_box.style.update(direction=ROW, padding=20) self.prfsel_box.style.update(direction=ROW, padding=20) dir_box.style.update(direction=ROW, padding=20) rtf_box.style.update(direction=ROW, padding=20) gen_box.style.update(direction=COLUMN, padding=20, alignment='center') self.main_box.style.update(direction=COLUMN, padding=10, 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()
def setUp(self): super().setUp() self.progress_bar = toga.ProgressBar(factory=toga_dummy.factory)
def __init__(self, main_window): pygame.init() self.main_window = main_window self.progress_bar = toga.ProgressBar(max=100, value=0, style=Pack(padding_top=5)) # Create a thread for the music time_thread = threading.Thread(target=self.prog_check) time_thread.start() # Set useful variables self.is_loaded = False self.is_paused = False # This adjusts the position as necessary for fforwards and rewinds self.time_adjuster = 0 # Volume tracker self.volume = 100 # Music player buttons self.play_pause_button = toga.Button( '>/II', on_press=self.play_pause, style=Pack(padding=(0,5), height=45, width=45) ) self.rewind_button = toga.Button( '<<', on_press=self.rewind, style=Pack(padding=(0,5), height=45, width=45) ) self.ultra_rewind_button = toga.Button( '<<<', on_press=self.ultra_rewind, style=Pack(padding=(0,5), height=45, width=45) ) self.fforward_button = toga.Button( '>>', on_press=self.fforward, style=Pack(padding=(0,5), height=45, width=45) ) self.ultra_fforward_button = toga.Button( '>>>', on_press=self.ultra_fforward, style=Pack(padding=(0,5), height=45, width=45) ) self.stop_button = toga.Button( 'Stop', on_press=self.stop_music, style=Pack(padding=(0,5), height=45, width=45) ) self.load_button = toga.Button( 'Load', on_press=self.load_music, style=Pack(padding=(0,5), height=45, width=45) ) # Music player box self.music_btn_box = toga.Box( children=[ self.load_button, self.ultra_rewind_button, self.rewind_button, self.play_pause_button, self.fforward_button, self.ultra_fforward_button, self.stop_button, ], style=Pack(direction=ROW, alignment=CENTER) ) self.lbl_playing = toga.Label("Currently Playing: Nothing Yet!", style=Pack( text_align=CENTER, padding_top=5, flex=1)) self.lbl_volume = toga.Label("Volume: " + str(self.volume), style=Pack( text_align=CENTER)) self.btn_vol_up = toga.Button( '+', on_press=self.volume_up, style=Pack(padding=(0,5), height=30, width=30) ) self.btn_vol_down = toga.Button( '-', on_press=self.volume_down, style=Pack(padding=(0,5), height=30, width=30) ) self.volume_box = toga.Box( children=[ self.btn_vol_down, self.lbl_volume, self.btn_vol_up], style=Pack(direction=ROW, alignment=CENTER, padding_top=5) ) self.music_box = toga.Box( children=[ self.music_btn_box, self.volume_box, self.progress_bar, self.lbl_playing ], style=Pack(direction=COLUMN, alignment=CENTER, padding_top=5) )
def build_settings(self): self.exp_duration = toga.Selection( items=[str(i) for i in range(7, 32)]) self.cnt_department = toga.Selection( items=[str(i) for i in range(5, 10)]) self.exp_step = toga.Selection( items=[str(i) + " час" for i in range(1, 10)]) self.select_event_day = toga.Selection( items=[str(i) for i in range(0, 32)]) self.select_event_hour = toga.Selection( items=[str(i) for i in range(5, 10)]) self.btn_start_experiment = toga.Button('Начать моделирование', on_press=self.start_experiment, style=Pack(flex=1, width=250, alignment='right')) self.btn_step = toga.Button('Выполнить шаг моделирования', on_press=self.step, style=Pack(flex=1, width=300, height=38)) self.btn_add_event = toga.Button('Добавить событие', on_press=self.add_event, style=Pack(flex=1, width=300, height=38)) self.add_event_day = toga.Selection(items=[str(i) for i in range(32)]) self.add_event_time = toga.Selection(items=[str(i) for i in range(24)]) self.add_event_duration = toga.Selection( items=[str(i) for i in range(24)]) self.add_event_room = toga.Selection( items=[str(1 + i) for i in range(5)]) self.add_event_name = toga.TextInput(placeholder='Название события') self.add_event_participants_list = toga.Table(['Имя работника'], multiple_select=True, style=table_style) self.add_event_participants = toga.TextInput( placeholder='Участники через запятую', style=Pack(width=200)) self.btn_delete_event = toga.Button('Удалить событие', on_press=self.delete_event, style=Pack(flex=1, width=300, height=38)) self.delete_event_id = toga.Selection( items=[str(i) for i in range(100)]) self.label_curtime = toga.Label("Текущее время: 0 день 0.00", style=main_label_style) self.label_warning = toga.Label("", style=main_label_style) progress = toga.ProgressBar(max=100, value=1, style=Pack(padding_top=15)) self.settings_box = toga.Box(children=[ toga.Box(style=box_style, children=[ toga.Label("Период моделирования", style=label_style), self.exp_duration ]), toga.Box(style=box_style, children=[ toga.Label("Количество отделов", style=label_style), self.cnt_department ]), self.btn_start_experiment, progress, self.label_warning, ], style=Pack(direction=COLUMN, padding=24)) self.step_box = toga.Box(children=[ toga.Box(children=[ self.label_curtime, ]), toga.Box(children=[ toga.Label("Шаг моделирования", style=label_style), self.exp_step, self.btn_step ], style=Pack(direction=ROW, padding=14)) ], style=Pack(direction=COLUMN, padding=24)) self.add_event_box = toga.Box(children=[ toga.Box(style=box_style, children=[ toga.Label("День", style=label_style), self.add_event_day ]), toga.Box(style=box_style, children=[ toga.Label("Время", style=label_style), self.add_event_time ]), toga.Box(style=box_style, children=[ toga.Label("Длительность", style=label_style), self.add_event_duration ]), toga.Box(style=box_style, children=[ toga.Label("Комната", style=label_style), self.add_event_room ]), toga.Box(style=box_style, children=[ toga.Label("Название", style=label_style), self.add_event_name ]), toga.Box(style=box_style, children=[ toga.Label("Участники", style=label_style), self.add_event_participants_list, self.add_event_participants ]), self.btn_add_event, ], style=Pack(direction=COLUMN, padding=24)) self.delete_event_box = toga.Box(children=[ toga.Box(style=box_style, children=[ toga.Label("Номер события", style=label_style), self.delete_event_id ]), self.btn_delete_event, ], style=Pack(direction=COLUMN, padding=24)) self.content_box = toga.Box(children=[ self.settings_box, self.step_box, self.add_event_box, self.delete_event_box ], style=Pack(direction=COLUMN)) return self.content_box
def create_progress_bar(self): self.progress_bar = toga.ProgressBar(style=Pack(flex=1, visibility=VISIBLE), max=1, running=False, value=0)