GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Wed Sep 03, 2014 7:11 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Want to create a clickable button from directory list
PostPosted: Tue Apr 08, 2008 9:20 am 
Offline

Joined: Tue Apr 08, 2008 9:11 am
Posts: 3
hi, I need help in gtk programming in C, I want to create a clickable button that get its data / label from a directory list, and upon clicked the button will do some performing jobs as instructed. Basically its for a service manager in gentoo.

Code:
#include <gtk/gtk.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <glib.h>
#include <glib/gstdio.h>

/*GTK quit function*/
gboolean delete_event(GtkWidget *widget, GdkEvent *event, gpointer data)
{
    gtk_main_quit();
    return FALSE;
}
void destroy( GtkWidget *widget,GdkEvent  *event,gpointer data)

{
    gtk_main_quit ();
}

/*end of gtk quit function*/

/* start of directory reading and listing */
void direntry (GtkWidget *widget, GtkLabel *label, gpointer data)
{
   GDir *dir;
   const gchar *direntry;

   dir = g_dir_open("/etc/init.d/", 0, NULL);
      
   direntry = g_dir_read_name(dir);
   
}
/*end of directory listing and reading */


int main( int   argc,char *argv[] )
{
    static GtkWidget *window = NULL;
    GtkWidget *button;
    GtkWidget *table;
    GtkWidget *label;
    GtkWidget *notebook;
    GtkWidget *mainframe;
    GtkWidget *subframe;   
    GtkWidget *hbox;
    GtkWidget *vbox;
    GtkWidget *tablabel;
    GtkWidget *direntry;
   
    gtk_init (&argc, &argv);


/*main windows properties */

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
     gtk_window_set_title (GTK_WINDOW(window), "Toshiba");
     gtk_window_set_default_size (GTK_WINDOW(window), 150, 150);
/*end main windows properties*/


gtk_signal_connect (GTK_OBJECT (window), "delete_event",
                        GTK_SIGNAL_FUNC (delete_event), NULL);
    gtk_container_set_border_width (GTK_CONTAINER (window), 10);
    table = gtk_table_new (3, 6, FALSE);

    gtk_container_add (GTK_CONTAINER (window), table);

/* Creating new notebook */   

   notebook =  gtk_notebook_new ();
   gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), GTK_POS_TOP);
   gtk_table_attach_defaults (GTK_TABLE (table), notebook, 0, 6, 0, 1);
   gtk_widget_show (notebook);

/* pages on notebook */
mainframe = gtk_frame_new ("Device Control");
tablabel = gtk_label_new ("Device");
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), mainframe, tablabel);

hbox = gtk_hbox_new (FALSE, 0);
vbox = gtk_vbox_new (FALSE, 0);

gtk_container_add (GTK_CONTAINER (mainframe), vbox);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (mainframe), 10);
gtk_table_attach_defaults(GTK_TABLE (table), mainframe, 0, 6, 1, 1);

hbox = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);

subframe = gtk_frame_new (NULL);
gtk_widget_set_size_request (subframe, 290, 250);
label = gtk_label_new (direntry);
gtk_container_add (GTK_CONTAINER (subframe), label);
gtk_box_pack_start (GTK_BOX (hbox), subframe, FALSE, FALSE, 0);

hbox = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
subframe = gtk_frame_new (NULL);

gtk_widget_set_size_request (subframe, 100, 40);
    button = gtk_button_new_with_label ("Start");
    g_signal_connect (G_OBJECT (button), "clicked",
                      G_CALLBACK (direntry), label);
gtk_container_add (GTK_CONTAINER (subframe), button);
gtk_box_pack_start (GTK_BOX (hbox), subframe, FALSE, FALSE, 0);


/* show the widget */
gtk_widget_show (table);
gtk_widget_show_all (window);


    gtk_main ();

    return 0;
}


can somebody help me fixing this?

cheers
duckz
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 09, 2008 5:14 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
I'm not sure I understand. You want to button to get it's data from a dir list? Do you mean you want to open a file chooser and select a file which becomes the label? you might want to check out the file chooser button if that's the case.

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 19, 2008 3:01 pm 
Offline

Joined: Tue Apr 08, 2008 9:11 am
Posts: 3
thanks for the reply,

actually what i am trying to do is something like this :

read the dir -> get file name one at a time -> put the filename to click able button label -> point the button to specific executable command -> get another filename for second button ...... and finish until no more filename to get.

all of it is done in background not by opening filechooser because I believe the /etc/init.d directory (which the program is supposed to read) contains lots of files. thus opening file chooser button everytime for each files is not a good option.

how am i able to get this done in gtk??


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


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 post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group