Exemplo n.º 1
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
Exemplo n.º 2
0
class SongEditor(Menu):
    """TODO...
    """
    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()


    def show(self, args):

        # get name of the selected song name from args:
        self.song = args[0]
        self.selected_song = self.song.info['mp3']
        self.song.writer = self.song.reader
        self.v_cont.visible = 1
        self.setup()


    def setup(self):
        # Sizes and positions for the lyrics:
        pos_size = {}
        pos_size['width'] = 70
        pos_size['height'] = 30
        pos_size['top'] = self.widget_properties['config']['screen'].as_int('resolution_y') / 1.1 - 12
        pos_size['left'] = 35
        self.widget_properties['pos_size'] = pos_size
        self.widget_properties['anchoring'] = 'bottom'

        # We deactivate the "done"-color by giving it the same color as "to_sing":
        self.lyrics_to_sing_color = self.widget_properties['font']['lyrics']['to_sing']['color']
        self.widget_properties['font']['lyrics']['to_sing']['color'] = \
            self.widget_properties['font']['lyrics']['done']['color']

        # The observer for the lyrics:
        lyrics = LyricsObserver(self.widget_properties)

        # The observer for the symbolical musical representations:

        song_bar_color = {}
        song_bar_color['special'] = (1, 0, 0, 0.6)
        song_bar_color['freestyle'] = (0, 1., 0., 0.6)
        song_bar_color['normal'] = (0, 0., 1., 0.4)

        cube = MainCubeObserver(self.widget_properties['root_world'], \
                        song_bar_color)

        self.music_notes = MusicNotes(self.parent_world)

        self.pos = 0
        self.song_data = SongData()
        self.song_data.attach(lyrics)
        self.song_data.attach(cube)
        self.song_data.attach(self.music_notes)

        # The paths to the song:
        self.msg['song'] = self.song
        self.song.read()
        self.song.split_in_lines()
        self.msg['type'] = 'nextLine'
        self.song_data.set_data(self.msg)
        self.msg['pos'] = 0
        self.msg['type'] = 'activateNote'
        self.song_data.set_data(self.msg)

        self.player.load(path=self.song.path, file= self.selected_song)

        self.heading_label = pudding.control.SimpleLabel( \
                self.v_cont, label=self.song.info['artist'] + \
                self.separator + self.song.info['title'], \
                font=self.font_h,\
                color=self.color_h, top=10, left=0)

        # The line number label:
        ln_label = ''
        self.line_number_label = pudding.control.SimpleLabel( \
            self.v_cont, label=ln_label, font=self.font_p, \
            color=self.color_p)

        self.bpm_label = self.l_bpm + str(self.song.info['bpm'])
        self.bpm_number_label = pudding.control.SimpleLabel( \
            self.v_cont, label= self.bpm_label, font=self.font_p, \
            color=self.color_p)

        self.parent_widget.on_resize()
        self.parent_world.add(self.keyboard_event)

        # Help menu:
        self.help_menu = MenuText(self.widget_properties, top=self.screen_res_y / 5, \
                left=self.screen_res_x / 2)
        self.help_menu.set_heading(self.h_help)
        fd_help = open(self.help_file_path, 'r')
        help = fd_help.read()
        self.help_menu.add_text(help)
        self.help_hint = pudding.control.SimpleLabel(self.help_hint_cont, \
                label=self.l_help_hint)

        self.add_child(self.help_menu)
        # needs testing
        #click_observer = ClickObserver(self.player)
        #self.song_data.attach(click_observer)

        self.parent_widget.on_resize()
        self.refresh()

    def back(self):
        self.msg['type'] = 'end'

        self.song_data.set_data(self.msg)

        del self.v_cont.children[0:]
        del self.help_hint_cont.children[0:]
        self.help_menu.box_cont.visible = 0
        self.help_hint_cont.visible = 0
        self.parent_world.remove(self.keyboard_event)
        # We reactivate the "done"-color:
        self.widget_properties['font']['lyrics']['to_sing']['color'] = \
            self.lyrics_to_sing_color
        self.quit_help()
        self.main_menu.show()


    def help(self):
        self.msg['type'] = 'nextLine'
        self.song_data.set_data(self.msg)

        self.keyboard_event.reset()
        self.keyboard_event.add_connection(type = soya.sdlconst.K_q, \
            action = self.back)
        self.keyboard_event.add_connection(type = soya.sdlconst.K_ESCAPE, \
            action = self.quit_help)
        self.keyboard_event.add_connection(type = soya.sdlconst.K_h, \
            action = self.quit_help)
        self.heading_label.visible = 0
        self.line_number_label.visible = 0
        self.bpm_number_label.visible = 0
        self.help_menu.visible = 1
        self.help_hint.label = self.l_help_hint_1


    def quit_help(self):
        self.heading_label.visible = 1
        self.line_number_label.visible = 1
        self.bpm_number_label.visible = 1
        self.keyboard_event.reset()
        self.__connect_keys__()
        self.help_hint.label = self.l_help_hint_0
        self.help_menu.visible = 0
        self.refresh()


    def init_text_field(self):
        if self.edit_value == 'text':
            self.txt_input.label.value = self.song.lines[self.song.line_nr].segments[self.pos].text
        elif self.edit_value == 'bar':
            self.txt_input.label.value = self.song.info['bar_length']

        self.txt_input.label.visible = 1
        self.txt_input.post_method = self.end_change_text

    def change_text(self, obj):
        self.edit_value = obj
        self.init_text_field()
        self.parent_world.remove(self.keyboard_event)
        self.parent_world.add(self.txt_input)

    def end_change_text(self):
        if self.txt_input.done:
            if self.edit_value == 'text':
                self.song.lines[self.song.line_nr].segments[self.pos].text = self.txt_input.label.value
            elif self.edit_value == 'bar':
                self.song.info['bar_length'] = self.txt_input.label.value
        self.txt_input.label.visible = 0
        self.parent_world.remove(self.txt_input)
        self.parent_world.add(self.keyboard_event)
        self.refresh()

    def split_line(self):
        line, tone, seg_pos = self.song.get_pos_in_segments(self.song.line_nr, self.pos)
        if self.song.segments > seg_pos+1 and self.pos < len(line.segments)-1:
            self.song.segments.insert(seg_pos+1, SongSegment( "pause", self.get_next_pos(tone)))
            self.song.split_in_lines()
        self.refresh()


    def get_next_pos(self, tone):
        ''' returns pos of next free position for a element after the actual tone
        '''
        return tone.time_stamp+tone.duration+1

    def merge_lines(self):
        line, tone, seg_pos = self.song.get_pos_in_segments(self.song.line_nr, self.pos)
        if self.song.line_nr + 1 < len(self.song.lines):
            for segment in self.song.segments[seg_pos:]:
                if segment.type == 'pause':
                    self.song.segments.pop(self.song.segments.index(segment))
                    break
            self.refresh()
        elif self.song.line_nr + 1 == len(self.song.lines) and self.song.line_nr > 0:
            self.song.line_nr -= 1
            self.merge_lines()


    def add_tone(self):
        line, tone, seg_pos = self.song.get_pos_in_segments(self.song.line_nr, self.pos)
        self.song.segments.insert(seg_pos+1, SongSegment( "note", self.get_next_pos(tone), 1, tone.pitch, text = '-'))
        self.refresh()

    def rem_tone(self):
        line, tone, seg_pos = self.song.get_pos_in_segments(self.song.line_nr, self.pos)
        line_nr = self.song.line_nr
        number_of_segments = len(self.song.lines[line_nr].segments)
        number_of_lines = len(self.song.lines)
        if number_of_segments == 1:
            if line_nr > 0:
                self.song.segments.pop(seg_pos)
                self.song.line_nr -= 1
                self.merge_lines()
            elif line_nr == 0 and number_of_lines > 1:
                self.merge_lines()
                self.song.segments.pop(seg_pos)
            else:
                pass
                #print "you cant delete last segment in last line"

        else:
            self.song.segments.pop(seg_pos)
            if self.pos + 1 == number_of_segments:
                self.pos -= 1
        self.refresh()

    def play_tone_wave(self):
        start_tone = self.song.lines[self.song.line_nr].segments[self.pos]
        self.play_wave(start_tone)

    def play_wave(self, start_tone, end_tone = None):
        duration_of_one_beat = 1. /self.song.info['bpm'] * 60
        if not end_tone:
            end_tone = start_tone
        beats = end_tone.duration + end_tone.time_stamp - start_tone.time_stamp
        length = beats * duration_of_one_beat / 4
        start = self.song.get_real_time(start_tone.time_stamp)
        self.player.play(start=float (start))
        time.sleep(length)
        self.player.stop()

    def play_line_wave(self):
        start_tone = self.song.lines[self.song.line_nr].segments[0]
        end_tone = self.song.lines[self.song.line_nr].segments[-1]
        self.play_wave(start_tone, end_tone)

    def play_tone_both(self):
        thread.start_new_thread(self.play_tone_freq, () )
        thread.start_new_thread(self.play_tone_wave, () )

    def play_line_both(self):
        thread_id = thread.start_new_thread(self.play_line_wave,())
        #if thread_id == thread.get_ident():
        #   thread.exit()
        thread.start_new_thread(self.play_line_freq, () )

    def play_tone_freq(self):
        self.play_freq(self.song.line_nr, self.pos)

    def play_line_freq(self):
        line = self.song.lines[self.song.line_nr]
        for i, segment in enumerate(line.segments[:-1]):
            b = time.time()
            self.play_freq(self.song.line_nr, i)
            dur = time.time() - b
            sleep_time = (line.segments[i+1].time_stamp - (segment.time_stamp)) * \
                (1. /self.song.info['bpm'] *60.)/4.-dur
            if sleep_time > 0:
                time.sleep(sleep_time)
        self.play_freq(self.song.line_nr, len(line.segments)-1)

    def play_freq(self, line_nr, note_nr):
        note = self.song.lines[line_nr].segments[note_nr]
        duration = note.duration* (1. /self.song.info['bpm'] *60) / 4
        freq = self.song.get_freq(line_nr, note_nr)
        self.player.play_freq(freq)
        time.sleep(duration)
        self.player.stop_freq()

    def bpm_up(self):
        self.song.info['bpm'] += 1
        self.bpm_number_label.label = u'BPM: '+ str(self.song.info['bpm'])

    def bpm_min(self):
        self.song.info['bpm']-=1
        self.bpm_number_label.label = u'BPM: '+ str(self.song.info['bpm'])


    def next(self):
        self.pos = 0
        if self.song.line_nr + 1 < len(self.song.lines):
            self.song.line_nr += 1
        else:
            self.song.line_nr = 0
        self.refresh()

    def refresh(self):
        self.song.split_in_lines()
        self.msg['type'] = 'nextLine'
        self.msg['song'] = self.song
        self.song_data.set_data(self.msg)
        self.msg['pos'] = self.pos
        self.msg['type'] = 'activateNote'
        self.song_data.set_data(self.msg)
        self.line_count = str(len(self.song.lines))
        self.line_number_label.label = self.l_line_no \
            + str(self.song.line_nr + 1) + u' / ' \
            + self.line_count


    def prev(self):
        self.pos = 0
        if self.song.line_nr > 0:
            self.song.line_nr -= 1
        else:
            self.song.line_nr = len(self.song.lines) - 1
        self.refresh()


    def select_note(self, args):
        self.msg['type'] = 'deActivateNote'
        self.msg['old_pos'] = self.pos
        self.song_data.set_data(self.msg)
        if args =='next':
            if self.pos < len(self.song.lines[self.song.line_nr].segments) - 1:
                self.pos += 1
        elif self.pos > 0:
            self.pos -= 1
        self.refresh()

    def increase(self):
        self.song.lines[self.song.line_nr].segments[self.pos].duration += 1
        self.refresh()

    def minimize(self):
        if self.song.lines[self.song.line_nr].segments[self.pos].duration >= 1:
            self.song.lines[self.song.line_nr].segments[self.pos].duration -= 1
            self.refresh()

    def save(self):
        self.song.write()


    def move(self, dif):
        self.song.lines[self.song.line_nr].segments[self.pos].time_stamp += dif
        self.refresh()

    def move_ri(self):
        line, tone, seg_pos = self.song.get_pos_in_segments(self.song.line_nr, self.pos)
        self.move(1)
        if self.pos + 1 < len(line.segments):
            if tone.time_stamp > line.segments[self.pos + 1].time_stamp:  # if tone have later timestamp then next tone, switch position in list
                next_tone = line.segments[self.pos + 1]
                self.song.segments[seg_pos] = next_tone
                self.song.segments[seg_pos + 1] = tone
                self.pos = self.pos + 1
                self.refresh()


    def move_le(self):
        line, tone, seg_pos = self.song.get_pos_in_segments(self.song.line_nr, self.pos)
        self.move(-1)
        if self.pos > 0:
            if tone.time_stamp < line.segments[self.pos - 1].time_stamp:  # if tone have further timestamp then the tone before, switch position in list
                before_tone = line.segments[self.pos - 1]
                self.song.segments[seg_pos] = before_tone
                self.song.segments[seg_pos - 1] = tone
                self.pos = self.pos - 1
                self.refresh()


    def change_pitch(self, dif):
        self.song.lines[self.song.line_nr].segments[self.pos].pitch += dif
        self.refresh()

    def pitch_up(self):
        self.change_pitch(1)


    def pitch_down(self):
        self.change_pitch(-1)

    def make_line_pictures(self):
        self.make_line_picture(all=True)

    def make_line_picture(self, all=False):
        ming = MingusSong()
        ming.load_from_song(self.song)
        if all:
            ming.generate_pictures()
        else:
            ming.generate_picture(self.song.line_nr)
        self.refresh()

    def __connect_keys__(self):
        """Map soya keyboard events to methods."""
        # Maybe we better should move this in a
        # xml/config-file and parse it from there

        key = soya.sdlconst
        connections = []
        connections.append((key.K_q, self.back))
        connections.append((key.K_PAGEDOWN, self.prev))
        connections.append((key.K_PAGEUP, self.next))
        connections.append((key.K_LEFT, self.select_note, 'prev'))
        connections.append((key.K_RIGHT, self.select_note, 'next'))
        connections.append((key.K_PLUS, self.increase))
        connections.append((key.K_MINUS, self.minimize))
        connections.append((key.K_KP_PLUS, self.increase))
        connections.append((key.K_KP_MINUS, self.minimize))
        connections.append((key.K_s, self.save))
        connections.append((key.K_y, self.move_le))
        connections.append((key.K_x, self.move_ri))
        connections.append((key.K_UP, self.pitch_up))
        connections.append((key.KEYUP, self.pitch_up))
        connections.append((key.K_UP, self.pitch_up))
        connections.append((key.KEYUP, self.pitch_up))
        connections.append((key.K_DOWN, self.pitch_down))
        connections.append((key.KEYDOWN, self.pitch_down))
        connections.append((key.K_h, self.help))
        connections.append((key.K_ESCAPE, self.back))
        connections.append((key.K_SPACE, self.play_tone_wave))
        connections.append((key.K_l, self.play_line_wave))
        connections.append((key.K_m, self.play_tone_freq))
        connections.append((key.K_n, self.play_line_freq))
        connections.append((key.K_v, self.play_tone_both))
        connections.append((key.K_b, self.play_line_both))
        connections.append((key.K_d, self.bpm_up))
        connections.append((key.K_c, self.bpm_min))
        connections.append((key.K_u, self.split_line))
        connections.append((key.K_i, self.merge_lines))
        connections.append((key.K_a, self.add_tone))
        connections.append((key.K_r, self.rem_tone))
        connections.append((key.K_t, self.change_text, 'text'))
        connections.append((key.K_z, self.change_text, 'bar'))
        connections.append((key.K_g, self.make_line_pictures))
        connections.append((key.K_e, self.make_line_picture))

        for connection in connections:
            self.keyboard_event.add_connection(*connection)
