This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Custom view class return an object
Webmaster4o last edited by Webmaster4o
I have a script using UI, and a second which contains a custom view class for modifying an image. At a certain point, script A generates an image. It then passes this image to the custom view class, which is added as a subviews and allows the user to edit the image. I want to have the custom view class return the image when editing is done, back to the main script.
If this doesn't make sense,
- Script passes an image from script A to an instance of the custom view class from script B
- User uses custom view class to modify image
- User confirms that they are finished.
- Modified image is passed from script B back to script A
I'm having trouble with step 4. This would be accomplished by
returnfrom a function, but how from a class?
omz last edited by
You could use some sort of callback mechanism for this. For example, let the custom view have a
finished_handlerattribute that the script sets to a function or method it wants the view to call when it's done editing. The function could have an argument that contains the result of the editing operation.
Remember that functions and methods are basically just objects, so you can not just call them, but also pass them around, set them as attributes, etc.
JonB last edited by
+1 for a callback, which can also just be defined inline in Script A, thus keeping the same local scope, etc.
The alternative is to use
wait_modal. Look at the source of the
dialogsmodule, for example list_dialog, etc, which do exactly what you describe: present a view, and return something selected by the user.