simple icon tray

Window managers, icon programs, widgets, etc.
Message
Author
User avatar
boscobearbank
Posts: 63
Joined: Thu 06 Apr 2006, 15:13
Location: MN

#61 Post by boscobearbank »

Technosaurus: The code below may not be pretty, but it does what I need it to do, thanks to sit-1.0. Thanks.

Code: Select all

#!/usr/bin/python

""" A very, very simple front-end for ffmpeg to capture screencasts
    Capture area begins in upper-left corner of screen
    Size of capture area is user-definable
    Frame rate is fixed at 25 fps
    Output resolution = input resolution
    No audio
    Output file is user-specified (except for container type
    Container type = Matroska
    Cludged together by RockDoctor
    Version 1  23-Sep-2012
"""

from gi.repository import Gtk
import os, signal, sys, subprocess

process = 'ffmpeg'
kill_sig = signal.SIGINT
mycmd = ''

# ======================================================================
def process_killer():

  l_process = len(process)
  for line in os.popen('ps ax'):
    fields = line.split()
    if fields[4][0:l_process]==process:
      pid_of_process = int(fields[0])
      print (pid_of_process)
      os.kill(pid_of_process, kill_sig)

# ======================================================================
class SitApp:
  """
  an adaptation and butchering of technosaurus's sit.c
  adapted by RockDoctor
  """

  def __init__(self):
    si = Gtk.StatusIcon.new_from_stock("gtk-stop")
    si.set_tooltip_text("Click to stop recording")
    si.connect("activate",self.leftClick,process_killer)
    si.connect("popup-menu",self.rightClick,process_killer)
    Gtk.main()

  def leftClick(self, status_icon, action):
    #print ("Interrupting ",process)
    action()
    #print ("Left-click")
    sys.exit()


  def rightClick(self, status_icon, button, mytime, action):
    #print ("Interrupting "+str(process)+"  button="+str(button)+"  time="+str(mytime)+"\n")
    action()
    #print ("Right-click")
    sys.exit()

# ======================================================================
class ScreenRecorder:
  """ A very simple screencast recorder
      Original command:
      ffmpeg -f x11grab -s 840x525 -r 25 -i :0.0 -threads 0 -sameq -an  /home/a/Desktop/video.mkv 2>/dev/null
  """
  def __init__(self):

    self.i_params = {}
    self.o_params = {}
    self.i_params['f'] = 'x11grab' # input from X11 screen
    self.i_params['s'] = '802x514' # input frame size
    self.i_params['r'] = '25'    # input file frame rate
    self.i_params['i'] = ':0.0'  # input file (or stream)

    self.o_params['threads'] = '0'
    self.o_params['sameq'] = ''  # same quality in encoder as in decoder
    self.o_params['an'] = ''     # disable audio recording

    self.outfile_name =  '/home/a/Desktop/video'
    self.outfile_extension = '.mkv'

    # I'm only going to permit modification of a limited number of the
    # above parameters (which are a very limited number of the
    # parameters available to ffmpeg for screen recording)

    w = Gtk.Window(title = "Screen Capture via FFMPEG")
    w.connect('destroy', Gtk.main_quit)
    w.set_default_size(400,300)
    vbox = Gtk.VBox(spacing=15)

    grid = Gtk.Grid()
    grid.set_row_spacing(3)
    grid.set_column_spacing(3)

    btn = Gtk.Button()
    btn.set_label("Frame Size: ")
    btn.set_alignment(0,0.5)
    btn.set_relief(Gtk.ReliefStyle.NONE)
    grid.attach(btn,0,0,1,1)
    s_entry = Gtk.Entry()
    s_entry.set_text(self.i_params['s'])
    grid.attach(s_entry,1,0,1,1)

    btn = Gtk.Button()
    btn.set_label("Output filename (w/o extension):")
    btn.set_alignment(0,0.5)
    btn.set_relief(Gtk.ReliefStyle.NONE)
    grid.attach(btn,0,1,1,1)
    f_entry = Gtk.Entry()
    f_entry.set_text(self.outfile_name)
    grid.attach(f_entry,1,1,1,1)

    btn = Gtk.Button(stock='gtk-execute')
    btn.connect('clicked', self.start_ffmpeg)
    grid.attach(btn,0,2,2,1)

    vbox.pack_start(grid, False, False, 0)
    w.add(vbox)
    self.w = w
    self.w.show_all()

    Gtk.main()

  def start_ffmpeg(self, widget):
    my_cmd = 'ffmpeg -f x11grab -s '+self.i_params['s']+' -r 25 -i :0.0 -threads 0 -sameq -an  '+self.outfile_name+'.mkv'
    self.w.hide()
    command = my_cmd.split()
    try:
      subprocess.Popen(['rm',self.outfile_name+'.mkv'])
    except:
      pass
    subprocess.Popen(command)
    Gtk.main_quit()

# ======================================================================
def main(data=None):
    app2 = ScreenRecorder()
    app1 = SitApp()

if __name__ == '__main__':
    main()


Bosco Bearbank

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

#62 Post by technosaurus »

I just updated some stuff and broke the old api:

startup will fail verbosely if an image does not stat
replaced popen with g_spawn_command_line_async (now you can get streamed output from your left/right click action helpers)
this also means it should now be 100% portable to non-posix systems
added tooltips from file, falls back to the argument if file does not stat
tooltips will automatically update if the file changes
no tooltip is set if "" is passed
no callbacks are issued for right/leftclick if the command is "" (NULL)
  • usage:
    sit image [tooltip_file] [left_action] [right_action] ... \
    image ["tooltip text"] [left_action] [right_action] ... \
    ... this may be repeated for an unlimited number of icons

Code: Select all

#include <gtk/gtk.h>

void leftclick(GtkStatusIcon *si, gpointer s){
	g_spawn_command_line_async(s,NULL);
}

void rightclick(GtkStatusIcon *si, guint b,guint a_t, gpointer s){
	g_spawn_command_line_async(s,NULL);
}

/** refreshes the status icon image from file if it changes */
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 */
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 < 2 ) {
	g_printerr("usage:\n%s /path/to/image /path/to/tooltip left-action right-action ...\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();
}
Attachments
sit.tar.gz
(1.99 KiB) Downloaded 632 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

#63 Post by seaside »

technosaurus,

Some nice updates here.

I especially liked the tooltips from a file idea, but I couldn't get that to work (perhaps I'm invoking the line wrong

Code: Select all

 sit /usr/share/pixmaps/group-chat.png /root/tooltip_file

Also tried the filename with double quotes.

Thanks and regards,
s
(Also got a "seg fault" and no useage info if just "sit" on command line)

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

#64 Post by technosaurus »

the file needs to exist when sit starts (it checks if it exists,so that the file monitor works), otherwise your tooltip will be that arg value "/root/tooltip_file" which will be unchangeable (which is perfectly normal for most situations) - it basically just lets you do things like update the network statistics as in the network monitor applet

Edit: I still need to update the original post, use my last binary from this post:
http://www.murga-linux.com/puppy/viewto ... 170#654170
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

#65 Post by seaside »

technosaurus,

I forgot I had the older copy of sit in the path when I tried it.

All works well as described. Great work as usual.

Thanks,
S

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

#66 Post by technosaurus »

one change to note:
now that I don't use popen, in order to run a bash function on a left/right click action, you would need to use "sh -c my_function" ... after exporting the function (bashism)

simple example:

Code: Select all

#!/bin/sh
snaptool(){
mtpaintsnapshot.sh
}
export -f snaptool
sit /usr/share/mini-icons/mini-camera.xpm "Left click to take an immediate snapshot
Right click to open a snapshot dialog" "mtpaint -s" "sh -c snaptool"
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:

#67 Post by technosaurus »

Too tired to do anything but post the new code adding sourced function support from /usr/share/sit/functions*

Code: Select all

#include <gtk/gtk.h>

void leftclick(GtkStatusIcon *si, gpointer s){
	if (!g_spawn_command_line_async(s,NULL)) {
		gchar *buf=g_strdup_printf("for x in /usr/share/sit/functions*; do . $x; done ; %s",s);
		popen(buf,"r");
		g_free(buf);
	}

}

void rightclick(GtkStatusIcon *si, guint b,guint a_t, gpointer s){
	if (!g_spawn_command_line_async(s,NULL)) {
		gchar *buf=g_strdup_printf("for x in /usr/share/sit/functions*; do . $x; done ; %s",s);
		popen(buf,"r");
		g_free(buf);
	}
}

/** refreshes the status icon image from file if it changes */
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 */
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 < 2 ) {
	g_printerr("usage:\n%s /path/to/image /path/to/tooltip left-action right-action ...\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();
}
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

#68 Post by seaside »

technosaurus,

Thanks for your improvements.

Working beautifully not having to do the "export -sh" part.

Best regards,
s

lobo115
Posts: 11
Joined: Thu 06 May 2010, 17:38

USB

#69 Post by lobo115 »

Hello, i want know if seaside, could make USB work?

in my pc only works sit 1, sit 2, and 3 doesn't work. Thankz for your great job.

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

Re: USB

#70 Post by seaside »

lobo115 wrote:Hello, i want know if seaside, could make USB work?

in my pc only works sit 1, sit 2, and 3 doesn't work. Thankz for your great job.
lobo115,

I have tested sit using Racy-5.3 booted from a usb and it works.

Cheers,
s

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

#71 Post by technosaurus »

OK, enough with the alpha versions and on with the release candidates.

Code: Select all

./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: Select all

#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();
}
Attachments
sit-1.0.pet
(2.75 KiB) Downloaded 682 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].

lobo115
Posts: 11
Joined: Thu 06 May 2010, 17:38

Re: USB

#72 Post by lobo115 »

seaside wrote: I have tested sit using Racy-5.3 booted from a usb and it works.

Cheers,
s
hello, Thankz for your answer :D , 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

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

#73 Post by technosaurus »

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: Select all

<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: Select all

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

#74 Post by seaside »

lobo115 wrote:
seaside wrote:
hello, Thankz for your answer :D , 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

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

#75 Post by seaside »

technosaurus,

Latest sit working nicely with added functions. Thanks.
svg code for an network transmit/receive app:
Now that is a very interesting use.

Regards,
s

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].

Post Reply