| Author |
Message |
Argolance

Joined: 06 Jan 2008 Posts: 1376 Location: PORT-BRILLET (Mayenne - France)
|
Posted: Tue 02 Aug 2011, 04:23 Post subject:
Detect cursor position |
|
Hello,
How to detect if the mouse cursor is crossing over or out of a specific area of a GUI? In my case, this area is composed by the lines/items of a tree list: I would like to deactivate mouse cursor events when it is out of the tree list area...
More: is it possible to change mouse cursor when this happens?
Thank you.
Cordialement.
_________________

|
|
Back to top
|
|
 |
puppyluvr

Joined: 06 Jan 2008 Posts: 3053 Location: Chickasha Oklahoma
|
Posted: Tue 02 Aug 2011, 04:35 Post subject:
|
|
Hello,
You could use "getcurpos" in a function..
_________________ "Close the "Windows", and open your eyes, to a whole new world"
http://puppylinuxstuff.meownplanet.net/puppyluvr/
http://theplpd.webs.com/
Nothing but Puppy since 2.15CE...
|
|
Back to top
|
|
 |
Argolance

Joined: 06 Jan 2008 Posts: 1376 Location: PORT-BRILLET (Mayenne - France)
|
Posted: Tue 02 Aug 2011, 04:48 Post subject:
|
|
Hello (Forgot to specify it is a Gtkdialog3 GUI).
Thank you for your fast reply!
Where could I find explanations and examples of the way to use "getcurpos"?
Cordialement.
_________________

|
|
Back to top
|
|
 |
8-bit

Joined: 03 Apr 2007 Posts: 3012 Location: Oregon
|
Posted: Tue 02 Aug 2011, 16:08 Post subject:
Subject description: Help maybe |
|
| Argolance wrote: | Hello (Forgot to specify it is a Gtkdialog3 GUI).
Thank you for your fast reply!
Where could I find explanations and examples of the way to use "getcurpos"?
Cordialement. |
I have been doing a lot of searching and coding and came up with this:
| Code: |
#!/bin/sh
move (){
sopp="`cat /tmp/who|sed -e 's/^.*\(...\)$/\1/'`"
where
if [ $sop = $sopp ];then
return
fi
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
}
where(){
getcurpos > /tmp/who
sop="`cat /tmp/who|sed -e 's/^.*\(...\)$/\1/'`"
}
export -f move
ls -1 /usr/share/backgrounds > /tmp/list
export -f where
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-press-event\">where</action>
<action signal=\"button-release-event\">move</action>
<action signal=\"button-release-event\">refresh:TREE</action>
</tree>"
gtkdialog3 --center -p test
|
I did not allow for cursor drift though. So click and release must be at the same position exactly. Modify it as you wish.
Now you do realize I would not do this for just anybody!
|
|
Back to top
|
|
 |
8-bit

Joined: 03 Apr 2007 Posts: 3012 Location: Oregon
|
Posted: Tue 02 Aug 2011, 16:32 Post subject:
|
|
I don't think I mentioned this, but I know almost nothing about the use of "sed" in programming. I actually found an example on the forum and cut and pasted it with minor modifications as to the source it was reading from and the number of characters to return.
But who knows.
One of these days, I may actually be able to do a little programming on my own.
|
|
Back to top
|
|
 |
puppyluvr

Joined: 06 Jan 2008 Posts: 3053 Location: Chickasha Oklahoma
|
Posted: Tue 02 Aug 2011, 17:12 Post subject:
|
|
Hello,
Thanks 8-bit..
I spent most of my lunch writing a script to demo getcurpos, but didnt finish it before I had to go back to work, and when I got home, you already had..
Here is the first part..
| Quote: |
#!/bin/sh
while z=1
do
MOUSE_X="`getcurpos | awk '{print $1}'`"
MOUSE_Y="`getcurpos | awk '{print $2}'`"
echo $MOUSE_X
echo $MOUSE_Y
sleep 1
done |
Run in a terminal, it echos the cursor position...
_________________ "Close the "Windows", and open your eyes, to a whole new world"
http://puppylinuxstuff.meownplanet.net/puppyluvr/
http://theplpd.webs.com/
Nothing but Puppy since 2.15CE...
|
|
Back to top
|
|
 |
