# IupSetAttributes

Definition: | include pGUI.e IupSetAttributes(Ihandles ih, string attributes, dword_seq args={})
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. args: if a non-empty sequence is passed, it performs attributes = sprintf(attributes,args) first.
pwa/p2js: | Supported.
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. Note also that hex values require quotes, eg IupSetAttributes(ih,"FGCOLOR=#008000") does not work but IupSetAttributes(ih,`FGCOLOR="#008000"`) does. 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 args={}` 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 potentially troublesome). C code that uses nested IupSetAtt[ributes[f]]() calls should normally be converted into a single paranormalised function call when possible, otherwise be broken down into consecutive statements that all get passed the same ih, and/or explicit variables created (suitably/sensibly/nicely named) for any (previously anonymous) inner elements. Sometimes that can be a bit of a drag, but more often than not the code ends up both easier to read and easier to modify at some later date.
Example 1: | Select the appropriate file dialog type and title.
    string dlgtype = iff(bOpen?`DIALOGTYPE=OPEN, TITLE=Open`
                              :`DIALOGTYPE=SAVE, TITLE=Save`)
    IupSetAttributes(filedlg, dlgtype)
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/or 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)
You could equivalently use IupSetInt and a bool, probably ever-so-slightly faster, but probably not by enough to ever actually measure.
See Also: | IupGetAttribute, IupSetAttribute, IupSetStrAttribute, IupList