GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Want to create a clickable button from directory list

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
duckz



Joined: 08 Apr 2008
Posts: 3

PostPosted: Tue Apr 08, 2008 9:20 am    Post subject: Want to create a clickable button from directory list Reply with quote

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: (C)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#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]
Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 495
Location: Portland, OR USA

PostPosted: Wed Apr 09, 2008 5:14 pm    Post subject: Reply with quote

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.
Back to top
duckz



Joined: 08 Apr 2008
Posts: 3

PostPosted: Sat Apr 19, 2008 3:01 pm    Post subject: Reply with quote

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??
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP