Fwd: gnome applet w/ bash
- From: "Michael Lamothe" <michael lamothe gmail com>
- To: "Matteo Landi" <matteo landi email it>, gtk-app-devel-list gnome org
- Subject: Fwd: gnome applet w/ bash
- Date: Mon, 5 Nov 2007 15:21:05 +1100
Hi Matteo,
There's a few ways to do this, two of which I'll tell you now.
Hopefully, you can change your application to use these functions
instead.
Firstly, there's the g_spawn_ set of APIs designed for this. I think
that something like g_spawn_command_line_sync() will do exactly what
you want. Basically, GLib calculates and allocates the space
required. The documentation mentions nothing about freeing the
allocated strings afterwards but I imagine you will have to free the
standard_output and standard_error parameters with g_free().
Secondly, if the spawned program is meant to run asynchronously in the
background then you'll need to use something like
g_spawn_async_with_pipes(). I don't think that this is what you want
because you were talking about having to allocate the length of the
output.
Thanks,
Michael
On 05/11/2007, Matteo Landi <matteo landi email it> wrote:
thank you very much, that solved one of my problems.
here is the second:
i'm using a pipe to catch the output of a specific command and store it
as a label in the panel; the problem is that if the array containing the
output is smaller than the output itself, the line is cut, and the
applet is show all middle aligned; if the output is bigger, i get the
label splitted in two lines: the first one containing the entire output,
and the second one is empty.
How could i solve this? maybe with dynamic allocation of memory, but in
order to know the output width size, i gotta insert a while that
overload the applet isn't it?
tnx in advance for the help
M@
On Sun, 2007-11-04 at 13:33 +1100, Michael Lamothe wrote:
Hi Matteo,
Look at g_timeout_add() or the new gdk_threads_add_timeout().
Thanks,
Michael
On 04/11/2007, Matteo Landi <matteo landi email it> wrote:
hi all
i'm a complete newbie in developing with gtk, but yesterday i had an
idea about develope a gnome panel which could substitute conky..
In fact i'm in need of a panel that simply display the output of a bash
script..
well, after have googled a bit, i found a guide for implementing gnome
applet and here is the result
#include <string.h>
#include <panel-applet.h>
#include <gtk/gtklabel.h>
#include <stdio.h>
static gboolean on_button_press (GtkWidget *event_box, GdkEventButton
*event, GtkWidget* label){
if (event->button != 1)
return FALSE;
else {
FILE* fp;
char line[160];
fp = popen("~/scripts/allin1", "r");
fgets( line, sizeof line, fp);
pclose(fp);
gtk_label_set_text (label,(const char*) line);
}
return TRUE;
}
static gboolean my_applet_fill (PanelApplet *applet, const gchar *iid,
gpointer data){
FILE* fp;
int pid;
char line[160];
GtkWidget *label;
fp = popen("~/scripts/allin1", "r");
fgets( line, sizeof line, fp);
pclose(fp);
label = gtk_label_new (line);
gtk_container_add (GTK_CONTAINER (applet), label);
g_signal_connect (G_OBJECT(applet), "button_press_event", G_CALLBACK
(on_button_press), label);
gtk_widget_show_all (GTK_WIDGET (applet));
return TRUE;
}
PANEL_APPLET_BONOBO_FACTORY ("OAFIID:my_applet_Factory",
PANEL_TYPE_APPLET, "Conky Porting", "0", my_applet_fill, NULL);
what i'm asking for is how could i refresh the label of the applet after
a fixed period of time... (now the applets refresh when mouse-clicked)
tnx in advance
M@
_______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]