Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Formatting Gtk Pages

by gnubbs (Beadle)
on Feb 18, 2005 at 16:58 UTC ( #432410=perlquestion: print w/replies, xml ) Need Help??

gnubbs has asked for the wisdom of the Perl Monks concerning the following question:

I am currently working on a simple app that will allow a user to select between a list of configurations for another program. I am currently use Gtk for the frontend and am having some issues. I would like to have a list of checkboxes in my window that looks like:
[] 1 Configuration 1 Description [] 2 Another Configuration Another Description [] 102 Third configuration Third description
I would like to have the entire line be selectable, not the just the checkbox. This leaves me trying something like:
my $check_string = sprintf("%$configuration_maxs %$name_maxs %$descrip +tion_maxs", $configuration, $name, $description"); $checkbox = new Gtk::CheckButton( $check_string );
Where $configuration_max, $name_max, and $description_max contain the maximum length of these strings.

This doesn't get the alignment right because the font in the Gtk theme may not be fixed width (almost definately won't be fixed width.) So, masters of window layout, please let me in on your secrets before the other programmers break me down into just another motif programmer.

Replies are listed 'Best First'.
Re: Formatting Gtk Pages
by Courage (Parson) on Feb 18, 2005 at 17:59 UTC
    for Tk it appears that simple tab character makes alignment.

    Dont know whether this works for Gtk however, and how to configure tab settings in case you know their positions.

Re: Formatting Gtk Pages
by Aristotle (Chancellor) on Feb 19, 2005 at 05:08 UTC

    Please don't use Gtk for new code. It is unmaintained, has never been complete, and binds a library that is obsolete. Have a look at Gtk2 instead.

    What you're trying to do is quite simple with Gtk2::Ex::Simple::List.

    my $slist = Gtk2::Ex::Simple::List->new ( 'Setting' => 'bool', 'Configuration' => 'int', 'Name' => 'text', 'Description' => 'text', ); @{$slist->{data}} = ( [ 0, 1, 'Configuration 1', 'Description' ], [ 0, 2, 'Another Configuration', 'Another Description' ], [ 0, 102, 'Third configuration', 'Third description' ], );

    Makeshifts last the longest.

      I agree that using Gtk is not ideal, but unfortunately I have no control over the modules installed on this system and Gtk is the only GUI toolkit installed. I will have to talk to the OS administrator for our systems to see if I can add it during the install of this script. Thanks everyone for the help. gnubbs

        Just to provide some closure to this post...

        I have ended up using Gtk2. It requires my install script for this script to also install perl-glib and perl-gtk2 but that in the end is not as hard as getting this functionality in Gtk (not Gtk2). So, it will be Gtk2 and a list store.

        Thanks again for your help.

Re: Formatting Gtk Pages
by paulbort (Hermit) on Feb 18, 2005 at 18:20 UTC

    OK, my Perl skills are all non-UI, but back in the dark days I programmed in a Very Basic language that was just about all UI.

    The solution there would be to hook the click event on the checkboxes, and then fiddle the background color of all of the fields on that row. Viola, you've highlighted the selection.

    I'm pretty sure the same method would work in Tk, too.

    Spring: Forces, Coiled Again!
      Yeah. This is where I am going if I don't hear a simpler solution. Hopefully someone will respond with something simple and brilliant... Thanks for the responses.
Re: Formatting Gtk Pages
by meredith (Friar) on Feb 18, 2005 at 22:13 UTC

    Gtk seems to have a grid widget that supports rendering cells as toggle-buttons. Would that help you out? Run 'gtk-demo' on your system, and double-click "List Store" on the left.

    mhoward - at -

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://432410]
Approved by jfroebe
Front-paged by Courage
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2020-08-14 05:40 GMT
Find Nodes?
    Voting Booth?
    Which rocket would you take to Mars?

    Results (75 votes). Check out past polls.