def __init__(self, config): self.__config: ConfigManager = ConfigManager(config) self.__yakuake = Yakuake( sessions=QtDBus.QDBusInterface("org.kde.yakuake", "/yakuake/sessions", "org.kde.yakuake"), tabs=QtDBus.QDBusInterface("org.kde.yakuake", "/yakuake/tabs", "org.kde.yakuake"), window=QtDBus.QDBusInterface("org.kde.yakuake", "/yakuake/window", "org.kde.yakuake"))
def read_dbus_property(obj, property): # QDBusInterface.property() didn't work for some reason props = QtDBus.QDBusInterface(obj.service(), obj.path(), 'org.freedesktop.DBus.Properties', obj.connection()) msg = props.call('Get', obj.interface(), property) return get_result(msg)
def _dbus_notify(self, header, msg, level='info'): item = "org.freedesktop.Notifications" path = "/org/freedesktop/Notifications" interface = "org.freedesktop.Notifications" app_name = "vorta" v = QtCore.QVariant(12321) # random int to identify all notifications if v.convert(QtCore.QVariant.UInt): id_replace = v icon = "" title = header text = msg actions_list = QtDBus.QDBusArgument([], QtCore.QMetaType.QStringList) hint = {'urgency': self.URGENCY[level]} time = 5000 # milliseconds for display timeout bus = QtDBus.QDBusConnection.sessionBus() notify = QtDBus.QDBusInterface(item, path, interface, bus) if notify.isValid(): x = notify.call(QtDBus.QDBus.AutoDetect, "Notify", app_name, id_replace, icon, title, text, actions_list, hint, time) if x.errorName(): logger.warning("Failed to send notification!") logger.warning(x.errorMessage()) else: logger.warning("Invalid dbus interface")
def export_objects(): app = QtWidgets.qApp app.setApplicationVersion("0.4.1") app.setOrganizationName("Youdao") app.setApplicationName("Youdao Dict") # set default font defaultFont = QtGui.QFont() defaultFont.setPointSize(11) app.setFont(defaultFont) if not session_bus.registerService(DBUS_NAME): print("Service is running: %s" % DBUS_NAME) iface = QtDBus.QDBusInterface(DBUS_NAME, DBUS_PATH, DBUS_INTERFACE, session_bus) iface.call("Raise") sys.exit(0) else: unique_obj = UniqueService() session_bus.registerObject(DBUS_PATH, unique_obj) print("Youdao Dict Unique Service is started...") youdao_api = ExternalApi() splash_window = SplashWindow(youdao_api) if not "--autostart" in sys.argv and not setting_config.get_basic_option( "start_mini"): splash_window.showCenter() splash_window.startTimer() indicator = YoudaoIndicator() return [ dict(name=unique_obj.name, obj=unique_obj), dict(name="indicator", obj=indicator), dict(name="splash_window", obj=splash_window), dict(name=youdao_api.name, obj=youdao_api), dict(name="config", obj=setting_config), ]
def alert(i, group_id, id, notify) : print("######### Match found at {0}th post! Link: {1} ###########".format(i, text)) if not notify : return item = "org.freedesktop.Notifications" path = "/org/freedesktop/Notifications" interface = "org.freedesktop.Notifications" app_name = "Marketplace Notification" v = QtCore.QVariant(91424) if v.convert(QtCore.QVariant.UInt): id_replace = v icon = "" title = "Match found in marketplace!" text = "https://www.facebook.com/groups/{0}/permalink/{1}".format(group_id, id) actions_list = QtDBus.QDBusArgument([], QtCore.QMetaType.QStringList) hint = {} time = 7000 # milliseconds for display timeout bus = QtDBus.QDBusConnection.sessionBus() if not bus.isConnected(): print("Not connected to dbus!") notify = QtDBus.QDBusInterface(item, path, interface, bus) if notify.isValid(): x = notify.call(QtDBus.QDBus.AutoDetect, "Notify", app_name, id_replace, icon, title, text, actions_list, hint, time) if x.errorName(): print("Failed to send notification!") print(x.errorMessage()) else: print("Invalid dbus interface")
def __init__(self): """ Test whether DBus and KDEWallet are available. """ self.iface = QtDBus.QDBusInterface(self.service_name, self.object_path, self.interface_name, QtDBus.QDBusConnection.sessionBus()) if not (self.iface.isValid() and self.get_result("isEnabled")): raise KWalletNotAvailableException
def __init__(self, url, width, height, open_url=None, stop_on_inactive=True, allow_screensaver=True, auto_restart_playback=False): super().__init__(None) self.url = url self.open_url = open_url self.auto_restart_playback_active = False self.dbus = QtDBus.QDBusConnection.systemBus() self.dbus_login_manager = QtDBus.QDBusInterface( "org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", self.dbus) self.dbus.connect("org.freedesktop.login1", "/org/freedesktop/login1/seat/seat0", "org.freedesktop.DBus.Properties", "PropertiesChanged", self.login_seat_changed) self.vlc_instance = vlc.Instance( "--no-disable-screensaver" if allow_screensaver else "") self.setFixedSize(QtCore.QSize(width, height)) self.media_player = None self.screensaver_state = False if auto_restart_playback: self.update_timer = QtCore.QTimer(self) self.update_timer.timeout.connect( self.update_auto_restart_playback) self.update_timer.start(1000) if stop_on_inactive: self.visibility_changed.connect(self.update_state_by_visibility) get_dashboard_instance().window_state_changed.connect( self.update_state_by_visibility) get_dashboard_instance().screensaver_state_changed.connect( self.screensaver_state_changed) else: self.play()
def initGui(self): self.setWindowTitle("Anna") self.setFrameStyle(widget.QFrame.NoFrame) self.setStyleSheet("background-color: transparent") self.setAttribute(core.Qt.WA_TranslucentBackground) self.pen = gui.QPen() self.pen.setWidth(3) self.pen.setColor(gui.QColor(255, 0, 0)) self.gs = widget.QGraphicsScene() self.setScene(self.gs) f = getattr(self.args, 'from') if f: reader = gui.QImageReader(f) reader.setAutoTransform(True) self.pixmap = gui.QPixmap.fromImage(reader.read()) if self.pixmap.isNull(): print('image read failed') else: self.gs.addPixmap(self.pixmap) pw, ph = self.pixmap.size().width(), \ self.pixmap.size().height() self.setGeometry(0, 0, pw, ph) self.setSceneRect(0, 0, pw, ph) else: self.setWindowFlags(core.Qt.X11BypassWindowManagerHint) rect = widget.QApplication.desktop().screenGeometry() self.setGeometry(rect) self.setSceneRect(core.QRectF(rect)) self.showFullScreen() self.mkIndicator() self.gs.addItem(self.ind) if dbus: self.interface = dbus.QDBusInterface("org.kde.KWin", "/Effects") resp = self.interface.call("Get", "org.kde.kwin.Effects", "activeEffects") if resp.type() == 2: if "diminactive" in resp.arguments()[0]: self.interface.call("unloadEffect", "diminactive") self.restore = True
def __init__(self, app, parent): self.parent = parent self.app = app super().__init__(app) self.__dbus = QtDBus.QDBusConnection.sessionBus() self.__dbus.registerObject('/', self) self.interface = QtDBus.QDBusInterface('io.opensnitch.service', '/', 'io.opensnitch.service', self.__dbus) if not self.interface.isValid(): raise RuntimeError('Could not connect to dbus') logging.info('Connected to dbus service') sig_connect = self.__dbus.connect('io.opensnitch.service', '/', 'io.opensnitch.service', 'prompt', self.prompt_user) if not sig_connect: raise RuntimeError('Could not connect dbus signal') logging.info('Connected dbus signal')
def __init__(self, url, width=None, height=None, stop_on_inactive=True, auto_restart_playback=False): super().__init__() self.url = url self.screensaver_state = False self.playing = False self.dbus = QtDBus.QDBusConnection.systemBus() self.dbus_login_manager = QtDBus.QDBusInterface( "org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", self.dbus) self.dbus.connect("org.freedesktop.login1", "/org/freedesktop/login1/seat/seat0", "org.freedesktop.DBus.Properties", "PropertiesChanged", self.login_seat_changed) if width and height: self.setFixedSize(QtCore.QSize(width, height)) self.player = QtMultimedia.QMediaPlayer(self) self.player.setVideoOutput(self) if auto_restart_playback: self.player.stateChanged.connect(self.state_changed) if stop_on_inactive: self.visibility_changed.connect(self.update_state_by_visibility) get_dashboard_instance().window_state_changed.connect( self.update_state_by_visibility) get_dashboard_instance().screensaver_state_changed.connect( self.screensaver_state_changed) else: self.play()
def send_notification(): global app_name global notification_id global saved_due_card_count due_card_count = len(mw.col.find_cards("is:new or is:due")) to_notify = due_card_count > saved_due_card_count saved_due_card_count = due_card_count if not to_notify: return short_app_name = "Anki" qt_notification_id = QtCore.QVariant(notification_id) qt_notification_id.convert(QtCore.QVariant.UInt) icon = app_name title = "Anki" text = str(due_card_count) + (" card" if due_card_count == 1 else " cards") + " to study" actions_list = QtDBus.QDBusArgument([], QtCore.QMetaType.QStringList) hint = {} time = -1 item = "org.freedesktop.Notifications" path = "/org/freedesktop/Notifications" interface = "org.freedesktop.Notifications" bus = QtDBus.QDBusConnection.sessionBus() if not bus.isConnected(): print("Not connected to dbus!") notify = QtDBus.QDBusInterface(item, path, interface, bus) if notify.isValid(): msg = notify.call(QtDBus.QDBus.AutoDetect, "Notify", short_app_name, qt_notification_id, icon, title, text, actions_list, hint, time) if msg.errorName(): print("Failed to send notification!") print(msg.errorMessage()) notification_id = msg.arguments()[0] else: print("Invalid dbus interface!")
def _notify(self, header, msg): if self._is_windows(): return False item = "org.freedesktop.Notifications" path = "/org/freedesktop/Notifications" interface = "org.freedesktop.Notifications" app_name = "pomito" v = QtCore.QVariant(100021) # random int to identify all notifications if v.convert(QtCore.QVariant.UInt): id_replace = v icon = "" title = header text = msg actions_list = QtDBus.QDBusArgument([], QtCore.QMetaType.QStringList) hint = {} time = 100 # milliseconds for display timeout bus = QtDBus.QDBusConnection.sessionBus() if not bus.isConnected(): logger.debug("Not connected to dbus!") return False notify = QtDBus.QDBusInterface(item, path, interface, bus) if notify.isValid(): x = notify.call(QtDBus.QDBus.AutoDetect, "Notify", app_name, id_replace, icon, title, text, actions_list, hint, time) if x.errorName(): logger.debug("Failed to send notification!") logger.debug(x.errorMessage()) return False else: logger.debug("Invalid dbus interface") return False return True
def __init__(self, name, path, interface, prevent_sleep_fn, allow_sleep_fn): super(DBusInhibitor, self).__init__() self.interface_name = interface self.insomnia_cookie = None bus_connection = QtDBus.QDBusConnection.sessionBus() assert bus_connection.isConnected(), 'Dbus is not connected' self.iface = QtDBus.QDBusInterface(name, path, interface, bus_connection) if self.iface.isValid(): LOGGER.debug('Registered to the DBus service: %s', name) else: LOGGER.debug('Failed to register DBus service object: %s', name) def call_dbus(method, *args): result = self.iface.call(method, *args) reply = QtDBus.QDBusReply(result) assert reply.isValid(), 'Dbus reply was not valid: {}'.format( bus_connection.lastError().message()) LOGGER.debug("Called dbus %s: returned %s (%s)", method, reply.value(), type(reply.value())) # return the whole value return reply.value() def inhibit(*args): # returns a QDBusMessage class return call_dbus(prevent_sleep_fn, *args) def uninhibit(*args): return call_dbus(allow_sleep_fn, *args) # Check we have the right attributes self._inhibit = inhibit self._uninhibit = uninhibit
def _get_iface(self, path, interface) -> QtDBus.QDBusInterface: return QtDBus.QDBusInterface(self.BUS_NAME, path, interface, self._bus)
def get_dbus_interface(self, service, interface): return QtDBus.QDBusInterface(service, "/org/mpris/MediaPlayer2", interface, self.bus)