simple icon tray

Window managers, icon programs, widgets, etc.
Post Reply
Message
Author
seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#81 Post by seaside »

technosaurus wrote:good thinking about /proc/partitions - I assume that when /proc/partitions changes you look at /sys/block and/or /proc/mounts in the other script?
technosaurus,

Yes , much better to monitor /sys/block for specific directory changes than examining the single file /proc/partitions for specific content changes (difficult to say what went missing :) )

Regards,
s

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

Usbdrive icon in tray

#82 Post by seaside »

Ok, apparently "inotifyd" will not monitor /sys/block . (Maybe because of the kernel filesystem?). So here's another version using /root/.pupevent.

Unfortunately it can only do one usbdrive at a time because I don't see any way to link a specific icon when multiple sit icons are in use.

Below goes in "usr/share/sit/functions.sh"

Code: Select all

mountcode() {
# left click function mountcode

 [ ! -e /tmp/drv-pid ] && exit # nothing to mount or unmount
tdrv=`cat  /tmp/drv-pid` # check drive status
tdrv="${tdrv% *}"
if grep $tdrv  /proc/mounts; then
   umount /mnt/$tdrv
	if [ $? -eq 0 ];then
		rmdir /mnt/$tdrv
		ln -sf /usr/local/lib/X11/pixmaps/usbdrv48.png /tmp/drv-icon
		FILEMGR="rox -D"
		$FILEMGR /mnt/$tdrv 
	else
		Xdialog --title "WARNING" --msgbox "Sorry $tdrv did not unmount" 0 0
	fi

else
	FILEMGR="rox -d" #eg.. xfe # 
	TYPE="$(guess_fstype /dev/"$tdrv")" 
	[ ! -e /mnt/$tdrv ] && mkdir -p /mnt/$tdrv
	mount -t $TYPE /dev/$tdrv /mnt/$tdrv
		if [ $? -eq 0 ];then
	    ln -sf /usr/local/lib/X11/pixmaps/usbdrv_mntd48.png /tmp/drv-icon
		$FILEMGR /mnt/$tdrv 
		else
			Xdialog --title "WARNING" --msgbox "Sorry $tdrv did not mount" 0 0
		fi

fi
}	
Place script "usb-watch" below in $HOME/usb-watch

Code: Select all

#!/bin/sh
#  # inotifyd $HOME/usb-watch /root/.pup_event:nd # in startup

#echo $1  $3
 
if [[ $1 == d ]] ;then
	pdrv=`cat  /tmp/drv-pid` 
	pdrv="${pdrv#* }"
	kill "$pdrv"
	
	rm -f /tmp/drv-pid
	rm -f /tmp/drv-icon
	exit
fi
usbdrv=$3
usbdrv="${usbdrv#*_}"
[[ ! $usbdrv == sd[a-z][1-9] ]] && exit 
ln -s /usr/local/lib/X11/pixmaps/usbdrv48.png  /tmp/drv-icon 
sleep 1 # need time for diirectory to show in ./pupevent
tooltip=` awk -v i=$usbdrv '/<Summary>/ {print" " i"\n"" "$2,$4}' /root/.pup_event/"drive_$usbdrv"/AppInfo.xml |cut -d"<" -f1 `
sit /tmp/drv-icon "$tooltip" "mountcode"  &
pid=$!
echo "$usbdrv $pid" > /tmp/drv-pid
And the line "inotifyd $HOME/usb-watch /root/.pup_event:nd" needs to be started.

Cheers,
s

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

Re: Usbdrive icon in tray

#83 Post by technosaurus »

seaside wrote:Ok, apparently "inotifyd" will not monitor /sys/block . (Maybe because of the kernel filesystem?). So here's another version using /root/.pupevent.
Yes, I tried that. That's why I was glad to hear that it worked on /proc/partitions - that meant we could monitor something that would tell us when to look in /sys/block, but I couldn't get it to work on /proc/partitions myself.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

Re: Usbdrive icon in tray

#84 Post by seaside »

technosaurus wrote:
seaside wrote:Ok, apparently "inotifyd" will not monitor /sys/block . (Maybe because of the kernel filesystem?). So here's another version using /root/.pupevent.
Yes, I tried that. That's why I was glad to hear that it worked on /proc/partitions - that meant we could monitor something that would tell us when to look in /sys/block, but I couldn't get it to work on /proc/partitions myself.
technosaurus,

It looks like you're right, it doesn't work in /proc/partitions either (or at least not today :) ) So .pupevent is it.

