You are not logged in.

#1 2015-02-02 12:31:46

Debasish Patra
Member
Registered: 2014-03-06
Posts: 64

GSubprocess Example

Hi,
I am trying to understand Gsubprocess, and how it functions. I just wanted to call a external program and interact with it in GTK in c.
I tried to google and check youtube videos, but they are filled with gsubprocess exampled in python.

Reading from the official gnome guide and following up is just liitle difficult for me. Anyone with some ideas where I can find a tutorial on it would be really helpful smile.

I am wrinting a program that sits in notification area and starts pacman when we click on it , it updates the system i.e pacman -Syyu. I wanted to use GSubprocess here, but I am utterly confused.
Please note that I have not implemented the GSubprocess till now. I dont expect anyone to write the code for me, but I would really appreciate the help if someone could give an example or point me to some blog where it is explained.

#include <gtk/gtk.h>

void tray_icon_on_click(GtkStatusIcon *status_icon,
                        gpointer user_data)
{
        printf("Clicked on tray icon\n");
}

void tray_icon_on_menu(GtkStatusIcon *status_icon, guint button,
                       guint activate_time, gpointer user_data)
{
//        printf("Popup menu\n");
	GtkWidget*	menu;
	GtkWidget*	menuitem1;
	GtkWidget*	menuitem2;

	menu = gtk_menu_new();
	menuitem1 = gtk_menu_item_new_with_label("Check For Updates...");
	menuitem2 = gtk_menu_item_new_with_label("Quit");
	gtk_menu_attach(GTK_MENU(menu),menuitem1,0,1,0,1);
	gtk_menu_attach(GTK_MENU(menu),menuitem2,0,1,1,2);

	gtk_widget_show_all(menu);
	gtk_menu_popup(GTK_MENU(menu),NULL,NULL,NULL,user_data,button, gtk_get_current_event_time());
}

static GtkStatusIcon *create_tray_icon() {
        GtkStatusIcon *tray_icon;
	gchar *iconfile;
	iconfile="/usr/share/icons/gnome/32x32/status/software-update-available.png";
        tray_icon = gtk_status_icon_new_from_file(iconfile);
        g_signal_connect(G_OBJECT(tray_icon), "activate",
                         G_CALLBACK(tray_icon_on_click), NULL);
        g_signal_connect(G_OBJECT(tray_icon),
                         "popup-menu",
                         G_CALLBACK(tray_icon_on_menu), NULL);
        gtk_status_icon_set_tooltip(tray_icon,
                                    "Tray Icon");
        gtk_status_icon_set_visible(tray_icon, TRUE);

        return tray_icon;
}

int main(int argc, char **argv) {
        GtkStatusIcon *tray_icon;

        gtk_init(&argc, &argv);
        tray_icon = create_tray_icon();
        gtk_main();

        return 0;
}

Keep Calm, And Enjoy Life smile

Offline

#2 2015-02-02 12:44:16

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,331
Website

Re: GSubprocess Example

I don't use gtk, so maybe I'm missing part of what this does, but why do you feel you need to use gsubprocess?  It looks like a standard fork+exec would do what you want.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2015-02-02 12:52:17

Debasish Patra
Member
Registered: 2014-03-06
Posts: 64

Re: GSubprocess Example

Trilby wrote:

I don't use gtk, so maybe I'm missing part of what this does, but why do you feel you need to use gsubprocess?  It looks like a standard fork+exec would do what you want.

Thanks  Trilby. Ok, my bad, I was too obssessed to use gsubprocess to look for alternatives. I will try using exec and fork and will come back.


Keep Calm, And Enjoy Life smile

Offline

Board footer

Powered by FluxBB