Skip to main content
August 27, 2009
Question

User interface changes on user action?

  • August 27, 2009
  • 1 reply
  • 1097 views

I am writing a plugin that loads fields from a csv file. I need to show a preview of those fields (say the first 3 rows) to the user so he can decide what type of field they are, ie date, name, address. What I want is a row of headers of popup boxes and the the first 3 rows under them. The problem is I don't know ahead of time how many columns there are.

I thought I would make a varible to hold a columnview and bind to the correct place on the interface. Then loop though the file and build the preview data.I have tried this and cannot get the data to update on the screen and I am not sure exactly how to bind the varible to a columnview.

Here is a preview of what I would want the data in the column view to be and then bind it to the.

f:row {
      f:popup_menu {
          items = fielditems
     },
      f:popup_menu {
          items = fielditems
     },
     f:popup_menu {
          items = fielditems
     },
},
f:row {
     f:static_text {
          title = 'DataField1',
          alignment = "left",
          width_in_chars = 20
     },
     f:static_text {
           title = 'DataField2',
           alignment = "left",
           width_in_chars = 20
      },

          f:static_text {
           title = 'DataField3',
           alignment = "left",
           width_in_chars = 20
      },
}

Am I going about this the entire wrong way? At this point I am lost on how to build a interface that will update on user interaction. I have seen this type on interface on LR Transporter (the import metadata from file) so I know it is possible.

This topic has been closed for replies.

1 reply

john beardsworth
Community Expert
Community Expert
August 27, 2009

Allen, that sounds right - or at least is similar to the approach I've been adopting with a similar plug-in. Are the field names an array/table? There doesn't seem to be a native split function in Lua but there are a few examples which could split the first line using the commas.

John

August 27, 2009

I can get the data out of the csv file fine. I am just having major problems getting it to update the screen.

here is how I am getting the data from the file to and putting into layout.

function layoutDataFile (FilePath)
    path = LrPathUtils.standardizePath(FilePath)
   
    local file=io.open(path,'r')
    local line   
    local firsttime = true   
    local LayoutRows = {}
    local rowindex = 1    
    local linecount = 0
   
    -- loop each line   
    for line in file:lines() do
        linecount = linecount + 1
        if linecount > 4 then
            -- Dont Add Lines after the 3rd
        else       
            -- Convert Line to table with elements
            t = fromCSV(line)
            lRowItems = {}
            -- First Time Through Make the Header Row
            if firsttime==true then               
                for i, s in ipairs(t) do
                    BarcodeMatchLMI.outputToLog('    Add Item '..i)
                    nm = f:static_text {
                            title = "Column"..i,
                            alignment = "left",
                            width_in_chars = 20
                        }
                    BarcodeMatchLMI.outputToLog('    Insert Item '..i)
                    table.insert(lRowItems,i,nm)           
                end
                lRow = f:row {lRowItems}
                table.insert(LayoutRows,rowindex,lRow)
                rowindex = rowindex + 1
                lRowItems = {}
                firsttime = false
            end
               
            -- Add Fields to Row of the current Line
            for i, s in ipairs(t) do           
                    nm = f:static_text {
                        title = s,
                        alignment = "left",
                        width_in_chars = 20
                    }
                BarcodeMatchLMI.outputToLog('    Insert Item '..i)
                table.insert(lRowItems,i,nm)           
            end
               
            --Insert Row
            lRow = f:row {lRowItems}
            BarcodeMatchLMI.outputToLog('  Insert Row '..rowindex)
            table.insert(LayoutRows,rowindex,lRow)
            rowindex = rowindex + 1
       
        end
    end


    file:close()
    -- Add Rows to Column Layout
    BarcodeDataLayout = f:column {LayoutRows}
    return DataLayout
   
    end

Here is where I am using function. After a button press to select the file.

SampleDataLayout = layoutDataFile (selectedpath)

Here is the Layout. I tried to figure out how to bind it, but am trying to use a strait varible now because I could not figure out how to bind a column. I only say examples of binding the values and data of a control not the entire control.

f:row {
                    f:group_box {
                        title = "Barcode Data",
                        font = "<system>",
                        width = 750,
                        height = 200,
                        SampleDataLayout,

                    }

}

And the where I declare the varible to hold the ui.

local BarcodeDataLayout = f:column {}

Does anyone have a better way that would work?