From: Neil Conway Date: 2001-09-30T08:39:58+09:00 Subject: [ruby-talk:21835] Re: how to position cursor in gtk entry field? Hi, On Sat, 2001-09-29 at 16:20, Ned Konz wrote: > Thanks to the suggestion earlier re: validation, I was able to get this working > (I'm using libglade and gtk+): > > in initialize: > > @entryField = @glade.getWidget("item_number_entry") > handler = method(:item_number_changed).to_proc > @entryFieldHandlerId = @entryField.signal_connect("insert_text", &handler) > > then: > > def item_number_changed(e, t, n) > newText = t.gsub(/\D/, '') I think using String#tr would be faster. > if newText.length > 0 > begin > e.signal_handler_block(@entryFieldHandlerId) > e.insert_text(newText, n) > # what to do here to move the cursor? > ensure > e.signal_handler_unblock(@entryFieldHandlerId) > end > end > e.signal_emit_stop("insert_text") > end Right, that should work -- although it's not the best solution. I'll think about the solution you suggested and see if I can implement something. > Which does the validation/filtering just fine. > But when it inserts the text, the cursor stays at the same place. > I've tried position=, set_position, and set_selection; none of the three seemed to work. set_position should work -- it's been implemented, and it's just a thin wrapper over the GTK+ function gtk_entry_set_position(int). In Ruby-GNOME 0.26, it will instead call gtk_editable_set_position(int), but the behavior should be the same. If you're having problems, can you post the code you're using and the error you get? Cheers, Neil