Exemplo n.º 1
0
class CdDrivesScreen(Screen):
    """ File Browser Screen """
    def __init__(self, util, listeners, voice_assistant):
        """ Initializer
        
        :param util: utility object
        :param listeners: file browser listeners
        """
        self.util = util
        self.config = util.config
        self.cdutil = CdUtil(util)
        self.factory = Factory(util)
        self.bounding_box = util.screen_rect
        layout = BorderLayout(self.bounding_box)
        layout.set_percent_constraints(PERCENT_TOP_HEIGHT,
                                       PERCENT_BOTTOM_HEIGHT, 0, 0)
        Screen.__init__(self, util, "", PERCENT_TOP_HEIGHT, voice_assistant,
                        "cd_drives_screen_title", True, layout.TOP)

        self.cd_drive_id = self.config[CD_PLAYBACK][CD_DRIVE_ID]
        self.cd_track = self.config[CD_PLAYBACK][CD_TRACK]
        self.cd_track_time = self.config[CD_PLAYBACK][CD_TRACK_TIME]
        self.screen_title.set_text(self.config[LABELS][KEY_CD_DRIVES])

        self.cd_drives_menu = CdDrivesMenu(util, layout.CENTER,
                                           listeners[KEY_CD_TRACKS])
        drives_info = self.cdutil.get_cd_drives_info()
        l = self.cd_drives_menu.get_layout(drives_info)
        bb = l.get_next_constraints()
        drives = self.cdutil.get_cd_drives(self.font_size, (bb.w, bb.h))
        self.cd_drives_menu.set_items(drives, 0, listeners[KEY_CD_TRACKS])

        for b in self.cd_drives_menu.buttons.values():
            b.parent_screen = self

        Container.add_component(self, self.cd_drives_menu)

        factory = Factory(util)
        self.menu_buttons = factory.create_home_player_buttons(
            self, self.layout.BOTTOM, listeners)
        self.home_button = self.menu_buttons[0]
        self.player_button = self.menu_buttons[1]

    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.cd_drives_menu.add_menu_observers(update_observer,
                                               redraw_observer)
        for b in self.menu_buttons:
            self.add_button_observers(b, update_observer, redraw_observer)
