Exemplo n.º 1
0
    def do_activate(self):
        #~ shell = self.object
        print "Activating Random Album Plugin"
        #~ action = Gtk.Action ('RandomAlbum', _('Random Album'), _('Play a Random Album'), "")
        #~ action.connect ('activate', self.random_album, shell)
        #~ action_group = Gtk.ActionGroup('RandomAlbumActionGroup')
        #~ action_group.add_action_with_accel (action, "<alt>R")

        self.shell = self.object

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

        action = self.action_group.add_action(
            func=self.random_album,
            action_name='RandomAlbum',
            label='RandomAlbum',
            action_type='app',
            action_state=ActionGroup.STANDARD)

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

        self.settings = Gio.Settings(
            'org.gnome.rhythmbox.plugins.randomalbumplayer')
Exemplo n.º 2
0
    def do_activate(self):
        self.shell = self.object
        
        self.action_group = ActionGroup(self.shell, 'PowerOffActionGroup')
        action = self.action_group.add_action(func=self.set_poweroff,
            action_name='PowerOffAction', label='PowerOff',
            action_type='app', action_state=ActionGroup.TOGGLE)

        self._appshell = ApplicationShell(self.shell)
        self._appshell.insert_action_group(self.action_group)
        self._appshell.add_app_menuitems(ui_str, 'PowerOffActionGroup')
        
        ## bind to signal, end of playlist
        self.shell_player = self.shell.props.shell_player
        self.player_connect_id = self.shell_player.connect('playing-changed', self.playing_changed)
        
        self.load_config()
  def do_activate(self):
    #~ shell = self.object
    print "Activating Random Album Plugin"
    #~ action = Gtk.Action ('RandomAlbum', _('Random Album'), _('Play a Random Album'), "")
    #~ action.connect ('activate', self.random_album, shell)
    #~ action_group = Gtk.ActionGroup('RandomAlbumActionGroup')
    #~ action_group.add_action_with_accel (action, "<alt>R")
    
    self.shell = self.object
        
    self.action_group = ActionGroup(self.shell, 'RandomAlbumActionGroup')
    
    action = self.action_group.add_action(func=self.random_album,
    action_name='RandomAlbum', label='RandomAlbum',
    action_type='app', action_state=ActionGroup.STANDARD)

    self._appshell = ApplicationShell(self.shell)
    self._appshell.insert_action_group(self.action_group)
    self._appshell.add_app_menuitems(ui_str, 'RandomAlbumActionGroup')
    
    self.settings = Gio.Settings('org.gnome.rhythmbox.plugins.randomalbumplayer')
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):
    #~ shell = self.object
    print "Activating Random Album Plugin"
    #~ action = Gtk.Action ('RandomAlbum', _('Random Album'), _('Play a Random Album'), "")
    #~ action.connect ('activate', self.random_album, shell)
    #~ action_group = Gtk.ActionGroup('RandomAlbumActionGroup')
    #~ action_group.add_action_with_accel (action, "<alt>R")
    
    self.shell = self.object
        
    self.action_group = ActionGroup(self.shell, 'RandomAlbumActionGroup')
    
    action = self.action_group.add_action(func=self.random_album,
    action_name='RandomAlbum', label='RandomAlbum',
    action_type='app', action_state=ActionGroup.STANDARD)

    self._appshell = ApplicationShell(self.shell)
    self._appshell.insert_action_group(self.action_group)
    self._appshell.add_app_menuitems(ui_str, 'RandomAlbumActionGroup')
    
    self.settings = Gio.Settings('org.gnome.rhythmbox.plugins.randomalbumplayer')

  def do_deactivate(self):
    print 'Deactivating Random Album Plugin'
    shell = self.object
    #~ ui_manager = shell.props.ui_manager
    #~ ui_manager.remove_ui(self.ui_id)

  def random_album(self, *args):
    # Get URIs of all the songs in the queue and remove them
    play_queue = self.shell.props.queue_source
    for row in play_queue.props.query_model:
      entry = row[0]
      play_queue.remove_entry(entry)
  
    # Queue a random album
    for _ in range(self.settings['albums-to-play']):
        self.queue_random_album()
    
    # Start the music!(well, first stop it, but it'll start up again.)
    print 'Playing Album'
    player = self.shell.props.shell_player
    player.stop()
    player.set_playing_source(self.shell.props.queue_source)
    player.playpause(True)

  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 = 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)
Exemplo n.º 5
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):
        #~ shell = self.object
        print "Activating Random Album Plugin"
        #~ action = Gtk.Action ('RandomAlbum', _('Random Album'), _('Play a Random Album'), "")
        #~ action.connect ('activate', self.random_album, shell)
        #~ action_group = Gtk.ActionGroup('RandomAlbumActionGroup')
        #~ action_group.add_action_with_accel (action, "<alt>R")

        self.shell = self.object

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

        action = self.action_group.add_action(
            func=self.random_album,
            action_name='RandomAlbum',
            label='RandomAlbum',
            action_type='app',
            action_state=ActionGroup.STANDARD)

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

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

    def do_deactivate(self):
        print 'Deactivating Random Album Plugin'
        shell = self.object
        #~ ui_manager = shell.props.ui_manager
        #~ ui_manager.remove_ui(self.ui_id)

    def random_album(self, *args):
        # Get URIs of all the songs in the queue and remove them
        play_queue = self.shell.props.queue_source
        for row in play_queue.props.query_model:
            entry = row[0]
            play_queue.remove_entry(entry)

        # Queue a random album
        for _ in range(self.settings['albums-to-play']):
            self.queue_random_album()

        # Start the music!(well, first stop it, but it'll start up again.)
        print 'Playing Album'
        player = self.shell.props.shell_player
        player.stop()
        player.set_playing_source(self.shell.props.queue_source)
        player.playpause(True)

    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 = 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)
