Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

How to organize a Perl TK application?

by Brutha (Friar)
on Oct 01, 2008 at 11:41 UTC ( [id://714783]=perlquestion: print w/replies, xml ) Need Help??

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

I am looking for ideas on how to organize a Perl TK application. All examples I have found have a big main file which contains all creations of widgets in an endless number of lines. This makes it not very maintainable. I would like to organize it more the Modell/View/Controller way with modules. How do You organize Your applications? Thank You for Your advice.

And it came to pass that in time the Great God Om spake unto Brutha, the Chosen One: "Psst!"
(Terry Pratchett, Small Gods)

Replies are listed 'Best First'.
Re: How to organize a Perl TK application?
by dHarry (Abbot) on Oct 01, 2008 at 13:02 UTC
      Thank You, that was something I was too stupid to find with Super Search, but that gives me a lot hints.

      And it came to pass that in time the Great God Om spake unto Brutha, the Chosen One: "Psst!"
      (Terry Pratchett, Small Gods)

Re: How to organize a Perl TK application?
by Wiggins (Hermit) on Oct 01, 2008 at 13:59 UTC
    The view of hundreds of lines of TK widget definitions may seem messy and daunting, but that is probably just bad organization. I find that having all the graphic layout in 1 location(file); well commented and visually organized; shows the whole picture in one place. PerlTK is relatively clean, compared to X11R3 with Sony widgets, where I started doing GUIs.

    Draw your layout; and have a naming convention for widgets and variables that supports your nesting or management scheme. Then segment the callbacks (action code) into separate modules that are related... all input in one, all validations in another; or 1 module per GUI manipulation object/widget.

    Trying to do incremental widget instantiation in a 'workproc' is probably beyond PerlTK.

    Comment...Describe why...think maintainability.

Re: How to organize a Perl TK application?
by zentara (Archbishop) on Oct 01, 2008 at 13:12 UTC
    I'm totally guilty of making large scripts. Why? Well it's easier to debug when developing, since ALL the code is open in your editor. My approach is make a big script, trying to use a big hash to store everything if possible, so if it is a useful script that I want to call often, I can easily turn it into a module, by turning the hash into a blessed $self.

    If you havn't already, google for "perl Tk mega", "perl Tk derived", "perl Tk custom widgets", for how to modularize your Tk code snippets.


    I'm not really a human, but I play one on earth Remember How Lucky You Are
Re: How to organize a Perl TK application?
by JavaFan (Canon) on Oct 01, 2008 at 11:52 UTC
    How do You organize Your applications?

    It depends. ;-)

    I've used MVC in the past. But I've also split my applications by function: use a module that, say, deals with displaying an image. It'll both have the "business logic" and the interaction with the widgets to display it.

    But most often, I use something in between. In the backend, there's code that deals with the "model", but the frontend code that deals with displaying and input also does input validation and some state transisitions.

Re: How to organize a Perl TK application?
by TGI (Parson) on Oct 01, 2008 at 20:53 UTC
Re: How to organize a Perl TK application?
by GrandFather (Saint) on Oct 01, 2008 at 20:01 UTC

    I tend to wrap up the $main in a light weight object in the .pl file then pass that object into light weight object constructors in .pm files to manage dialogs and other such pieces that I want to organize into their own box. That lets me pass common information around in a blessed hash and allows maintenance of separate chunks of code in their own file.

    I haven't time to provide a code outline at present, but ask and I'll whip up something tonight.


    Perl reduces RSI - it saves typing
Re: How to organize a Perl TK application?
by vkon (Curate) on Oct 02, 2008 at 08:46 UTC
    All my perl/Tk applications are using Tk via Tcl::Tk which allows me better flexibility.

    I do this way:

    use strict; use Tcl::Tk; my $int = new Tcl::Tk; $int->Eval (<<'EOS'); # here goes Tk code to construct GUI pack [text .t] pack [button .b -text button] EOS # and here goes main code with perl/Tk syntax my $txt = $int->widget('.t','Text'); $txt->insert('end',"text text tex"); $int->MainLoop;

    This has proven to be very convenient for all my Tk-GUI projects.
    Indeed, separated GUI and logic,much easier to maintain than ordinary perl/Tk code.
    Perl/Tk, in the contrary, is much more noisy than Tcl/Tk GUI.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://714783]
Approved by moritz
Front-paged by TGI
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-19 19:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found