本文整理汇总了Python中dbus.service方法的典型用法代码示例。如果您正苦于以下问题:Python dbus.service方法的具体用法?Python dbus.service怎么用?Python dbus.service使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dbus
的用法示例。
在下文中一共展示了dbus.service方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read_sdp_service_record
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import service [as 别名]
def read_sdp_service_record(self):
print("Reading service record")
try:
fh = open(BTKbDevice.SDP_RECORD_PATH, "r")
except:
sys.exit("Could not open the sdp record. Exiting...")
return fh.read()
#listen for incoming client connections
#ideally this would be handled by the Bluez 5 profile
#but that didn't seem to work
示例2: __init__
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import service [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()
示例3: run_mpris2_server
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import service [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()
示例4: __verifyNotRunning
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import service [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
示例5: show_script_error
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import service [as 别名]
def show_script_error(self, parent):
"""
Show the last script error (if any)
"""
if self.service.scriptRunner.error != '':
dlg = Gtk.MessageDialog(type=Gtk.MessageType.INFO, buttons=Gtk.ButtonsType.OK,
message_format=self.service.scriptRunner.error)
self.service.scriptRunner.error = ''
# revert the tray icon
self.notifier.set_icon(cm.ConfigManager.SETTINGS[cm.NOTIFICATION_ICON])
self.notifier.errorItem.hide()
self.notifier.update_visible_status()
else:
dlg = Gtk.MessageDialog(type=Gtk.MessageType.INFO, buttons=Gtk.ButtonsType.OK,
message_format=_("No error information available"))
dlg.set_title(_("View script error"))
dlg.set_transient_for(parent)
dlg.run()
dlg.destroy()
示例6: read_sdp_service_record
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import service [as 别名]
def read_sdp_service_record(self):
print("Reading service record")
try:
fh = open(BluetoothDevice.SDP_RECORD_PATH, "r")
except:
sys.exit("Could not open the sdp record. Exiting...")
return fh.read()
# listen for incoming client connections
# ideally this would be handled by the Bluez 5 profile
# but that didn't seem to work
示例7: __init__
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import service [as 别名]
def __init__(self, advert_id, ad_type):
"""Default initialiser.
Creates the interface to the specified advertising data.
The DBus path must be specified.
:param advert_id: Unique ID of advertisement.
:param ad_type: Possible values: "broadcast" or "peripheral"
"""
# Setup D-Bus object paths and register service
self.path = '/ukBaz/bluezero/advertisement{0:04d}'.format(advert_id)
self.bus = dbus.SystemBus()
self.eventloop = async_tools.EventLoop()
self.interface = constants.LE_ADVERTISEMENT_IFACE
dbus.service.Object.__init__(self, self.bus, self.path)
self.props = {
constants.LE_ADVERTISEMENT_IFACE: {
'Type': ad_type,
'ServiceUUIDs': None,
'ManufacturerData': None,
'SolicitUUIDs': None,
'ServiceData': None,
'IncludeTxPower': False
}
}
示例8: __init__
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import service [as 别名]
def __init__(self, device_id=None):
"""Default initialiser.
1. Initialises the program loop using ``GObject``.
2. Registers the Application on the D-Bus.
3. Initialises the list of services offered by the application.
"""
# Initialise the loop that the application runs in
GObject.threads_init()
dbus.mainloop.glib.threads_init()
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
self.mainloop = GObject.MainLoop()
# Initialise the D-Bus path and register it
self.bus = dbus.SystemBus()
self.path = '/ukBaz/bluezero/application{}'.format(id(self))
self.bus_name = dbus.service.BusName('ukBaz.bluezero', self.bus)
dbus.service.Object.__init__(self, self.bus_name, self.path)
# Initialise services within the application
self.services = []
self.dongle = adapter.Adapter(device_id)
示例9: get_properties
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import service [as 别名]
def get_properties(self):
"""Return a dictionary of the service properties.
The dictionary has the following keys:
- UUID: the service UUID
- Primary: whether the service is the primary service
- Characteristics: D-Bus array of the characteristic object paths
associated with the service.
"""
return {
constants.GATT_SERVICE_IFACE: {
'UUID': self.uuid,
'Primary': self.primary,
'Characteristics': dbus.Array(
self.get_characteristic_paths(),
signature='o')
}
}
示例10: GetManagedObjects
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import service [as 别名]
def GetManagedObjects(self):
"""Get all objects that are managed by the service.
Return type is a dictionary whose keys are each registered object and
values the properties of the given object.
"""
response = {}
# print('GetManagedObjects')
response[self.get_path()] = self.get_properties()
chrcs = self.get_characteristics()
for chrc in chrcs:
response[chrc.get_path()] = chrc.get_properties()
descs = chrc.get_descriptors()
for desc in descs:
response[desc.get_path()] = desc.get_properties()
return response
示例11: __init__
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import service [as 别名]
def __init__(self, service_id, uuid, primary):
"""Default initialiser.
1. Registers the service on the D-Bus.
2. Sets up the service UUID and primary flags.
:param service_id:
:param uuid: service BLE UUID
:param primary: whether or not the service is a primary service
"""
# Setup D-Bus object paths and register service
self.path = self.PATH_BASE + str('{0:04d}'.format(service_id))
self.bus = dbus.SystemBus()
self.interface = constants.GATT_SERVICE_IFACE
dbus.service.Object.__init__(self, self.bus, self.path)
self.props = {
constants.GATT_SERVICE_IFACE: {
'UUID': uuid,
'Primary': primary}
}
示例12: GetAll
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import service [as 别名]
def GetAll(self, interface_name):
"""Return the service properties.
This method is registered with the D-Bus at
``org.freedesktop.DBus.Properties``
:param interface: interface to get the properties of.
The interface must be ``org.bluez.GattService1`` otherwise an
exception is raised.
"""
if interface_name != constants.GATT_SERVICE_IFACE:
raise InvalidArgsException()
try:
return self.props[interface_name]
except KeyError:
raise dbus.exceptions.DBusException(
'no such interface ' + interface_name,
name=interface_name + '.UnknownInterface')
示例13: get_service
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import service [as 别名]
def get_service(bus_name, object_path):
"""
Get an instance of the service history
:param bus_name: DBus bus name
:type bus_name: str
:param object_path: DBus Object name
:type object_path: str
:return: New object
:rtype: DBusService
"""
new_service = type("DBUSService{0:04}".format(DBusServiceFactory.service_number), (DBusService,), {})
DBusServiceFactory.service_number += 1
return new_service(bus_name, object_path)
示例14: __init__
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import service [as 别名]
def __init__(self, rc = '~/.task'):
self.tw = TaskWarrior(data_location=rc, create=True)
self.status_icon = Gtk.StatusIcon()
self.status_icon.set_from_file("images/iconStarted-0.png")
self.status_icon.connect("popup-menu", self.right_click_event)
self.status_icon.connect("activate", self.left_click_event)
# systray daemon
name = dbus.service.BusName(self.bus_name, bus=dbus.SessionBus(),do_not_queue=True, replace_existing=False, allow_replacement=False )
dbus.service.Object.__init__(self, name, '/systray')
# client for daemon
bus = dbus.SessionBus(private = True)
daemon_client = bus.get_object('org.liloman.pomodoro', "/daemon")
self.interface = dbus.Interface(daemon_client, "org.liloman.pomodoroInterface")
示例15: __init__
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import service [as 别名]
def __init__(self, bus, path):
dbus.service.Object.__init__(self, bus, path)
#
#create a bluetooth device to emulate a HID keyboard,
# advertize a SDP record using our bluez profile class
#