>> How can I use a Gtk2::SpinButton to prompt for an integer expressed in hex? >> I've tried the following, but it fails. >> >> ... >> >> The text appears to be correct while I hold either arrow button down; I see >> hex values incrementing. However, single clicks of an arrow button fail if >> the displayed text contains A-F. Hitting the Enter key also fails on the >> same values. In both cases, the text changes to a decimal integer. > > What do the '$value's look like in the outputCB (either in a debugger or ...).
With single clicks of the up arrow button, the values in outputCB() increment from 0 to 10. 10 correctly displays as A. One more click of the up arrow calls outputCB() twice for some reason, the first time with a value of 0, and the second with a value of 1. So visibly, 10 wraps to 1 instead of 11, or B. If I manually type 'FF' and hit the Enter key, outputCB() is called with a value of 0. I've played with callbacks on the 'input' and 'changed' signals too, but nothing has worked so far. I learned something else. If I change the sprintf() to use '0x%X' instead of '%X', it seems to work. It also works in octal with '0%o' and binary with '0b%b'. Unfortunately, the '0x' prefix is unacceptable to my users. Grr. So I'm still in search of a way to spin a hex value, but with no '0x'. Knowing this about the prefix, though, still may be useful to others wanting something similar. > sprint - should be sprintf? Sorry about the "sprint". We're on a closed network; that was a transcription typo. > Maybe try set_value or set_digits rather than set_text? I think I have to call set_text() to see the hex version in the entry. I have tried calling set_value() too, both before and after set_text(). That gives me the same behavior: spinning seems to work, but single clicks wrap to 0 or 1 as soon as I reach a number containing [A-F]+. On set_digits(), I'm spinning integers, so I've left it at the default, 0. It wouldn't make sense being any other value, if I understand its purpose. > How are any of these impacted by the set_numeric statement? I've set this to FALSE, since I have to allow A-F to be typed into the entry. Otherwise, those key events are ignored. Thanks for any other ideas you may have. Jim -----Original Message----- From: Robert Wilkinson [mailto:b...@fourtheye.org] Sent: Wednesday, May 20, 2015 3:12 AM To: Williams, James P2 Cc: 'gtk-perl-list@gnome.org' Subject: EXTERNAL: Re: Gtk2::SpinButton For Hex On Tue, May 19, 2015 at 10:22:51PM +0000, Williams, James P2 wrote: > How can I use a Gtk2::SpinButton to prompt for an integer expressed in hex? > I've tried the following, but it fails. > > use strict; > use warnings; > > use Glib qw(TRUE FALSE); > use Gtk2 qw(-init); > > my($spin)=Gtk2::SpinButton->new_with_range(0,1000,1); > $spin->set_numeric(FALSE); > $spin->signal_connect(output => \&outputCB); > > my($win)=new Gtk2::Window(); > $win->add($spin); > $win->show_all(); > > Gtk2->main(); > > sub outputCB > { > my($spin)=@_; > my($value)=$spin->get_adjustment()->get_value(); > > $spin->set_text(sprint '%X',$value); > } > > The text appears to be correct while I hold either arrow button down; I see > hex values incrementing. However, single clicks of an arrow button fail if > the displayed text contains A-F. Hitting the Enter key also fails on the > same values. In both cases, the text changes to a decimal integer. > > Thanks. > > Jim Hi Jim What do the '$value's look like in the outputCB (either in a debugger or ...). sprint - should be sprintf? Maybe try set_value or set_digits rather than set_text? How are any of these impacted by the set_numeric statement? Bob _______________________________________________ gtk-perl-list mailing list gtk-perl-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-perl-list