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


Python SessionBus.get_object方法代码示例

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


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

示例1: DBusMediaKeyListener

# 需要导入模块: from dbus import SessionBus [as 别名]
# 或者: from dbus.SessionBus import get_object [as 别名]
class DBusMediaKeyListener(object):
    '''Listen on DBus for media-key events.'''

    def __init__(self, callback=None):
        self._subscribers = []
        self.app = APP_NAME
        self.bus = SessionBus()
        self.bus_object = self.bus.get_object(
            'org.gnome.SettingsDaemon', '/org/gnome/SettingsDaemon/MediaKeys')
        self.bus_object.GrabMediaPlayerKeys(
            self.app, 0, dbus_interface='org.gnome.SettingsDaemon.MediaKeys')
        self.bus_object.connect_to_signal(
            'MediaPlayerKeyPressed', self._notify)
        if callback:
            self.subscribe(callback)

    def _notify(self, application, *mmkeys):
        for subscriber in self._subscribers:
            subscriber(mmkeys)

    def subscribe(self, callback):
        self._subscribers.append(callback)

    def unsubscribe(self, callback):
        self._subscribers.remove(callback)
开发者ID:adiroiban,项目名称:keysocket,代码行数:27,代码来源:websocket_keylogger_dbus.py

示例2: nh_side_command_process

# 需要导入模块: from dbus import SessionBus [as 别名]
# 或者: from dbus.SessionBus import get_object [as 别名]
def nh_side_command_process():
    """
    Execute command (clear screen or exit) on NH.

    :return: [no return value]
    """

    bus = SessionBus()
    obj = bus.get_object("im.pidgin.purple.PurpleService",
                         "/im/pidgin/purple/PurpleObject")
    purple = Interface(obj, "im.pidgin.purple.PurpleInterface")
    account = purple.PurpleAccountsGetAllActive()[0]

    while True:
        if nh_side_command.empty():
            sleep(0.001)
            continue

        cmd = nh_side_command.get()

        if cmd.startswith("TFC|N|%s|U|CLEAR|" % int_version):
            contact = cmd.split('|')[5]
            new_conv = purple.PurpleConversationNew(1, account, contact)
            purple.PurpleConversationClearMessageHistory(new_conv)
            system("clear")
开发者ID:regina-book,项目名称:tfc-nacl,代码行数:27,代码来源:NH.py

示例3: Vibra_Plugin

# 需要导入模块: from dbus import SessionBus [as 别名]
# 或者: from dbus.SessionBus import get_object [as 别名]
class Vibra_Plugin(Plugin):
    def __init__(self):
        DBusGMainLoop(set_as_default=True)

        self.bus = SystemBus()
        self.sessionbus = SessionBus()
        try:
            self.mce = self.bus.get_object("com.nokia.mce", "/com/nokia/mce")
        except DBusException:
            warning("Nokia MCE not found. Vibra is disabled\n")
            return

        self.profiled = self.sessionbus.get_object("com.nokia.profiled", "/com/nokia/profiled")

        self.sessionbus.add_signal_receiver(
            self.profile_changed_handler,
            "profile_changed",
            "com.nokia.profiled",
            "com.nokia.profiled",
            "/com/nokia/profiled",
        )

        profile = self.profiled.get_profile(dbus_interface="com.nokia.profiled")
        self.get_vibra_enabled(profile)

        self.register_plugin(PLUGIN_TYPE_VIBRA)

    def ready(self):
        self.notification = get_plugin_by_type(PLUGIN_TYPE_NOTIFICATION)

        sendfile = get_plugin_by_type(PLUGIN_TYPE_SEND_FILE)
        sendfile.receive_cb.append(self.file_receive)

    def get_vibra_enabled(self, profile):
        self.enabled = (
            self.profiled.get_value(profile, "vibrating.alert.enabled", dbus_interface="com.nokia.profiled") == "On"
        )
        debug("Vibra enabled: %s\n" % self.enabled)

    def profile_changed_handler(self, foo, bar, profile, *args):
        self.get_vibra_enabled(profile)

    def vibrate(self):
        if self.enabled:
            self.mce.req_vibrator_pattern_activate("PatternChatAndEmail", dbus_interface="com.nokia.mce.request")

    def file_receive(self, cb, user, fname):
        self.vibrate()

    def user_appears(self, user):
        if user.get("friend"):
            self.vibrate()
开发者ID:proximate,项目名称:proximate,代码行数:54,代码来源:vibra.py

示例4: Audiobox

