示例#1
0
文件: equalizer.py 项目: Rucia1/Peppy
class EqualizerScreen(Screen):
    """ Equalizer Screen """
    def __init__(self, util, listeners, voice_assistant):
        """ Initializer
        
        :param util: utility object
        :param listener: screen menu event listener
        """
        self.util = util
        self.config = util.config
        self.current_values = FLAT_PRESETS.copy()
        try:
            config_values = self.config[CURRENT][EQUALIZER]
            self.current_values = config_values.copy()
        except:
            pass

        Screen.__init__(self, util, EQUALIZER, PERCENT_TOP_HEIGHT,
                        voice_assistant)

        self.equalizer_menu = EqualizerMenu(util, self.handle_slider_event,
                                            (0, 0, 0), self.layout.CENTER)
        self.equalizer_menu.set_bands(self.current_values)
        self.add_menu(self.equalizer_menu)

        c = self.config[COLORS][COLOR_DARK_LIGHT]
        self.equalizer_navigator = EqualizerNavigator(util,
                                                      listeners[KEY_HOME],
                                                      listeners[KEY_PLAYER],
                                                      self.handle_presets, c,
                                                      self.layout.BOTTOM)
        self.add_menu(self.equalizer_navigator)

    def handle_presets(self, state):
        name = state.name
        if name == CLASSICAL: self.current_values = CLASSIC_PRESETS.copy()
        elif name == JAZZ: self.current_values = JAZZ_PRESETS.copy()
        elif name == POP: self.current_values = POP_PRESETS.copy()
        elif name == ROCK: self.current_values = ROCK_PRESETS.copy()
        elif name == CONTEMPORARY:
            self.current_values = CONTEMPORARY_PRESETS.copy()
        elif name == FLAT:
            self.current_values = FLAT_PRESETS.copy()

        self.equalizer_menu.set_bands(self.current_values)
        self.config[CURRENT][EQUALIZER] = self.current_values.copy()
        self.util.set_equalizer(self.current_values)

    def handle_slider_event(self, state):
        band = int(state.event_origin.name[-1])
        v = state.position
        self.current_values[band] = v
        self.config[CURRENT][EQUALIZER] = self.current_values.copy()
        self.util.set_equalizer_band_value(band + 1, v)

        s = self.equalizer_menu.sliders[band]
        s.set_value(str(v))

    def add_screen_observers(self, update_observer, redraw_observer):
        """ Add screen observers
        
        :param update_observer: observer for updating the screen
        :param redraw_observer: observer to redraw the whole screen
        """
        Screen.add_screen_observers(self, update_observer, redraw_observer)

        self.equalizer_menu.add_menu_observers(update_observer,
                                               redraw_observer)
        for b in self.equalizer_navigator.menu_buttons:
            self.add_button_observers(b, update_observer, redraw_observer)
示例#2
0
class EqualizerScreen(Screen):
    """ Equalizer Screen """
    def __init__(self, util, listeners, voice_assistant):
        """ Initializer
        
        :param util: utility object
        :param listener: screen menu event listener
        """
        self.util = util
        self.config = util.config
        self.current_values = FLAT_PRESETS.copy()
        try:
            config_values = self.config[CURRENT][EQUALIZER]
            self.current_values = config_values.copy()
        except:
            pass

        Screen.__init__(self, util, EQUALIZER, PERCENT_TOP_HEIGHT,
                        voice_assistant)

        self.equalizer_menu = EqualizerMenu(util, self.handle_slider_event,
                                            self.layout.CENTER)
        self.equalizer_menu.set_parent_screen(self)
        self.equalizer_menu.set_bands(self.current_values)
        self.add_menu(self.equalizer_menu)

        self.equalizer_navigator = EqualizerNavigator(util, self.layout.BOTTOM,
                                                      listeners,
                                                      self.handle_presets)
        self.add_navigator(self.equalizer_navigator)

        self.link_borders(first_index=0, last_index=9)
        self.equalizer_navigator.buttons[0].set_selected(True)
        self.navigator_selected = True

    def handle_presets(self, state):
        """ Handle presets

        :param state: state object
        """
        name = state.name
        if name == CLASSICAL: self.current_values = CLASSIC_PRESETS.copy()
        elif name == JAZZ: self.current_values = JAZZ_PRESETS.copy()
        elif name == POP: self.current_values = POP_PRESETS.copy()
        elif name == ROCK: self.current_values = ROCK_PRESETS.copy()
        elif name == CONTEMPORARY:
            self.current_values = CONTEMPORARY_PRESETS.copy()
        elif name == FLAT:
            self.current_values = FLAT_PRESETS.copy()

        self.equalizer_menu.set_bands(self.current_values)
        self.config[CURRENT][EQUALIZER] = self.current_values.copy()
        self.util.set_equalizer(self.current_values)

    def handle_slider_event(self, state):
        """ Handle slider event

        :param state: state object
        """
        if self.navigator_selected:
            for b in self.equalizer_navigator.buttons:
                b.set_selected(False)
                b.clean_draw_update()
            self.navigator_selected = False

        band = int(state.event_origin.name[-1])
        v = state.position
        self.current_values[band] = v
        self.config[CURRENT][EQUALIZER] = self.current_values.copy()
        self.util.set_equalizer_band_value(band + 1, v)

        s = self.equalizer_menu.sliders[band]
        s.set_value(str(v))

    def add_screen_observers(self, update_observer, redraw_observer):
        """ Add screen observers
        
        :param update_observer: observer for updating the screen
        :param redraw_observer: observer to redraw the whole screen
        """
        Screen.add_screen_observers(self, update_observer, redraw_observer)

        self.equalizer_menu.add_menu_observers(update_observer,
                                               redraw_observer)
        self.equalizer_navigator.add_observers(update_observer,
                                               redraw_observer)