gengrid Module

../_images/gengrid-preview.png

Widget description

This widget aims to position objects in a grid layout while actually creating and rendering only the visible ones, using the same idea as the Genlist: the user defines a class for each item, specifying functions that will be called at object creation, deletion, etc. When those items are selected by the user, a callback function is issued. Users may interact with a gengrid via the mouse (by clicking on items to select them and clicking on the grid’s viewport and swiping to pan the whole view) or via the keyboard, navigating through item with the arrow keys.

Scrollable Interface

This widget supports the scrollable interface.

If you wish to control the scolling behaviour using these functions, inherit both the widget class and the Scrollable class using multiple inheritance, for example:

class ScrollableGenlist(Genlist, Scrollable):
    def __init__(self, canvas, *args, **kwargs):
        Genlist.__init__(self, canvas)

Gengrid layouts

Gengrid may layout its items in one of two possible layouts:

  • horizontal or
  • vertical.

When in “horizontal mode”, items will be placed in columns, from top to bottom and, when the space for a column is filled, another one is started on the right, thus expanding the grid horizontally, making for horizontal scrolling. When in “vertical mode” , though, items will be placed in rows, from left to right and, when the space for a row is filled, another one is started below, thus expanding the grid vertically (and making for vertical scrolling).

Gengrid items

An item in a gengrid can have 0 or more texts (they can be regular text or textblock Evas objects - that’s up to the style to determine), 0 or more contents (which are simply objects swallowed into the gengrid item’s theming Edje object) and 0 or more boolean states, which have the behavior left to the user to define. The Edje part names for each of these properties will be looked up, in the theme file for the gengrid, under the Edje (string) data items named "texts", "contents" and "states", respectively. For each of those properties, if more than one part is provided, they must have names listed separated by spaces in the data fields. For the default gengrid item theme, we have one text part ("elm.text"), two content parts ("elm.swalllow.icon" and "elm.swallow.end") and no state parts.

A gengrid item may be at one of several styles. Elementary provides one by default - “default”, but this can be extended by system or application custom themes/overlays/extensions (see Theme for more details).

Gengrid item classes

In order to have the ability to add and delete items on the fly, gengrid implements a class (callback) system where the application provides a structure with information about that type of item (gengrid may contain multiple different items with different classes, states and styles). Gengrid will call the functions in this struct (methods) when an item is “realized” (i.e., created dynamically, while the user is scrolling the grid). All objects will simply be deleted when no longer needed with evas_object_del(). The #Elm_Gengrid_Item_Class structure contains the following members:

  • item_style - This is a constant string and simply defines the name of the item style. It must be specified and the default should be "default".
  • func.text_get - This function is called when an item object is actually created. The data parameter will point to the same data passed to elm_gengrid_item_append() and related item creation functions. The obj parameter is the gengrid object itself, while the part one is the name string of one of the existing text parts in the Edje group implementing the item’s theme. This function must return a strdup’()ed string, as the caller will free() it when done. See GengridItem.text_get().
  • func.content_get - This function is called when an item object is actually created. The data parameter will point to the same data passed to GengridItem.append_to() and related item creation functions. The obj parameter is the gengrid object itself, while the part one is the name string of one of the existing (content) swallow parts in the Edje group implementing the item’s theme. It must return None, when no content is desired, or a valid object handle, otherwise. The object will be deleted by the gengrid on its deletion or when the item is “unrealized”. See GengridItem.content_get().
  • func.state_get - This function is called when an item object is actually created. The data parameter will point to the same data passed to GengridItem.append_to() and related item creation functions. The obj parameter is the gengrid object itself, while the part one is the name string of one of the state parts in the Edje group implementing the item’s theme. Return False for false/off or True for true/on. Gengrids will emit a signal to its theming Edje object with "elm,state,xxx,active" and "elm" as “emission” and “source” arguments, respectively, when the state is true (the default is false), where xxx is the name of the (state) part. See #Elm_Gengrid_Item_State_Get_Cb.
  • func.del - This is called when elm_object_item_del() is called on an item or elm_gengrid_clear() is called on the gengrid. This is intended for use when gengrid items are deleted, so any data attached to the item (e.g. its data parameter on creation) can be deleted. See GengridItem.delete().

Usage hints

