def add_fd(self, fd, event_callback, event_type): """ Adds a fd for watch. """ condition = None if event_type & EVENT_TYPE_READ: condition = ecore.ECORE_FD_READ if event_type & EVENT_TYPE_WRITE: if not condition: condition = ecore.ECORE_FD_WRITE else: condition = condition | ecore.ECORE_FD_WRITE if event_type & EVENT_TYPE_EXCEPTION: if not condition: condition = ecore.ECORE_FD_ERROR else: condition = condition | ecore.ECORE_FD_ERROR class CallbackWrapper(object): def __init__(self, callback): self.callback = callback def __call__(self, ecore_handler): return self.callback(ecore_handler.fd_get(), self.get_condition(ecore_handler)) def get_condition(self, ecore_handler): cond = 0 flags = ecore_handler.active_get(7) if flags & ecore.ECORE_FD_READ: cond |= EVENT_TYPE_READ if flags & ecore.ECORE_FD_WRITE: cond |= EVENT_TYPE_WRITE if flags & ecore.ECORE_FD_ERROR: cond |= EVENT_TYPE_EXCEPTION return cond return ecore.fd_handler_add(fd, condition, CallbackWrapper(event_callback))
def __init__(self, edit_grp, port, agent_register, agent_unregister): #FIXME: Change localhost to a host received as parameter. self._server = EditjeServer(("localhost", port), edit_grp, agent_register, agent_unregister) self._socket_no = self._server.fileno() self._input_fd = ecore.fd_handler_add( self._server.fileno(), ecore.ECORE_FD_READ | ecore.ECORE_FD_ERROR, self._command_handle)
def add_fd(self, fd, event_callback, event_type): """ Adds a fd for watch. """ condition = None if event_type & EVENT_TYPE_READ: condition = ecore.ECORE_FD_READ if event_type & EVENT_TYPE_WRITE: if not condition: condition = ecore.ECORE_FD_WRITE else: condition = condition | ecore.ECORE_FD_WRITE if event_type & EVENT_TYPE_EXCEPTION: if not condition: condition = ecore.ECORE_FD_ERROR else: condition = condition | ecore.ECORE_FD_ERROR return ecore.fd_handler_add(fd, condition, event_callback)
def cb_read(fd_handler, a, b): data = os.read(fd_handler.fd, 50) print "ready for read:", fd_handler, ", params: a=", a, ", b=", b return True def timer_write(wfd): print "write to fd:", wfd os.write(wfd, "[some data]") return True rfd, wfd = os.pipe() fdh = ecore.fd_handler_add(rfd, ecore.ECORE_FD_READ, cb_read, 123, b="xyz") ecore.timer_add(0.2, timer_write, wfd) print "before: fdh=", fdh ecore.timer_add(1, ecore.main_loop_quit) ecore.main_loop_begin() print "main loop stopped" print "after: fdh=", fdh fdh.delete() del fdh ecore.shutdown()
sub_window = ecore.x.Window(main_window, 10, 10, 780, 580) sub_window.background_color_set(0, 0, 0xffff) sub_window.show() cmd = [ "/usr/bin/mplayer", "-slave", "-nomouseinput", "-quiet", "-wid", str(sub_window.xid), filename ] p = Popen(cmd, stdin=PIPE, stdout=PIPE, close_fds=True) def handle_read(fd_handler, file): line = file.read(1) r = bool(line and not fd_handler.has_error()) if not r: ecore.main_loop_quit() return r def on_configure(event, main_window, sub_window): if event.win == main_window: sub_window.resize(event.w - 20, event.h - 20) return True ecore.x.on_window_configure_add(on_configure, main_window, sub_window) ecore.fd_handler_add(p.stdout, ecore.ECORE_FD_ALL, handle_read, p.stdout) ecore.main_loop_begin()
print "ready for read2:", fd_handler, ", params: a=", a, ", b=", b return True def cb_read3(fd_handler, a, b): print "ready for read3:", fd_handler, ", params: a=", a, ", b=", b return False def timer_write(wfd): print "write to fd:", wfd os.write(wfd, "[some data]") return True rfd, wfd = os.pipe() fdh1 = ecore.fd_handler_add(rfd, ecore.ECORE_FD_READ, cb_read1, 123, b="xyz") fdh2 = ecore.FdHandler(rfd, ecore.ECORE_FD_READ, cb_read2, 456, b="www") fdh3 = ecore.FdHandler(rfd, ecore.ECORE_FD_READ, cb_read3, 789, b="stop next") ecore.timer_add(0.2, timer_write, wfd) print "before: fdh1=", fdh1 print "before: fdh2=", fdh2 print "before: fdh3=", fdh3 ecore.timer_add(1, ecore.main_loop_quit) ecore.main_loop_begin() print "main loop stopped" print "after: fdh1=", fdh1 print "after: fdh2=", fdh2
except IndexError, e: raise SystemExit("Usage: %s <filename>" % sys.argv[0]) main_window = ecore.x.Window(w=800, h=600) main_window.background_color_set(0xffff, 0, 0) main_window.show() sub_window = ecore.x.Window(main_window, 10, 10, 780, 580) sub_window.background_color_set(0, 0, 0xffff) sub_window.show() cmd = ["/usr/bin/mplayer", "-slave", "-nomouseinput", "-quiet", "-wid", str(sub_window.xid), filename] p = Popen(cmd, stdin=PIPE, stdout=PIPE, close_fds=True) def handle_read(fd_handler, file): line = file.read(1) r = bool(line and not fd_handler.has_error()) if not r: ecore.main_loop_quit() return r def on_configure(event, main_window, sub_window): if event.win == main_window: sub_window.resize(event.w - 20, event.h - 20) return True ecore.x.on_window_configure_add(on_configure, main_window, sub_window) ecore.fd_handler_add(p.stdout, ecore.ECORE_FD_ALL, handle_read, p.stdout) ecore.main_loop_begin()