Regards,
s
(I did the testing by faking a change to the /proc/partitions file instead of repeatedly plugging and unplugging a usb drive)

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#85 Post by technosaurus »

In case anyone was looking to make their applications portable to windows

this was built with mingw and http://ftp.acc.umu.se/pub/gnome/binarie ... _win32.zip
gcc -Os sit.c -o sit.exe -std=c89 -Wall `pkg-config gtk+-2.0 --cflags --libs` -s
Attachments
sit-win32.zip
(4.51 KiB) Downloaded 905 times
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

tweather

#86 Post by seaside »

Since there are libraries for many languages to handle xml code parsing, I was wondering if any xml help existed for shell programs in Linux and ran across this -
http://xml-coreutils.sourceforge.net/

It's a set of utilities aimed at emulating the standard shell text tools like sed, tr, cat, printf, find, etc... but specifically for xml.

I compiled xml-printf which can be used to capture the content between tags and made a tray icon program for weather.

Tweather takes information from rss.accuweather.com by zip code and displays the current weather icon in the tray. When the mouse is moved over the icon, current conditions are displayed and the forecast for tomorrow. A left-click of the icon refreshes the data and a right-click quits the program.

You'll need to edit the zip code at the top of the script for the zipcode you want to monitor.

Tweather requires Technosaurus' sit program found here-
http://www.murga-linux.com/puppy/viewto ... 1&start=70
and xml-printf which is in the attached xml-printf.tar.gz file. EDIT: see next post with a much smaller version kindly compiled by Vovchik

Probably best used by linking the tweather script to the /root/Startup folder so that it's available at the start.

Cheers,
s

Code: Select all

#!/bin/sh -a

# tweather tray icon weather
# Requires Technosaurus' sit program and xml-printf
# Seaside December 29, 2012
# Left-click refresh Right-click quit
# Place zip code below

refresh() {
	
	zipcode='10012' # <<< zipcode here
	
	
	loc='http://rss.accuweather.com/rss/liveweather_rss.asp?locCode='"$zipcode"''
	
	wget -O /tmp/tweather $loc
	
	w=`xml-printf '%s\n' /tmp/tweather :/rss/channel/item/description`
	
	i=o
	while read line; do  
	  array[$((++i))]=$line
	  case $i in
		1) CURRENT=${line%%<*} CURRENTI=${line#*=} CURRENTI=${CURRENTI/>/} ; wget -O /tmp/currenti ${CURRENTI//\"/}  ;;
		2) RANGE=${line%%<*}       ;;
		3) TOMORROW=${line%%<*}    ;;
		*)                         ;;
	  esac	
	done <<<"$w"
	
	echo "$CURRENT 
    $RANGE
-------------------------------------------------------------------
Tomorrow: $TOMORROW" >/tmp/tweather-tip
}

export -f refresh
refresh

sit /tmp/currenti /tmp/tweather-tip refresh  "kill $( </tmp/tweatherpid)" &
tweatherPID=$!
echo $tweatherPID >/tmp/tweatherpid
Attachments
tweather.png
Screenshot of tweather
(16.26 KiB) Downloaded 999 times
Last edited by seaside on Fri 04 Jan 2013, 17:37, edited 1 time in total.

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#87 Post by vovchik »

Dear seaside,

Happy New Year, and thanks for tweather and xml-print. I stripped your version and then upx'd it, reducing the size from 233k to 33k. I wish I knew how I could get tweather to show Vienna, Austria and Lviv, Ukraine. I don't know where to find the source xml file on accuweather. Have any ideas?

With kind regards,
vovchik
Attachments
xml-print.tar.gz
(31.75 KiB) Downloaded 789 times

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#88 Post by seaside »

vovchik wrote:Dear seaside,

Happy New Year, and thanks for tweather and xml-print. I stripped your version and then upx'd it, reducing the size from 233k to 33k. I wish I knew how I could get tweather to show Vienna, Austria and Lviv, Ukraine. I don't know where to find the source xml file on accuweather. Have any ideas?

With kind regards,
vovchik
vovchik,

A very Happy New Year to you as well.

Wow, that was an impressive reduction in the xml-printf size and thank you for doing that.

As the latest sit by default looks for functions in /usr/share/sit/functions, the above script will not refresh. So I moved the refresh function to /usr/share/sit/function*refresh. I also combined sit 1.0, xml-printf (your nicely reduced one) and tweather into an all inclusive pet as attached.

