Detect cursor position
- Argolance
- Posts: 3767
- Joined: Sun 06 Jan 2008, 22:57
- Location: PORT-BRILLET (Mayenne - France)
- Contact:
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.
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.
I have been doing a lot of searching and coding and came up with this: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.
Code: Select all
#!/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
Now you do realize I would not do this for just anybody!
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.
But who knows.
One of these days, I may actually be able to do a little programming on my own.
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..
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..
Run in a terminal, it echos the cursor position...#!/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
Close the Windows, and open your eyes, to a whole new world
I am Lead Dog of the
Puppy Linux Users Group on Facebook
Join us!
Puppy since 2.15CE...
I am Lead Dog of the
Puppy Linux Users Group on Facebook
Join us!
Puppy since 2.15CE...
What does the "tput clear" line do?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
# ==============================
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.
Argolance,
Perhaps some signal functions in gtkdialog would help -
Specifically, the "enter-notify-event" and "leave-notify-event" signals.
Regards,
s
Perhaps some signal functions in gtkdialog would help -
Code: Select all
#! /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
Regards,
s
- cat_n_mouse
- Posts: 12
- Joined: Thu 04 Aug 2011, 18:29
- Location: /usr/bin/Paulo