当前位置: 首页>>代码示例>>Python>>正文


Python pydbus.SessionBus类代码示例

本文整理汇总了Python中pydbus.SessionBus的典型用法代码示例。如果您正苦于以下问题:Python SessionBus类的具体用法?Python SessionBus怎么用?Python SessionBus使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SessionBus类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post_config_hook

 def post_config_hook(self):
     if self.user:
         bus = SessionBus()
     else:
         bus = SystemBus()
     systemd = bus.get("org.freedesktop.systemd1")
     self.systemd_unit = bus.get(".systemd1", systemd.LoadUnit(self.unit))
开发者ID:ultrabug,项目名称:py3status,代码行数:7,代码来源:systemd.py

示例2: info

    def info(self):
        tod_time = time.strftime("%a, %d %b %Y %H:%M:%S", 
                                 time.localtime(start_time))
        message_string = ("Wheel circumference: {} meters\n"
                          "Start time: {}\n"
                          "GPIO Channel Number: {}"
                          .format(wheel_circumference, tod_time, channel))

        bus_1 = SessionBus()
        notifications = bus_1.get('.Notifications')
        notifications.Notify('test', 0, 
                             'dialog-information', 
                             "Pydbus Server Information", 
                             message_string, 
                             [], {}, 5000)
开发者ID:HamPUG,项目名称:meetings,代码行数:15,代码来源:server.py

示例3: bus

def bus():
    from pydbus import SessionBus

    bus = SessionBus()
    time.sleep(.5)
    print("\n[initalize] pydbus.SessionBus ...")
    bus.own_name(name="org.scarlett")
    # bus.dbus
    time.sleep(.5)
    yield bus
    print("\n[teardown] pydbus.SessionBus ...")
    # del bus._dbus
    print("ran: del bus._dbus")
    del bus
    print("ran: del bus")
开发者ID:bossjones,项目名称:scarlett_os,代码行数:15,代码来源:test_mpris.py

示例4: _init_dbus

    def _init_dbus(self):
        """
        Get the device id
        """
        _bus = SessionBus()

        if self.device_id is None:
            self.device_id = self._get_device_id(_bus)
            if self.device_id is None:
                return False

        try:
            self._dev = _bus.get(SERVICE_BUS, DEVICE_PATH + "/%s" % self.device_id)
        except Exception:
            return False

        return True
开发者ID:ultrabug,项目名称:py3status,代码行数:17,代码来源:kdeconnector.py

示例5: _connect_to_dbus

 def _connect_to_dbus(self):
     self.bus = SessionBus()
     self.dbus_proxy = self.bus.get("org.scarlett", object_path='/org/scarlett/Listener')  # NOQA
     self.dbus_proxy.emitConnectedToListener('ScarlettListener')
     sleep(2)
     logger.info('_connect_to_dbus')
     ss_cancel_signal = self.bus.subscribe(sender=None,
                                      iface="org.scarlett.Listener",
                                      signal="ListenerCancelSignal",
                                      object="/org/scarlett/Listener",
                                      arg0=None,
                                      flags=0,
                                      signal_fired=self.cancel_listening)
开发者ID:bossjones,项目名称:scarlett-dbus-poc,代码行数:13,代码来源:generator_listener.py

示例6: __init__

    def __init__(self, use_terminal = True,
                 use_libnotify = True,
                 debug = False,
                 device_id = None,
                 device_name = None,
                 ignore = None):
        """
        Get the device id
        """
        self.terminal = use_terminal
        self.libnotify = use_libnotify
        self.debug = debug

        if ignore:
            self.ignore = [app.lower() for app in ignore]

        if not self.terminal:
            self._debug('hide terminal messages')

        if not self.libnotify:
            self._debug('hide notifications')

        if use_libnotify:
            Notify.init('KDEConnect Notify')

        if ignore:
            apps = ignore[0]
            for app in ignore[1:]:
                apps += ', ' + app
            self._debug('ignore ' + apps)

        self._bus = SessionBus()

        if device_id is None:
            self.device_id = self._get_device_id(device_id, device_name)
            if self.device_id is None:
                self._debug('No device id found')
                return
        else:
            self.device_id = device_id

        self._debug('Device id is %s' % self.device_id)
        try:
            self._dev = self._bus.get(SERVICE_BUS,
                                      DEVICE_PATH + '/%s' % self.device_id)
        except Exception:
            self.device_id = None
            return
开发者ID:ritze,项目名称:kdeconnect-notify,代码行数:48,代码来源:kdeconnect-notify.py

