RE: [tcltk-perl] Why is Tcl a subclass of Tck::Tk?
Brought to you by:
hobbs
From: Jeff H. <je...@Ac...> - 2004-04-17 22:42:57
|
> Actually 'use Tcl::Tk q(:perlTk);' needed only to export > MainWindow, MainLoop functions and few other, and nothing > more. Most perlTk syntax is available even without that qw(:perlTk) > > Currently you still can write using "perlTk syntax": > > use Tcl::Tk; > $mw = Tcl::Tk::MainWindow; > $mw->Button(-text=>'test',-command=>sub{print 'test'})->pack; > Tcl::Tk::MainLoop; This is in fact how we are setting our preferred Perl/Tcl::Tk coding style, to use $mw->Widgettype as the way to create widgets. While it's not as "simple" as the usual Tcl style, it is "clean" from the Perl perspective and works well. > > A separate module is cleaner. I would actually prefer that, but it is > > certainly an API change. If we then end up with two ways of doing > > this because we need to stay compatible I rather just keep as it is. > > In case we'll move out perlTk compatibility to separate > module, what will stay in Tcl::Tk? Only few very old > subroutines like "label", "toplevel" and so on? There are multiple levels of compatability. The basic coding style, as noted above, it worth keeping. However, there are a lot of Perl/Tk-isms that needn't be repeated in a "clean" Tcl::Tk, like modifications to core commands that do not reflect the usual behavior of Tk. There is also a ton of extra widgets that could be moved over. I would also like to add a "DeclareWidget" sub in Tcl::Tk that allows the use (or some submodule) to declare that it is making a widget available (freeing up the need to hack the ptk2tcltk hash). Something like: Tcl::Tk::Declare('BWTree', # name in Perl 'tree', # name in Tcl 'BWidget', # required Tcl package 'Tree::use', # extra code (if necessary) ) There may be other options, but you get the idea. Perhaps even do it in option => value syntax to extend it easier in the future. > May be instead of doing special compatiiblity layer for > perlTk, may be it could be reasonable to just use perlTk > syntax as main way of doing GUI in perl? Many people just > used to using that syntax from perl, and there are books about it. Right, as above, but with minor mods. I've noticed that the Perl/Tk docs aren't accurate often enough that if we start to veer from them, it won't be a big deal. > BTW (unrelated issue) if a line in Tk.pm "*{Tk::Exists} = > \&Tcl::Tk::Exists;" is commented out, it is possible to debug > Tcl::Tk code ising "ptkdb" debugger, which uses perlTk. Cool, but why is that one line needed? Are you actually loading Perl/Tk as well? I intentionally turn on the tk_gestapo to avoid such interactions from occuring, as it may lead to undesired consequences. Jeff |