def create_menu_structure(self): base_subdir = self.app_directory.rstrip('/') for subdir_path in self.subdir_paths: self.subdir_menu_contents[subdir_path] = [] for subdir_path in self.subdir_paths: if subdir_path == base_subdir: continue parent_path = os.path.split(subdir_path)[0] menu_name = self.get_subdir_menu_name(subdir_path) subdir_entry = Entry(menu_name, type="dir", path=subdir_path) self.subdir_menu_contents[parent_path].append(subdir_entry) subdir_menu_paths = self.subdir_menu_contents.keys() for app_path, app_obj in self.app_list.items(): if self.app_has_callback(app_obj): subdir_menu_name = max( [n for n in subdir_menu_paths if app_path.startswith(n)]) menu_name = self.get_app_name(app_obj, app_path) app_entry = Entry(menu_name, type="app", obj=app_obj, path=app_path) self.subdir_menu_contents[subdir_menu_name].append(app_entry) for path, subdir_contents in self.subdir_menu_contents.items(): ordering = self.get_ordering(path) unordered_contents = self.prepare_menu_contents_for_ordering( subdir_contents) menu_contents = self.order_contents_by_ordering( unordered_contents, ordering) creator = self.subdir_menu_creators.get(path, self.create_subdir_menu) menu = creator(path, menu_contents) for overlay_cb in self.subdir_menu_overlays.get(path, []): overlay_cb(menu) self.subdir_menus[path] = menu return self.subdir_menus[base_subdir]
def test_shows_data_on_screen_with_entries(self): """Tests whether the Listbox outputs data on screen when it's ran - using entries""" num_elements = 3 contents = [ Entry("A" + str(i), name="a" + str(i)) for i in range(num_elements) ] self.shows_data_on_screen_runner(contents)
def test_graphical_display_entry_eh2_redraw(self): num_elements = 3 contents = [ Entry(["A" + str(i), "B" + str(i)], name="a" + str(i)) for i in range(num_elements) ] self.graphical_display_redraw_eh2_wrapper(contents)
def test_selected_entry(self): num_elements = 3 contents = [ Entry("A" + str(i), name="a" + str(i)) for i in range(num_elements) ] selected = contents[1].name self.selected_runner(contents, selected)
def test_returns_on_enter_entry(self): num_elements = 3 contents = [ Entry("A" + str(i), name="a" + str(i)) for i in range(num_elements) ] self.returns_on_enter_runner(contents, num_elements, contents[0].name, contents[-1].name)
def __init__(self, **kwargs): Renderer.__init__(self, **kwargs) self.label = Label(padding=self.padding, overflow=pango.EllipsizeMode.END) self.label.graphics = self.graphics self._prev_dict = {} self._editor = Entry()
def test_entry_callback_is_executed(self): num_elements = 2 contents = [Entry("A" + str(i)) for i in range(num_elements)] cb1 = Mock() cb2 = Mock() contents[0].cb = cb1 contents[1].cb = cb2 self.callback_is_executed_wrapper(contents, cb1, cb2)
def on_start(self): dir = "resources/" icons = [f for f in os.listdir(dir) if f.endswith(".png")] icon_paths = [[f, os.path.join(dir, f)] for f in icons] grid_contents = [Entry(f.rsplit('.', 1)[0].capitalize(), icon=Image.open(p), cb=lambda x=f: test_func(x)) \ for f,p in icon_paths] self.gm = GridMenu(grid_contents, self.i, self.o, entry_width=32, draw_lines=False) self.overlay1 = GridMenuLabelOverlay() self.overlay1.apply_to(self.gm) self.overlay2 = GridMenuSidebarOverlay(self.sidebar_cb) self.overlay2.apply_to(self.gm) self.gm.activate()
def get_scan_results_contents(): network_menu_contents = [] networks = wpa_cli.get_scan_results() for network in networks: if network["ssid"] == '': ui_ssid = '[Hidden]' else: ui_ssid = network["ssid"] network_cache = wpa_cli.list_configured_networks() network_names = [n["ssid"] for n in network_cache] network_is_known = network["ssid"] in network_names network_is_secured = False if wpa_cli.is_open_network( network) else True network["known"] = network_is_known network["secured"] = network_is_secured cb = lambda x=network: network_info_menu(x) network_menu_contents.append(Entry(ui_ssid, cb=cb, \ network_secured=network_is_secured, \ network_known=network_is_known )) return network_menu_contents
def test_entering_value_with_entries(self): contents = [ Entry("Entry {}".format(x), name=x) for x in ("1", "3", "2") ] self.entering_value_runner(contents)
def test_shows_entry_data_on_screen(self): """Tests whether the OrderAdjust outputs data on screen when it's ran""" o = get_mock_output() contents = [Entry(str(x)) for x in range(o.rows + 4)] self.shows_data_on_screen_wrapper(contents, o)
def test_entering_value_with_entries_no_name(self): contents = [Entry(x) for x in ("1", "3", "2")] self.entering_value_runner(contents)
def test_selected_single_el_entry(self): num_elements = 3 contents = [Entry("A" + str(i)) for i in range(num_elements)] selected = contents[1].text self.selected_single_el_entry_runner(contents, selected)
def test_entry_shows_data_on_screen(self): """Tests whether the BaseListUIElement outputs data on screen when it's ran""" num_elements = 3 contents = [Entry("A" + str(i), name="a" + str(i)) for i in range(num_elements)] self.shows_data_on_screen_runner(contents)
def test_enter_on_last_returns_right_with_entries(self): num_elements = 3 contents = [ Entry("A" + str(i), name="a" + str(i)) for i in range(num_elements) ] self.enter_on_last_returns_right_runner(contents, num_elements)
def callback(): contents = [ Entry("Hello1", cb=lambda: print("1")), Entry("Hello2", cb=lambda: print("2"), cb2=lambda: print("3")) ] Menu(contents, i, o, "Entry object test menu").activate()
def test_graphical_display_redraw_with_entries(self): num_elements = 2 contents = [ Entry("A" + str(i), name="a" + str(i)) for i in range(num_elements) ] self.graphical_display_redraw_runner(contents)