def returns_on_enter_runner(self, contents, num_elements, exp_return1, exp_return2): lb = Listbox(contents, get_mock_input(), get_mock_output(), name=lb_name, config={}) lb.refresh = lambda *args, **kwargs: None # Checking at the start of the list def scenario(): lb.select_entry() # KEY_ENTER assert not lb.in_foreground with patch.object(lb, 'idle_loop', side_effect=scenario) as p: return_value = lb.activate() assert return_value == exp_return1 # Checking at the end of the list def scenario(): for i in range(num_elements - 1): lb.move_down() # KEY_DOWN x2 lb.select_entry() # KEY_ENTER assert not lb.in_foreground with patch.object(lb, 'idle_loop', side_effect=scenario) as p: return_value = lb.activate() assert return_value == exp_return2
def test_left_key_returns_none(self): """ A Listbox shouldn't return anything when LEFT is pressed""" num_elements = 3 contents = [["A" + str(i), "a" + str(i)] for i in range(num_elements)] lb = Listbox(contents, get_mock_input(), get_mock_output(), name=lb_name, config={}) lb.refresh = lambda *args, **kwargs: None # Checking at the start of the list def scenario(): lb.deactivate() # KEY_LEFT assert not lb.in_foreground with patch.object(lb, 'idle_loop', side_effect=scenario) as p: return_value = lb.activate() assert return_value is None # Checking at the end of the list def scenario(): for i in range(num_elements): lb.move_down() # KEY_DOWN x3 lb.deactivate() # KEY_LEFT assert not lb.in_foreground with patch.object(lb, 'idle_loop', side_effect=scenario) as p: return_value = lb.activate() assert return_value is None
def callback(): listbox_contents = [ ["NumberAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 101], ["String", "stringstring"], ["Tuple", (1, 2, 3)]] lb = Listbox(listbox_contents, i, o) HelpOverlay(lambda: print("Halp plz")).apply_to(lb) lb.activate()
def shows_data_on_screen_runner(self, contents): i = get_mock_input() o = get_mock_output() lb = Listbox(contents, i, o, name=lb_name, config={}) def scenario(): lb.deactivate() with patch.object(lb, 'idle_loop', side_effect=scenario) as p: lb.activate() #The scenario should only be called once assert lb.idle_loop.called assert lb.idle_loop.call_count == 1 assert o.display_data.called assert o.display_data.call_count == 1 #One in to_foreground assert o.display_data.call_args[0] == ('A0', 'A1', 'A2', lb.exit_entry[0])
def test_left_key_works_when_not_exitable(self): """Listbox should still exit on KEY_LEFT when exitable is set to False""" num_elements = 3 contents = [["A" + str(i), "a" + str(i)] for i in range(num_elements)] lb = Listbox(contents, get_mock_input(), get_mock_output(), name=lb_name, config={}) lb.refresh = lambda *args, **kwargs: None def scenario(): assert "KEY_LEFT" in lb.keymap lb.deactivate() assert not lb.in_foreground with patch.object(lb, 'idle_loop', side_effect=scenario) as p: lb.activate()
def graphical_display_redraw_runner(self, contents): o = get_mock_graphical_output() lb = Listbox(contents, get_mock_input(), o, name=lb_name, config={}) Canvas.fonts_dir = fonts_dir # Exiting immediately, but we should get at least one redraw def scenario(): lb.deactivate() # KEY_LEFT assert not lb.in_foreground with patch.object(lb, 'idle_loop', side_effect=scenario) as p: return_value = lb.activate() assert o.display_image.called assert o.display_image.call_count == 1 #One in to_foreground
def selected_single_el_entry_runner(self, contents, selected): lb = Listbox(contents, get_mock_input(), get_mock_output(), selected=selected, name=lb_name, config={}) lb.refresh = lambda *args, **kwargs: None # Checking at the start of the list def scenario(): lb.select_entry() # KEY_ENTER assert not lb.in_foreground with patch.object(lb, 'idle_loop', side_effect=scenario) as p: return_value = lb.activate() assert return_value == selected
class LoadingBarExampleApp(ZeroApp): def __init__(self, i, o): super(LoadingBarExampleApp, self).__init__(i, o) self.menu_name = "Loading bar test app" self.default_progress_bar = ProgressBar(self.i, self.o) self.text_progress_bar = TextProgressBar(self.i, self.o, refresh_interval=.1, show_percentage=True, percentage_offset=0) self.circular_progress = CircularProgressBar(self.i, self.o, show_percentage=True) self.dotted_progress_bar = IdleDottedMessage(self.i, self.o) self.throbber = Throbber(self.i, self.o, message="Test message") self.graphical_progress_bar = GraphicalProgressBar(self.i, self.o) self.default_progress_bar = ProgressBar(self.i, self.o) lb_contents = [ ["Default progress bar", self.default_progress_bar], ["Text progress bar", self.text_progress_bar], ["Dotted idle ", self.dotted_progress_bar], ["Circular progress ", self.circular_progress], ["Idle Throbber", self.throbber], ["Graphical Loading bar", self.graphical_progress_bar], ] self.bar_choice_listbox = Listbox(lb_contents, self.i, self.o) def on_start(self): with self.bar_choice_listbox.activate() as chosen_loading_bar: if hasattr(chosen_loading_bar, "progress"): for i in range(101): chosen_loading_bar.progress = i sleep(0.01) sleep(1) for i in range(101)[::-1]: chosen_loading_bar.progress = i sleep(0.1) else: sleep(3)
class LoadingBarExampleApp(ZeroApp): def __init__(self, i, o): super(LoadingBarExampleApp, self).__init__(i, o) self.menu_name = "Loading bar test app" self.progress_bar = ProgressBar( self.i, self.o, refresh_interval=.1, show_percentage=True, percentage_offset=0, keymap={"KEY_RIGHT": self.increase_progress}) self.dotted_progress_bar = DottedProgressIndicator(self.i, self.o, refresh_interval=.1) lb_contents = [["Progress bar", self.progress_bar], ["Dotted bar", self.dotted_progress_bar]] self.bar_choice_listbox = Listbox(lb_contents, self.i, self.o) def increase_progress(self): self.loading_screen.progress += .05 def on_start(self): super(LoadingBarExampleApp, self).on_start() chosen_loading_bar = self.bar_choice_listbox.activate() chosen_loading_bar.run_in_background() if isinstance(chosen_loading_bar, ProgressBar): for i in range(101): chosen_loading_bar.progress = float(i) / 100 sleep(0.1) sleep(2) for i in range(101)[::-1]: chosen_loading_bar.progress = float(i) / 100 sleep(0.1) else: sleep(3) chosen_loading_bar.deactivate()
def select_loglevel(current): available_levels = get_available_levels() lb_contents = [[level.capitalize(), level] for level in available_levels] lb = Listbox(lb_contents, i, o, "Loglevel selection listbox") lb.start_pointer = available_levels.index(current.lower()) return lb.activate()