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


Python SessionBus.subscribe方法代码示例

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


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

示例1: __init__

# 需要导入模块: from pydbus import SessionBus [as 别名]
# 或者: from pydbus.SessionBus import subscribe [as 别名]
    def __init__(self, *args):
        _IdleObject.__init__(self)
        context = GObject.MainContext.default()

        self.bucket = bucket = Queue.Queue()  # NOQA
        self.hello = None

        # with SessionBus() as bus:
        bus = SessionBus()
        ss = bus.get("org.scarlett", object_path='/org/scarlett/Listener')  # NOQA
        time.sleep(1)

        ss_failed_signal = bus.subscribe(sender=None,
                                         iface="org.scarlett.Listener",
                                         signal="SttFailedSignal",
                                         object="/org/scarlett/Listener",
                                         arg0=None,
                                         flags=0,
                                         signal_fired=player_cb)

        ss_rdy_signal = bus.subscribe(sender=None,
                                      iface="org.scarlett.Listener",
                                      signal="ListenerReadySignal",
                                      object="/org/scarlett/Listener",
                                      arg0=None,
                                      flags=0,
                                      signal_fired=player_cb)

        ss_kw_rec_signal = bus.subscribe(sender=None,
                                         iface="org.scarlett.Listener",
                                         signal="KeywordRecognizedSignal",
                                         object="/org/scarlett/Listener",
                                         arg0=None,
                                         flags=0,
                                         signal_fired=player_cb)

        ss_cmd_rec_signal = bus.subscribe(sender=None,
                                          iface="org.scarlett.Listener",
                                          signal="CommandRecognizedSignal",
                                          object="/org/scarlett/Listener",
                                          arg0=None,
                                          flags=0,
                                          signal_fired=command_cb)

        ss_cancel_signal = bus.subscribe(sender=None,
                                         iface="org.scarlett.Listener",
                                         signal="ListenerCancelSignal",
                                         object="/org/scarlett/Listener",
                                         arg0=None,
                                         flags=0,
                                         signal_fired=player_cb)

        pp.pprint((ss_failed_signal,
                   ss_rdy_signal,
                   ss_kw_rec_signal,
                   ss_cmd_rec_signal,
                   ss_cancel_signal))

        logger.debug("ss_failed_signal: {}".format(ss_failed_signal))
        logger.debug("ss_rdy_signal: {}".format(ss_rdy_signal))
        logger.debug("ss_kw_rec_signal: {}".format(ss_kw_rec_signal))
        logger.debug("ss_cmd_rec_signal: {}".format(ss_cmd_rec_signal))
        logger.debug("ss_cancel_signal: {}".format(ss_cancel_signal))

        ss.emitConnectedToListener('ScarlettTasker')

        loop.run()

        # THE ACTUAL THREAD BIT
        # self.manager = FooThreadManager(3)

        try:
            print("ScarlettTasker Thread Started")
        except Exception:
            ss_failed_signal.disconnect()
            ss_rdy_signal.disconnect()
            ss_kw_rec_signal.disconnect()
            ss_cmd_rec_signal.disconnect()
            ss_cancel_signal.disconnect()
            loop.quit()
            self.bucket.put(sys.exc_info())
            raise
开发者ID:bossjones,项目名称:scarlett-dbus-poc,代码行数:84,代码来源:generator_tasker.py

示例2: ScarlettListenerI

# 需要导入模块: from pydbus import SessionBus [as 别名]
# 或者: from pydbus.SessionBus import subscribe [as 别名]

#.........这里部分代码省略.........
                           'fakesink']

        return _gst_launch

    # @trace
    def cancel(self):
        """
        Threads in python are not cancellable, so we implement our own
        cancellation logic
        """
        self.cancelled = True

    @abort_on_exception
    def run(self, event=None):
        # TODO: WE NEED TO USE A THREADING EVENT OR A RLOCK HERE TO WAIT TILL DBUS SERVICE IS RUNNING TO CONNECT
        # TODO: SIGNALS TO THE DBUS PROXY METHODS WE WANT TO USE
        # TODO: lock.acquire() / event / condition
        # TODO: self.connect_to_dbus()
        # TODO: self.setup_dbus_callbacks_handlers()
        self._connect_to_dbus()
        self.init_gst()
        print "Running %s" % str(self)
        self.play()
        self.emit('playback-status-changed')
        self.emit('playing-changed')
        # FIXME: is this needed? # self.mainloop.run()

    def _connect_to_dbus(self):
        self.bus = SessionBus()
        self.dbus_proxy = self.bus.get("org.scarlett", object_path='/org/scarlett/Listener')  # NOQA
        self.dbus_proxy.emitConnectedToListener('ScarlettListener')
        sleep(2)
        logger.info('_connect_to_dbus')
        ss_cancel_signal = self.bus.subscribe(sender=None,
                                         iface="org.scarlett.Listener",
                                         signal="ListenerCancelSignal",
                                         object="/org/scarlett/Listener",
                                         arg0=None,
                                         flags=0,
                                         signal_fired=self.cancel_listening)

    # NOTE: This function generates the dot file, checks that graphviz in installed and
    # then finally generates a png file, which it then displays
    def on_debug_activate(self):
        dotfile = "/home/pi/dev/bossjones-github/scarlett-dbus-poc/_debug/generator-listener.dot"
        pngfile = "/home/pi/dev/bossjones-github/scarlett-dbus-poc/_debug/generator-listener-pipeline.png"  # NOQA
        if os.access(dotfile, os.F_OK):
            os.remove(dotfile)
        if os.access(pngfile, os.F_OK):
            os.remove(pngfile)
        Gst.debug_bin_to_dot_file(self.pipelines_stack[0],
                                  Gst.DebugGraphDetails.ALL, "generator-listener")
        os.system('/usr/bin/dot' + " -Tpng -o " + pngfile + " " + dotfile)

    def result(self, final_hyp):
        """Forward result signals on the bus to the main thread."""
        logger.debug("Inside result function")
        logger.debug("final_hyp: {}".format(final_hyp))
        pp.pprint(final_hyp)
        logger.debug("kw_to_find: {}".format(self.kw_to_find))
        if final_hyp in self.kw_to_find and final_hyp != '':
            logger.debug(
                "HYP-IS-SOMETHING: " +
                final_hyp +
                "\n\n\n")
            self.failed = 0
