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 

help me by solving this

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
vinodh
Familiar Face


Joined: 12 Feb 2008
Posts: 8

PostPosted: Wed Mar 19, 2008 3:43 am    Post subject: help me by solving this Reply with quote

i want to display the list of partitions in a combo box reading from a file /proc/partitons.

take a look at the below code..

char *p;
n=4;
FILE *f=fopen("/proc/partitions","r");
Glist combo_items=NULL;


while(n!=0)
{
fgets(p,20,*f);
combo_items=g_list_append(combo_items,(gpointer) p);
n--;
}
Code: (C)
1
[color=green][/color]
Back to top
Wolfgang
Familiar Face


Joined: 05 Feb 2008
Posts: 37

PostPosted: Mon Mar 24, 2008 9:25 am    Post subject: Reply with quote

show entire source
Back to top
vinodh
Familiar Face


Joined: 12 Feb 2008
Posts: 8

PostPosted: Wed Mar 26, 2008 5:06 am    Post subject: gtk combo Reply with quote

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

#include <gtk/gtk.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <gdk/gdkkeysyms.h>

GtkWidget* createcombo (void)
{
  GtkWidget *window1;
  GtkWidget *fixed1;
  GtkWidget *combo1;
  GList *combo1_items = NULL;
  FILE *f;
int n;
char *q;
char *t[10];

n=4;
f=fopen("/root/Desktop/untitled/filesystem.txt","r");

  window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window1), "window1");
  g_signal_connect (G_OBJECT (window1), "delete_event", G_CALLBACK (gtk_main_quit), NULL);
  gtk_widget_show (window1);

  fixed1 = gtk_fixed_new ();
  gtk_widget_show (fixed1);
  gtk_container_add (GTK_CONTAINER (window1), fixed1);

  combo1 = gtk_combo_new ();
  g_object_set_data (G_OBJECT (GTK_COMBO (combo1)->popwin), "GladeParentKey", combo1);
 
  gtk_fixed_put (GTK_FIXED (fixed1), combo1, 80, 56);
  gtk_widget_set_size_request (combo1, 187, 27);
  gtk_widget_show (combo1);

while(n!=0)
{

fgets(q,15,f);
t[n]= (char *) malloc (strlen(q)+1);
printf("%s",q);
strcpy(t[n],q);
combo1_items = g_list_append (combo1_items, (gpointer) t[n]);

n--;
t[n]=NULL;
printf("%s",t[n]);
}
gtk_combo_set_popdown_strings (GTK_COMBO (combo1), combo1_items);
g_list_free (combo1_items);

return window1;
}


int main (int argc, char *argv[])
{
  gtk_init (&argc, &argv);

  GtkWidget *window1;

window1=createcombo();
  gtk_main ();
  return 0;
}
[/code]
Back to top
Wolfgang
Familiar Face


Joined: 05 Feb 2008
Posts: 37

PostPosted: Thu Mar 27, 2008 4:17 pm    Post subject: Reply with quote

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
#include <gtk/gtk.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <gdk/gdkkeysyms.h>

GtkWidget* createcombo (void)
{
  GtkWidget *window1;
  GtkWidget *fixed1;
  GtkWidget *combo1;
  GList *combo1_items = NULL;
  GList *cbb = NULL; // new
 
FILE *f;
int n;
char *q;
char *t[10];

n=4;
f=fopen("filesystem.txt","r");

  window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window1), "window1");
  g_signal_connect (G_OBJECT (window1), "delete_event", G_CALLBACK (gtk_main_quit), NULL);
  gtk_widget_show (window1);

  fixed1 = gtk_fixed_new ();
  gtk_widget_show (fixed1);
  gtk_container_add (GTK_CONTAINER (window1), fixed1);

  combo1 = gtk_combo_new ();
  g_object_set_data (G_OBJECT (GTK_COMBO (combo1)->popwin), "GladeParentKey", combo1);
 
  gtk_fixed_put (GTK_FIXED (fixed1), combo1, 80, 56);
  gtk_widget_set_size_request (combo1, 187, 27);
  gtk_widget_show (combo1);

while(n!=0)
{

fgets(q,15,f);
t[n]= (char *) malloc (strlen(q)+1);
printf("f: %s\n",q);
strcpy(t[n],q);
combo1_items = g_list_append (combo1_items, (gpointer) t[n]);
if (!cbb) cbb = combo1_items; // new

n--;
t[n]=NULL;
printf("r: %s\n",t[n]);
}
gtk_combo_set_popdown_strings (GTK_COMBO (combo1), cbb); // new
g_list_free (cbb); // new

return window1;
}


int main (int argc, char *argv[])
{
  gtk_init (&argc, &argv);

  GtkWidget *window1;

window1=createcombo();
  gtk_main ();
  return 0;
}


see lines with comment "new"
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