comp.lang.perl.tk FAQ part2 of 3 
Author Message
 comp.lang.perl.tk FAQ part2 of 3




explicitely here?

Quote:

> There is no Perl equivalent to the Tcl unknown proc.

AUTOLOAD.

Quote:
>     #!/usr/bin/perl -w


        use lib $ENV{PWD};

Quote:
>      use Tk;
>      use Foo;

> After a successful test; if you are a system administrator, or have root
> priveleges, or are modifying your own copy of perl; then copy it to the
> perl5/Tk directory. Depending on how the module was written it should
> be possible to use it either with the use Tk; statement itself or with an
> explicit use Tk::Foo; (for module perl5/Tk/Foo.pm).

No mention of MakeMaker ?!

Quote:
> Keep in mind that you are programming in perl after all. The perl debug line
> mode is available to you through executing the following from your shell:

>     perl -de 0

> Whereupon you must enter all the lines of a script including use Tk;.
> (Fancier file reads & evals are possible - but if you are getting that
> sophisticated why not create your own custom PERL5DB file?) When using
> perl -dwe 0 beware of the emacs like line editing under this de{*filter*},
> and be forewarned that as soon as you type in the MainLoop; statement
> perl will no longer read from <STDIN>.

Unless you use the latest version I sent to p5p yesterday ;-). Note
that you may use

sub myLoop {
  if (defined &DB::DB) {
    while (1) {                 # MainWindow->Count
      Tk::DoOneEvent(0);
    }
  } else {
    MainLoop;
  }

Quote:
}

(and I hope the analogous provision will be in MainLoop in tk-b9 - hi,
Nick ;-)

Ilya



Tue, 02 Jun 1998 03:00:00 GMT  
 comp.lang.perl.tk FAQ part2 of 3

Newsgroups: comp.lang.perl.tk,comp.answers,news.answers
Subject: comp.lang.perl.tk FAQ part2 of 3
Followup-To: comp.lang.perl.tk
Summary: comp.lang.perl.tk Frequently Asked Questions.

Archive-name: ptkFAQ/part2
Posting-Frequency: monthly
Last-modified: Thu Dec 14 22:10:38 EST 1995
URL: http://w4.lns.cornell.edu/~pvhp/ptk/ptkFAQ.html
Version: DRAFT

URL (Hypertext-split): http://w4.lns.cornell.edu/~pvhp/ptk/ptkTOC.html
URL (Text-version): http://w4.lns.cornell.edu/~pvhp/ptk/ptkFAQ.txt
URL (Image-supplement):
http://w4.lns.cornell.edu/~pvhp/ptk/ptkIMG.html
ftp-Archive: ftp://ftp.ccd.bnl.gov/pub/ptk/ptkFAQ.txt
ftp-Archive: ftp://ftp.wpi.edu/perl5/pTk-FAQ

gopher-Archive: none yet

Perl/Tk FAQ part 2 of 3 - More Programming
******************************************

______________________________________________________________________

12. What are some of the primary differences between Tcl/Tk and Perl/Tk?

Considering that both interpreter/compilers for Tcl and Perl were written in
C for use on Unix computers it is not surprising that there are some
similarities. Nevertheless, there are a large number of differences between
the Tcl scripting language and the Perl scripting language. While this table
does not cover all the differences it is hoped that it will prove useful,
especially to those people coming from a primarily Tcl/Tk background.
These are some of the common Tcl->Perl stumbling points:

what              Tcl/Tk                 Perl/Tk
variable          set a 123              $a = 123; or $a = '123';
 initialization
re-assignment     set b $a               $b = $a;



associative       set a(Jan) 456.02      %a = ('Jan',456.02,'Feb',534.96);
 arrays           set a(Feb) 534.96
re-assignment     foreach i \            %b = %a;
                   [array names a] {
                   set b($i) = $a($i) }

Note on the above examples:
In Tcl the scalar, list, and array variable 'a' will overwrite each
previous assignment.

