donnieh
Feb 10, 2015 - 15:03
How come the photos.pick_image() call doesn't work inside a function but works outside?
def pick_photo(sender):
pic = photos.pick_image()
How come the photos.pick_image() call doesn't work inside a function but works outside?
def pick_photo(sender):
pic = photos.pick_image()
It does work in a function, but not within a ui action. The reason for this is that ui actions block the main thread of the app by default, which would essentially cause it to hang if it would present a modal dialog or anything like that. The pick_image function detects this, and simply does nothing in this case.
You can fix this by "decorating" your action with @ui.in_background, like this:
@ui.in_background
def pick_photo(sender):
pic = photos.pick_image()