Click here to get back home

Win32::GUI newbie question re dynamic GUI building

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Win32::GUI newbie question re dynamic GUI building arne thormodsen 10-06-2005
Posted by arne thormodsen on October 6, 2005, 8:44 pm
Please log in for more thread options


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




Posted by arne thormodsen on October 6, 2005, 9:09 pm
Please log in for more thread options




> 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

>
>




Posted by Rob on October 6, 2005, 11:13 pm
Please log in for more thread options


arne thormodsen wrote:
>
>>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-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/


Posted by arne thormodsen on October 6, 2005, 11:03 pm
Please log in for more thread options



> arne thormodsen wrote:
>>
>>>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-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




Similar ThreadsPosted
Question about building modules on W2K September 24, 2004, 7:09 am
Problems building Javascript-1.00 on Win32 system November 11, 2006, 9:59 pm
Newbie Question January 3, 2005, 4:11 pm
Newbie question about NTLM and web sites August 12, 2004, 9:17 am
Question to WIN32::OLE October 14, 2004, 11:34 am
Win32::OLE->Initialize question December 3, 2005, 1:18 am
question(s) re: win32::ole and active-directory interaction June 19, 2006, 10:26 pm
How to Add dynamic array/hashes to Curses::UI:Listbox -lables January 5, 2008, 1:40 am
mod_perl-1.99_16 won't make: don't know how to make dynamic September 1, 2004, 10:52 pm
Perl MakeMaker - how to force Perl linking with the static C library (libcrt.lib) instead of dynamic C library (msvcrt.lib) April 17, 2007, 5:22 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap