I've tried to separate Content from View from Model. I have a pretty firm grip on this approach in a web-app context. The app I am writing about is a desktop app that polls a group of sensors and displays the data collected (among other things).

I modeled things along the CMV principle by creating a set of libraries that abstract interaction with the sensors. As I split things up, the Content is the raw data from the sensors; the Model is libraries that control the sensors, and the View is my big collection of GUI code. Most of my code (little surprise here) is in the GUI.

The communications library takes allows the calling program to register a 'monitor' function that is in charge of scheduling polling of my input buffers and passing data back to the rest of the codebase. That's the only place that Model touches View.

Each element of the GUI code, say for example a display panel, is a vanilla perl object (in this case a blah::blah::blah::Display::Panel object). Each display pannel has some attributes it uses to store it state, GUI elements and references to shared data. I considered building MegaWidgets to handle this type of task, but I decided to keep my options open (which you and zentara) seem to agree was the right idea.

Right now I could rip out pTk and replace it with another GUI library with minimal pain. Some of my objects might need some new attributes, or others might be removable. Probably the hardest thing would be making sure that all my callbacks are getting called with the right data.

If I read the various replies correctly, they are an endorsement of my current approach and advise against making any changes.

I wish I could share more of my code and get a more detailed commentary, alas, it is proprietary (and not legally mine).

Thank you for your thoughts.

PS. As to the maintainability of large pTk apps, it can be done. I've been living with the current incarnation of this app for about 8 months and have needed to come back and make changes on several occasions, each time has been painless. However, the first version of this same application was impossible to work on--I wrote the core of it (my first big pTk app) under considerable time pressure. Due to other projects that kept me busy, some changes were handed off to a contractor who bolted on some less than pretty code (although my code was cluttered and ugly to begin with). The poor thing rapidly evolved into the famous big-ball of mud pattern and had to be put down. My current code base is built on the painful lessons learned there.

PPS. As to pTk vs other libraries, I considered switching very carefully, but the better documentation and widget library has kept me with pTk, warts and all. wxPerl looks very tempting, as does Prima, Gtk2, and Tcl::Tk. When I have some spare time I'll look into these options again.


TGI says moo


In reply to Re^4: Perl Tk - propagating events by TGI
in thread Perl Tk - propagating events by TGI

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.