# 需要导入模块: from dbus import SessionBus [as 别名]
# 或者: from dbus.SessionBus import get_object [as 别名]
class Audiobox():
    """Audiobox class"""
    def __init__(self):
        self.bus = SessionBus()
        self.init()

    def init(self):
        self.proxy_obj = self.bus.get_object(vim.eval('g:audiobox_dbus_dest'),
                                             vim.eval('g:audiobox_dbus_path'))
        self.player = Interface(self.proxy_obj, vim.eval('g:audiobox_dbus_interface'))
        self.properties = Interface(self.proxy_obj, vim.eval('g:audiobox_dbus_properties_interface'))

    def Play(self):
        """Play current song"""
        if self.player:
            self.player.Play()

    def Pause(self):
        """Pause current song"""
        if self.player:
            self.player.Pause()

    def Next(self):
        """Play the next song"""
        if self.player:
            self.player.Next()

    def Prev(self):
        """Play the previous song"""
        if self.player:
            self.player.Previous()

    def PlayPause(self):
        """Play / Pause the current song"""
        if self.player:
            self.player.PlayPause()

    def Stop(self):
        """Stop the current song"""
        if self.player:
            self.player.Stop()

    def GetCurrentSong(self):
        """Get the title of the current song"""
        if self.properties:
            metadata = self.properties.Get(vim.eval('g:audiobox_dbus_interface'), 'Metadata')
            if len(metadata) > 0:
                vim.command("echohl String | echom \"" + ("Song: %s, Artist: %s, Album: %s"
                    % (str(metadata['xesam:title']),
                        str(metadata['xesam:artist'][0]),
                        str(metadata['xesam:album']))) + "\" | echohl None")
开发者ID:dhruvasagar,项目名称:vim-audiobox,代码行数:53,代码来源:audiobox.py

示例5: run_client

# 需要导入模块: from dbus import SessionBus [as 别名]
# 或者: from dbus.SessionBus import get_object [as 别名]
    def run_client(self):
        bus = SessionBus()
        obj = bus.get_object(CROSS_TEST_BUS_NAME, CROSS_TEST_PATH)
        self.obj = obj

        self.run_synchronous_tests(obj)

        # Signal tests
        logger.info("Binding signal handler for Triggered")
        # FIXME: doesn't seem to work when going via the Interface method
        # FIXME: should be possible to ask the proxy object for its
        # bus name
        bus.add_signal_receiver(self.triggered_cb, 'Triggered',
                                INTERFACE_SIGNAL_TESTS,
                                CROSS_TEST_BUS_NAME,
                                path_keyword='sender_path')
        logger.info("method/signal: Triggering signal")
        self.expected.add('%s.Trigger' % INTERFACE_TESTS)
        Interface(obj, INTERFACE_TESTS).Trigger(u'/Where/Ever', dbus.UInt64(42), reply_handler=self.trigger_returned_cb, error_handler=self.trigger_error_handler)
开发者ID:tizenorg,项目名称:external.dbus-python,代码行数:21,代码来源:cross-test-client.py

示例6: header_printer_process

# 需要导入模块: from dbus import SessionBus [as 别名]
# 或者: from dbus.SessionBus import get_object [as 别名]
def header_printer_process():
    """
    Print NH.py headers.

    :return: [no return value]
    """

    try:
        bus = SessionBus()
        obj = bus.get_object("im.pidgin.purple.PurpleService",
                             "/im/pidgin/purple/PurpleObject")
        purple = Interface(obj, "im.pidgin.purple.PurpleInterface")
        active = purple.PurpleAccountsGetAllActive()[0]
        acco_u = purple.PurpleAccountGetUsername(active)[:-1]

        print("TFC-NaCl %s | NH.py\n" % str_version)
        print("Active account: %s\n" % acco_u)

    except DBusException:
        raise CriticalError("header_printer_process", "DBusException. Ensure "
                                                      "Pidgin is running.")
开发者ID:regina-book,项目名称:tfc-nacl,代码行数:23,代码来源:NH.py

示例7: queue_to_pidgin_process

