Module gwy :: Class Inventory
[show private | hide private]
[frames | no frames]

Class Inventory


Inventory The Inventory struct contains private data only and should be accessed using the functions below.
Method Summary
  __init__(itype)
Creates a new inventory.
  can_make_copies()
Returns: True if inventory can create new items itself.
  delete_item(name)
Deletes an item from an inventory.
  delete_nth_item(n)
Deletes an item on given position from an inventory.
  forget_order()
Forces an inventory to be unsorted.
  get_default_item()
Returns: The default item.
  get_default_item_name()
Returns: The default item name, NULL if no default name is set.
  get_item(name)
Looks up an item in an inventory.
  get_item_position(name)
Finds position of an item in an inventory.
  get_n_items()
Returns: The number of items.
  item_updated(name)
Notifies inventory an item was updated.
  nth_item_updated(n)
Notifies inventory item on given position was updated.
  restore_order()
Assures an inventory is sorted.
  set_default_item_name(name)
Sets the default of an inventory.
  store_new()
Creates a new GtkTreeModel wrapper around a Inventory.
  UNIMPLEMENTED_find(predicate, user_data)
Finds an inventory item using user-specified predicate function.
  UNIMPLEMENTED_foreach(function, user_data)
Calls a function on each item of an inventory, in order.
  UNIMPLEMENTED_get_item_or_default(name)
Looks up an item in an inventory, eventually falling back to default.
  UNIMPLEMENTED_get_item_type()
Returns: The item type.
  UNIMPLEMENTED_get_nth_item(n)
Returns: Item at given position.
  UNIMPLEMENTED_insert_item(item)
Inserts an item into an inventory.
  UNIMPLEMENTED_insert_nth_item(item, n)
Inserts an item to an explicit position in an inventory.
  UNIMPLEMENTED_new_item(name, newname)
Creates a new item as a copy of existing one and inserts it to inventory.
  UNIMPLEMENTED_rename_item(name, newname)
Renames an inventory item.

Method Details

__init__(itype)
(Constructor)

Creates a new inventory.
Returns:
The newly created inventory.

can_make_copies()

Returns: True if inventory can create new items itself.
Returns:
True if inventory can create new items itself.

delete_item(name)

Deletes an item from an inventory.
Parameters:
name - Name of item to delete. (string)
Returns:
True if item was deleted.

delete_nth_item(n)

Deletes an item on given position from an inventory.
Parameters:
n - Position of item to delete. (int)
Returns:
True if item was deleted.

forget_order()

Forces an inventory to be unsorted.

Item positions don't change, but future Inventory.insert_item() won't try to insert items in order.

get_default_item()

Returns: The default item. If there is no default item, NULL is returned.
Returns:
The default item. If there is no default item, NULL is returned.

get_default_item_name()

Returns: The default item name, NULL if no default name is set.
Returns:
The default item name, NULL if no default name is set. Item of this name may or may not exist in the inventory.

get_item(name)

Looks up an item in an inventory.
Parameters:
name - Item name. (string)
Returns:
Item called name, or NULL if there is no such item.

get_item_position(name)

Finds position of an item in an inventory.
Parameters:
name - Item name. (string)
Returns:
Item position, or -1 if there is no such item.

get_n_items()

Returns: The number of items.
Returns:
The number of items.

item_updated(name)

Notifies inventory an item was updated.

This function makes sense primarily for non-object items, as object items can notify inventory via signals.
Parameters:
name - Item name. (string)

nth_item_updated(n)

Notifies inventory item on given position was updated.

This function makes sense primarily for non-object items, as object items can implement Watchable interface.
Parameters:
n - Item position. (int)

restore_order()

Assures an inventory is sorted.

set_default_item_name(name)

Sets the default of an inventory.

Item name must already exist in the inventory.
Parameters:
name - Item name, pass NULL to unset default item. (string)

store_new()

Creates a new GtkTreeModel wrapper around a Inventory.
Returns:
The newly created inventory store.

UNIMPLEMENTED_find(predicate, user_data)

Finds an inventory item using user-specified predicate function.

predicate is called for each item in inventory (in order) until it returns True. Its arguments are the same as in Inventory.foreach().
Parameters:
predicate - A function testing some item property. It must not modify inventory. (GHRFunc)
user_data - Data passed to predicate. (gpointer)
Returns:
The item for which predicate returned True. If there is no such item in the inventory, NULL is returned.

UNIMPLEMENTED_foreach(function, user_data)

Calls a function on each item of an inventory, in order.

function's first argument is item position (transformed with GUINT_TO_POINTER()), second is item pointer, and the last is user_data.
Parameters:
function - A function to call on each item. It must not modify inventory. (GHFunc)
user_data - Data passed to function. (gpointer)

UNIMPLEMENTED_get_item_or_default(name)

Looks up an item in an inventory, eventually falling back to default.

The lookup order is: item of requested name, default item (if set), any inventory item, NULL (can happen only when inventory is empty).
Parameters:
name - Item name. (string)
Returns:
Item called name, or default item.

UNIMPLEMENTED_get_item_type()

Returns: The item type. It is owned by inventory and must not be modified
Returns:
The item type. It is owned by inventory and must not be modified or freed.

UNIMPLEMENTED_get_nth_item(n)

Returns: Item at given position.
Parameters:
n - Item position. It must be between zero and the number of items in inventory, inclusive. If it is equal to the number of items, NULL is returned. In other words, inventory behaves like a NULL-terminated array, you can simply iterate over it until Inventory.get_nth_item() returns NULL. (int)
Returns:
Item at given position.

UNIMPLEMENTED_insert_item(item)

Inserts an item into an inventory.

Item of the same name must not exist yet.

If the inventory is sorted, item is inserted to keep order. If the inventory is unsorted, item is simply added to the end.
Parameters:
item - An item to insert. (gpointer)
Returns:
item, for convenience.

UNIMPLEMENTED_insert_nth_item(item, n)

Inserts an item to an explicit position in an inventory.

Item of the same name must not exist yet.
Parameters:
item - An item to insert. (gpointer)
n - Position to insert item to. (int)
Returns:
item, for convenience.

UNIMPLEMENTED_new_item(name, newname)

Creates a new item as a copy of existing one and inserts it to inventory.

The newly created item can be called differently than newname if that already exists.
Parameters:
name - Name of item to duplicate, may be NULL to use default item (the same happens when name does not exist). (string)
newname - Name of new item, it must not exist yet. It may be NULL, the new name is based on name then. (string)
Returns:
The newly added item.

UNIMPLEMENTED_rename_item(name, newname)

Renames an inventory item.

If an item of name newname is already present in inventory, the rename will fail.
Parameters:
name - Name of item to rename. (string)
newname - New name of item. (string)
Returns:
The item, for convenience.

Generated by Epydoc 2.1 on Tue Dec 30 04:01:43 2008 http://epydoc.sf.net