expressions       set a [expr $b+$c]     $a = $b+$c;

increment         incr i                 $i++;


 subroutines       expr $a + $b }         $a+$b; }

variable scope    local default          global default
                  override w/ "global"   override w/ "my"    

call              plus 1 2               &plus(1,2); #or
 subroutines                             plus(1,2);  #OK after sub plus

statement end     newline or at ";"      ";" required

statement         "\" - newline          none required
 continuation

verbatim strings  {}                     ''

escaped strings   ""                     ""
 e.g.             "Who\nWhat\nIdunno"    "Who\nWhat\nIdunno"

STDOUT            puts "Hello World!"    print "Hello World!\n"
                  puts stdout "Hello!"   print STDOUT "Hello!\n"

Note also that Tcl/Tk has a built-in abbreviation completion mechanism
that lets you specify short hand, e.g.

   canvas .frame.canvas -yscrollcommand ".frame.scroll set" ; #Tcl/Tk OK
   canvas .frame.canvas -yscroll ".frame.scroll set" ;        #Tcl/Tk also OK
   $canvas=$main->Canvas(-yscroll => ['set',$scroll]);  #ERROR perl/Tk
   $canvas=$main->Canvas(-yscrollcommand => ['set',$scroll]); #perl/Tk OK

You may get around this with the perl abbrev.pl package in certain
circumstances. For example:

   require 'abbrev.pl';
   %foo = ();
   &abbrev(*foo,'-yscrollcommand');
 ...
   $canvas=$main->Canvas($foo{'-yscroll'} => ['set',$scroll]); #perl/Tk OK

There is no Perl equivalent to the Tcl unknown proc.

______________________________________________________________________

13. How do I install new modules?

Check out the module - make sure it is OK and will run on your system -
does it require a specific location? For testing purposes (always a good idea)
or if you do not have root priveleges set the file in a directory that you do
have write access to and try to include it in a test script. Assuming you have
a module to test called "Foo.pm" and are simply running the test script in

    #!/usr/bin/perl -w

     use Tk;
     use Foo;

After a successful test; if you are a system administrator, or have root
priveleges, or are modifying your own copy of perl; then copy it to the
perl5/Tk directory. Depending on how the module was written it should
be possible to use it either with the use Tk; statement itself or with an
explicit use Tk::Foo; (for module perl5/Tk/Foo.pm).

______________________________________________________________________

14. How do I write new modules?

You might want to start by poking around your Tk-b# distribution directory.
Is there something there that already does what you want? Is there
something that is reasonably close - but only requires minor modification?

