Python gi.repository.GLib.io_add_watch() Examples

The following are 8 code examples of gi.repository.GLib.io_add_watch(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module gi.repository.GLib , or try the search function .
Example #1
Source File: network.py    From mopidy-mpd with Apache License 2.0 5 votes vote down vote up
def register_server_socket(self, fileno):
        return GLib.io_add_watch(fileno, GLib.IO_IN, self.handle_connection) 
Example #2
Source File: network.py    From mopidy-mpd with Apache License 2.0 5 votes vote down vote up
def enable_recv(self):
        if self.recv_id is not None:
            return

        try:
            self.recv_id = GLib.io_add_watch(
                self._sock.fileno(),
                GLib.IO_IN | GLib.IO_ERR | GLib.IO_HUP,
                self.recv_callback,
            )
        except OSError as exc:
            self.stop(f"Problem with connection: {exc}") 
Example #3
Source File: network.py    From mopidy-mpd with Apache License 2.0 5 votes vote down vote up
def enable_send(self):
        if self.send_id is not None:
            return

        try:
            self.send_id = GLib.io_add_watch(
                self._sock.fileno(),
                GLib.IO_OUT | GLib.IO_ERR | GLib.IO_HUP,
                self.send_callback,
            )
        except OSError as exc:
            self.stop(f"Problem with connection: {exc}") 
Example #4
Source File: inputhookgtk3.py    From Computable with MIT License 5 votes vote down vote up
def inputhook_gtk3():
    GLib.io_add_watch(sys.stdin, GLib.IO_IN, _main_quit)
    Gtk.main()
    return 0 
Example #5
Source File: btk.py    From btk with MIT License 5 votes vote down vote up
def __init__(self, ctrl_fd):
        self.ctrl_fd = ctrl_fd

        self.ctrl_io_id = GLib.io_add_watch(
            self.ctrl_fd,
            GLib.IO_IN,
            self.ctrl_data_cb
        ) 
Example #6
Source File: btk.py    From btk with MIT License 5 votes vote down vote up
def NewConnection(self, device, fd, fd_properties):
        print("New control connection (%s, %d, %s)" % (device, fd, fd_properties))
        self.conns[device] = HIDConnection(fd)

        def new_intr_conn(ssock, ip_type):
            sock, info = ssock.accept()
            print("interrupt connection:", info)
            self.conns[device].register_intr_socks(sock)
            return False

        GLib.io_add_watch(self.sock, GLib.IO_IN, new_intr_conn) 
Example #7
Source File: stats_counter.py    From Apostrophe with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, callback):
        super().__init__()

        # Worker process to handle counting.
        self.counting = False
        self.count_pending_text = None
        self.parent_conn, child_conn = Pipe()
        Process(target=self.do_count, args=(child_conn,), daemon=True).start()
        GLib.io_add_watch(
            self.parent_conn.fileno(), GLib.PRIORITY_LOW, GLib.IO_IN, self.on_counted, callback) 
Example #8
Source File: main.py    From gagar with GNU General Public License v3.0 5 votes vote down vote up
def gtk_watch_client(client):
    # watch client's websocket in GTK main loop
    # `or True` is for always returning True to keep watching
    GLib.io_add_watch(client.ws, GLib.IO_IN, lambda ws, _: client.on_message() or True)
    GLib.io_add_watch(client.ws, GLib.IO_ERR, lambda ws, _: client.subscriber.on_sock_error() or True)
    GLib.io_add_watch(client.ws, GLib.IO_HUP, lambda ws, _: client.disconnect() or True)