Module gwy :: Class Resource
[hide private]
[frames] | no frames]

Class Resource

source code

Built-in and/or user supplied application resources

Resource is a base class for various application resources. It defines common interface: questioning resource name (Resource.get_name()), modifiability (Resource.get_is_modifiable()), loading resources from files and saving them.

Instance Methods [hide private]
 
get_name()
Returns resource name.
source code
 
get_is_modifiable()
Returns whether a resource is modifiable.
source code
 
get_is_preferred()
Returns whether a resource is preferred.
source code
 
set_is_preferred(is_preferred)
Sets preferability of a resource.
source code
 
use()
Starts using a resource.
source code
 
release()
Releases a resource.
source code
 
is_used()
Tells whether a resource is currently in use.
source code
 
data_changed()
Emits signal "data-changed" on a resource.
source code
 
data_saved()
Clears is_modified flag of a resource.
source code
 
build_filename()
Builds file name a resource should be saved to.
source code
 
dump()
Dumps a resource to a textual (human readable) form.
source code
 
rename(newname)
Renames a resource, including renaming it on disk.
source code
 
delete()
Deletes a resource, including removal from disk.
source code
 
save()
Saves a resource to disk.
source code
Method Details [hide private]

get_name()

source code 

Returns resource name.

Returns:
Name of resource. The string is owned by resource and must not be modfied or freed. (string)

get_is_modifiable()

source code 

Returns whether a resource is modifiable.

Returns:
True if resource is modifiable, False if it's fixed (system) resource. (bool)

get_is_preferred()

source code 

Returns whether a resource is preferred.

Returns:
True if resource is preferred, False otherwise. (bool)

set_is_preferred(is_preferred)

source code 

Sets preferability of a resource.

Parameters:
  • is_preferred - True to make resource preferred, False to make it not preferred. (bool)

use()

source code 

Starts using a resource.

Call to this function is necessary to use a resource properly. It makes the resource to create any auxiliary structures that consume considerable amount of memory and perform other initialization to ready-to-use form.

When a resource is no longer used, it should be released with Resource.release().

In addition, it calls g_object_ref() on the resource.

Resources usually exist through almost whole program lifetime from GObject perspective, but from the viewpoint of use this method is the constructor and Resource.release() is the destructor.

release()

source code 

Releases a resource.

When the number of resource uses drops to zero, it frees all auxiliary data and returns back to `latent' form. In addition, it calls g_object_unref() on it. See Resource.use() for more.

is_used()

source code 

Tells whether a resource is currently in use.

See Resource.use() for details.

Returns:
True if resource is in use, False otherwise. (bool)

data_changed()

source code 

Emits signal "data-changed" on a resource.

It can be called only on non-constant resources. The default handler sets is_modified flag on the resource.

Mostly useful in resource implementation.

data_saved()

source code 

Clears is_modified flag of a resource.

Since: 2.8

build_filename()

source code 

Builds file name a resource should be saved to.

If the resource has not been newly created, renamed, or system it was probably loaded from file of the same name.

Returns:
Resource file name as a newly allocated string that must be freed by caller. (string)

dump()

source code 

Dumps a resource to a textual (human readable) form.

Returns:
Textual resource representation. (string)

rename(newname)

source code 

Renames a resource, including renaming it on disk.

The method renames the resource both in the inventory and on disk. The renaming must not conflict with an existing resource, constant resources cannot be renamed, etc. It is OK to rename a resource to the same name (nothing happens then).

Parameters:
  • newname - New resource name. (string)
Returns:
True if the renaming succeeded. (bool)

Since: 2.51

delete()

source code 

Deletes a resource, including removal from disk.

The method deletes the resource both in the inventory and on disk. Constant resources cannot be deleted.

Returns:
True if the removal succeeded. (bool)

Since: 2.51

save()

source code 

Saves a resource to disk.

Only non-constant resources can be saved. The file name is determined by Resource.build_filename(). The resource data are saved even if the modified flag is not set. Upon successful save, the modified flag is cleared.

Instead of saving individual resources, consider also using Resource.class_save_modified().

Returns:
True if resource was saved to disk, False otherwise. (bool)

Since: 2.62