id: variable_qtgui_toggle_button_msg
label: QT GUI Toggle Button
category: '[Core]/GUI Widgets/QT'
flags: [ show_id, python ]

parameters:
-   id: label
    label: Label
    dtype: string
    hide: ${ ('none' if label else 'part') }
-   id: type
    label: Type
    dtype: enum
    default: int
    options: [real, int, string, bool]
    option_labels: [Float, Integer, String, Boolean]
    option_attributes:
        conv: [float, int, str, bool]
    hide: part
-   id: value
    label: Default Value
    dtype: ${ type }
    default: '0'
-   id: initPressed
    label: Initial State
    dtype: enum
    default: 'False'
    options: ['False', 'True']
    option_labels: ['Released', 'Pressed']
-   id: pressed
    label: Pressed
    dtype: ${ type }
    default: '1'
-   id: released
    label: Released
    dtype: ${ type }
    default: '0'
-   id: outputmsgname
    label: Message Property Name
    dtype: string
    default: 'value'
    hide: 'part'
-   id: relBackgroundColor
    label: Released Background
    dtype: enum
    default: 'default'
    options: ['default', 'silver', 'gray', 'black', 'white', 'red', 'green', 'blue', 'navy', 'yellow', 'orange', 'purple', 'lime', 'aqua', 'teal']
    option_labels: ['default', 'silver', 'gray', 'black', 'white', 'red', 'green', 'blue', 'navy', 'yellow', 'orange', 'purple', 'lime', 'aqua', 'teal']
    hide: 'part'
-   id: relFontColor
    label: Released Font Color
    dtype: enum
    default: 'default'
    options: ['default', 'silver', 'gray', 'black', 'white', 'red', 'green', 'blue', 'navy', 'yellow', 'orange', 'purple', 'lime', 'aqua', 'teal']
    option_labels: ['default', 'silver', 'gray', 'black', 'white', 'red', 'green', 'blue', 'navy', 'yellow', 'orange', 'purple', 'lime', 'aqua', 'teal']
    hide: 'part'
-   id: pressBackgroundColor
    label: Pressed Background
    dtype: enum
    default: 'default'
    options: ['default', 'silver', 'gray', 'black', 'white', 'red', 'green', 'blue', 'navy', 'yellow', 'orange', 'purple', 'lime', 'aqua', 'teal']
    option_labels: ['default', 'silver', 'gray', 'black', 'white', 'red', 'green', 'blue', 'navy', 'yellow', 'orange', 'purple', 'lime', 'aqua', 'teal']
    hide: 'part'
-   id: pressFontColor
    label: Pressed Font Color
    dtype: enum
    default: 'default'
    options: ['default', 'silver', 'gray', 'black', 'white', 'red', 'green', 'blue', 'navy', 'yellow', 'orange', 'purple', 'lime', 'aqua', 'teal']
    option_labels: ['default', 'silver', 'gray', 'black', 'white', 'red', 'green', 'blue', 'navy', 'yellow', 'orange', 'purple', 'lime', 'aqua', 'teal']
    hide: 'part'
-   id: gui_hint
    label: GUI Hint
    dtype: gui_hint
    hide: part
value: ${ value }

outputs:
-   domain: message
    id: state
    optional: true

templates:
    var_make: self.${id} = ${id} = ${value}
    make: |-
        <%
            win = '_%s_toggle_button'%id
        %>\
        % if type == 'bool':
        self._${id}_choices = {'Pressed': bool(${pressed}), 'Released': bool(${released})}
        % else:
        self._${id}_choices = {'Pressed': ${pressed}, 'Released': ${released}}
        % endif

        ${win} = qtgui.ToggleButton(${ 'self.set_' + context.get('id')() }, ${(label if (len(label) - 2 > 0) else repr(id))}, self._${id}_choices, ${initPressed}, ${outputmsgname})
        ${win}.setColors("${relBackgroundColor}", "${relFontColor}", "${pressBackgroundColor}", "${pressFontColor}")
        self.${id} = ${win}

        ${gui_hint() % win}

documentation: |-
    This block creates a variable toggle button. Leave the label blank to use the variable id as the label.

    A toggle button selects between two values of similar type, but will stay depressed until clicked again. The variable will take on one value or the other depending on whether the button is pressed or released.

    This button will also produce a state message matching the set values.

    The GUI hint can be used to position the widget within the application. The hint is of the form [tab_id@tab_index]: [row, col, row_span, col_span]. Both the tab specification and the grid position are optional.

file_format: 1
