[Glade-users] number entry



Hi John,

I would try to do it by having the number pad being composed of Buttons.
Then I would have a callback for each of the buttons. Each callback would:
?- Take the existing number from the entry (if length is non-zero). That will be a string.
?- Then take print the number associated with the button that was clicked as a character and append it to the 
string in the entry. I use C, so here's some unchecked C code...

I pass the number around in a struct, so I define it here:

typedef struct _ProgData ProgData;
struct _ProgData {
? gint magic_number;
? // You'd probably have other stuff in here.
}

I assume the entry was grabbed from the glade file using gtkbuilder? We need to get the entry object:

data->entry1 = GTK_WIDGET (gtk_builder_get_object (builder, "entry1"));?? // Our number

Same for the buttons, but only if the keypad has popped-up. (I use 10 for 0 because I'm not sure you're 
allowed to name a button as 'button0'.)
data->button10 = GTK_BUTTON (gtk_builder_get_object (builder, "button10"));? // Keypad button 0
data->button1 = GTK_BUTTON (gtk_builder_get_object (builder, "button1"));? // Keypad button 1
data->button2 = GTK_BUTTON (gtk_builder_get_object (builder, "button2"));? // Keypad button 2
...etc...
data->button9 = GTK_BUTTON (gtk_builder_get_object (builder, "button9"));? // Keypad button 9

Then the callback for the button labelled "3", for example, might be something roughly like:

// Callback to add a digit '3' to the number entry.
gboolean
on_button3_clicked (GtkButton *button, ProgData *data)
{
? const gchar *entry1_text;
? char value[256];

? entry1_text = gtk_entry_get_text (GTK_ENTRY (entry1));

? memset (value, 0, 256);
? sprintf (value, "%s3", entry1_text);

? data->magic_number = atoi (value);
? gtk_entry_set_text (GTK_ENTRY (data->entry1), value);
? 
? return (TRUE); 
}

I *think* that should do it, unless I misunderstood.

I wonder if you really need that to be an entry. You can have the buttons update the actual number in the 
variable and show it in a textview instead. Just a thought. I suppose with the text entry, the user can use 
the number pad or type the number in directly. Maybe you desire that extra option.

Dave



________________________________
 From: John Thornton <jthornton at gnipsel.com>
To: Glade Users List <glade-users at lists.ximian.com> 
Sent: Monday, November 26, 2012 12:55 PM
Subject: [Glade-users] number entry
 
I want to create a number entry glade and have done so. Where I'm having
a problem is to bring that into my main program. What I'm after is when
I click on an entry box the number keypad pops up so I can enter the
numbers and when I press the save button it puts the numbers into the
entry box.

Is this possible? Any examples anywhere?

Thanks
John

_______________________________________________
Glade-users maillist? -? Glade-users at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/glade-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/glade-users/attachments/20121127/10fc93f5/attachment.html>




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]