Attn: Thomas Reg. Temp Conversion Combobox example code.....
- From: manchalapraveenk reddy <praveenmkr yahoo com>
- To: gtk-app-devel-list gnome org
- Subject: Attn: Thomas Reg. Temp Conversion Combobox example code.....
- Date: Tue, 4 Sep 2001 05:47:13 -0700 (PDT)
hi Thomoas,
10q for responding i got confused in passing the
parameter to the switch() to
what to pass and the parameters of the eventhandler i
will he thak ful to u if
u can provide the required. plz find my coding for the
same.
/* example-start convert2.c */
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include <gtk/gtk.h>
#include<glib.h>
#include<gdk/gdkkeysyms.h>
static GtkWidget *entry1,*entry2;
static GList *glist;
static char *str;
/* static void on_button1_clicked (void)
{
//
gtk_entry_set_text(GTK_ENTRY(entry2),gtk_entry_get_text(GTK_ENTRY(entry1)));
const char
*str1=gtk_entry_get_text(GTK_ENTRY(entry1));
int i1=atoi(str1);
char buf[10];
int i2=((i1-32)*(0.556));
snprintf(buf,10,"%i",i2);
gtk_entry_set_text(GTK_ENTRY(entry2),buf);
// g_print(gtk_entry_get_text(GTK_ENTRY(entry1)));
g_print("Hello");
}*/
static void fah(void)
{
const char
*str1=gtk_entry_get_text(GTK_ENTRY(entry1));
int i1=atoi(str1);
int i2;
char buf[10];
switch ( GTK_COMBO(combo->entry))
{
case 1:
i2=((i1-32)*(0.556));
snprintf(buf,10,"%i",i2);
break;
case Kelvin:
i2=(((i1-32)*(0.556))+273.15);
snprintf(buf,10,"%i",i2);
break;
default:
snprintf(buf, 10,"%i",i1);
}
}
int main( int argc,
char *argv[] )
{
GtkWidget *window;
GtkWidget *table;
GtkWidget *label1,*label2;
GtkWidget *button;
GtkWidget *combo;
GtkWidget *button2;
gtk_init (&argc, &argv);
/* create a new window */
window =
gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_set_usize( GTK_WIDGET (window),
300, 200);
gtk_window_set_title(GTK_WINDOW (window),
"GTK Entry");
gtk_signal_connect(GTK_OBJECT (window),
"delete_event",
(GtkSignalFunc) gtk_exit,
NULL);
table= gtk_table_new(4,2,TRUE);
gtk_container_add(GTK_CONTAINER (window),
table);
/* Create a new Label*/
label1 = gtk_label_new("Enter Value");
gtk_table_attach_defaults(GTK_TABLE(table),label1,
0,1,0,1);
gtk_widget_show(label1);
/* Create a new label*/
label2 = gtk_label_new("Converted Value");
gtk_table_attach_defaults(GTK_TABLE(table),
label2, 1,2,0,1);
gtk_widget_show(label2);
/* Create a new Text Entry */
entry2 = gtk_entry_new_with_max_length
(50);
gtk_table_attach_defaults(GTK_TABLE(table),
entry2, 1,2,1,2);
gtk_widget_show (entry2);
/* Create a new Text Entry */
entry1 = gtk_entry_new_with_max_length
(50);
gtk_table_attach_defaults(GTK_TABLE(table),
entry1, 0,2,1,2);
gtk_widget_show (entry1);
/* Create a combo */
combo=gtk_combo_new();
gtk_table_attach_defaults(GTK_TABLE(table),combo,
0,1,2,3);
glist =g_list_append(glist,"Fahrenheit");
glist =g_list_append(glist,"Celsius");
glist =g_list_append(glist,"Kelvin");
gtk_combo_set_popdown_strings(GTK_COMBO(combo),glist);
str=gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo)->entry));
//gtk_signal_connect(GTK_COMBO((combo)->entry),"changed",GTK_SIGNAL_FUNC(fah),
glist);
gtk_signal_connect(GTK_OBJECT(GTK_COMBO(combo)->entry),"activate",
GTK_SIGNAL_FUNC(fah),
&glist);
gtk_widget_show(combo);
/* Create a new button */
button2 = gtk_button_new_with_label
("Close");
gtk_signal_connect_object (GTK_OBJECT
(button2), "clicked",
GTK_SIGNAL_FUNC(gtk_exit),
GTK_OBJECT (window));
gtk_table_attach_defaults(GTK_TABLE(table),
button2, 1,2,3,4);
gtk_widget_show_all(window);
GTK_WIDGET_SET_FLAGS(button,
GTK_CAN_DEFAULT);
// gtk_widget_grab_default (button);
gtk_main();
return(0);
}
Regards,
Praveen
=====
Praveen K Reddy
Mumbai
__________________________________________________
Do You Yahoo!?
Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger
http://im.yahoo.com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]