For Programmers: Free Programming Magazines  


Home > Archive > PERL Modules > October 2005 > Win32::GUI newbie question re dynamic GUI building









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Win32::GUI newbie question re dynamic GUI building
arne thormodsen

2005-10-06, 6:55 pm

I'm not new to Perl, but I am new to Win32::GUI. Hope this is the
right group to ask questions in.

I've been Googling the world for about 1/2 a day now trying to find an
example of how to dynamically generate an array of buttons and
associated callbacks at runtime.

The basic problem is that I want to be able to, at runtime, define a
list of buttons based on an external config file that contains the
button names, and add the appropriate set of callback "on click"
functions for each. I know how I'd do this in C, but can't find an
example for Perl, or anything in the docs (yet) that seems to help.
All the examples are static layouts.

Beyond this I want to dynamically generate a bunch of listboxes, and
maybe other GUI elements.

The end result is a GUI that will allow someone to move items from a
master list to one of N target lists using N add buttons. The number
of target lists will not be known until runtime, and will vary with
each instantiation of the GUI. I can put an upper bound on N.

Any help would be appreciated. Right now I'm contemplating the very
ugly solution of pre-defining a large number of elements and callback
functions and only displaying as many as I need. But this just seems
gross to me.

--arne


arne thormodsen

2005-10-06, 6:55 pm


"arne thormodsen" <arneDOTthormodsen@REMOVE.hp.com> wrote in message
news:Y0g1f.14092$fR.13839@news.cpqcorp.net...

> Any help would be appreciated. Right now I'm contemplating the very
> ugly solution of pre-defining a large number of elements and
> callback functions and only displaying as many as I need. But this
> just seems gross to me.
>
> --arne


Following up to your own post is not in the best taste, but I think
that I found one less-gross way to do it, which is to use "eval()" to
build the functions on-the-fly. But it seems to me there should be a
nicer way.

--arne

>
>



Rob

2005-10-06, 6:55 pm

arne thormodsen wrote:
> "arne thormodsen" <arneDOTthormodsen@REMOVE.hp.com> wrote in message
> news:Y0g1f.14092$fR.13839@news.cpqcorp.net...
>
>
> Following up to your own post is not in the best taste, but I think
> that I found one less-gross way to do it, which is to use "eval()" to
> build the functions on-the-fly. But it seems to me there should be a
> nicer way.


You might do better looking for help on the Win32::GUI mailing list:
perl-win32-gui-users@lists.sourceforge.net Subscribe at
http://lists.sourceforge.net/lists/...win32-gui-users

That's probably how I'd do it. Something like:

#!perl -w
use strict;
use warnings;

use Win32::GUI;

my $mw = Win32::GUI::Window->new(
-title => $0,
);
my $ncw = $mw->Width() - $mw->ScaleWidth();
my $nch = $mw->Height() - $mw->ScaleHeight();

my ($x, $y) = (10,10);

while (<DATA> ) {
chomp;
$mw->AddButton(
-name => $_,
-title => $_,
-pos => [$x,$y],
-size => [60,20],
);
$y += 30;
eval "sub ${_}_Click { print '$_ clicked\n'; 0; }";
}

$mw->Resize(80+$ncw, $y+$nch);

$mw->Show();
Win32::GUI::Dialog();
exit(0);
__END__
Button1
Button2
Button3
Button4
Button5
Button6
Button7
Button8


Regards,
Rob.
--
Robert May
Win32::GUI, a perl extension for native Win32 applications
http://perl-win32-gui.sourceforge.net/
arne thormodsen

2005-10-06, 6:55 pm


"Rob" <rm@nospam.popeslane.clara.co.uk> wrote in message
news:xNWdnf6MDdo4PNjeRVnysA@pipex.net...
> arne thormodsen wrote:
>
> You might do better looking for help on the Win32::GUI mailing list:
> perl-win32-gui-users@lists.sourceforge.net Subscribe at
> http://lists.sourceforge.net/lists/...win32-gui-users
>
> That's probably how I'd do it. Something like:
>


Thanks for the quick answer. I'm trying the "eval()" approach right
now.

--arne


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com