The time now is Mon 20 May 2013, 22:28
All times are UTC - 4 |
| Author |
Message |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Wed 26 Sep 2012, 02:46 Post subject:
|
|
OK, enough with the alpha versions and on with the release candidates.
| Code: | ./sit [-i files] image tooltip left-action right-action ...
-i full path to file(s) with shell functions to include
by default it looks in /usr/share/sit/functions*
image full path to image file
tooltip full path to tooltip file or a "quoted tooltip"
left-action action to run when left mouse button is clicked
right-action action to run when right mouse button is clicked |
| Code: | #include <gtk/gtk.h>
gchar *incfiles="/usr/share/sit/functions*";
static void run(gpointer 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){
run(s);
}
static void rightclick(GtkStatusIcon *si, guint b,guint a_t, gpointer s){
run(s);
}
/** refreshes the status icon image from file if it changes */
static void refresh(GFileMonitor *monitor, GFile *file, GFile *to_file, GFileMonitorEvent event, gpointer si){
gtk_status_icon_set_from_file(si,g_file_get_path(file));
}
/** gets a new mouse over tooltip from file if it changes */
static void updatetooltip(GFileMonitor *monitor, GFile *file, GFile *to_file, GFileMonitorEvent event, gpointer si){
gtk_status_icon_set_tooltip_text(si, g_mapped_file_get_contents(g_mapped_file_new(g_file_get_path(file), FALSE, NULL)));
}
int main(int argc, char *argv[]){
GtkStatusIcon *si;
char i=1;
gtk_init (&argc, &argv);
if ((argc>1)&&(argv[i][0]=='-')&&(argv[i++][1]=='i')) incfiles=argv[i++];
if ( argc < i+1 ) {
g_printerr(
"usage:\n%s [-i files] image tooltip left-action right-action ...\n\n" \
" -i full path to file(s) with shell functions to include\n" \
" by default it looks in /usr/share/sit/functions*\n"
" image full path to image file\n" \
" tooltip full path to tooltip file or a \"quoted tooltip\"\n" \
" left-action action to run when left mouse button is clicked\n" \
" right-action action to run when right mouse button is clicked\n\n" \
,argv[0]);
return 1;
}
/** loop through icon, tooltip, click messages **/
while (i<argc){
/** status icon **/
if (g_file_test(argv[i], G_FILE_TEST_EXISTS)){
si = gtk_status_icon_new_from_file(argv[i]);
g_signal_connect(g_file_monitor_file(g_file_new_for_path(argv[i++]), G_FILE_MONITOR_NONE, FALSE, NULL),
"changed", G_CALLBACK(refresh),(gpointer) si);
}else{
g_printerr("error: could not stat file %s\n",argv[i]);
return 2;
}
/** tooltip **/
if (g_file_test(argv[i], G_FILE_TEST_EXISTS)){
gtk_status_icon_set_tooltip_text(si, g_mapped_file_get_contents(g_mapped_file_new(argv[i], FALSE, NULL)));
g_signal_connect(g_file_monitor_file(g_file_new_for_path(argv[i]), G_FILE_MONITOR_NONE, FALSE, NULL),
"changed", G_CALLBACK(updatetooltip),(gpointer) si);
}else if (argv[i]!=NULL) gtk_status_icon_set_tooltip_text(si, argv[i]);
++i;
/** left click action **/
if (argv[i]!=NULL) g_signal_connect(G_OBJECT(si), "activate", G_CALLBACK(leftclick),(gpointer) argv[i]);
++i;
/** right click action **/
if (argv[i]!=NULL) g_signal_connect(G_OBJECT(si), "popup-menu", G_CALLBACK(rightclick), (gpointer) argv[i]);
++i;
}
gtk_main();
} |
 |
| Description |
|

