Re: [gtk-list] Re: gtk-text(activate) only 1 enter key!!!



Stephen Witkop wrote:
> 
> "David J. Topper" wrote:
> >
> > Hey folks,
> >
> > I've connected a vscale to a text box to get a nice little widget set
> > which acts like a spin button with a slider.  But here's the thing, I
> > can only connect signals:
> >
> >         activate
> >         changed
> >
> > to the text area.  The former only comes into play when I hit the ENTER
> > key, not the ENTER key on my keypad.  The latter is a problem because I
> > do some significant digit calculation, which gets triggered with every #
> > I hit (makes for paranoid numeric entry).
> >
> > Can this be changed?  The whole purpose here is to rapidly enter
> > numbers, that little 2nd enter key is nice, eh?
> >
> > Thanks all,
> >
> > Dave Topper
> > --
> > Technical Director, Virginia Center for Computer Music
> > Programmer / Analyst, Dean's Office (School of A&S)
> > http://www.people.virginia.edu/~djt7p
> > (804) 924-6887
> >
> > --
> > To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null
> 
> The way that I've been getting around this is to connect to the
> key_press_event and watch for a GDK_KP_enter key and handle it yourself.
> --
>                 Stephen
> 
> --
> To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null


Here's the code I use to set up the key_event callback:

  gtk_widget_set_events(GTK_WIDGET(window), 
			GDK_EXPOSURE_MASK|
			GDK_KEY_PRESS_MASK|
			GDK_KEY_RELEASE_MASK);
   
  gtk_signal_connect(GTK_OBJECT (window), "key_press_event",
		     GTK_SIGNAL_FUNC(key_press_callback), entry);

and the callback:

void key_press_callback(GtkWidget *widget, GdkEventKey *event, gpointer
data)
{
  if (event->keyval == GDK_KP_ENTER) {
    gchar *entry_data;
	
    entry_data = gtk_entry_get_text (GTK_ENTRY(entry));
  }
}

If you need to stop the key from going any further after you trap it you
can use
 
gtk_signal_emit_stop_by_name (my_widget, "key_press_event");

Of course you need to change the call for the entry widget to a text
widget, but other than that it should work for you.  

	HTH
-- 
		Stephen



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