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 Oct 22, 2014 10:19 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: help me by solving this
PostPosted: Wed Mar 19, 2008 3:43 am 
Offline
Familiar Face

Joined: Tue Feb 12, 2008 8:47 am
Posts: 8
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:
[color=green][/color]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 24, 2008 9:25 am 
Offline
GTK+ Guru

Joined: Tue Feb 05, 2008 8:39 am
Posts: 130
show entire source


Top
 Profile  
 
 Post subject: gtk combo
PostPosted: Wed Mar 26, 2008 5:06 am 
Offline
Familiar Face

Joined: Tue Feb 12, 2008 8:47 am
Posts: 8
Code:
#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]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 27, 2008 4:17 pm 
Offline
GTK+ Guru

Joined: Tue Feb 05, 2008 8:39 am
Posts: 130
Code:
#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"


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group