Download |
| Filename |
sit-1.0.pet |
| Filesize |
2.75 KB |
| Downloaded |
130 Time(s) |
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
lobo115
Joined: 06 May 2010 Posts: 11
|
Posted: Wed 26 Sep 2012, 14:09 Post subject:
Re: USB |
|
| seaside wrote: |
I have tested sit using Racy-5.3 booted from a usb and it works.
Cheers,
s |
hello, Thankz for your answer , but i want know if you could do this:
| seaside wrote: | technosaurus,
I was wondering if it were possible to extend the inotify aspect to include monitoring for usb drive additions and removals.
Regards,
s |
Thank you
and technosaurus, first of all thankz for your great job, i want know, if new sit 1.0 doesn't work with your first example script ?. I mean the script that is in the second post, the one that beging with Here is the beginning of the applet suite - a drive tray for the tray
ThZ
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Wed 26 Sep 2012, 17:44 Post subject:
|
|
I haven't been working on the drive stuff, but the biggest difference is that now it needs an extra parameter for a tooltip (mouse-over message) after the icon, but before the click actions. This is a good place to put what each mouse button does or any useful information - this can be a path to a text file that you can update or an unchangeable string
Here is the svg code for an network transmit/receive app:
path1 is for receive, path2 is for transmit
| Code: | <svg width="48" height="48" id="svg1" xmlns:xlink="http://www.w3.org/1999/xlink">
<image xlink:href="/usr/share/midi-icons/www48.png" width="48" height="48" id="image1"/>
<path id="path1" style="fill:#00FF00;fill-opacity:0.6;stroke-width:0;"
d="M 46.5,17.8 L 36.8,29.0 L 27.2,17.8 L 32.1,17.8 C 33.7,13.4
30.4,10.6 26.5,10.6 C 23.7,10.6 19.9,12.1 18.6,15.9 C 18.0,17.9
16.8,17.0 16.8,15.3 C 17.0,8.7 21.9,3.4 29.3,3.4 C 36.6,3.4
42.1,9.1 41.7,17.8 L 46.5,17.8 z" />
<path id="path2" style="fill:#00FF00;fill-opacity:0.6;stroke-width:0;"
d="M 1.5,30.2 L 11.2,19.0 L 20.8,30.2 L 15.9,30.2 C 14.3,34.6
17.6,37.4 21.5,37.4 C 24.3,37.4 28.1,35.9 29.4,32.1 C 30.0,30.1
31.2,31.0 31.2,32.7 C 31.0,39.3 26.1,44.6 18.7,44.6 C 11.4,44.6
5.9,38.9 6.3,30.2 L 1.5,30.2 z" />
</svg> |
and a very basic implementation with no calculations or anything like some existing ones do (should be easy enough to add though):
| Code: | #!/bin/ash
while :; do
NETSVG='<svg width="48" height="48" id="svg1" xmlns:xlink="http://www.w3.org/1999/xlink">
<image xlink:href="/usr/share/midi-icons/www48.png" width="48" height="48" id="image1"/>'
while read IFACE RBYTES RPACKS RERRS RDROP RFIFO RFRAM RCOMP RMULTI TBYTES TPACKS TERRS TDROP TFIFO TCOLLS TCAR TCOMP
do
case $IFACE in
eth*|wlan*)[ $RBYTES -gt ${LASTRBYTES:-0} ] && LASTRBYTES=$RBYTES && \
NETSVG=$NETSVG'<path id="path1" style="fill:#00FF00;fill-opacity:0.6;stroke-width:0;"
d="M 46.5,17.8 L 36.8,29.0 L 27.2,17.8 L 32.1,17.8 C 33.7,13.4
30.4,10.6 26.5,10.6 C 23.7,10.6 19.9,12.1 18.6,15.9 C 18.0,17.9
16.8,17.0 16.8,15.3 C 17.0,8.7 21.9,3.4 29.3,3.4 C 36.6,3.4
42.1,9.1 41.7,17.8 L 46.5,17.8 z" />'
[ $TBYTES -gt ${LASTTBYTES:-0} ] && LASTTBYTES=$TBYTES && \
NETSVG=$NETSVG'<path id="path2" style="fill:#00FF00;fill-opacity:0.6;stroke-width:0;"
d="M 1.5,30.2 L 11.2,19.0 L 20.8,30.2 L 15.9,30.2 C 14.3,34.6
17.6,37.4 21.5,37.4 C 24.3,37.4 28.1,35.9 29.4,32.1 C 30.0,30.1
31.2,31.0 31.2,32.7 C 31.0,39.3 26.1,44.6 18.7,44.6 C 11.4,44.6
5.9,38.9 6.3,30.2 L 1.5,30.2 z" />'
;;#/proc/net/wireless for signal
esac
done</proc/net/dev
NETSVG=$NETSVG'
</svg>'
[ "$NETSVG" != "$LASTNETSVG" ] && echo "$NETSVG" >net.svg && LASTNETSVG=$NETSVG
sleep 1
done |
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
seaside
Joined: 11 Apr 2007 Posts: 833
|
Posted: Wed 26 Sep 2012, 20:06 Post subject:
Re: USB |
|
[quote="lobo115"][quote="seaside"]
hello, Thankz for your answer , but i want know if you could do this:
| seaside wrote: | technosaurus,
I was wondering if it were possible to extend the inotify aspect to include monitoring for usb drive additions and removals.
Regards,
s |
lobo115,
Ah, yes --that question was when sit was using inotify which it no longer does. It's possible to do this with another program, "inotifyd" to watch for activity.
Cheers,
s
|
|
Back to top
|
|
 |
seaside
Joined: 11 Apr 2007 Posts: 833
|
Posted: Wed 26 Sep 2012, 20:13 Post subject:
|
|
technosaurus,
Latest sit working nicely with added functions. Thanks.
| Quote: | | svg code for an network transmit/receive app: |
Now that is a very interesting use.
Regards,
s
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
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.
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
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)
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
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.
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
seaside
Joined: 11 Apr 2007 Posts: 833
|
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: 3843
|
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;
}
|
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
seaside
Joined: 11 Apr 2007 Posts: 833
|
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: 833
|
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: 3843
|
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.
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
seaside
Joined: 11 Apr 2007 Posts: 833
|
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: 3843
|
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 |
150 Time(s) |
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
|
|
|
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
|