Exemplo n.º 2
0
class HomeMenu(Menu):
    """ Home Menu class. Extends base Menu class """
    def __init__(self, util, bgr=None, bounding_box=None, font_size=None):
        """ Initializer

        :param util: utility object
        :param bgr: menu background
        :param bounding_box: bounding box
        """
        self.util = util
        self.factory = Factory(util)
        self.config = util.config
        self.cdutil = CdUtil(util)

        self.bb = bounding_box
        self.horizontal_layout = True
        self.rows = None
        self.cols = None
        items = self.get_menu_items()
        cell_bb = items[2]

        m = self.create_home_menu_button
        label_area = (cell_bb.h / 100) * (100 - ICON_AREA)
        font_size = int((label_area / 100) * FONT_HEIGHT)
        Menu.__init__(self,
                      util,
                      bgr,
                      bounding_box,
                      None,
                      None,
                      create_item_method=m,
                      font_size=font_size)
        self.set_modes(*items)

    def get_menu_items(self):
        """ Prepare menu items

        :return: array containing menu items, disabled items, cell bounding box snf icon box
        """
        items = []
        disabled_items = []
        player = self.config[AUDIO][PLAYER_NAME]

        if self.config[HOME_MENU][RADIO]:
            items.append(RADIO)
            if not self.util.is_radio_enabled(
            ) or not self.util.connected_to_internet:
                disabled_items.append(RADIO)

        if self.config[HOME_MENU][AUDIO_FILES]:
            items.append(AUDIO_FILES)

        if self.config[HOME_MENU][AUDIOBOOKS]:
            items.append(AUDIOBOOKS)
            if not self.util.is_audiobooks_enabled(
            ) or not self.util.connected_to_internet:
                disabled_items.append(AUDIOBOOKS)

        if self.config[HOME_MENU][STREAM]:
            items.append(STREAM)
            if not self.util.connected_to_internet:
                disabled_items.append(STREAM)

        if self.config[HOME_MENU][CD_PLAYER]:
            cd_drives_info = self.cdutil.get_cd_drives_info()
            if len(cd_drives_info) == 0 or player == MPV_NAME:
                disabled_items.append(CD_PLAYER)
            items.append(CD_PLAYER)

        if self.config[HOME_MENU][PODCASTS]:
            podcasts_util = self.util.get_podcasts_util()
            podcasts = podcasts_util.get_podcasts_links()
            downloads = podcasts_util.are_there_any_downloads()
            connected = self.util.connected_to_internet
            valid_players = [VLC_NAME, MPV_NAME]
            if (connected and len(podcasts) == 0 and not downloads) or (
                    not connected
                    and not downloads) or player not in valid_players:
                disabled_items.append(PODCASTS)
            items.append(PODCASTS)

        if self.config[HOME_MENU][AIRPLAY]:
            items.append(AIRPLAY)
            if not self.util.config[LINUX_PLATFORM]:
                disabled_items.append(AIRPLAY)

        if self.config[HOME_MENU][SPOTIFY_CONNECT]:
            items.append(SPOTIFY_CONNECT)
            if not self.util.config[LINUX_PLATFORM]:
                disabled_items.append(SPOTIFY_CONNECT)

        if self.config[HOME_MENU][COLLECTION]:
            items.append(COLLECTION)
            db_util = self.util.get_db_util()
            if db_util.conn == None:
                disabled_items.append(COLLECTION)

        l = self.get_layout(items)
        bounding_box = l.get_next_constraints()
        box = self.factory.get_icon_bounding_box(bounding_box, ICON_LOCATION,
                                                 ICON_AREA, ICON_SIZE,
                                                 BUTTON_PADDING)

        return (items, disabled_items, bounding_box, box)

    def set_current_modes(self):
        """ Set current player modes """

        items = self.get_menu_items()
        self.set_modes(*items)

    def set_modes(self, items, disabled_items, bounding_box, box):
        """ Set menu items

        :param items: menu items
        :param disabled_items: disabled menu items
        :param bounding_box: cell bounding box
        :param box: image boundng box
        """
        self.modes = self.util.load_menu(items,
                                         NAME,
                                         disabled_items,
                                         V_ALIGN_TOP,
                                         bb=box)
        va_commands = self.util.get_voice_commands()

        if self.config[USAGE][USE_VOICE_ASSISTANT]:
            self.add_voice_command(RADIO, ["VA_RADIO", "VA_GO_RADIO"],
                                   va_commands)
            self.add_voice_command(AUDIO_FILES, ["VA_FILES", "VA_GO_FILES"],
                                   va_commands)
            self.add_voice_command(
                AUDIOBOOKS, ["VA_AUDIOBOOKS", "VA_BOOKS", "VA_GO_BOOKS"],
                va_commands)
            self.add_voice_command(STREAM, ["VA_STREAM", "VA_GO_STREAM"],
                                   va_commands)
            self.add_voice_command(CD_PLAYER, ["VA_CD_PLAYER"], va_commands)
            self.add_voice_command(PODCASTS, ["VA_PODCAST", "VA_PODCASTS"],
                                   va_commands)

        if not items:
            return

        if not self.config[CURRENT][MODE]:
            for i in items:
                if i not in disabled_items:
                    mode = i
                    break
        else:
            mode = self.config[CURRENT][MODE]

        self.set_items(self.modes, 0, self.change_mode, False)
        self.current_mode = self.modes[mode.lower()]
        self.item_selected(self.current_mode)

    def create_home_menu_button(self, s, constr, action, scale, font_size):
        """ Create Home Menu button

        :param s: button state
        :param constr: scaling constraints
        :param action: button event listener
        :param scale: True - scale images, False - don't scale images
        :param font_size: label font height in pixels

        :return: home menu button
        """
        s.padding = BUTTON_PADDING
        s.image_area_percent = ICON_AREA

        return self.factory.create_menu_button(s,
                                               constr,
                                               action,
                                               scale,
                                               font_size=font_size)

    def add_voice_command(self, name, commands, va_commands):
        """ Add voice command

        :param name: item name
        :param commands: item commands
        :param va_commands: voice commands
        """
        if not self.config[HOME_MENU][name]:
            return
        c = []
        for m in commands:
            c.append(va_commands[m].strip())
        self.modes[name].voice_commands = c

    def change_mode(self, state):
        """ Change mode event listener

        :param state: button state
        """
        if not self.visible:
            return
        state.previous_mode = self.current_mode.name
        self.current_mode = state
        self.config[CURRENT][MODE] = state.name
        self.notify_listeners(state)