If the user wants to have multiple items selected at the same time, elm_gengrid_multi_select_set() will permit it. If the gengrid is single-selection only (the default), then elm_gengrid_select_item_get() will return the selected item or None, if none is selected. If the gengrid is under multi-selection, then elm_gengrid_selected_items_get() will return a list (that is only valid as long as no items are modified (added, deleted, selected or unselected) of child items on a gengrid.

If an item changes (internal (boolean) state, text or content changes), then use elm_gengrid_item_update() to have gengrid update the item with the new state. A gengrid will re-“realize” the item, thus calling the functions in the #Elm_Gengrid_Item_Class set for that item.

To programmatically (un)select an item, use elm_gengrid_item_selected_set(). To get its selected state use elm_gengrid_item_selected_get(). To make an item disabled (unable to be selected and appear differently) use elm_object_item_disabled_set() to set this and elm_object_item_disabled_get() to get the disabled state.

Grid cells will only have their selection smart callbacks called when firstly getting selected. Any further clicks will do nothing, unless you enable the “always select mode”, with elm_gengrid_select_mode_set() as ELM_OBJECT_SELECT_MODE_ALWAYS, thus making every click to issue selection callbacks. elm_gengrid_select_mode_set() as ELM_OBJECT_SELECT_MODE_NONE will turn off the ability to select items entirely in the widget and they will neither appear selected nor call the selection smart callbacks.

Remember that you can create new styles and add your own theme augmentation per application with elm_theme_extension_add(). If you absolutely must have a specific style that overrides any theme the user or system sets up you can use elm_theme_overlay_add() to add such a file.

Gengrid smart events

Smart events that you can add callbacks for are:

  • activated - The user has double-clicked or pressed (enter|return|spacebar) on an item. The event_info parameter is the gengrid item that was activated.
  • clicked,double - The user has double-clicked an item. The event_info parameter is the gengrid item that was double-clicked.
  • longpressed - This is called when the item is pressed for a certain amount of time. By default it’s 1 second.
  • selected - The user has made an item selected. The event_info parameter is the gengrid item that was selected.
  • unselected - The user has made an item unselected. The event_info parameter is the gengrid item that was unselected.
  • realized - This is called when the item in the gengrid has its implementing Evas object instantiated, de facto. event_info is the gengrid item that was created. The object may be deleted at any time, so it is highly advised to the caller not to use the object returned from GengridItem.object, because it may point to freed objects.
  • unrealized - This is called when the implementing Evas object for this item is deleted. event_info is the gengrid item that was deleted.
  • changed - Called when an item is added, removed, resized or moved and when the gengrid is resized or gets “horizontal” property changes.
  • scroll,anim,start - This is called when scrolling animation has started.
  • scroll,anim,stop - This is called when scrolling animation has stopped.
  • drag,start,up - Called when the item in the gengrid has been dragged (not scrolled) up.
  • drag,start,down - Called when the item in the gengrid has been dragged (not scrolled) down.
  • drag,start,left - Called when the item in the gengrid has been dragged (not scrolled) left.
  • drag,start,right - Called when the item in the gengrid has been dragged (not scrolled) right.
  • drag,stop - Called when the item in the gengrid has stopped being dragged.
  • drag - Called when the item in the gengrid is being dragged.
  • scroll - called when the content has been scrolled (moved).
  • scroll,drag,start - called when dragging the content has started.
  • scroll,drag,stop - called when dragging the content has stopped.
  • edge,top - This is called when the gengrid is scrolled until the top edge.
  • edge,bottom - This is called when the gengrid is scrolled until the bottom edge.
  • edge,left - This is called when the gengrid is scrolled until the left edge.
  • edge,right - This is called when the gengrid is scrolled until the right edge.
  • moved - This is called when a gengrid item is moved by a user interaction in a reorder mode. The %c event_info parameter is the item that was moved.
  • index,update - This is called when a gengrid item index is changed. Note that this callback is called while each item is being realized.
  • highlighted - an item in the list is highlighted. This is called when the user presses an item or keyboard selection is done so the item is physically highlighted. The %c event_info parameter is the item that was highlighted.
  • unhighlighted - an item in the list is unhighlighted. This is called when the user releases an item or keyboard selection is moved so the item is physically unhighlighted. The %c event_info parameter is the item that was unhighlighted.
  • language,changed - This is called when the program’s language is changed. Call the elm_gengrid_realized_items_update() if items text should be translated.
  • focused - When the gengrid has received focus. (since 1.8)
  • unfocused - When the gengrid has lost focus. (since 1.8)

Enumerations

Items’ scroll to types

efl.elementary.gengrid.ELM_GENLIST_ITEM_SCROLLTO_NONE

No scroll to

efl.elementary.gengrid.ELM_GENLIST_ITEM_SCROLLTO_IN

Scroll to the nearest viewport

efl.elementary.gengrid.ELM_GENLIST_ITEM_SCROLLTO_TOP

Scroll to the top of viewport

efl.elementary.gengrid.ELM_GENLIST_ITEM_SCROLLTO_MIDDLE

Scroll to the middle of viewport

class efl.elementary.gengrid.Gengrid

Bases: efl.elementary.object.Object

This is the class that actually implements the widget.

align

This sets the alignment of the whole grid of items of a gengrid within its given viewport. By default, those values are both 0.5, meaning that the gengrid will have its items grid placed exactly in the middle of its viewport.

Note

If given alignment values are out of the cited ranges, they’ll be changed to the nearest boundary values on the valid ranges.

Type :tuple of floats
at_xy_item_get(int x, int y) -> (GengridItem, int xposret, int yposret)

Get the item that is at the x, y canvas coords.

Parameters:
  • x – The input x coordinate
  • y – The input y coordinate
Returns:

(GengridItem, int xposret, int yposret)

This returns the item at the given coordinates (which are canvas relative, not object-relative). If an item is at that coordinate, that item handle is returned, and if @p xposret is not NULL, the integer pointed to is set to a value of -1, 0 or 1, depending if the coordinate is on the left portion of that item (-1), on the middle section (0) or on the right part (1). if @p yposret is not NULL, the integer pointed to is set to a value of -1, 0 or 1, depending if the coordinate is on the upper portion of that item (-1), on the middle section (0) or on the lower part (1). If NULL is returned as an item (no item found there), then posret may indicate -1 or 1 based if the coordinate is above or below all items respectively in the gengrid.

New in version 1.8.

bounce

Deprecated since version 1.8: You should combine with Scrollable class instead.

callback_changed_add()

Called when an item is added, removed, resized or moved and when the gengrid is resized or gets “horizontal” property changes.

callback_drag_add()

Called when the item in the gengrid is being dragged.

callback_drag_start_down_add()

Called when the item in the gengrid has been dragged (not scrolled) down.

callback_drag_start_left_add()

Called when the item in the gengrid has been dragged (not scrolled) left.

callback_drag_start_right_add()

Called when the item in the gengrid has been dragged (not scrolled) right.

callback_drag_start_up_add()

Called when the item in the gengrid has been dragged (not scrolled) up.

callback_drag_stop_add()

Called when the item in the gengrid has stopped being dragged.

callback_edge_bottom_add()

This is called when the gengrid is scrolled until the bottom edge.

callback_edge_left_add()

This is called when the gengrid is scrolled until the left edge.

callback_edge_right_add()

This is called when the gengrid is scrolled until the right edge.

callback_edge_top_add()

This is called when the gengrid is scrolled until the top edge.

callback_focused_add()

When the gengrid has received focus.

New in version 1.8.

callback_highlighted_add()

an item in the list is highlighted. This is called when the user presses an item or keyboard selection is done so the item is physically highlighted. The %c event_info parameter is the item that was highlighted.

callback_index_update_add()

This is called when a gengrid item index is changed. Note that this callback is called while each item is being realized.

callback_language_changed_add()

This is called when the program’s language is changed. Call the elm_gengrid_realized_items_update() if items text should be translated.

callback_moved_add()

This is called when a gengrid item is moved by a user interaction in a reorder mode. The %c event_info parameter is the item that was moved.

callback_realized_add()

This is called when the item in the gengrid has its implementing Evas object instantiated, de facto. event_info is the gengrid item that was created. The object may be deleted at any time, so it is highly advised to the caller not to use the object returned from GengridItem.object, because it may point to freed objects.

callback_scroll_add()

called when the content has been scrolled (moved).

callback_scroll_anim_start_add()

This is called when scrolling animation has started.

callback_scroll_anim_stop_add()

This is called when scrolling animation has stopped.

callback_scroll_drag_start_add()

called when dragging the content has started.

callback_scroll_drag_stop_add()

called when dragging the content has stopped.

callback_unfocused_add()

When the gengrid has lost focus.

New in version 1.8.

callback_unhighlighted_add()

an item in the list is unhighlighted. This is called when the user releases an item or keyboard selection is moved so the item is physically unhighlighted. The %c event_info parameter is the item that was unhighlighted.

callback_unrealized_add()

This is called when the implementing Evas object for this item is deleted. event_info is the gengrid item that was deleted.

clear()

Remove all items from a given gengrid widget.

filled

The fill state of the whole grid of items of a gengrid within its given viewport. By default, this value is False, meaning that if the first line of items grid’s isn’t filled, the items are centered with the alignment.

Type :bool
first_item

Get the first item in the gengrid widget.

Type :GengridItem
group_item_size

A gengrid, after creation, has still no information on the size to give to each of its cells. So, you most probably will end up with squares one “finger” wide, the default size. Use this function to force a custom size for you group items, making them as big as you wish.

highlight_mode

This will turn on/off the highlight effect when items are selected and they will or will not be highlighted. The selected and clicked callback functions will still be called.

Highlight is enabled by default.

horizontal

When in “horizontal mode” (True), items will be placed in columns, from top to bottom and, when the space for a column is filled, another one is started on the right, thus expanding the grid horizontally. When in “vertical mode” (False), though, items will be placed in rows, from left to right and, when the space for a row is filled, another one is started below, thus expanding the grid vertically.

Type :bool
item_append(self, GengridItemClass item_class, item_data, func=None) → GengridItem

Append a new item (add as last item) to this gengrid.

Parameters:
  • item_class – a valid instance that defines the behavior of this item. See GengridItemClass.
  • item_data – some data that defines the model of this item. This value will be given to methods of item_class such as GengridItemClass.text_get(). It will also be provided to func as its last parameter.
  • func

    if not None, this must be a callable to be called back when the item is selected. The function signature is:

    func(item, obj, item_data)
    

    Where item is the handle, obj is the Evas object that represents this item, and item_data is the value given as parameter to this function.

item_insert_after(self, GengridItemClass item_class, item_data, GengridItem after_item=None, func=None) → GengridItem

Insert a new item after another item in this gengrid.

Parameters:
  • item_class – a valid instance that defines the behavior of this item. See GengridItemClass.
  • item_data – some data that defines the model of this item. This value will be given to methods of item_class such as GengridItemClass.text_get(). It will also be provided to func as its last parameter.
  • after_item – a reference item to use, the new item will be inserted after it.
  • func

    if not None, this must be a callable to be called back when the item is selected. The function signature is:

    func(item, obj, item_data)
    

    Where item is the handle, obj is the Evas object that represents this item, and item_data is the value given as parameter to this function.

item_insert_before(self, GengridItemClass item_class, item_data, GengridItem before_item=None, func=None) → GengridItem

Insert a new item before another item in this gengrid.

Parameters:
  • item_class – a valid instance that defines the behavior of this item. See GengridItemClass.
  • item_data – some data that defines the model of this item. This value will be given to methods of item_class such as GengridItemClass.text_get(). It will also be provided to func as its last parameter.
  • before_item – a reference item to use, the new item will be inserted before it.
  • func

    if not None, this must be a callable to be called back when the item is selected. The function signature is:

    func(item, obj, item_data)
    

    Where item is the handle, obj is the Evas object that represents this item, and item_data is the value given as parameter to this function.

item_prepend(self, GengridItemClass item_class, item_data, func=None) → GengridItem

Prepend a new item (add as first item) to this gengrid.

Parameters:
  • item_class – a valid instance that defines the behavior of this item. See GengridItemClass.
  • item_data – some data that defines the model of this item. This value will be given to methods of item_class such as GengridItemClass.text_get(). It will also be provided to func as its last parameter.
  • func

    if not None, this must be a callable to be called back when the item is selected. The function signature is:

    func(item, obj, item_data)
    

    Where item is the handle, obj is the Evas object that represents this item, and item_data is the value given as parameter to this function.

item_size

A gengrid, after creation, has still no information on the size to give to each of its cells. So, you most probably will end up with squares one finger wide, the default size. Use this property to force a custom size for you items, making them as big as you wish.

items_count

Return how many items are currently in a list.

Type :int
last_item

Get the last item in the gengrid widget.

Type :GengridItem
multi_select

Multi-selection is the ability to have more than one item selected, on a given gengrid, simultaneously. When it is enabled, a sequence of clicks on different items will make them all selected, progressively. A click on an already selected item will unselect it. If interacting via the keyboard, multi-selection is enabled while holding the “Shift” key.

Note

By default, multi-selection is disabled on gengrids.

Type :bool
nth_item_get(int nth) → :py:class:`GengridItem`

Get the nth item, in a given gengrid widget, placed at position nth, in its internal items list

Parameters:nth – The number of the item to grab (0 being the first)
Returns:The item stored in the object at position nth or None, if there’s no item with that index (and on errors)

New in version 1.8.

realized_items

This returns a tuple of the realized items in the gengrid.

Type :tuple of GengridItem
realized_items_update()

This updates all realized items by calling all the item class functions again to get the contents, texts and states. Use this when the original item data has changed and the changes are desired to be reflected.

To update just one item, use elm_gengrid_item_update().

reorder_mode

If a gengrid is set to allow reordering, a click held for more than 0.5 over a given item will highlight it specially, signaling the gengrid has entered the reordering state. From that time on, the user will be able to, while still holding the mouse button down, move the item freely in the gengrid’s viewport, replacing to said item to the locations it goes to. The replacements will be animated and, whenever the user releases the mouse button, the item being replaced gets a new definitive place in the grid.

Type :bool
scroller_policy

Deprecated since version 1.8: You should combine with Scrollable class instead.

select_mode

Item select mode in the gengrid widget. Possible values are:

  • ELM_OBJECT_SELECT_MODE_DEFAULT : Items will only call their

    selection func and callback when first becoming selected. Any further clicks will do nothing, unless you set always select mode.

  • ELM_OBJECT_SELECT_MODE_ALWAYS : This means that, even if selected,

    every click will make the selected callbacks be called.

  • ELM_OBJECT_SELECT_MODE_NONE : This will turn off the ability to

    select items entirely and they will neither appear selected nor call selected callback functions.

selected_item

This returns the selected item. If multi selection is enabled (multi_select), only the first item in the list is selected, which might not be very useful. For that case, see selected_items.

Type :GengridItem
selected_items

This returns a tuple of the selected items, in the order that they appear in the grid.

See also

selected_item

Type :tuple of GengridItem
class efl.elementary.gengrid.GengridItem

Bases: efl.elementary.object_item.ObjectItem

An item for the Gengrid widget.

Parameters:
  • item_class – a valid instance that defines the behavior of this item. See GengridItemClass.
  • item_data – some data that defines the model of this item. This value will be given to methods of item_class such as GengridItemClass.text_get(). It will also be provided to func as its last parameter.
  • func

    if not None, this must be a callable to be called back when the item is selected. The function signature is:

    func(item, obj, item_data)
    

    Where item is the handle, obj is the Evas object that represents this item, and item_data is the value given as parameter to this function.

append_to()

item_append(Gengrid gengrid) -> GengridItem

Append a new item (add as last item) to this gengrid.

New in version 1.8.

bring_in(int scrollto_type = ELM_GENLIST_ITEM_SCROLLTO_IN)

This causes gengrid to jump to the item and show it (by scrolling), if it is not fully visible. This will use animation to do so and take a period of time to complete.

See also

show()

Parameters:type – Where to position the item in the viewport.
cursor

The cursor that will be displayed when mouse is over the item. The item can have only one cursor set to it, so if this property is set twice for an item, the previous one will be unset.

data

User data for the item.

index

Get the index of the item. It is only valid once displayed.

insert_after(GengridItem after not None) → GengridItem

Insert a new item after another item in this gengrid.

Parameters:after – a reference item to use, the new item will be inserted after it.

New in version 1.8.

insert_before(GengridItem before not None) → GengridItem

Insert a new item before another item in this gengrid.

Parameters:before – a reference item to use, the new item will be inserted before it.

New in version 1.8.

item_tooltip_unset()

Deprecated since version 1.8: Use tooltip_unset() instead

next

This returns the item placed after the item, on the container gengrid.

prepend_to()

item_prepend(Gengrid gengrid) -> GengridItem

Prepend a new item (add as first item) to this gengrid.

New in version 1.8.

prev

This returns the item placed before the item, on the container gengrid.

selected

The selected state of an item. If multi-selection is not enabled on the containing gengrid and selected is True, any other previously selected items will get unselected in favor of a new one.

show(int scrollto_type = ELM_GENLIST_ITEM_SCROLLTO_IN)

This causes gengrid to redraw its viewport’s contents to the region containing the given item, if it is not fully visible.

See also

bring_in()

Parameters:type – Where to position the item in the viewport.
sorted_insert()

insert_after(GengridItem after not None) -> GengridItem

Insert a new item after another item in this gengrid.

Parameters:after – a reference item to use, the new item will be inserted after it.

New in version 1.8.

tooltip_content_cb_set(func, *args, **kargs)

Set the content to be shown in the tooltip object

Setup the tooltip to object. The object can have only one tooltip, so any previews tooltip data is removed. func(args, kargs) will be called every time that need show the tooltip and it should return a valid Evas_Object. This object is then managed fully by tooltip system and is deleted when the tooltip is gone.

Parameters:func – Function to be create tooltip content, called when need show tooltip.
tooltip_style

Style for this object tooltip.

tooltip_text

Set the text to be shown in the tooltip object

Setup the text as tooltip object. The object can have only one tooltip, so any previous tooltip data is removed. Internally, this method calls tooltip_content_cb_set()

tooltip_unset()

item_tooltip_unset()

Unset tooltip from object

Remove tooltip from object. If used the tooltip_text_set() the internal copy of label will be removed correctly. If used tooltip_content_cb_set(), the data will be unreferred but no freed.

update()

This updates an item by calling all the item class functions again to get the contents, texts and states. Use this when the original item data has changed and you want the changes to be reflected.

class efl.elementary.gengrid.GengridItemClass

Bases: object

Defines the behavior of each grid item.

This class should be created and handled to the Gengrid itself.

It may be subclassed, in this case the methods text_get(), content_get(), state_get() and delete() will be used.

It may also be instantiated directly, given getters to override as constructor parameters.

GengridItemClass constructor.

Parameters:
  • item_style – the string that defines the gengrid item theme to be used. The corresponding edje group will have this as suffix.
  • text_get_func – if provided will override the behavior defined by text_get() in this class. Its purpose is to return the label string to be used by a given part and row. This function should have the signature: func(obj, part, item_data) -> str
  • content_get_func – if provided will override the behavior defined by content_get() in this class. Its purpose is to return the icon object to be used (swalloed) by a given part and row. This function should have the signature: func(obj, part, item_data) -> obj
  • state_get_func – if provided will override the behavior defined by state_get() in this class. Its purpose is to return the boolean state to be used by a given part and row. This function should have the signature: func(obj, part, item_data) -> bool
  • del_func – if provided will override the behavior defined by delete() in this class. Its purpose is to be called when item is deleted, thus finalizing resources and similar. This function should have the signature: func(obj, item_data)

Note

In all these signatures, ‘obj’ means Gengrid and ‘item_data’ is the value given to Gengrid item append/prepend methods, it should represent your item model as you want.

content_get()

To be called by Gengrid for each item to get its icon.

Parameters:
  • obj – the Gengrid instance
  • part – the part that is being handled.
  • item_data – the value given to gengrid append/prepend.
Returns:

icon object to be used and swallowed.

Return type:

evas Object or None

free()

Free the C level struct.

New in version 1.8.

item_style

The style of this item class.

ref()

Increase the C level reference count.

New in version 1.8.

state_get()

To be called by Gengrid for each item to get its state.

Parameters:
  • obj – the Gengrid instance
  • part – the part that is being handled.
  • item_data – the value given to gengrid append/prepend.
Returns:

boolean state to be used.

Return type:

bool or None

text_get()

To be called by Gengrid for each item to get its label.

Parameters:
  • obj – the Gengrid instance
  • part – the part that is being handled.
  • item_data – the value given to gengrid append/prepend.
Returns:

label to be used.

Return type:

str or None

unref()

Decrease the C level reference count.

New in version 1.8.