http://qs321.pair.com?node_id=566515

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.

Thanks!

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