コード例 #1
0
ファイル: theme.py プロジェクト: spiderbit/canta
    def create_fonts(self):
        height = soya.get_screen_height()

        # TODO: quick hack for font sizes, but it works for now.
        if height < 480:
        # 320x480
            p_w = 7 # paragraphs width, height
            p_h = 2
            h1_w = 9 # headings
            h1_h = 4
            ly_w = 7 # lyrics
            ly_h = 2
            bu_w = 7 # buttons
            bu_h = 2
        if height >= 480 and height < 600:
        # 640x480
            p_w = 11 # paragraphs width, height
            p_h = 6
            h1_w = 15 # headings
            h1_h = 10
            ly_w = 19 # lyrics
            ly_h = 14
            bu_w = 9 # buttons
            bu_h = 2
        elif height >= 600 and height < 720:
        # 800x600
            p_w = 15
            p_h = 10
            h1_w = 27
            h1_h = 17
            ly_w = 31
            ly_h = 23
            bu_w = 15
            bu_h = 10
        elif height >= 720 and height <= 768:
        # 1280x720
        # 1024x768
            p_w = 19
            p_h = 14
            h1_w = 31
            h1_h = 20
            ly_w = 43
            ly_h = 32
            bu_w = 17
            bu_h = 12
        elif height > 768 and height < 1024:
        # 1280x800
            p_w = 21
            p_h = 14
            h1_w = 39
            h1_h = 28
            ly_w = 45
            ly_h = 34
            bu_w = 25
            bu_h = 14
        elif height > 768 and height < 1050:
        # 1280x1024
            p_w = 25
            p_h = 16
            h1_w = 45
            h1_h = 34
            ly_w = 55
            ly_h = 45
            bu_w = 25
            bu_h = 16
        elif height >= 1050 and height < 1200:
        # 1400x1050
        # 1680x1050
            p_w = 31
            p_h = 24
            h1_w = 47
            h1_h = 36
            ly_w = 59
            ly_h = 56
            bu_w = 31
            bu_h = 21
        elif height >= 1200:
        # 1600x1200
        # 1920x1200
            p_w = 27
            p_h = 20
            h1_w = 56
            h1_h = 46
            ly_w = 75
            ly_h = 64
            bu_w = 31
            bu_h = 24
        else:
        # 800x600
            p_w = 15
            p_h = 10
            h1_w = 27
            h1_h = 17
            ly_w = 31
            ly_h = 23
            bu_w = 15
            bu_h = 10

        for font in self.theme_file.fonts:
            if font['element'] == 'p':
                self.fonts['p'][font['type']] = {}
                self.fonts['p'][font['type']]['color'] = font['attrs']['color']
                self.fonts['p'][font['type']]['font'] = soya.Font(
                        os.path.join(self.theme_dir, 'media', 'fonts',
                        font['attrs']['file_name']),
                        p_w,
                        p_h)
            elif font['element'] == 'h1':
                self.fonts['h1'][font['type']] = {}
                self.fonts['h1'][font['type']]['color'] = font['attrs']['color']
                self.fonts['h1'][font['type']]['font'] = soya.Font(
                        os.path.join(self.theme_dir, 'media', 'fonts',
                        font['attrs']['file_name']),
                        h1_w,
                        h1_h)
            elif font['element'] == 'lyrics':
                self.fonts['lyrics'][font['type']] = {}
                self.fonts['lyrics'][font['type']]['color'] = font['attrs']['color']
                self.fonts['lyrics'][font['type']]['font'] = soya.Font(
                        os.path.join(self.theme_dir, 'media', 'fonts',
                        font['attrs']['file_name']),
                        ly_w,
                        ly_h)
            elif font['element'] == 'button':
                self.fonts['button'][font['type']] = {}
                self.fonts['button'][font['type']]['color'] = font['attrs']['color']
                self.fonts['button'][font['type']]['font'] = soya.Font(
                        os.path.join(self.theme_dir, 'media', 'fonts',
                        font['attrs']['file_name']),
                        bu_w,
                        bu_h)
コード例 #2
0
    def show(self, args):
        h1_pause = _(u'Pause')
        h1_results = _(u'Results')

        self.menu_list['browser'] = args[1]

        #self.camera = MovableCamera(self.app_dir, self.parent_world, debug = self.debug)
        self.camera.z = 15
        self.parent.add_child(self.camera)

        self.song = args[0]
        self.song.reset()
        self.song.read()
        song_path = self.song.path
        self.song.split_in_lines()

        theme_cfg_file = os.path.join(song_path, 'theme_cfg.xml')

        if os.path.exists(theme_cfg_file):
            media_path = os.path.join(song_path, 'media')
            soya.path.append(media_path)

            self.theme_mgr.hide_theme(self.widget_properties['theme']['main'])
            theme_name = self.song.info['title']
            self.widget_properties['theme']['song'] = theme_name
            self.theme_mgr.get_theme(theme_name, song_path)
            self.theme_mgr.show_theme(theme_name)

            self.widget_properties['font']['lyrics']['to_sing'] = {}
            font_lyrics_ts = self.theme_mgr.get_font(theme_name, 'lyrics',
                                                     'to_sing', 'font')
            color_lyrics_ts = self.theme_mgr.get_font(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(theme_name, 'lyrics',
                                                       'special', 'font')
            color_lyrics_spec = self.theme_mgr.get_font(
                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(theme_name, 'lyrics',
                                                      'active', 'font')
            color_lyrics_act = self.theme_mgr.get_font(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(theme_name, 'lyrics',
                                                       'done', 'font')
            color_lyrics_done = self.theme_mgr.get_font(
                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(theme_name, 'button',
                                                     'on_focus', 'font')
            color_button_on = self.theme_mgr.get_font(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(theme_name, 'button',
                                                      'off_focus', 'font')
            color_button_off = self.theme_mgr.get_font(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(theme_name)
            self.widget_properties['button'] = self.theme_mgr.get_button(
                theme_name)

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

        img_observer = False
        song_theme_path = os.path.join(song_path, 'theme_cfg.xml')
        media_path = os.path.join(song_path, 'media')

        # The observer for the musical notes:
        music_notes = MusicNotes(self.parent_world)

        # Sizes and positions for the labels:
        pos_size = {}
        pos_size['width'] = 70
        pos_size['height'] = 30
        pos_size['left'] = 35
        self.widget_properties['pos_size'] = pos_size
        self.widget_properties['anchoring'] = 'bottom'

        # The observers for the lyrics:
        self.widget_properties['pos_size']['top'] = soya.get_screen_height(
        ) * 0.8
        lyrics_current = LyricsObserver(self.widget_properties)

        self.widget_properties['pos_size']['top'] = soya.get_screen_height(
        ) * 0.9
        lyrics_next = LyricsObserver(self.widget_properties, line_diff=1)

        use_pil = self.config['screen']['pil']
        self.game = Game(self.config)
        # The observer for the results screen (when the song ended):
        result_view = ResultView(self.widget_properties, self.menu_list, self.song, \
                use_pil, self.game)
        result_view.set_heading(h1_results)

        sing_bar_color = self.widget_properties['bar']['singbar']['color']
        sing_bar_formula = self.widget_properties['bar']['singbar']['formula']

        song_bar_color = {}
        song_bar_color['special'] = self.widget_properties['bar']['songbar'][
            'special']['color']
        song_bar_color['freestyle'] = self.widget_properties['bar']['songbar'][
            'freestyle']['color']
        song_bar_color['normal'] = self.widget_properties['bar']['songbar'][
            'normal']['color']

        pos_bar_color = self.widget_properties['bar']['posbar']['color']

        # The observer for the symbolical musical representations:
        bar = MainCubeObserver(self.parent_world, song_bar_color,
                               self.song.getMinPitch(),
                               self.song.getMaxPitch())

        # The observer for the microphone captured notes:
        input_bar = SingCubeObserver(self.parent_world, sing_bar_color,
                                     sing_bar_formula, self.song.getMinPitch(),
                                     self.song.getMaxPitch(), self.game)

        # The observer for the song position cube:
        pos_bar = PosCubeObserver(self.parent_world, pos_bar_color)

        # Observer for the song time:
        time_label = TimeLabel(self.widget_properties)

        self.input_subject = SongData()
        self.input_subject.attach(input_bar)
        self.input_subject.attach(result_view)
        self.song_data = SongData()

        # maybe a subject-observer solution would be better
        # if we make would use it over network but for first release i think its good enough
        self.keyboard_event = KeyboardEvent(self.widget_properties)

        self.keyboard_event.add_connection(type = soya.sdlconst.K_ESCAPE, \
            action = self.pause)
        self.keyboard_event.add_connection(type = soya.sdlconst.K_q, \
            action = self.exit)
        self.keyboard_event.add_connection(type = soya.sdlconst.K_w, \
            action = soya.toggle_wireframe)
        self.keyboard_event.add_connection(type = soya.sdlconst.K_s, \
            action = self.make_screenshot)

        selected_input = self.config['sound']['input']
        if selected_input == 'Gstreamer':
            from canta.event.input_gstreamer import Input

        self.input = Input(self.song, self.input_subject, \
                self.player, self.config)

        self.song_event = SongEvent(self.song, self.widget_properties,\
                self.song_data, self.player, \
                self.keyboard_event, self.input)

        # Observer for the pause menu:
        pause = Pause(self.widget_properties, \
            self.song_data, self.player, self.keyboard_event, self.song, \
            self.song_event)
        pause.set_heading(h1_pause)

        self.song_data.attach(lyrics_current)
        self.song_data.attach(lyrics_next)
        self.song_data.attach(pos_bar)
        self.song_data.attach(bar)
        self.song_data.attach(time_label)
        self.song_data.attach(pause)
        self.song_data.attach(result_view)
        self.song_data.attach(input_bar)
        self.song_data.attach(music_notes)

        self.parent_world.add(self.keyboard_event)

        self.input.start()

        self.parent_world.add(self.song_event)
        self.player.load(self.song.path, self.song.info['mp3'])
        self.player.play()
コード例 #3
0
ファイル: sing_screen.py プロジェクト: spiderbit/canta
    def show(self, args):
        h1_pause = _(u'Pause')
        h1_results = _(u'Results')

        #self.camera = MovableCamera(self.app_dir, self.parent_world, debug = self.debug)
        self.camera.z = 15
        #self.parent.add_child(self.camera)

        self.song = args[0]
        self.song.reset()
        self.song.read()
        song_path = self.song.path
        self.song.split_in_lines()

        theme_cfg_file = os.path.join(song_path, 'theme_cfg.xml')

        if os.path.exists(theme_cfg_file):
            media_path = os.path.join(song_path, 'media')
            soya.path.append(media_path)

            self.theme_mgr.hide_theme(self.widget_properties['theme']['main'])
            theme_name = self.song.info['title']
            self.widget_properties['theme']['song'] = theme_name
            self.theme_mgr.get_theme(theme_name, song_path)
            self.theme_mgr.show_theme(theme_name)

            self.widget_properties['font']['lyrics']['to_sing'] = {}
            font_lyrics_ts = self.theme_mgr.get_font(theme_name, 'lyrics', 'to_sing', 'font')
            color_lyrics_ts = self.theme_mgr.get_font(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(theme_name, 'lyrics', 'special', 'font')
            color_lyrics_spec = self.theme_mgr.get_font(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(theme_name, 'lyrics', 'active', 'font')
            color_lyrics_act = self.theme_mgr.get_font(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(theme_name, 'lyrics', 'done', 'font')
            color_lyrics_done = self.theme_mgr.get_font(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(theme_name, 'button', 'on_focus', 'font')
            color_button_on = self.theme_mgr.get_font(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(theme_name, 'button', 'off_focus', 'font')
            color_button_off = self.theme_mgr.get_font(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(theme_name)
            self.widget_properties['button'] = self.theme_mgr.get_button(theme_name)

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

        img_observer = False
        song_theme_path = os.path.join(song_path, 'theme_cfg.xml')
        media_path = os.path.join(song_path, 'media')


        # The observer for the musical notes:
        music_notes = MusicNotes(self.parent_world)

        # Sizes and positions for the labels:
        pos_size = {}
        pos_size['width'] = 70
        pos_size['height'] = 30
        pos_size['left'] = 35
        self.widget_properties['pos_size'] = pos_size
        self.widget_properties['anchoring'] = 'bottom'

        # The observers for the lyrics:
        self.widget_properties['pos_size']['top'] = soya.get_screen_height() * 0.8
        lyrics_current = LyricsObserver(self.widget_properties)

        self.widget_properties['pos_size']['top'] = soya.get_screen_height() * 0.9
        lyrics_next = LyricsObserver(self.widget_properties, line_diff=1)

        use_pil = self.config['screen']['pil']
        self.game = Game(self.config)
        # The observer for the results screen (when the song ended):
        browser = args[1]
        result_view = ResultView(self.widget_properties, self.main_menu, \
                browser, self.song, use_pil, self.game)
        result_view.set_heading(h1_results)

        sing_bar_color = self.widget_properties['bar']['singbar']['color']
        sing_bar_formula = self.widget_properties['bar']['singbar']['formula']

        song_bar_color = {}
        song_bar_color['special'] = self.widget_properties['bar']['songbar']['special']['color']
        song_bar_color['freestyle'] = self.widget_properties['bar']['songbar']['freestyle']['color']
        song_bar_color['normal'] = self.widget_properties['bar']['songbar']['normal']['color']

        pos_bar_color = self.widget_properties['bar']['posbar']['color']

        # The observer for the symbolical musical representations:
        bar = MainCubeObserver(self.parent_world,
                       song_bar_color,
                       self.song.getMinPitch(),
                       self.song.getMaxPitch())

        # The observer for the microphone captured notes:
        input_bar = SingCubeObserver(self.parent_world,
                         sing_bar_color, sing_bar_formula,
                         self.song.getMinPitch(),
                         self.song.getMaxPitch(),
                         self.game)

        # The observer for the song position cube:
        pos_bar = PosCubeObserver(self.parent_world,
                      pos_bar_color)

        # Observer for the song time:
        time_label = TimeLabel(self.widget_properties)

        self.input_subject = SongData()
        self.input_subject.attach(input_bar)
        self.input_subject.attach(result_view)
        self.song_data = SongData()

        # maybe a subject-observer solution would be better
        # if we make would use it over network but for first release i think its good enough
        self.keyboard_event = KeyboardEvent(self.widget_properties)

        self.keyboard_event.add_connection(type = soya.sdlconst.K_ESCAPE, \
            action = self.pause)
        self.keyboard_event.add_connection(type = soya.sdlconst.K_q, \
            action = self.exit)
        self.keyboard_event.add_connection(type = soya.sdlconst.K_w, \
            action = soya.toggle_wireframe)
        self.keyboard_event.add_connection(type = soya.sdlconst.K_s, \
            action = self.make_screenshot)

        selected_input = self.config['sound']['input']
        if selected_input == 'Gstreamer':
            from canta.event.input_gstreamer import Input

        self.input = Input(self.song, self.input_subject, \
                self.player, self.config)

        self.song_event = SongEvent(self.song, self.widget_properties,\
                self.song_data, self.player, \
                self.keyboard_event, self.input)


        # Observer for the pause menu:
        pause = Pause(self.widget_properties, \
            self.song_data, self.player, self.keyboard_event, self.song, \
            self.song_event)
        pause.set_heading(h1_pause)

        self.song_data.attach(lyrics_current)
        self.song_data.attach(lyrics_next)
        self.song_data.attach(pos_bar)
        self.song_data.attach(bar)
        self.song_data.attach(time_label)
        self.song_data.attach(pause)
        self.song_data.attach(result_view)
        self.song_data.attach(input_bar)
        self.song_data.attach(music_notes)

        self.parent_world.add(self.keyboard_event)

        self.input.start()

        self.parent_world.add(self.song_event)
        self.player.load(self.song.path, self.song.info['mp3'])
        self.player.play()
コード例 #4
0
    def create_fonts(self):
        height = soya.get_screen_height()

        # TODO: quick hack for font sizes, but it works for now.
        if height < 480:
            # 320x480
            p_w = 7  # paragraphs width, height
            p_h = 2
            h1_w = 9  # headings
            h1_h = 4
            ly_w = 7  # lyrics
            ly_h = 2
            bu_w = 7  # buttons
            bu_h = 2
        if height >= 480 and height < 600:
            # 640x480
            p_w = 11  # paragraphs width, height
            p_h = 6
            h1_w = 15  # headings
            h1_h = 10
            ly_w = 19  # lyrics
            ly_h = 14
            bu_w = 9  # buttons
            bu_h = 2
        elif height >= 600 and height < 720:
            # 800x600
            p_w = 15
            p_h = 10
            h1_w = 27
            h1_h = 17
            ly_w = 31
            ly_h = 23
            bu_w = 15
            bu_h = 10
        elif height >= 720 and height <= 768:
            # 1280x720
            # 1024x768
            p_w = 19
            p_h = 14
            h1_w = 31
            h1_h = 20
            ly_w = 43
            ly_h = 32
            bu_w = 17
            bu_h = 12
        elif height > 768 and height < 1024:
            # 1280x800
            p_w = 21
            p_h = 14
            h1_w = 39
            h1_h = 28
            ly_w = 45
            ly_h = 34
            bu_w = 25
            bu_h = 14
        elif height > 768 and height < 1050:
            # 1280x1024
            p_w = 25
            p_h = 16
            h1_w = 45
            h1_h = 34
            ly_w = 55
            ly_h = 45
            bu_w = 25
            bu_h = 16
        elif height >= 1050 and height < 1200:
            # 1400x1050
            # 1680x1050
            p_w = 31
            p_h = 24
            h1_w = 47
            h1_h = 36
            ly_w = 59
            ly_h = 56
            bu_w = 31
            bu_h = 21
        elif height >= 1200:
            # 1600x1200
            # 1920x1200
            p_w = 27
            p_h = 20
            h1_w = 56
            h1_h = 46
            ly_w = 75
            ly_h = 64
            bu_w = 31
            bu_h = 24
        else:
            # 800x600
            p_w = 15
            p_h = 10
            h1_w = 27
            h1_h = 17
            ly_w = 31
            ly_h = 23
            bu_w = 15
            bu_h = 10

        for font in self.theme_file.fonts:
            if font['element'] == 'p':
                self.fonts['p'][font['type']] = {}
                self.fonts['p'][font['type']]['color'] = font['attrs']['color']
                self.fonts['p'][font['type']]['font'] = soya.Font(
                    os.path.join(self.theme_dir, 'media', 'fonts',
                                 font['attrs']['file_name']), p_w, p_h)
            elif font['element'] == 'h1':
                self.fonts['h1'][font['type']] = {}
                self.fonts['h1'][
                    font['type']]['color'] = font['attrs']['color']
                self.fonts['h1'][font['type']]['font'] = soya.Font(
                    os.path.join(self.theme_dir, 'media', 'fonts',
                                 font['attrs']['file_name']), h1_w, h1_h)
            elif font['element'] == 'lyrics':
                self.fonts['lyrics'][font['type']] = {}
                self.fonts['lyrics'][
                    font['type']]['color'] = font['attrs']['color']
                self.fonts['lyrics'][font['type']]['font'] = soya.Font(
                    os.path.join(self.theme_dir, 'media', 'fonts',
                                 font['attrs']['file_name']), ly_w, ly_h)
            elif font['element'] == 'button':
                self.fonts['button'][font['type']] = {}
                self.fonts['button'][
                    font['type']]['color'] = font['attrs']['color']
                self.fonts['button'][font['type']]['font'] = soya.Font(
                    os.path.join(self.theme_dir, 'media', 'fonts',
                                 font['attrs']['file_name']), bu_w, bu_h)