The time now is Fri 27 Apr 2018, 04:52
All times are UTC - 4 |
Page 6 of 11 [162 Posts] |
Goto page: Previous 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 Next |
Author |
Message |
technosaurus

Joined: 18 May 2008 Posts: 4787 Location: Kingwood, TX
|
Posted: Wed 26 Sep 2012, 20:39 Post subject:
|
|
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 github repositories. I may eventually get around to updating my blogspot.
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 4787 Location: Kingwood, TX
|
Posted: Thu 27 Sep 2012, 00:48 Post subject:
|
|
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 github repositories. I may eventually get around to updating my blogspot.
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 4787 Location: Kingwood, TX
|
Posted: Thu 27 Sep 2012, 23:37 Post subject:
|
|
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 github repositories. I may eventually get around to updating my blogspot.
|
Back to top
|
|
 |
seaside
Joined: 11 Apr 2007 Posts: 917
|
Posted: Sat 29 Sep 2012, 12:15 Post subject:
usbdrive Subject description: Detect usbdrive insertion |
|
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: |
#!/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"
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 4787 Location: Kingwood, TX
|
Posted: Sat 29 Sep 2012, 14:17 Post subject:
|
|
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: | #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 github repositories. I may eventually get around to updating my blogspot.
|
Back to top
|
|
 |
seaside
Joined: 11 Apr 2007 Posts: 917
|
Posted: Sat 29 Sep 2012, 17:56 Post subject:
|
|
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
|
Back to top
|
|
 |
seaside
Joined: 11 Apr 2007 Posts: 917
|
Posted: Tue 02 Oct 2012, 12:25 Post subject:
Usbdrive icon in tray |
|
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: | 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: |
#!/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
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 4787 Location: Kingwood, TX
|
Posted: Tue 02 Oct 2012, 13:45 Post subject:
Re: Usbdrive icon in tray |
|
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 github repositories. I may eventually get around to updating my blogspot.
|
Back to top
|
|
 |
seaside
Joined: 11 Apr 2007 Posts: 917
|
Posted: Tue 02 Oct 2012, 20:31 Post subject:
Re: Usbdrive icon in tray |
|
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)
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 4787 Location: Kingwood, TX
|
Posted: Mon 19 Nov 2012, 18:58 Post subject:
|
|
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/binaries/win32/gtk+/2.24/gtk+-bundle_2.24.10-20120208_win32.zip
gcc -Os sit.c -o sit.exe -std=c89 -Wall `pkg-config gtk+-2.0 --cflags --libs` -s
Description |
|

Download |
Filename |
sit-win32.zip |
Filesize |
4.51 KB |
Downloaded |
751 Time(s) |
_________________ Check out my github repositories. I may eventually get around to updating my blogspot.
|
Back to top
|
|
 |
seaside
Joined: 11 Apr 2007 Posts: 917
|
Posted: Sun 30 Dec 2012, 00:34 Post subject:
tweather Subject description: monitor weather with a tray icon |
|
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/viewtopic.php?t=76431&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: |
#!/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
|
 |
Description |
Screenshot of tweather |
Filesize |
16.26 KB |
Viewed |
943 Time(s) |

|
Last edited by seaside on Fri 04 Jan 2013, 13:37; edited 1 time in total
|
Back to top
|
|
 |
vovchik

Joined: 23 Oct 2006 Posts: 1447 Location: Ukraine
|
Posted: Sun 30 Dec 2012, 20:27 Post subject:
|
|
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
Description |
|

Download |
Filename |
xml-print.tar.gz |
Filesize |
31.75 KB |
Downloaded |
630 Time(s) |
|
Back to top
|
|
 |
seaside
Joined: 11 Apr 2007 Posts: 917
|
Posted: Sun 30 Dec 2012, 23:56 Post subject:
|
|
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-rss-weather-updates/
but their formats would most likely be quite different.
Best Regards,
s
Description |
|

Download |
Filename |
tweather.pet |
Filesize |
35.06 KB |
Downloaded |
715 Time(s) |
|
Back to top
|
|
 |
vovchik

Joined: 23 Oct 2006 Posts: 1447 Location: Ukraine
|
Posted: Mon 31 Dec 2012, 15:41 Post subject:
|
|
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: | 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
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 4787 Location: Kingwood, TX
|
Posted: Mon 31 Dec 2012, 16:30 Post subject:
|
|
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 github repositories. I may eventually get around to updating my blogspot.
|
Back to top
|
|
 |
|
Page 6 of 11 [162 Posts] |
Goto page: Previous 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 Next |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|