Beispiel #1
0
    def __init__(self, widget_properties):
        Menu.__init__(self, widget_properties)
        l_next = _(u'next >>')
        l_prev = _(u'<< previous')

        self.prev_button = MenuButton(label=l_prev, \
            widget_properties=self.widget_properties)
        self.next_button = MenuButton(l_next, \
            widget_properties=self.widget_properties)
        self.add(self.prev_button, 'center')
        self.add(self.next_button, 'center')

        self.bc_top = self.nc_top + 10 + self.nc_height
        self.bc_left = 20
        self.bc_width = self.screen_res_x - 40
        self.bc_height = self.screen_res_y - self.bc_top - 25
        self.bc_right = 20
        self.bc_bottom = 30
        self.box_cont = pudding.container.Container( \
                self, left=self.bc_left, top=self.bc_top, \
                width=self.bc_width, height=self.bc_height, \
                right=self.bc_right)

        self.bg_box = pudding.control.Box(self.box_cont, \
                width=self.bc_width, \
                height=self.bc_height, \
                background_color=self.box_bg_color, \
                border_color=self.box_border_color, \
                z_index=-3)
        self.bg_box.anchors = pudding.ANCHOR_ALL

        self.directory_cont = pudding.container.HorizontalContainer( \
            self.box_cont, top=self.height * 0.02, \
            right=self.right, width=self.width, \
            height=self.height, left=0)

        pos_size = {}
        pos_size['top'] = 0
        pos_size['left'] = 0
        pos_size['height'] = self.height * 0.05
        pos_size['width'] = self.width * 0.3

        self.directory_cont.anchors = pudding.ANCHOR_ALL
        self.directory_cont.padding = 10

        self.directory_up_button = MenuButton("<<", \
            widget_properties = self.widget_properties, pos_size=pos_size)
        self.directory_cont.add_child(self.directory_up_button, \
                pudding.ALIGN_LEFT)

        pos_size = {}
        pos_size['top'] = 0
        pos_size['left'] = self.width * 0.9
        pos_size['height'] = self.height * 0.05
        pos_size['width'] = self.width * 0.3

        self.choose_base_button = MenuButton("", \
            widget_properties = self.widget_properties, pos_size=pos_size)
        self.directory_cont.add_child(self.choose_base_button, \
                pudding.ALIGN_RIGHT)
Beispiel #2
0
    def __init__(self, widget_properties):
        Menu.__init__(self, widget_properties)
        l_next = _(u'next >>')
        l_prev = _(u'<< previous')

        self.prev_button = MenuButton(label=l_prev, \
            widget_properties=self.widget_properties)
        self.next_button = MenuButton(l_next, \
            widget_properties=self.widget_properties)
        self.add(self.prev_button, 'center')
        self.add(self.next_button, 'center')

        self.bc_top = self.nc_top + 10 + self.nc_height
        self.bc_left = 20
        self.bc_width = self.screen_res_x - 40
        self.bc_height = self.screen_res_y - self.bc_top - 25
        self.bc_right = 20
        self.bc_bottom = 30
        self.box_cont = pudding.container.Container( \
                self, left=self.bc_left, top=self.bc_top, \
                width=self.bc_width, height=self.bc_height, \
                right=self.bc_right)

        self.bg_box = pudding.control.Box(self.box_cont, \
                width=self.bc_width, \
                height=self.bc_height, \
                background_color=self.box_bg_color, \
                border_color=self.box_border_color, \
                z_index=-3)
        self.bg_box.anchors = pudding.ANCHOR_ALL

        self.directory_cont = pudding.container.HorizontalContainer( \
            self.box_cont, top=self.height * 0.02, \
            right=self.right, width=self.width, \
            height=self.height, left=0)

        pos_size = {}
        pos_size['top'] = 0
        pos_size['left'] = 0
        pos_size['height'] = self.height * 0.05
        pos_size['width'] = self.width * 0.3

        self.directory_cont.anchors = pudding.ANCHOR_ALL
        self.directory_cont.padding = 10

        self.directory_up_button = MenuButton("<<", \
            widget_properties = self.widget_properties, pos_size=pos_size)
        self.directory_cont.add_child(self.directory_up_button, \
                pudding.ALIGN_LEFT)

        pos_size = {}
        pos_size['top'] = 0
        pos_size['left'] = self.width * 0.9
        pos_size['height'] = self.height * 0.05
        pos_size['width'] = self.width * 0.3

        self.choose_base_button = MenuButton("", \
            widget_properties = self.widget_properties, pos_size=pos_size)
        self.directory_cont.add_child(self.choose_base_button, \
                pudding.ALIGN_RIGHT)
Beispiel #3
0
 def __init__(self, app_dir, camera, theme_mgr, widget_properties, \
         menu_list, config, player=None):
     Menu.__init__(self, widget_properties)
     self.app_dir = app_dir
     self.camera = camera
     self.theme_mgr = theme_mgr
     self.player = player
     self.menu_list = menu_list
     self.menu_list['singscreen'] = self
     self.config = config
     self.widget_properties['theme_mgr'] = theme_mgr
Beispiel #4
0
 def __init__(self, app_dir, camera, theme_mgr, widget_properties, \
         menu_list, config, player=None):
     Menu.__init__(self, widget_properties)
     self.app_dir = app_dir
     self.camera = camera
     self.theme_mgr = theme_mgr
     self.player = player
     self.menu_list = menu_list
     self.menu_list['singscreen'] = self
     self.config = config
     self.widget_properties['theme_mgr'] = theme_mgr
Beispiel #5
0
    def __init__(self, widget_props, song_data=None, \
            player=None, keyboard_event=None, song=None, \
            song_event=None):
        Menu.__init__(self, widget_props)
        l_continue = _(u'continue singing')
        l_quit = _(u'quit song')

        self.song_data = song_data
        self.song = song
        self.player = player
        self.keyboard_event = keyboard_event
        self.song_event = song_event

        args = {}
        args['widgets'] = [self]
        self.add(MenuButton(label=l_quit, \
                function=self._end, args=args, \
                widget_properties=widget_props), 'horiz')
        self.add(MenuButton(label=l_continue, \
                function=self.continue_song, args=args, \
                widget_properties=widget_props), 'horiz')
Beispiel #6
0
    def __init__(self, app_dir, widget_properties, theme_mgr, main_menu, player):

        Menu.__init__(self, widget_properties)
        self.l_help_hint_0 = _(u'Press [h] for help...')
        self.l_help_hint_1 = _(u'Press [ESC] to go back...')
        self.l_help_hint = self.l_help_hint_0
        self.l_bpm = _(u'BPM: ')
        self.l_line_no = _(u'Line: ')
        self.separator = u' - '
        self.h_help = _(u'Help')
        self.help_file_path = os.path.join(app_dir, 'misc', 'HELP.txt')
        self.widget_properties = widget_properties
        self.app_dir = app_dir
        self.parent_widget = widget_properties['root_widget']
        self.theme_mgr = theme_mgr

        self.screen_res_x = self.widget_properties['config']['screen'].as_int('resolution_x')
        self.screen_res_y = self.widget_properties['config']['screen'].as_int('resolution_y')

        self.font_p = widget_properties['font']['p']['obj']
        self.color_p = widget_properties['font']['p']['color']

        self.font_h = widget_properties['font']['h1']['obj']
        self.color_h = widget_properties['font']['h1']['color']

        self.main_menu = main_menu
        self.help_hint_cont = pudding.container.VerticalContainer( \
                self, left=self.screen_res_x / 2.5, top=5)
        self.help_hint_cont.right = 10
        self.help_hint_cont.anchors = pudding.ANCHOR_ALL
        self.keyboard_event = KeyboardEvent(self.widget_properties, theme_mgr)

        self.txt_input = InputField(self.widget_properties, '')
        self.txt_input.label.visible = 0

        self.player = player
        self.__connect_keys__()
        self.msg = dict()
