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 Thu 14 Dec 2017, 00:39
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 2 of 3 [40 Posts]   Goto page: Previous 1, 2, 3 Next
Author Message
MochiMoppel


Joined: 26 Jan 2011
Posts: 1397
Location: Japan

PostPosted: Thu 06 Oct 2016, 05:28    Post subject:  

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:
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.
Back to top
View user's profile Send private message 
LazY Puppy


Joined: 21 Nov 2014
Posts: 2007
Location: Germany

PostPosted: Thu 06 Oct 2016, 09:37    Post subject:  

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:
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. Shocked Laughing

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) Laughing

No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! Wink
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1397
Location: Japan

PostPosted: Fri 07 Oct 2016, 23:52    Post subject:  

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?
Back to top
View user's profile Send private message 
some1

Joined: 17 Jan 2013
Posts: 75

PostPosted: Sun 09 Oct 2016, 18:12    Post subject:  

MochiMoppel:

2 parallel trees ATREE and BTREE

ATREE:
Code:

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

<action signal=\"button-release-event\">echo \"BTREE - button-release-event\" \$BTREE >> ./SHOWME_EVENT</action>
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1397
Location: Japan

PostPosted: Sun 09 Oct 2016, 23:12    Post subject:  

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.

Quote:
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?
Back to top
View user's profile Send private message 
zigbert


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

PostPosted: Mon 10 Oct 2016, 02:07    Post subject:  

This is getting interesting Very Happy
My original statement is many years old, and I don't remember what lead to it... MochiMoppel has a valid point in the fact that:
When pressing in treeA, it locks the focus, so release in treeB won't get the signal.

But hey, why so pessimistic Laughing
I have more than once got impressed of what you guys are able to do to push the limits...

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

Joined: 01 Oct 2016
Posts: 6

PostPosted: Thu 13 Oct 2016, 14:33    Post subject:  

Trying to make this drag'n drop widget to work like this :
Code:

<entry width-request="300">
<variable>X</variable>
 <default>Drag an exe</default>
<action>echo $X > /tmp/txt &</action>

<action>'$HERE'/sedscript &</action>
 <action signal="changed"> some action on X </action>
</entry>


And the sedscript is:
Code:

#!/bin/bash

sed -i 's/.*\///' /tmp/txt
sed -i 's/ *$//' /tmp/txt

fsg=$( cat /tmp/txt )

echo "#!/bin/bash

env WINEPREFIX=\"/home/lns/.wine\" /opt/wine-staging/bin/wine Z:\\\\\\\\media\\\\\\\\SDA\\\\\\\\VST\\\\\\\\VSTi\\\\\\\\$fsg &" > /media/SDA/VST/VSTi/sfile

./media/SDA/VST/VSTi/sfile


What I want with these is to "drag'n drop" an windows .exe file over the empty field of this widget ,drop it there and make wine start it.sed is copying it as win.exe(without path) and wine should start it through sfile script. Everything works untill starting /media/SDA/VST/VSTi/sfile.Somehow ,in this file "env WINEPREFIX=\"/home/lns/.wine\" /opt/wine-staging/bin/wine Z:\\\\\\\\media\\\\\\\\SDA\\\\\\\\VST\\\\\\\\VSTi\\\\\\\\win.exe" is corectly copied on one line but without "&" on it's trail ,that's copied on the next line resulting something like this:
Code:

#!/bin/bash

env WINEPREFIX="/home/lns/.wine" /opt/wine-staging/bin/wine Z:\\\\media\\\\SDA\\\\VST\\\\VSTi\\\\win.exe

 &

Wine can't start win.exe without "&" on it's trail ,so everything stops there.How to put "&" on it's place?I tried almost everything with sed but the result is the same with "&" thrown on the wrong place ,on the next line, not on the same line with win.exe and after win.exe.
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1397
Location: Japan

PostPosted: Tue 18 Oct 2016, 22:35    Post subject:  

zigbert wrote:
why so pessimistic

I was optimistic when I read your "of course". After reading your disclaimer and no word from some1 I lost my optimism. Let's call this realism, not pessimism. You can't always get what you want ♩ ♪♫ Wink

