def do_activate(self):
        print("Activating Random Album Plugin")
        self.shell = self.object

        self.action_group = ActionGroup(self.shell, 'RandomAlbumActionGroup')

        action = self.action_group.add_action_with_accel(
            func=self.random_album,
            action_name='RandomAlbum',
            label='Random Album',
            action_type='app',
            action_state=ActionGroup.STANDARD,
            accel="<shift><ctrl>R")

        self._appshell = ApplicationShell(self.shell)
        self._appshell.insert_action_group(self.action_group)
        self._appshell.add_app_menuitems(menu_item_ui,
                                         'RandomAlbumActionGroup')

        if not random_rb3compat.is_rb3():
            #uim = self.shell.props.ui_manager
            self._appshell.add_app_menuitems(toolbar_button_ui, 'RandomAlbum')
            #uim.add_ui_from_string(toolbar_button_ui)

        self.settings = Gio.Settings(
            'org.gnome.rhythmbox.plugins.randomalbumplayer')
コード例 #2
0
  def do_activate(self):
    print("Activating Random Album Plugin")
    self.shell = self.object
        
    self.action_group = ActionGroup(self.shell, 'RandomAlbumActionGroup')
    
    action = self.action_group.add_action_with_accel(func=self.random_album,
    action_name='RandomAlbum', label='Random Album',
    action_type='app', action_state=ActionGroup.STANDARD,
    accel="<shift><ctrl>R")

    self._appshell = ApplicationShell(self.shell)
    self._appshell.insert_action_group(self.action_group)
    self._appshell.add_app_menuitems(menu_item_ui, 'RandomAlbumActionGroup')

    if not random_rb3compat.is_rb3():
        #uim = self.shell.props.ui_manager
        self._appshell.add_app_menuitems(toolbar_button_ui, 'RandomAlbum')
        #uim.add_ui_from_string(toolbar_button_ui)
    
    self.settings = Gio.Settings('org.gnome.rhythmbox.plugins.randomalbumplayer')
コード例 #3
0
class RandomAlbumPlugin(GObject.Object, Peas.Activatable):
  __gtype_name__ = 'RandomAlbumPlugin'
  object = GObject.property(type=GObject.Object)

  def __init__(self):
    super(RandomAlbumPlugin, self).__init__()

  def do_activate(self):
    print("Activating Random Album Plugin")
    self.shell = self.object
        
    self.action_group = ActionGroup(self.shell, 'RandomAlbumActionGroup')
    
    action = self.action_group.add_action_with_accel(func=self.random_album,
    action_name='RandomAlbum', label='Random Album',
    action_type='app', action_state=ActionGroup.STANDARD,
    accel="<shift><ctrl>R")

    self._appshell = ApplicationShell(self.shell)
    self._appshell.insert_action_group(self.action_group)
    self._appshell.add_app_menuitems(menu_item_ui, 'RandomAlbumActionGroup')

    if not random_rb3compat.is_rb3():
        #uim = self.shell.props.ui_manager
        self._appshell.add_app_menuitems(toolbar_button_ui, 'RandomAlbum')
        #uim.add_ui_from_string(toolbar_button_ui)
    
    self.settings = Gio.Settings('org.gnome.rhythmbox.plugins.randomalbumplayer')

  def do_deactivate(self):
    print('Deactivating Random Album Plugin')
    shell = self.object
    self._appshell.cleanup()

  def random_album(self, *args):
    self.clear_queue()
    self.queue_random_albums(self.settings['albums-to-play'])
    self.play_album()
    self.scroll_to_current_song()

  def clear_queue(self):
    play_queue = self.shell.props.queue_source
    for row in play_queue.props.query_model:
      entry = row[0]
      play_queue.remove_entry(entry)
    
  def queue_random_albums(self, album_count):
    for _ in range(album_count):
        self.queue_random_album()

  def play_album(self):
    print('Playing Album')
    player = self.shell.props.shell_player
    player.stop()
    player.set_playing_source(self.shell.props.queue_source)
    player.playpause(True)

  def scroll_to_current_song(self):
    song = self.shell.props.shell_player.get_playing_entry()
    src = self.shell.props.library_source
    lst = src.get_entry_view()
    lst.scroll_to_entry(song)

  def queue_random_album(self):
    shell = self.object
    library = shell.props.library_source
    albums = {}
    
    ignore_albums = [ item.strip() for item in self.settings['ignored-albums'].split(',') ]

    for row in library.props.query_model:
      entry = row[0]
      album_name = entry.get_string(RB.RhythmDBPropType.ALBUM)
      
      if album_name in ignore_albums:
        continue
        
      album_struct = albums.get(album_name, { "songs" : [], "count": 0 })
      album_struct["count"] = album_struct["count"] + 1
      album_struct["songs"].append(entry)
      albums[album_name] = album_struct
  
    # Choose a random album with more than 5 songs
    while True:
        album_names = list(albums.keys())
        num_albums = len(albums)
        selected_album = album_names[random.randint(0, num_albums - 1)]

        print('Queuing ' + selected_album + '.')
  
        # Find all the songs from that album
        songs = albums[selected_album]["songs"]
    
        if len(songs) > 5:
            # album is long enough
            break
  
    # Sort the songs by disc number, track number
    songs = sorted(songs, key=lambda song: song.get_ulong(RB.RhythmDBPropType.TRACK_NUMBER))
    songs = sorted(songs, key=lambda song: song.get_ulong(RB.RhythmDBPropType.DISC_NUMBER))
        
    # Add the songs to the play queue      
    for song in songs:
      shell.props.queue_source.add_entry(song, -1)
