[Glade-users] number entry


I apologize for not mentioning that I'm using Python... What I tried was
to make a main glade file and a keypad glade file and bring them both
into my python program with the builder but could not get the two
screens to show up correctly. Either the keypad screen would show up or
I got a blank screen.

So next I thought I would try making a dialog box and I was able to get
that working. In the process I discovered I had been doing some things
the long hand way like using a separate function for each number. What I
stumbled across was the widget is passed to the function so I could use
that to get the label of the button and know which entry had called the
keypad. Of course other keys like Clear and Save have their own

This function stores the widget that runs the dialog.
def on_entry_button_press_event(self, widget, data=None):
    self.current_entry = widget
    self.response = self.dialog1.run()

This function adds the number pressed to the keyboard label
def on_kb_clicked(self, widget, data=None):
  self.current = self.num_entry.get_text()
  self.current = self.current + widget.get_label()

This function saves the numbers to the calling entry box and closes the dialog
def on_kb_save_clicked(self, widget, data=None):

All in all it works fine, but I was looking for a modular thing with the
keypad being in it's own glade file and being able to load it into
another file so to speak.


On Tue, 2012-11-27 at 10:31 -0800, David Buchan wrote:
Ah. I missed one aspect I see you desired.
I'm not so sure you can have an Entry send a signal unless the Enter
key is pressed (which would be on_entry1_activate).
I don't see anything like "on_entry1_clicked". Perhaps someone else
can advise.

Instead, you might consider having the Entry as planned, and a
callback for it, so the user can enter the number via the entry, but
then also...

Maybe add a little button beside it labelled "Use Keypad" or
something, that pops-up the keypad.
Then you're back to using what I had in my previous email.


From: David Buchan <pdbuchan at yahoo.com>
To: John Thornton <jthornton at gnipsel.com>; Glade Users List
<glade-users at lists.ximian.com> 
Sent: Tuesday, November 27, 2012 1:22 PM
Subject: Re: [Glade-users] number entry

Hi John,

I would try to do it by having the number pad being composed of
Then I would have a callback for each of the buttons. Each callback
 - 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
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
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.
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.


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
a problem is to bring that into my main program. What I'm after is
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?


Glade-users maillist  -  Glade-users at lists.ximian.com

Glade-users maillist  -  Glade-users at lists.ximian.com

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