:right-sidebar: True FileLoader =================================================================== .. currentmodule:: gi.repository.GtkSource .. class:: FileLoader(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.GObject.Object` Load a file into a GtkSourceBuffer. A ``GtkSourceFileLoader`` object permits to load the contents of a :obj:`~gi.repository.Gio.File` or a :obj:`~gi.repository.Gio.InputStream` into a :obj:`~gi.repository.GtkSource.Buffer`\. A file loader should be used only for one load operation, including errors handling. If an error occurs, you can reconfigure the loader and relaunch the operation with :obj:`~gi.repository.FileLoader.load_async`\. Running a ``GtkSourceFileLoader`` is an undoable action for the :obj:`~gi.repository.GtkSource.Buffer`\. After a file loading, the buffer is reset to the contents provided by the :obj:`~gi.repository.Gio.File` or :obj:`~gi.repository.Gio.InputStream`\, so the buffer is set as “unmodified”, that is, :obj:`~gi.repository.Gtk.TextBuffer.set_modified` is called with :const:`False`. If the contents isn't saved somewhere (for example if you load from stdin), then you should probably call :obj:`~gi.repository.Gtk.TextBuffer.set_modified` with :const:`True` after calling :obj:`~gi.repository.FileLoader.load_finish`\. Constructors ------------ .. rst-class:: interim-class .. class:: FileLoader :no-index: .. classmethod:: new(buffer: ~gi.repository.GtkSource.Buffer, file: ~gi.repository.GtkSource.File) -> ~gi.repository.GtkSource.FileLoader Creates a new ``GtkSourceFileLoader`` object. The contents is read from the :obj:`~gi.repository.GtkSource.File`\'s location. If not already done, call :obj:`~gi.repository.File.set_location` before calling this constructor. The previous location is anyway not needed, because as soon as the file loading begins, the ``buffer`` is emptied. :param buffer: the :obj:`~gi.repository.GtkSource.Buffer` to load the contents into. :param file: the :obj:`~gi.repository.GtkSource.File`\. .. classmethod:: new_from_stream(buffer: ~gi.repository.GtkSource.Buffer, file: ~gi.repository.GtkSource.File, stream: ~gi.repository.Gio.InputStream) -> ~gi.repository.GtkSource.FileLoader Creates a new :obj:`~gi.repository.GtkSource.FileLoader` object. The contents is read from ``stream``\. :param buffer: the :obj:`~gi.repository.GtkSource.Buffer` to load the contents into. :param file: the :obj:`~gi.repository.GtkSource.File`\. :param stream: the :obj:`~gi.repository.Gio.InputStream` to load, e.g. stdin. Methods ------- .. rst-class:: interim-class .. class:: FileLoader :no-index: .. method:: get_buffer() -> ~gi.repository.GtkSource.Buffer .. method:: get_compression_type() -> ~gi.repository.GtkSource.CompressionType .. method:: get_encoding() -> ~gi.repository.GtkSource.Encoding .. method:: get_file() -> ~gi.repository.GtkSource.File .. method:: get_input_stream() -> ~gi.repository.Gio.InputStream | None .. method:: get_location() -> ~gi.repository.Gio.File | None .. method:: get_newline_type() -> ~gi.repository.GtkSource.NewlineType .. method:: load_async(io_priority: int, cancellable: ~gi.repository.Gio.Cancellable | None = None, progress_callback: ~typing.Callable[[int, int, ~typing.Any], None] | None = None, progress_callback_data: ~typing.Any = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None Loads asynchronously the file or input stream contents into the :obj:`~gi.repository.GtkSource.Buffer`\. See the :obj:`~gi.repository.Gio.AsyncResult` documentation to know how to use this function. :param io_priority: the I/O priority of the request. E.g. %G_PRIORITY_LOW, %G_PRIORITY_DEFAULT or %G_PRIORITY_HIGH. :param cancellable: optional :obj:`~gi.repository.Gio.Cancellable` object, :const:`None` to ignore. :param progress_callback: function to call back with progress information, or :const:`None` if progress information is not needed. :param progress_callback_data: user data to pass to ``progress_callback``\. :param callback: a :obj:`~gi.repository.Gio.AsyncReadyCallback` to call when the request is satisfied. :param user_data: user data to pass to ``callback``\. .. method:: load_finish(result: ~gi.repository.Gio.AsyncResult) -> bool Finishes a file loading started with :obj:`~gi.repository.FileLoader.load_async`\. If the contents has been loaded, the following :obj:`~gi.repository.GtkSource.File` properties will be updated: the location, the encoding, the newline type and the compression type. :param result: a :obj:`~gi.repository.Gio.AsyncResult`\. .. method:: set_candidate_encodings(candidate_encodings: list[~gi.repository.GtkSource.Encoding]) -> None Sets the candidate encodings for the file loading. The encodings are tried in the same order as the list. For convenience, ``candidate_encodings`` can contain duplicates. Only the first occurrence of a duplicated encoding is kept in the list. By default the candidate encodings are (in that order in the list): - If set, the :obj:`~gi.repository.GtkSource.File`\'s encoding as returned by :obj:`~gi.repository.File.get_encoding`\. - The default candidates as returned by :obj:`~gi.repository.Encoding.get_default_candidates`\. :param candidate_encodings: a list of :obj:`~gi.repository.GtkSource.Encoding`\s. Properties ---------- .. rst-class:: interim-class .. class:: FileLoader :no-index: .. attribute:: props.buffer :type: ~gi.repository.GtkSource.Buffer The type of the None singleton. .. attribute:: props.file :type: ~gi.repository.GtkSource.File The type of the None singleton. .. attribute:: props.input_stream :type: ~gi.repository.Gio.InputStream The type of the None singleton. .. attribute:: props.location :type: ~gi.repository.Gio.File The type of the None singleton.