Python gobject 模块,IO_IN 实例源码

我们从Python开源项目中,提取了以下16个代码示例,用于说明如何使用gobject.IO_IN

项目:barbieri-playground    作者:barbieri    | 项目源码 | 文件源码
def _register_io_handlers(self):
        def handler(source, cond):
            if cond & gobject.IO_IN:
                if not self.fifo:
                    self.fifo = open(self.fifo_name, "w")

                self.fifo.write(source.recv(1024))
                return True
            else:
                self.log.debug("Error communicating with MPlayer")
                return False

        flags = gobject.IO_IN | gobject.IO_ERR | gobject.IO_HUP
        self.io_watcher_id = gobject.io_add_watch(self.data,
                                                  flags,
                                                  handler)
    # _register_io_handlers()
项目:code    作者:ActiveState    | 项目源码 | 文件源码
def _get_mask(self, obj):
        mask = 0
        if obj.readable():
            mask |= gobject.IO_IN | gobject.IO_PRI
        if obj.writable():
            mask |= gobject.IO_OUT
        # Only watch for errors if the socket is either readable or writable
        if mask:
            mask |= gobject.IO_ERR | gobject.IO_HUP | gobject.IO_NVAL
        return mask
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def _doReadOrWrite(self, source, condition, faildict={
        error.ConnectionDone: failure.Failure(error.ConnectionDone()),
        error.ConnectionLost: failure.Failure(error.ConnectionLost()),
        }):
        why = None
        didRead = None
        if condition & POLL_DISCONNECTED and \
               not (condition & gobject.IO_IN):
            why = main.CONNECTION_LOST
        else:
            try:
                if condition & gobject.IO_IN:
                    why = source.doRead()
                    didRead = source.doRead
                if not why and condition & gobject.IO_OUT:
                    # if doRead caused connectionLost, don't call doWrite
                    # if doRead is doWrite, don't call it again.
                    if not source.disconnected and source.doWrite != didRead:
                        why = source.doWrite()
                        didRead = source.doWrite # if failed it was in write
            except:
                why = sys.exc_info()[1]
                log.msg('Error In %s' % source)
                log.deferr()

        if why:
            self._disconnectSelectable(source, why, didRead == source.doRead)
项目:dbus-mqtt    作者:victronenergy    | 项目源码 | 文件源码
def _init_socket_handlers(self):
        if self._socket_watch is not None:
            gobject.source_remove(self._socket_watch)
        self._socket_watch = gobject.io_add_watch(self._client.socket().fileno(), gobject.IO_IN,
            self._on_socket_in)
        if self._socket_timer is None:
            self._socket_timer = gobject.timeout_add_seconds(1, exit_on_error, self._on_socket_timer)
项目:leetcode    作者:thomasyimgit    | 项目源码 | 文件源码
def inputhook_gtk():
    gobject.io_add_watch(sys.stdin, gobject.IO_IN, _main_quit)
    gtk.main()
    return 0
项目:leetcode    作者:thomasyimgit    | 项目源码 | 文件源码
def inputhook(context):
    """
    When the eventloop of prompt-toolkit is idle, call this inputhook.

    This will run the GTK main loop until the file descriptor
    `context.fileno()` becomes ready.

    :param context: An `InputHookContext` instance.
    """
    def _main_quit(*a, **kw):
        gtk.main_quit()
        return False

    gobject.io_add_watch(context.fileno(), gobject.IO_IN, _main_quit)
    gtk.main()
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def _doReadOrWrite(self, source, condition, faildict={
        error.ConnectionDone: failure.Failure(error.ConnectionDone()),
        error.ConnectionLost: failure.Failure(error.ConnectionLost()),
        }):
        why = None
        didRead = None
        if condition & POLL_DISCONNECTED and \
               not (condition & gobject.IO_IN):
            why = main.CONNECTION_LOST
        else:
            try:
                if condition & gobject.IO_IN:
                    why = source.doRead()
                    didRead = source.doRead
                if not why and condition & gobject.IO_OUT:
                    # if doRead caused connectionLost, don't call doWrite
                    # if doRead is doWrite, don't call it again.
                    if not source.disconnected and source.doWrite != didRead:
                        why = source.doWrite()
                        didRead = source.doWrite # if failed it was in write
            except:
                why = sys.exc_info()[1]
                log.msg('Error In %s' % source)
                log.deferr()

        if why:
            self._disconnectSelectable(source, why, didRead == source.doRead)