Exemplo n.º 3
0
class HomeMenu(Menu):
    """ Home Menu class. Extends base Menu class """
    def __init__(self, util, bgr=None, bounding_box=None, font_size=None):
        """ Initializer

        :param util: utility object
        :param bgr: menu background
        :param bounding_box: bounding box
        """
        self.util = util
        self.factory = Factory(util)
        self.config = util.config
        m = self.factory.create_home_menu_button
        Menu.__init__(self,
                      util,
                      bgr,
                      bounding_box,
                      None,
                      None,
                      create_item_method=m,
                      font_size=font_size)
        self.cdutil = CdUtil(util)
        self.set_modes()

    def set_modes(self):
        items = []
        disabled_items = []
        player = self.config[AUDIO][PLAYER_NAME]

        if self.config[HOME_MENU][RADIO]:
            items.append(RADIO)
            if not self.util.is_radio_enabled(
            ) or not self.util.connected_to_internet:
                disabled_items.append(RADIO)

        if self.config[HOME_MENU][AUDIO_FILES]:
            items.append(AUDIO_FILES)

        if self.config[HOME_MENU][AUDIOBOOKS]:
            items.append(AUDIOBOOKS)
            if not self.util.is_audiobooks_enabled(
            ) or not self.util.connected_to_internet:
                disabled_items.append(AUDIOBOOKS)

        if self.config[HOME_MENU][STREAM]:
            items.append(STREAM)
            if not self.util.connected_to_internet:
                disabled_items.append(STREAM)

        if self.config[HOME_MENU][CD_PLAYER]:
            cd_drives_info = self.cdutil.get_cd_drives_info()
            if len(cd_drives_info) == 0 or player == MPV_NAME:
                disabled_items.append(CD_PLAYER)
            items.append(CD_PLAYER)

        if self.config[HOME_MENU][PODCASTS]:
            podcasts_util = self.util.get_podcasts_util()
            podcasts = podcasts_util.get_podcasts_links()
            downloads = podcasts_util.are_there_any_downloads()
            connected = self.util.connected_to_internet
            valid_players = [VLC_NAME, MPV_NAME]
            if (connected and len(podcasts) == 0 and not downloads) or (
                    not connected
                    and not downloads) or player not in valid_players:
                disabled_items.append(PODCASTS)
            items.append(PODCASTS)

        if self.config[HOME_MENU][AIRPLAY]:
            items.append(AIRPLAY)
            if not self.util.config[LINUX_PLATFORM]:
                disabled_items.append(AIRPLAY)

        if self.config[HOME_MENU][SPOTIFY_CONNECT]:
            items.append(SPOTIFY_CONNECT)
            if not self.util.config[LINUX_PLATFORM]:
                disabled_items.append(SPOTIFY_CONNECT)

        if self.config[HOME_MENU][COLLECTION]:
            items.append(COLLECTION)
            db_util = self.util.get_db_util()
            if db_util.conn == None:
                disabled_items.append(COLLECTION)

        l = self.get_layout(items)
        bounding_box = l.get_next_constraints()
        self.modes = self.util.load_menu(items,
                                         NAME,
                                         disabled_items,
                                         V_ALIGN_TOP,
                                         bb=bounding_box,
                                         scale=0.5)
        va_commands = self.util.get_voice_commands()

        if self.config[USAGE][USE_VOICE_ASSISTANT]:
            self.add_voice_command(RADIO, ["VA_RADIO", "VA_GO_RADIO"],
                                   va_commands)
            self.add_voice_command(AUDIO_FILES, ["VA_FILES", "VA_GO_FILES"],
                                   va_commands)
            self.add_voice_command(
                AUDIOBOOKS, ["VA_AUDIOBOOKS", "VA_BOOKS", "VA_GO_BOOKS"],
                va_commands)
            self.add_voice_command(STREAM, ["VA_STREAM", "VA_GO_STREAM"],
                                   va_commands)
            self.add_voice_command(CD_PLAYER, ["VA_CD_PLAYER"], va_commands)
            self.add_voice_command(PODCASTS, ["VA_PODCAST", "VA_PODCASTS"],
                                   va_commands)

        if not items:
            return

        if not self.config[CURRENT][MODE]:
            for i in items:
                if i not in disabled_items:
                    mode = i
                    break
        else:
            mode = self.config[CURRENT][MODE]

        self.set_items(self.modes, 0, self.change_mode, False)
        self.current_mode = self.modes[mode.lower()]
        self.item_selected(self.current_mode)

    def add_voice_command(self, name, commands, va_commands):
        """ Add voice command

        :param name: item name
        :param commands: item commands
        :param va_commands: voice commands
        """
        if not self.config[HOME_MENU][name]:
            return
        c = []
        for m in commands:
            c.append(va_commands[m].strip())
        self.modes[name].voice_commands = c

    def change_mode(self, state):
        """ Change mode event listener

        :param state: button state
        """
        if not self.visible:
            return
        state.previous_mode = self.current_mode.name
        self.current_mode = state
        self.config[CURRENT][MODE] = state.name
        self.notify_listeners(state)