# 需要导入模块: from dbus import SessionBus [as 别名]
# 或者: from dbus.SessionBus import get_object [as 别名]
def queue_to_pidgin_process():
    """
    Send message from queue to Pidgin.

    :return: [no return value]
    """

    bus = SessionBus()
    obj = bus.get_object("im.pidgin.purple.PurpleService",
                         "/im/pidgin/purple/PurpleObject")
    purple = Interface(obj, "im.pidgin.purple.PurpleInterface")
    account = purple.PurpleAccountsGetAllActive()[0]

    while True:
        if message_to_pidgin.empty():
            sleep(0.001)
            continue

        message = message_to_pidgin.get()

        if message.startswith("TFC|N|%s|M|" % int_version):
            tfc, model, ver, pt, ct, key_id, recipient = message.split('|')
            to_pidgin = '|'.join(message.split('|')[:6])

            if output_pidgin:
                new_conv = purple.PurpleConversationNew(1, account, recipient)
                sel_conv = purple.PurpleConvIm(new_conv)
                purple.PurpleConvImSend(sel_conv, to_pidgin)

        if message.startswith("TFC|N|%s|P|" % int_version):
            tfc, model, ver, pt, pub_key, recipient = message.split('|')
            to_pidgin = '|'.join(message.split('|')[:5])

            if output_pidgin:
                new_conv = purple.PurpleConversationNew(1, account, recipient)
                sel_conv = purple.PurpleConvIm(new_conv)
                purple.PurpleConvImSend(sel_conv, to_pidgin)
开发者ID:regina-book,项目名称:tfc-nacl,代码行数:39,代码来源:NH.py

示例8: __init__

# 需要导入模块: from dbus import SessionBus [as 别名]
# 或者: from dbus.SessionBus import get_object [as 别名]
 def __init__(self):
     session_bus = SessionBus()
     self.player_engine = session_bus.get_object(self.BANSHEE_OBJECT, self.PLAYER_ENGINE_NODE)
开发者ID:BlazerJenzo,项目名称:BlazerJenzo.NET,代码行数:5,代码来源:banshee_xchat.py

示例9: SystemTrayApp

# 需要导入模块: from dbus import SessionBus [as 别名]
# 或者: from dbus.SessionBus import get_object [as 别名]
class SystemTrayApp(QApplication):
    def __init__(self, args, read_pipe):
        QApplication.__init__(self, args)

        self.menu = None
        self.read_pipe = read_pipe
        self.fmt = "80s80sI32sI80sf"
        self.fmt_size = struct.calcsize(self.fmt)
        self.timer_active = False
        self.active_icon = False
        self.user_settings = UserSettings()
        self.user_settings.load()
        self.user_settings.debug()

        self.tray_icon = QSystemTrayIcon()

        pm = load_pixmap("hp_logo", "32x32")
        self.prop_icon = QIcon(pm)

        a = load_pixmap('active', '16x16')
        painter = QPainter(pm)
        painter.drawPixmap(32, 0, a)
        painter.end()

        self.prop_active_icon = QIcon(pm)

        self.tray_icon.setIcon(self.prop_icon)

        self.session_bus = SessionBus()
        self.service = None

        for d in device.getSupportedCUPSDevices(back_end_filter=['hp', 'hpfax']):
            self.addDevice(d)

        self.tray_icon.setToolTip(self.__tr("HPLIP Status Service"))
        QObject.connect(self.tray_icon, SIGNAL("messageClicked()"), self.messageClicked)
        notifier = QSocketNotifier(self.read_pipe, QSocketNotifier.Read)
        QObject.connect(notifier, SIGNAL("activated(int)"), self.notifierActivated)
        QObject.connect(self.tray_icon, SIGNAL("activated(QSystemTrayIcon::ActivationReason)"), self.trayActivated)
        self.tray_icon.show()

        if self.user_settings.systray_visible == SYSTRAY_VISIBLE_SHOW_ALWAYS:
            self.tray_icon.setVisible(True)
        else:
            QTimer.singleShot(HIDE_INACTIVE_DELAY, self.timeoutHideWhenInactive) # show icon for awhile @ startup

        self.tray_icon.setIcon(self.prop_active_icon)
        self.active_icon = True

        QTimer.singleShot(SET_MENU_DELAY, self.initDone)


    def initDone(self):
        self.tray_icon.setIcon(self.prop_icon)
        self.active_icon = False

        self.setMenu()


    def addDevice(self, device_uri):
        try:
            devices[device_uri]
        except KeyError:
            devices[device_uri] = HistoryDevice(device_uri)
        else:
            devices[device_uri].needs_update = True



    def setMenu(self):
        self.menu = QMenu()

        title = QAction(self.menu)
        #title.setDisabled(True)
        title.setText(self.__tr("HPLIP Status Service"))
        title.setIcon(self.prop_icon)
        title.setIconVisibleInMenu(True)
        self.menu.insertAction(None, title)

        if devices:
            if self.service is None:
                t = 0
                while t < 3:
                    try:
                        self.service = self.session_bus.get_object('com.hplip.StatusService',
                                                                  "/com/hplip/StatusService")
                    except DBusException:
                        log.warn("Unable to connect to StatusService. Retrying...")

                    t += 1
                    time.sleep(0.5)

            if self.service is not None:
                self.menu.addSeparator()

                for d in devices:
                    devices[d].getHistory(self.service)

                    menu = DeviceMenu(devices[d].menu_text, self.menu, d, devices[d].history, devices[d].index)
                    self.menu.addMenu(menu)
