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 Fri 18 Aug 2017, 16:22
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 3 of 3 [37 Posts]   Goto page: Previous 1, 2, 3
Author Message
MochiMoppel


Joined: 26 Jan 2011
Posts: 1326
Location: Japan

PostPosted: Tue 08 Aug 2017, 11:15    Post subject:  

Something like this?
Code:
#!/bin/bash
ls -1 /usr/share/backgrounds > /tmp/test
do_something () { [[ $TREE ]] && viewnior "/usr/share/backgrounds/$TREE" ;} ; export -f do_something
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>"[[ $(</tmp/test) == $(</tmp/testbackup) ]] && do_something &"</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

Item is activated upon button-release-event, but not after reordering.
If the list hasn't been reordered, the very last action condition doesn't need be tested and you can add a bit of sophistication and break the action chain before it reaches this nonsense test:
Code:
<action condition="command_is_true([[ $(</tmp/test) == $(</tmp/testbackup) ]] && { do_something & echo true ;} || echo false )">break:</action>
Better performance, worse readability Laughing
Back to top
View user's profile Send private message 
zigbert


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

PostPosted: Tue 08 Aug 2017, 12:56    Post subject:  

Yeahhh!

Your code works, but it looses the handling of the $BUTTON value for release-event. I made a simple flag to store $BUTTON on press-event for later usage.

The code is too dirty (and complex) atm to show, but I will come back to it with a fresh brain and clean up. I had some other minor issues, so I had to change the approach a bit. I will come back with more feedback.

In the end we need to complete a simple, yet complete, example how to use and understand your code.

Keep it coming Very Happy
Thanks a lot
Sigmund

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


Joined: 26 Jan 2011
Posts: 1326
Location: Japan

PostPosted: Wed 09 Aug 2017, 00:39    Post subject:  

zigbert wrote:
Keep it coming Very Happy
OK, here we go:

First let's get rid of [[ $TREE ]] test in the function. The reason for that was a possibly empty $TREE, which occurs when the user drags the item just below itself.

And now the beauty part: Avoid all this (double) saving and copying stuff.
In my previous code all these actions fired with every release event, and of course double with a doubleclick. Made me nervous to think what might happen with speed when the list becomes bigger. Not elegant at all.

Below I attach an improved version that triggers only the main action and nothing else when the user clicks an item. It triggers the saving routine when the user moves an item. Find out why it works Wink
Code:
#!/bin/bash
ls -1 /usr/share/backgrounds > /tmp/test
do_something () { Xdialog -info  "Do something with\n$TREE" x 2000 ;} ; export -f do_something
echo '
<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" condition="command_is_true( ((PTR_Y)) && { do_something & echo true ;})">break:</action> 
      <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 -s


zigbert wrote:
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...
Well, "row-activated" , the default action, was listening. At least it listened to the Enter or Space key. It didn't pick up a doubleclick because a simple <action> (= "row-activated") , no matter where it is placed in the code, is always processed after the "button-release-event". With activating BTN_SAVE the action chain of the tree widget comes to an end and actions of the Button widget are processed. The process never returns to the tree widget to continue with the still "pending" row-activated event.

Good news: with above code the default action will now work. Personally I would prefer to use the default action so that the user can use either keyboard (Enter or Space) or mouse (doubleclick).

In above code try to change
Code:
<action signal="button-release-event" condition="command_is_true( ((PTR_Y)) && { do_something & echo true ;})">break:</action>
with
Code:
<action>do_something &</action>
<action signal="button-release-event" condition="command_is_true( echo $PTR_Y )">break:</action>
I think there is no need to specify the mouse button. Dragging works only with the left button, and so does doubleclick. Middle or right mouse button clicks are not affected by the code.
Back to top
View user's profile Send private message 
zigbert


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

PostPosted: Thu 10 Aug 2017, 13:47    Post subject:  

I think this is a wonderful workaround...
...But I really wonder what made you notice that $PTR_Y became 0 when moving an item - That is luck Laughing

I will wait a couple of days before updating the tips and tricks thread... It could be more.

Code:
#!/bin/bash
#Code below line 15 (break:) is activated when user move item in list

ls -1 /usr/share/backgrounds > /tmp/test
do_something () { Xdialog -info  "Do something with\n$TREE" x 2000 ;} ; export -f do_something
echo '
<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>do_something &</action>
      <action signal="button-release-event" condition="command_is_true( echo $PTR_Y )">break:</action>
      <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 -s

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


Joined: 10 Mar 2010
Posts: 4648
Location: Ontario

PostPosted: Sat 12 Aug 2017, 11:51    Post subject:  

sorting a list alphabetically can sometimes be helpful if test file is
created haphazardly

Code:
# sort alphabetically
LIST=$(sort -f /tmp/test)
echo "$LIST" > /tmp/test


I used script in puppy help system

http://murga-linux.com/puppy/viewtopic.php?p=964003#964003
____________________________________________________
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1326
Location: Japan

PostPosted: Sat 12 Aug 2017, 22:57    Post subject:  

Just for the record and everybody's amusement here is what I *thought* would be a solution to the "move onto item" problem.

It uses the deprecated table widget.
It nicely allows drag&drop only between items, eliminating the need for a work around. As a bonus it keeps the dragged item marked and does not fall into instant amnesia like tree.

Works perfectly here for at least 3 drops, but then...
Code:
#!/bin/bash
echo '
<table column-header-active="false|false" reorderable="true">
   <label>No|Fruit</label>
   <item>1|apple</item>
   <item>2|banana</item>
   <item>3|citron</item>
   <item>4|durian</item>
</table>' | gtkdialog -s
Back to top
View user's profile Send private message 
zigbert


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

PostPosted: Wed 16 Aug 2017, 18:08    Post subject:  

MochiMoppel wrote:
Works perfectly here for at least 3 drops, but then...
Laughing
_________________
Stardust resources
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 3 of 3 [37 Posts]   Goto page: Previous 1, 2, 3
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.1049s ][ Queries: 14 (0.0063s) ][ GZIP on ]