simple icon tray

Window managers, icon programs, widgets, etc.
Message
Author
User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#76 Post by technosaurus »

Unfortunately inotify doesn't work on sysfs AFAIK, thus the polling.
You could adapt pup_event* similar to how scottman did in akita. Akaskrawal may have a better method though. He wrote a standalone drive monitor in c using glib/gio.
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
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#77 Post by technosaurus »

I only put one function in /usr/share/sit/... feel free to add your own to that file so you don't need to use the -i parameter.

FYI puppy has inotifyd (from busybox) that can do the same stuff for your sit scripts.

RE drive icons - rather than changing the .DirIcon in $HOME/.pup_event/* Barry has a function in /etc/rc.d/functions4puppy4 called icon_{un,}mounted_func that guts $HOME/.config/rox.sourceforge.net/globicons
(note that I am using $HOME vs /root - why intentionally make your scripts unportable? ... even ~ would be better than /root)
short answer - you can modify /etc/rc.d/functions4puppy4 to (additionally or instead of) put the icons somewhere. (long answer is left as an exercise for the reader)
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
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#78 Post by technosaurus »

I was just poking around on gtkdialog to try and replace libglade with gtk's builtin gtkbuilder (displays, but actions didn't work). If I ever figure out how to connect the callback functions I may add support for using gtkbuilder ui files (XML built with glade-3) if anyone is interested in using a GUI RAD to put together their UI rather than hand coding XML and having to call gtkdialog.
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

usbdrive

#79 Post by seaside »

Here's a short prototype for recognizing and showing an icon in the tray when a usbdrive is inserted. It utilizes an "inotifyd" command line which should be evoked at startup. Inotifyd monitors the file "/proc/partions" for any changes. and then using Technosaurus's sit, places an icon in the tray with a tooltip showing the drive name and size. The "mountcode -$dr" for the left click is just pseudocode. The following script should be put in $HOME/usb-watch.

Cheers,
s

Code: Select all

#!/bin/sh
#$HOME/usb-watch
# inotifyd $HOME/usb-watch /proc/partitions:c   # put line in startup script

usbdrv="sd[a-z][1-9]"
tooltip=`tail -1 /proc/partitions | awk "/$usbdrv/"' {print $4};{printf("%.2f",$3/1024/1024); print "GB"} '`
[ -z "$tooltip" ] && exit
drv=($tooltip)
sit /usr/local/lib/X11/pixmaps/usbdrv48.png "$tooltip"  "mountcode -$drv"

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

#80 Post by technosaurus »

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?

I was trying to understand how to use gtkbuilder, so I decided to throw together something similar to sit just to figure it out (just because I am familiar with that chunk of the api already). I could probably cut some code here and there, but there was absolute crap for examples, so I cobbled it together enough to make it work. All you need to do is create a gui in glade-3 (status icons are near the bottom) and add handlers to activate (left click) and popup (right click) ... puppy's glade doesn't support tooltips though

Code: Select all

#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

gchar *incfiles="/usr/share/sit/functions*";

static void run(gpointer s){													g_print("trying to run %s\n",s);
	if (!g_spawn_command_line_async(s,NULL)) {
		gchar *buf=g_strdup_printf("for x in %s; do . $x; done ; %s",incfiles,s);
		popen(buf,"r");
		g_free(buf);
	}
}

static void leftclick(GtkStatusIcon *si, gpointer s){
	(s==NULL) ? (g_print("left click on status icon\n")) : run(s);
	g_print("l:%s\n",s);
}

static void rightclick(GtkStatusIcon *si, guint b,guint a_t, gpointer s){		g_print("r:%s\n",(gchar*) s);
	(s==NULL) ? (g_print("left click on status icon\n")) : run(s);
}

static gboolean
gtk_status_icon_signal_handler_connector(
	GtkBuilder *builder,
	GObject *object,
	const gchar *signal_name,
	const gchar *signal_handler,
	GObject *connect_object,
	GConnectFlags flags,
	gpointer user_data){

gint n;
/* gchar *signal_names[] = {
	"activate", "button-press-event", "button-release-event", "popup-menu",
	"query-tooltip", "scroll-event", "size-changed",  NULL }; */

/* for (n = 0; signal_names[n] != NULL; ++n) {
	if (g_ascii_strcasecmp(signal_name, signal_names[n]) == 0) { ...*/
g_print("debug: signal_name %s, signal_handler %s\n",signal_name,signal_handler);
	if (g_ascii_strcasecmp(signal_name, "activate")){
		g_signal_connect(G_OBJECT(object), "activate", G_CALLBACK(leftclick), g_strdup(signal_handler));
		return TRUE;}
	if (g_ascii_strcasecmp(signal_name, "popup-menu")){
		g_signal_connect(G_OBJECT(object), "popup-menu", G_CALLBACK(rightclick), g_strdup(signal_handler));
		return TRUE;}
g_print("shit: signal_name %s, signal_handler %s\n",signal_name,signal_handler);		
 return FALSE;
} 


static gboolean
signal_handler_connector(
      GtkBuilder *builder,
      GObject *object,
      const gchar *signal_name,
      const gchar *signal_handler,
      GObject *connect_object,
      GConnectFlags flags,
      gpointer user_data){


   if (GTK_IS_STATUS_ICON(object))
      if (gtk_status_icon_signal_handler_connector(builder,
         object,
         signal_name,
         signal_handler,
         connect_object,
         flags,
         user_data))
         return; //may need TRUE?
} 


int main (int argc, char **argv) {
g_type_init ();
gtk_init(&argc, &argv);
GtkBuilder* builder;
builder = gtk_builder_new ();
GObject *main_widget;
gtk_builder_add_from_file(builder, argv[1], NULL);

if (builder == NULL) return 1;
if (argv[2] != NULL)
	main_widget = G_OBJECT (gtk_builder_get_object (builder, argv[2]));
else
	main_widget = G_OBJECT (gtk_builder_get_object (builder, "window1"));
if (main_widget==NULL) return 2;
gtk_builder_connect_signals_full(builder, (GtkBuilderConnectFunc) signal_handler_connector, NULL);
//gtk_widget_show_all ((GtkWidget*) main_widget);
gtk_main ();
(builder == NULL) ? NULL : (builder = (g_object_unref (builder), NULL));
(main_widget == NULL) ? NULL : (main_widget = (g_object_unref (main_widget), NULL));
return 0;
}
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

#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

Post Reply