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 try_unlock(self): wallet_name = self.get_result("networkWallet") wId = QVariant(0) wId.convert(4) output = self.get_result("open", args=[wallet_name, wId, 'vorta-repo']) try: self.handle = int(output) except ValueError: # For when kwallet is disabled or dbus otherwise broken self.handle = -2
def notify(self, summary, body, actions=[]): varRPlaceId = QVariant(0) varRPlaceId.convert(QVariant.UInt) varActions = QVariant(actions) varActions.convert(QVariant.StringList) msg = self.call("Notify", "Deepin Screenshot", varRPlaceId, "deepin-screenshot", summary, body, varActions, {}, -1) reply = QDBusReply(msg) return reply.value()
def notify(self, summary, body): replaceId = QVariant(0) replaceId.convert(QVariant.UInt) actions = QVariant([]) actions.convert(QVariant.StringList) msg = self.call("Notify", "Deepin Movie", replaceId, "deepin-movie", summary, body, actions, {}, -1) reply = QDBusReply(msg) return reply.value if reply.isValid() else None
def roleNames(self): """ Return a list of column heading titles. :return: list of str column headings """ values = [] for v in self.my_headings: # explicit cast is needed on Qt 5.5.0 vv = QVariant(v) vv.convert(QVariant.ByteArray) values.append(vv.value()) return dict(enumerate(values, 32))
def notify(self, summary, body): replaceId = QVariant(0) replaceId.convert(QVariant.UInt) actions = QVariant([]) actions.convert(QVariant.StringList) msg = self.call( "Notify", "Deepin Movie", replaceId, "deepin-movie", summary, body, actions, {}, -1) reply = QDBusReply(msg) return reply.value if reply.isValid() else None
def notify(self, summary, body, actions=[], hints={}): varRPlaceId = QVariant(0) varRPlaceId.convert(QVariant.UInt) varActions = QVariant(actions) varActions.convert(QVariant.StringList) varHints = QVariant(hints) varHints.convert(QVariant.Map) msg = self.call("Notify", "Deepin Screenshot", varRPlaceId, "deepin-screenshot", summary, body, varActions, varHints, -1) reply = QDBusReply(msg) if reply.isValid(): return reply.value() else: return None
def uninhibit(self, cookie=None): if self._inhibit_cookie: arg = QVariant(cookie or self._inhibit_cookie) arg.convert(QVariant.UInt) self.call('UnInhibit', arg)
def _as_uint32(x: int) -> QVariant: """Convert the given int to an uint32 for DBus.""" variant = QVariant(x) successful = variant.convert(QVariant.UInt) assert successful return variant
def runWithArguments(self, arguments): arguments = QVariant(arguments) arguments.convert(QVariant.StringList) self.call("RunWithArguments", arguments)
def uninhibit(self, cookie=None): if cookie or self._inhibit_cookie: arg = QVariant(cookie or self._inhibit_cookie) arg.convert(QVariant.UInt) self.call('UnInhibit', arg)
def showItems(self, items, startupId=""): urize = lambda x: "file://%s" % x.replace("file://", "") uris = QVariant(map(urize, items)) uris.convert(QVariant.StringList) self.call("ShowItems", uris, "")
def get_handle(self): wallet_name = self.get_result("networkWallet") wId = QVariant(0) wId.convert(4) output = self.get_result("open", args=[wallet_name, wId, 'vorta-repo']) self.handle = int(output)
def dbus_as(value): var = QVariant(value) ret = var.convert(QVariant.StringList) assert ret, "QVariant conversion failure: {}".format(value) return var
def dbus_uint(value): var = QVariant(value) ret = var.convert(QVariant.UInt) assert ret, "QVariant conversion failure: {}".format(value) return var