예제 #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()