我们从Python开源项目中,提取了以下16个代码示例,用于说明如何使用gobject.IO_IN。
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()
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
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)
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)
def inputhook_gtk(): gobject.io_add_watch(sys.stdin, gobject.IO_IN, _main_quit) gtk.main() return 0
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()
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
def run(self): gobject.io_add_watch(0, gobject.IO_IN | gobject.IO_HUP, self.__stdin_cb) super(MainLoop, self).run()
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()