Next go through the various perl documents - including the FAQ as well as
the various relevant man pages: perlmod(1), perlobj(1),
perlbot(1), (and please don't forget: perlpod(1)!)

Post your idea to comp.lang.perl.tk and discuss it with others - there might
very well be someone working on an approach already. A clear explanation
of all the stuff that gets put into a module was posted to the mailing list and
can be found in the archive at:

    http://sun20.ccd.bnl.gov/%7Eptk/archive/ptk.1995.10/0012.html

Also, be sure to check out a recent version of the official Module List that

comp.lang.perl.announce periodically. The list is also available at:

    ftp://rtfm.mit.edu/pub/usenet/news.answers/perl-faq/module-list
    ftp://ftp.demon.co.uk/pub/perl/db/mod/module-list.txt
    ftp://ftp.wpi.edu/perl5/Modules/module_list.txt

Finally ready to ship? Small (perl/Tk) modules have been posted directly to
comp.lang.perl.tk. Big modules may require ftp distribution (see upload info
at one of the CPAN sites) then make your announcement to
comp.lang.perl.tk and possibly to comp.lang.perl.announce.

______________________________________________________________________

15. Composite Widgets.

Composite widgets combine the functions of two or more widget primitives
into something that is not quite a stand alone program but is something that
may prove very useful for inclusion in your own scripts. A variety of
composite widgets have been written and many are still being worked on.
Many come bundled with your Tk-b# distribution, and some are simply
posted to comp.lang.perl.tk. It is quite common to have composite widgets
written in perl modules - usually in terms of the Tk widget primitives.
Graphical examples of some of the composites discussed here can be seen by
GUI browsers at:

    http://w4.lns.cornell.edu/~pvhp/ptk/ptkIMG.html

______________________________________________________________________

15.1. How do I get a Dialog box?

For things like a simple "are you sure?" dialog box you might want to take a
look at perl5/Tk/Dialog.pm. This module may be invoked with
require Tk::Dialog; etc. - there are much more extensive directions
inside the comment fields at the top of the Dialog.pm file itself. The
module has a lot of options and has a tutorial driver script in
perl5/Tk/demos/dialog. Dialog.pm is also used by the
perl5/Tk/demos/widget demo. In particular look at
perl5/Tk/demos/widget_lib/dialog1.pl and dialog2.pl
for examples of how one makes use of Tk::Dialog. A snippet of a script that
uses this module could look like:

    require Tk::Dialog;

    my $mw = MainWindow->new;
    my $D = $mw->Dialog(
                 -title => 'Are you sure?',
                 -text  => "You have requested rm \*\nAre you sure?",
                 -default_button => 'No',
                 -buttons        => ['No','yes']
                       );
    my $choice = $D->show;

    print " you chose $choice \n";

______________________________________________________________________

15.2. Is there a file selector?

Yes, there may be several eventually...

One distributed with the Tk-b# code itself is called FileSelect.pm and was
written by Frederick L. Wagner - (based on an original by Klaus
Lichtenwalder).

Another module called SelFile.pm was adapted by Alan Louis Scheinine
from Wagner's FileSelect.pm. It is available from:

    http://sun20.ccd.bnl.gov/%7Eptk/archive/ptk.1995.11/0122.html
or
    http://w4.lns.cornell.edu/~pvhp/ptk/etc/SelFile.pm

A module called FileSave.pm allows one to type in a new (non-existant)
filename for "Save as..." type operations. It was posted by Mark Elston on 12
Oct 1995 to the mailing list and is available from:

    http://sun20.ccd.bnl.gov/%7Eptk/archive/ptk.1995.10/0093.html
or
    http://w4.lns.cornell.edu/~pvhp/ptk/etc/FileSave.pm

Many of these will no doubt be bundled with the next Tk-b# release.

______________________________________________________________________

15.3. Is there a color editor?

There is. Please see

    perldoc ColorEditor.pm

or run the perl5/Tk/demos/color_editor demo script for more
information.

______________________________________________________________________

15.4. Is there a round Scale?

It is not quite a "round Scale" but Roy Johnson has written "Dial.pm" for
round dial (or speedometer) -like settable widgets. It is available from:

    http://sun20.ccd.bnl.gov/%7Eptk/archive/ptk.1995.08/0431.html
or
    http://w4.lns.cornell.edu/~pvhp/ptk/etc/Dial.pm

______________________________________________________________________

15.5. Is there something equivalent to tkerror?

There is. Please see the Tk/ErrorDialog.pm module for further
information.
...

read more »



Tue, 02 Jun 1998 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. comp.lang.perl.tk FAQ part2 of 5

2. comp.lang.perl.tk FAQ part2 of 5

3. comp.lang.perl.tk FAQ part2 of 3

4. comp.lang.perl.tk FAQ part2 of 5

5. comp.lang.perl.tk FAQ part2 of 5

6. comp.lang.perl.tk FAQ part2 of 5

7. comp.lang.perl.tk FAQ part2 of 5

8. comp.lang.perl.tk FAQ part2 of 5

9. comp.lang.perl.tk FAQ part2 of 5

10. comp.lang.perl.tk FAQ part2 of 5

11. comp.lang.perl.tk FAQ part2 of 5

12. comp.lang.perl.tk FAQ part2 of 5

 

 
Powered by phpBB® Forum Software