示例#1
0
    def __init__(self, app_name=None, menus=None, example=False):
        # Name used in every menu header
        if app_name is None:
            app_name = 'ACME'

        # Create initial options for main menu
        options = []

        # Adding submenus
        if example is True:
            options += examples
        else:
            if menus is not None:
                for m in menus:
                    check_mro(m)
                options += menus

        # Options with app_name added to it
        new_options = []
        for o in options:
            # Adding the app name to the menu
            o.app_name = app_name
            o.options.append(('Main Menu', getattr(o, 'done')))

            # Quick hack to add users class name as menu option
            # only for main menu
            new_o = (o.menu_name, o)
            new_options.append(new_o)

        new_options.append(('Quit', self.quit))

        # Sanatisation checks on passed options
        check_options_else_raise(new_options)

        # Initilazie main menu with submenus
        self.main = MainMenu(new_options)

        # Adding the app name to the main menu
        self.main.app_name = app_name
示例#2
0
文件: engine.py 项目: JMSwag/Menus
class Engine(object):

    def __init__(self, app_name=None, menus=None, example=False):
        # Name used in every menu header
        if app_name is None:
            app_name = 'ACME'

        # Create initial options for main menu
        options = []

        # Adding submenus
        if example is True:
            options += examples
        else:
            if menus is not None:
                for m in menus:
                    check_mro(m)
                options += menus

        # Options with app_name added to it
        new_options = []
        for o in options:
            # Adding the app name to the menu
            o.app_name = app_name
            o.options.append(('Main Menu', getattr(o, 'done')))

            # Quick hack to add users class name as menu option
            # only for main menu
            new_o = (o.menu_name, o)
            new_options.append(new_o)

        new_options.append(('Quit', self.quit))

        # Sanatisation checks on passed options
        check_options_else_raise(new_options)

        # Initilazie main menu with submenus
        self.main = MainMenu(new_options)

        # Adding the app name to the main menu
        self.main.app_name = app_name

    # Starts event loop
    def start(self):  # pragma: no cover
        while 1:
            start = self.main.display()
            start()

    def quit(self):  # pragma: no cover
        log.debug('Quitting')
        sys.exit(0)
示例#3
0
class Engine(object):
    def __init__(self, app_name=None, menus=None, example=False):
        # Name used in every menu header
        if app_name is None:
            app_name = 'ACME'

        # Create initial options for main menu
        options = []

        # Adding submenus
        if example is True:
            options += examples
        else:
            if menus is not None:
                for m in menus:
                    check_mro(m)
                options += menus

        # Options with app_name added to it
        new_options = []
        for o in options:
            # Adding the app name to the menu
            o.app_name = app_name
            o.options.append(('Main Menu', getattr(o, 'done')))

            # Quick hack to add users class name as menu option
            # only for main menu
            new_o = (o.menu_name, o)
            new_options.append(new_o)

        new_options.append(('Quit', self.quit))

        # Sanatisation checks on passed options
        check_options_else_raise(new_options)

        # Initilazie main menu with submenus
        self.main = MainMenu(new_options)

        # Adding the app name to the main menu
        self.main.app_name = app_name

    # Starts event loop
    def start(self):  # pragma: no cover
        while 1:
            start = self.main.display()
            start()

    def quit(self):  # pragma: no cover
        log.debug('Quitting')
        sys.exit(0)
示例#4
0
文件: engine.py 项目: JMSwag/Menus
    def __init__(self, app_name=None, menus=None, example=False):
        # Name used in every menu header
        if app_name is None:
            app_name = 'ACME'

        # Create initial options for main menu
        options = []

        # Adding submenus
        if example is True:
            options += examples
        else:
            if menus is not None:
                for m in menus:
                    check_mro(m)
                options += menus

        # Options with app_name added to it
        new_options = []
        for o in options:
            # Adding the app name to the menu
            o.app_name = app_name
            o.options.append(('Main Menu', getattr(o, 'done')))

            # Quick hack to add users class name as menu option
            # only for main menu
            new_o = (o.menu_name, o)
            new_options.append(new_o)

        new_options.append(('Quit', self.quit))

        # Sanatisation checks on passed options
        check_options_else_raise(new_options)

        # Initilazie main menu with submenus
        self.main = MainMenu(new_options)

        # Adding the app name to the main menu
        self.main.app_name = app_name