Exemplo n.º 4
0
class HomeMenu(Menu):
    """ Home Menu class. Extends base Menu class """
    def __init__(self, util, bgr=None, bounding_box=None, font_size=None):
        """ Initializer
        
        :param util: utility object
        :param bgr: menu background
        :param bounding_box: bounding box
        """
        self.util = util
        self.factory = Factory(util)
        self.config = util.config
        m = self.factory.create_home_menu_button
        Menu.__init__(self,
                      util,
                      bgr,
                      bounding_box,
                      None,
                      None,
                      create_item_method=m,
                      font_size=font_size)
        self.cdutil = CdUtil(util)
        self.set_modes()

    def set_modes(self):
        items = []
        disabled_items = []

        if self.config[HOME_MENU][RADIO]:
            items.append(RADIO)
            if not self.util.is_radio_enabled(
            ) or not self.util.connected_to_internet:
                disabled_items.append(RADIO)

        if self.config[HOME_MENU][AUDIO_FILES]:
            items.append(AUDIO_FILES)

        if self.config[HOME_MENU][AUDIOBOOKS]:
            items.append(AUDIOBOOKS)
            if not self.util.is_audiobooks_enabled(
            ) or not self.util.connected_to_internet:
                disabled_items.append(AUDIOBOOKS)

        if self.config[HOME_MENU][STREAM]:
            items.append(STREAM)
            if not self.util.connected_to_internet:
                disabled_items.append(STREAM)

        if self.config[HOME_MENU][CD_PLAYER]:
            cd_drives_info = self.cdutil.get_cd_drives_info()
            if len(cd_drives_info) == 0:
                disabled_items.append(CD_PLAYER)
            items.append(CD_PLAYER)

        if self.config[HOME_MENU][PODCASTS]:
            podcasts_util = self.util.get_podcasts_util()
            podcasts = podcasts_util.get_podcasts_links()
            downloads = podcasts_util.are_there_any_downloads()
            connected = self.util.connected_to_internet
            player = self.config[AUDIO][PLAYER_NAME]
            if (connected and len(podcasts) == 0
                    and not downloads) or (not connected
                                           and not downloads) or player != VLC:
                disabled_items.append(PODCASTS)
            items.append(PODCASTS)

        l = self.get_layout(items)
        bounding_box = l.get_next_constraints()
        self.modes = self.util.load_menu(items,
                                         NAME,
                                         disabled_items,
                                         V_ALIGN_TOP,
                                         bb=bounding_box,
                                         scale=0.5)
        va_commands = self.util.get_voice_commands()

        if self.config[USAGE][USE_VOICE_ASSISTANT]:
            if self.config[HOME_MENU][RADIO]:
                r = [
                    va_commands["VA_RADIO"].strip(),
                    va_commands["VA_GO_RADIO"].strip()
                ]
                self.modes[RADIO].voice_commands = r
            if self.config[HOME_MENU][AUDIO_FILES]:
                f = [
                    va_commands["VA_FILES"].strip(),
                    va_commands["VA_GO_FILES"].strip(),
                    va_commands["VA_AUDIO_FILES"].strip()
                ]
                self.modes[AUDIO_FILES].voice_commands = f
            if self.config[HOME_MENU][AUDIOBOOKS]:
                a = [
                    va_commands["VA_AUDIOBOOKS"].strip(),
                    va_commands["VA_BOOKS"].strip(),
                    va_commands["VA_GO_BOOKS"].strip()
                ]
                self.modes[AUDIOBOOKS].voice_commands = a
            if self.config[HOME_MENU][STREAM]:
                s = [
                    va_commands["VA_STREAM"].strip(),
                    va_commands["VA_GO_STREAM"].strip()
                ]
                self.modes[STREAM].voice_commands = s
            if self.config[HOME_MENU][CD_PLAYER]:
                s = [va_commands["VA_CD_PLAYER"].strip()]
                self.modes[STREAM].voice_commands = s

        if not items:
            return

        if not self.config[CURRENT][MODE]:
            for i in items:
                if i not in disabled_items:
                    mode = i
                    break
        else:
            mode = self.config[CURRENT][MODE]

        self.set_items(self.modes, 0, self.change_mode, False)
        self.current_mode = self.modes[mode.lower()]
        self.item_selected(self.current_mode)

    def change_mode(self, state):
        """ Change mode event listener
        
        :param state: button state
        """
        if not self.visible:
            return
        state.previous_mode = self.current_mode.name
        self.current_mode = state
        self.config[CURRENT][MODE] = state.name
        self.notify_listeners(state)
