Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Wx and MVC

by rvosa (Curate)
on Aug 10, 2006 at 00:03 UTC ( #566515=perlquestion: print w/replies, xml ) Need Help??

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

Dear monks,

I'm writing my first GUI app using wxglade. I'm trying to come up with a sensible MVC-ish architecture.

The way wxglade works is that you can define handlers for events, e.g., a button is pressed, and a subroutine \&handle_button_press (or whatever) is called. In the wxglade interface you can specify the name of the handler, and then when you generate gui code, a stub for the handler is generated as well.

I can imagine the end result being an enormous file with gui code plus lots of stubs I am supposed to fill in in the same file. This seems spaghetti-ish (and not very MVC).

I figured the following could work: I do this code generation thing as wxglade wants me to, then I delete all the handler stubs, and instead write an AUTOLOAD sub that, using $AUTOLOAD calls something like $Model->update( '-message' => $AUTOLOAD ), were the $Model in turn calls $self->notify_listeners( '-message' => $AUTOLOAD ).

I'm wondering if I'm on the right track with this or whether I'm missing something obvious.


Replies are listed 'Best First'.
Re: Wx and MVC
by TGI (Parson) on Aug 10, 2006 at 18:01 UTC

    I haven't played much with Wx, but I've built a couple pTk apps, and ran into the same problem. It seems like this is a common complaint among people who use any GUI toolset. If there is one out there that doesn't have this problem, I'd love to hear about it!

    My solution is to put all the Model and Controller code into separate modules, and also put each large chunk of interface into a module. The final script that unifies all this and configures and creates the UI units is very short.

    You may find some of the discussion Name spaces and Perl::Tk coding style helpful.

    TGI says moo

Re: Wx and MVC
by Anonymous Monk on Aug 11, 2006 at 08:50 UTC

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2020-11-26 01:42 GMT
Find Nodes?
    Voting Booth?

    No recent polls found