示例7: _connect_to_dbus

 def _connect_to_dbus(self):
     self.bus = SessionBus()
     self.dbus_proxy = self.bus.get(
         "org.scarlett", object_path="/org/scarlett/Listener"
     )  # NOQA
     self.dbus_proxy.emitConnectedToListener("ScarlettListener")
     time.sleep(2)
     logger.info("_connect_to_dbus")
     # TODO: Add a ss_cancel_signal.disconnect() function later
     ss_cancel_signal = self.bus.subscribe(
         sender=None,
         iface="org.scarlett.Listener",
         signal="ListenerCancelSignal",
         object="/org/scarlett/Listener",
         arg0=None,
         flags=0,
         signal_fired=self.on_cancel_listening,
     )
开发者ID:bossjones,项目名称:scarlett_os,代码行数:18,代码来源:listener.py

示例8: post_config_hook

 def post_config_hook(self):
     self._dbus = None
     self._data = {}
     self._control_states = {}
     self._kill = False
     self._mpris_players = {}
     self._mpris_names = {}
     self._mpris_name_index = {}
     self._player = None
     self._player_details = {}
     self._tries = 0
     # start last
     self._dbus = SessionBus()
     self._start_listener()
     self._states = {
         'pause': {
             'action': 'Pause',
             'clickable': 'CanPause',
             'icon': self.icon_pause
         },
         'play': {
             'action': 'Play',
             'clickable': 'CanPlay',
             'icon': self.icon_play
         },
         'stop': {
             'action': 'Stop',
             'clickable': 'True',  # The MPRIS API lacks 'CanStop' function.
             'icon': self.icon_stop
         },
         'next': {
             'action': 'Next',
             'clickable': 'CanGoNext',
             'icon': self.icon_next
         },
         'previous': {
             'action': 'Previous',
             'clickable': 'CanGoPrevious',
             'icon': self.icon_previous
         }
     }
开发者ID:mrt-prodz,项目名称:py3status,代码行数:41,代码来源:mpris.py

示例9: post_config_hook

 def post_config_hook(self):
     if self.py3.is_gevent():
         raise Exception(STRING_GEVENT)
     self._dbus = None
     self._data = {}
     self._control_states = {}
     self._kill = False
     self._mpris_players = {}
     self._mpris_names = {}
     self._mpris_name_index = {}
     self._player = None
     self._player_details = {}
     self._tries = 0
     # start last
     self._dbus = SessionBus()
     self._start_listener()
     self._states = {
         "pause": {
             "action": "Pause",
             "clickable": "CanPause",
             "icon": self.icon_pause,
         },
         "play": {"action": "Play", "clickable": "CanPlay", "icon": self.icon_play},
         "stop": {
             "action": "Stop",
             "clickable": "True",  # The MPRIS API lacks 'CanStop' function.
             "icon": self.icon_stop,
         },
         "next": {
             "action": "Next",
             "clickable": "CanGoNext",
             "icon": self.icon_next,
         },
         "previous": {
             "action": "Previous",
             "clickable": "CanGoPrevious",
             "icon": self.icon_previous,
         },
     }
开发者ID:ultrabug,项目名称:py3status,代码行数:39,代码来源:mpris.py