Back to the thread topic. The solution to use a gtkdialog entry widget still has a flaw: While dropping works, editing the text in the entry field does not work anymore. Any attempt to edit the text will trigger a "changed" signal and therefore fire the associated action.

The following version lets the user edit text manually as usual. The action is triggered only after hitting the Enter key. Dropped text triggers the action immediately.

Here is the catch: This version of Drag&Drop&Go works only with window focus model "click". With focus model "sloppy" drag&drop works normally, but triggers action only after hitting the Enter key - just like manual entry.
Code:
#!/bin/sh
export FOCUS_FLAG=/tmp/hasfocus
trap "rm $FOCUS_FLAG" EXIT

function some_action {
  [ -f $FOCUS_FLAG ] && METHOD=typed || METHOD=dropped
  Xdialog -msg "You $METHOD \n$vENTRY" x   
}
export -f some_action

echo '
<window>
  <entry>
    <variable>vENTRY</variable>
    <default>D&D or type&ENTER</default>
    <action signal="changed"            condition="command_is_true([ -f $FOCUS_FLAG ] || echo true )">some_action &</action>
    <action signal="enter-notify-event" condition="command_is_true([ -f $FOCUS_FLAG ] || echo true )">grabfocus:vENTRY</action>
    <action signal="key-release-event"  condition="command_is_true([ $KEY_SYM = Return ] && echo true )">some_action &</action>
  </entry>
  <action signal="focus-in-event">touch $FOCUS_FLAG</action>
  <action signal="focus-out-event">rm   $FOCUS_FLAG</action>
</window>'| gtkdialog -cs
Back to top
View user's profile Send private message 
zigbert


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

PostPosted: Tue 25 Oct 2016, 11:59    Post subject:  

I have updated the Tips and trick post with MochiMoppel's 'move' function.
Thank you

Depending on the focus model "sloppy" is somewhat strict Smile. A creative soluiton, but I have not included the example.

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


Joined: 26 Jan 2011
Posts: 1397
Location: Japan

PostPosted: Wed 26 Jul 2017, 23:00    Post subject:  

@zigbert: Now, 9 months later, I regret my 'move' Laughing

This is what tips&tricks suggests now:
Quote:
But this is not all....The next script shows how to move items in list by drag'n drop. Code:
Code:
#!/bin/sh

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


...and this is how IMO moving items could be achieved much easier:
Code:
#!/bin/sh
export test='
<tree headers-clickable="false" reorderable="true" rules_hint="true" Xhover-selection="true" tooltip-text="Drag'\''n drop items to move them in list">
<label>Backgrounds</label>
<input>ls -1 /usr/share/backgrounds</input>
<variable>TREE</variable>
<height>300</height><width>200</width>
</tree>'
gtkdialog -p test

The reorderable tag attribute is not mentioned in the gtkdialog documentation, but it's included in the main Gtk documentation, used by GtkFileChooserDialog for shuffling bookmarks in the left bookmarks pane and you use it in Pmusic for sorting playlists, so it should have a place somewhere in tips&tricks.
Back to top
View user's profile Send private message 
zigbert


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

PostPosted: Thu 27 Jul 2017, 17:21    Post subject:  

Very Happy
Like it

Tried to make it more usable with a output file, but the release-event saves the list to <output file> 1 step behind my move. - I have to move twice to update the output file with the first move.

Code:
#!/bin/sh
export test='
<tree headers-clickable="false" reorderable="true" rules_hint="true" Xhover-selection="true" tooltip-text="Drag'\''n drop items to move them in list">
<label>Backgrounds</label>
<input>ls -1 /usr/share/backgrounds</input>
<output file>/tmp/test</output>
<variable>TREE</variable>
<height>300</height><width>200</width>
<action signal="button-release-event">save:TREE</action>
</tree>'
gtkdialog -p test
Another issue is that moving an item onto another item deletes it. You have to ensure that the marker is between 2 items to make it work.

Any thoughts?

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


