コード例 #1
0
ファイル: app.py プロジェクト: xuhui/clay
    def log_in(self, use_token=True):
        """
        Called when this page is shown.

        Request user authorization.
        """
        authtoken, device_id, username, password = [
            settings.get(key, "play_settings")
            for key in ('authtoken', 'device_id', 'username', 'password')
        ]

        if self._login_notification:
            self._login_notification.close()
        if use_token and authtoken:
            self._login_notification = notification_area.notify(
                'Using cached auth token...')
            gp.use_authtoken_async(authtoken,
                                   device_id,
                                   callback=self.on_check_authtoken)
        elif username and password and device_id:
            self._login_notification = notification_area.notify(
                'Logging in...')
            gp.login_async(username,
                           password,
                           device_id,
                           callback=self.on_login)
        else:
            self._login_notification = notification_area.notify(
                'Please set your credentials on the settings page.')
コード例 #2
0
ファイル: search.py プロジェクト: vale981/clay
 def search_finished(self, results, error):
     """
     Populate song list with search results.
     """
     if error:
         notification_area.notify('Failed to search: {}'.format(str(error)))
     else:
         self.songlist.populate(results.get_tracks())
         self.app.redraw()
コード例 #3
0
 def _download_track(self, url, error, track):
     if error:
         notification_area.notify('Failed to request media URL: {}'.format(
             str(error)))
         logger.error('Failed to request media URL for track %s: %s',
                      track.original_data, str(error))
         return
     response = urlopen(url)
     path = settings.save_file_to_cache(track.filename, response.read())
     self._play_ready(path, None, track)
コード例 #4
0
 def on_remove_from_my_library(result, error):
     """
     Show notification with song removal result.
     """
     if error or not result:
         notification_area.notify(
             'Error while removing track from my library: {}'.format(
                 str(error) if error else 'reason is unknown :('))
     else:
         notification_area.notify('Track removed from library!')
コード例 #5
0
 def on_add_to_my_library(result, error):
     """
     Show notification with song addition result.
     """
     if error or not result:
         notification_area.notify(
             'Error while adding track to my library: {}'.format(
                 str(error) if error else 'reason is unknown :('))
     else:
         notification_area.notify('Track added to library!')
コード例 #6
0
    def on_station_loaded(self, station, error):
        """
        Called when station  tracks  fetch completes.
        Populates songlist with tracks from the selected station.
        """
        if error:
            notification_area.notify('Failed to get station tracks: {}'.format(
                str(error)))

        self.songlist.populate(station.get_tracks())
        self.app.redraw()
コード例 #7
0
ファイル: mylibrary.py プロジェクト: xuhui/clay
 def on_get_all_songs(self, tracks, error):
     """
     Called when all library songs are fetched from server.
     Populate song list.
     """
     if error:
         notification_area.notify('Failed to load my library: {}'.format(
             str(error)))
         return
     tracks.sort(key=lambda k: k.original_data['title'])
     self.songlist.populate(tracks)
     self.app.redraw()
コード例 #8
0
ファイル: clipboard.py プロジェクト: xuhui/clay
def copy(text):
    """
    Copy text to clipboard.

    Return True on success.
    """
    for cmd in COMMANDS:
        proc = Popen(cmd, stdin=PIPE)
        proc.communicate(text.encode('utf-8'))
        if proc.returncode == 0:
            return True

    notification_area.notify(
        'Failed to copy text to clipboard. '
        'Please install "xclip" or "xsel".'
    )
    return False
コード例 #9
0
 def create_station_from_track(self, track):
     """
     Request creation of new station from some track.
     Runs in background.
     """
     self._create_station_notification = notification_area.notify(
         'Creating station...')
     track.create_station_async(
         callback=self._create_station_from_track_ready)
コード例 #10
0
    def _play_ready(self, url, error, track):
        """
        Called once track's media stream URL request completes.
        If *error* is ``None``, tell libVLC to play media by *url*.
        """
        self._is_loading = False
        if error:
            notification_area.notify('Failed to request media URL: {}'.format(
                str(error)))
            logger.error('Failed to request media URL for track %s: %s',
                         track.original_data, str(error))
            return
        assert track
        media = vlc.Media(url)
        self.media_player.set_media(media)

        self.media_player.play()

        osd_manager.notify(track)
コード例 #11
0
    def on_get_stations(self, stations, error):
        """
        Called when a list of stations fetch completes.
        Populates list of stations.
        """
        if error:
            notification_area.notify('Failed to get stations: {}'.format(
                str(error)))

        items = []
        for station in stations:
            mystationlistitem = MyStationListItem(station)
            urwid.connect_signal(mystationlistitem, 'activate',
                                 self.item_activated)
            items.append(mystationlistitem)

        self.walker[:] = items

        self.app.redraw()
コード例 #12
0
ファイル: hotkeys.py プロジェクト: xuhui/clay
    def __init__(self):
        self._x_hotkeys = {}
        self._hotkeys = self._parse_hotkeys()
        self.config = None

        self.play_pause = EventHook()
        self.next = EventHook()
        self.prev = EventHook()

        if IS_INIT:
            Keybinder.init()
            self.initialize()
            threading.Thread(target=Gtk.main).start()
        else:
            logger.debug("Not loading the global shortcuts.")
            notification_area.notify(
                ERROR_MESSAGE +
                ", this means the global shortcuts will not work.\n" +
                "You can check the log for more details.")
コード例 #13
0
ファイル: myplaylists.py プロジェクト: xuhui/clay
    def on_get_playlists(self, playlists, error):
        """
        Called when a list of playlists fetch completes.
        Populates list of playlists.
        """
        if error:
            notification_area.notify('Failed to get playlists: {}'.format(
                str(error)))

        items = []
        for playlist in playlists:
            myplaylistlistitem = MyPlaylistListItem(playlist)
            urwid.connect_signal(myplaylistlistitem, 'activate',
                                 self.item_activated)
            items.append(myplaylistlistitem)

        self.walker[:] = items

        self.app.redraw()
コード例 #14
0
ファイル: osd.py プロジェクト: xuhui/clay
"""
from clay.notifications import notification_area
from clay import meta

IS_INIT = False

try:
    from dbus import SessionBus, Interface
    IS_INIT = True
except ImportError:
    ERROR_MESSAGE = 'Could not import dbus. OSD notifications will be disabled.'
except Exception as exception:  # pylint: disable=broad-except
    ERROR_MESSAGE = 'Error while importing dbus: \'{}\''.format(str(exception))

if not IS_INIT:
    notification_area.notify(ERROR_MESSAGE)


class _OSDManager(object):
    """
    Manages OSD notifications via DBus.
    """
    def __init__(self):
        self._last_id = 0

        if IS_INIT:
            self.bus = SessionBus()
            self.notifcations = self.bus.get_object(
                "org.freedesktop.Notifications",
                "/org/freedesktop/Notifications")
            self.notify_interface = Interface(self.notifcations,