def packagekit_install(pack='ffmpeg'): """ Equivalent of: qdbus org.freedesktop.PackageKit /org/freedesktop/PackageKit org.freedesktop.PackageKit.Modify.InstallPackageNames 0 ffmpeg "show-confirm-search,hide-finished" Or: qdbus org.freedesktop.PackageKit /org/freedesktop/PackageKit org.freedesktop.PackageKit.Query.IsInstalled 0 ffmpeg See also (dbus) http://www.freedesktop.org/software/PackageKit/pk-faq.html#session-methods Doc: http://blog.fpmurphy.com/2013/11/packagekit-d-bus-abstraction-layer.html """ from PyQt5.QtDBus import QDBusConnection from PyQt5.QtDBus import QDBusInterface bus = QDBusConnection.sessionBus() service_name = 'org.freedesktop.PackageKit' service_path = '/org/freedesktop/PackageKit' interface = 'org.freedesktop.PackageKit.Query.IsInstalled' install = QDBusInterface(service_name, service_path, interface, bus) reply = install.call(0, pack, 'show-confirm-search,hide-finished') print(reply.arguments()) interface = 'org.freedesktop.PackageKit.Modify.InstallPackageNames' install = QDBusInterface(service_name, service_path, interface, bus) reply = install.call(0, pack, 'show-confirm-search,hide-finished') print(reply.arguments())
def __init__(self): """ NetworkInterfaces is a list of the plugged-in network connections. ```python [{ "path": b"/org/freedesktop/NetworkManager/Devices/1" "name": "Ethernet", "address": "192.168.100.166" or "2001:0db8:85a3::8a2e:0370:7334" }, { ... }] ``` You can `networkInterfaces.observe(callback)` to get updates. """ super().__init__() self._connections = [] #observers collection self._callbacks = [] self.networkManager = QDBusInterface( f"org.freedesktop.NetworkManager", #Service f"/org/freedesktop/NetworkManager", #Path f"org.freedesktop.NetworkManager", #Interface QDBusConnection.systemBus(), ) self.networkManager.setTimeout(10) #Set to 1000 after startup period. #Retry. This doesn't connect the first time, no matter what the time limit is. I don't know why, probably something in the start-on-demand logic. if not self.networkManager.isValid(): self.networkManager = QDBusInterface( f"org.freedesktop.NetworkManager", #Service f"/org/freedesktop/NetworkManager", #Path f"org.freedesktop.NetworkManager", #Interface QDBusConnection.systemBus(), ) self.networkManager.setTimeout(10) if not self.networkManager.isValid(): log.critical(f"Error: Can not connect to NetworkManager at {self.networkManager.service()}. ({self.networkManager.lastError().name()}: {self.networkManager.lastError().message()}) Try running `apt install network-manager`?") raise Exception("D-Bus Setup Error") self.networkManager.setTimeout(1000) #The .connect call freezes if we don't do this, or if we do this twice. #This bug was fixed by Qt 5.11. QDBusConnection.systemBus().registerObject( f"/org/freedesktop/NetworkManager", self, ) self._acquireInterfacesCall = QDBusPendingCallWatcher( self.networkManager.asyncCall('GetDevices') ) self._acquireInterfacesCall.finished.connect(self._acquireInterfaceData)
def __grabSelectedWindow(self): """ Private method to grab a selected window. """ snapshot = QPixmap() if Globals.isKdeDesktop(): mask = 0 if self.__captureDecorations: mask |= 1 if self.__captureCursor: mask |= 2 interface = QDBusInterface( "org.kde.KWin", "/Screenshot", "org.kde.kwin.Screenshot" ) reply = interface.call( "interactive", mask ) if self.__checkReply(reply, 1): filename = reply.arguments()[0] if filename: snapshot = QPixmap(filename) try: os.remove(filename) except OSError: # just ignore it pass elif Globals.isGnomeDesktop(): path = self.__temporaryFilename() interface = QDBusInterface( "org.gnome.Shell", "/org/gnome/Shell/Screenshot", "org.gnome.Shell.Screenshot" ) reply = interface.call( "ScreenshotWindow", self.__captureDecorations, self.__captureCursor, False, path ) if self.__checkReply(reply, 2): filename = reply.arguments()[1] if filename: snapshot = QPixmap(filename) try: os.remove(filename) except OSError: # just ignore it pass self.grabbed.emit(snapshot)
def __grabFullscreen(self): """ Private method to grab the complete desktop. """ snapshot = QPixmap() if Globals.isKdeDesktop(): interface = QDBusInterface( "org.kde.KWin", "/Screenshot", "org.kde.kwin.Screenshot" ) reply = interface.call( "screenshotFullscreen", self.__captureCursor ) if self.__checkReply(reply, 1): filename = reply.arguments()[0] if filename: snapshot = QPixmap(filename) try: os.remove(filename) except OSError: # just ignore it pass elif Globals.isGnomeDesktop(): path = self.__temporaryFilename() interface = QDBusInterface( "org.gnome.Shell", "/org/gnome/Shell/Screenshot", "org.gnome.Shell.Screenshot" ) reply = interface.call( "Screenshot", self.__captureCursor, False, path ) if self.__checkReply(reply, 2): filename = reply.arguments()[1] if filename: snapshot = QPixmap(filename) try: os.remove(filename) except OSError: # just ignore it pass self.grabbed.emit(snapshot)
def install_packages(pkg_names): iface = QDBusInterface("com.linuxdeepin.softwarecenter_frontend", "/com/linuxdeepin/softwarecenter_frontend", '', QDBusConnection.sessionBus()) iface.asyncCall("install_pkgs", pkg_names) iface.asyncCall("show_page", "install") iface.asyncCall("raise_to_top")
def __init__(self, application): super().__init__(application) self.__sessionService = application.sessionService self.__settings = application.settings self._menubarAdapter = CanonicalDBusMenuAdapter( sessionService=self.__sessionService, settings=self.__settings, app=application, parent=self, ) self.__sessionService.registerObject( "/MenuBar", self._menubarAdapter, ) self._sniAdapter = KdeStatusNotifierAdapter( sessionService=self.__sessionService, parent=self, ) self.__sessionService.registerObject( "/StatusNotifierItem", self._sniAdapter, ) self._interface = QDBusInterface( "org.kde.StatusNotifierWatcher", "/StatusNotifierWatcher", "org.kde.StatusNotifierWatcher", )
def __init__(self, bus, listener=None): super().__init__() self.bus = bus self.bus.registerObject('/', self) self.requests: Dict[str, Tuple[str, str, str]] = {} self.thumbnailer = QDBusInterface( 'org.freedesktop.thumbnails.Thumbnailer1', '/org/freedesktop/thumbnails/Thumbnailer1', 'org.freedesktop.thumbnails.Thumbnailer1', connection=self.bus) self.listener = listener self.bus.connect('', '', 'org.freedesktop.thumbnails.Thumbnailer1', 'Ready', self._receive_ready) self.bus.connect('', '', 'org.freedesktop.thumbnails.Thumbnailer1', 'Started', self._receive_started) self.bus.connect('', '', 'org.freedesktop.thumbnails.Thumbnailer1', 'Finished', self._receive_finished) self.bus.connect('', '', 'org.freedesktop.thumbnails.Thumbnailer1', 'Error', self._receive_error)
def unmount_usb_device(block_device: str): """ Attempts to unmount a USB device via org.freedesktop.UDisks2.Filesystem D-Bus interface as described at http://storaged.org/doc/udisks2-api/latest/gdbus-org.freedesktop.UDisks2.Filesystem.html#gdbus-method-org-freedesktop-UDisks2-Filesystem.Unmount. :param block_device: a partition name to unmount, for example /dev/sdb1 """ if block_device is None: raise TypeError("'block_device' cannot be of type 'NoneType'") elif block_device == '': raise ValueError("'block_device' cannot be empty") path = block_device.replace('/dev', '/org/freedesktop/UDisks2/block_devices') file_system_interface = QDBusInterface( 'org.freedesktop.UDisks2', path, 'org.freedesktop.UDisks2.Filesystem', QDBusConnection.systemBus()) if not file_system_interface.isValid(): raise RuntimeError(_translate('DriveUtils', 'Invalid D-Bus interface')) reply = file_system_interface.call('Unmount', {}) if reply.type() == QDBusMessage.ErrorMessage: raise RuntimeError(reply.errorMessage()) elif reply.type() != QDBusMessage.ReplyMessage: raise RuntimeError( _translate('DriveUtils', 'Unexpected reply from Udisks'))
def __init__(self, qobject): ''' Starts the d-bus service to watch for any stray notifications ''' super().__init__(qobject) sb = QDBusConnection.sessionBus() print("Notifs_Dbus: Registering notif. service…") try: sb.registerService("org.freedesktop.Notifications") except: print("Couldn't register freedesktop notifications service!") print("Notifs_Dbus: Registering notif. object…") try: sb.registerObject("/org/freedesktop/Notifications", qobject) except: print("Couldn't register freedesktop notifications object!") # match string m = "eavesdrop='true', interface='org.freedesktop.Notifications', member='Notify', type='method_call'" i = QDBusInterface("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus") i.call("AddMatch", m) print("Notifs_Dbus: Listener should start by now.")
def _dbus_notify(title, message, duration=5000): from PyQt5.QtDBus import ( QDBus, QDBusArgument, QDBusConnection, QDBusInterface) bus = QDBusConnection.sessionBus() if not bus.isConnected(): raise OSError("Could not connect to DBus") interface = QDBusInterface( 'org.freedesktop.Notifications', '/org/freedesktop/Notifications', 'org.freedesktop.Notifications', bus) error = interface.lastError() if error.type(): raise RuntimeError("{}; {}".format(error.name(), error.message())) # See https://developer.gnome.org/notification-spec/ # "This allows clients to effectively modify the notification while # it's active. A value of value of 0 means that this notification # won't replace any existing notifications." replaces_id = QVariant(0) replaces_id.convert(QVariant.UInt) interface.call( QDBus.NoBlock, 'Notify', APP_NAME, replaces_id, resource(settings['application']['tray_icon']), title, message, QDBusArgument([], QMetaType.QStringList), {}, duration)
def main(): import sys app = QCoreApplication(sys.argv) # noqa: F841 if not QDBusConnection.sessionBus().isConnected(): sys.stderr.write("Cannot connect to the D-Bus session bus.\n" "To start it, run:\n" "\teval `dbus-launch --auto-syntax`\n") sys.exit(1) iface = QDBusInterface(SERVICE_NAME, "/", "", QDBusConnection.sessionBus()) if iface.isValid(): msg = iface.call("ping", sys.argv[1] if len(sys.argv) > 1 else "") reply = QDBusReply(msg) if reply.isValid(): sys.stdout.write("Reply was: %s\n" % reply.value()) sys.exit() sys.stderr.write("Call failed: %s\n" % reply.error().message()) sys.exit(1) sys.stderr.write("%s\n" % QDBusConnection.sessionBus().lastError().message()) sys.exit(1)
def __init__(self, *, taskModel, frontendSettings, parent): super().__init__(parent) self.__taskModel = taskModel self.__frontendSettings = frontendSettings self._conn = QDBusConnection("Xware Desktop").sessionBus() self._interface = QDBusInterface(_DBUS_NOTIFY_SERVICE, _DBUS_NOTIFY_PATH, _DBUS_NOTIFY_INTERFACE, self._conn) self._notified = {} # a dict of notifyId: taskDict self.__taskModel.taskCompleted.connect(self.notifyTaskCompleted, Qt.DirectConnection) self._capabilities = self._getCapabilities() if "actions" in self._capabilities: successful = self._conn.connect(_DBUS_NOTIFY_SERVICE, _DBUS_NOTIFY_PATH, _DBUS_NOTIFY_INTERFACE, "ActionInvoked", self.slotActionInvoked) if not successful: logging.error("ActionInvoked connect failed.") self._qSound_complete = QSound(":/sound/download-complete.wav", self)
def __init__(self, bus): super().__init__() bus.registerObject('/', self) bus.connect('', '', 'org.freedesktop.DBus.ObjectManager', 'InterfacesAdded', self._on_interfaces_added) bus.connect('', '', 'org.freedesktop.DBus.ObjectManager', 'InterfacesRemoved', self._on_interfaces_removed) if False: ud_objectmanager = QDBusInterface( "org.freedesktop.UDisks2", "/org/freedesktop/UDisks2", "org.freedesktop.DBus.ObjectManager", connection=bus) result = call(ud_objectmanager, "GetManagedObjects") pprint.pprint(result) self._print_blockdevices(bus) self._print_drives(bus) self.udisks_manager = QDBusInterface( "org.freedesktop.UDisks2", "/org/freedesktop/UDisks2/Manager", "org.freedesktop.UDisks2.Manager", connection=bus) self._drives: Dict[str, List[str]] = defaultdict(list) block_devices = call(self.udisks_manager, "GetBlockDevices", {})[0] for block_device in block_devices: # block_iface = QDBusInterface("org.freedesktop.UDisks2", # block_device, # "org.freedesktop.UDisks2.Block", # connection=bus) block_props = QDBusInterface("org.freedesktop.UDisks2", block_device, "org.freedesktop.DBus.Properties", connection=bus) drive = call(block_props, "Get", "org.freedesktop.UDisks2.Block", "Drive")[0] self._drives[drive].append(block_device)
def __init__(self, parent=None): # manages power actions, and act them. super().__init__(parent) self._conn = QDBusConnection("Xware Desktop").systemBus() self._interface = QDBusInterface(_DBUS_POWER_SERVICE, _DBUS_POWER_PATH, _DBUS_POWER_INTERFACE, self._conn) self._actions = {} # {Action: ActionType} self._loadActions()
def __init__(self): QtCore.QObject.__init__(self) self.session_bus = QDBusConnection.sessionBus() self.session_bus.connect(self.DBUS_NAME, self.DBUS_PATH, self.DBUS_IFACE, 'MenuItemClicked', self.MenuItemClickedSlot) self.session_bus.connect(self.DBUS_NAME, self.DBUS_PATH, self.DBUS_IFACE, 'CheckMenuItemClicked', self.CheckMenuItemClickedSlot) self._iface = QDBusInterface(self.DBUS_NAME, self.DBUS_PATH, self.DBUS_IFACE, self.session_bus)
def __init__(self, parent: QObject = None) -> None: super().__init__(bridge) if not qtutils.version_check('5.14'): raise Error("Notifications are not supported on Qt < 5.14") if utils.is_windows: # The QDBusConnection destructor seems to cause error messages (and # potentially segfaults) on Windows, so we bail out early in that case. # We still try to get a connection on macOS, since it's theoretically # possible to run DBus there. raise Error("libnotify is not supported on Windows") bus = QDBusConnection.sessionBus() if not bus.isConnected(): raise Error( "Failed to connect to DBus session bus: " + self._dbus_error_str(bus.lastError())) self._watcher = QDBusServiceWatcher( self.SERVICE, bus, QDBusServiceWatcher.WatchForUnregistration, self, ) self._watcher.serviceUnregistered.connect( # type: ignore[attr-defined] self._on_service_unregistered) test_service = 'test-notification-service' in objects.debug_flags service = self.TEST_SERVICE if test_service else self.SERVICE self.interface = QDBusInterface(service, self.PATH, self.INTERFACE, bus) if not self.interface.isValid(): raise Error( "Could not construct a DBus interface: " + self._dbus_error_str(self.interface.lastError())) connections = [ ("NotificationClosed", self._handle_close), ("ActionInvoked", self._handle_action), ] for name, func in connections: if not bus.connect(service, self.PATH, self.INTERFACE, name, func): raise Error( f"Could not connect to {name}: " + self._dbus_error_str(bus.lastError())) self._quirks = _ServerQuirks() if not test_service: # Can't figure out how to make this work with the test server... # https://www.riverbankcomputing.com/pipermail/pyqt/2021-March/043724.html self._get_server_info() if self._quirks.skip_capabilities: self._capabilities = _ServerCapabilities.from_list([]) else: self._fetch_capabilities()
def __init__(self, dbus_name, object_name): QObject.__init__(self) iface = QDBusInterface(dbus_name, object_name, '', QDBusConnection.sessionBus()) if iface.isValid(): iface.call("unique") sys.exit(1) QDBusConnection.sessionBus().registerService(dbus_name) QDBusConnection.sessionBus().registerObject(object_name, self, QDBusConnection.ExportAllSlots)
def method2(): sys.stdout.write("Method 2:\n") bus = QDBusConnection.sessionBus() dbus_iface = QDBusInterface('org.freedesktop.DBus', '/org/freedesktop/DBus', 'org.freedesktop.DBus', bus) names = dbus_iface.call('ListNames').arguments()[0] # Mimic the output from the C++ version. sys.stdout.write('QVariant(QStringList, ("%s") )\n' % '", "'.join(names))
def uninhibitScreenlock(self): if not QDBusConnection.sessionBus().isConnected(): sys.stderr.write("Cannot connect to the D-Bus session bus.\n" "To start it, run:\n" "\teval `dbus-launch --auto-syntax`\n") return iface = QDBusInterface('org.kde.screensaver', '/ScreenSaver', '', QDBusConnection.sessionBus()) if iface.isValid(): iface.call('UnInhibit', self.screenLockCookie)
def _print_drives(self, bus): udisks_manager_introspect = QDBusInterface( "org.freedesktop.UDisks2", "/org/freedesktop/UDisks2/drives", "org.freedesktop.DBus.Introspectable", connection=bus) xml_text, = call(udisks_manager_introspect, "Introspect") print(xml_text) root = ElementTree.fromstring(xml_text) for el in root.findall("./interface"): print(" ", el.attrib['name'])
def get_devices(self): devices = [] interface = QDBusInterface(self.DBUS_SERVICE, self.DBUS_PATH, 'org.freedesktop.DBus.Introspectable', self.bus) xml_str = interface.call('Introspect').arguments()[0] for child in ElementTree.fromstring(xml_str): if child.tag == 'node': devices.append(child.attrib['name']) return devices
def __init__(self, parent=None): super().__init__(parent) self.sessionBus = QDBusConnection.sessionBus() self._dbusInterface = QDBusInterface("org.freedesktop.DBus", "/", "org.freedesktop.DBus") if self.serviceExists(self.serviceName): raise RuntimeError("There's a DBus that has the same name.") created = self.sessionBus.registerService(self.serviceName) if not created: raise RuntimeError("Cannot create DBus Service.") self.registerObject("/", self)
def inhibitScreenlock(self): if not QDBusConnection.sessionBus().isConnected(): sys.stderr.write("Cannot connect to the D-Bus session bus.\n" "To start it, run:\n" "\teval `dbus-launch --auto-syntax`\n"); return iface = QDBusInterface('org.kde.screensaver', '/ScreenSaver', '', QDBusConnection.sessionBus()) if iface.isValid(): msg = iface.call('Inhibit', 'DisUpgradeViewKDE', 'Upgrading base OS') reply = QDBusReply(msg) self.screenLockCookie = reply.value()
def __init__(self, loaderLauncher): super().__init__(loaderLauncher) if not QDBusConnection.sessionBus().interface().isServiceRegistered(SignalTraceLoaderDBus.DBUS_SERVICE_NAME): raise DBusInterfaceError('Service {} is not registered'.format(SignalTraceLoaderDBus.DBUS_SERVICE_NAME)) self._dbusIface = QDBusInterface(SignalTraceLoaderDBus.DBUS_SERVICE_NAME, SignalTraceLoaderDBus.DBUS_OBJECT_PATH, '') if not self._dbusIface.isValid(): raise DBusInterfaceError('DBus interface is invalid') abiVersion = self._fetchABIVersion() if abiVersion[0] != self.ABI_VERSION_MAJOR or abiVersion[1] != self.ABI_VERSION_MINOR: raise DBusInterfaceError('Incompatible version od DBus interface ABI {}.{}'.format(abiVersion[0], abiVersion[1])) self._supportedFileFormats = self._fetchSupportedFormats() self._dbusIface.setTimeout(600000)
def __init__(self, parent=None): QObject.__init__(self, parent) self.ui = loadUi('keyboard.ui') self.ui.show() self.buttons = {} self.active_color = Color(0, 0, 0) self.effect_color = Color(0, 0, 0) self.color_dialog = QColorDialog() self.bus = QDBusConnection.sessionBus() tmp = self.get_devices()[0] print(f'Using service {tmp}') self.kb_leds = QDBusInterface(self.DBUS_SERVICE, self.DBUS_PATH + '/' + tmp, self.DBUS_INT_LEDS, self.bus)
def __init__(self, dbus_name, object_name): QObject.__init__(self) search_option = len(sys.argv) >= 2 and sys.argv[1] == "--search" iface = QDBusInterface(dbus_name, object_name, '', QDBusConnection.sessionBus()) if iface.isValid(): iface.call("unique") if search_option: iface.call("search") sys.exit(1) QDBusConnection.sessionBus().registerService(dbus_name) QDBusConnection.sessionBus().registerObject( object_name, self, QDBusConnection.ExportAllSlots)
def __init__(self): QtCore.QObject.__init__(self) self.session_bus = QDBusConnection.sessionBus() self.session_bus.connect(self.DBUS_NAME, self.DBUS_PATH, self.DBUS_IFACE, 'hide', self.hideSlot) self.session_bus.connect(self.DBUS_NAME, self.DBUS_PATH, self.DBUS_IFACE, 'ocrRecognized', self.ocrRecognizedSlot) self.session_bus.connect(self.DBUS_NAME, self.DBUS_PATH, self.DBUS_IFACE, 'strokeRecognized', self.strokeRecognizedSlot) self.session_bus.connect(self.DBUS_NAME, self.DBUS_PATH, self.DBUS_IFACE, 'ocrEnableChanged', self.ocrEnableChangedSlot) self.session_bus.connect(self.DBUS_NAME, self.DBUS_PATH, self.DBUS_IFACE, 'strokeEnableChanged', self.strokeEnableChangedSlot) self.session_bus.connect(self.DBUS_NAME, self.DBUS_PATH, self.DBUS_IFACE, 'cursorPositionChanged', self.cursorPositionChangedSlot) self.session_bus.connect(self.DBUS_NAME, self.DBUS_PATH, self.DBUS_IFACE, 'doubleCtrlReleased', self.doubleCtrlReleasedSlot) self.session_bus.connect(self.DBUS_NAME, self.DBUS_PATH, self.DBUS_IFACE, 'altPressed', self.altPressedSlot) self.session_bus.connect(self.DBUS_NAME, self.DBUS_PATH, self.DBUS_IFACE, 'ctrlPressed', self.ctrlPressedSlot) self.session_bus.connect(self.DBUS_NAME, self.DBUS_PATH, self.DBUS_IFACE, 'shiftPressed', self.shiftPressedSlot) self.session_bus.connect(self.DBUS_NAME, self.DBUS_PATH, self.DBUS_IFACE, 'altReleased', self.altReleasedSlot) self.session_bus.connect(self.DBUS_NAME, self.DBUS_PATH, self.DBUS_IFACE, 'ctrlReleased', self.ctrlReleasedSlot) self.session_bus.connect(self.DBUS_NAME, self.DBUS_PATH, self.DBUS_IFACE, 'shiftReleased', self.shiftReleasedSlot) self.session_bus.connect(self.DBUS_NAME, self.DBUS_PATH, self.DBUS_IFACE, 'keyPressed', self.keyPressedSlot) self.session_bus.connect(self.DBUS_NAME, self.DBUS_PATH, self.DBUS_IFACE, 'keyReleased', self.keyReleasedSlot) self.session_bus.connect(self.DBUS_NAME, self.DBUS_PATH, self.DBUS_IFACE, 'wheelKeyReleased', self.wheelKeyReleasedSlot) self.getword_iface = QDBusInterface(self.DBUS_NAME, self.DBUS_PATH, self.DBUS_IFACE, self.session_bus)
def __init__(self, parent): super().__init__(parent) self._conn = QDBusConnection("Xware Desktop").sessionBus() self._interface = QDBusInterface(_DBUS_NOTIFY_SERVICE, _DBUS_NOTIFY_PATH, _DBUS_NOTIFY_INTERFACE, self._conn) self._notifications = {} self._completedTasksStat = app.etmpy.completedTasksStat self._completedTasksStat.sigTaskCompleted.connect(self.notifyTask) self._capabilities = self._getCapabilities() if "actions" in self._capabilities: successful = self._conn.connect(_DBUS_NOTIFY_SERVICE, _DBUS_NOTIFY_PATH, _DBUS_NOTIFY_INTERFACE, "ActionInvoked", self.slotActionInvoked) if not successful: logging.error("ActionInvoked connect failed.") self._qSound_complete = QSound(":/sound/download-complete.wav", self)
def __grabRectangle(self): """ Private method to grab a rectangular desktop area. """ snapshot = QPixmap() if Globals.isGnomeDesktop(): # Step 1: let the user select the area interface = QDBusInterface( "org.gnome.Shell", "/org/gnome/Shell/Screenshot", "org.gnome.Shell.Screenshot" ) reply = interface.call("SelectArea") if self.__checkReply(reply, 4): x, y, width, height = reply.arguments()[:4] # Step 2: grab the selected area path = self.__temporaryFilename() reply = interface.call( "ScreenshotArea", x, y, width, height, False, path ) if self.__checkReply(reply, 2): filename = reply.arguments()[1] if filename: snapshot = QPixmap(filename) try: os.remove(filename) except OSError: # just ignore it pass self.grabbed.emit(snapshot)
def __init__(self, service, path, interface="", bus=QDBusConnection.systemBus()): if not QDBusConnection.systemBus().isConnected(): log.error("Can not connect to D-Bus. Is D-Bus itself running?") raise Exception("D-Bus Setup Error") self.name = type(self).__name__ self.iface = QDBusInterface(service, path, interface, bus) # For Asynchronous call handling. self.enqueuedCalls = [] self.callInProgress = False self.activeCall = None log.info("Connected to D-Bus %s API at %s", self.name, self.iface.path()) # Check for errors. if not self.iface.isValid(): # Otherwise, an error occured. log.error("Can not connect to %s D-Bus API at %s. (%s: %s)", self.name, self.iface.service(), self.iface.lastError().name(), self.iface.lastError().message()) else: self.iface.setTimeout(API_TIMEOUT_MS)