Forum Archive

Form_dialog that takes pictures and save locally

Grun6

Hello,

I've been trying for days to do the following, and run into the same NoneType problem. Here is what I am after: in addition to entering text, numbers, checkmarks, and dates in a form dialog, I would like to also take a picture, and store it locally.

The "picture" row in the form dialog would have two buttons, one to take a picture, and one to show a preview of it. The form dialog return dictionary would return the path to the picture as the value for that given photo row.

Example:

fields = [{'type':'text', 'title':'First Name', 'key':'fname', 'value':''}, {'type':'photo', 'title':'ID card', 'key':'ID_photo', 'value':''}]
dialogs.form_dialog(fields = fields)

And say the user enters "Bob" as first name, and uses the buttons to take a picture that gets stored locally at path pictures/some_unique_id.jpeg
Then the form dialog would return:

{'fname':'Bob', 'ID_photo':'pictures/some_unique_id.jpeg'}

In my attempts, I have used the photos module, the capture_image() function to get the image, and the image.save(path) function to save it.

Any help would be greatly appreciated,
Merry Christmas to you all,
G

JonB

why not post a gist of your furthest attempt?

Grun6

You are right. I thought it would be long here but a gist is perfect:
https://gist.github.com/368433/043e7e00955b7f880d422d3961a79215

Also you can use this code for the demo:

import PhotoDialogs

fields = [{'type':'text', 'title':'First Name', 'key':'fname', 'value':''}, {'type':'photo', 'title':'ID card', 'key':'ID_photo', 'value':''}]
PhotoDialogs.form_dialog(fields = fields)

Notice what happens when you press Done after a picture is taken.

Grun6

Notice:

  • the photo type is implemented at line 94
  • the take_photo call is implemented at line 344
  • the rest is pretty much the form_dialog module (I have implemented a segmented type but it has nothing to do with the rest)

It all works well, but it seems that the capture_image() call changes the self.container_view item

cvp

@Grun6 if you comment the line just after wait_modal

    #c.container_view = None

The problem does not occur anymore, that proves that the wait_modal does not wait...

Before this comment, I've tried @ui.in_background in front of some def, but without success.

Grun6

wow. @cvp. I don't know what to say...I've been trying to sort this out for literally three days...
Thanks so much for looking at it,
Merry Christmas,
G

cvp

@Grun6 Thanks, it was my 🎁