Exemplo n.º 3
0
    def setup(self):
        # Sizes and positions for the lyrics:
        pos_size = {}
        pos_size['width'] = 70
        pos_size['height'] = 30
        pos_size['top'] = self.widget_properties['config']['screen'].as_int('resolution_y') / 1.1 - 12
        pos_size['left'] = 35
        self.widget_properties['pos_size'] = pos_size
        self.widget_properties['anchoring'] = 'bottom'

        # We deactivate the "done"-color by giving it the same color as "to_sing":
        self.lyrics_to_sing_color = self.widget_properties['font']['lyrics']['to_sing']['color']
        self.widget_properties['font']['lyrics']['to_sing']['color'] = \
            self.widget_properties['font']['lyrics']['done']['color']

        # The observer for the lyrics:
        lyrics = LyricsObserver(self.widget_properties)

        # The observer for the symbolical musical representations:

        song_bar_color = {}
        song_bar_color['special'] = (1, 0, 0, 0.6)
        song_bar_color['freestyle'] = (0, 1., 0., 0.6)
        song_bar_color['normal'] = (0, 0., 1., 0.4)

        cube = MainCubeObserver(self.widget_properties['root_world'], \
                        song_bar_color)

        self.music_notes = MusicNotes(self.parent_world)

        self.pos = 0
        self.song_data = SongData()
        self.song_data.attach(lyrics)
        self.song_data.attach(cube)
        self.song_data.attach(self.music_notes)

        # The paths to the song:
        self.msg['song'] = self.song
        self.song.read()
        self.song.split_in_lines()
        self.msg['type'] = 'nextLine'
        self.song_data.set_data(self.msg)
        self.msg['pos'] = 0
        self.msg['type'] = 'activateNote'
        self.song_data.set_data(self.msg)

        self.player.load(path=self.song.path, file= self.selected_song)

        self.heading_label = pudding.control.SimpleLabel( \
                self.v_cont, label=self.song.info['artist'] + \
                self.separator + self.song.info['title'], \
                font=self.font_h,\
                color=self.color_h, top=10, left=0)

        # The line number label:
        ln_label = ''
        self.line_number_label = pudding.control.SimpleLabel( \
            self.v_cont, label=ln_label, font=self.font_p, \
            color=self.color_p)

        self.bpm_label = self.l_bpm + str(self.song.info['bpm'])
        self.bpm_number_label = pudding.control.SimpleLabel( \
            self.v_cont, label= self.bpm_label, font=self.font_p, \
            color=self.color_p)

        self.parent_widget.on_resize()
        self.parent_world.add(self.keyboard_event)

        # Help menu:
        self.help_menu = MenuText(self.widget_properties, top=self.screen_res_y / 5, \
                left=self.screen_res_x / 2)
        self.help_menu.set_heading(self.h_help)
        fd_help = open(self.help_file_path, 'r')
        help = fd_help.read()
        self.help_menu.add_text(help)
        self.help_hint = pudding.control.SimpleLabel(self.help_hint_cont, \
                label=self.l_help_hint)

        self.add_child(self.help_menu)
        # needs testing
        #click_observer = ClickObserver(self.player)
        #self.song_data.attach(click_observer)

        self.parent_widget.on_resize()
        self.refresh()
Exemplo n.º 4
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()