Wp.State

g GObject.Object GObject.Object Wp.State Wp.State GObject.Object->Wp.State

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

new (name)

clear ()

get_location ()

get_name ()

load ()

save (props)

save_after_timeout (core, props)

Virtual Methods

Inherited:

GObject.Object (7)

Properties

Name

Type

Flags

Short Description

name

str

r/w/co

The file name where the state will be stored

timeout

int

r/w

The timeout in milliseconds to save the state

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Class Details

class Wp.State(**kwargs)
Bases:

GObject.Object

Abstract:

No

Structure:

Wp.StateClass

The Wp.State class saves and loads properties from a file

classmethod new(name)
Parameters:

name (str) – the state name

Returns:

the new Wp.State

Return type:

Wp.State

Constructs a new state object.

clear()

Clears the state removing its file.

get_location()
Returns:

the location of this state

Return type:

str

Gets the location of a state object.

get_name()
Returns:

the name of this state

Return type:

str

Gets the name of a state object.

load()
Returns:

a new Wp.Properties containing the state data

Return type:

Wp.Properties

Loads the state data from the file system.

This function will never fail. If it cannot load the state, for any reason, it will simply return an empty Wp.Properties, behaving as if there was no previous state stored.

save(props)
Parameters:

props (Wp.Properties) – the properties to save

Raises:

GLib.Error

Returns:

True if the properties could be saved, False otherwise

Return type:

bool

Saves new properties in the state, overwriting all previous data.

save_after_timeout(core, props)
Parameters:
  • core (Wp.Core) – the core, used to add the timeout callback to the main loop

  • props (Wp.Properties) – the properties to save. This object will be referenced and kept alive until the timeout elapses, but not deep copied.

Saves new properties in the state, overwriting all previous data, after a timeout.

This is similar to Wp.State.save() but it will save the state after a timeout has elapsed. If the state is saved again before the timeout elapses, the timeout is reset. This function is useful to avoid saving the state too often. When called consecutively, it will save the state only once. Every time it is called, it will cancel the previous timer and start a new one, resulting in timing out only after the last call.

New in version 0.5.0.

Property Details

Wp.State.props.name
Name:

name

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The file name where the state will be stored

Wp.State.props.timeout
Name:

timeout

Type:

int

Default Value:

1000

Flags:

READABLE, WRITABLE

The timeout in milliseconds to save the state