I get the impression that images returned from `dt.collection` carry
the wrong id in their `image.id` field.

On 2016-Jan-07, Tobias Ellinghaus wrote with possible deletions:
> And what version of dt is that?

I have verified this with with 851e3aa and f710269.

> Works for me. Anything else I have to do besides filtering by color
> label?

I realised that this becomes clearer when the list index is printed as
well: Change the script slightly so that

    local dt = require "darktable"

    local function foo()

          print("________________________________________")
          print("--- action images ---")
          for n, i in pairs(dt.gui.action_images) do
              print(n, i.id, i)
          end

          print("--- collection ---")
          for n, i in pairs(dt.collection) do
              print(n, i.id, i)
          end

    end

    dt.register_event("shortcut", function(_, _) foo() end, "foo")

You need to narrow down the selection, but not necessarily by color
label.  To observe the effect, just have a collection *not containing*
an image with the ID 1.  For this example: color-label images with IDs
3, 5, and 7.  Collect by that label.  Choose ‘Select all’ on the right
pane.  Now invoking `foo` prints

    ________________________________________
    --- action images ---
    1       3       /tmp/dt/foto/DSC_0259.NEF
    2       5       /tmp/dt/foto/DSC_0261.NEF
    3       6       /tmp/dt/foto/DSC_0262.NEF
    --- collection ---
    1       1       /tmp/dt/foto/DSC_0257.NEF
    2       2       /tmp/dt/foto/DSC_0258.NEF
    3       3       /tmp/dt/foto/DSC_0259.NEF

Observe that the second column should contain the image's database ID,
which is correct for “action images” but wrong for “collection”.

> > By the way: Is there any good reason why `dt.gui.action_images` and
> > `dt.collection` do not return a table that maps the image id to the
> > image?
> 
> What would be the benefit over having a list of images?

It would reflect the semantics, and would give Lua the knowledge that
an image ID identifies an image.  Returning a list just throws away
this knowledge which then must be recalculated when needed.

My particular usecase: I need to find all images that belong to a
group *and* are in the current collection.  To this end, set
intersection on sets of images is req'd.  Now to be at least somewhat
efficient, I have to construct potentially huge tables in the Lua
script representing the set of images in the collection.

    local collection = {}
    for _, img in pairs(dt.collection) do
        collection[img.id] = true
    end

    local targets = {}
    for _,m in pairs(someimage:get_group_members()) do
        if collection[m.id] then targets[m.id] = m end
    end


Stefan


-- 
http://stefan-klinger.de                                      o/X
Send plain text messages only, not exceeding 32kB.            /\/
                                                                \

------------------------------------------------------------------------------
_______________________________________________
Darktable-users mailing list
Darktable-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/darktable-users

Reply via email to