I think that accuweather seems to only have US feeds. There are other feeds mentioned here-
http://www.makeuseof.com/tag/7-feeds-rs ... r-updates/
but their formats would most likely be quite different.

Best Regards,
s
Attachments
tweather.pet
(35.06 KiB) Downloaded 900 times

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#89 Post by vovchik »

Dear seaside,

I installed your pet and it works nicely. I have also checked that link you provided for RSS feeds. Yahoo seems to cover the globe. To get Vienna, Austria, and centigrade, I use this:

Code: Select all

wget -O /tmp/weather-vienna 'http://weather.yahooapis.com/forecastrss?w=551801&u=c'
The next thing I will have to do is to learn how to parse that xml with xml-print. If you - or anybody else on the forum - have any good ideas, please post them....

With kind regards,
vovchik

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#90 Post by technosaurus »

I just posted some new svg tips for slicing png images in the
simple svg game framework thread
This allows you to use a single slice-able png image for all of the sprites (better for file size and for http requests if they are served online)
The tray icons are pretty small so I didn't think this would be relevant but it seems that some weather apis use png sprites to combine clouds, rain, sun, etc... into 1 image so that it can be downloaded all at once (this only requires 1 http request, so it is usually faster) and formatted using to the correct slice using css

I also wrote a sprite generator here:
http://murga-linux.com/puppy/viewtopic.php?t=82009
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

#91 Post by 01micko »

Hello vovchik

To get your weather code (replace zipcode variable) you have to jump through some hoops. You go to the download page for accuweather and get the "Net Weather" as if you were to add it to your website. Agree to their terms and a code box is presented. Scroll to the zipcode part and there is your weather code, replace spaces with %20. Mine is:

Code: Select all

zipcode='OCN|AU|QLD|GOLD%20COAST|&metric=1'
as it appears in /usr/share/sit/functions, works but is in farenheit. Would likely need to parse the METRIC= option in seaside's script for a choice. Or do the math, either way.
EDIT: no need for math or extra code, just add the "&metric=1" bit further down in the code for celcius.. edited my code and it works. For farenheit, no param or metric=0.
Attachments
capture29320.png
(9.37 KiB) Downloaded 1530 times
capture29633.png
(32.38 KiB) Downloaded 1569 times
Puppy Linux Blog - contact me for access

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#92 Post by vovchik »

Dear 01micko,

Happy New Year! You solved the problen in a very clever way. No need to register, but almost, to see the address. I also now get Celcius, which is what I want. Thanks.

With kind regards,
vovchik

User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

#93 Post by 01micko »

Hello vovchik

Yes, it is the same weather code as Pwidgets uses, but I didn't know you could append the "metric=" bit to that code, a handy feature.

Once upon a time Accuweather had that code in the URL for a location, but now it is hidden away in the html. I just stumbled upon the "Net Weather" method, kind of an "educated guess". Easy enough I think :) .

Happy New Year to you too.
Puppy Linux Blog - contact me for access

User avatar
Geoffrey
Posts: 2355
Joined: Sun 30 May 2010, 08:42
Location: Queensland

#94 Post by Geoffrey »

I had a bit of a play with this weather app, I managed to get it working using yad for the notification.

Code: Select all

#! /bin/bash

function refresh() {
	zipcode='10012' # <<< put zipcode here
	
	loc='http://rss.accuweather.com/rss/liveweather_rss.asp?locCode='"$zipcode"''
	wget -O /tmp/tweather $loc
	
	w=`xml-printf '%s\n' /tmp/tweather :/rss/channel/item/description`
	
	i=o
	while read line; do  
	  array[$((++i))]=$line
	  case $i in
		1) CURRENT=${line%%<*} CURRENTI=${line#*=} CURRENTI=${CURRENTI/>/} ; wget -O /tmp/currenti ${CURRENTI//\"/}  ;;
		2) RANGE=${line%%<*}       ;;
		3) TOMORROW=${line%%<*}    ;;
		*)                         ;;
	  esac	
	done <<<"$w"
echo "$CURRENT 
    $RANGE
-------------------------------------------------------------------
Tomorrow: $TOMORROW" >/tmp/tweather-tip
}
export -f refresh
sh -c refresh

line1=`awk 'NR==1' < /tmp/tweather-tip`	
line2=`awk 'NR==2' < /tmp/tweather-tip`
line3=`awk 'NR==3' < /tmp/tweather-tip`
line4=`awk 'NR==4' < /tmp/tweather-tip`

