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.


    Gestures + drag & drop

    Pythonista
    1
    1
    935
    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.
    • mikael
      mikael last edited by mikael

      Thanks to the relentless work of @rozaimech and others in this thread, I was inspired and able to add the drag & drop gestures to the package.

      The module now supports dragging and dropping both within a Pythonista app and between Pythonista and another app (latter only possible on iPads). These two cases are handled differently:

      • For in-app drops, Apple method of relaying objects is skipped completely, and you can refer to any Python object to be dropped to the target view.
      • For cross-app drops, we have to conform to Apple method of managing data. Currently only plain text and image drops are supported, in either direction.
      • It is also good to note that ui.TextField and ui.TextView views natively act as receivers for both in-app and cross-app plain text drag and drop.

      View is set to be a sender for a drap and drop operation with the drag function. Drag starts with a long press, and can end in any view that has been set as a receiver with the drop function. Views show the readiness to receive data with a green "plus" sign. You can accept only specific types of data; incompatible drop targets show a grey "forbidden" sign.

      Following example covers setting up an in-app drag and drop operation between two labels. To repeat, in the in-app case, the simple string could replaced by any Python object of any complexity, passed by reference:

      drag(sender_label, "Important data")
      
      drop(receiver_label,
          lambda data, sender, receiver: setattr(receiver, 'text', data),
          accept=str)
      

      See the module documentation for the two functions for details.

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