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


Python dbus.SessionBus方法代码示例

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


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

示例1: get_song_info

# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import SessionBus [as 别名]
def get_song_info(player):
    if player == "mpd":
        from mpd import MPDClient
        client = MPDClient()
        client.connect("localhost", 6600)
        song_info = client.currentsong()
        return song_info["artist"], song_info["title"]
    else:
        bus = dbus.SessionBus()
        try:
            proxy = bus.get_object("org.mpris.MediaPlayer2.%s" % player,
                                   "/org/mpris/MediaPlayer2")
        except dbus.exceptions.DBusException:
            print("[ERROR] Player \"%s\" doesn't exist or isn't playing" \
                  % player)
            return

        interface = dbus.Interface(
            proxy, dbus_interface="org.freedesktop.DBus.Properties"
        )
        properties = interface.GetAll("org.mpris.MediaPlayer2.Player")
        metadata = properties["Metadata"]
        artist = str(metadata["xesam:artist"][0])
        title = str(metadata["xesam:title"])
        return artist, title 
开发者ID:kenogo,项目名称:spotify-lyrics-cli,代码行数:27,代码来源:__init__.py

示例2: display3dgraph

# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import SessionBus [as 别名]
def display3dgraph(graph, reset_world=True):
        """Send the graph (produced by buildgraph()) to a running
        rtgraph3d instance.

        """
        dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
        bus = dbus.SessionBus()
        control = bus.get_object("org.secdev.rtgraph3d", "/control")
        graph3d = dbus.Interface(control, "org.secdev.rtgraph3d.command")
        if reset_world:
            graph3d.reset_world()
        for node, node_edges in viewitems(graph):
            for destnode in node_edges:
                if destnode == node:
                    continue
                try:
                    graph3d.new_edge(utils.int2ip(node), {},
                                     utils.int2ip(destnode), {})
                except Exception:
                    utils.LOGGER.warning('Exception', exc_info=True)
        return graph3d 
开发者ID:cea-sec,项目名称:ivre,代码行数:23,代码来源:graphroute.py

示例3: __init__

# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import SessionBus [as 别名]
def __init__(self, desktop_name):
        """
        Creates a SoundMenuControls object.

        Requires a dbus loop to be created before the gtk mainloop,
        typically by calling DBusGMainLoop(set_as_default=True).

        arguments:
        desktop_name: The name of the desktop file for the application,
        such as, "simple-player" to refer to the file: simple-player.desktop.

        """

        self.desktop_name = desktop_name
        bus_str = """org.mpris.MediaPlayer2.%s""" % desktop_name
        bus_name = dbus.service.BusName(bus_str, bus=dbus.SessionBus())
        dbus.service.Object.__init__(self, bus_name, "/org/mpris/MediaPlayer2")
        self.__playback_status = "Stopped"

        self.song_changed() 
开发者ID:atareao,项目名称:lplayer,代码行数:22,代码来源:sound_menu.py

示例4: factory

# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import SessionBus [as 别名]
def factory(type):
        try:
            interface = dbus.Interface(
                dbus.SessionBus().get_object(
                    'org.mpris.MediaPlayer2.spotify',
                    '/org/mpris/MediaPlayer2'
                ),
                type
            )
        except dbus.exceptions.DBusException:
            """
                If we catch this exception, Spotify is not running.
                Let the user know.
            """
            sys.exit(
                "\nSome errors occured. Try restart or start Spotify. Pytify is just a cli application which controls Spotify. So you can't use Pytify without Spotify.\n"
            )

        return interface 
开发者ID:bjarneo,项目名称:Pytify,代码行数:21,代码来源:interface.py

示例5: run_mpris2_server

# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import SessionBus [as 别名]
def run_mpris2_server(app):
    try:
        import dbus
        import dbus.service
        import dbus.mainloop.pyqt5
    except ImportError as e:
        logger.error("can't run mpris2 server: %s",  str(e))
    else:
        from .mpris2 import Mpris2Service, BusName

        # check if a mainloop was already set
        mainloop = dbus.get_default_main_loop()
        if mainloop is not None:
            logger.warn("mpris2 service already enabled? "
                        "maybe you should remove feeluown-mpris2-plugin")
            return

        # set the mainloop before any dbus operation
        dbus.mainloop.pyqt5.DBusQtMainLoop(set_as_default=True)
        session_bus = dbus.SessionBus()
        bus = dbus.service.BusName(BusName, session_bus)
        service = Mpris2Service(app, bus)
        service.enable() 
开发者ID:feeluown,项目名称:FeelUOwn,代码行数:25,代码来源:__init__.py

示例6: priority

# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import SessionBus [as 别名]
def priority(cls):
        if 'dbus' not in globals():
            raise RuntimeError('python-dbus not installed')
        try:
            bus = dbus.SessionBus(mainloop=DBusGMainLoop())
        except dbus.DBusException as exc:
            raise RuntimeError(exc.get_dbus_message())
        try:
            bus.get_object(cls.bus_name, cls.object_path)
        except dbus.DBusException:
            tmpl = 'cannot connect to {bus_name}'
            msg = tmpl.format(bus_name=cls.bus_name)
            raise RuntimeError(msg)
        if "KDE" in os.getenv("XDG_CURRENT_DESKTOP", "").split(":"):
            return 5.1
        return 4.9 
开发者ID:jaraco,项目名称:keyring,代码行数:18,代码来源:kwallet.py

示例7: connected

# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import SessionBus [as 别名]
def connected(self, service):
        if self.handle >= 0:
            if self.iface.isOpen(self.handle):
                return True

        bus = dbus.SessionBus(mainloop=DBusGMainLoop())
        wId = 0
        try:
            remote_obj = bus.get_object(self.bus_name, self.object_path)
            self.iface = dbus.Interface(remote_obj, 'org.kde.KWallet')
            self.handle = self.iface.open(self.iface.networkWallet(), wId, self.appid)
        except dbus.DBusException as e:
            raise InitError('Failed to open keyring: %s.' % e)

        if self.handle < 0:
            return False
        self._migrate(service)
        return True 
开发者ID:jaraco,项目名称:keyring,代码行数:20,代码来源:kwallet.py

示例8: __verifyNotRunning

# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import SessionBus [as 别名]
def __verifyNotRunning(self):
        if os.path.exists(common.LOCK_FILE):
            pid = Application._read_pid_from_lock_file()

            # Check that the found PID is running and is autokey
            with subprocess.Popen(["ps", "-p", pid, "-o", "command"], stdout=subprocess.PIPE) as p:
                output = p.communicate()[0]

            if "autokey" in output.decode():
                logging.debug("AutoKey is already running as pid %s", pid)
                bus = dbus.SessionBus()

                try:
                    dbusService = bus.get_object("org.autokey.Service", "/AppService")
                    dbusService.show_configure(dbus_interface="org.autokey.Service")
                    sys.exit(0)
                except dbus.DBusException as e:
                    logging.exception("Error communicating with Dbus service")
                    self.show_error_dialog(_("AutoKey is already running as pid %s but is not responding") % pid, str(e))
                    sys.exit(1)

        return True 
开发者ID:autokey,项目名称:autokey,代码行数:24,代码来源:gtkapp.py

示例9: __init__

# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import SessionBus [as 别名]
def __init__(self):
    self.ip = (([ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.")] or [[(s.connect(("8.8.8.8", 53)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1]]) + [None])[0]
    with contextlib.closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as s:
      s.bind(('0.0.0.0', 0))
      self.port = s.getsockname()[1]
    self.app = bottle.Bottle()
    self.cast = None
    self.last_known_player_state = None
    self.last_known_current_time = None
    self.last_time_current_time = None
    self.fn = None
    self.video_stream = None
    self.audio_stream = None
    self.last_fn_played = None
    self.transcoder = None
    self.duration = None
    self.subtitles = None
    self.seeking = False
    self.last_known_volume_level = None
    bus = dbus.SessionBus() if DBUS_AVAILABLE else None
    self.saver_interface = find_screensaver_dbus_iface(bus)
    self.inhibit_screensaver_cookie = None
    self.autoplay = False 
开发者ID:keredson,项目名称:gnomecast,代码行数:25,代码来源:gnomecast.py

示例10: __init__

# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import SessionBus [as 别名]
def __init__(self):
        # Load up the DBus
        session_bus = _dbus.SessionBus()
        try:
            self._dbus = session_bus.get_object("org.razer", "/org/razer")
        except _dbus.DBusException:
            raise DaemonNotFound("Could not connect to daemon")

        # Get interface for daemon methods
        self._dbus_daemon = _dbus.Interface(self._dbus, "razer.daemon")

        # Get interface for devices methods
        self._dbus_devices = _dbus.Interface(self._dbus, "razer.devices")

        self._device_serials = self._dbus_devices.getDevices()
        self._devices = []

        self._daemon_version = self._dbus_daemon.version()

        for serial in self._device_serials:
            device = _RazerDeviceFactory.get_device(serial)
            self._devices.append(device) 
开发者ID:openrazer,项目名称:openrazer,代码行数:24,代码来源:__init__.py

示例11: __init__

# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import SessionBus [as 别名]
def __init__(self, serial: str, capabilities: dict, daemon_dbus=None, matrix_dims=(-1, -1)):
        super(RazerAdvancedFX, self).__init__(serial, capabilities, daemon_dbus)

        # Only init'd when there's a matrix
        self._capabilities = capabilities

        if not all([dim >= 1 for dim in matrix_dims]):
            raise ValueError("Matrix dimensions cannot contain -1")

        if daemon_dbus is None:
            session_bus = _dbus.SessionBus()
            daemon_dbus = session_bus.get_object("org.razer", "/org/razer/device/{0}".format(serial))

        self._matrix_dims = matrix_dims
        self._lighting_dbus = _dbus.Interface(daemon_dbus, "razer.device.lighting.chroma")

        self.matrix = Frame(matrix_dims) 
开发者ID:openrazer,项目名称:openrazer,代码行数:19,代码来源:fx.py

示例12: _prepair

# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import SessionBus [as 别名]
def _prepair(self):
        '''Try to connect to the given dbus services. If successful it will
        return a callable dbus proxy and those arguments.
        '''
        try:
            sessionbus = dbus.SessionBus()
            systembus  = dbus.SystemBus()
        except:
            return (None, None)
        for dbus_props in self.DBUS_SHUTDOWN.values():
            try:
                if dbus_props['bus'] == SESSION_BUS:
                    bus = sessionbus
                else:
                    bus = systembus
                interface = bus.get_object(dbus_props['service'],
                                           dbus_props['objectPath'])
                proxy = interface.get_dbus_method(dbus_props['method'],
                                                  dbus_props['interface'])
                return (proxy, dbus_props['arguments'])
            except dbus.exceptions.DBusException:
                continue
        return (None, None) 
开发者ID:XuShaohua,项目名称:bcloud,代码行数:25,代码来源:Shutdown.py

示例13: setwallpaper

# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import SessionBus [as 别名]
def setwallpaper(filepath):
    """
    This script is taken from https://github.com/pashazz/ksetwallpaper/

    All the credit goes to the user for the code, I'm just using it
    to add a functionality to my app.
    """

    jscript = """var allDesktops = desktops();
    for ( i = 0; i < allDesktops.length;i++ ) {
        d = allDesktops[i];
        d.wallpaperPlugin = "org.kde.image";
        d.currentConfigGroup = Array("Wallpaper", "org.kde.image", "General");
        d.writeConfig("Image", "file://%s")
    }
    """
    bus = dbus.SessionBus()
    plasma = dbus.Interface(bus.get_object('org.kde.plasmashell', '/PlasmaShell'), dbus_interface='org.kde.PlasmaShell')
    plasma.evaluateScript(jscript % filepath) 
开发者ID:deepjyoti30,项目名称:QuickWall,代码行数:21,代码来源:kde.py

示例14: restoreWallpaper

# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import SessionBus [as 别名]
def restoreWallpaper():
    """
    Load wallpaper from RestorableImage config
    """
    
    jscript = """var first = desktopForScreen(0);
    first.currentConfigGroup = Array( 'Wallpaper', 'org.kde.image', 'General' );
    var img = first.readConfig('RestorableImage');
    var allDesktops = desktops();
    for ( i = 0; i < allDesktops.length;i++ ) {
        d = allDesktops[i];
        d.wallpaperPlugin = "org.kde.image";
        d.currentConfigGroup = Array("Wallpaper", "org.kde.image", "General");
        d.writeConfig("Image", img)
    }
    """
    bus = dbus.SessionBus()
    plasma = dbus.Interface(bus.get_object('org.kde.plasmashell', '/PlasmaShell'), dbus_interface='org.kde.PlasmaShell')
    plasma.evaluateScript(jscript) 
开发者ID:deepjyoti30,项目名称:QuickWall,代码行数:21,代码来源:kde.py

示例15: __init__

# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import SessionBus [as 别名]
def __init__(self, number=2,
                 logfile=os.path.join(image_tmp, "openscap.log"),
                 onlycache=False,
                 reportdir=image_tmp, workdir=image_tmp):

        self.arg_tup = self.tup(number=number, logfile=logfile,
                                onlycache=onlycache, reportdir=reportdir,
                                workdir=workdir)

        self.arg_dict = {'number': number, 'logfile': logfile,
                         'onlycache': onlycache, 'reportdir': reportdir,
                         'workdir': workdir}
        self._docker_ping()
        self.num_threads = number
        self.bus = dbus.SessionBus()
        self.dbus_object = self.bus.get_object(dbus_utils.BUS_NAME,
                                               dbus_utils.OBJECT_PATH)
        self.logfile = logfile
        self.onlycache = onlycache
        self.reportdir = reportdir
        self.workdir = workdir
        self.onlyactive = False
        self.allcontainers = False
        self.allimages = False
        self.images = False 
开发者ID:OpenSCAP,项目名称:openscap-daemon,代码行数:27,代码来源:scanner_client.py


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