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

Drag, drop and go

#1 Post by Wognath »

In Xdialog and gtkDialog, one can make an input box where a folder or file can be dragged and dropped, then acted upon when OK is clicked.

Is it possible to create an input box in which an action starts immediately when the item is dropped into the box? Edit: by any means, not necessarily Xdialog or gtkDialog

Thanks
Last edited by Wognath on Fri 12 Aug 2016, 17:42, edited 2 times in total.

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#2 Post by zigbert »

gtkdialog supports some basic drag 'n drop.
The following examples is taken from this thread.
_________________________________________________________________

Drag'n drop
>> Gtkdialog supports drag'n drop from file browser (rox) to <entry> widget.

Code: Select all

export test="
<entry accept=\"directory\" width-request=\"300\">
 <default>Drag a directory from Rox</default>
</entry>"
gtkdialog -p test

>> But this is not all....The next script shows how to move items in list by drag'n drop. This example shows only one list, but it is of course possible to drag between 2 lists.

Code: Select all

#!/bin/sh

move (){
	PRESS_EVENT="`cat /tmp/PRESS_EVENT`"
	grep -Fv "$PRESS_EVENT" /tmp/list > /tmp/tmp
	grep -Fm1 -B500 "$TREE" /tmp/tmp | grep -v "$TREE" > /tmp/tmp1
	echo "$PRESS_EVENT" >> /tmp/tmp1
	grep -Fm1 -A500 "$TREE" /tmp/tmp >> /tmp/tmp1
	mv -f /tmp/tmp1 /tmp/list
} 

export -f move
ls -1 /usr/share/backgrounds > /tmp/list

export test="
<tree rules_hint=\"true\" hover-selection=\"true\" tooltip-text=\"Drag'n drop items to move them in list\">
 <label>Backgrounds</label>
 <input>cat /tmp/list</input>
 <variable>TREE</variable>
 <height>300</height><width>200</width>
 <action signal=\"button-press-event\">echo \$TREE > /tmp/PRESS_EVENT</action>
 <action signal=\"button-release-event\">move</action>
 <action signal=\"button-release-event\">refresh:TREE</action>
</tree>"
gtkdialog -p test

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#3 Post by zigbert »

Regarding activate on signal, these may be of interest:

Code: Select all

<action signal="activate"></action>
Enter key is pressed

Code: Select all

<action signal="key-release-event"></action>
<action signal="focus-out-event"></action>
Not tested, but maybe the 'changed' signal works with the <entry> widget

Code: Select all

<action signal="changed"></action>

Wognath
Posts: 423
Joined: Sun 19 Apr 2009, 17:23

#4 Post by Wognath »

Zigbert, <action signal="changed"> seems to be just what I need. Thank you very much!

Wognath
Posts: 423
Joined: Sun 19 Apr 2009, 17:23

#5 Post by Wognath »

A follow-up question. Based on Zigbert's examples, I have

Code: Select all

export test=' 
<entry width-request="300"> 
<variable>X</variable>
 <default>Drag a directory from Rox</default> 
 <action signal="changed"> some action on X </action>
</entry>'
gtkdialog -p test
The text "Drag a directory from Rox" is replaced by the first input, and "some action on X" is immediately executed. Is it possible to have the second drag and drop item replace the first so the action can be repeated more efficiently? As written, it's necessary to select the first entry before dropping in the second; otherwise it just appends.

<action type="clear">X</action> does clear the box, but since it's also a change it results in "some action on X" being applied to the working directory instead of waiting for a new input. :( The function "some action on X" could begin with "if [[ $X != $pwd ]] ..." but there must be a better way!

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

#6 Post by MochiMoppel »

Code: Select all

export test='
<entry width-request="300"> 
<variable>X</variable> 
<default>Drag a directory from Rox</default> 
<action signal="enter-notify-event">grabfocus:X</action>
<action signal="changed">[[ $X != $PWD ]] && gxmessage -c Not PWD $PWD || gxmessage -c BINGO!</action> 
</entry>
'
gtkdialog -p test

Wognath
Posts: 423
Joined: Sun 19 Apr 2009, 17:23

Two methods--so far

#7 Post by Wognath »

The matter of drag&drop with immediate action was originally raised by forum member arivas_2005 here. He needed a way to efficiently process a large number of items and noticed that the "Set Run Action..." dialog in ROX acts this way. So far, two working methods have emerged.

gtkdialog method
Zigbert showed how to do this in gtkdialog with action signal="changed". MochiMoppel's "enter-notify-event" line solves the issue with repeat input; the code in the previous post works perfectly to drag and drop one item after another.

Code: Select all

<action signal="enter-notify-event">grabfocus:X</action>
<action signal="changed">function1 $X &</action> 
arivas' method of clearing the box for repeated input was to exit and restart the gtkdialog instead of using the "enter-notify-event" line

yad method
MochiMoppel pointed out that yad can do this kind of thing. I'm usng yad 0.31.0 from the Fatdog repo. From Smokey01's great tutorial:

Code: Select all

yad --text "drag file or folder here" --dnd --command=/root/script
One line!! The output of yad is "file:///path/file", so the script has to begin by stripping "file://".

mos
Posts: 6
Joined: Sat 01 Oct 2016, 12:15

#8 Post by mos »

How to make this drag'n drop gtkdialog box to stay "Always on top"?And generally how to make gtkdialog created apps ,menus ,boxes to stay "Always on top"?

Wognath
Posts: 423
Joined: Sun 19 Apr 2009, 17:23

#9 Post by Wognath »

mos,
in Openbox: add <application name="gtkdialog"> <layer>above</layer></application> in <appllications> section of ~/.config/openbox/rc.xml, followed by #openbox --reconfigure.
From https://askubuntu.com/questions/445529/ ... th-openbox

in jwm: http://www.murga-linux.com/puppy/viewto ... &start=345 (last post on page 24)

yad has --on-top option :D Maybe there's a way to do this within gtkdialog :?:

User avatar
LazY Puppy
Posts: 1934
Joined: Fri 21 Nov 2014, 18:14
Location: Germany

#10 Post by LazY Puppy »

"Display on all desktops" is very different to "Always on top" !!! :wink:

The solution for "Always on top" presented for JWM seems not to work in newer version of JWM (tested in tahr 602 - solution/posting is from Oct. 2011).

If anyone gets this to work in newer versions of JWM, please consider to publish the complete solution incl. a short gtkdialog example.

Thanks
RSH

"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) :lol:

No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! :wink:

mos
Posts: 6
Joined: Sat 01 Oct 2016, 12:15

#11 Post by mos »

Thanks guys .Right now I,m swinging between ubunty with unity, kx with kde5 and tahr.So if it doesn't work on tahr it probably does on ubuntu's unity.I found something related to gtk based environments https://developer.gnome.org/gtk3/stable ... nsient-for.
It's the parameter
gtk_window_set_transient_for ()
that does
Dialog windows should be set transient for the main application window they were spawned from. This allows window managers to e.g. keep the dialog on top of the main window, or center the dialog over the main window
But this is probably referring to the way a dialog window of a gtk app pops-up on top of the main window of that app and not to "always on top" attribute.

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#12 Post by zigbert »

Puppy Slacko
Recent Slacko includes a ontop jwm class, so you can simply run

Code: Select all

gtkdialog -p program --class ontop


Puppy Tahr
For some reason Puppy Tahr don't want to use the new jwm-tools, so you have to include the class manually in /etc/xdg/templates/_root_.jwmrc

Code: Select all

<Group>
<Class>ontop</Class>
<Option>layer:above</Option>	
</Group>
... and run

Code: Select all

fixmenus
Now you can use the class in gtkdialog with

Code: Select all

gtkdialog -p program --class ontop

User avatar
LazY Puppy
Posts: 1934
Joined: Fri 21 Nov 2014, 18:14
Location: Germany

#13 Post by LazY Puppy »

Yes, this works!

Thank you very much, zigbert! :D

Made a quick test by using the your code in: /root/.jwm/jwmrc-personal

Code: Select all

<Group>
<Class>ontop</Class>
<Option>layer:above</Option>
</Group>
it worked, though

Code: Select all

<Group>
<Name>on-top</Name>
<Class>on-top</Class>
<Option>layer:12</Option>
</Group>
where I made of

Code: Select all

<Group>
<Name>SimpleGUI2</Name>
<Class>ontop</Class>
<Option>layer:3</Option>
</Group>
and

Code: Select all

<Group>
<Name>SimpleGUI2</Name>
<Class>ontop</Class>
<Option>layer:2</Option>
</Group>
doesn't work.

Looks like the mean part is:

Code: Select all

<Option>layer:above</Option>
Then it works in (my T.O.P.L.E.S.S.) tahr (at least 602, which I'm running mostly) also from within /root/.jwm/jwmrc-personal.

Again, thanks! :D
RSH

"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) :lol:

No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! :wink:

User avatar
LazY Puppy
Posts: 1934
Joined: Fri 21 Nov 2014, 18:14
Location: Germany

#14 Post by LazY Puppy »

Made some testings using zigbert's gtkdialog code here

When drag & drop any item from the list of wallpapers and the drop position is equal to the drag position, the list will contain only a single entry after drag & drop any item.

My solution for this is to check first if drag position is unequal compared to the drop position:

So, function move should look like code below:

Code: Select all

move(){
   PRESS_EVENT="`cat /tmp/PRESS_EVENT`"
   if [ "$PRESS_EVENT" != "$TREE" ]; then
	   grep -Fv "$PRESS_EVENT" /tmp/list > /tmp/tmp
	   grep -Fm1 -B500 "$TREE" /tmp/tmp | grep -v "$TREE" > /tmp/tmp1
	   echo "$PRESS_EVENT" >> /tmp/tmp1
	   grep -Fm1 -A500 "$TREE" /tmp/tmp >> /tmp/tmp1
	   mv -f /tmp/tmp1 /tmp/list
   fi
}
export -f move
RSH

"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) :lol:

No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! :wink:

User avatar
LazY Puppy
Posts: 1934
Joined: Fri 21 Nov 2014, 18:14
Location: Germany

#15 Post by LazY Puppy »

Just found another issue on zigbert's gtkdialog code here

When mouse click & release is executed above the same item from the list of wallpapers (similar to a mouse double-click) the item remains not selected. If clicking again on that item without to move the mouse (so, item is still not selected), the list remains empty after clicking that same item.

My solution for this is to check also first if PRESS_EVENT is not an empty string:

So, function move should look like code below:

Code: Select all

move(){
   PRESS_EVENT="`cat /tmp/PRESS_EVENT`"
   if [[ "$PRESS_EVENT" != "$TREE" && "$PRESS_EVENT" != "" ]]; then
	   grep -Fv "$PRESS_EVENT" /tmp/list > /tmp/tmp
	   grep -Fm1 -B500 "$TREE" /tmp/tmp | grep -v "$TREE" > /tmp/tmp1
	   echo "$PRESS_EVENT" >> /tmp/tmp1
	   grep -Fm1 -A500 "$TREE" /tmp/tmp >> /tmp/tmp1
	   mv -f /tmp/tmp1 /tmp/list
   fi
}
export -f move
RSH

"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) :lol:

No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! :wink:

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

#16 Post by MochiMoppel »

LazY Puppy wrote:So, function move should look like code below:
This will delete most items when release event happens outside of the tree items (=no item is highlighted anymore) but still insided the tree widget area (e.g. an empty area below the items)

My attempt:

Code: Select all

move(){ 
    PRESS_EVENT=$(cat /tmp/PRESS_EVENT)
    [[ $PRESS_EVENT && $TREE ]] || exit                          # exit if at least one of the 2 values is empty
    [[ $PRESS_EVENT == $TREE ]] && exit                          # exit if both are equal (=single or double click)
    sed -i "/$PRESS_EVENT/d; /$TREE/ i\\$PRESS_EVENT" /tmp/list  # remove PRESS_EVENT, then insert item PRESS_EVENT before item $TREE
}
export -f move
Overall I'm not happy with this poor man's drag'n'drop substitute. Too many restrictions and pitfalls, but may still be useful in some cases.

User avatar
LazY Puppy
Posts: 1934
Joined: Fri 21 Nov 2014, 18:14
Location: Germany

#17 Post by LazY Puppy »

MochiMoppel wrote:
LazY Puppy wrote:So, function move should look like code below:
This will delete most items when release event happens outside of the tree items (=no item is highlighted anymore) but still insided the tree widget area (e.g. an empty area below the items)

My attempt:

Code: Select all

move(){ 
    PRESS_EVENT=$(cat /tmp/PRESS_EVENT)
    [[ $PRESS_EVENT && $TREE ]] || exit                          # exit if at least one of the 2 values is empty
    [[ $PRESS_EVENT == $TREE ]] && exit                          # exit if both are equal (=single or double click)
    sed -i "/$PRESS_EVENT/d; /$TREE/ i\\$PRESS_EVENT" /tmp/list  # remove PRESS_EVENT, then insert item PRESS_EVENT before item $TREE
}
export -f move
Overall I'm not happy with this poor man's drag'n'drop substitute. Too many restrictions and pitfalls, but may still be useful in some cases.
Thanks.

Just another situation that did not come to mind and therefor wasn't tested.

Checked right now. Out of a list of 69 wallpapers only two items remains in the tree item list. :shock: :lol:

How would example code look like, to move content of tree items between two gtkdialog tree widgets (where I can see many more use of compared to the one discussed) ?
RSH

"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) :lol:

No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! :wink:

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

#18 Post by MochiMoppel »

LazY Puppy wrote:How would example code look like, to move content of tree items between two gtkdialog tree widgets
I dare to say that this is not possible, but then we have zigbert's statement:
zigbert wrote:This example shows only one list, but it is of course possible to drag between 2 lists.
So my question would be the same as LazY's: How?

some1
Posts: 117
Joined: Thu 17 Jan 2013, 11:07

#19 Post by some1 »

MochiMoppel:

2 parallel trees ATREE and BTREE

ATREE:

Code: Select all

<action signal=\"button-release-event\">echo \"ATREE - button-release-event\" \$ATREE >> ./SHOWME_EVENT</action>
<action signal=\"leave-notify-event\">echo \"ATREE - leave-notify-event\" \$ATREE>> ./SHOWME_EVENT</action>
<action signal=\"leave-notify-event\"> grabfocus BTREE>> ./SHOWME_EVENT</action
Ofcourse - 2 events to get the value of ATREE is not needed - just examples - 1 is sufficient.A matter of policy -when to fixate the ATREE-choice.

grabfocus BTREE will allow you to choose a position in BTREE

We can not have a "real" DnD - but have to move the mouse horizontally from ATREE to BTREE,press mousebutton when i BTREE - and do a release on BTREE-item-position.

BTREE:

Code: Select all

<action signal=\"button-release-event\">echo \"BTREE - button-release-event\" \$BTREE >> ./SHOWME_EVENT</action>

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

#20 Post by MochiMoppel »

I don't understand how this could work. A demo would be nice.
some1 wrote:grabfocus BTREE will allow you to choose a position in BTREE
How? I doubt that you can use the gtkdialog grabfocus function the way you do. What should the action grabfocus BTREE>> ./SHOWME_EVENT do? For me it produces an error message. Even if you use grabfocus:BTREE to activate BTREE, with a preceding button-press-event in ATREE item selection does not shift to BTREE.
We can not have a "real" DnD - but have to move the mouse horizontally from ATREE to BTREE,press mousebutton when i BTREE - and do a release on BTREE-item-position.
??? If we want do drag from ATREE to BTREE we need to press mousebutton in ATREE first. We can't possibly also press in BTREE. Or are you suggesting something like click'n'click instead of drag'n'drop?

Post Reply