当前位置: 首页>>代码示例>>Python>>正文


Python Notification.close方法代码示例

本文整理汇总了Python中blueman.gui.Notification.Notification.close方法的典型用法代码示例。如果您正苦于以下问题:Python Notification.close方法的具体用法?Python Notification.close怎么用?Python Notification.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在blueman.gui.Notification.Notification的用法示例。


在下文中一共展示了Notification.close方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Agent

# 需要导入模块: from blueman.gui.Notification import Notification [as 别名]
# 或者: from blueman.gui.Notification.Notification import close [as 别名]

#.........这里部分代码省略.........
        self._applet = applet
        self._config = Config("org.blueman.transfer")

        self._allowed_devices = []
        self._notification = None
        self._pending_transfer = None
        self.transfers = {}

    def _handle_method_call(self, connection, sender, agent_path, interface_name, method_name, parameters, invocation):
        log_msg = "%s %s" % (method_name, agent_path)
        if method_name == 'Release':
            logging.info(log_msg)
            self._on_release()
        elif method_name == 'AuthorizePush':
            logging.info(log_msg)
            self._on_authorize(parameters, invocation)
        elif method_name == 'Cancel':
            logging.info(log_msg)
            self._on_cancel(parameters, invocation)

    def register(self):
        obex.AgentManager().register_agent(self.__agent_path)

    def unregister(self):
        obex.AgentManager().unregister_agent(self.__agent_path)

    def _on_release(self):
        raise Exception(self.__agent_path + " was released unexpectedly")

    def _on_authorize(self, parameters, invocation):
        def on_action(action):
            logging.info("Action %s" % action)

            if action == "accept":
                self.transfers[self._pending_transfer['transfer_path']] = {
                    'path': self._pending_transfer['root'] + '/' + os.path.basename(self._pending_transfer['filename']),
                    'size': self._pending_transfer['size'],
                    'name': self._pending_transfer['name']
                }

                param = GLib.Variant('(s)', (self.transfers[self._pending_transfer['transfer_path']]['path'],))
                invocation.return_value(param)

                self._allowed_devices.append(self._pending_transfer['address'])
                GLib.timeout_add(60000, self._allowed_devices.remove, self._pending_transfer['address'])
            else:
                invocation.return_dbus_error('org.bluez.obex.Error.Rejected', 'Rejected')

        transfer_path = parameters.unpack()[0]

        transfer = obex.Transfer(transfer_path)
        session = obex.Session(transfer.session)
        root = session.root
        address = session.address
        filename = transfer.name
        size = transfer.size

        try:
            adapter = self._applet.Manager.get_adapter()
            device = self._applet.Manager.find_device(address, adapter.get_object_path())
            name = device["Alias"]
            trusted = device["Trusted"]
        except Exception as e:
            logging.exception(e)
            name = address
            trusted = False

        self._pending_transfer = {'transfer_path': transfer_path, 'address': address, 'root': root,
                                  'filename': filename, 'size': size, 'name': name}

        notif_kwargs = {"icon_name": "blueman"}
        try:
            notif_kwargs["pos_hint"] = self._applet.Plugins.StatusIcon.geometry
        except AttributeError:
            logging.error("Failed to get StatusIcon")

        # This device was neither allowed nor is it trusted -> ask for confirmation
        if address not in self._allowed_devices and not (self._config['opp-accept'] and trusted):
            self._notification = Notification(_("Incoming file over Bluetooth"),
                _("Incoming file %(0)s from %(1)s") % {"0": "<b>" + escape(filename) + "</b>",
                                                       "1": "<b>" + escape(name) + "</b>"},
                30000, [["accept", _("Accept"), "help-about"], ["reject", _("Reject"), "help-about"]], on_action,
                **notif_kwargs)
            self._notification.show()
        # Device is trusted or was already allowed, larger file -> display a notification, but auto-accept
        elif size > 350000:
            self._notification = Notification(_("Receiving file"),
                _("Receiving file %(0)s from %(1)s") % {"0": "<b>" + escape(filename) + "</b>",
                                                        "1": "<b>" + escape(name) + "</b>"},
                **notif_kwargs)
            on_action('accept')
            self._notification.show()
        # Device is trusted or was already allowed. very small file -> auto-accept and transfer silently
        else:
            self._notification = None
            on_action("accept")

    def _on_cancel(self, parameters, invocation):
        self._notification.close()
        invocation.return_dbus_error('org.bluez.obex.Error.Canceled', 'Canceled')
开发者ID:cschramm,项目名称:blueman,代码行数:104,代码来源:TransferService.py

示例2: Agent