Exemplo n.º 5
0
 def __init__(self, util, bgr=None, bounding_box=None, font_size=None):
     """ Initializer
     
     :param util: utility object
     :param bgr: menu background
     :param bounding_box: bounding box
     """   
     self.factory = Factory(util)
     self.config = util.config
     m = self.factory.create_home_menu_button
     Menu.__init__(self, util, bgr, bounding_box, None, None, create_item_method=m, font_size=font_size)
     cdutil = CdUtil(util)
     
     items = []
     disabled_items = []
     
     if self.config[HOME_MENU][RADIO]: 
         items.append(RADIO)
         if not util.is_radio_enabled() or not util.connected_to_internet:
             disabled_items.append(RADIO)
             
     if self.config[HOME_MENU][AUDIO_FILES]: 
         items.append(AUDIO_FILES)
         
     if self.config[HOME_MENU][AUDIOBOOKS]: 
         items.append(AUDIOBOOKS)
         if not util.is_audiobooks_enabled() or not util.connected_to_internet:
             disabled_items.append(AUDIOBOOKS)
             
     if self.config[HOME_MENU][STREAM]:
         items.append(STREAM)
         if not util.connected_to_internet:
             disabled_items.append(STREAM)
             
     if self.config[HOME_MENU][CD_PLAYER]: 
         cd_drives_info = cdutil.get_cd_drives_info()
         player = self.config[AUDIO][PLAYER_NAME]
         if len(cd_drives_info) == 0:
             disabled_items.append(CD_PLAYER)
         items.append(CD_PLAYER)
     
     l = self.get_layout(items)
     bounding_box = l.get_next_constraints()
     self.modes = util.load_menu(items, NAME, disabled_items, V_ALIGN_TOP, bb=bounding_box, scale=0.5)
     va_commands = self.util.get_voice_commands()
     
     if self.config[USAGE][USE_VOICE_ASSISTANT]:
         if self.config[HOME_MENU][RADIO]:
             r = [va_commands["VA_RADIO"].strip(), va_commands["VA_GO_RADIO"].strip()]
             self.modes[RADIO].voice_commands = r            
         if self.config[HOME_MENU][AUDIO_FILES]:
             f = [va_commands["VA_FILES"].strip(), va_commands["VA_GO_FILES"].strip(), va_commands["VA_AUDIO_FILES"].strip()]
             self.modes[AUDIO_FILES].voice_commands = f
         if self.config[HOME_MENU][AUDIOBOOKS]:    
             a = [va_commands["VA_AUDIOBOOKS"].strip(), va_commands["VA_BOOKS"].strip(), va_commands["VA_GO_BOOKS"].strip()]
             self.modes[AUDIOBOOKS].voice_commands = a
         if self.config[HOME_MENU][STREAM]:    
             s = [va_commands["VA_STREAM"].strip(), va_commands["VA_GO_STREAM"].strip()]
             self.modes[STREAM].voice_commands = s
         if self.config[HOME_MENU][CD_PLAYER]:    
             s = [va_commands["VA_CD_PLAYER"].strip()]
             self.modes[STREAM].voice_commands = s
         
     if not items:
         return
     
     if not self.config[CURRENT][MODE]:
         for i in items:
             if i not in disabled_items:            
                 mode = i
                 break            
     else:
         mode = self.config[CURRENT][MODE]
     
     self.set_items(self.modes, 0, self.change_mode, False)
     self.current_mode = self.modes[mode.lower()]
     self.item_selected(self.current_mode)