:right-sidebar: True FileSaver =================================================================== .. currentmodule:: gi.repository.GtkSource .. class:: FileSaver(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.GObject.Object` Save a :obj:`~gi.repository.GtkSource.Buffer` into a file. A ``GtkSourceFileSaver`` object permits to save a :obj:`~gi.repository.GtkSource.Buffer` into a :obj:`~gi.repository.Gio.File`\. A file saver should be used only for one save operation, including errors handling. If an error occurs, you can reconfigure the saver and relaunch the operation with :obj:`~gi.repository.FileSaver.save_async`\. Constructors ------------ .. rst-class:: interim-class .. class:: FileSaver :no-index: .. classmethod:: new(buffer: ~gi.repository.GtkSource.Buffer, file: ~gi.repository.GtkSource.File) -> ~gi.repository.GtkSource.FileSaver Creates a new :obj:`~gi.repository.GtkSource.FileSaver` object. The ``buffer`` will be saved to the :obj:`~gi.repository.GtkSource.File`\'s location. This constructor is suitable for a simple "save" operation, when the ``file`` already contains a non-:const:`None` :obj:`~gi.repository.GtkSource.File.props.location`\. :param buffer: the :obj:`~gi.repository.GtkSource.Buffer` to save. :param file: the :obj:`~gi.repository.GtkSource.File`\. .. classmethod:: new_with_target(buffer: ~gi.repository.GtkSource.Buffer, file: ~gi.repository.GtkSource.File, target_location: ~gi.repository.Gio.File) -> ~gi.repository.GtkSource.FileSaver Creates a new :obj:`~gi.repository.GtkSource.FileSaver` object with a target location. When the file saving is finished successfully, ``target_location`` is set to the ``file``\'s :obj:`~gi.repository.GtkSource.File.props.location` property. If an error occurs, the previous valid location is still available in :obj:`~gi.repository.GtkSource.File`\. This constructor is suitable for a "save as" operation, or for saving a new buffer for the first time. :param buffer: the :obj:`~gi.repository.GtkSource.Buffer` to save. :param file: the :obj:`~gi.repository.GtkSource.File`\. :param target_location: the :obj:`~gi.repository.Gio.File` where to save the buffer to. Methods ------- .. rst-class:: interim-class .. class:: FileSaver :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_flags() -> ~gi.repository.GtkSource.FileSaverFlags .. method:: get_location() -> ~gi.repository.Gio.File .. method:: get_newline_type() -> ~gi.repository.GtkSource.NewlineType .. method:: save_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 Saves asynchronously the buffer into the file. 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:: save_finish(result: ~gi.repository.Gio.AsyncResult) -> bool Finishes a file saving started with :obj:`~gi.repository.FileSaver.save_async`\. If the file has been saved successfully, the following :obj:`~gi.repository.GtkSource.File` properties will be updated: the location, the encoding, the newline type and the compression type. Since the 3.20 version, :obj:`~gi.repository.Gtk.TextBuffer.set_modified` is called with :const:`False` if the file has been saved successfully. :param result: a :obj:`~gi.repository.Gio.AsyncResult`\. .. method:: set_compression_type(compression_type: ~gi.repository.GtkSource.CompressionType) -> None Sets the compression type. By default the compression type is taken from the :obj:`~gi.repository.GtkSource.File`\. :param compression_type: the new compression type. .. method:: set_encoding(encoding: ~gi.repository.GtkSource.Encoding | None = None) -> None Sets the encoding. If ``encoding`` is :const:`None`, the UTF-8 encoding will be set. By default the encoding is taken from the :obj:`~gi.repository.GtkSource.File`\. :param encoding: the new encoding, or :const:`None` for UTF-8. .. method:: set_flags(flags: ~gi.repository.GtkSource.FileSaverFlags) -> None :param flags: the new flags. .. method:: set_newline_type(newline_type: ~gi.repository.GtkSource.NewlineType) -> None Sets the newline type. By default the newline type is taken from the :obj:`~gi.repository.GtkSource.File`\. :param newline_type: the new newline type. Properties ---------- .. rst-class:: interim-class .. class:: FileSaver :no-index: .. attribute:: props.buffer :type: ~gi.repository.GtkSource.Buffer The type of the None singleton. .. attribute:: props.compression_type :type: ~gi.repository.GtkSource.CompressionType The type of the None singleton. .. attribute:: props.encoding :type: ~gi.repository.GtkSource.Encoding The type of the None singleton. .. attribute:: props.file :type: ~gi.repository.GtkSource.File The type of the None singleton. .. attribute:: props.flags :type: ~gi.repository.GtkSource.FileSaverFlags The type of the None singleton. .. attribute:: props.location :type: ~gi.repository.Gio.File The type of the None singleton. .. attribute:: props.newline_type :type: ~gi.repository.GtkSource.NewlineType The type of the None singleton.