Exemplo n.º 1
0
    def _get_available_implementation():
        macos_version, *_ = platform.mac_ver()

        if platform.system() == 'Darwin':
            if IS_MACOS_BUNDLE and Version(macos_version) >= Version(
                    '10.14.0'):
                # UNUserNotificationCenter is only supported from signed app bundles
                return SupportedImplementations.notification_center
            elif Version(macos_version) < Version('10.16.0'):
                # deprecated but still works
                return SupportedImplementations.legacy_notification_center
            elif shutil.which('osascript'):
                # fallback
                return SupportedImplementations.osascript
        elif platform.system() == 'Linux':
            try:
                connection = connect_and_authenticate(bus='SESSION')
                proxy = Proxy(FreedesktopNotifications(), connection)
                notification_server_info = proxy.GetServerInformation()
                connection.close()
            except Exception:
                notification_server_info = None

            if notification_server_info:
                return SupportedImplementations.freedesktop_dbus
            elif shutil.which('notify-send'):
                return SupportedImplementations.notify_send

        return SupportedImplementations.stdout
Exemplo n.º 2
0
 def handleTrackListChange(self, data):
     "Callback for when we receive a NameOwnerChanged signal"
     invalidated = data[2]
     if "Tracks" in invalidated:
         print("Track list changed\n")
         tracklist_bus = Proxy(TrackListProperties(), self.connection)
         tracks = tracklist_bus.Tracks()
         for track in tracklist_bus.GetTracksMetadata(tracks):
             print(parseTrackMetadata(track))
def check_service_availability(connection: DBusConnection) -> bool:
    """Returns True if the Security Service daemon is either running or
	available for activation via D-Bus, False otherwise.

	.. versionadded:: 3.2
	"""
    from secretstorage.util import BUS_NAME
    proxy = Proxy(message_bus, connection)
    return (proxy.NameHasOwner(BUS_NAME)[0] == 1
            or BUS_NAME in proxy.ListActivatableNames()[0])
Exemplo n.º 4
0
 def handleSignal(self, data):
     interface, changed, invalidated = data
     print("Interface: {}, Changed: {}, Invalidated: {}".format(
         interface, changed, invalidated))
     if "Tracks" in invalidated:
         tracklist_bus = Proxy(TrackList(), self.connection)
         tracks = tracklist_bus.GetTracksMetadata([
             "/org/videolan/vlc/playlist/10", "/org/videolan/vlc/playlist/9"
         ])
         metadata = []
         for track in tracks[0]:
             t = parseTrackMetadata(track)
             print(repr(t))
             metadata.append(t)
Exemplo n.º 5
0
class DesktopNotifierFreedesktopDBus(DesktopNotifierBase):
    """DBus notification backend for Linux. This implements the
    org.freedesktop.Notifications standard."""
    def __init__(self, app_name):
        super().__init__(app_name)
        connection = connect_and_authenticate(bus='SESSION')
        self.proxy = Proxy(FreedesktopNotifications(), connection)
        self._past_notification_ids = deque([0] * self.notification_limit)

    def send(self,
             title,
             message,
             urgency=DesktopNotifierBase.NORMAL,
             icon_path=None):

        replace_id = self._past_notification_ids.popleft()

        resp = self.proxy.Notify(
            self.app_name,
            replace_id,
            APP_ICON_PATH,
            title,
            message,
            [],  # Actions
            {},  # Hints
            -1,  # expire_timeout (-1 = default)
        )

        self._past_notification_ids.append(resp[0])
Exemplo n.º 6
0
    def __init__(self, connection):
        self.connection = connection
        # Object to interact with D-Bus daemon
        session_bus = Proxy(message_bus, connection)

        # Register signals matching the specified criteria
        rule = TrackAdded()

        success = session_bus.AddMatch(rule) == ()
        if not success:
            raise RuntimeError("Could not register matching rule")

        # Register callback for tracklist changes
        connection.router.subscribe_signal(
            path="/org/mpris/MediaPlayer2",
            interface="org.freedesktop.DBus.Properties",
            member="PropertiesChanged",
            callback=partial(self.handleTrackListChange),
        )
Exemplo n.º 7
0
#!/usr/bin/python3
from jeepney.integrate.blocking import connect_and_authenticate, Proxy

from jukebox.dbus.org_mpris_MediaPlayer2 import Player

with connect_and_authenticate(bus="SESSION") as connection:
    player = Proxy(Player(), connection)
    player.Next()

Exemplo n.º 8
0
 def __init__(self, app_name):
     super().__init__(app_name)
     connection = connect_and_authenticate(bus='SESSION')
     self.proxy = Proxy(FreedesktopNotifications(), connection)
     self._past_notification_ids = deque([0] * self.notification_limit)
Exemplo n.º 9
0
#!/usr/bin/python3

from jeepney.integrate.blocking import Proxy
from jukebox.dbus.org_mpris_MediaPlayer2 import Player, TrackList
from jukebox.dbus.properties import PlayerProperties, TrackListProperties
from jukebox.server.search import YouTubeFinder
from jukebox.server.status import PlayerListener, PlayStatusListener, TrackListListener

# Talk with DBus daemon itself
from jeepney.integrate.blocking import connect_and_authenticate

try:
    with connect_and_authenticate(bus="SESSION") as connection:
        tracklistProperties = Proxy(TrackListProperties(), connection)
        tracks = tracklistProperties.Tracks()[0]
        print(tracks)

        # matcher = PlayerListener(connection)
        matcher = PlayStatusListener(connection)
        # matcher = TrackListListener(connection)
        while True:
            connection.recv_messages()
except KeyboardInterrupt:
    pass