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

Class Selection

source code

Data selection base class

Selection is an abstract class representing data selections. Particular selection types are defined by vector layer modules.

Selections behave as flat arrays of coordinates. They are however logically split into selection objects (points, lines, rectangles), characteristic for each selection type. For example, to describe a horizontal line one needs only one coordinate, for a point two coordinates are needed, rectangle or arbitrary line need four. Selection.get_object_size() can be used to generically determine the number of coordinates used to describe a one selection object.

The number of selection objects in a selection can vary, Selection.set_max_objects() sets the maximum possible number. Functions for getting and setting individual selection objects (Selection.get_object(), Selection.set_object()) or complete selection (Selection.get_data(), Selection.set_data()) are available. The method Selection.set_data() with None second argument is also used to determine the number of selected object.

Instance Methods [hide private]
 
get_object_size()
Gets the number of coordinates that make up a one selection object.
source code
 
clear()
Clears a selection.
source code
 
delete_object(i)
Deletes a one selection object.
source code
 
get_max_objects()
Gets the maximum number of selected objects.
source code
 
set_max_objects(max_objects)
Sets the maximum number of objects allowed to select.
source code
 
is_full()
Checks whether the maximum number of objects is selected.
source code
 
crop(xmin, ymin, xmax, ymax)
Limits objects in a selection to a rectangle.
source code
 
move(vx, vy)
Moves entire selection in plane by given vector.
source code
 
filter(filter, data)
Removes selection objects matching certain criteria.
source code
 
changed(i)
Emits "changed" signal on a selection.
source code
 
finished()
Emits "finished" signal on a selection.
source code
 
get_data()
Get selection coordinates as single flat list.
source code
 
get_object(i)
Gets one selection object.
source code
 
set_data(data)
Sets selection data.
source code
 
set_object(i, data)
Sets one selection object.
source code
 
duplicate()
Convenience macro doing gwy_serializable_duplicate() with all the necessary typecasting.
source code
Method Details [hide private]

get_object_size()

source code 

Gets the number of coordinates that make up a one selection object.

Returns:
The number of coordinates in one selection object. (int)

delete_object(i)

source code 

Deletes a one selection object.

Since there cannot be holes in the object list, the rest of selection objects is moved to close the gap.

Parameters:
  • i - Index of object to delete. (int)

get_max_objects()

source code 

Gets the maximum number of selected objects.

Returns:
The maximum number of selected objects; (int)

set_max_objects(max_objects)

source code 

Sets the maximum number of objects allowed to select.

When selection reaches this number of selected objects, it emits "finished" signal.

Parameters:
  • max_objects - The maximum number of objects allowed to select. Note particular selection types may allow only specific values. (int)

is_full()

source code 

Checks whether the maximum number of objects is selected.

Returns:
True when the maximum possible number of objects is selected, False otherwise. (bool)

crop(xmin, ymin, xmax, ymax)

source code 

Limits objects in a selection to a rectangle.

Objects that are fully outside specified rectangle are removed. Objects partially outside may be removed or cut, depending on what makes sense for the specific selection type. If the selection class does not implement this method then all objects are removed.

Parameters:
  • xmin - Minimum x-coordinate. (float)
  • ymin - Minimum y-coordinate. (float)
  • xmax - Maximum x-coordinate. (float)
  • ymax - Maximum y-coordinate. (float)

Since: 2.16

move(vx, vy)

source code 

Moves entire selection in plane by given vector.

If a selection class does not implement this operation the selection remains unchanged. Bult-in selection classes generally implement this operation if it is meaningful. For some, such as SelectionLattice, it is not meaningful and moving SelectionLattice thus does not do anything.

Parameters:
  • vx - Value to add to all x-coordinates. (float)
  • vy - Value to add to all y-coordinates. (float)

Since: 2.43

filter(filter, data)

source code 

Removes selection objects matching certain criteria.

Parameters:
  • filter - Function returning True for objects that should be kept, False for objects that should be removed. (SelectionFilterFunc)
  • data - User data passed to filter. (gpointer)

Since: 2.16

changed(i)

source code 

Emits "changed" signal on a selection.

Parameters:
  • i - Index of object that changed. Use -1 when not applicable, e.g., when complete selection was changed, cleared, or truncated. (int)

get_data()

source code 

Get selection coordinates as single flat list.

Returns:
a list of selected data (list)

get_object(i)

source code 

Gets one selection object.

Parameters:
  • i - Index of object to get. (int)
Returns:
True if there was such an object and data was filled. (list)

set_data(data)

source code 

Sets selection data.

Parameters:
  • data - Selection data, that is an array nselected * Selection.get_object_size() long with selected object coordinates. (list)

set_object(i, data)

source code 

Sets one selection object.

This method can be also used to append objects (if the maximum number is not exceeded). Since there cannot be holes in the object list, i must be then equal to either the number of selected objects or special value -1 meaning append to end.

Parameters:
  • i - Index of object to set. (int)
  • data - Object selection data. It's an array of coordinates whose precise meaning is defined by particular selection types. (list)

duplicate()

source code 

Convenience macro doing gwy_serializable_duplicate() with all the necessary typecasting.

Returns:
(Selection)