# 需要导入模块: from blueman.gui.Notification import Notification [as 别名]
# 或者: from blueman.gui.Notification.Notification import close [as 别名]
class Agent(DbusService):
    __agent_path = '/org/bluez/obex/agent/blueman'

    def __init__(self, applet):
        super().__init__(None, "org.bluez.obex.Agent1", self.__agent_path, Gio.BusType.SESSION)

        self.add_method("Release", (), "", self._release)
        self.add_method("Cancel", (), "", self._cancel)
        self.add_method("AuthorizePush", ("o",), "s", self._authorize_push, is_async=True)
        self.register()

        self._applet = applet
        self._config = Config("org.blueman.transfer")

        self._allowed_devices = []
        self._notification = None
        self._pending_transfer = None
        self.transfers = {}

    def register_at_manager(self):
        obex.AgentManager().register_agent(self.__agent_path)

    def unregister_from_manager(self):
        obex.AgentManager().unregister_agent(self.__agent_path)

    def _release(self):
        raise Exception(self.__agent_path + " was released unexpectedly")

    def _authorize_push(self, transfer_path, ok, err):
        def on_action(action):
            logging.info("Action %s" % action)

            if action == "accept":
                self.transfers[self._pending_transfer['transfer_path']] = {
                    'path': self._pending_transfer['root'] + '/' + os.path.basename(self._pending_transfer['filename']),
                    'size': self._pending_transfer['size'],
                    'name': self._pending_transfer['name']
                }

                ok(self.transfers[self._pending_transfer['transfer_path']]['path'])

                self._allowed_devices.append(self._pending_transfer['address'])
                GLib.timeout_add(60000, self._allowed_devices.remove, self._pending_transfer['address'])
            else:
                err(ObexErrorRejected("Rejected"))

        transfer = obex.Transfer(transfer_path)
        session = obex.Session(transfer.session)
        root = session.root
        address = session.address
        filename = transfer.name
        size = transfer.size

        try:
            adapter = self._applet.Manager.get_adapter()
            device = self._applet.Manager.find_device(address, adapter.get_object_path())
            name = device["Alias"]
            trusted = device["Trusted"]
        except Exception as e:
            logging.exception(e)
            name = address
            trusted = False

        self._pending_transfer = {'transfer_path': transfer_path, 'address': address, 'root': root,
                                  'filename': filename, 'size': size, 'name': name}

        notif_kwargs = {"icon_name": "blueman"}
        try:
            notif_kwargs["pos_hint"] = self._applet.Plugins.StatusIcon.geometry
        except AttributeError:
            logging.error("Failed to get StatusIcon")

        # This device was neither allowed nor is it trusted -> ask for confirmation
        if address not in self._allowed_devices and not (self._config['opp-accept'] and trusted):
            self._notification = Notification(
                _("Incoming file over Bluetooth"),
                _("Incoming file %(0)s from %(1)s") % {"0": "<b>" + escape(filename) + "</b>",
                                                       "1": "<b>" + escape(name) + "</b>"},
                30000, [["accept", _("Accept"), "help-about"], ["reject", _("Reject"), "help-about"]], on_action,
                **notif_kwargs
            )
            self._notification.show()
        # Device is trusted or was already allowed, larger file -> display a notification, but auto-accept
        elif size > 350000:
            self._notification = Notification(
                _("Receiving file"),
                _("Receiving file %(0)s from %(1)s") % {"0": "<b>" + escape(filename) + "</b>",
                                                        "1": "<b>" + escape(name) + "</b>"},
                **notif_kwargs
            )
            on_action('accept')
            self._notification.show()
        # Device is trusted or was already allowed. very small file -> auto-accept and transfer silently
        else:
            self._notification = None
            on_action("accept")

    def _cancel(self):
        self._notification.close()
        raise ObexErrorCanceled("Canceled")
开发者ID:blueman-project,项目名称:blueman,代码行数:102,代码来源:TransferService.py

示例3: transfer_finished