#.........这里部分代码省略.........
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:103,代码来源:systemtray.py

示例10: _ISkypeAPI

# 需要导入模块: from dbus import SessionBus [as 别名]
# 或者: from dbus.SessionBus import get_object [as 别名]
class _ISkypeAPI(_ISkypeAPIBase):
    def __init__(self, handler, opts):
        _ISkypeAPIBase.__init__(self, opts)
        self.RegisterHandler(handler)
        self.skype_in = self.skype_out = self.dbus_name_owner_watch = None
        self.bus = opts.pop('Bus', None)
        try:
            mainloop = opts.pop('MainLoop')
            if self.bus is not None:
                raise TypeError('Bus and MainLoop cannot be used at the same time!')
        except KeyError:
            if self.bus is None:
                import dbus.mainloop.glib
                import gobject
                gobject.threads_init()
                dbus.mainloop.glib.threads_init()
                mainloop = dbus.mainloop.glib.DBusGMainLoop()
                self.mainloop = gobject.MainLoop()
        if self.bus is None:
            from dbus import SessionBus
            self.bus = SessionBus(private=True, mainloop=mainloop)
        if opts:
            raise TypeError('Unexpected parameter(s): %s' % ', '.join(opts.keys()))

    def run(self):
        self.DebugPrint('thread started')
        if hasattr(self, 'mainloop'):
            self.mainloop.run()
        self.DebugPrint('thread finished')

    def Close(self):
        if hasattr(self, 'mainloop'):
            self.mainloop.quit()
        self.skype_in = self.skype_out = None
        if self.dbus_name_owner_watch is not None:
            self.bus.remove_signal_receiver(self.dbus_name_owner_watch)
        self.dbus_name_owner_watch = None
        self.DebugPrint('closed')

    def SetFriendlyName(self, FriendlyName):
        self.FriendlyName = FriendlyName
        if self.skype_out:
            self.SendCommand(ICommand(-1, 'NAME %s' % FriendlyName))

    def StartWatcher(self):
        self.dbus_name_owner_watch = self.bus.add_signal_receiver(self.dbus_name_owner_changed,
            'NameOwnerChanged',
            'org.freedesktop.DBus',
            'org.freedesktop.DBus',
            '/org/freedesktop/DBus',
            arg0='com.Skype.API')

    def __Attach_ftimeout(self):
        self.wait = False

    def Attach(self, Timeout=30000, Wait=True):
        try:
            if not self.isAlive():
                self.StartWatcher()
                self.start()
        except AssertionError:
            pass
        try:
            self.wait = True
            t = threading.Timer(Timeout / 1000.0, self.__Attach_ftimeout)
            if Wait:
                t.start()
            while self.wait:
                if not Wait:
                    self.wait = False
                try:
                    if not self.skype_out:
                        self.skype_out = self.bus.get_object('com.Skype.API', '/com/Skype')
                    if not self.skype_in:
                        self.skype_in = _SkypeNotifyCallback(self.bus, self.notify)
                except dbus.DBusException:
                    if not Wait:
                        break
                    time.sleep(1.0)
                else:
                    break
            else:
                raise ISkypeAPIError('Skype attach timeout')
        finally:
            t.cancel()
        c = ICommand(-1, 'NAME %s' % self.FriendlyName, '', True, Timeout)
        if self.skype_out:
            self.SendCommand(c)
        if c.Reply != 'OK':
            self.skype_out = None
            self.SetAttachmentStatus(apiAttachRefused)
            return
        self.SendCommand(ICommand(-1, 'PROTOCOL %s' % self.Protocol))
        self.SetAttachmentStatus(apiAttachSuccess)

    def IsRunning(self):
        try:
            self.bus.get_object('com.Skype.API', '/com/Skype')
            return True
        except dbus.DBusException:
#.........这里部分代码省略.........
开发者ID:brianhlin,项目名称:htcondor,代码行数:103,代码来源:posix_dbus.py

