コード例 #1
0
ファイル: Mpris2Skill.py プロジェクト: js5342/icarus
    def main(self, message):
        action = 0
        DBusGMainLoop(set_as_default=True)

        for unit in self._actions:
            if unit[0] in message.tokens:
                action = unit[1]
        if action == 0:
            message.run_next_skill()
            return
        uri = next(get_players_uri())
        player = Player(dbus_interface_info={'dbus_uri': uri})
        if action == 1:
            player.Play()
        elif action == 2:
            player.Pause()
        elif action == 3:
            player.PlayPause()
        elif action == 4:
            player.Next()
        elif action == 5:
            player.Previous()
        elif action == 6:
            message.send(player.Metadata)

        message.send("Action accomplished")
コード例 #2
0
ファイル: music.py プロジェクト: 10ktris/py3status
    def on_click(self, event):
        player_uri = self._get_player()
        if player_uri is None:
            return

        try:
            player = Player(dbus_interface_info={'dbus_uri': player_uri})
        except dbus.DBusException:
            return

        try:
            buttons = {
                1: 'left',
                2: 'middle',
                3: 'right',
                4: 'wheel_up',
                5: 'wheel_down',
                6: 'wheel_left',
                7: 'wheel_right',
                8: 'previous',
                9: 'next',
            }
            btn_name = buttons[event['button']]
            action = getattr(self, 'button_' + btn_name)
        except KeyError:
            return

        try:
            if action == 'play':
                player.Play()
            elif action == 'toggle':
                player.PlayPause()
            elif action == 'pause':
                player.Pause()
            elif action == 'stop':
                player.Stop()
            elif action == 'volume_up':
                player.Volume += self.volume_offset
            elif action == 'volume_down':
                player.Volume -= self.volume_offset
            elif action == 'next':
                player.Next()
            elif action == 'previous':
                player.Previous()
            elif action == "forward":
                player.Seek(self.seek_offset * 1000000)
            elif action == "backward":
                player.Seek(-self.seek_offset * 1000000)
        except dbus.DBusException:
            return