Exemplo n.º 6
0
class SuspendPlugin(GObject.GObject, Peas.Activatable):
    __gtype_name__ = 'SuspendPlugin'
    object = GObject.Property(type=GObject.GObject)

    def __init__(self):
        super(SuspendPlugin, self).__init__()
        self.gconf = GConf.Client.get_default()
        self.window = None
        self.poweroff = False
        self.config_dialog = None
        self.dialog = None
        
        self.gconf.add_dir(GCONF_DIR, preload=False)
        userdata=None
        self.gconf.notify_add(GCONF_KEYS['action'], self.action_changed_cb, userdata)
        self.gconf.notify_add(GCONF_KEYS['time'], self.time_changed_cb, userdata)
        
        self.poweroff_time = 60
        self.poweroff_action = 1 # 0 - poweroff, 1 - suspend
        self.poweroff_action_dict = { 0: 'Shutdown', 1: 'Suspend' }
        self.poweroff_action_func = {0: self.action_shutdown, 1: self.action_suspend}
        
        self.is_playing = False
        
    def do_activate(self):
        self.shell = self.object
        
        self.action_group = ActionGroup(self.shell, 'PowerOffActionGroup')
        action = self.action_group.add_action(func=self.set_poweroff,
            action_name='PowerOffAction', label='PowerOff',
            action_type='app', action_state=ActionGroup.TOGGLE)

        self._appshell = ApplicationShell(self.shell)
        self._appshell.insert_action_group(self.action_group)
        self._appshell.add_app_menuitems(ui_str, 'PowerOffActionGroup')
        
        ## bind to signal, end of playlist
        self.shell_player = self.shell.props.shell_player
        self.player_connect_id = self.shell_player.connect('playing-changed', self.playing_changed)
        
        self.load_config()
        
    def do_deactivate(self):
        self._appshell.cleanup()
        self.shell_player.disconnect(self.player_connect_id)
        if self.dialog:
            self.dialog.destroy()
    
    def action_changed_cb(self, client, id, entry, d):
        gaction = self.gconf.get_int(GCONF_KEYS['action'])
        self.poweroff_action = gaction
    
    def time_changed_cb(self, client, id, entry, d):
        gtime = self.gconf.get_string(GCONF_KEYS['time'])
        self.poweroff_time = gtime
    
    def load_config(self):
        gtime = self.gconf.get_string(GCONF_KEYS['time'])
        gaction = self.gconf.get_int(GCONF_KEYS['action'])
        if gtime == None:
            gtime = 60
        else:
            gtime = int(gtime)
        
        if gaction not in [0,1]:
            gaction = 1
        
        self.poweroff_time = gtime
        self.poweroff_action = gaction
    
    def set_poweroff(self, *args):
        #btn = self.ui.get_widget('/ToolBar/PowerOff')
        
        if self.poweroff:
            self.poweroff = False
            #btn.set_tooltip_text(_("%s computer after playlist end [is OFF]" % (self.poweroff_action_dict[self.poweroff_action])))
        else:
            self.poweroff = True
            #btn.set_tooltip_text(_("%s computer after playlist end [is ON]" % (self.poweroff_action_dict[self.poweroff_action])))
    
    def action_suspend(self):
        bus = dbus.SystemBus()
        proxy = bus.get_object('org.freedesktop.UPower', '/org/freedesktop/UPower')
        iface = dbus.Interface(proxy, 'org.freedesktop.UPower')
        ret = iface.Suspend()
        print('POWER OFF', ret)
        self.dialog.destroy()
    
    def action_shutdown(self):
        bus = dbus.SystemBus()
        proxy = bus.get_object('org.freedesktop.ConsoleKit', '/org/freedesktop/ConsoleKit/Manager')
        iface = dbus.Interface(proxy, 'org.freedesktop.ConsoleKit.Manager')
        iface.Stop()
        print('SHUTDOWN')
        self.dialog.destroy()
    
    def playing_changed(self, player, playing):
        
        if not self.is_playing and playing:
            self.is_playing = True
        
        if not playing and self.poweroff and self.is_playing:
            self.dialog = Gtk.MessageDialog(type=Gtk.MessageType.WARNING, buttons=Gtk.ButtonsType.CANCEL, message_format=_("Computer will be %s after %d seconds. You can cancel this procedure now." % (self.poweroff_action_dict[self.poweroff_action], int(self.poweroff_time))))            
            timer = threading.Timer(int(self.poweroff_time), self.poweroff_action_func[int(self.poweroff_action)])
            timer.start()
            
            response = self.dialog.run()
            if response == Gtk.ResponseType.CANCEL:
                timer.cancel()
                print('cancel')
                self.is_playing = False
                
            self.dialog.destroy()
            
    def create_configure_dialog(self, dialog=None):
        if self.config_dialog is None:
            self.config_dialog = config.SuspendConfigDialog(self)
            self.config_dialog.connect('response', self.config_dialog_response_cb)
            
        self.config_dialog.present()
        return self.config_dialog
    
    def config_dialog_response_cb(self, dialog, response):
        print('response cb')
        dialog.hide()