示例11: SessionBus

# 需要导入模块: from dbus import SessionBus [as 别名]
# 或者: from dbus.SessionBus import get_object [as 别名]
# -*- coding: utf-8 -*-
from os import environ
from os.path import join, expanduser
from dbus import SessionBus, Interface, glib
from xdg.BaseDirectory import xdg_config_home, xdg_data_home
SCRIBES_DBUS_SERVICE = "net.sourceforge.Scribes"
SCRIBES_DBUS_PATH = "/net/sourceforge/Scribes"
SCRIBES_SAVE_PROCESS_DBUS_SERVICE = "net.sourceforge.ScribesSaveProcess"
SCRIBES_SAVE_PROCESS_DBUS_PATH = "/net/sourceforge/ScribesSaveProcess"
session_bus = SessionBus()
dbus_proxy_obj = session_bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus')
dbus_iface = Interface(dbus_proxy_obj, 'org.freedesktop.DBus')
home_folder = expanduser("~")
from tempfile import gettempdir
tmp_folder = gettempdir()
folder_ = join(home_folder, "Desktop")
from os.path import exists
desktop_folder = folder_ if exists(folder_) else home_folder
metadata_folder = config_folder = join(xdg_config_home, "scribes")
print_settings_filename = join(metadata_folder, "ScribesPrintSettings.txt")
home_plugin_folder = home_generic_plugin_folder = join(config_folder, "GenericPlugins")
home_language_plugin_folder = join(config_folder, "LanguagePlugins")
scribes_theme_folder = join(config_folder, "styles")
storage_folder = join(config_folder, ".config")
default_home_theme_folder = join(xdg_data_home, "gtksourceview-2.0", "styles")
name = "scribes"
prefix = "/usr"
executable_path = join(prefix, "bin")
data_path = "/usr/share"
library_path = "/usr/lib"
sysconfdir = "/usr/etc"
开发者ID:mystilleef,项目名称:scribes,代码行数:33,代码来源:Globals.py

示例12: ArgumentParser

# 需要导入模块: from dbus import SessionBus [as 别名]
# 或者: from dbus.SessionBus import get_object [as 别名]
#!/usr/bin/env python3

from argparse import ArgumentParser

from dbus import Interface, SessionBus

parser = ArgumentParser(description='wrapper DBus pour Spotify')
parser.add_argument('action', nargs=1, choices=['play', 'pause', 'playpause', 'next', 'previous'])
action = parser.parse_args().action[0]

bus = SessionBus()
proxy = bus.get_object('org.mpris.MediaPlayer2.spotify', '/org/mpris/MediaPlayer2')
interface = Interface(proxy, dbus_interface='org.mpris.MediaPlayer2.Player')

if action in ['pause', 'play']:  # Workaround spotify’s bad implementation of Play…
    interface.Pause()
if action in ['playpause', 'play']:
    interface.PlayPause()
elif action == 'next':
    interface.Next()
elif action == 'previous':
    interface.Previous()
开发者ID:nim65s,项目名称:scripts,代码行数:24,代码来源:spotify.py

示例13: SystemTrayApp

# 需要导入模块: from dbus import SessionBus [as 别名]
# 或者: from dbus.SessionBus import get_object [as 别名]

#.........这里部分代码省略.........
    def setMenu(self):
        self.menu = QMenu()

        title = QWidgetAction(self.menu)
        #title.setDisabled(True)

        hbox = QFrame(self.menu)
        layout = QHBoxLayout(hbox)
        layout.setMargin(3)
        layout.setSpacing(5)
        pix_label = QLabel(hbox)

        layout.insertWidget(-1, pix_label, 0)

        icon_size = self.menu.style().pixelMetric(QStyle.PM_SmallIconSize)
        pix_label.setPixmap(self.prop_icon.pixmap(icon_size))

        label = QLabel(hbox)
        layout.insertWidget(-1, label, 20)
        title.setDefaultWidget(hbox)

        label.setText(self.__tr("HPLIP Status Service"))

        f = label.font()
        f.setBold(True)
        label.setFont(f)
        self.menu.insertAction(None, title)

        if devices:
            if self.service is None:
                t = 0
                while t < 3:
                    try:
                        self.service = self.session_bus.get_object('com.hplip.StatusService',
                                                                  "/com/hplip/StatusService")
                    except dbus.DBusException:
                        log.warn("Unable to connect to StatusService. Retrying...")

                    t += 1
                    time.sleep(0.5)

            if self.service is not None:
                self.menu.addSeparator()

                for d in devices:
                    devices[d].getHistory(self.service)

                    menu = DeviceMenu(devices[d].menu_text, self.menu, d, devices[d].history, devices[d].index)
                    self.menu.addMenu(menu)
                    menu.update()


        self.menu.addSeparator()
        self.menu.addAction(self.__tr("HP Device Manager..."), self.toolboxTriggered)

        self.menu.addSeparator()

        self.settings_action = self.menu.addAction(QIcon(load_pixmap('settings', '16x16')),
                                    self.__tr("Settings..."),  self.settingsTriggered)

        self.menu.addSeparator()
        self.menu.addAction(QIcon(load_pixmap('quit', '16x16')), "Quit", self.quitTriggered)
        self.tray_icon.setContextMenu(self.menu)


