Ejemplo n.º 1
0
    def _start(self):

        # get user config settings and store them:
        self.config_path = os.path.join(user.home, '.canta')
        if not os.access(self.config_path, os.F_OK):
            os.mkdir(self.config_path)
        self.config = ConfigObj()
        vdt = Validator()
        # copy default config
        spec_file = os.path.join(self.app_dir, 'misc', 'configspec')
        self.config = ConfigObj(configspec=spec_file)
        self.config.filename = os.path.join(self.config_path, 'config')
        if not os.access(os.path.join(self.config_path, 'config'), os.F_OK):
            self.config.validate(vdt, copy=True)
            self.config.write()
        else:
            self.config = ConfigObj(os.path.join(self.config_path, 'config'), configspec=spec_file)
            self.config.validate(vdt)


        self.screen_res_x =  self.config['screen'].as_int('resolution_x')
        self.screen_res_y =  self.config['screen'].as_int('resolution_y')
        self.theme_name = self.config['theme']['name']


        self.widget_properties = {}
        self.widget_properties['theme'] = {}
        self.widget_properties['theme']['main'] = self.theme_name
        self.widget_properties['theme']['song'] = None

        self.widget_properties['config'] = self.config

        # initialize game engine:
        self._init_game_engine()


        ### CHRISTMAS TEST ###
        test = False
        if test:
            particles = ParticleSystem(self.root_world)
            particles.set_colors((1.0,1.0,1.0,1.0),(1.0,0.0,0.0,0.5), \
                (1.0,1.0,0.,0.5),(0.5,0.5,0.5,0.5),(0.,0.,0.,0.5))
            particles.set_sizes((0.19,0.19),(0.35,0.35))
            particles.set_xyz(10.0,-6.0,0.0)
            particles.rotate_z(-180.0)

        # load the theme config settings:
        self.theme_mgr = ThemeManager(self.root_world)
        self.theme_dir = os.path.join(self.app_dir, 'media', 'themes', self.theme_name)
        self.theme_mgr.get_theme(self.theme_name, self.theme_dir)

        self.widget_properties['font'] = {}

        font_elems = ['p', 'h1', 'lyrics', 'button']
        lyrics_types = ['to_sing', 'special', 'active', 'done']
        button_types = ['on_focus', 'off_focus']

        for elem in font_elems:
            self.widget_properties['font'][elem] = {}

        font_p = self.theme_mgr.get_font(self.theme_name, 'p', 'None', 'font')
        self.widget_properties['font']['p']['obj'] = font_p
        color_p = self.theme_mgr.get_font(self.theme_name, 'p', 'None', 'color')
        self.widget_properties['font']['p']['color'] = color_p

        font_h1 = self.theme_mgr.get_font(self.theme_name, 'h1', 'None', 'font')
        self.widget_properties['font']['h1']['obj'] = font_h1
        color_h1 = self.theme_mgr.get_font(self.theme_name, 'h1', 'None', 'color')
        self.widget_properties['font']['h1']['color'] = color_h1

        self.widget_properties['font']['lyrics']['to_sing'] = {}
        font_lyrics_ts = self.theme_mgr.get_font(self.theme_name, 'lyrics', 'to_sing', 'font')
        color_lyrics_ts = self.theme_mgr.get_font(self.theme_name, 'lyrics', 'to_sing', 'color')
        self.widget_properties['font']['lyrics']['to_sing']['obj'] = font_lyrics_ts
        self.widget_properties['font']['lyrics']['to_sing']['color'] = color_lyrics_ts

        self.widget_properties['font']['lyrics']['special'] = {}
        font_lyrics_spec = self.theme_mgr.get_font(self.theme_name, 'lyrics', 'special', 'font')
        color_lyrics_spec = self.theme_mgr.get_font(self.theme_name, 'lyrics', 'special', 'color')
        self.widget_properties['font']['lyrics']['special']['obj'] = font_lyrics_spec
        self.widget_properties['font']['lyrics']['special']['color'] = color_lyrics_spec

        self.widget_properties['font']['lyrics']['active'] = {}
        font_lyrics_act = self.theme_mgr.get_font(self.theme_name, 'lyrics', 'active', 'font')
        color_lyrics_act = self.theme_mgr.get_font(self.theme_name, 'lyrics', 'active', 'color')
        self.widget_properties['font']['lyrics']['active']['obj'] = font_lyrics_act
        self.widget_properties['font']['lyrics']['active']['color'] = color_lyrics_act

        self.widget_properties['font']['lyrics']['done'] = {}
        font_lyrics_done = self.theme_mgr.get_font(self.theme_name, 'lyrics', 'done', 'font')
        color_lyrics_done = self.theme_mgr.get_font(self.theme_name, 'lyrics', 'done', 'color')
        self.widget_properties['font']['lyrics']['done']['obj'] = font_lyrics_done
        self.widget_properties['font']['lyrics']['done']['color'] = color_lyrics_done

        self.widget_properties['font']['button']['on_focus'] = {}
        font_button_on = self.theme_mgr.get_font(self.theme_name, 'button', 'on_focus', 'font')
        color_button_on = self.theme_mgr.get_font(self.theme_name, 'button', 'on_focus', 'color')
        self.widget_properties['font']['button']['on_focus']['obj'] = font_button_on
        self.widget_properties['font']['button']['on_focus']['color'] = color_button_on

        self.widget_properties['font']['button']['off_focus'] = {}
        font_button_off = self.theme_mgr.get_font(self.theme_name, 'button', 'off_focus', 'font')
        color_button_off = self.theme_mgr.get_font(self.theme_name, 'button', 'off_focus', 'color')
        self.widget_properties['font']['button']['off_focus']['obj'] = font_button_off
        self.widget_properties['font']['button']['off_focus']['color'] = color_button_off

        self.widget_properties['box'] = self.theme_mgr.get_box(self.theme_name)
        self.widget_properties['button'] = self.theme_mgr.get_button(self.theme_name)

        self.widget_properties['bar'] = self.theme_mgr.get_bar(self.theme_name)

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

        # initialize widget system:
        self._init_widget_engine()

        # show selected theme:
        self.theme_mgr.show_theme(self.theme_name)

        # Init menus and instances:
        self.init_menus()
Ejemplo n.º 2
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')