class RandomAlbumPlugin(GObject.Object, Peas.Activatable):
    __gtype_name__ = 'RandomAlbumPlugin'
    object = GObject.property(type=GObject.Object)

    def __init__(self):
        super(RandomAlbumPlugin, self).__init__()

    def do_activate(self):
        print("Activating Random Album Plugin")
        self.shell = self.object

        self.action_group = ActionGroup(self.shell, 'RandomAlbumActionGroup')

        action = self.action_group.add_action_with_accel(
            func=self.random_album,
            action_name='RandomAlbum',
            label='Random Album',
            action_type='app',
            action_state=ActionGroup.STANDARD,
            accel="<shift><ctrl>R")

        self._appshell = ApplicationShell(self.shell)
        self._appshell.insert_action_group(self.action_group)
        self._appshell.add_app_menuitems(menu_item_ui,
                                         'RandomAlbumActionGroup')

        if not random_rb3compat.is_rb3():
            #uim = self.shell.props.ui_manager
            self._appshell.add_app_menuitems(toolbar_button_ui, 'RandomAlbum')
            #uim.add_ui_from_string(toolbar_button_ui)

        self.settings = Gio.Settings(
            'org.gnome.rhythmbox.plugins.randomalbumplayer')

    def do_deactivate(self):
        print('Deactivating Random Album Plugin')
        shell = self.object
        self._appshell.cleanup()

    def random_album(self, *args):
        self.clear_queue()
        self.queue_random_albums(self.settings['albums-to-play'])
        self.play_album()
        self.scroll_to_current_song()

    def clear_queue(self):
        play_queue = self.shell.props.queue_source
        for row in play_queue.props.query_model:
            entry = row[0]
            play_queue.remove_entry(entry)

    def queue_random_albums(self, album_count):
        for _ in range(album_count):
            self.queue_random_album()

    def play_album(self):
        print('Playing Album')
        player = self.shell.props.shell_player
        player.stop()
        player.set_playing_source(self.shell.props.queue_source)
        player.playpause()

    def scroll_to_current_song(self):
        song = self.shell.props.shell_player.get_playing_entry()
        src = self.shell.props.library_source
        lst = src.get_entry_view()
        lst.scroll_to_entry(song)

    def queue_random_album(self):
        shell = self.object
        library = shell.props.library_source
        albums = {}

        ignore_albums = [
            item.strip() for item in self.settings['ignored-albums'].split(',')
        ]

        for row in library.props.query_model:
            entry = row[0]
            album_name = entry.get_string(RB.RhythmDBPropType.ALBUM)

            if album_name in ignore_albums:
                continue

            album_struct = albums.get(album_name, {"songs": [], "count": 0})
            album_struct["count"] = album_struct["count"] + 1
            album_struct["songs"].append(entry)
            albums[album_name] = album_struct

        # Choose a random album with more than 5 songs
        while True:
            album_names = list(albums.keys())
            num_albums = len(albums)
            selected_album = album_names[random.randint(0, num_albums - 1)]

            print('Queuing ' + selected_album + '.')

            # Find all the songs from that album
            songs = albums[selected_album]["songs"]

            if len(songs) > 5:
                # album is long enough
                break

        # Sort the songs by disc number, track number
        songs = sorted(
            songs,
            key=lambda song: song.get_ulong(RB.RhythmDBPropType.TRACK_NUMBER))
        songs = sorted(
            songs,
            key=lambda song: song.get_ulong(RB.RhythmDBPropType.DISC_NUMBER))

        # Add the songs to the play queue
        for song in songs:
            shell.props.queue_source.add_entry(song, -1)