On Wed, May 20, 2015 at 05:23:53PM +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.
> >> 
> >> ...
> >> 
> >> 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?

Bob

<SNIP>

> 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
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-perl-list

Reply via email to