:right-sidebar: True IOChannel =================================================================== .. currentmodule:: gi.repository.GLib .. class:: IOChannel(*args, **kwargs) :no-contents-entry: The ``GIOChannel`` data type aims to provide a portable method for using file descriptors, pipes, and sockets, and integrating them into the main event loop (see :obj:`~gi.repository.GLib.MainContext`\). Currently, full support is available on UNIX platforms; support for Windows is only partially complete. To create a new ``GIOChannel`` on UNIX systems use :obj:`~gi.repository.GLib.IOChannel.unix_new`\. This works for plain file descriptors, pipes and sockets. Alternatively, a channel can be created for a file in a system independent manner using :obj:`~gi.repository.GLib.IOChannel.new_file`\. Once a ``GIOChannel`` has been created, it can be used in a generic manner with the functions :obj:`~gi.repository.GLib.IOChannel.read_chars`\, :obj:`~gi.repository.GLib.IOChannel.write_chars`\, :obj:`~gi.repository.GLib.IOChannel.seek_position`\, and :obj:`~gi.repository.GLib.IOChannel.shutdown`\. To add a ``GIOChannel`` to the main event loop, use :obj:`~gi.repository.GLib.io_add_watch` or :obj:`~gi.repository.GLib.io_add_watch_full`\. Here you specify which events you are interested in on the ``GIOChannel``\, and provide a function to be called whenever these events occur. ``GIOChannel`` instances are created with an initial reference count of 1. :obj:`~gi.repository.GLib.IOChannel.ref` and :obj:`~gi.repository.GLib.IOChannel.unref` can be used to increment or decrement the reference count respectively. When the reference count falls to 0, the ``GIOChannel`` is freed. (Though it isn’t closed automatically, unless it was created using :obj:`~gi.repository.GLib.IOChannel.new_file`\.) Using :obj:`~gi.repository.GLib.io_add_watch` or :obj:`~gi.repository.GLib.io_add_watch_full` increments a channel’s reference count. The new functions :obj:`~gi.repository.GLib.IOChannel.read_chars`\, :obj:`~gi.repository.GLib.IOChannel.read_line`\, :obj:`~gi.repository.GLib.IOChannel.read_line_string`\, :obj:`~gi.repository.GLib.IOChannel.read_to_end`\, :obj:`~gi.repository.GLib.IOChannel.write_chars`\, :obj:`~gi.repository.GLib.IOChannel.seek_position`\, and :obj:`~gi.repository.GLib.IOChannel.flush` should not be mixed with the deprecated functions :obj:`~gi.repository.GLib.IOChannel.read`\, :obj:`~gi.repository.GLib.IOChannel.write`\, and :obj:`~gi.repository.GLib.IOChannel.seek` on the same channel. Methods ------- .. rst-class:: interim-class .. class:: IOChannel :no-index: .. method:: add_watch(condition, callback, *user_data, priority=0) :param condition: :param callback: :param user_data: :param priority: .. method:: read(max_count=-1) Reads data from a :obj:`~gi.repository.GLib.IOChannel`\. .. deprecated:: 2.2 Use :func:`~gi.repository.GLib.IOChannel.read_chars` instead. :param max_count: .. method:: readline(size_hint=-1) :param size_hint: .. method:: readlines(size_hint=-1) :param size_hint: .. method:: seek(offset, whence=0) Sets the current position in the :obj:`~gi.repository.GLib.IOChannel`\, similar to the standard library function fseek(). .. deprecated:: 2.2 Use :func:`~gi.repository.GLib.IOChannel.seek_position` instead. :param offset: an offset, in bytes, which is added to the position specified by ``type`` :param whence: .. method:: write(buf, buflen=-1) Writes data to a :obj:`~gi.repository.GLib.IOChannel`\. .. deprecated:: 2.2 Use :func:`~gi.repository.GLib.IOChannel.write_chars` instead. :param buf: the buffer containing the data to write :param buflen: .. method:: writelines(lines) :param lines: