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 Sun 21 Sep 2014, 18:31
All times are UTC - 4
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Desktop
move icon by a script
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
Page 2 of 2 Posts_count   Goto page: Previous 1, 2
Author Message
SFR


Joined: 26 Oct 2011
Posts: 1068

PostPosted: Thu 27 Dec 2012, 17:56    Post_subject:  

Not sure if I understand...

To destroy a window you can use the technique from my previous post:
Quote:
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:
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:
#! /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. Wink

Greetings!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send_private_message 
der-schutzhund

Joined: 26 Nov 2007
Posts: 781
Location: Blomberg / Germany

PostPosted: Thu 27 Dec 2012, 18:29    Post_subject:  

Hey,

i have made 2 scripts like:
This script to make the Infowindow:
Code:
#! /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:
#! /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
Back to top
View user's profile Send_private_message 
SFR


Joined: 26 Oct 2011
Posts: 1068

PostPosted: Thu 27 Dec 2012, 18:39    Post_subject:  

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:
#! /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:
#! /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!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send_private_message 
der-schutzhund

Joined: 26 Nov 2007
Posts: 781
Location: Blomberg / Germany

PostPosted: Thu 27 Dec 2012, 19:02    Post_subject:  

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

Greetings!

Wolfgang
Back to top
View user's profile Send_private_message 
SFR


Joined: 26 Oct 2011
Posts: 1068

PostPosted: Thu 27 Dec 2012, 20:05    Post_subject:  

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

Greetings!

Wolfgang

You're welcome. Smile
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!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send_private_message 
der-schutzhund

Joined: 26 Nov 2007
Posts: 781
Location: Blomberg / Germany

PostPosted: Fri 28 Dec 2012, 13:27    Post_subject:  

Hey SFR,

Code:
# -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
Back to top
View user's profile Send_private_message 
SFR


Joined: 26 Oct 2011
Posts: 1068

PostPosted: Fri 28 Dec 2012, 14:00    Post_subject:  

Hey, usually I'm doing it this way:

Code:
#! /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:
MAXX=`xwininfo -root | grep Width | awk '{print $2}'`
MAXY=`xwininfo -root | grep Height | awk '{print $2}'`

Use what suits you better.

Greetings!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send_private_message 
der-schutzhund

Joined: 26 Nov 2007
Posts: 781
Location: Blomberg / Germany

PostPosted: Fri 28 Dec 2012, 15:51    Post_subject:  

Hey,

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

Greetings!

Wolfgang
Back to top
View user's profile Send_private_message 
SFR


Joined: 26 Oct 2011
Posts: 1068

PostPosted: Fri 28 Dec 2012, 16:17    Post_subject:  

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

This line already doing it:
Code:
[ "`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!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send_private_message 
der-schutzhund

Joined: 26 Nov 2007
Posts: 781
Location: Blomberg / Germany

PostPosted: Fri 28 Dec 2012, 18:27    Post_subject:  

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:
#! /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
Back to top
View user's profile Send_private_message 
SFR


Joined: 26 Oct 2011
Posts: 1068

PostPosted: Fri 28 Dec 2012, 19:22    Post_subject:  

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:
#! /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!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send_private_message 
der-schutzhund

Joined: 26 Nov 2007
Posts: 781
Location: Blomberg / Germany

PostPosted: Sat 29 Dec 2012, 07:59    Post_subject:  

Hey SFR,

here you can see the result: http://murga-linux.com/puppy/viewtopic.php?p=674090#674090

My be you can use it.

Greetings!

Wolfgang
Back to top
View user's profile Send_private_message 
SFR


Joined: 26 Oct 2011
Posts: 1068

PostPosted: Sat 29 Dec 2012, 11:14    Post_subject:  

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!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send_private_message 
der-schutzhund

Joined: 26 Nov 2007
Posts: 781
Location: Blomberg / Germany

PostPosted: Sat 29 Dec 2012, 15:28    Post_subject:  

Hey,

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

Greetings!

Wolfgang
Back to top
View user's profile Send_private_message 
SFR


Joined: 26 Oct 2011
Posts: 1068

PostPosted: Sat 29 Dec 2012, 16:12    Post_subject:  

Thanks, now it's fine!

Greetings!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send_private_message 
Display_posts:   Sort by:   
Page 2 of 2 Posts_count   Goto page: Previous 1, 2
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Desktop
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1107s ][ Queries: 12 (0.0148s) ][ GZIP on ]