RE: EXTERNAL: Re: Gtk2::SpinButton For Hex



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.

Hi Jim

If that is the case can you not use chain the sprintf through substr?

e.g.

      $spin->set_text(substr (sprintf '0x%X',$value), 2);

which will drop the first 2 characters of the string that is printed > by sprintf?

That's the same as what I had originally, which failed.

   $spin->set_text(sprintf('%X',$value));

Gtk2::SpinButton seems to spin hex values fine if the "0x" is in the string.  Your substr() version and my 
original fail, I think, because the "0x" is missing.  My users, of course, don't want to type the "0x" since 
the input is always hex, and it's really a programming convention; not something for a user interface.

Thanks.

Jim



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