Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Tue 19 Sep 2017, 20:38
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Drag, drop and go
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 3 [39 Posts]   Goto page: 1, 2, 3 Next
Author Message
Wognath

Joined: 19 Apr 2009
Posts: 394

PostPosted: 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
View user's profile Send private message 
zigbert


Joined: 29 Mar 2006
Posts: 6475
Location: Valåmoen, Norway

PostPosted: 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
View user's profile Send private message Visit poster's website 
zigbert


Joined: 29 Mar 2006
Posts: 6475
Location: Valåmoen, Norway

PostPosted: 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
View user's profile Send private message Visit poster's website 
Wognath

Joined: 19 Apr 2009
Posts: 394

PostPosted: 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
View user's profile Send private message 
Wognath

Joined: 19 Apr 2009
Posts: 394

PostPosted: 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. Sad The function "some action on X" could begin with "if [[ $X != $pwd ]] ..." but there must be a better way!
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1348
Location: Japan

PostPosted: 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
View user's profile Send private message 
Wognath

Joined: 19 Apr 2009
Posts: 394

PostPosted: 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
View user's profile Send private message 
mos

Joined: 01 Oct 2016
Posts: 6

PostPosted: 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
View user's profile Send private message 
Wognath

Joined: 19 Apr 2009
Posts: 394

PostPosted: 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 Very Happy Maybe there's a way to do this within gtkdialog Question
Back to top
View user's profile Send private message 
LazY Puppy


Joined: 21 Nov 2014
Posts: 1975
Location: Germany

PostPosted: Wed 05 Oct 2016, 14:59    Post subject:  

"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

Die etablierten Parteien in Deutschland setzen mathematische Regeln außer Kraft. Zuviele Nullen vor dem Komma - das ist gefährlich.
Back to top
View user's profile Send private message 
mos

Joined: 01 Oct 2016
Posts: 6

PostPosted: 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
View user's profile Send private message 
zigbert


Joined: 29 Mar 2006
Posts: 6475
Location: Valåmoen, Norway

PostPosted: 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
Code:
fixmenus
Now you can use the class in gtkdialog with
Code:
gtkdialog -p program --class ontop

_________________
Stardust resources
Back to top
View user's profile Send private message Visit poster's website 
LazY Puppy


Joined: 21 Nov 2014
Posts: 1975
Location: Germany

PostPosted: Wed 05 Oct 2016, 17:55    Post subject:  

Yes, this works!

Thank you very much, zigbert! Very Happy

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! Very Happy

_________________
RSH

Die etablierten Parteien in Deutschland setzen mathematische Regeln außer Kraft. Zuviele Nullen vor dem Komma - das ist gefährlich.
Back to top
View user's profile Send private message 
LazY Puppy


Joined: 21 Nov 2014
Posts: 1975
Location: Germany

PostPosted: 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

Die etablierten Parteien in Deutschland setzen mathematische Regeln außer Kraft. Zuviele Nullen vor dem Komma - das ist gefährlich.
Back to top
View user's profile Send private message 
LazY Puppy


Joined: 21 Nov 2014
Posts: 1975
Location: Germany

PostPosted: 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

Die etablierten Parteien in Deutschland setzen mathematische Regeln außer Kraft. Zuviele Nullen vor dem Komma - das ist gefährlich.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 3 [39 Posts]   Goto page: 1, 2, 3 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0666s ][ Queries: 12 (0.0074s) ][ GZIP on ]