Beispiel #7
0
    def __init__(self, widget_properties, config, theme_mgr, camera, core=None):
        Menu.__init__(self, widget_properties)
        self.core = core
        self.config = config

        self.locale = self.config['misc']['locale']
        self.lm = LocaleManager(self.core.app_dir)
        valid_languages = self.lm.get_langs()
        self.lm.install(self.locale)


        self.theme_mgr = theme_mgr
        self.camera = camera
        # Button labels:
        l_start = _(u"Sing")#_(u'Party Mode')
        l_song_editor = _(u'Song Editor')
        l_about = _(u'About')
        l_quit2 = _(u'Quit')
        l_settings_main = _(u'Settings')
        l_back =  _(u'back')
        l_save =  _(u'save')
        l_save_quit =  _(u'save & restart')
        l_quit =  _(u'quit')

        # Menu headings:
        h1_main_menu =  _(u'Main Menu')
        h1_about =  _(u'About')
        h1_song_browser =  _(u'Choose a song...')


        # File paths:
        about_file = os.path.join('misc', 'ABOUT.txt')
        logo_path = 'logo.png'
        show_logo = False

        #self.menus['main'] = main_menu # obsolete?
        # About menu:
        about_menu = MenuText(self.widget_properties, top=self.screen_res_y / 3, \
                left=self.screen_res_x / 2)
        about_menu.set_heading(h1_about)
        about_back = MenuButton(l_back, widget_properties = self.widget_properties, \
            target = self)
        about_menu.add(about_back, 'horiz')
        about_quit = MenuButton(l_quit, function=self.quit, \
            pos_size=0, widget_properties = self.widget_properties)
        about_menu.add(about_quit, 'center')
        fd_license = open(os.path.join(self.core.app_dir, about_file), 'r')
        license = fd_license.read()
        about_menu.add_text(license)

        self.settings = Settings(self.config, self.widget_properties, self.lm, self, self.core)

        self.load_player()
        song_editor = SongEditor(self.core.app_dir, self.widget_properties, \
            self.theme_mgr, self, player=self.player)

        # Sing screen:
        sing_screen = SingScreen(app_dir=self.core.app_dir, main_menu=self, \
                    camera=self.camera, theme_mgr=self.theme_mgr, \
                    widget_properties=self.widget_properties, \
                    config=self.config, player=self.player)

        self.add_child(sing_screen)

        pos_size = {}
        pos_size['height'] = self.screen_res_y / 16
        pos_size['width'] = self.screen_res_x - 80
        pos_size['top'] = 10
        pos_size['left'] = 10

        # Song browser:
        entries = []
        entry_sing_screen = {}
        entry_sing_screen['song_start_text'] = 'Start'
        entry_sing_screen['start_screen'] = sing_screen
        entry_sing_screen['menu_text'] = _(u"Sing")
        entry_sing_screen['default_manager'] = 0
        entry_song_editor = {}
        entry_song_editor['song_start_text'] = 'Edit'
        entry_song_editor['start_screen'] = song_editor
        entry_song_editor['menu_text'] = _(u'Song Editor')
        entry_song_editor['default_manager'] = 1
        entries.append(entry_sing_screen)
        entries.append(entry_song_editor)

        browsers = []
        for entry in entries:
            browser = MenuBrowser(entry['default_manager'], self.widget_properties, \
                entry['start_screen'], self.config, player = self.player,\
                song_start_text=entry['song_start_text'])
            browser.set_heading(h1_song_browser)

            back_button = MenuButton(l_back, target=self, \
                widget_properties = self.widget_properties, \
                function=browser.stop_preview)
            quit_button = MenuButton(l_quit, function=self.quit, \
                pos_size=0, widget_properties = self.widget_properties)
            browser.add(back_button, 'center')
            browser.add(quit_button, 'center')
            browsers.append(browser)
            # Add buttons to main menu:
            args = {}
            args['selected'] = entry['start_screen']
            args['widgets'] = [self]
            self.add(MenuButton(entry['menu_text'], target=browser, function=browser.start_song,\
                widget_properties=self.widget_properties, pos_size=pos_size), 'center')

#        self.settings.init_menus(main_menu, pos_size)
        self.add(MenuButton(l_settings_main, target=self.settings, \
            widget_properties=self.widget_properties, pos_size=pos_size), 'center')
        self.add(MenuButton(l_about, target=about_menu, \
            widget_properties=self.widget_properties, pos_size=pos_size), 'center')
        self.add(MenuButton(l_quit2, function=self.quit, args=0, \
            widget_properties=self.widget_properties, pos_size=pos_size), 'center')


        use_pil = int(self.config['screen'].as_bool('pil'))
        # logo:
        if use_pil and show_logo:
            try:
                logo = pudding.control.Logo(self.parent, logo_path, z_index=4)
            except:
                pass
Beispiel #8
0
    def init_menus(self):
        """Initialize all menus, then tell pudding main loop to idle().
        """

        # Button labels:
        l_start = _(u"Sing")#_(u'Party Mode')
        l_song_editor = _(u'Song Editor')

        l_about = _(u'About')
        l_quit2 = _(u'Quit')

        l_back =  _(u'back')
        l_save =  _(u'save')
        l_save_quit =  _(u'save & restart')
        l_quit =  _(u'quit')

        # Menu headings:
        h1_main_menu =  _(u'Main Menu')
        h1_about =  _(u'About')
        h1_song_browser =  _(u'Choose a song...')


        # File paths:
        about_file = os.path.join('misc', 'ABOUT.txt')
        logo_path = 'logo.png'
        show_logo = False

        self.menus = {}

        # Main menu:
        main_menu = Menu(self.widget_properties)

        self.menus['main'] = main_menu # obsolete?
        # About menu:
        about_menu = MenuText(self.widget_properties, top=self.screen_res_y / 3, \
                left=self.screen_res_x / 2)
        about_menu.set_heading(h1_about)
        about_back = MenuButton(l_back, widget_properties = self.widget_properties, \
            target = main_menu)
        about_menu.add(about_back, 'horiz')
        about_quit = MenuButton(l_quit, function=self.quit, \
            pos_size=0, widget_properties = self.widget_properties)
        about_menu.add(about_quit, 'center')
        fd_license = open(os.path.join(self.app_dir, about_file), 'r')
        license = fd_license.read()
        about_menu.add_text(license)

        self.load_player()
        song_editor = SongEditor(self.app_dir, self.widget_properties, \
            self.theme_mgr, main_menu, player=self.player)

        # Sing screen:
        sing_screen = SingScreen(app_dir=self.app_dir, \
                    camera=self.camera, theme_mgr=self.theme_mgr, \
                    widget_properties=self.widget_properties, \
                    menu_list=self.menus, config=self.config, \
                    player=self.player)

        pos_size = {}
        pos_size['height'] = self.screen_res_y / 16
        pos_size['width'] = self.screen_res_x - 80
        pos_size['top'] = 10
        pos_size['left'] = 10

        # Song browser:
        entries = []
        entry_sing_screen = {}
        entry_sing_screen['song_start_text'] = 'Start'
        entry_sing_screen['start_screen'] = sing_screen
        entry_sing_screen['menu_text'] = _(u"Sing")
        entry_sing_screen['default_manager'] = 0
        entry_song_editor = {}
        entry_song_editor['song_start_text'] = 'Edit'
        entry_song_editor['start_screen'] = song_editor
        entry_song_editor['menu_text'] = _(u'Song Editor')
        entry_song_editor['default_manager'] = 1
        entries.append(entry_sing_screen)
        entries.append(entry_song_editor)

        browsers = []
        for entry in entries:
            browser = MenuBrowser(entry['default_manager'], self.widget_properties, \
                entry['start_screen'], self.config, player = self.player,\
                song_start_text=entry['song_start_text'])
            browser.set_heading(h1_song_browser)

            back_button = MenuButton(l_back, target=main_menu, \
                widget_properties = self.widget_properties, \
                function=browser.stop_preview)
            quit_button = MenuButton(l_quit, function=self.quit, \
                pos_size=0, widget_properties = self.widget_properties)
            browser.add(back_button, 'center')
            browser.add(quit_button, 'center')
            browsers.append(browser)
            # Add buttons to main menu:
            args = {}
            args['selected'] = entry['start_screen']
            args['widgets'] = [main_menu]
            main_menu.add(MenuButton(entry['menu_text'], target=browser, function=browser.start_song,\
                widget_properties=self.widget_properties, pos_size=pos_size), 'center')

        self.settings.init_menus(main_menu, pos_size)

        main_menu.add(MenuButton(l_about, target=about_menu, \
            widget_properties=self.widget_properties, pos_size=pos_size), 'center')
        main_menu.add(MenuButton(l_quit2, function=self.quit, args=0, \
            widget_properties=self.widget_properties, pos_size=pos_size), 'center')

        # hide the loading label:
        self.loading_cont.visible = 0
        use_pil = int(self.config['screen'].as_bool('pil'))
        # logo:
        if use_pil and show_logo:
            try:
                logo = pudding.control.Logo(self.root_widget, logo_path, z_index=4)
            except:
                pass

        main_menu.show()
        pudding.main_loop.MainLoop(self.root_world).idle()