示例10: __init__

    def __init__(self, bucket, loop, *args, **kargs):
        self.bucket = bucket
        self.loop = loop
        self.running = True
        self._stop = threading.Event()
        self.queue = Queue.Queue(10)

        # NOTE: enumerate req to iterate through tuple and find GVariant
        @trace
        def player_cb(*args, **kwargs):
            if SCARLETT_DEBUG:
                logger.debug("player_cb PrettyPrinter: ")
                pp = pprint.PrettyPrinter(indent=4)
                pp.pprint(args)
            for i, v in enumerate(args):
                if SCARLETT_DEBUG:
                    logger.debug("Type v: {}".format(type(v)))
                    logger.debug("Type i: {}".format(type(i)))
                if type(v) is gi.overrides.GLib.Variant:
                    if SCARLETT_DEBUG:
                        logger.debug(
                            "THIS SHOULD BE A Tuple now: {}".format(v))
                    msg, scarlett_sound = v
                    logger.warning(" msg: {}".format(msg))
                    logger.warning(
                        " scarlett_sound: {}".format(scarlett_sound))
                    # NOTE: Create something like test_gdbus_player.ScarlettPlayer('pi-listening')
                    # NOTE: test_gdbus_player.ScarlettPlayer
                    # NOTE: self.bucket.put()
                    # NOTE: ADD self.queue.put(v)

        # NOTE: enumerate req to iterate through tuple and find GVariant
        @trace
        def command_cb(*args, **kwargs):
            if SCARLETT_DEBUG:
                logger.debug("player_cb PrettyPrinter: ")
                pp = pprint.PrettyPrinter(indent=4)
                pp.pprint(args)
            for i, v in enumerate(args):
                if SCARLETT_DEBUG:
                    logger.debug("Type v: {}".format(type(v)))
                    logger.debug("Type i: {}".format(type(i)))
                if type(v) is gi.overrides.GLib.Variant:
                    if SCARLETT_DEBUG:
                        logger.debug(
                            "THIS SHOULD BE A Tuple now: {}".format(v))
                    msg, scarlett_sound, command = v
                    logger.warning(" msg: {}".format(msg))
                    logger.warning(
                        " scarlett_sound: {}".format(scarlett_sound))
                    logger.warning(" command: {}".format(command))
                    # NOTE: Create something like test_gdbus_player.ScarlettPlayer('pi-listening')
                    # NOTE: test_gdbus_player.ScarlettPlayer
                    # NOTE: self.bucket.put()
                    # NOTE: ADD self.queue.put(v)

        # with SessionBus() as bus:
        bus = SessionBus()
        ss = bus.get("org.scarlett", object_path='/org/scarlett/Listener')

        # SttFailedSignal / player_cb
        ss_failed_signal = bus.con.signal_subscribe(None,
                                                    "org.scarlett.Listener",
                                                    "SttFailedSignal",
                                                    '/org/scarlett/Listener',
                                                    None,
                                                    0,
                                                    player_cb)

        # ListenerReadySignal / player_cb
        ss_rdy_signal = bus.con.signal_subscribe(None,
                                                 "org.scarlett.Listener",
                                                 "ListenerReadySignal",
                                                 '/org/scarlett/Listener',
                                                 None,
                                                 0,
                                                 player_cb)

        # KeywordRecognizedSignal / player_cb
        ss_kw_rec_signal = bus.con.signal_subscribe(None,
                                                    "org.scarlett.Listener",
                                                    "KeywordRecognizedSignal",
                                                    '/org/scarlett/Listener',
                                                    None,
                                                    0,
                                                    player_cb)

        # CommandRecognizedSignal /command_cb
        ss_cmd_rec_signal = bus.con.signal_subscribe(None,
                                                     "org.scarlett.Listener",
                                                     "CommandRecognizedSignal",
                                                     '/org/scarlett/Listener',
                                                     None,
                                                     0,
                                                     command_cb)

        # ListenerCancelSignal / player_cb
        ss_cancel_signal = bus.con.signal_subscribe(None,
                                                    "org.scarlett.Listener",
                                                    "ListenerCancelSignal",
#.........这里部分代码省略.........
开发者ID:bossjones,项目名称:scarlett-dbus-poc,代码行数:101,代码来源:run_tasker.py

示例11: SessionBus

#!/usr/bin/python3

import os
import sys
import datetime
import json
import subprocess
from time import sleep
from pydbus import SessionBus
from glob import glob


BUS = SessionBus()
LAYOUT = BUS.get(bus_name='org.way-cooler', object_path='/org/way_cooler/Layout')


def main():
    while True:
        layout = json.loads(LAYOUT.Debug())
        workspaces = get_workspaces(layout)
        workspaces.sort()
        active_workspace = ""
        try:
            active_workspace = LAYOUT.ActiveWorkspace()
        except Exception:
            pass
        workspaces = " ".join(workspaces)
        workspaces = format_workspaces(layout, workspaces, active_workspace)
        funcs = [workspaces + "%{c}",
                 lambda: get_time() + "%{r}",
                 my_get_temp,
开发者ID:matejc,项目名称:helper_scripts,代码行数:31,代码来源:bar.py

示例12: __init__

class Py3status:
    """
    """
    # available configuration parameters
    button_next = 4
    button_previous = 5
    button_stop = None
    button_toggle = 1
    format = '{previous}{toggle}{next} {state} [{artist} - ][{title}]'
    format_none = 'no player running'
    icon_next = u'»'
    icon_pause = u'▮'
    icon_play = u'▶'
    icon_previous = u'«'
    icon_stop = u'◾'
    player_priority = []
    state_pause = u'▮'
    state_play = u'▶'
    state_stop = u'◾'

    def __init__(self):
        self._dbus = None
        self._data = {}
        self._kill = False
        self._mpris_players = {}
        self._mpris_names = {}
        self._mpris_name_index = {}
        self._player = None
        self._player_details = {}
        self._tries = 0

    def post_config_hook(self):
        self._dbus = SessionBus()
        self._start_listener()

    def _init_data(self):
        self._data = {
            'album': None,
            'artist': None,
            'error_occurred': False,
            'length': None,
            'player': None,
            'state': STOPPED,
            'title': None
        }

        if self._player is None:
            return

        try:
            self._data['player'] = self._player.Identity
            playback_status = self._player.PlaybackStatus
            self._data['state'] = self._get_state(playback_status)
            metadata = self._player.Metadata
            self._update_metadata(metadata)
        except Exception:
            self._data['error_occurred'] = True

    def _get_button_state(self, control_state):
        try:
            # Workaround: The last parameter returns True for the Stop button.
            clickable = getattr(self._player, control_state['clickable'], True)
        except Exception:
            clickable = False

        state = self._data.get('state')
        if control_state['action'] == 'Play' and state == PLAYING:
            clickable = False
        elif control_state['action'] == 'Pause' and state in [STOPPED, PAUSED]:
            clickable = False
        elif control_state['action'] == 'Stop' and state == STOPPED:
            clickable = False

        return clickable

    def _get_state(self, playback_status):
        if playback_status == 'Playing':
            return PLAYING
        elif playback_status == 'Paused':
            return PAUSED
        else:
            return STOPPED

    def _get_text(self):
        """
        Get the current metadata
        """
        if self._data.get('state') == PLAYING:
            color = self.py3.COLOR_PLAYING or self.py3.COLOR_GOOD
            state_symbol = self.state_play
        elif self._data.get('state') == PAUSED:
            color = self.py3.COLOR_PAUSED or self.py3.COLOR_DEGRADED
            state_symbol = self.state_pause
        else:
            color = self.py3.COLOR_STOPPED or self.py3.COLOR_BAD
            state_symbol = self.state_stop

        if self._data.get('error_occurred'):
            color = self.py3.COLOR_BAD

#.........这里部分代码省略.........
开发者ID:Andrwe,项目名称:py3status,代码行数:101,代码来源:mpris.py

示例13: SessionBus

#!/usr/bin/env python

# Based on http://stackoverflow.com/questions/22390064/use-dbus-to-just-send-a-message-in-python

# Python script to call the methods of the DBUS Test Server

from pydbus import SessionBus

#get the session bus
bus = SessionBus()
#get the object
the_object = bus.get("net.lew21.pydbus.ClientServerExample")

#call the methods and print the results
reply = the_object.Hello()
print(reply)

reply = the_object.EchoString("test 123")
print(reply)

the_object.Quit()
开发者ID:LEW21,项目名称:pydbus,代码行数:21,代码来源:client.py

示例14: sleep

from __future__ import print_function
from pydbus import SessionBus
from gi.repository import GLib
import subprocess
from time import sleep

loop = GLib.MainLoop()

subprocess.Popen("gnome-music")
sleep(5)
print("Waiting for GNOME Music to start...")

b = SessionBus()
m = b.get("org.mpris.MediaPlayer2.GnomeMusic", "/org/mpris/MediaPlayer2")

m.PropertiesChanged.connect(print)

m.ActivatePlaylist(m.GetPlaylists(0, 5, "Alphabetical", 0)[0][0])

m.Play()
sleep(1)
assert(m.PlaybackStatus == "Playing")

m.Pause()
assert(m.PlaybackStatus == "Paused")

m.Play()
assert(m.PlaybackStatus == "Playing")

t = m.Metadata["xesam:title"]
开发者ID:LEW21,项目名称:pydbus,代码行数:30,代码来源:gnome_music.py

示例15: Mpvplayer

from playthread import Mpvplayer

loop = GLib.MainLoop()
player = Mpvplayer()
player.start()

class DBUSPlayerService(object):
    """
        <node>
            <interface name='github.zhangn1985.dbplay'>
                <method name='play'>
                    <arg type='s' name='playinfo' direction='in'/>
                </method>
				<method name='stop'/>
				<method name='exit'/>
            </interface>
        </node>
    """

    def play(self, playinfo):
        player.play(playinfo)
    def stop(self):
        player.stop()
    def exit(self):
        player.exit()
        loop.quit()

bus = SessionBus()
bus.publish("github.zhangn1985.dbplay", DBUSPlayerService())
loop.run()
开发者ID:wwqgtxx,项目名称:ykdl,代码行数:30,代码来源:dbusplayer.py


注:本文中的pydbus.SessionBus类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。