8-bit

Joined: 03 Apr 2007 Posts: 3012 Location: Oregon
|
Posted: Tue 02 Aug 2011, 18:30 Post subject:
|
|
I originally had one similar to yours that worked fine in a terminal.
But for some reason, the same thing dropped into a gtkdialog script did not populate the variables.
I am still trying to figure out why it would work in a terminal and not in a gtkdialog script.
|
|
Back to top
|
|
 |
Dave_G

Joined: 21 Jul 2011 Posts: 459
|
Posted: Wed 03 Aug 2011, 04:30 Post subject:
|
|
Hi guys,
Nice one.
How about:
# ==============================
#!/bin/sh
while z=1
do
tput clear
MOUSE_X="`getcurpos | awk '{print $1}'`"
MOUSE_Y="`getcurpos | awk '{print $2}'`"
echo $MOUSE_X
echo $MOUSE_Y
sleep 1
done
# ==============================
|
|
Back to top
|
|
 |
Argolance

Joined: 06 Jan 2008 Posts: 1376 Location: PORT-BRILLET (Mayenne - France)
|
Posted: Wed 03 Aug 2011, 14:05 Post subject:
|
|
Hello,
I am just coming back home! Thanks to all of you for your very useful comments and code lines much appreciated.
Now I have to understand... and adapt!
"See" you soon!
Best regards.
_________________

|
|
Back to top
|
|
 |
8-bit

Joined: 03 Apr 2007 Posts: 3012 Location: Oregon
|
Posted: Wed 03 Aug 2011, 23:25 Post subject:
|
|
| Dave_G wrote: | Hi guys,
Nice one.
How about:
# ==============================
#!/bin/sh
while z=1
do
tput clear
MOUSE_X="`getcurpos | awk '{print $1}'`"
MOUSE_Y="`getcurpos | awk '{print $2}'`"
echo $MOUSE_X
echo $MOUSE_Y
sleep 1
done
# ============================== |
What does the "tput clear" line do?
The reason I am curious, is that with my attempt at using getcurpos, If I get carried away with mouse clicks, the program tries to execute the returned variable witch messes up the application.
|
|
Back to top
|
|
 |
puppyluvr

Joined: 06 Jan 2008 Posts: 3053 Location: Chickasha Oklahoma
|
Posted: Thu 04 Aug 2011, 00:04 Post subject:
|
|
Hello,
| Quote: | | What does the "tput clear" line do? |
Clears the terminal between inputs...
(Instead of scrolling them in the terminal.)
_________________ "Close the "Windows", and open your eyes, to a whole new world"
http://puppylinuxstuff.meownplanet.net/puppyluvr/
http://theplpd.webs.com/
Nothing but Puppy since 2.15CE...
|
|
Back to top
|
|
 |
