Drag, drop and go

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
Wognath
Posts: 423
Joined: Sun 19 Apr 2009, 17:23

Unidentified flying objects

#41 Post by Wognath »

Drag and drop scripts, based on Zigbert's on 1st page of this topic, have been useful for me:

Code: Select all

<window title="title"><vbox>
		<entry width-request="400" height-request="60"> 
			<variable>X</variable> 
			<default>"Drag a file here or click the button"</default> 
			<action signal="changed">EXIT:1</action> 
		</entry> 
		<button><label>"button label"</label></button>
</vbox></window>
After the script exits, icons occasionally fly across the screen, from nowhere to nowhere, as though replaying a drag and drop action. The UFOs do not appear to be hostile, but :?: why do they appear :?:
Fatdog 720 frugal, HP AMD streambook

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#42 Post by MochiMoppel »

This is an enhanced version of my last posted version.

I needed a "drop zone" for a toolbar which combines the advantages of Wognath's and my own approach
- contains a default text in the entry field. No need to keep the field empty and no need for a frame.
- can be used multiple times without the need to close the dialog

A bit tricky but interesting. I learned that the entry widget does not trigger an "enter-notify-event" signal when the mouse enters the widget with a dragged text but that this signal is emitted - somewhat belatedly - when the text is finally dropped. I also learned that the "enter-notify-event" and "leave-notify-event" signals are always emitted twice, only heaven knows why.

The real challenge was to keep the default text always visible without mixing with the dropped text. I almost succeeded. Now the entry field is only cleared during simple mouse movements and only while the cursor hovers over the field. The default text remains visible while dragging text onto the widget and the dropped text never appears in the field. Good enough for me.

Code: Select all

#!/bin/sh
function drop_action { 
	 Xdialog -left -backtitle "You dropped:" -msg "${DROP_ZONE// \//\n/}" x &
}; export -f drop_action 

export MSG="Drop files/folders"
echo ' 
<entry xalign="0.5" can-focus="false" overwrite-mode="true"> 
	<variable>DROP_ZONE</variable> 
	<input>echo "$MSG"</input>
	<action signal="enter-notify-event">clear:DROP_ZONE</action>
	<action signal="leave-notify-event">refresh:DROP_ZONE</action>
	<action>[[ -z $DROP_ZONE || $DROP_ZONE == $MSG ]] || drop_action</action> 
	<action condition="command_is_true( [[ $DROP_ZONE ]] && echo true )">refresh:DROP_ZONE</action> 
</entry>'| gtkdialog -s
Attachments
Enhanced_drag_and_drop.png
(52.91 KiB) Downloaded 130 times

Post Reply