Win32::GUI newbie question re dynamic GUI building
am 06.10.2005 22:44:40 von arne thormodsen
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
Re: Win32::GUI newbie question re dynamic GUI building
am 06.10.2005 23:09:05 von arne thormodsen
"arne thormodsen" 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
>
>
Re: Win32::GUI newbie question re dynamic GUI building
am 07.10.2005 00:13:54 von Rob
arne thormodsen wrote:
> "arne thormodsen" 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.
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/listinfo/perl-win32-gui-u sers
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 () {
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/
Re: Win32::GUI newbie question re dynamic GUI building
am 07.10.2005 00:46:26 von arne thormodsen
"Rob" wrote in message
news:xNWdnf6MDdo4PNjeRVnysA@pipex.net...
> arne thormodsen wrote:
>> "arne thormodsen" 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.
>
> 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/listinfo/perl-win32-gui-u sers
>
> That's probably how I'd do it. Something like:
>
Thanks for the quick answer. I'm trying the "eval()" approach right
now.
--arne