Drag, drop and go
Drag, drop and go
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
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.
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.
>> 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.
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
Regarding activate on signal, these may be of interest:
Enter key is pressed
Not tested, but maybe the 'changed' signal works with the <entry> widget
Code: Select all
<action signal="activate"></action>
Code: Select all
<action signal="key-release-event"></action>
<action signal="focus-out-event"></action>
Code: Select all
<action signal="changed"></action>
A follow-up question. Based on Zigbert's examples, I have
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!
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
<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!
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
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
Two methods--so far
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.
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:One line!! The output of yad is "file:///path/file", so the script has to begin by stripping "file://".
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>
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
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 Maybe there's a way to do this within gtkdialog
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 Maybe there's a way to do this within gtkdialog
- LazY Puppy
- Posts: 1934
- Joined: Fri 21 Nov 2014, 18:14
- Location: Germany
"Display on all desktops" is very different to "Always on top" !!!
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
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:
"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:
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
It's the parameter
that doesgtk_window_set_transient_for ()
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.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
Puppy Slacko
Recent Slacko includes a ontop jwm class, so you can simply run
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... and run Now you can use the class in gtkdialog with
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>
Code: Select all
fixmenus
Code: Select all
gtkdialog -p program --class ontop
- LazY Puppy
- Posts: 1934
- Joined: Fri 21 Nov 2014, 18:14
- Location: Germany
Yes, this works!
Thank you very much, zigbert!
Made a quick test by using the your code in: /root/.jwm/jwmrc-personal
it worked, though
where I made of
and
doesn't work.
Looks like the mean part is:
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!
Thank you very much, zigbert!
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>
Code: Select all
<Group>
<Name>on-top</Name>
<Class>on-top</Class>
<Option>layer:12</Option>
</Group>
Code: Select all
<Group>
<Name>SimpleGUI2</Name>
<Class>ontop</Class>
<Option>layer:3</Option>
</Group>
Code: Select all
<Group>
<Name>SimpleGUI2</Name>
<Class>ontop</Class>
<Option>layer:2</Option>
</Group>
Looks like the mean part is:
Code: Select all
<Option>layer:above</Option>
Again, 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:
"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:
- LazY Puppy
- Posts: 1934
- Joined: Fri 21 Nov 2014, 18:14
- Location: Germany
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:
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:
"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:
- LazY Puppy
- Posts: 1934
- Joined: Fri 21 Nov 2014, 18:14
- Location: Germany
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:
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:
"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:
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
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)LazY Puppy wrote:So, function move should look like code below:
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
- LazY Puppy
- Posts: 1934
- Joined: Fri 21 Nov 2014, 18:14
- Location: Germany
Thanks.MochiMoppel wrote: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)LazY Puppy wrote:So, function move should look like code below:
My attempt: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.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
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.
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:
"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:
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
I dare to say that this is not possible, but then we have zigbert's statement:LazY Puppy wrote:How would example code look like, to move content of tree items between two gtkdialog tree widgets
So my question would be the same as LazY's: How?zigbert wrote:This example shows only one list, but it is of course possible to drag between 2 lists.
MochiMoppel:
2 parallel trees ATREE and BTREE
ATREE:
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:
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
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>
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
I don't understand how this could work. A demo would be nice.
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.some1 wrote:grabfocus BTREE will allow you to choose a position in BTREE
??? 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?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.