Example #1
0
 def load_all_apps(self):
     base_menu = Menu([], self.i, self.o, "Main app menu",
                      exitable=False)  # Main menu for all applications.
     base_menu.exit_entry = ["Exit", "exit"]
     base_menu.process_contents()
     self.subdir_menus[self.app_directory] = base_menu
     apps_blocked_in_config = self.config.get("do_not_load", {})
     for path, subdirs, modules in app_walk(self.app_directory):
         for subdir in subdirs:
             # First, we create subdir menus (not yet linking because they're not created in correct order) and put them in subdir_menus.
             subdir_path = os.path.join(path, subdir)
             self.subdir_menus[subdir_path] = Menu([], self.i, self.o,
                                                   subdir_path)
         for _module in modules:
             # Then, we load modules and store them along with their paths
             try:
                 module_path = os.path.join(path, _module)
                 if module_path in apps_blocked_in_config:
                     logger.warning(
                         "App {} blocked from config; not loading".format(
                             module_path))
                     continue
                 app = self.load_app(module_path)
                 logger.info("Loaded app {}".format(module_path))
                 self.app_list[module_path] = app
             except Exception as e:
                 logger.error("Failed to load app {}".format(module_path))
                 logger.error(traceback.format_exc())
                 Printer(["Failed to load",
                          os.path.split(module_path)[1]], self.i, self.o, 2)
     for subdir_path in self.subdir_menus:
         # Now it's time to link menus to parent menus
         if subdir_path == self.app_directory:
             continue
         parent_path = os.path.split(subdir_path)[0]
         ordering = self.get_ordering(parent_path)
         parent_menu = self.subdir_menus[parent_path]
         subdir_menu = self.subdir_menus[subdir_path]
         subdir_menu_name = self.get_subdir_menu_name(subdir_path)
         # Inserting by the ordering given
         parent_menu_contents = self.insert_by_ordering(
             [subdir_menu_name, subdir_menu.activate],
             os.path.split(subdir_path)[1], parent_menu.contents, ordering)
         parent_menu.set_contents(parent_menu_contents)
     for app_path in self.app_list:
         # Last thing is attaching applications to the menu structure created.
         app = self.app_list[app_path]
         subdir_path, app_dirname = os.path.split(app_path)
         ordering = self.get_ordering(subdir_path)
         menu_name = app.menu_name if hasattr(
             app, "menu_name") else app_dirname.capitalize()
         self.bind_callback(app, app_path, menu_name, ordering, subdir_path)
     return base_menu
Example #2
0
 def process_contents(self):
     Menu.process_contents(self)
     if self.prepend_numbers:
         self.prepend_entry_text()