home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2000 May
/
Chip_2000-05_cd1.bin
/
zkuste
/
Perl
/
ActivePerl-5.6.0.613.msi
/
䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥
/
_e8671967a2a5c5dc12c39f1e210f3471
< prev
next >
Wrap
Text File
|
2000-03-23
|
8KB
|
239 lines
<HTML>
<HEAD>
<TITLE>perl - very old suspect documentation on porting.</TITLE>
<LINK REL="stylesheet" HREF="../../../Active.css" TYPE="text/css">
<LINK REV="made" HREF="mailto:">
</HEAD>
<BODY>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
<STRONG><P CLASS=block> perl - very old suspect documentation on porting.</P></STRONG>
</TD></TR>
</TABLE>
<A NAME="__index__"></A>
<!-- INDEX BEGIN -->
<UL>
<LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
<LI><A HREF="#description">DESCRIPTION</A></LI>
</UL>
<!-- INDEX END -->
<HR>
<P>
<H1><A NAME="name">NAME</A></H1>
<P>Tcl vs perl - very old suspect documentation on porting.</P>
<P>
<HR>
<H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
<UL>
<LI>Linux</LI>
<LI>Solaris</LI>
<LI>Windows</LI>
</UL>
<HR>
<H1><A NAME="description">DESCRIPTION</A></H1>
<P>This isn't really a .pod yet, nor is it Tcl vs perl
it is a copy of John's comparison of Malcolm's original perl/Tk
port with the current one. It is also out-of-date in places.</P>
<PRE>
From: john@WPI.EDU (John Stoffel )</PRE>
<PRE>
Here are some thoughts on the new Tk extension and how I think the
organization of the commands looks. Mostly, I'm happy with it, it
makes some things more organized and more consistent with tcl/tk, but
since the overlying language is so different, I don't think we need to
follow exactly the tcl/tk model for how to call the language.</PRE>
<PRE>
The basic structure of the Tk program is:</PRE>
<PRE>
require Tk;</PRE>
<PRE>
$top = MainWindow->new();</PRE>
<PRE>
#
# create widgets
#</PRE>
<PRE>
Tk::MainLoop;</PRE>
<PRE>
sub method1 {
}</PRE>
<PRE>
sub methodN {
}</PRE>
<PRE>
This is pretty much the same as tkperl5a5, with some cosmetic naming
changes, and some more useful command name and usage changes. A quick
comparison in no particular order follows:</PRE>
<PRE>
tkperl5a5 Tk
------------------------------- -----------------------------------
$top=tkinit(name,display,sync); $top=MainWindow->new();</PRE>
<PRE>
tkpack $w, ... ; $w->pack(...)</PRE>
<PRE>
$w = Class::new($top, ...); $w = $top->Class(...);</PRE>
<PRE>
tkmainloop; Tk::MainLoop;</PRE>
<PRE>
tkbind($w,"<key>",sub); $w->bind("<key>",sub);</PRE>
<PRE>
tkdelete($w, ...); $w->delete(...);</PRE>
<PRE>
$w->scanmark(...); $w->scan("mark", ...);</PRE>
<PRE>
$w->scandragto(...); $w->scan("dragto", ...);</PRE>
<PRE>
$w->tkselect(); $w->Select();</PRE>
<PRE>
$w->selectadjust(...); $w->selection("adjust", ...);</PRE>
<PRE>
$w->selectto(...); $w->selection("to", ...);</PRE>
<PRE>
$w->selectfrom(...); $w->selection("from", ...);</PRE>
<PRE>
$w->tkindex(...); $w->index(...);</PRE>
<PRE>
tclcmd("xxx",...); &Tk::xxx(...) # all Tk commands, but no Tcl at all</PRE>
<PRE>
tclcmd("winfo", xxx, $w, ...); $w->xxx(...);</PRE>
<PRE>
$w->mark(...);</PRE>
<PRE>
$w->tag(...);</PRE>
<PRE>
$w->grabstatus(); $w->grab("status");</PRE>
<PRE>
$w->grabrelease(...); $w->grab("release", ...);</PRE>
<PRE>
focus($w); $w->focus;</PRE>
<PRE>
update(); Tk->update();</PRE>
<PRE>
idletasks(); Tk->update("idletasks");</PRE>
<PRE>
wm("cmd",$w, ...); $w->cmd(...);</PRE>
<PRE>
destroy($w); $w->destroy();</PRE>
<PRE>
Tk::option(...);
$w->OptionGet(name,Class)</PRE>
<PRE>
$w->place(...)</PRE>
<PRE>
Tk::property(...);</PRE>
<PRE>
$w = Entry::new($parent,...)</PRE>
<PRE>
is now</PRE>
<PRE>
$w = $parent->Entry(...)</PRE>
<PRE>
As this allows new to be inherited from a Window class.</PRE>
<PRE>
-method=>x,-slave=>y</PRE>
<PRE>
is now</PRE>
<PRE>
-command => [x,y]</PRE>
<PRE>
1st element of list is treated as "method" if y is an object reference.
(You can have -command => [a,b,c,d,e] too; b..e get passed as args).</PRE>
<PRE>
Object references are now hashes rather than scalars and there
is only ever one such per window. The Tcl_CmdInfo and PathName
are entries in the hash.</PRE>
<PRE>
(This allows derived classes to
re-bless the hash and keep their on stuff in it too.)</PRE>
<PRE>
Tk's "Tcl_Interp" is in fact a ref to "." window.
You can find all the Tk windows descended from it as their object
references get added (by PathName) into this hash.
$w->MainWindow returns this hash from any window.</PRE>
<PRE>
I think that it should extend to multiple tkinits / Tk->news
with different Display's - if Tk code does.</PRE>
<PRE>
Finally "bind" passes window as "extra" (or only)
argument. Thus</PRE>
<PRE>
Tk::Button->bind(<Any-Enter>,"Enter");</PRE>
<PRE>
Binds Enter events to Tk::Button::Enter by default
but gets called as $w->Enter so derived class of Button can just
define its own Enter method. &EvWref and associated globals and race
conditions are no longer needed.</PRE>
<PRE>
One thing to beware of : commands bound to events with $widget->bind
follow same pattern, but get passed extra args :</PRE>
<PRE>
$widget->bind(<Any-1>,[sub {print shift}, $one, $two ]);</PRE>
<PRE>
When sub gets called it has :</PRE>
<PRE>
$widget $one $two</PRE>
<PRE>
passed.</PRE>
<PRE>
1st extra arg is reference to the per-widget hash that serves as the
perl object for the widget.</PRE>
<PRE>
Every time an XEvent a reference to a special class is placed
in the widget hash. It can be retrieved by $w->XEvent method.</PRE>
<PRE>
The methods of the XEvent class are the
Tcl/Tk % special characters.</PRE>
<PRE>
Thus:</PRE>
<PRE>
$widget->bind(<Any-KeyPress>,
sub {
my $w = shift;
my $e = $w->XEvent;
print $w->PathName," ",$e->A," pressed ,$e->xy,"\n");
});</PRE>
<PRE>
XEvent->xy is a special case which returns "@" . $e->x . "," . $e->y
which is common in Text package.</PRE>
<PRE>
Because of passing a blessed widget hash to "bound" subs they can be
bound to (possibly inherited) methods of the widget's class:</PRE>
<PRE>
Class->bind(<Any-Down>,Down);</PRE>
<PRE>
sub Class::Down
{
my $w = shift;
# handle down arrow
}</PRE>
<PRE>
Also:</PRE>
<PRE>
-command and friends can take a list the 1st element can be a ref to
as sub or a method name. Remaining elements are passed as args to the
sub at "invoke" time. Thus :</PRE>
<PRE>
$b= $w->Button(blah blah, '-command' => [sub{print shift} , $fred ]);</PRE>
<PRE>
Should do the trick, provided $fred is defined at time of button creation.</PRE>
<PRE>
Thus 1st element of list is equivalent to Malcolm's -method and second
would be his -slave. Any further elements are a bonus and avoid
having to pass ref to an array/hash as a slave.</PRE>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
<STRONG><P CLASS=block> perl - very old suspect documentation on porting.</P></STRONG>
</TD></TR>
</TABLE>
</BODY>
</HTML>