Gimp.ConfigWriter

Fields

None

Methods

class

new_from_fd (fd)

class

new_from_file (file, atomic, header)

class

new_from_stream (output, header)

class

new_from_string (string)

close ()

comment (comment)

comment_mode (enable)

data (data)

finish (footer)

identifier (identifier)

linefeed ()

open (name)

print_ (string, len)

ref ()

revert ()

string (string)

unref ()

Details

class Gimp.ConfigWriter

Functions for writing config info to a file for libgimpconfig.

classmethod new_from_fd(fd)
Parameters:

fd (int) –

Returns:

a new Gimp.ConfigWriter or None in case of an error

Return type:

Gimp.ConfigWriter or None

New in version 2.4.

classmethod new_from_file(file, atomic, header)
Parameters:
  • file (Gio.File) – a Gio.File

  • atomic (bool) – if True the file is written atomically

  • header (str) – text to include as comment at the top of the file

Raises:

GLib.Error

Returns:

a new Gimp.ConfigWriter or None in case of an error

Return type:

Gimp.ConfigWriter or None

Creates a new Gimp.ConfigWriter and sets it up to write to file. If atomic is True, a temporary file is used to avoid possible race conditions. The temporary file is then moved to file when the writer is closed.

New in version 2.10.

classmethod new_from_stream(output, header)
Parameters:
Raises:

GLib.Error

Returns:

a new Gimp.ConfigWriter or None in case of an error

Return type:

Gimp.ConfigWriter or None

Creates a new Gimp.ConfigWriter and sets it up to write to output.

New in version 2.10.

classmethod new_from_string(string)
Parameters:

string (GLib.String) –

Returns:

a new Gimp.ConfigWriter or None in case of an error

Return type:

Gimp.ConfigWriter or None

New in version 2.4.

close()

Closes an element opened with Gimp.ConfigWriter.open().

New in version 2.4.

comment(comment)
Parameters:

comment (str) – the comment to write (ASCII only)

Appends the comment to str and inserts linebreaks and hash-marks to format it as a comment. Note that this function does not handle non-ASCII characters.

New in version 2.4.

comment_mode(enable)
Parameters:

enable (bool) – True to enable comment mode, False to disable it

This function toggles whether the self should create commented or uncommented output. This feature is used to generate the system-wide installed gimprc that documents the default settings.

Since comments have to start at the beginning of a line, this function will insert a newline if necessary.

New in version 2.4.

data(data)
Parameters:

data (bytes) – The data to write

Writes data to self.

New in version 2.4.

finish(footer)
Parameters:

footer (str) – text to include as comment at the bottom of the file

Raises:

GLib.Error

Returns:

True if everything could be successfully written, False otherwise

Return type:

bool

This function finishes the work of self and unrefs it afterwards. It closes all open elements, appends an optional comment and releases all resources allocated by self.

Using any function except Gimp.ConfigWriter.ref() or Gimp.ConfigWriter.unref() after this function is forbidden and will trigger warnings.

New in version 2.4.

identifier(identifier)
Parameters:

identifier (str) – a NUL-terminated string

Writes an identifier to self. The string is *not* quoted and special characters are *not* escaped.

New in version 2.4.

linefeed()
open(name)
Parameters:

name (str) – name of the element to open

This function writes the opening parenthesis followed by name. It also increases the indentation level and sets a mark that can be used by Gimp.ConfigWriter.revert().

New in version 2.4.

print_(string, len)
Parameters:
  • string (str) – a string to write

  • len (int) – number of bytes from string or -1 if string is NUL-terminated.

Appends a space followed by string to the self. Note that string must not contain any special characters that might need to be escaped.

New in version 2.4.

ref()
Returns:

the same self.

Return type:

Gimp.ConfigWriter

Adds a reference to a Gimp.ConfigWriter.

New in version 3.0.

revert()

Reverts all changes to self that were done since the last call to Gimp.ConfigWriter.open(). This can only work if you didn’t call Gimp.ConfigWriter.close() yet.

New in version 2.4.

string(string)
Parameters:

string (str) – a NUL-terminated string

Writes a string value to self. The string is quoted and special characters are escaped.

New in version 2.4.

unref()

Unref a Gimp.ConfigWriter. If the reference count drops to zero, the writer is freed.

Note that at least one of the references has to be dropped using Gimp.ConfigWriter.finish().

New in version 3.0.