Joined: 26 Jan 2011
Posts: 1397
Location: Japan

PostPosted: Fri 28 Jul 2017, 12:14    Post subject:  

zigbert wrote:
Tried to make it more usable with a output file, but the release-event saves the list to <output file> 1 step behind my move.
Yeah, nice, isn't it? A great feature. Saves the status just after you released the button and before gtkdialog shuffles the sort order, updates the display and whatever else has to be done to process the signal. Gives you a last chance to backup your current sort order before you mess up your list with an accidental drop.

It's the same with other signals, e.g. selection-changed. Whatever action you define, user defined actions have precedence and are processed before the built-in actions.

If you want to save the reordered list you can either use the changed signal (which I find too heavy since it fires often) or you can "outsource" the save action. An (invisible) button is fine for that:
Code:
<action signal="button-release-event">activate:BTN_SAVE</action>
.
.
<button visible="false">
   <variable>BTN_SAVE</variable>
   <action>save:TREE</action>
</button>


Quote:
Another issue is that moving an item onto another item deletes it.
...and hovering another item over the item that just ate your deleted item causes the culprit to spit it out again. You can have much fun with this feature ...or is it a bug? Anyway, if you combine your "1 step behind" save and my "outsourced" save, you have all ingredients for a bullet-proof reorder function.

The following code works for me. It takes a snapshot of the list before and after the reordering. Then it compares the output of the wc command, which should be the same for both files - unless a line is missing (deleted). In this case the tree is refreshed with the first snapshot, which effectively recreates the former sort order.

Code:
#!/bin/sh
ls -1 /usr/share/backgrounds > /tmp/test
export test='
<vbox>
<tree headers-clickable="false" reorderable="true">
   <label>Backgrounds</label>
   <input>cat /tmp/test</input>
   <output file>/tmp/test</output>
   <variable>TREE</variable>
   <height>300</height><width>200</width>
   <action signal="button-release-event">save:TREE</action>
   <action signal="button-release-event">activate:BTN_SAVE</action>
</tree>
<button visible="false">
   <variable>BTN_SAVE</variable>
   <action>cp /tmp/test /tmp/testbackup</action>
   <action>save:TREE</action>
   <action condition="command_is_true([[ $(wc </tmp/test) != $(wc </tmp/testbackup) ]] && sed \"s/^|*//\" /tmp/testbackup > /tmp/test && echo true )">refresh:TREE</action>
</button>
</vbox>'
gtkdialog -p test
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1397
Location: Japan

PostPosted: Sat 05 Aug 2017, 07:15    Post subject:  

zigbert wrote:
Any thoughts?

Question Did my thoughts solve your problems?

Just in case you are still waiting for more: There might be a chance to avoid the "move onto item" problem, but I'll still have to run some tests - when I find time.
Back to top
View user's profile Send private message 
zigbert


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

PostPosted: Sun 06 Aug 2017, 11:23    Post subject:  

Wow, you're really into something Very Happy

Will do more testing when time comes my way...
Would be nice to see if I could get it work properly in pMusic.

Thank you
Sigmund

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


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

PostPosted: Tue 08 Aug 2017, 08:40    Post subject:  

In the work of getting this exiting code work in actual usage, I've managed to implement the reorderable feature in the the pMusic playqueue. 2 of the 3 others functions that pMusic use in the queue are ok, but I struggle with the last one...

- The right-click menu is ok.
- The hot-key for removing items in queue by pressing mouse middle-button is ok.
- But activating (play) an item in the list by left-clicking on it seems to be troublesome. Well, it is sure doable with the release-event, but then I play every track I move by the reorderable function. I have tried to instead use doubleclick, but it doesn't seem to work in this combination. And the signal "row-activated" doesn't listen...

So, at this stage, the workaround is a bit hard. It reorders the list gently, but without any option to run actions on a left-click, we miss the last brick in the wall.

Any thoughts?
Sigmund

_________________
Stardust resources
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 2 of 3 [40 Posts]   Goto page: Previous 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.0728s ][ Queries: 14 (0.0060s) ][ GZIP on ]