omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    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

    Pythonista
    3
    3
    1753
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Webmaster4o
      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,

      1. Script passes an image from script A to an instance of the custom view class from script B
      2. User uses custom view class to modify image
      3. User confirms that they are finished.
      4. Modified image is passed from script B back to script A

      I'm having trouble with step 4. This would be accomplished by return from a function, but how from a class?

      1 Reply Last reply Reply Quote 0
      • omz
        omz last edited by

        You could use some sort of callback mechanism for this. For example, let the custom view have a finished_handler attribute 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.

        1 Reply Last reply Reply Quote 0
        • JonB
          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 dialogs module, for example list_dialog, etc, which do exactly what you describe: present a view, and return something selected by the user.

          1 Reply Last reply Reply Quote 1
          • First post
            Last post
          Powered by NodeBB Forums | Contributors