开发者ID:csteacherd22,项目名称:hplip,代码行数:67,代码来源:systemtray.py

示例14: Client

# 需要导入模块: from dbus import SessionBus [as 别名]
# 或者: from dbus.SessionBus import get_object [as 别名]
class Client(GObject):
    (STATE_INITIALIZED,
     STATE_STATIONS_LOADED,
     STATE_CHANNELS_LOADED) = range(3)

    __gtype_name__ = 'WebRadioClient'

    __gsignals__ = {
        'station-added':       (SIGNAL_RUN_LAST, TYPE_NONE, (object,)),
        'channel-added':       (SIGNAL_RUN_LAST, TYPE_NONE, (object,)),
        'state-changed':       (SIGNAL_RUN_LAST, TYPE_NONE, ()),
        'stream-tags-changed': (SIGNAL_RUN_LAST, TYPE_NONE, ()),
    }

    @staticmethod
    def decode_stream(uri, title, length):
        return Stream(uri, title, length)

    @classmethod
    def decode_channel(cls, station, uri, tags, streams):
        streams = [cls.decode_stream(*s) for s in streams]
        return Channel(station, uri, tags, streams)

    def __init__(self):
        super(Client, self).__init__()

        self.__stations = dict()
        self.__channels = dict()
        self.__stream_tags = dict()

        self.__current_channel = None
        self.__is_playing = False

        def register_channel(station, channel):
            if station:
                station.channels.append(channel)

            for stream in channel.streams:
                self.__channels[stream.uri] = channel

            self.__channels[channel.uri] = channel

        def station_added_cb(station):
            id, title, uri, channels = station
            station = Station(id, title, uri)

            for channel in channels:
                channel = self.decode_channel(station, *channel)
                register_channel(station, channel)

            self.__stations[station.id] = station
            self.emit('station-added', station)

        def channel_added_cb(station_id, channel):
            station = self.find_station(station_id)
            channel = self.decode_channel(station, *channel)
            register_channel(station, channel)
            self.emit('channel-added', channel)

        def state_changed_cb(playing, stream_uri):
            self.__stream_tags = self.__service.GetStreamTags()
            self.__current_channel = self.__channels.get(stream_uri)
            self.__is_playing = playing
            self.emit('state-changed')

        def stream_tags_changed_cb(tags):
            self.__stream_tags.update(tags)
            self.emit('stream-tags-changed')

        def name_owner_cb(new_owner):
            if not new_owner:
                # FIXME
                from gtk import main_quit
                main_quit()

        self.__bus = SessionBus()
        proxy = self.__bus.get_object(Service.name, '/')
        self.__bus.watch_name_owner(Service.name, name_owner_cb)
        self.__service = Interface(proxy, Service.interface)
        self.__service.connect_to_signal('StationAdded',      station_added_cb)
        self.__service.connect_to_signal('ChannelAdded',      channel_added_cb)
        self.__service.connect_to_signal('StateChanged',      state_changed_cb)
        self.__service.connect_to_signal('StreamTagsChanged', stream_tags_changed_cb)

        for station in self.__service.GetStations():
            station_added_cb(station)

        state_changed_cb(*self.__service.GetState())

    def wait(self, stage=STATE_CHANNELS_LOADED):
        loop = MainLoop(None, True)

        def data_ready_cb(new_stage):
            if new_stage >= stage:
                loop.quit()

        self.__service.connect_to_signal('DataReady', data_ready_cb)

        if self.__service.GetDataStage() >= stage:
            loop.quit()
#.........这里部分代码省略.........
开发者ID:MarvinMuuss,项目名称:webradio-1,代码行数:103,代码来源:client.py


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