Пример #1
0
 def perform_command(self, command: Suggestion):
     """
     Executes a command
     :param command: Suggestion object
     :return:
     """
     try:
         if command.parameter == "":
             command.function(self.manager)
         else:
             command.function(self.manager, command.parameter)
     except:
         print("[Error] Command failed to execute")
Пример #2
0
 def execute_function(self, suggestion: Suggestion):
     """
     Executes a command
     :param suggestion: Suggestion Object
     """
     try:
         if suggestion.title == "Authentication":  # opens Auth UI, needs changed at some point
             self.auth_ui.show()
         elif suggestion.parameter == "":  # executes Suggestion's function
             suggestion.function(self.manager)
         else:  # executes Suggestion's function with a string parameter
             suggestion.function(self.manager, suggestion.parameter)
     except:
         print("[Error] Command failed to execute")
Пример #3
0
 def perform_command(self, item: Suggestion):
     """
     Executes a command
     :param command: Suggestion object
     """
     try:
         if item.title == "Authentication":  # opens Auth UI, needs changed at some point
             self.auth_ui.show()
         elif item.parameter == "":  # executes Suggestion's function
             item.function(self.manager)
         else:  # executes Suggestion's function with a string parameter
             item.function(self.manager, item.parameter)
     except:
         print("[Error] Command failed to execute")
Пример #4
0
    def __init__(self, title: str, description: str, icon: str, fill_str: str, menu_suggestions: list,
                 fill_prefix=True):
        """

        :param title:
        :param description:
        :param icon:
        :param fill_str:
        :param menu_suggestions: stores a list of Suggestions to be displayed
        :param fill_prefix: confirms that when clicked the fill_str will fill into the Spotlight search
        """
        Suggestion.__init__(self, title, description, icon, lambda: None, fill_str,
                            "", "menu_fill" if fill_prefix else "menu")
        self.__menu_suggestions = []
        self.menu_suggestions = menu_suggestions
Пример #5
0
    def refresh_menu_suggestions(self):
        # get relevant info from playlists
        playlists = []
        for key, value in CacheHolder.playlist_cache["playlists"].items():
            if value["owner"] == getenv(
                    'SPOTIFY_USERNAME'
            ):  # TODO Change to something more solid e.g. singleton
                playlists.append({"name": value["name"], "id": key})

        # create pages list
        len_ = len(playlists)
        num_pages = ceil(len_ / 4)

        # append back item
        back_item = MenuSuggestion("Back",
                                   f"Page 1 of {num_pages}",
                                   "exit",
                                   "",
                                   SongOptions.create_song_options(
                                       self.song_name, self.artist_name,
                                       self.image_name, self.song_id),
                                   fill_prefix=False)
        menu_items = [back_item]

        # make playlist suggestions list
        for i in range(0, len_):
            playlist = playlists[i]
            ids = {"song": self.song_id, "playlist": playlists[i]["id"]}
            menu_items.append(
                Suggestion(playlist["name"], f"Add to {playlist['name']}",
                           playlist['id'], PlaybackManager.add_to_playlist, "",
                           ids, "exe"))
        # paging method is called in the setter of menu_suggestions
        self.menu_suggestions = menu_items
Пример #6
0
 def __init__(self, title: str, description: str, icon: str, prefix: str, menu_items: list, fill_prefix=True):
     Suggestion.__init__(self, title, description, icon, lambda: None, prefix,
                         "", "menu_fill" if fill_prefix else "menu")
     self.__menu_items = []
     self.menu_items = menu_items
Пример #7
0
 def __init__(self, title, description, icon, fill_str):
     Suggestion.__init__(self, title, description, icon, lambda: None,
                         fill_str, "", "fill")
     self.prefix = fill_str  # TODO Change this by creating a base class for ITEM
Пример #8
0
 def __init__(self, title, description, icon, function, parameter=""):
     Suggestion.__init__(self, title, description, icon, function, "",
                         parameter, "exe")
Пример #9
0
 def __init__(self, title, description, icon):
     Suggestion.__init__(self, title, description, icon, lambda: None, "",
                         "", "none")
Пример #10
0
 def __init__(self, title, description, fill_str):
     Suggestion.__init__(self, title, description, "cog", lambda: None,
                         fill_str, "", "fill")
Пример #11
0
 def __init__(self, song_name, song_id):
     Suggestion.__init__(self, f"Go to Song Radio",
                         f"Start '{song_name}' Radio", "radio",
                         PlaybackManager.play_recommended, "", song_id,
                         "exe")
Пример #12
0
 def __init__(self, song_name):
     Suggestion.__init__(self, f"Save Song", f"Save '{song_name}'", "heart",
                         PlaybackManager.toggle_like_song, "", "", "exe")
Пример #13
0
 def __init__(self, song_name, song_id):
     Suggestion.__init__(self, f"Add to Queue", f"Queue '{song_name}'",
                         "queue", PlaybackManager.queue_song, "", song_id,
                         "exe")
Пример #14
0
 def __init__(self, song_id):
     Suggestion.__init__(self, f"Share Song URL", f"Copy URL to Clipboard",
                         "share", PlaybackManager.copy_url_to_clipboard, "",
                         song_id, "exe")
Пример #15
0
 def __init__(self, song_name, artists, image):
     Suggestion.__init__(self, "", "", "", lambda: None, "", "none")
Пример #16
0
 def __init__(self, title: str, description: str, icon_name: str, function: classmethod, parameter: str,
              prefix: str, setting: str):
     Suggestion.__init__(self, title, description, icon_name, function, prefix, parameter, setting)