move icon by a script

Window managers, icon programs, widgets, etc.
Message
Author
User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#16 Post by SFR »

Not sure if I understand...

To destroy a window you can use the technique from my previous post:
gtkdialog -G 256x48+400+400 -p MAIN & WINDOW_PID=$!
sleep 5
kill $WINDOW_PID # kill window
Of course instead of 'sleep 5' you need to put a condition, like:

Code: Select all

if [ something ]; then
  kill $WINDOW_PID
fi
But if this info window is supposed to be placed on fixed position, it's better to only change its contents, like in this:

Code: Select all

#! /bin/bash

touch /tmp/temp_text.txt
echo "initial msg" > /tmp/temp_text.txt

export MAIN='
<window width-request="300">
  <text><variable>MESSAGE</variable><input file>/tmp/temp_text.txt</input></text>
  <timer interval="1" visible="false">
    <action>refresh:MESSAGE</action>
  </timer>
</window>
'

gtkdialog -p MAIN
(When you run this script, just modify contents of /tmp/temp_text.txt file and the change in the window will be visible after max. 1 second.)

But like I said, I'm not sure if I fully understand your design plan. ;)

Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

der-schutzhund
Posts: 1045
Joined: Mon 26 Nov 2007, 22:07
Location: Blomberg / Germany

#17 Post by der-schutzhund »

Hey,

i have made 2 scripts like:
This script to make the Infowindow:

Code: Select all

#! /bin/bash

# decorated="false" - no window decorations
# skip_taskbar_hint="true" - no script name on the taskbar (thanks to Puppylvr ;)
export MAIN='
<window decorated="false" skip_taskbar_hint="true">
  <text use-markup="true"><label>"<b><span color='"'blue'"' size='"'xx-large'"'><u>Some message...</u></span></b>"</label></text>
</window>
'

# -G <width>x<height>+<X_position>+<Y_position>
gtkdialog -G 256x48+400+400 -p MAIN & WINDOW_PID=$!
And a script to clear the Infowindow:

Code: Select all

#! /bin/bash

kill $WINDOW_PID   # kill window
Then I have used the first script that generates info window, and later with the second script tries again to delete.
Sometimes I could not delete the window anymore.
That's the problem!

Greetings!

Wolfgang

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#18 Post by SFR »

The problem is that the second script can't read the real $WINDOW_PID value, as it is complete different process that has no access to another processes' data.

But the workaround is simple, it's enough to use a temporary file.

First script:

Code: Select all

#! /bin/bash 

# decorated="false" - no window decorations 
# skip_taskbar_hint="true" - no script name on the taskbar (thanks to Puppylvr ;) 
export MAIN=' 
<window decorated="false" skip_taskbar_hint="true"> 
   <text use-markup="true"><label>"<b><span color='"'blue'"' size='"'xx-large'"'><u>Some message...</u></span></b>"</label></text>
</window> 
 ' 

# -G <width>x<height>+<X_position>+<Y_position> 
gtkdialog -G 256x48+400+400 -p MAIN & WINDOW_PID=$!
echo $WINDOW_PID > /tmp/temp_PID
Second script:

Code: Select all

#! /bin/bash 
[ -f /tmp/temp_PID ] && WINDOW_PID=`cat /tmp/temp_PID` || exit
rm -f /tmp/temp_PID # remove temp file, if already used
kill $WINDOW_PID   # kill window
Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

der-schutzhund
Posts: 1045
Joined: Mon 26 Nov 2007, 22:07
Location: Blomberg / Germany

#19 Post by der-schutzhund »

Absolutely brilliant!
Thank you so much!
Where do you live and what you do professionally?

Greetings!

Wolfgang

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#20 Post by SFR »

der-schutzhund wrote:Absolutely brilliant!
Thank you so much!
Where do you live and what you do professionally?

Greetings!

Wolfgang
You're welcome. :)
We're neighbours actually - the next country eastward.
Currently I'm happily unemployed yet (I truly hated my last job), that's why I have some more time to tinker with Puppy, but have no profession as such; general high school.
Everything (useful) that I know, I've learned by myself...

Cheers from PL &
Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

der-schutzhund
Posts: 1045
Joined: Mon 26 Nov 2007, 22:07
Location: Blomberg / Germany

#21 Post by der-schutzhund »

Hey SFR,

Code: Select all

# -G <width>x<height>+<X_position>+<Y_position>
gtkdialog -G 256x24+500+600 -p MAIN & WINDOW_PID=$!
How can i place the Window at X-center and for example 50 from max Y?

Greetings

Wolfgang

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#22 Post by SFR »

Hey, usually I'm doing it this way:

Code: Select all

#! /bin/bash

# Determine current screen resolution
RES=$(xrandr | grep "current" | awk '{print$8"x"$10}' | tr -d ',')
[ "`echo "$RES" | tr -cd '[[:digit:]]'`" = "" ] && RES=$(xrandr | grep "*" | awk '{print$2"x"$4}')	# XVesa has different ouput IIRC(?)
MAXX=$(echo $RES | cut -f1 -d 'x')
MAXY=$(echo $RES | cut -f2 -d 'x')

WIDTH=200	# Window width
HEIGHT=40	# Window height

X=$(( ($MAXX/2) - ($WIDTH/2) ))		# Center horizontally
Y=$(( $MAXY-$HEIGHT-50 ))			# 50px above bottom of the screen

export MAIN='
<window>
  <text><label>Some text blah blah blah...</label></text>
</window>
'

gtkdialog -G "$WIDTH"x"$HEIGHT"+"$X"+"$Y" -p MAIN
BTW, the max. width and height of the screen can be also determined using xwininfo:

Code: Select all

MAXX=`xwininfo -root | grep Width | awk '{print $2}'`
MAXY=`xwininfo -root | grep Height | awk '{print $2}'`
Use what suits you better.

Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

der-schutzhund
Posts: 1045
Joined: Mon 26 Nov 2007, 22:07
Location: Blomberg / Germany

#23 Post by der-schutzhund »

Hey,

and what happens when you work with Xvesa and how an error can be avoided?

Greetings!

Wolfgang

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#24 Post by SFR »

and what happens when you work with Xvesa and how an error can be avoided?
This line already doing it:

Code: Select all

[ "`echo "$RES" | tr -cd '[[:digit:]]'`" = "" ] && RES=$(xrandr | grep "*" | awk '{print$2"x"$4}')   # XVesa has different ouput IIRC(?)
(desc.: if the first readout, stripped of non-digits, is empty - use alternative method to read resolution)

I can't verify it at the moment, but the above code worked fine in Akita with XVesa.

But maybe actually it's better to use xwininfo; should be more resistant to such factors...

Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

der-schutzhund
Posts: 1045
Joined: Mon 26 Nov 2007, 22:07
Location: Blomberg / Germany

#25 Post by der-schutzhund »

ok!
Then I have two small questions:
1. When I run a script in the first erase routine to delete the last window and then the routine to create a new window, then nothing is displayed.

2. How can I use the text to be displayed variable?

Code: Select all

#! /bin/bash
[ -f /tmp/temp_PID ] && WINDOW_PID=`cat /tmp/temp_PID` || exit
rm -f /tmp/temp_PID # remove temp file, if already used
kill $WINDOW_PID   # kill window
.
.
my programcode
.
.
----------------------------------------------------------- 
RES=$(xrandr | grep "current" | awk '{print$8"x"$10}' | tr -d ',')
----------------------------------------------------------- 
[ "`echo "$RES" | tr -cd '[[:digit:]]'`" = "" ] && RES=$(xrandr | grep "*" | awk '{print$2"x"$4}')
----------------------------------------------------------- 
MAXX=$(echo $RES | cut -f1 -d 'x')
MAXY=$(echo $RES | cut -f2 -d 'x')
----------------------------------------------------------- 
WIDTH=300
HEIGHT=24
----------------------------------------------------------- 
X=$(( ($MAXX/2) - ($WIDTH/2) ))
Y=$(( $MAXY-$HEIGHT-130 ))
export MAIN='
<window decorated="false" skip_taskbar_hint="true">
   <text use-markup="true"><label>"<b><span color='"'black'"' size='"'large'"'><u>Some message...</u></span></b>"</label></text>
</window>
'
gtkdialog -G "$WIDTH"x"$HEIGHT"+"$X"+"$Y" -p MAIN & WINDOW_PID=$!
echo $WINDOW_PID > /tmp/temp_PID

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#26 Post by SFR »

Since scripts have been merged again, everything ends at the first line because of 'exit' - simply, it cannot find /tmp/temp_PID file.

This one should be ok and additionally, if you'd like to have it that way, 'WITDH' is being (approximately) calculated from the text lenght.
But if you change font size, you have to adjust it again...

Usage:
script_name "Some text..."
script_name "Some different text..."
or
script_name
without arguments to close the window completely.

Code: Select all

#! /bin/bash 

TEMPFILE=/tmp/infowindow_temp_PID
[ -f $TEMPFILE ] && WINDOW_PID=`cat $TEMPFILE` && kill $WINDOW_PID && rm -f $TEMPFILE

#. 
#. 
#my programcode 
#. 
#.

MESSAGE="$1"	# first passed parameter is a message
[ "$MESSAGE" = "" ] && exit	# if no parameter - exit

#----------------------------------------------------------- 
RES=$(xrandr | grep "current" | awk '{print$8"x"$10}' | tr -d ',') 
#----------------------------------------------------------- 
[ "`echo "$RES" | tr -cd '[[:digit:]]'`" = "" ] && RES=$(xrandr | grep "*" | awk '{print$2"x"$4}') 
#----------------------------------------------------------- 
MAXX=$(echo $RES | cut -f1 -d 'x')
MAXY=$(echo $RES | cut -f2 -d 'x')
#----------------------------------------------------------- 
WIDTH=$(( (${#MESSAGE}+1) *12))		# WIDTH = ((lenght of text + 1) * 12)
HEIGHT=24
#----------------------------------------------------------- 
X=$(( ($MAXX/2) - ($WIDTH/2) )) 
Y=$(( $MAXY-$HEIGHT-130 )) 
export MAIN=' 
<window decorated="false" skip_taskbar_hint="true"> 
   <text use-markup="true"><label>"<b><span color='"'black'"' size='"'large'"'><u>'$MESSAGE'</u></span></b>"</label></text> 
</window> 
' 
gtkdialog -G "$WIDTH"x"$HEIGHT"+"$X"+"$Y" -p MAIN & WINDOW_PID=$! 
echo $WINDOW_PID > $TEMPFILE
Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

der-schutzhund
Posts: 1045
Joined: Mon 26 Nov 2007, 22:07
Location: Blomberg / Germany

#27 Post by der-schutzhund »

Hey SFR,

here you can see the result: http://murga-linux.com/puppy/viewtopic. ... 090#674090

My be you can use it.

Greetings!

Wolfgang

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#28 Post by SFR »

Hey Wolfgang.

Although I was able to use v1.0 from command line and create/enable/disable different groups, but I tried to download a couple of times v1.1 and it seems that this is the same version - can't see any difference...
Could you check if variomen_1_1.pet contains new scripts for sure?

Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

der-schutzhund
Posts: 1045
Joined: Mon 26 Nov 2007, 22:07
Location: Blomberg / Germany

#29 Post by der-schutzhund »

Hey,

you are right! Sorry! Now you can download the 1.1!

Greetings!

Wolfgang

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#30 Post by SFR »

Thanks, now it's fine!

Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

Post Reply