Michael Aivaliotis Posted September 5, 2005 Report Share Posted September 5, 2005 A question on Info-LV prompted me to answer with an example here on the Forums: Dear all,I'm trying to write a VI that implements simple drag and drop using event handlers. This is a proof-of-concept thing at the moment, so it's practically useless, but bear with me... I have two text controls and one text indicator. I want to be able to click on a control and drag the mouse over to the indicator - when I let go of the mouse button the contents of the control I dragged from are copied to the indicator. I can get so far by using a Mouse Down event on each control, in which a ref to that control is written to a shift register. In the Mouse Up event on the indicator, I check whether the contents of the shift register represent a valid text control. If so, I copy the value of that control to the indicator. So far so good. But - I want the VI to clear the reference if I drop anywhere other than in the indicator. I've tried adding a "<This VI>.Mouse Up" event, but this event always takes precedence over the indicator's Mouse Up event. I thought I might be able to get around this by re-ordering my events, but that makes no difference. Any clues on how I might proceed? I imagine that dynamic event registration might hold the key, but as far as I can see I'd need to be able to dynamically register an event to handle either Mouse Up on the indicator or Mouse Up on the VI (with registration occuring on Mouse Over and Mouse Out events on the indicator) - but I'm not having much joy there because the VI and the indicator are different types. Thanks in advance, Simon Here is a VI example (LV7.1) that acomplishes this. You need to register the Mouse Up event dynamically on the indicator that will receive the drop: Download File:post-2-1125948351.vi Quote Link to comment
SULLutions Posted September 6, 2005 Report Share Posted September 6, 2005 Michael, Your solution is probably the best one for dragging the content from the control to the indicator :thumbup: but, in his original post, Simon said: ... I want the VI to clear the reference if I drop anywhere other than in the indicator...and your solution does not do that. :thumbdown: The approach he posted to Info-LabVIEW: ...by dynamically registering the <This VI>.Mouse Up event, allocating it to a not-a-ref constant while the mouse is over the indicator. , while too sketchy to be definitive, certainly has the potential to do so. As a general programming point, tying the empty string constant to the frame of the while loop in your example does not ensure that the indicator is updated before the loop starts. In this particular case, operator response times are too long for the wiring to make any difference, but I have been bitten by this configuration when the machine response was too fast (commonly with my Running Global.vi utility). Your wiring only requires that the constant be read before the loop starts. (You can verify this by dragging the local variable upward and exposing the direct wiring from the constant to the frame of the loop.) To ensure that the indicator is updated before the loop starts, enclose the constant and the local variable in a single frame sequence. (The constant need not be in the sequence as long as the wire to the loop comes through the sequence, but I think putting both there is more explicit.) Quote Link to comment
Michael Aivaliotis Posted September 7, 2005 Author Report Share Posted September 7, 2005 Michael, Your solution is probably the best one for dragging the content from the control to the indicator :thumbup: but, in his original post, Simon said: and your solution does not do that. :thumbdown: The approach he posted to Info-LabVIEW: , while too sketchy to be definitive, certainly has the potential to do so. 6005[/snapback] Where is your improved solution then? Read my signature... Quote Link to comment
Michael Aivaliotis Posted September 7, 2005 Author Report Share Posted September 7, 2005 Here's the modified example to address the concerns about unregistering the mouse down if clicked outside the indicator. Download File:post-2-1126073019.llb Quote Link to comment
aart-jan Posted September 7, 2005 Report Share Posted September 7, 2005 I believe there are plans to support drag and drop in the next version of LV Quote Link to comment
m3nth Posted September 7, 2005 Report Share Posted September 7, 2005 I believe there are plans to support drag and drop in the next version of LV 6027[/snapback] That would be nice. Here's a quick mod to Michael's version which drags only selected text. - Select text using left click as normal - Drag text to string indicator using right click & hold Download File:post-360-1126099569.llb Quote Link to comment
simonwhitaker Posted September 9, 2005 Report Share Posted September 9, 2005 I believe there are plans to support drag and drop in the next version of LV I have heard this too. It will be interesting to see the details. The fact is that there is already support for drag and drop - as evidenced by these examples. Mouse events are the building blocks on which drag and drop is built. But it would be nice to see the ability to drag objects (e.g. files) from outside LabVIEW into it. For example, it would be nice to be able to drag a JPG file from your file manager onto a picture control and be able to handle that event, opening the image and updating the picture control with it. (Mac OS X users will be familiar with this mode of updating a picture control.) That would make drag and drop in LabVIEW truly powerful. I've attached my own solution to the problem I'd originally described. Enjoy! Simon Download File:post-924-1126252563.vi Quote Link to comment
PJM_labview Posted September 9, 2005 Report Share Posted September 9, 2005 ...But it would be nice to see the ability to drag objects (e.g. files) from outside LabVIEW into it. For example, it would be nice to be able to drag a JPG file from your file manager onto a picture control and be able to handle that event, opening the image and updating the picture control with it...Simon 6050[/snapback] Simon You can already do that very easily with almost no code. Overlay a path control over a picture control and catch the value change events. That's it. *Edit 1 * Note: the image I drag and drop, is actualy the image of the block diagram of the attached example. *Edit 2 * Note: if you use firefox, drag and drop supported images directly from your browser to the VI (this is pretty cool). Attached is an example (LV 7.1.1) PJM Download File:post-121-1126286915.vi Quote Link to comment
m3nth Posted September 9, 2005 Report Share Posted September 9, 2005 Wow. That's pretty cool. And the code is so complicated it's making my head spin. nice Quote Link to comment
BChandler Posted September 11, 2005 Report Share Posted September 11, 2005 A question on Info-LV prompted me to answer with an example here on the Forums:You need to register the Mouse Up event dynamically on the indicator that will receive the drop: 5996[/snapback] True, but this works too (see attachment) You where playing with the wrong end of the drag'n (The tails bad but the heads even worse) You can ignore undefined Mouse Up events, just clear undefined Mouse Down events. Control Mouse-Down's take priority over the vi Mouse-Down. So your orignial, simpler idea was almost right. -Bill Download File:post-2910-1126465573.vi Quote Link to comment
Michael Aivaliotis Posted September 11, 2005 Author Report Share Posted September 11, 2005 True, but this works too (see attachment) You where playing with the wrong end of the drag'n(The tails bad but the heads even worse) You can ignore undefined Mouse Up events, just clear undefined Mouse Down events. Control Mouse-Down's take priority over the vi Mouse-Down. So your orignial, simpler idea was almost right. -Bill 6097[/snapback] Your solution is very nice. This is why I love the LAVA Forums... Great exchange of ideas. Keep it up guys... and gals. Quote Link to comment
huotom Posted May 15, 2009 Report Share Posted May 15, 2009 QUOTE (BChandler @ Sep 12 2005, 03:07 AM) True, but this works too (see attachment) You where playing with the wrong end of the drag'n(The tails bad but the heads even worse) You can ignore undefined Mouse Up events, just clear undefined Mouse Down events. Control Mouse-Down's take priority over the vi Mouse-Down. So your orignial, simpler idea was almost right. -Bill The performance is very well. I love it, a beautiful and simple soultion. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.