Developer Forums | About Us | Site Map
Search  
HOME > TUTORIALS > SERVER SIDE CODING > PERL TUTORIALS > INCLUDE GUIS IN YOUR SERVER PROGRAMMING WITH PERL/TK


Sponsors





Useful Lists

Web Host
site hosted by netplex

Online Manuals

Include GUIs in your server programming with Perl/Tk
By Cameron Laird - 2004-10-21 Page:  1 2

New horizons

This is exciting stuff. You can wrap up all your existing Perl-coded applications with skinny GUI scripts to make them into similarly interactive and "user-friendly" programs. In fact, you can easily rewrite utilities you have now so that they can continue to operate in a normal "batch" mode when given appropriate command-line arguments, but they can branch and construct a GUI window otherwise:

Listing 3. Select between command-line and GUI operation


        
      
      sub batch_operation {
      }

      sub start_GUI {
         use Tk;
         ...
         MainLoop();
            }

      if (0 == scalar(@ARGV)) {
    start_GUI();
      }
      if (errors_detected_in_@ARGV()) {
    start_GUI();
      }
      batch_operation();
     

Remember: it's just a few extra lines of the Perl (or Python, or ...) code you already know to give these results. What's more, because Perl acts as "glue" to external applications, these same techniques work to wrap legacy Fortran or C applications that you don't want to touch. Just wrap them up in a bit of Perl with backticks or exec, and you're in business.

Perl/Tk scales well, too. Substantial Perl/Tk applications are in everyday use around the world, including a biochemical simulator, geographic mapping programs, a flight management system, and much more. It's difficult to convey the feel of large-scale Perl/Tk programming. The examples above demonstrate how straightforward it is to "GUIfy" with a few extra lines of Perl. For a fuller sense of Perl/Tk programming "in the large," follow the references in Resources below, and study for yourself the source code of more complex programs.

One program I haven't written yet, except in a crude prototype, is a graphical version of Zlatanov's genetic algorithm modeler (read about it in his developerWorks article listed in Resources). I leave a more satisfying version as an exercise to the reader. My own experiments suggested it'll make a showcase for the approach this column recommends: its batch-mode operation will really come alive when visualized on the convenient Perl/Tk Canvas widget.

If you tried Perl/Tk a few years ago, and were unimpressed, it's time to give it another chance. The Perl/Tk processor has improved a great deal lately. It's far easier for Perl/Tk beginners to install binaries for popular platforms, Windows portability is much better, and the latest releases simply exhibit higher quality. Perhaps even more important, more books on Perl/Tk are available. July's second edition of O'Reilly's Perl in a Nutshell includes a valuable Perl/Tk reference. Best of all, O'Reilly kicked off 2002 with publication of Mastering Perl/Tk by Nancy Walsh and Stephen Lidie. If you plan to work for more than a couple of hours with Perk/Tk, Mastering Perl/Tk is the one reference you need to buy.

Conclusion

GUI work can seem mysterious to systems programmers and administrators. It looks like a specialized pursuit that's rather removed from the kinds of development we normally do in "Server clinic."

It doesn't have to be that way, though. Modern GUI toolkits like Perl/Tk offer good performance and functionality, along with the productivity and ease-of-learning this column most often emphasizes. Take an hour or two this month and give Perl/Tk a chance to help you wrap up your programs more attractively.

esources



View Include GUIs in your server programming with Perl/Tk Discussion

Page:  1 2 Next Page: Modern GUI toolkits make for easy system-level GUIs

First published by IBM developerWorks


Copyright 2004-2024 GrindingGears.com. All rights reserved.
Article copyright and all rights retained by the author.