seaside
Joined: 11 Apr 2007 Posts: 834
|
Posted: Thu 04 Aug 2011, 11:33 Post subject:
|
|
Argolance,
Perhaps some signal functions in gtkdialog would help -
| Code: |
#! /bin/bash
export DIALOG='
<window title="Example Window" icon-name="gtk-dialog-warning">
<vbox>
<frame Widgets>
<text>
<label>Label</label>
<action signal="button-press-event">echo Label: button-press-event</action>
<action signal="button-release-event">echo Label: button-release-event</action>
<action signal="configure-event">echo Label: configure-event</action>
<action signal="enter-notify-event">echo Label: enter-notify-event</action>
<action signal="leave-notify-event">echo Label: leave-notify-event</action>
<action signal="focus-in-event">echo Label: focus-in-event</action>
<action signal="focus-out-event">echo Label: focus-out-event</action>
<action signal="key-press-event">echo Label: key-press-event</action>
<action signal="key-release-event">echo Label: key-release-event</action>
<action signal="hide">echo Label: hide</action>
<action signal="show">echo Label: show</action>
<action signal="map-event">echo Label: map-event</action>
<action signal="unmap-event">echo Label: unmap-event</action>
</text>
<entry>
<default>Entry</default>
<action signal="button-press-event">echo Entry: button-press_event</action>
<action signal="button-release-event">echo Entry: button-release-event</action>
<action signal="configure-event">echo Entry: configure-event</action>
<action signal="enter-notify-event">echo Entry: enter-notify-event</action>
<action signal="leave-notify-event">echo Entry: leave-notify-event</action>
<action signal="focus-in-event">echo Entry: focus-in-event</action>
<action signal="focus-out-event">echo Entry: focus-out-event</action>
<action signal="key-press-event">echo Entry: key-press-event</action>
<action signal="key-release-event">echo Entry: key-release-event</action>
<action signal="hide">echo Entry: hide</action>
<action signal="show">echo Entry: show</action>
<action signal="map-event">echo Entry: map-event</action>
<action signal="unmap-event">echo Entry: unmap-event</action>
</entry>
</frame>
<hbox>
<button ok>
<action signal="button-press-event">echo Button: button-press_event</action>
<action signal="button-release-event">echo Button: button-release-event</action>
<action signal="configure-event">echo Button: configure-event</action>
<action signal="enter-notify-event">echo Button: enter-notify-event</action>
<action signal="leave-notify-event">echo Button: leave-notify-event</action>
<action signal="focus-in-event">echo Button: focus-in-event</action>
<action signal="focus-out-event">echo Button: focus-out-event</action>
<action signal="key-press-event">echo Button: key-press-event</action>
<action signal="key-release-event">echo Button: key-release-event</action>
<action signal="hide">echo Button: hide</action>
<action signal="show">echo Button: show</action>
<action signal="map-event">echo Button: map-event</action>
<action signal="unmap-event">echo Button: unmap-event</action>
</button>
</hbox>
</vbox>
<action signal="button-press-event">echo Window: button-press_event</action>
<action signal="button-release-event">echo Window: button-release-event</action>
<action signal="configure-event">echo Window: configure-event</action>
<action signal="delete-event">echo Window: delete-event</action>
<action signal="destroy-event">echo Window: destroy-event</action>
<action signal="enter-notify-event">echo Window: enter-notify-event</action>
<action signal="leave-notify-event">echo Window: leave-notify-event</action>
<action signal="focus-in-event">echo Window: focus-in-event</action>
<action signal="focus-out-event">echo Window: focus-out-event</action>
<action signal="key-press-event">echo Window: key-press-event</action>
<action signal="key-release-event">echo Window: key-release-event</action>
<action signal="hide">echo Window: hide</action>
<action signal="show">echo Window: show</action>
<action signal="map-event">echo Window: map-event</action>
<action signal="unmap-event">echo Window: unmap-event</action>
</window>
'
gtkdialog3 --program=DIALOG
|
Specifically, the "enter-notify-event" and "leave-notify-event" signals.
Regards,
s
|
|
Back to top
|
|
 |
8-bit

Joined: 03 Apr 2007 Posts: 3012 Location: Oregon
|
Posted: Thu 04 Aug 2011, 12:18 Post subject:
|
|
Seaside,
Thank you for the signal function example!
It gives one a better idea of what can be done.
|
|
Back to top
|
|
 |
cat_n_mouse

Joined: 04 Aug 2011 Posts: 12 Location: /usr/bin/Paulo
|
Posted: Thu 04 Aug 2011, 14:39 Post subject:
|
|
Thank you seaside, I suspect your example will be of help to many.
|
|
Back to top
|
|
 |
|