Beispiel #9
0
    def __init__(self, config, widget_properties, locale_manager, main_menu, core=None):
        Menu.__init__(self, widget_properties)
        self.core = core
        self.main_menu = main_menu
        self.widget_properties = widget_properties
        self.config = config
        self.disp = DisplayProperties()

        pos_size = {}
        pos_size['height'] = self.screen_res_y / 16
        pos_size['width'] = self.screen_res_x - 80
        pos_size['top'] = 10
        pos_size['left'] = 10

        # Button labels:
        l_back =  _(u'back')
        l_save =  _(u'save')
        l_save_quit =  _(u'save & restart')
        l_quit =  _(u'quit')

        # Menu headings:
        h1_settings_main =  _(u'Settings')

        # Settings:
        on_off_toggle = [('off'), ('on')]

       # Options parent menu:
        self.options_menu_main = self
        self.options_menu_main.set_heading(h1_settings_main)

        # Add buttons to options parent menu:
        self.options_menu_main.add(MenuButton(l_back, target=self.main_menu, \
            widget_properties=self.widget_properties, pos_size=pos_size), 'horiz')
        #self.options_menu_main.add(MenuButton(l_save, function=self.save, \
        #    widget_properties = self.widget_properties, pos_size=pos_size), 'horiz')
        #self.options_menu_main.add(MenuButton(l_save_quit, function=self.save, \
        #    args='quit', widget_properties=self.widget_properties, pos_size=pos_size), 'horiz')

        # Options sub menus:
        for k, v in self.config.iteritems():
            # Options sub menus:
            menu = MenuGroup(self.widget_properties, key=k)
            menu.set_heading(_(k[0].upper() + k[1:]) + ' ' + _('Settings'))

            self.options_menu_main.add(
                MenuButton(_(k[0].upper() + k[1:]), target=menu, \
                widget_properties=self.widget_properties, \
                pos_size=pos_size), 'center')
            back_from_screen = MenuButton(l_back, \
                target=self.options_menu_main, \
                widget_properties=self.widget_properties)

            save_button = MenuButton(l_save, function=self.save, \
                args=[menu, 'go_on'], widget_properties=self.widget_properties)
            save_quit_button = MenuButton(l_save_quit, function=self.save, \
                args=[menu, 'quit'], widget_properties=self.widget_properties)

            # Add items to settings menus:
            menu.add(back_from_screen, 'center')
            menu.add(save_button, 'center')
            menu.add(save_quit_button, 'center')

            x_items = []
            for key, value in v.iteritems():
                item_spec = v.configspec[key]
                if item_spec.startswith('boolean'):
                    if value == True:
                        toggle='on'
                    else:
                        toggle='off'
                    x_items.append({'info' : _(key),
                        'button_type' : 'toggle',
                        'toggle_items' : on_off_toggle,
                        'selected_item' : toggle})
                elif item_spec.startswith('option'):
                    options = item_spec.strip('option(').strip(')').split(',')
                    choices = []
                    for option in options:
                        option = option.strip().replace("'", '')
                        if option.startswith('default='):
                            default_value = option.split('=')[1]
                        else:
                            choices.append(option.strip())
                    try:
                        selected_index = choices.index(value)
                    except ValueError:
                        selected_index = choices.index(default_value)

                    x_items.append({'info' : key,
                        'button_type' : 'toggle',
                        'toggle_items' : choices,
                        'selected_item' : selected_index})
            if len(x_items) > 0:
                item_group = {'heading' : k, 'items' : x_items}
                menu.add_group(item_group)
        '''
Beispiel #10
0
    def init_menus(self, main_menu, pos_size):
        # Button labels:
        l_settings_main = _(u'Settings')
        l_settings_screen = _(u'Screen')
        l_settings_sound = _(u'Sound')
        l_settings_theme = _(u'Theme')
        l_settings_misc = _(u'Misc')
        l_back =  _(u'back')
        l_save =  _(u'save')
        l_save_quit =  _(u'save & restart')
        l_quit =  _(u'quit')

        # Menu headings:
        h1_settings_main =  _(u'Settings')
        h1_settings_screen =  _(u'Screen Settings')
        h2_settings_screen =  _(u'SCREEN:')
        h1_settings_sound =  _(u'Sound Settings')
        h2_settings_sound =  _(u'SOUND:')
        h1_settings_theme =  _(u'Theme Settings')
        h2_settings_theme =  _(u'THEME:')
        h1_settings_misc = _(u'Miscellaneous Settings')
        h2_settings_misc = _(u'Miscellaneous')

        # Settings:
        valid_languages = self.lm.get_langs()
        on_off_toggle = [_('off'), _('on')]
        i_resolution =  _(u'Resolution:')
        i_fullscreen =  _(u'Fullscreen:')
        i_fps_label =  _(u'FPS label:')
        i_pil =  _(u'Cover images:')
        i_sound_output =  _(u'Select sound output engine:')
        i_sound_input =  _(u'Select sound input engine:')
        i_song_preview =  _(u'Play preview in song browser:')
        i_theme =  _(u'Choose a theme:')
        i_lan = _(u'Choose a language:')
        i_octave = _(u'Octave correctness:')
        i_helper = _(u'Easier tone hitting:')
        i_allowed_difference = _(u'Allowed difference:')

       # Options parent menu:
        self.options_menu_main = Menu(self.widget_properties)
        self.options_menu_main.set_heading(h1_settings_main)

        # Options sub menus:
        self.options_menu_screen = MenuGroup(self.widget_properties)
        self.options_menu_screen.set_heading(h1_settings_screen)
        self.options_menu_sound = MenuGroup(self.widget_properties)
        self.options_menu_sound.set_heading(h1_settings_sound)
        self.options_menu_theme = MenuGroup(self.widget_properties)
        self.options_menu_theme.set_heading(h1_settings_theme)
        self.options_menu_misc = MenuGroup(self.widget_properties)
        self.options_menu_misc.set_heading(h1_settings_misc)

        # Add buttons to options parent menu:
        self.options_menu_main.add(MenuButton(l_back, target=main_menu, \
            widget_properties=self.widget_properties, pos_size=pos_size), 'horiz')
        self.options_menu_main.add(MenuButton(l_save, function=self.save, \
            widget_properties = self.widget_properties, pos_size=pos_size), 'horiz')
        self.options_menu_main.add(MenuButton(l_save_quit, function=self.save, \
            args='quit', widget_properties=self.widget_properties, pos_size=pos_size), 'horiz')

        self.options_menu_main.add(MenuButton(l_settings_screen, target=self.options_menu_screen, \
            widget_properties=self.widget_properties, pos_size=pos_size), 'center')
        self.options_menu_main.add(MenuButton(l_settings_sound, target=self.options_menu_sound, \
            widget_properties=self.widget_properties, pos_size=pos_size), 'center')
        self.options_menu_main.add(MenuButton(l_settings_theme, target=self.options_menu_theme, \
            widget_properties=self.widget_properties, pos_size=pos_size), 'center')
        self.options_menu_main.add(MenuButton(l_settings_misc, target=self.options_menu_misc, \
            widget_properties=self.widget_properties, pos_size=pos_size), 'center')

        back_from_screen = MenuButton(l_back, target=self.options_menu_main, \
            widget_properties=self.widget_properties)
        back_from_sound = MenuButton(l_back, target=self.options_menu_main, \
            widget_properties=self.widget_properties)
        back_from_theme = MenuButton(l_back, target=self.options_menu_main, \
            widget_properties=self.widget_properties)
        back_from_misc = MenuButton(l_back, target=self.options_menu_main, \
            widget_properties=self.widget_properties)
        save_button = MenuButton(l_save, function=self.save, \
            widget_properties=self.widget_properties)
        save_quit_button = MenuButton(l_save_quit, function=self.save, \
            args='quit', widget_properties=self.widget_properties)

        # Add items to settings menus:
        self.options_menu_screen.add(back_from_screen, 'center')
        self.options_menu_screen.add(save_button, 'center')
        self.options_menu_screen.add(save_quit_button, 'center')

        self.options_menu_sound.add(back_from_sound, 'center')
        self.options_menu_sound.add(save_button, 'center')
        self.options_menu_sound.add(save_quit_button, 'center')

        self.options_menu_theme.add(back_from_theme, 'center')
        self.options_menu_theme.add(save_button, 'center')
        self.options_menu_theme.add(save_quit_button, 'center')

        self.options_menu_misc.add(back_from_misc, 'center')
        self.options_menu_misc.add(save_button, 'center')
        self.options_menu_misc.add(save_quit_button, 'center')



        res = str(self.screen_res_x) + 'x' + str(self.screen_res_y)
        if res in self.disp.valid_resolutions:
            selected_resolution = \
                self.disp.valid_resolutions.index(res)
        else:
            selected_resolution = 2

        screen_items = []
        screen_items.append({'info' : i_resolution,
                    'button_type' : 'toggle',
                    'toggle_items' : self.disp.valid_resolutions,
                    'selected_item' : selected_resolution})
        screen_items.append({'info' : i_fullscreen, 'button_type' : 'toggle', \
                    'toggle_items' : on_off_toggle,
                    'selected_item' : self.fullscreen_on})
        screen_items.append({'info' : i_fps_label, 'button_type' : 'toggle', \
                    'toggle_items' : on_off_toggle,
                    'selected_item' : self.fps_label})
        screen_items.append({'info' : i_pil, 'button_type' : 'toggle', \
                    'toggle_items' : on_off_toggle, \
                    'selected_item' : self.use_pil})
        screen_group = {'heading' : h2_settings_screen, 'items' : screen_items}
        self.options_menu_screen.add_group(screen_group)


        misc_items = []
        misc_items.append({'info' : i_lan,
                    'button_type' : 'toggle',
                    'toggle_items' : valid_languages,
                    'selected_item' : self.locale})
        misc_items.append({'info' : i_octave,
                    'button_type' : 'toggle',
                    'toggle_items' : on_off_toggle,
                    'selected_item' : self.octave})

        misc_items.append({'info' : i_helper,
                    'button_type' : 'toggle',
                    'toggle_items' : on_off_toggle,
                    'selected_item' : self.helper})
        misc_items.append({'info' : i_allowed_difference,
                    'button_type' : 'toggle',
                    'toggle_items' : ['1', '2', '3', '4', '5', '6', '7'],
                    'selected_item' : str(self.allowed_difference)})

        misc_group = {'heading' : h2_settings_misc, 'items' : misc_items}
        self.options_menu_misc.add_group(misc_group)


        if self.sound_player in self.valid_sound_players:
            self.selected_player = self.valid_sound_players.index(self.sound_player)
        else:
            self.selected_player = 1 # defaults to PyGame
        sound_items = []
        sound_items.append({'info' : i_sound_output,
                    'button_type' : 'toggle',
                    'toggle_items' : self.valid_sound_players,
                    'selected_item' : self.selected_player})

        if self.sound_input in self.valid_sound_inputs:
            self.selected_input = self.valid_sound_inputs.index(self.sound_input)
        else:
            self.selected_input = 0 # defaults to OSS

        sound_items.append({'info' : i_sound_input,
                    'button_type' : 'toggle',
                    'toggle_items' : self.valid_sound_inputs,
                    'selected_item' : self.selected_input})

        sound_items.append({'info' : i_song_preview,
                    'button_type' : 'toggle',
                    'toggle_items' : on_off_toggle,
                    'selected_item' : self.sound_preview})

        sound_group = {'heading' : h2_settings_sound, 'items' : sound_items}
        self.options_menu_sound.add_group(sound_group)
        theme_mgr = ThemeManager()
        available_themes = theme_mgr.get_theme_names(os.path.join(self.app_dir, 'media', 'themes'))

        if self.theme_name in available_themes:
            selected_theme = available_themes.index(self.theme_name)
        else: selected_theme = 0
        theme_items = []
        theme_items.append({'info' : i_theme,
                    'button_type' : 'toggle',
                    'toggle_items' : available_themes,
                    'selected_item' : selected_theme})
        theme_group = {'heading': h2_settings_theme, 'items' : theme_items}
        self.options_menu_theme.add_group(theme_group)

        main_menu.add(MenuButton(l_settings_main, target=self.options_menu_main, \
            widget_properties=self.widget_properties, pos_size=pos_size), 'center')
Beispiel #11
0
class Settings:
    """Initialize
        * user configuration (screen resolution, fullscreen settings, selected theme, ...)
    """
    def __init__(self, config, widget_properties, core):
        self.core = core
        self.widget_properties = widget_properties
        self.config = config
        self.locale = self.config['misc']['locale']
        self.octave = int(self.config['misc'].as_bool('octave'))
        self.helper = int(self.config['misc'].as_bool('helper'))
        self.allowed_difference =  int(self.config['misc'].as_int('allowed_difference'))

        self.screen_res_x =  self.config['screen'].as_int('resolution_x')
        self.screen_res_y =  self.config['screen'].as_int('resolution_y')
        self.fullscreen_on = int(self.config['screen'].as_bool('fullscreen'))
        self.fps_label = int(self.config['screen'].as_bool('fps_label'))
        self.use_pil = int(self.config['screen'].as_bool('pil'))
        self.sound_player = self.config['sound']['player']
        self.sound_input = self.config['sound']['input']
        self.sound_preview = int(self.config['sound'].as_bool('preview'))
        self.theme_name = self.config['theme']['name']

        self.app_dir = os.path.dirname(sys.argv[0])

        self.lm = LocaleManager(self.app_dir)
        self.lm.install(self.locale)

        self.disp = DisplayProperties()

        self.valid_sound_players = ['Dummy', 'Gstreamer']
        self.valid_sound_inputs = ['Gstreamer']


    def init_menus(self, main_menu, pos_size):
        # Button labels:
        l_settings_main = _(u'Settings')
        l_settings_screen = _(u'Screen')
        l_settings_sound = _(u'Sound')
        l_settings_theme = _(u'Theme')
        l_settings_misc = _(u'Misc')
        l_back =  _(u'back')
        l_save =  _(u'save')
        l_save_quit =  _(u'save & restart')
        l_quit =  _(u'quit')

        # Menu headings:
        h1_settings_main =  _(u'Settings')
        h1_settings_screen =  _(u'Screen Settings')
        h2_settings_screen =  _(u'SCREEN:')
        h1_settings_sound =  _(u'Sound Settings')
        h2_settings_sound =  _(u'SOUND:')
        h1_settings_theme =  _(u'Theme Settings')
        h2_settings_theme =  _(u'THEME:')
        h1_settings_misc = _(u'Miscellaneous Settings')
        h2_settings_misc = _(u'Miscellaneous')

        # Settings:
        valid_languages = self.lm.get_langs()
        on_off_toggle = [_('off'), _('on')]
        i_resolution =  _(u'Resolution:')
        i_fullscreen =  _(u'Fullscreen:')
        i_fps_label =  _(u'FPS label:')
        i_pil =  _(u'Cover images:')
        i_sound_output =  _(u'Select sound output engine:')
        i_sound_input =  _(u'Select sound input engine:')
        i_song_preview =  _(u'Play preview in song browser:')
        i_theme =  _(u'Choose a theme:')
        i_lan = _(u'Choose a language:')
        i_octave = _(u'Octave correctness:')
        i_helper = _(u'Easier tone hitting:')
        i_allowed_difference = _(u'Allowed difference:')

       # Options parent menu:
        self.options_menu_main = Menu(self.widget_properties)
        self.options_menu_main.set_heading(h1_settings_main)

        # Options sub menus:
        self.options_menu_screen = MenuGroup(self.widget_properties)
        self.options_menu_screen.set_heading(h1_settings_screen)
        self.options_menu_sound = MenuGroup(self.widget_properties)
        self.options_menu_sound.set_heading(h1_settings_sound)
        self.options_menu_theme = MenuGroup(self.widget_properties)
        self.options_menu_theme.set_heading(h1_settings_theme)
        self.options_menu_misc = MenuGroup(self.widget_properties)
        self.options_menu_misc.set_heading(h1_settings_misc)

        # Add buttons to options parent menu:
        self.options_menu_main.add(MenuButton(l_back, target=main_menu, \
            widget_properties=self.widget_properties, pos_size=pos_size), 'horiz')
        self.options_menu_main.add(MenuButton(l_save, function=self.save, \
            widget_properties = self.widget_properties, pos_size=pos_size), 'horiz')
        self.options_menu_main.add(MenuButton(l_save_quit, function=self.save, \
            args='quit', widget_properties=self.widget_properties, pos_size=pos_size), 'horiz')

        self.options_menu_main.add(MenuButton(l_settings_screen, target=self.options_menu_screen, \
            widget_properties=self.widget_properties, pos_size=pos_size), 'center')
        self.options_menu_main.add(MenuButton(l_settings_sound, target=self.options_menu_sound, \
            widget_properties=self.widget_properties, pos_size=pos_size), 'center')
        self.options_menu_main.add(MenuButton(l_settings_theme, target=self.options_menu_theme, \
            widget_properties=self.widget_properties, pos_size=pos_size), 'center')
        self.options_menu_main.add(MenuButton(l_settings_misc, target=self.options_menu_misc, \
            widget_properties=self.widget_properties, pos_size=pos_size), 'center')

        back_from_screen = MenuButton(l_back, target=self.options_menu_main, \
            widget_properties=self.widget_properties)
        back_from_sound = MenuButton(l_back, target=self.options_menu_main, \
            widget_properties=self.widget_properties)
        back_from_theme = MenuButton(l_back, target=self.options_menu_main, \
            widget_properties=self.widget_properties)
        back_from_misc = MenuButton(l_back, target=self.options_menu_main, \
            widget_properties=self.widget_properties)
        save_button = MenuButton(l_save, function=self.save, \
            widget_properties=self.widget_properties)
        save_quit_button = MenuButton(l_save_quit, function=self.save, \
            args='quit', widget_properties=self.widget_properties)

        # Add items to settings menus:
        self.options_menu_screen.add(back_from_screen, 'center')
        self.options_menu_screen.add(save_button, 'center')
        self.options_menu_screen.add(save_quit_button, 'center')

        self.options_menu_sound.add(back_from_sound, 'center')
        self.options_menu_sound.add(save_button, 'center')
        self.options_menu_sound.add(save_quit_button, 'center')

        self.options_menu_theme.add(back_from_theme, 'center')
        self.options_menu_theme.add(save_button, 'center')
        self.options_menu_theme.add(save_quit_button, 'center')

        self.options_menu_misc.add(back_from_misc, 'center')
        self.options_menu_misc.add(save_button, 'center')
        self.options_menu_misc.add(save_quit_button, 'center')



        res = str(self.screen_res_x) + 'x' + str(self.screen_res_y)
        if res in self.disp.valid_resolutions:
            selected_resolution = \
                self.disp.valid_resolutions.index(res)
        else:
            selected_resolution = 2

        screen_items = []
        screen_items.append({'info' : i_resolution,
                    'button_type' : 'toggle',
                    'toggle_items' : self.disp.valid_resolutions,
                    'selected_item' : selected_resolution})
        screen_items.append({'info' : i_fullscreen, 'button_type' : 'toggle', \
                    'toggle_items' : on_off_toggle,
                    'selected_item' : self.fullscreen_on})
        screen_items.append({'info' : i_fps_label, 'button_type' : 'toggle', \
                    'toggle_items' : on_off_toggle,
                    'selected_item' : self.fps_label})
        screen_items.append({'info' : i_pil, 'button_type' : 'toggle', \
                    'toggle_items' : on_off_toggle, \
                    'selected_item' : self.use_pil})
        screen_group = {'heading' : h2_settings_screen, 'items' : screen_items}
        self.options_menu_screen.add_group(screen_group)


        misc_items = []
        misc_items.append({'info' : i_lan,
                    'button_type' : 'toggle',
                    'toggle_items' : valid_languages,
                    'selected_item' : self.locale})
        misc_items.append({'info' : i_octave,
                    'button_type' : 'toggle',
                    'toggle_items' : on_off_toggle,
                    'selected_item' : self.octave})

        misc_items.append({'info' : i_helper,
                    'button_type' : 'toggle',
                    'toggle_items' : on_off_toggle,
                    'selected_item' : self.helper})
        misc_items.append({'info' : i_allowed_difference,
                    'button_type' : 'toggle',
                    'toggle_items' : ['1', '2', '3', '4', '5', '6', '7'],
                    'selected_item' : str(self.allowed_difference)})

        misc_group = {'heading' : h2_settings_misc, 'items' : misc_items}
        self.options_menu_misc.add_group(misc_group)


        if self.sound_player in self.valid_sound_players:
            self.selected_player = self.valid_sound_players.index(self.sound_player)
        else:
            self.selected_player = 1 # defaults to PyGame
        sound_items = []
        sound_items.append({'info' : i_sound_output,
                    'button_type' : 'toggle',
                    'toggle_items' : self.valid_sound_players,
                    'selected_item' : self.selected_player})

        if self.sound_input in self.valid_sound_inputs:
            self.selected_input = self.valid_sound_inputs.index(self.sound_input)
        else:
            self.selected_input = 0 # defaults to OSS

        sound_items.append({'info' : i_sound_input,
                    'button_type' : 'toggle',
                    'toggle_items' : self.valid_sound_inputs,
                    'selected_item' : self.selected_input})

        sound_items.append({'info' : i_song_preview,
                    'button_type' : 'toggle',
                    'toggle_items' : on_off_toggle,
                    'selected_item' : self.sound_preview})

        sound_group = {'heading' : h2_settings_sound, 'items' : sound_items}
        self.options_menu_sound.add_group(sound_group)
        theme_mgr = ThemeManager()
        available_themes = theme_mgr.get_theme_names(os.path.join(self.app_dir, 'media', 'themes'))

        if self.theme_name in available_themes:
            selected_theme = available_themes.index(self.theme_name)
        else: selected_theme = 0
        theme_items = []
        theme_items.append({'info' : i_theme,
                    'button_type' : 'toggle',
                    'toggle_items' : available_themes,
                    'selected_item' : selected_theme})
        theme_group = {'heading': h2_settings_theme, 'items' : theme_items}
        self.options_menu_theme.add_group(theme_group)

        main_menu.add(MenuButton(l_settings_main, target=self.options_menu_main, \
            widget_properties=self.widget_properties, pos_size=pos_size), 'center')



    def save(self, args=None):
        # Sucking values out of the pudding labels, wich is crap:
        toggle_map = [_('off'), _('on')]
        on_off_mapping = {toggle_map[0]: 'off', toggle_map[1]: 'on'}
        x, y = self.options_menu_screen.toggle_list[0].label.split('x')
        fs = on_off_mapping[self.options_menu_screen.toggle_list[1].label]
        fps = on_off_mapping[self.options_menu_screen.toggle_list[2].label]
        pil = on_off_mapping[self.options_menu_screen.toggle_list[3].label]

        sp = self.options_menu_sound.toggle_list[0].label
        si = self.options_menu_sound.toggle_list[1].label
        spr = on_off_mapping[self.options_menu_sound.toggle_list[2].label]

        tn = self.options_menu_theme.toggle_list[0].label

        locale = self.options_menu_misc.toggle_list[0].label
        octave = on_off_mapping[self.options_menu_misc.toggle_list[1].label]
        helper = on_off_mapping[self.options_menu_misc.toggle_list[2].label]
        allowed_difference = self.options_menu_misc.toggle_list[3].label


        self.config['screen'] = {
            'resolution_x' : x,
            'resolution_y' : y,
            'fullscreen' : fs,
            'fps_label' : fps,
            'pil' : pil
        }
        self.config['sound'] = {
            'player' : sp,
            'input' : si,
            'preview' : spr,
        }
        self.config['theme'] = {
            'name' : tn
        }
        self.config['misc'] = {
            'locale' : locale,
            'octave' : octave,
            'helper' : helper,
            'allowed_difference' : allowed_difference
        }
        self.config.write()

        if args == 'quit':
            soya.quit()
            self.core._start()
Beispiel #12
0
    def init_menus(self, main_menu, pos_size):
        # Button labels:
        l_settings_main = _(u'Settings')
        l_settings_screen = _(u'Screen')
        l_settings_sound = _(u'Sound')
        l_settings_theme = _(u'Theme')
        l_settings_misc = _(u'Misc')
        l_back = _(u'back')
        l_save = _(u'save')
        l_save_quit = _(u'save & restart')
        l_quit = _(u'quit')

        # Menu headings:
        h1_settings_main = _(u'Settings')
        h1_settings_screen = _(u'Screen Settings')
        h2_settings_screen = _(u'SCREEN:')
        h1_settings_sound = _(u'Sound Settings')
        h2_settings_sound = _(u'SOUND:')
        h1_settings_theme = _(u'Theme Settings')
        h2_settings_theme = _(u'THEME:')
        h1_settings_misc = _(u'Miscellaneous Settings')
        h2_settings_misc = _(u'Miscellaneous')

        # Settings:
        valid_languages = self.lm.get_langs()
        on_off_toggle = [_('off'), _('on')]
        i_resolution = _(u'Resolution:')
        i_fullscreen = _(u'Fullscreen:')
        i_fps_label = _(u'FPS label:')
        i_pil = _(u'Cover images:')
        i_sound_output = _(u'Select sound output engine:')
        i_sound_input = _(u'Select sound input engine:')
        i_song_preview = _(u'Play preview in song browser:')
        i_theme = _(u'Choose a theme:')
        i_lan = _(u'Choose a language:')
        i_octave = _(u'Octave correctness:')
        i_helper = _(u'Easier tone hitting:')
        i_allowed_difference = _(u'Allowed difference:')

        # Options parent menu:
        self.options_menu_main = Menu(self.widget_properties)
        self.options_menu_main.set_heading(h1_settings_main)

        # Options sub menus:
        self.options_menu_screen = MenuGroup(self.widget_properties)
        self.options_menu_screen.set_heading(h1_settings_screen)
        self.options_menu_sound = MenuGroup(self.widget_properties)
        self.options_menu_sound.set_heading(h1_settings_sound)
        self.options_menu_theme = MenuGroup(self.widget_properties)
        self.options_menu_theme.set_heading(h1_settings_theme)
        self.options_menu_misc = MenuGroup(self.widget_properties)
        self.options_menu_misc.set_heading(h1_settings_misc)

        # Add buttons to options parent menu:
        self.options_menu_main.add(MenuButton(l_back, target=main_menu, \
            widget_properties=self.widget_properties, pos_size=pos_size), 'horiz')
        self.options_menu_main.add(MenuButton(l_save, function=self.save, \
            widget_properties = self.widget_properties, pos_size=pos_size), 'horiz')
        self.options_menu_main.add(MenuButton(l_save_quit, function=self.save, \
            args='quit', widget_properties=self.widget_properties, pos_size=pos_size), 'horiz')

        self.options_menu_main.add(MenuButton(l_settings_screen, target=self.options_menu_screen, \
            widget_properties=self.widget_properties, pos_size=pos_size), 'center')
        self.options_menu_main.add(MenuButton(l_settings_sound, target=self.options_menu_sound, \
            widget_properties=self.widget_properties, pos_size=pos_size), 'center')
        self.options_menu_main.add(MenuButton(l_settings_theme, target=self.options_menu_theme, \
            widget_properties=self.widget_properties, pos_size=pos_size), 'center')
        self.options_menu_main.add(MenuButton(l_settings_misc, target=self.options_menu_misc, \
            widget_properties=self.widget_properties, pos_size=pos_size), 'center')

        back_from_screen = MenuButton(l_back, target=self.options_menu_main, \
            widget_properties=self.widget_properties)
        back_from_sound = MenuButton(l_back, target=self.options_menu_main, \
            widget_properties=self.widget_properties)
        back_from_theme = MenuButton(l_back, target=self.options_menu_main, \
            widget_properties=self.widget_properties)
        back_from_misc = MenuButton(l_back, target=self.options_menu_main, \
            widget_properties=self.widget_properties)
        save_button = MenuButton(l_save, function=self.save, \
            widget_properties=self.widget_properties)
        save_quit_button = MenuButton(l_save_quit, function=self.save, \
            args='quit', widget_properties=self.widget_properties)

        # Add items to settings menus:
        self.options_menu_screen.add(back_from_screen, 'center')
        self.options_menu_screen.add(save_button, 'center')
        self.options_menu_screen.add(save_quit_button, 'center')

        self.options_menu_sound.add(back_from_sound, 'center')
        self.options_menu_sound.add(save_button, 'center')
        self.options_menu_sound.add(save_quit_button, 'center')

        self.options_menu_theme.add(back_from_theme, 'center')
        self.options_menu_theme.add(save_button, 'center')
        self.options_menu_theme.add(save_quit_button, 'center')

        self.options_menu_misc.add(back_from_misc, 'center')
        self.options_menu_misc.add(save_button, 'center')
        self.options_menu_misc.add(save_quit_button, 'center')

        res = str(self.screen_res_x) + 'x' + str(self.screen_res_y)
        if res in self.disp.valid_resolutions:
            selected_resolution = \
                self.disp.valid_resolutions.index(res)
        else:
            selected_resolution = 2

        screen_items = []
        screen_items.append({
            'info': i_resolution,
            'button_type': 'toggle',
            'toggle_items': self.disp.valid_resolutions,
            'selected_item': selected_resolution
        })
        screen_items.append({'info' : i_fullscreen, 'button_type' : 'toggle', \
                    'toggle_items' : on_off_toggle,
                    'selected_item' : self.fullscreen_on})
        screen_items.append({'info' : i_fps_label, 'button_type' : 'toggle', \
                    'toggle_items' : on_off_toggle,
                    'selected_item' : self.fps_label})
        screen_items.append({'info' : i_pil, 'button_type' : 'toggle', \
                    'toggle_items' : on_off_toggle, \
                    'selected_item' : self.use_pil})
        screen_group = {'heading': h2_settings_screen, 'items': screen_items}
        self.options_menu_screen.add_group(screen_group)

        misc_items = []
        misc_items.append({
            'info': i_lan,
            'button_type': 'toggle',
            'toggle_items': valid_languages,
            'selected_item': self.locale
        })
        misc_items.append({
            'info': i_octave,
            'button_type': 'toggle',
            'toggle_items': on_off_toggle,
            'selected_item': self.octave
        })

        misc_items.append({
            'info': i_helper,
            'button_type': 'toggle',
            'toggle_items': on_off_toggle,
            'selected_item': self.helper
        })
        misc_items.append({
            'info': i_allowed_difference,
            'button_type': 'toggle',
            'toggle_items': ['1', '2', '3', '4', '5', '6', '7'],
            'selected_item': str(self.allowed_difference)
        })

        misc_group = {'heading': h2_settings_misc, 'items': misc_items}
        self.options_menu_misc.add_group(misc_group)

        if self.sound_player in self.valid_sound_players:
            self.selected_player = self.valid_sound_players.index(
                self.sound_player)
        else:
            self.selected_player = 1  # defaults to PyGame
        sound_items = []
        sound_items.append({
            'info': i_sound_output,
            'button_type': 'toggle',
            'toggle_items': self.valid_sound_players,
            'selected_item': self.selected_player
        })

        if self.sound_input in self.valid_sound_inputs:
            self.selected_input = self.valid_sound_inputs.index(
                self.sound_input)
        else:
            self.selected_input = 0  # defaults to OSS

        sound_items.append({
            'info': i_sound_input,
            'button_type': 'toggle',
            'toggle_items': self.valid_sound_inputs,
            'selected_item': self.selected_input
        })

        sound_items.append({
            'info': i_song_preview,
            'button_type': 'toggle',
            'toggle_items': on_off_toggle,
            'selected_item': self.sound_preview
        })

        sound_group = {'heading': h2_settings_sound, 'items': sound_items}
        self.options_menu_sound.add_group(sound_group)
        theme_mgr = ThemeManager()
        available_themes = theme_mgr.get_theme_names(
            os.path.join(self.app_dir, 'media', 'themes'))

        if self.theme_name in available_themes:
            selected_theme = available_themes.index(self.theme_name)
        else:
            selected_theme = 0
        theme_items = []
        theme_items.append({
            'info': i_theme,
            'button_type': 'toggle',
            'toggle_items': available_themes,
            'selected_item': selected_theme
        })
        theme_group = {'heading': h2_settings_theme, 'items': theme_items}
        self.options_menu_theme.add_group(theme_group)

        main_menu.add(MenuButton(l_settings_main, target=self.options_menu_main, \
            widget_properties=self.widget_properties, pos_size=pos_size), 'center')
Beispiel #13
0
class Settings:
    """Initialize
        * user configuration (screen resolution, fullscreen settings, selected theme, ...)
    """
    def __init__(self, config, widget_properties, core):
        self.core = core
        self.widget_properties = widget_properties
        self.config = config
        self.locale = self.config['misc']['locale']
        self.octave = int(self.config['misc'].as_bool('octave'))
        self.helper = int(self.config['misc'].as_bool('helper'))
        self.allowed_difference = int(
            self.config['misc'].as_int('allowed_difference'))

        self.screen_res_x = self.config['screen'].as_int('resolution_x')
        self.screen_res_y = self.config['screen'].as_int('resolution_y')
        self.fullscreen_on = int(self.config['screen'].as_bool('fullscreen'))
        self.fps_label = int(self.config['screen'].as_bool('fps_label'))
        self.use_pil = int(self.config['screen'].as_bool('pil'))
        self.sound_player = self.config['sound']['player']
        self.sound_input = self.config['sound']['input']
        self.sound_preview = int(self.config['sound'].as_bool('preview'))
        self.theme_name = self.config['theme']['name']

        self.app_dir = os.path.dirname(sys.argv[0])

        self.lm = LocaleManager(self.app_dir)
        self.lm.install(self.locale)

        self.disp = DisplayProperties()

        self.valid_sound_players = ['Dummy', 'Gstreamer']
        self.valid_sound_inputs = ['Gstreamer']

    def init_menus(self, main_menu, pos_size):
        # Button labels:
        l_settings_main = _(u'Settings')
        l_settings_screen = _(u'Screen')
        l_settings_sound = _(u'Sound')
        l_settings_theme = _(u'Theme')
        l_settings_misc = _(u'Misc')
        l_back = _(u'back')
        l_save = _(u'save')
        l_save_quit = _(u'save & restart')
        l_quit = _(u'quit')

        # Menu headings:
        h1_settings_main = _(u'Settings')
        h1_settings_screen = _(u'Screen Settings')
        h2_settings_screen = _(u'SCREEN:')
        h1_settings_sound = _(u'Sound Settings')
        h2_settings_sound = _(u'SOUND:')
        h1_settings_theme = _(u'Theme Settings')
        h2_settings_theme = _(u'THEME:')
        h1_settings_misc = _(u'Miscellaneous Settings')
        h2_settings_misc = _(u'Miscellaneous')

        # Settings:
        valid_languages = self.lm.get_langs()
        on_off_toggle = [_('off'), _('on')]
        i_resolution = _(u'Resolution:')
        i_fullscreen = _(u'Fullscreen:')
        i_fps_label = _(u'FPS label:')
        i_pil = _(u'Cover images:')
        i_sound_output = _(u'Select sound output engine:')
        i_sound_input = _(u'Select sound input engine:')
        i_song_preview = _(u'Play preview in song browser:')
        i_theme = _(u'Choose a theme:')
        i_lan = _(u'Choose a language:')
        i_octave = _(u'Octave correctness:')
        i_helper = _(u'Easier tone hitting:')
        i_allowed_difference = _(u'Allowed difference:')

        # Options parent menu:
        self.options_menu_main = Menu(self.widget_properties)
        self.options_menu_main.set_heading(h1_settings_main)

        # Options sub menus:
        self.options_menu_screen = MenuGroup(self.widget_properties)
        self.options_menu_screen.set_heading(h1_settings_screen)
        self.options_menu_sound = MenuGroup(self.widget_properties)
        self.options_menu_sound.set_heading(h1_settings_sound)
        self.options_menu_theme = MenuGroup(self.widget_properties)
        self.options_menu_theme.set_heading(h1_settings_theme)
        self.options_menu_misc = MenuGroup(self.widget_properties)
        self.options_menu_misc.set_heading(h1_settings_misc)

        # Add buttons to options parent menu:
        self.options_menu_main.add(MenuButton(l_back, target=main_menu, \
            widget_properties=self.widget_properties, pos_size=pos_size), 'horiz')
        self.options_menu_main.add(MenuButton(l_save, function=self.save, \
            widget_properties = self.widget_properties, pos_size=pos_size), 'horiz')
        self.options_menu_main.add(MenuButton(l_save_quit, function=self.save, \
            args='quit', widget_properties=self.widget_properties, pos_size=pos_size), 'horiz')

        self.options_menu_main.add(MenuButton(l_settings_screen, target=self.options_menu_screen, \
            widget_properties=self.widget_properties, pos_size=pos_size), 'center')
        self.options_menu_main.add(MenuButton(l_settings_sound, target=self.options_menu_sound, \
            widget_properties=self.widget_properties, pos_size=pos_size), 'center')
        self.options_menu_main.add(MenuButton(l_settings_theme, target=self.options_menu_theme, \
            widget_properties=self.widget_properties, pos_size=pos_size), 'center')
        self.options_menu_main.add(MenuButton(l_settings_misc, target=self.options_menu_misc, \
            widget_properties=self.widget_properties, pos_size=pos_size), 'center')

        back_from_screen = MenuButton(l_back, target=self.options_menu_main, \
            widget_properties=self.widget_properties)
        back_from_sound = MenuButton(l_back, target=self.options_menu_main, \
            widget_properties=self.widget_properties)
        back_from_theme = MenuButton(l_back, target=self.options_menu_main, \
            widget_properties=self.widget_properties)
        back_from_misc = MenuButton(l_back, target=self.options_menu_main, \
            widget_properties=self.widget_properties)
        save_button = MenuButton(l_save, function=self.save, \
            widget_properties=self.widget_properties)
        save_quit_button = MenuButton(l_save_quit, function=self.save, \
            args='quit', widget_properties=self.widget_properties)

        # Add items to settings menus:
        self.options_menu_screen.add(back_from_screen, 'center')
        self.options_menu_screen.add(save_button, 'center')
        self.options_menu_screen.add(save_quit_button, 'center')

        self.options_menu_sound.add(back_from_sound, 'center')
        self.options_menu_sound.add(save_button, 'center')
        self.options_menu_sound.add(save_quit_button, 'center')

        self.options_menu_theme.add(back_from_theme, 'center')
        self.options_menu_theme.add(save_button, 'center')
        self.options_menu_theme.add(save_quit_button, 'center')

        self.options_menu_misc.add(back_from_misc, 'center')
        self.options_menu_misc.add(save_button, 'center')
        self.options_menu_misc.add(save_quit_button, 'center')

        res = str(self.screen_res_x) + 'x' + str(self.screen_res_y)
        if res in self.disp.valid_resolutions:
            selected_resolution = \
                self.disp.valid_resolutions.index(res)
        else:
            selected_resolution = 2

        screen_items = []
        screen_items.append({
            'info': i_resolution,
            'button_type': 'toggle',
            'toggle_items': self.disp.valid_resolutions,
            'selected_item': selected_resolution
        })
        screen_items.append({'info' : i_fullscreen, 'button_type' : 'toggle', \
                    'toggle_items' : on_off_toggle,
                    'selected_item' : self.fullscreen_on})
        screen_items.append({'info' : i_fps_label, 'button_type' : 'toggle', \
                    'toggle_items' : on_off_toggle,
                    'selected_item' : self.fps_label})
        screen_items.append({'info' : i_pil, 'button_type' : 'toggle', \
                    'toggle_items' : on_off_toggle, \
                    'selected_item' : self.use_pil})
        screen_group = {'heading': h2_settings_screen, 'items': screen_items}
        self.options_menu_screen.add_group(screen_group)

        misc_items = []
        misc_items.append({
            'info': i_lan,
            'button_type': 'toggle',
            'toggle_items': valid_languages,
            'selected_item': self.locale
        })
        misc_items.append({
            'info': i_octave,
            'button_type': 'toggle',
            'toggle_items': on_off_toggle,
            'selected_item': self.octave
        })

        misc_items.append({
            'info': i_helper,
            'button_type': 'toggle',
            'toggle_items': on_off_toggle,
            'selected_item': self.helper
        })
        misc_items.append({
            'info': i_allowed_difference,
            'button_type': 'toggle',
            'toggle_items': ['1', '2', '3', '4', '5', '6', '7'],
            'selected_item': str(self.allowed_difference)
        })

        misc_group = {'heading': h2_settings_misc, 'items': misc_items}
        self.options_menu_misc.add_group(misc_group)

        if self.sound_player in self.valid_sound_players:
            self.selected_player = self.valid_sound_players.index(
                self.sound_player)
        else:
            self.selected_player = 1  # defaults to PyGame
        sound_items = []
        sound_items.append({
            'info': i_sound_output,
            'button_type': 'toggle',
            'toggle_items': self.valid_sound_players,
            'selected_item': self.selected_player
        })

        if self.sound_input in self.valid_sound_inputs:
            self.selected_input = self.valid_sound_inputs.index(
                self.sound_input)
        else:
            self.selected_input = 0  # defaults to OSS

        sound_items.append({
            'info': i_sound_input,
            'button_type': 'toggle',
            'toggle_items': self.valid_sound_inputs,
            'selected_item': self.selected_input
        })

        sound_items.append({
            'info': i_song_preview,
            'button_type': 'toggle',
            'toggle_items': on_off_toggle,
            'selected_item': self.sound_preview
        })

        sound_group = {'heading': h2_settings_sound, 'items': sound_items}
        self.options_menu_sound.add_group(sound_group)
        theme_mgr = ThemeManager()
        available_themes = theme_mgr.get_theme_names(
            os.path.join(self.app_dir, 'media', 'themes'))

        if self.theme_name in available_themes:
            selected_theme = available_themes.index(self.theme_name)
        else:
            selected_theme = 0
        theme_items = []
        theme_items.append({
            'info': i_theme,
            'button_type': 'toggle',
            'toggle_items': available_themes,
            'selected_item': selected_theme
        })
        theme_group = {'heading': h2_settings_theme, 'items': theme_items}
        self.options_menu_theme.add_group(theme_group)

        main_menu.add(MenuButton(l_settings_main, target=self.options_menu_main, \
            widget_properties=self.widget_properties, pos_size=pos_size), 'center')

    def save(self, args=None):
        # Sucking values out of the pudding labels, wich is crap:
        toggle_map = [_('off'), _('on')]
        on_off_mapping = {toggle_map[0]: 'off', toggle_map[1]: 'on'}
        x, y = self.options_menu_screen.toggle_list[0].label.split('x')
        fs = on_off_mapping[self.options_menu_screen.toggle_list[1].label]
        fps = on_off_mapping[self.options_menu_screen.toggle_list[2].label]
        pil = on_off_mapping[self.options_menu_screen.toggle_list[3].label]

        sp = self.options_menu_sound.toggle_list[0].label
        si = self.options_menu_sound.toggle_list[1].label
        spr = on_off_mapping[self.options_menu_sound.toggle_list[2].label]

        tn = self.options_menu_theme.toggle_list[0].label

        locale = self.options_menu_misc.toggle_list[0].label
        octave = on_off_mapping[self.options_menu_misc.toggle_list[1].label]
        helper = on_off_mapping[self.options_menu_misc.toggle_list[2].label]
        allowed_difference = self.options_menu_misc.toggle_list[3].label

        self.config['screen'] = {
            'resolution_x': x,
            'resolution_y': y,
            'fullscreen': fs,
            'fps_label': fps,
            'pil': pil
        }
        self.config['sound'] = {
            'player': sp,
            'input': si,
            'preview': spr,
        }
        self.config['theme'] = {'name': tn}
        self.config['misc'] = {
            'locale': locale,
            'octave': octave,
            'helper': helper,
            'allowed_difference': allowed_difference
        }
        self.config.write()

        if args == 'quit':
            soya.quit()
            self.core._start()