Author |
Message |
Wognath
Joined: 19 Apr 2009 Posts: 424
|
Posted: Tue 09 Aug 2016, 12:58 Post subject:
Drag, drop and go Subject description: Can it be done? |
|
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, 13:42; edited 2 times in total
|
Back to top
|
|
 |
zigbert

Joined: 29 Mar 2006 Posts: 6629 Location: Valåmoen, Norway
|
Posted: Tue 09 Aug 2016, 15:57 Post subject:
|
|
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: | 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: | #!/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 |
_________________ Stardust resources
|
Back to top
|
|
 |
zigbert

Joined: 29 Mar 2006 Posts: 6629 Location: Valåmoen, Norway
|
Posted: Tue 09 Aug 2016, 16:04 Post subject:
|
|
Regarding activate on signal, these may be of interest:
Code: | <action signal="activate"></action> | Enter key is pressed
Code: | <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: | <action signal="changed"></action> |
_________________ Stardust resources
|
Back to top
|
|
 |
Wognath
Joined: 19 Apr 2009 Posts: 424
|
Posted: Tue 09 Aug 2016, 16:40 Post subject:
|
|
Zigbert, <action signal="changed"> seems to be just what I need. Thank you very much!
|
Back to top
|
|
 |
Wognath
Joined: 19 Apr 2009 Posts: 424
|
Posted: Wed 10 Aug 2016, 14:53 Post subject:
|
|
A follow-up question. Based on Zigbert's examples, I have
Code: | 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!
|
Back to top
|
|
 |
MochiMoppel

Joined: 26 Jan 2011 Posts: 2084 Location: Japan
|
Posted: Wed 10 Aug 2016, 23:54 Post subject:
|
|
Code: | 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 |
|
Back to top
|
|
 |
Wognath
Joined: 19 Apr 2009 Posts: 424
|
Posted: Fri 12 Aug 2016, 13:41 Post subject:
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. Code: | <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: | 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://".
|
Back to top
|
|
 |
mos
Joined: 01 Oct 2016 Posts: 6
|
Posted: Wed 05 Oct 2016, 10:59 Post subject:
|
|
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"?
|
Back to top
|
|
 |
Wognath
Joined: 19 Apr 2009 Posts: 424
|
Posted: Wed 05 Oct 2016, 13:36 Post subject:
|
|
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/how-can-i-have-an-application-automatically-display-on-all-desktops-with-openbox
in jwm: http://www.murga-linux.com/puppy/viewtopic.php?t=69188&start=345 (last post on page 24)
yad has --on-top option Maybe there's a way to do this within gtkdialog
|
Back to top
|
|
 |
LazY Puppy

Joined: 21 Nov 2014 Posts: 2007 Location: Germany
|
Posted: Wed 05 Oct 2016, 14:59 Post subject:
|
|
"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
_________________ RSH
"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0)
No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! 
|
Back to top
|
|
 |
mos
Joined: 01 Oct 2016 Posts: 6
|
Posted: Wed 05 Oct 2016, 16:33 Post subject:
|
|
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/GtkWindow.html#gtk-window-set-transient-for.
It's the parameter Quote: | gtk_window_set_transient_for () |
that does Quote: | 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.
|
Back to top
|
|
 |
zigbert

Joined: 29 Mar 2006 Posts: 6629 Location: Valåmoen, Norway
|
Posted: Wed 05 Oct 2016, 17:13 Post subject:
|
|
Puppy Slacko
Recent Slacko includes a ontop jwm class, so you can simply run Code: | 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: | <Group>
<Class>ontop</Class>
<Option>layer:above</Option>
</Group> | ... and run Now you can use the class in gtkdialog with Code: | gtkdialog -p program --class ontop |
_________________ Stardust resources
|
Back to top
|
|
 |
LazY Puppy

Joined: 21 Nov 2014 Posts: 2007 Location: Germany
|
Posted: Wed 05 Oct 2016, 17:55 Post subject:
|
|
Yes, this works!
Thank you very much, zigbert!
Made a quick test by using the your code in: /root/.jwm/jwmrc-personal
Code: | <Group>
<Class>ontop</Class>
<Option>layer:above</Option>
</Group> |
it worked, though
Code: | <Group>
<Name>on-top</Name>
<Class>on-top</Class>
<Option>layer:12</Option>
</Group> |
where I made of
Code: | <Group>
<Name>SimpleGUI2</Name>
<Class>ontop</Class>
<Option>layer:3</Option>
</Group> |
and
Code: | <Group>
<Name>SimpleGUI2</Name>
<Class>ontop</Class>
<Option>layer:2</Option>
</Group> |
doesn't work.
Looks like the mean part is:
Code: | <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!
_________________ RSH
"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0)
No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! 
|
Back to top
|
|
 |
LazY Puppy

Joined: 21 Nov 2014 Posts: 2007 Location: Germany
|
Posted: Wed 05 Oct 2016, 22:48 Post subject:
|
|
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: | 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)
No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! 
|
Back to top
|
|
 |
LazY Puppy

Joined: 21 Nov 2014 Posts: 2007 Location: Germany
|
Posted: Wed 05 Oct 2016, 23:13 Post subject:
|
|
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: | 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)
No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! 
|
Back to top
|
|
 |
|