项目:Repobot    作者:Desgard    | 项目源码 | 文件源码
def inputhook_gtk():
    gobject.io_add_watch(sys.stdin, gobject.IO_IN, _main_quit)
    gtk.main()
    return 0
项目:Repobot    作者:Desgard    | 项目源码 | 文件源码
def inputhook(context):
    """
    When the eventloop of prompt-toolkit is idle, call this inputhook.

    This will run the GTK main loop until the file descriptor
    `context.fileno()` becomes ready.

    :param context: An `InputHookContext` instance.
    """
    def _main_quit(*a, **kw):
        gtk.main_quit()
        return False

    gobject.io_add_watch(context.fileno(), gobject.IO_IN, _main_quit)
    gtk.main()
项目:blender    作者:gastrodia    | 项目源码 | 文件源码
def inputhook_gtk():
    gobject.io_add_watch(sys.stdin, gobject.IO_IN, _main_quit)
    gtk.main()
    return 0
项目:blender    作者:gastrodia    | 项目源码 | 文件源码
def inputhook(context):
    """
    When the eventloop of prompt-toolkit is idle, call this inputhook.

    This will run the GTK main loop until the file descriptor
    `context.fileno()` becomes ready.

    :param context: An `InputHookContext` instance.
    """
    def _main_quit(*a, **kw):
        gtk.main_quit()
        return False

    gobject.io_add_watch(context.fileno(), gobject.IO_IN, _main_quit)
    gtk.main()
项目:yatta_reader    作者:sound88    | 项目源码 | 文件源码
def inputhook_gtk():
    gobject.io_add_watch(sys.stdin, gobject.IO_IN, _main_quit)
    gtk.main()
    return 0
项目:yatta_reader    作者:sound88    | 项目源码 | 文件源码
def inputhook(context):
    """
    When the eventloop of prompt-toolkit is idle, call this inputhook.

    This will run the GTK main loop until the file descriptor
    `context.fileno()` becomes ready.

    :param context: An `InputHookContext` instance.
    """
    def _main_quit(*a, **kw):
        gtk.main_quit()
        return False

    gobject.io_add_watch(context.fileno(), gobject.IO_IN, _main_quit)
    gtk.main()
项目:Alexa_MMDAgent    作者:jianmliu    | 项目源码 | 文件源码
def __stdin_cb(self, fd, condition):
        if condition & gobject.IO_IN:
            line = sys.stdin.readline().decode(coding, 'ignore').rstrip('\n\r')
            if len(line) > 0:
                args = line.split('|')
                self.__service.Message(args[0], args[1:])               
        if condition & gobject.IO_HUP:
            exit()
        return True
项目:Alexa_MMDAgent    作者:jianmliu    | 项目源码 | 文件源码
def run(self):
        gobject.io_add_watch(0, gobject.IO_IN | gobject.IO_HUP, self.__stdin_cb)
        super(MainLoop, self).run()
项目:barbieri-playground    作者:barbieri    | 项目源码 | 文件源码
def _register_io_handlers(self):
        flags_err = gobject.IO_ERR | gobject.IO_HUP
        def handler(fd, flags):
            if flags & flags_err:
                return False
            else:
                while self.playing:
                    line = self._readline()

                    if not line:
                        return True
                    elif line[:2] == "A:" and line[-1] =="\r":
                        pieces = line.split()
                        pos = float(pieces[1])
                        self.emit("pos", pos)
                        return True
                    elif line == "Exiting... (Quit)\n":
                        self.proc.wait()
                        self.proc = None
                        self.emit("eos")
                        self.emit("state-changed", PlayerEngine.STATE_NONE)
                        return False
                    elif line == "Starting playback...\n":
                        # make buffer empty
                        while line:
                            line = self._readline(100)
                            if line and line[:2] == "A:" and line[-1] == "\r":
                                break

                        self.set_volume(self.volume)
                        self.set_mute(self.mute)
                        self.set_fullscreen(self.fullscreen)
                        self._query_media_info()
                        self._register_state_timeout()
                        self.emit("state-changed", PlayerEngine.STATE_PLAYING)
                        return True
                    else:
                        self.log.debug("Ignored MPlayer output: %r" % line)

                return True

        flags = gobject.IO_IN | gobject.IO_PRI | flags_err
        self.out_watcher = gobject.io_add_watch(self.proc.stdout,
                                                flags, handler)
    # _register_io_handlers()