# 需要导入模块: from blueman.gui.Notification import Notification [as 别名]
# 或者: from blueman.gui.Notification.Notification import close [as 别名]
    def transfer_finished(self, session, *args):
        type = args[-1]
        dprint(args)
        try:
            if not session.transfer["finished"]:

                if type != "cancelled" and type != "error":
                    session.transfer["finished"] = True

                    if session.transfer["total"] > 350000:
                        icon = get_icon("blueman", 48)
                        n = Notification(_("File received"),
                                         _("File %(0)s from %(1)s successfully received") % {
                                         "0": "<b>" + session.transfer["filename"] + "</b>",
                                         "1": "<b>" + session.transfer["name"] + "</b>"},
                                         pixbuf=icon, status_icon=self.status_icon)
                        self.add_open(n, "Open", session.transfer["filepath"])
                else:
                    session.transfer["failed"] = True
                    session.transfer["finished"] = True

                    n = session.transfer["notification"]
                    if n:
                        n.close()

                    icon = get_icon("blueman", 48)

                    session.transfer["notification"] = Notification(_("Transfer failed"),
                                                                    _("Transfer of file %(0)s failed") % {
                                                                    "0": "<b>" + session.transfer["filename"] + "</b>",
                                                                    "1": "<b>" + session.transfer["name"] + "</b>"},
                                                                    pixbuf=icon, status_icon=self.status_icon)
                    if session.transfer["total"] > 350000:
                        session.transfer["normal_transfers"] -= 1
                    else:
                        session.transfer["silent_transfers"] -= 1

            if type == "disconnected":
                icon = get_icon("blueman", 48)

                if session.transfer["normal_transfers"] == 0 and session.transfer["silent_transfers"] == 1:
                    n = Notification(_("File received"),
                                     _("File %(0)s from %(1)s successfully received") % {
                                     "0": "<b>" + session.transfer["filename"] + "</b>",
                                     "1": "<b>" + session.transfer["name"] + "</b>"},
                                     pixbuf=icon, status_icon=self.status_icon)

                    self.add_open(n, "Open", session.transfer["filepath"])

                elif session.transfer["normal_transfers"] == 0 and session.transfer["silent_transfers"] > 0:
                    n = Notification(_("Files received"),
                                     ngettext("Received %d file in the background",
                                              "Received %d files in the background",
                                              session.transfer["silent_transfers"]) % session.transfer[
                                         "silent_transfers"],
                                     pixbuf=icon, status_icon=self.status_icon)

                    self.add_open(n, "Open Location", self.Config.props.shared_path)

                elif session.transfer["normal_transfers"] > 0 and session.transfer["silent_transfers"] > 0:

                    n = Notification(_("Files received"),
                                     ngettext("Received %d more file in the background",
                                              "Received %d more files in the background",
                                              session.transfer["silent_transfers"]) % session.transfer[
                                         "silent_transfers"],
                                     pixbuf=icon, status_icon=self.status_icon)
                    self.add_open(n, "Open Location", self.Config.props.shared_path)

                del session.transfer
                del session.server

        except KeyError:
            pass
开发者ID:Acidburn0zzz,项目名称:blueman,代码行数:76,代码来源:Transfer.py

示例4: __init__

# 需要导入模块: from blueman.gui.Notification import Notification [as 别名]
# 或者: from blueman.gui.Notification.Notification import close [as 别名]

#.........这里部分代码省略.........

        self._agent = obex.Agent(self._agent_path)
        self._agent.connect("release", self._on_release)
        self._agent.connect("authorize", self._on_authorize)
        self._agent.connect("cancel", self._on_cancel)

        self._allowed_devices = []
        self._notification = None
        self._pending_transfer = None
        self.transfers = {}

        obex.AgentManager().register_agent(self._agent_path)

    def __del__(self):
        obex.AgentManager().unregister_agent(self._agent_path)

    def _on_release(self, _agent):
        raise Exception(self._agent_path + " was released unexpectedly")

    def _on_action(self, _notification, action):
        dprint(action)

        if action == "accept":
            self.transfers[self._pending_transfer["transfer_path"]] = {
                "path": self._pending_transfer["root"] + "/" + os.path.basename(self._pending_transfer["filename"]),
                "size": self._pending_transfer["size"],
                "name": self._pending_transfer["name"],
            }
            self._agent.reply(self.transfers[self._pending_transfer["transfer_path"]]["path"])
            self._allowed_devices.append(self._pending_transfer["address"])
            GObject.timeout_add(60000, self._allowed_devices.remove, self._pending_transfer["address"])
        else:
            self._agent.reply(obex.Error.Rejected)

    def _on_authorize(self, _agent, transfer_path, address=None, filename=None, size=None):
        if address and filename and size:
            # stand-alone obexd
            # FIXME: /tmp is only the default. Can we get the actual root
            # directory from stand-alone obexd?
            root = "/tmp"
        else:
            # BlueZ 5 integrated obexd
            transfer = obex.Transfer(transfer_path)
            session = obex.Session(transfer.session)
            root = session.root
            address = session.address
            filename = transfer.name
            size = transfer.size

        try:
            device = Device(self._applet.Manager.get_adapter().find_device(address))
            name = device.Alias
            trusted = device.Trusted
        except Exception as e:
            dprint(e)
            name = address
            trusted = False

        self._pending_transfer = {
            "transfer_path": transfer_path,
            "address": address,
            "root": root,
            "filename": filename,
            "size": size,
            "name": name,
        }

        try:
            status_icon = self._applet.Plugins.StatusIcon
        except:
            status_icon = None

        # This device was neither allowed nor is it trusted -> ask for confirmation
        if address not in self._allowed_devices and not (self._config["opp-accept"] and trusted):
            self._notification = Notification(
                _("Incoming file over Bluetooth"),
                _("Incoming file %(0)s from %(1)s") % {"0": "<b>" + filename + "</b>", "1": "<b>" + name + "</b>"},
                30000,
                [["accept", _("Accept"), "help-about"], ["reject", _("Reject"), "help-about"]],
                self._on_action,
                pixbuf=get_icon("blueman", 48),
                status_icon=status_icon,
            )
        # Device is trusted or was already allowed, larger file -> display a notification, but auto-accept
        elif size > 350000:
            self._notification = Notification(
                _("Receiving file"),
                _("Receiving file %(0)s from %(1)s") % {"0": "<b>" + filename + "</b>", "1": "<b>" + name + "</b>"},
                pixbuf=get_icon("blueman", 48),
                status_icon=status_icon,
            )
            self._on_action(self._notification, "accept")
        # Device is trusted or was already allowed. very small file -> auto-accept and transfer silently
        else:
            self._notification = None
            self._on_action(self._notification, "accept")

    def _on_cancel(self, agent):
        self._notification.close()
        agent.reply(obex.Error.Canceled)