开发者ID:bossjones,项目名称:scarlett-dbus-poc,代码行数:70,代码来源:generator_listener.py

示例3: ScarlettListenerI

# 需要导入模块: from pydbus import SessionBus [as 别名]
# 或者: from pydbus.SessionBus import subscribe [as 别名]

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

    def cancel(self):
        """
        Threads in python are not cancellable, so we implement our own
        cancellation logic
        """
        self.cancelled = True

    @abort_on_exception
    def run(self, event=None):
        # TODO: WE NEED TO USE A THREADING EVENT OR A RLOCK HERE TO WAIT TILL DBUS SERVICE IS RUNNING TO CONNECT
        # TODO: SIGNALS TO THE DBUS PROXY METHODS WE WANT TO USE
        # TODO: lock.acquire() / event / condition
        # TODO: self.connect_to_dbus()
        # TODO: self.setup_dbus_callbacks_handlers()
        self._connect_to_dbus()
        self.init_gst()
        print("Running {}".format(str(self)))
        self.play()
        self.emit("playback-status-changed")
        self.emit("playing-changed")
        # FIXME: is this needed? # self.mainloop.run()

    def _connect_to_dbus(self):
        self.bus = SessionBus()
        self.dbus_proxy = self.bus.get(
            "org.scarlett", object_path="/org/scarlett/Listener"
        )  # NOQA
        self.dbus_proxy.emitConnectedToListener("ScarlettListener")
        time.sleep(2)
        logger.info("_connect_to_dbus")
        # TODO: Add a ss_cancel_signal.disconnect() function later
        ss_cancel_signal = self.bus.subscribe(
            sender=None,
            iface="org.scarlett.Listener",
            signal="ListenerCancelSignal",
            object="/org/scarlett/Listener",
            arg0=None,
            flags=0,
            signal_fired=self.on_cancel_listening,
        )

    # NOTE: This function generates the dot file, checks that graphviz in installed and
    # then finally generates a png file, which it then displays
    def on_debug_activate(self):
        # FIXME: This needs to use dynamic paths, it's possible that we're having issues because of order of operations
        # FIXME: STATIC PATH 7/3/2018
        # dotfile = (
        #     "/home/pi/dev/bossjones-github/scarlett_os/_debug/generator-listener.dot"
        # )
        # pngfile = "/home/pi/dev/bossjones-github/scarlett_os/_debug/generator-listener-pipeline.png"  # NOQA
        dotfile = self._dotfile_listener
        pngfile = self._pngfile_listener

        if os.access(dotfile, os.F_OK):
            os.remove(dotfile)
        if os.access(pngfile, os.F_OK):
            os.remove(pngfile)

        Gst.debug_bin_to_dot_file(
            self.pipelines_stack[0], Gst.DebugGraphDetails.ALL, "generator-listener"
        )

        cmd = "/usr/bin/dot -Tpng -o {pngfile} {dotfile}".format(
            pngfile=pngfile, dotfile=dotfile
开发者ID:bossjones,项目名称:scarlett_os,代码行数:70,代码来源:listener.py

示例4: SessionBus

# 需要导入模块: from pydbus import SessionBus [as 别名]
# 或者: from pydbus.SessionBus import subscribe [as 别名]
    loop = GLib.MainLoop()

    recieved_signals = []

    from pydbus import SessionBus

    bus = SessionBus()
    ss = bus.get("org.scarlett", object_path="/org/scarlett/Listener")
    time.sleep(0.5)

    # taken from tasker
    ss_failed_signal = bus.subscribe(
        sender=None,
        iface="org.scarlett.Listener",
        signal="SttFailedSignal",
        object="/org/scarlett/Listener",
        arg0=None,
        flags=0,
        signal_fired=catchall_handler,
    )

    ss_rdy_signal = bus.subscribe(
        sender=None,
        iface="org.scarlett.Listener",
        signal="ListenerReadySignal",
        object="/org/scarlett/Listener",
        arg0=None,
        flags=0,
        signal_fired=catchall_handler,
    )
开发者ID:bossjones,项目名称:scarlett_os,代码行数:32,代码来源:receiver.py


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