本文整理汇总了Python中dbus.SessionBus.watch_name_owner方法的典型用法代码示例。如果您正苦于以下问题:Python SessionBus.watch_name_owner方法的具体用法?Python SessionBus.watch_name_owner怎么用?Python SessionBus.watch_name_owner使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dbus.SessionBus
的用法示例。
在下文中一共展示了SessionBus.watch_name_owner方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TelepathyPlugin
# 需要导入模块: from dbus import SessionBus [as 别名]
# 或者: from dbus.SessionBus import watch_name_owner [as 别名]
#.........这里部分代码省略.........
return self._conn
def suggest_room_for_activity(self, activity_id):
"""Suggest a room to use to share the given activity.
"""
return activity_id
def identify_contacts(self, tp_chan, handles, identifiers=None):
raise NotImplementedError
def _init_connection(self):
"""Set up our connection
if there is no existing connection
(_find_existing_connection returns None)
produce a new connection with our protocol for our
account.
if there is an existing connection, reuse it by
registering for various of events on it.
"""
_logger.debug('%r: init connection', self)
conn = self._find_existing_connection()
if not conn:
_logger.debug('%r: no existing connection', self)
return
m = conn[CONN_INTERFACE].connect_to_signal('StatusChanged',
self._handle_connection_status_change)
self._matches.append(m)
m = conn[CONN_INTERFACE].connect_to_signal('NewChannel',
self._new_channel_cb)
self._matches.append(m)
self._watch_conn_name = self._session_bus.watch_name_owner(
conn.service_name, self._watch_conn_name_cb)
self._conn = conn
status = self._conn.GetStatus()
self._handle_connection_status_change(status, CONNECTION_STATUS_REASON_NONE_SPECIFIED)
def _find_existing_connection(self):
raise NotImplementedError
def _watch_conn_name_cb(self, dbus_name):
"""Check if we still have a connection on the DBus session bus.
If the connection disappears, stop the plugin.
"""
if not dbus_name and self._conn is not None:
_logger.warning(
'D-Bus name %s disappeared, this probably means %s crashed',
self._conn.service_name, self._TP_CONN_MANAGER)
self._handle_connection_status_change(
CONNECTION_STATUS_DISCONNECTED,
CONNECTION_STATUS_REASON_NONE_SPECIFIED)
def _handle_connection_status_change(self, status, reason):
if status == self._conn_status:
return
if status == CONNECTION_STATUS_CONNECTING:
self._conn_status = status
_logger.debug("%r: connecting...", self)
elif status == CONNECTION_STATUS_CONNECTED:
self._conn_status = status
示例2: Client
# 需要导入模块: from dbus import SessionBus [as 别名]
# 或者: from dbus.SessionBus import watch_name_owner [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()
#.........这里部分代码省略.........