Hi all,
i have a little problem with entry widget.
When i am entering the text in entry widget and when giving enter key
it takes input. I am not able to modify it in such a way that
when give submit button then only it should take the entry.
source code and makefile.
if any body can help......
#make file for car
car: test.c entry_widget.c
gcc -g test.c entry_widget.c -o car `pkg-config --cflags --libs gtk+-2.0`
clean:
rm -r car
#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>
static void
enter_callback (GtkWidget * widget, GtkWidget * entry)
{
const gchar *entry_text;
entry_text = gtk_entry_get_text (GTK_ENTRY (entry));
printf ("Entry contents: %s\n", entry_text);
}
void
callback_card (GtkWidget * checkbutton, GtkWidget * widget)
{
GtkWidget *window;
GtkWidget *vbox, *hbox;
GtkWidget *entry;
GtkWidget *button;
GtkWidget *check;
gint tmp_pos;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_set_size_request (GTK_WIDGET (window), 200, 100);
gtk_window_set_title (GTK_WINDOW (window), "Card Entry");
g_signal_connect (G_OBJECT (window), "destroy",
G_CALLBACK (gtk_main_quit), NULL);
vbox = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (window), vbox);
gtk_widget_show (vbox);
entry = gtk_entry_new ();
gtk_entry_set_max_length (GTK_ENTRY (entry), 50);
g_signal_connect (G_OBJECT (entry), "activate",
G_CALLBACK (enter_callback), (gpointer) entry);
gtk_entry_set_text (GTK_ENTRY (entry), "Enter the Credict Card ");
tmp_pos = GTK_ENTRY (entry)->text_length;
gtk_editable_insert_text (GTK_EDITABLE (entry), "number ", -1, &tmp_pos);
gtk_editable_select_region (GTK_EDITABLE (entry),
0, GTK_ENTRY (entry)->text_length);
gtk_box_pack_start (GTK_BOX (vbox), entry, TRUE, TRUE, 0);
gtk_widget_show (entry);
hbox = gtk_hbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (vbox), hbox);
gtk_widget_show (hbox);
button = gtk_button_new_with_label ("submit");
g_signal_connect_swapped (G_OBJECT (button), "clicked",
G_CALLBACK (gtk_widget_destroy),
G_OBJECT(window));
gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
gtk_widget_grab_default (button);
gtk_widget_show (button);
gtk_widget_show (window);
}
#include <stdlib.h>
#include <gtk/gtk.h>
void callback_card (GtkWidget *, GtkWidget *);
int
main (int argc, char *argv[])
{
static GtkWidget *window = NULL;
GtkWidget *hbox;
GtkWidget *vbox;
GtkWidget *frame;
GtkWidget *label;
GtkWidget *button;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (G_OBJECT (window), "destroy",
G_CALLBACK (gtk_main_quit), NULL);
gtk_window_set_title (GTK_WINDOW (window), "CARS");
vbox = gtk_vbox_new (FALSE, 5);
hbox = gtk_hbox_new (FALSE, 5);
gtk_container_add (GTK_CONTAINER (window), hbox);
gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (window), 5);
frame = gtk_frame_new ("Specifications");
label = gtk_label_new ("BHP:14\nFuel: Diesel\nColor: Red\n");
gtk_container_add (GTK_CONTAINER (frame), label);
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
frame = gtk_frame_new ("TOYOTA");
label = gtk_label_new ("\nModel: Corola\nPrice: 25 Lacs\n\nModel: Camry\nPrice: 22 Lacs\n");
gtk_container_add (GTK_CONTAINER (frame), label);
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
frame = gtk_frame_new ("Ordering info");
label = gtk_label_new ("Choose right model\n"
"select payment mode\nclick submit");
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
gtk_container_add (GTK_CONTAINER (frame), label);
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
frame = gtk_frame_new ("Service Detail");
label = gtk_label_new ("You will get\nfree service for 2 yrs\n"
"After that 20% discount");
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_RIGHT);
gtk_container_add (GTK_CONTAINER (frame), label);
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
vbox = gtk_vbox_new (FALSE, 5);
gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
frame = gtk_frame_new ("Submission");
label = gtk_label_new ("The company has entire "
"right to change the policy "
"as and when required."
"If you make the payment through check "
"and it get bounsed, there will be necessary "
"legal invistigation and it is done automatically"
"by the system,so there is no kind hand or concernes."
);
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
gtk_container_add (GTK_CONTAINER (frame), label);
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
frame = gtk_frame_new ("Company Detail");
label =gtk_label_new ("This is the whole property of: "
"SoCrates Software India Pvt Ltd\n"
"The Copyright policy is according to the company "
"Policy\nIt also has free distribution "
"License as per GNU Free Software Foundation "
);
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_FILL);
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
gtk_container_add (GTK_CONTAINER (frame), label);
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
frame = gtk_frame_new ("Important");
label = gtk_label_new ("Your not able to edit the order\n"
" once you click submit!!so please read once again ");
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
gtk_label_set_pattern (GTK_LABEL (label),
"_________________________ _ _________ _ ______ __ _______ ___");
gtk_container_add (GTK_CONTAINER (frame), label);
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
frame = gtk_frame_new ("Here we go!! ");
button=gtk_button_new_with_label("Submit");
g_signal_connect(G_OBJECT(button),"clicked",
G_CALLBACK(callback_card),NULL);
gtk_container_add(GTK_CONTAINER(frame),button);
gtk_box_pack_start(GTK_BOX(vbox),frame,FALSE,FALSE,0);
gtk_widget_show_all (window);
gtk_main ();
return 0;
}
With regds,
Shyjumon N
Mobile: +91-9945006965
The information contained in this e-mail message and in any annexure is confidential to the recipient and may contain privileged information. If you are not the intended recipient, please notify the sender and delete the message along with any annexure. You should not disclose, copy or otherwise use the information contained in the message or any annexure. Any views expressed in this e-mail are those of the individual sender except where the sender specifically states them to be the views of SoCrates Software India Pvt Ltd., Bangalore.