Adobe 65007312 Programming Guide - Page 95

Specifying bindings, LrView.bind

Page 95 highlights

CHAPTER 5: Creating a User Interface for Your Plug-in Binding UI values to data values 95 2. For each specific UI element, set the value of each dynamic property using the LrView.bind() function to associate that value with a specific key in the bound table. Z The simplest binding simply mirrors the key value and the property value; for instance, setting one value to true sets the other value to true. Z You can use the LrBindings functions to create other common mappings between the bound key value and the view property value. See "Specifying bindings" on page 95. Z For more complex mappings, see "Transforming values" on page 103 and "Binding multiple keys" on page 105. A typical example is a binding between the visible property and a particular settings value, so that a control is only shown when the appropriate setting is present. For example, in the File Settings section of the Export dialog, the control that appears next to the Format combo box changes according to the selected format. When JPEG is selected, there is a slider for setting the Quality. When you select the TIFF format, the slider is hidden and a Compression pop-up menu is shown. For PSD and DNG, both of these controls (and their labels) are hidden. To accomplish this, Lightroom binds the Format pop-up menu's value property to the LR_format setting. Then the visible property of the slider and its label are bound to the JPEG value of LR_format. The example code in "Changing the contents of a view dynamically" on page 112 shows how to use bindings in this way, setting the visibility state of different sets of controls, based on the selection in a pop-up menu. Notice in this example that two control values are related by being bound to the same key value; this is how you bind control values to one another. NOTE: Bindings are used to create dynamic text in LrView objects only. The title of a dialog box, for example, is not part of an LrView object, and you cannot bind it. Similarly, the title of an Export dialog section cannot be bound. Specifying bindings The LrView namespace function LrView.bind() creates a direct association between a key or keys in an observable table and a view property value. Use this function when creating the view or control, to specify the view property value. For example: visible = LrView.bind( "LR_export_useSubfolder" ) Many of the sample plug-ins create a shortcut to the function: local bind = LrView.bind -- shortcut for bind() method

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204

C
HAPTER
5: Creating a User Interface for Your Plug-in
Binding UI values to data values
95
2.
For each specific UI element, set the value of each dynamic property using the
LrView.bind()
function to associate that value with a specific key in the bound table.
Z
The simplest binding simply mirrors the key value and the property value; for instance, setting one
value to true sets the other value to true.
Z
You can use the
LrBindings
functions to create other common mappings between the bound
key value and the view property value. See
“Specifying bindings” on page 95
.
Z
For more complex mappings, see
“Transforming values” on page 103
and
“Binding multiple keys”
on page 105
.
A typical example is a binding between the
visible
property and a particular settings value, so that a
control is only shown when the appropriate setting is present. For example, in the File Settings section of
the Export dialog, the control that appears next to the Format combo box changes according to the
selected format.
When JPEG is selected, there is a slider for setting the Quality. When you select the TIFF format, the slider is
hidden and a Compression pop-up menu is shown. For PSD and DNG, both of these controls (and their
labels) are hidden.
To accomplish this, Lightroom binds the Format pop-up menu’s
value
property to the
LR_format
setting.
Then the
visible
property of the slider and its label are bound to the
JPEG
value of
LR_format
. The
example code in
“Changing the contents of a view dynamically” on page 112
shows how to use bindings
in this way, setting the visibility state of different sets of controls, based on the selection in a pop-up menu.
Notice in this example that two control values are related by being bound to the same key value; this is
how you bind control values to one another.
N
OTE
:
Bindings are used to create dynamic text in
LrView
objects only. The title of a dialog box, for
example, is not part of an
LrView
object, and you cannot bind it. Similarly, the title of an Export dialog
section cannot be bound.
Specifying bindings
The
LrView
namespace function
LrView.bind()
creates a direct association between a key or keys in an
observable table and a view property value. Use this function when creating the view or control, to specify
the view property value. For example:
visible =
LrView.bind
( "LR_export_useSubfolder" )
Many of the sample plug-ins create a shortcut to the function:
local
bind
= LrView.bind -- shortcut for bind() method