IupSetAttributes

Definition: include pGUI.e

IupSetAttributes(Ihandles ih, string attributes, sequence data={})
Description: Sets several attributes of an interface element or elements.

ih: Identifier(s) of the interface element.
attributes: string with the attributes in the format "v1=a1, v2=a2,..." where vi is the name of an attribute and ai is its value.
data: if a non-empty sequence is passed, it performs attributes = sprintf(attributes,data) first.
Comments: Most interface elements can be created with an optional inline invocation of IupSetAttributes, which can make code much cleaner than invoking this function, as example 2 below shows.

There are cases such as a title of "the string is \"X\" [SIZE=%d]" which are difficult if not impossible to achieve via IupSetAttributes, because of the obvious mis-parsing of commas, spaces, quotes, and equal signs. Bear this in mind, especially when the data originates from file or user input, as a similar potential error might not be so readily apparent. While quotation marks are parsed, so eg IupSetAttributes(ih,"TITLE=\"Address Book\", SIZE=500x300") works fine, there is however no way to include literal quotation marks in a value when using IupSetAttributes. Any such fields must be set individually using IupSetAttribute() or (perhaps better) IupSetStrAttribute(). If there is any doubt, especially with settings that are not fixed constants, just do them one at a time.

While the most common use is to set several attributes on a single element, it is also possible to set the same attribute(s) on several elements, as example 3 below shows.

The function IupSetAttributesf has been removed, since that functionality is now provided by the optional string attributes="", sequence data={} parameters on all relevant element creation routines (with non-default values triggering an internal invocation of this very routine).
Likewise the IupSetAtt function has been removed, see example 2 below, though admittedly when a non-null name has been provided that may require extra IupSetHandle() calls (which, btw, is equivalent to making the handle global, and therefore a recipe for disaster in my book).
Example 1: Select the appropriate file dialog type and title.
if bOpen then
    IupSetAttributes(filedlg, "DIALOGTYPE=OPEN, TITLE=Open")
else
    IupSetAttributes(filedlg, "DIALOGTYPE=SAVE, TITLE=Save")
end if
Example 2: Creates a list with country names and defines Japan as the selected option.
Translate C code such as list = IupList(); IupSetAtt(NULL, list, "VALUE", "3", "1", "Brazil", "2", "USA", "3", "Japan", "4", "France", NULL); to
Ihandle list = IupList("VALUE=3, 1=Brazil, 2=USA, 3=Japan, 4=France")

Admittedly this is more of an example of when not to use IupsetAttributes, or more accurately inline it.
Example 3: Enable or disable several buttons and menu entries simultaneously.
string active = iff(selected_text={}?"NO":"YES")
IupSetAttributes({b_cut,b_copy,b_delete,m_cut,m_copy,m_delete}, "ACTIVE", active)
See Also: IupGetAttribute, IupSetAttribute, IupSetStrAttribute, IupCanvas, IupDialog, IupHBox, IupList