开发者ID:City-busz,项目名称:blueman,代码行数:104,代码来源:TransferService.py

示例5: __init__

# 需要导入模块: from blueman.gui.Notification import Notification [as 别名]
# 或者: from blueman.gui.Notification.Notification import close [as 别名]
class _Agent:
    def __init__(self, applet):
        self._applet = applet
        self._config = Config("org.blueman.transfer")

        self._agent_path = '/org/blueman/obex_agent'

        self._agent = obex.Agent(self._agent_path)
        self._agent.connect('release', self._on_release)
        self._agent.connect('authorize', self._on_authorize)
        self._agent.connect('cancel', self._on_cancel)

        self._allowed_devices = []
        self._notification = None
        self._pending_transfer = None
        self.transfers = {}

    def register(self):
        obex.AgentManager().register_agent(self._agent_path)

    def unregister(self):
        obex.AgentManager().unregister_agent(self._agent_path)

    def _on_release(self, _agent):
        raise Exception(self._agent_path + " was released unexpectedly")

    def _on_action(self, _notification, action):
        dprint(action)

        if action == "accept":
            self.transfers[self._pending_transfer['transfer_path']] = {
                'path': self._pending_transfer['root'] + '/' + os.path.basename(self._pending_transfer['filename']),
                'size': self._pending_transfer['size'],
                'name': self._pending_transfer['name']
            }
            self._agent.reply(self.transfers[self._pending_transfer['transfer_path']]['path'])
            self._allowed_devices.append(self._pending_transfer['address'])
            GLib.timeout_add(60000, self._allowed_devices.remove, self._pending_transfer['address'])
        else:
            self._agent.reply(obex.Error.Rejected)

    def _on_authorize(self, _agent, transfer_path):
        transfer = obex.Transfer(transfer_path)
        session = obex.Session(transfer.session)
        root = session.root
        address = session.address
        filename = transfer.name
        size = transfer.size

        try:
            device = self._applet.Manager.get_adapter().find_device(address)
            name = device["Alias"]
            trusted = device["Trusted"]
        except Exception as e:
            dprint(e)
            name = address
            trusted = False

        self._pending_transfer = {'transfer_path': transfer_path, 'address': address, 'root': root,
                                  'filename': filename, 'size': size, 'name': name}

        try:
            status_icon = self._applet.Plugins.StatusIcon
        except:
            status_icon = None

        # This device was neither allowed nor is it trusted -> ask for confirmation
        if address not in self._allowed_devices and not (self._config['opp-accept'] and trusted):
            self._notification = Notification(_("Incoming file over Bluetooth"),
                _("Incoming file %(0)s from %(1)s") % {"0": "<b>" + filename + "</b>",
                                                       "1": "<b>" + name + "</b>"},
                30000, [["accept", _("Accept"), "help-about"], ["reject", _("Reject"), "help-about"]], self._on_action,
                pixbuf=get_icon("blueman", 48), status_icon=status_icon)
        # Device is trusted or was already allowed, larger file -> display a notification, but auto-accept
        elif size > 350000:
            self._notification = Notification(_("Receiving file"),
                _("Receiving file %(0)s from %(1)s") % {"0": "<b>" + filename + "</b>",
                                                        "1": "<b>" + name + "</b>"},
                pixbuf=get_icon("blueman", 48), status_icon=status_icon)
            self._on_action(self._notification, 'accept')
        # Device is trusted or was already allowed. very small file -> auto-accept and transfer silently
        else:
            self._notification = None
            self._on_action(self._notification, "accept")

    def _on_cancel(self, agent):
        self._notification.close()
        agent.reply(obex.Error.Canceled)
开发者ID:KentVu,项目名称:blueman,代码行数:90,代码来源:TransferService.py


注:本文中的blueman.gui.Notification.Notification.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。