exec yad --notification --text="$line1 $line2 $line3 $line4" --image="/tmp/currenti" --command "sh -c refresh"
[b]Carolina:[/b] [url=http://smokey01.com/carolina/pages/recent-repo.html]Recent Repository Additions[/url]
[img]https://dl.dropboxusercontent.com/s/ahfade8q4def1lq/signbot.gif[/img]

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

tweather

#95 Post by seaside »

01micko,

I was pleased to see that you found a world solution for Accuweather because I just took a look at Yahoo weather and while they have the same xml path to the "description" tag, the actual content is composed of DATA html markup. Short of stripping out the html code, I'm not sure how sit can display any markup.

Geoffrey,

Yes, nice and Yad is always a good swiss army knife located comfortably between Xdialog and gtkdialog.

vovchik ,

I feel much warmer knowing that you'll be able to tell exactly how cold it is where you are. :D

A very Happy New Year to all,
s

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#96 Post by technosaurus »

to get markup from rss feeds most people typically grep for the needed tag and then strip the tags out using sed ... I use shell only methods such as:
(just the jist of it - not tested, and I always seem to mix up ## and %%)

Code: Select all

wget -O - url | while read LINE; do
case "$LINE in" *something*)
  CONTENT=${LINE%%* beginning stuff to remove>}
  CONTENT=${CONTENT##</end stuff to remove*}
  echo $CONTENT >>somefile.svg
;;
esac
done
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
mavrothal
Posts: 3096
Joined: Mon 24 Aug 2009, 18:23

#97 Post by mavrothal »

seaside wrote: As the latest sit by default looks for functions in /usr/share/sit/functions, the above script will not refresh. So I moved the refresh function to /usr/share/sit/function*refresh. I also combined sit 1.0, xml-printf (your nicely reduced one) and tweather into an all inclusive pet as attached.
Works nicely with JWM tray and also with tint2 that I tried it.
I have this little /root/Startup script (since is will fail with no connection in pace).

Code: Select all

#!/bin/sh

IFCONFIG="`ifconfig | grep '^[pwe]' | grep -v 'wmaster'`"
while [ "$IFCONFIG" != "" ]; do
	sleep 1
    ping -c 1 8.8.8.8 
    if [ $? -eq 0 ];then
		break
	else
		ping -c 1 www.google.com
		if [ $? -eq 0 ];then
			break
		fi
	fi
done

tweather
One "problem" I have is that right-click on the applet will quit it.
How do I avoid this?

Happy New Year.
== [url=http://www.catb.org/esr/faqs/smart-questions.html]Here is how to solve your[/url] [url=https://www.chiark.greenend.org.uk/~sgtatham/bugs.html]Linux problems fast[/url] ==

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#98 Post by seaside »

mavrothal wrote:
One "problem" I have is that right-click on the applet will quit it.
How do I avoid this?

Happy New Year.
mavrothal,

Happy New Year to you as well.

You can change this line-

Code: Select all

sit /tmp/currenti /tmp/tweather-tip refresh  "kill $( </tmp/tweatherpid)" & 
to

Code: Select all

sit /tmp/currenti /tmp/tweather-tip refresh  & 
That should reassign the right-click to no action.

Nice script for checking if your connection is up.

Regards,
s

User avatar
Geoffrey
Posts: 2355
Joined: Sun 30 May 2010, 08:42
Location: Queensland

#99 Post by Geoffrey »

mavrothal wrote:
I have this little /root/Startup script (since is will fail with no connection in pace).

Code: Select all

#!/bin/sh

IFCONFIG="`ifconfig | grep '^[pwe]' | grep -v 'wmaster'`"
while [ "$IFCONFIG" != "" ]; do
	sleep 1
    ping -c 1 8.8.8.8 
    if [ $? -eq 0 ];then
		break
	else
		ping -c 1 www.google.com
		if [ $? -eq 0 ];then
			break
		fi
	fi
done

tweather
Nice, I was only the other day looking for such a script, I found that cairo-dock with it's weather widget has the same dilemma, I will be using this, thanks.
[b]Carolina:[/b] [url=http://smokey01.com/carolina/pages/recent-repo.html]Recent Repository Additions[/url]
[img]https://dl.dropboxusercontent.com/s/ahfade8q4def1lq/signbot.gif[/img]

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

Yweather 0.1a - taskbar weather app

#100 Post by vovchik »

Dear guys,

I have coded a taskbar weather app in BaCon - based on Yahoo's weather API - and it is available here: http://www.murga-linux.com/puppy/viewto ... 079#676079.

Have fun....

With kind regards,
vovchik

Post Reply