7 Replies Latest reply on Oct 18, 2013 5:07 PM by areohbee

    combo_boxes and how to use them

    victorvodka Level 1

      I'd like to be able to type a search term into a combo box and, with each typed character, i'd like to perform a SQLite query and get back results that influence what items appear in the popup menu part of the combo-box.  I've been able to do this with a popup_menu and a separate edit_field, but it takes up too much room in the user interface. ideally i'd like to be able to do it from a combo_box.  but there don't seem to be enough hooks into a combo_box to do this. take for example the value parameter.  while a variable bound to it will contain the text typed into the combo_box, it also contains the value of whatever item is pulled down in the popup menu.  this leads to confusion and none of my experiments have been able to get values typed into the combo_box to actually produce new SQLite queries on a character-by-character basis (yes, i tried adding immediate=true to the combo_box instance when i created it).

       

      that said, i'm going to guess that (like everything else in the SDK), there are parameters i can set in a combo_box to deal with the text typed into it and the item selected by the popup separately. i just don't know what they are because they are not mentioned in the documentation for a combo_box.  or i'm wrong and what i am requesting is impossible.  but i thought i'd ask here first.

        • 1. Re: combo_boxes and how to use them
          areohbee Level 5

          immediate = true,

          • 2. Re: combo_boxes and how to use them
            victorvodka Level 1

            I know about that, but it doesn't solve my problem. Is there a way to have separate functions fire for changes made to the text being typed into the text box vs. the selecting of items in the popup menu? I'd like changes made via typing to affect the items showing up in the popup menu as those changes are typed.

            • 3. Re: combo_boxes and how to use them
              areohbee Level 5

              victorvodka wrote:

               

              I know about that, but it doesn't solve my problem.

              Sorry.

               

               

              victorvodka wrote:

               

              I'd like changes made via typing to affect the items showing up in the popup menu as those changes are typed.

              Yes (maybe) - bind "popup" items to member of property table, then change as user types.

               

               

              I've never done it (bound items to "dynamic" property in table) with a combo_box, but such works for popup_menu.

               

               

              UPDATE:

              -----------

              I decided to try this and I'm having problem, it seems combo_box validate function is broken (validate not getting called no matter what I do). Are you having better luck than me?

               

              This is so weird - I thought validator functions worked for combo_box, but current testing suggests they do not (I tested Lr3 & Lr4 as well as Lr5). Validator functions work for edit_field just fine, but not combo_box, not on my win7 box anyway. Bug reported here:

               

              http://feedback.photoshop.com/photoshop_family/topics/lightroom_sdk_combo_box_validate_fun ction_not_called?rfm=1

              -----------

               

              Rob

               

              Message was UPDATED by: Rob Cole

              • 4. Re: combo_boxes and how to use them
                victorvodka Level 1

                i'm trying this with a combo box.  when i edit the text in the box, the SQLite query happens and a new popup menu list is generated, but as it does so, focus always goes back to the beginning of the text i am editing in the combo box.  so if i type "cow" then the first letter causes a query on "c" and focus in the combo box goes to just in front of the "c."  so when i type "o" the result is "oc," and the query happens on that.  and then if i type "w" the result is "woc." i don't suppose there is a way to block the changing of focus within a combo box while typing into it, is there?

                • 5. Re: combo_boxes and how to use them
                  areohbee Level 5

                  Well, you're doing better than me Victor (or should I call you Mr. Vodka?).

                   

                  I can't get a validator to be called to save my life, not for a combo-box anyway, edit-field: yes, combo-box: no.

                   

                  You may need to help me get on the same page as you before I can help, if then... - are you testing on Mac or Windows?

                   

                  Rob

                  • 6. Re: combo_boxes and how to use them
                    victorvodka Level 1

                    this is Windows 7.  When you use the term "Validator" -- do you mean the firing of an Observer function?  Does the that term show up anywhere in the SDK documentation?  I am familiar with it from web development of course.

                    • 7. Re: combo_boxes and how to use them
                      areohbee Level 5

                      HI Victor,

                       

                      I meant the validate function - it would be clarified if you download the test plugin (see link a few posts up).

                       

                      Here is guts of the code:

                      -------------------------------

                      vf:push_button {

                          title = "Push me... (perform test)",

                          action = function( button )

                              LrFunctionContext.postAsyncTaskWithContext( "Test", function( context )

                       

                                  local efValidated = false

                                  local cbValidated = false

                       

                                  context:addCleanupHandler( function( status, message )

                                      if status then

                                          local m = {}

                                          local c = 0

                                          if efValidated then

                                              m[#m + 1] = "edit-field validator was called"

                                              c = c + 1

                                          else

                                              m[#m + 1] = "*** edit-field validator was NOT called"

                                          end

                                          if cbValidated then

                                              m[#m + 1] = "combo-box validator was called"

                                              c = c + 1

                                          else

                                              m[#m + 1] = "*** combo-box validator was NOT called"

                                          end

                                          if c > 0 then

                                              LrDialogs.message( section.title.." completed without an error being thrown - "..table.concat( m, ", " ).."." )

                                          else

                                              LrDialogs.message( section.title.." failed! - no validators were called." )

                                          end

                                      else

                                          LrDialogs.message( "*** "..section.title.." ended - an error was thrown: " .. ( message or "?" ) .. " - push '"..button.title.."' button to perform test again, if desired." )

                                      end

                                  end )

                       

                                  props.efValue = "Edit this - validator should get called when you do"

                                  props.cbValue = "Edit this - validator should get called when you do"

                                  props.items = {

                                      "No worthwhile items...",

                                  }

                       

                                  --[[ validate function spec -

                                      Parameters:

                       

                                          view (LrView) This control.

                                          value (any) The value to validate.

                       

                                      Returns three values:

                       

                                          result (Boolean) True if value was valid.

                                          value (any) The new value.

                                          message (string) If result is false, an error message.

                                  --]]                           

                                  local function validate( viewObject, value )

                                      props.items = {

                                          "One", "Two", "Three", "...",

                                      }

                                      return true, value

                                  end

                       

                                  local vi = {

                                      vf:row {

                                          vf:static_text {

                                              title = "Edit field:",

                                              width = share 'label_width',

                                          },

                                          vf:edit_field {

                                              bind_to_object = props,

                                              value = bind 'efValue',

                                              --items = { 'no worthwhile items' },

                                              immediate = true,

                                              validate = function( vo, value )

                                                  efValidated = true

                                                  return true, value -- false, "edit-field validator was called", "edit-field validator is ok"

                                              end,

                                              width_in_chars = 30,

                                          },

                                      },

                                      vf:row {

                                          vf:static_text {

                                              title = "Combo box:",

                                              width = share 'label_width',

                                          },

                                          vf:combo_box {

                                              bind_to_object = props,

                                              value = bind 'cbValue',

                                              items = { 'no worthwhile items' },

                                              immediate = true,

                                              validate = function( vo, value)

                                                  cbValidated = true

                                                  return true, value -- false, "combo-box validator was called", "combo-box validator is ok"

                                              end,

                                              width_in_chars = 30,

                                          },

                                      },

                                  }

                       

                                  local args = {}

                                  args.title = "Test"

                                  args.contents = vf:view( vi )

                                  LrDialogs.presentModalDialog( args )

                       

                              end )

                          end, -- action func

                      },

                      ---------------------------

                       

                      Problem: validate function (of combo box) not getting called - what am I doing wrong?

                      PS - validate function of edit-field is getting called.

                       

                      Rob