Add To Tcl Syntax Highlighting Tk Commands Textastic For Mac

admin
  • DESCRIPTION
  • Basic Usage/Operation
    • Creating and using widgets
  • A behind-the-scenes look at auto-wrapped widgets
  • Miscellaneous methods

Apart from 80+ languages and syntax highlighting, the app is compatible with TextMate syntax definitions and themes. Key Takeaways. There are many text editors for programming out there, some of them free while others are not. The features the programming text editors come with may also vary greatly. The second group of commands is created using the Tcl extension mechanism. Tcl provides APIs that allow you to create a new command by writing a command procedure in C or C that implements the command. You then register the command procedure with the Tcl interpreter by telling Tcl the name of the command that the procedure implements.

Tcl::pTk - Interface to Tcl/Tk with Perl/Tk compatible syntax

Perl/Tk Compatible Syntax:

Or Tcl::pTk Synax with direct access to Tcl:

Tcl::pTk interfaces perl to an existing Tcl/Tk installation on your computer. It has fully perl/tk (See Tk) compatible syntax for running existing perl/tk scripts, as well as direct-tcl syntax for using any other Tcl/Tk features.

Using this module an interpreter object is created, which then provides access to all the installed Tcl libraries (Tk, Tix, BWidgets, BLT, etc) and existing features (for example native-looking widgets using the Tile package).

Features

  • Perl/Tk compatible syntax.

  • Pure perl megawidgets work just like in perl/tk. See the test case t/slideMegaWidget.t in the source distribution for a simple example.

  • All the perl/tk widget demos work with minimal changes. Typically the only changes needed are just changing the use Tk; to use Tcl::pTk; at the top of the file. See the widgetTclpTk demo script included in the source distribution to run the demos.

  • Built-in local drag-drop support, compatible with perl/tk drag-drop coding syntax.

  • Tcl::pTk::TkHijack package supplied which enables Tcl::pTk to be used with existing Tk Scripts.

  • Similar interface approach to Tcl/Tk that other dynamic languages use (e.g. ruby, python). Because of this approach, upgrades to Tcl/Tk shouldn't require much coding changes (if any) in Tcl::pTk.

  • Tcl::pTk::Facelift package supplied, which provides a quick way of using the new better-looking Tile/ttk widgets in existing code.

  • TableMatrix (spreadsheet/grid Tktable widget, built to emulate the perl/tk Tk::TableMatrix interface ) built into the package (as long as you have the Tktable Tcl/Tk extension installed).

  • Extensive test suite.

  • Crystal reports 9 full download or descarga. Compatible with Tcl/Tk 8.4+

Examples

There are many examples in the widgetTclpTk script (This is very simlar to the widget demo installed with perl/tk). After installing the Tcl::pTk package, type widgetTclpTk on the command line to run.

The test cases in the t directory of the source distribution also is a good source of code examples.

This package (Tcl::pTk) is similar (and much of the code is derived from) the Tcl::Tk package, maintained by Vadim Konovalov. However it differs from the Tcl::Tk package in some important ways:

  • Emphasis is on 100% compatibility with existing perl/tk syntax.

    For developers with a perl/Tk background and an existing perl/Tk codebase to support. For perl/Tk developers looking to take advantage of the look/feel updates in Tcl/Tk 8.5 and above.

  • Emphasis is on a lightweight interface to Tcl/Tk with syntax similar to (but not exactly like) perl/tk.

    For developers with some perl/Tk background, writing new code, but no existing perl/Tk codebase to support.

Creating a Tcl interpreter for Tk

Before you start using widgets, an interpreter (at least one) should be created, which will manage all things in Tcl. Creating an interpreter is created automatically by the call to the MainWindow (or tkinit) methods, but can also be created explicitly.

Example showing perl/Tk compatible syntax: For perl/tk syntax, the interpreter is created for you when you create the mainwindow.

Example showing explicit creation of an interpreter using Tcl::pTk:

Optionally a DISPLAY argument can be specified: my $int = new Tcl::pTk(':5');. This creates a Tcl interpreter object $int, and creates a main toplevel window. The window is created on display DISPLAY (defaulting to the display named in the DISPLAY environment variable)

Entering the main event loop

Perl/Tk compatible syntax:

Tcl::pTk Syntax:

Creating and using widgets

Two different approaches are used to manipulate widgets (or to manipulate any Tcl objects that act similarly to widgets).

  • Perl/Tk compatible-syntax approach. i.e. $widget->method syntax.

  • Direct access using Eval-ed Tcl code. (e.g. using the Eval Tcl::pTk method)

The first way to manipulate widgets is identical to the perl/Tk calling conventions, the second one uses Tcl syntax. Both ways are interchangeable in that a widget created with one way can be used the another way. This interchangability enables use of Tcl-code created elsewhere (e.g. by some WYSIWYG IDE).

Usually Perl programs operate with Tcl::pTk via perl/Tk syntax, so users have no need to deal with the Tcl language directly. Only some basic understanding of Tcl/Tk widgets is needed.

Tcl/Tk syntax

In order to get better understanding on usage of Tcl/Tk widgets from within Perl, a bit of Tcl/Tk knowledge is needed, so we'll start from 2nd approach, with Tcl's Eval ($int->Eval('..')) and then smoothly move to first approach with perl/Tk syntax.

  • The Tcl Interpreter

    The Tcl interpreter is used to process Tcl/Tk widgets; within Tcl::pTk you create it with new, and given any widget object, you can retrieve it by the $widget->interp method. ( Within pure Tcl/Tk the interpreter already exists, you don't need to create it explicitly. )

  • The Widget Path

    The Widget path is a string starting with a dot and consisting of several names separated by dots. These names are individual widget-names that comprise a widget's hierarchy. As an example, if there exists a frame with a path .fram, and you want to create a button on it and name it butt, then you should specify name .fram.butt. Widget paths are also referred in other miscellaneous widget operations, like geometry management.

    At any time a widget's path can be retrieved with $widget->path; within Tcl::pTk.

  • The Widget Path as a Tcl/Tk command

    When a widget is created in Tcl/Tk, a special command is created that is the name of the widget's path. For example, a button created in a frame has a path and command-name .fr.b. This command also has subcommands which manipulate the widget. That is why $int->Eval('.fr.b configure -text {new text}'); makes sense. Note that using perl/tk syntax $button->configure(-text=>'new text'); does exactly the same thing, if $button corresponds to .fr.b widget.

The use Tcl::pTk; statement not only creates the Tcl::pTk package, but also creates the Tcl::pTk::Widget package, which is responsible for widgets. Each widget ( an object blessed to Tcl::pTk::Widget, or any of its subclasses ) behaves in such a way that its method will result in calling its path on the interpreter.

Perl/Tk syntax

Tcl::pTk fully supports perl/Tk widget syntax of the Tk package, which has been used for many years. This means that any Tcl::pTk widget has a number of methods like Button, Frame, Text, Canvas and so on, and invoking those methods will create an appropriate child widget. Tcl::pTk will generate an unique path-name for a newly created widget.

To demonstrate this concept, the perl/Tk syntax:

executes the command

and this command similar to

This way Tcl::pTk widget commands are translated to Tcl syntax and directed to the Tcl interpreter. This translation that occurs from perl/Tk syntax to Tcl calls is why the two approaches for dealing with widgets are interchangeable.

The newly created widget $label will be blessed to package Tcl::pTk::Label which is isa-Tcl::pTk::Widget (i.e. Tcl::pTk::Label is a subclass of Tcl::pTk::Widget).

Tcl::pTk Widgets fall into the following basic categories, based on how they are implemented in the Tcl::pTk package.

Direct auto-wrapped widgets

These types of widgets (for example the Entry, Button, Scrollbar, and Label widgets) have no special code written for them in Tcl::pTk. Their creation and method calls (e.g. $button->configure(-text => 'ButtonText')) are handled by the wrapping code in the base Tcl::pTk::Widget package.

Auto-wrapped widgets, with compatibility code

These types of widgets are similar to the Direct auto-wraped widgets, but have additional code written to be completely compatibile with the perl/Tk syntax. Examples of this type of widget are the Text, Frame, Menu, and Menubutton widgets.

Megawidgets

These are widgets that are composed of one-or-more other base widget types. Pure-perl megawidgets are supported in Tcl::pTk, just like they are in perl/Tk. Examples of these types of widgets are ProgressBar, LabEntry, BrowseEntry, and SlideSwitch (one of the test cases in the source distribution).

Derived Widgets

Derived widgets are sub-classes of existing widgets that provide some additional functions. Derived widgets are created in Tcl::pTk using very similar syntax to perl/Tk (i.e. using the Tcl::pTk::Derived package, similar to the Tk::Derived package). Examples of these types of widgets are Tree, TextEdit, TextUndo, ROText, and DirTree.

All widgets in Tcl::pTk are objects, and have an inheritance hierarchy that derives from the Tcl::pTk::Widget parent class. Megawidgets and derived widgets are handled very similar (if not exactly) the same as in perl/tk.

Auto-wrapped widgets (like the Entry, Button, Scrollbar, etc.) are handled differently. The object system for these types of widgets is dynamic. Classes and/or methods are created when they are first used or needed.

The following describes how methods are called for the two different categories of auto-wrapped widgets

Direct auto-wrapped widget example

Here is an example of a Entry widget, a direct auto-wrapped widget:

Internally, the following mechanics come into play: The Entry method creates an Entry widget (known as entry in the Tcl/Tk environment). When this creation method is invoked the first time, a package Tcl::pTk::Entry is created, which sets up the class hierarchy for any further Entry widgets. The newly-created Tcl::pTk::Entry class is be a direct subclass of Tcl::pTk::Widget.

The second code line above calls the insert method of the $entry object. When invoked first time, a method (i.e. subref) insert is created in package Tcl::pTk::Entry, which will end-up calling calling the invoke method on the Tcl/Tk interpreter (i.e. $entry->interp()->invoke($entry, 'insert', -text, 'text')).

The first time insert is called, the insert method does not exist, so AUTOLOAD comes into play and creates the method. The second time insert is called, the already-created method is called directly (i.e. not created again), thus saving execution time.

Auto-wrapped widgets, with compatibility code

Here is an example of a Text widget, which is an auto-wrapped widget with extra code added for compatibility with the perl/tk Text widget.

Internally, following mechanics come into play: The Text method creates an Text widget (known as text in Tcl/Tk environment). Because a Tcl::pTk::Text package already exists, a new package is not created at runtime like the case above.

The second code line above calls the insert of the $text object of type Tcl::pTk::Text. This insert method is already defined in the Tcl::pTk::Text package, so it is called directly.

The third code line above calls the markNames method on the $text object. This method is not defined in the Tcl::pTk::Text package, so the first time when markNames is called, AUTOLOAD in the Tcl::pTk package comes into play and creates the method. The second time markNames is called, the already-created method is called directly (i.e. not created again), thus saving execution time.

Description of an auto-wrapped method call

Suppose $widget isa Tcl::pTk::Widget, its path is .path, and method method invoked on it with a list of parameters, @parameters:

In this case all @parameters will be preprocessed by performing the following actions:

  1. For each variable reference, a Tcl variable will be created and tied to it, so changes in the perl variable will be reflected in the Tcl variable, and changes in the Tcl variable will show up in the perl variable.

  2. For each perl code-reference, a Tcl command will be created that calls this perl code-ref.

  3. Each array reference will considered a callback, and proper actions will be taken.

After processing of @parameters, the Tcl/Tk interpreter will be requested to perform following operation:

if $method is all lowercase (e.g. insert), m/^[a-z]$/

.path method parameter1 parameter2..

if $method contains exactly one capital letter inside the method name (e.g. tagNames), m/^[a-z]+[A-Z][a-z]+$/

.path method submethod parameter1 parameter2..

if $method contains several capital letter inside the method name, methodSubmethSubsubmeth

.path method submeth subsubmeth parameter1 parameter2..

Fast method invocation for auto-wrapped widgets

If you are sure that preprocessing of @parameters in a method call aren't required (i.e. no parameters are Perl references to scalars, subroutines or arrays), then the preprocessing step described above can be skipped by calling the method with an underscore _ prepended to the name. (e.g call $text->_markNames(), instead of $text->markNames()). Calling the method this way means you are using an internal method that executes faster, but normally you should use a 'public' (i.e. non-underscore) method, which includes all preprocessing.

Example:

When doing many inserts to a text widget, the faster version can help speed things up.

In addition to the standard widgets (e.g. Entry, Button, Menu, etc), the Tcl::pTk module lets you use any other widget from the Tcl/Tk widget library. This can be done with either Tcl syntax (via the Eval method), or with regular perl/tk syntax.

To interface to a new Tcl/Tk widget using perl/tk syntax, a Declare method call is made on an already-created widget, or on the Tcl::pTk interpreter object itself.

Syntax is

or, exactly the same,

Options are:

The -require option specifies the new Tcl/Tk widget requires a Tcl package to be loaded with a name of 'tcl-package-name';

The -prefix option used to specify the prefix of the autogenerated widget path-name. This option is normally used when the Tcl/Tk widget name contains non-alphabetic characters (e.g. ':'). If not specified, the prefix will be generated from the package-name.

A typical example of using the Declare method:

After this call, Tcl::pTk will create a widget creation method for this new package to make it an auto-wrapped widget (See the definition of auto-wrapped widgets above).

This means

will create blt::tabnotebook widget. Effectively, this is equivalent to the following Tcl/Tk code:

After the above example code, the variable $tab is a Tcl::pTk::Widget that behaves in the usual way, for example:

These two lines are the Tcl/Tk equivalent of:

You can also intermix the perl/tk and Tcl/Tk syntax like this:

For the documentation of standard perl/tk widgets (like Button, Entry, Menu, etc), you can refer to the the perl/tk docs Tk (We may move a copy of the perl/tk docs to Tcl::pTk in the future). For non-standard widgets (like the BLTNotebook widget example above) you have to use the Tcl docs on the widget for the widget documentation. (Most Tcl/Tk docs can be found at http://www.tcl.tk/ )

When reading Tcl/Tk widget documentation about widgets, you can apply the following guidelines to determine how to use the widget in Tcl::pTk using perl/tk syntax.

Suppose the Tcl/Tk docs say:

This means the widget has a has method method-name and you can invoke it in Tcl::pTk like

The $widget variable in Tcl::pTk is like the pathName in the Tcl/Tk docs.

Sometimes the Tcl/Tk method-name consists of two words (verb1 verb2). In this case there are two equivalent ways to invoke it, $widget->verb1('verb2',..); or $widget->verb1Verb2(..);.

Widget options are used just like they are shown in the Tcl/Tk docs. There is no special translation needed for the widget options described in the Tcl/Tk docs for use in Tcl::pTk.

$int->widget( path, widget-type )

When widgets are created in Tcl::pTk they are stored internally and can be retrieved by the widget() method, which takes widget path as first parameter, and optionally the widget type (such as Button, or Text etc.). For Example:

Please note that this method will return to you a widget object even if it was not created within Tcl::pTk. A check is not performed to see if a widget with given path name exists. This enables the use of widgets created elsewhere in Tcl/Tk to be treated like Tcl::pTk widgets.

widget_data

If you need to associate any data with particular widget, you can do this with widget_data method of either interpreter or widget object itself. This method returns same anonymous hash and it should be used to hold any keys/values pairs.

Syntax

Examples:

Note:

Use of this method has largely been superceded by the perl/tk-compatible privateData widget method.

$widget->tooltip('text')

Any widget accepts the tooltip method, accepting any text as parameter, which will be used as floating help text explaining the widget. The widget itself is returned, so to provide convenient way of chaining:

The tooltip method uses the tooltip package, which is a part of tklib within Tcl/Tk, so be sure you have that Tcl/Tk package installed.

Note: The perl/tk-compatible Balloon widget is also available for installing tool-tips on widgets and widget-elements.

In the documentation and comments for this package, perl/Tk, Tcl/Tk, Tcl::pTk, Tcl.pm, and Tcl are used. These terms have the following meanings in the context of this package.

perl/Tk

The traditional perl interface to the Tk GUI libraries. i.e the perl package occupying the Tk namespace on CPAN.

Tcl/Tk

The Tcl/Tk package with tcl-code and associated libraries (e.g. Tcl.so or Tcl.dll and associated tcl-code). See http://www.tcl.tk/

Tcl::pTk

This package, which provides a perl interface into the Tcl/Tk GUI libraries.

Tcl.pm

The Tcl perl package, which provides a simple interface from perl to Tcl/Tk. Tcl::pTk interpreter objects are subclassed from the Tcl package.

Tcl

The Tcl programming language.

Currently work is in progress, and some features could change in future versions.

Malcolm Beattie.
Vadim Konovalov, vadim_tcltk@vkonovalov.ru 19 May 2003.
Jeff Hobbs, jeffh _a_ activestate com, February 2004.
Gisle Aas, gisle _a_ activestate . com, 14 Apr 2004.
John Cerney, john.cerney _a_ gmail . com, 29 Sep 2009.
Christopher A. Chavez, chrischavez _a_ gmx . us, May 2018.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See http://www.perl.com/perl/misc/Artistic.html

To install Tcl::pTk, simply copy and paste either of the commands in to your terminal

For more information on module installation please visit the detailed CPAN module installation guide.

TR - Tcl is good at introspection for monitoring its own execution. Tk is good at graphical user interfaces. Combining them with little more than two standard extensions, namely ctext (for syntax highlighting) and BWidget (for a tree viewer) quickly makes a nice tool for debugging. You just plug in the following code in your main programand you get a picture like the following:Although it resembles Mac OS X, this screenshot was made on Linux ..Normally you also want to create a pkgIndex.tcl file containing:The code used to create that thing is down below. It is not completely finished but you can already use it to change procedures at runtime and save the changes back to the running program or to a file. This debugger was inspired by ped.wcf3 This is really cool. I did find a minor problem when using the tDOM package. There is a ::dom::domDoc::info proc that messes up twDebug::InspectorInitNS when it runs info procs in that namespace. I modified that code to use ::info procs instead, and it works great now. -- TR Thanks for this improvement!RLH That is neat.MG This is extremely cool. The only problem I have with it is that, with my screen set to 1024x768, I was looking at a var with a very long value and found that most of it was off the screen, because the window was much bigger than my screen. Haven't looked for the problem yet (squinting too much atm to be likely to find it), though..TR Hmm, interesting. Do you mean the debugger window is bigger than your screen? I modified the code above to give a smaller window now. Will it fit then?MG I did, yes - though, looking at it closer now that I'm more awake, the problem is not with the toplevel. Even with the whole toplevel visible, the text widget appears to be larger than the area allocated to it inside the toplevel, so a large part of it just isn't visible on screen. I just clicked at the start of the first line of visible text, and kept pressing the right arrow key - after 80 keypresses, I got to the last character visible on the screen, but it took a further 83 keypresses (moving the cursor right another 83 characters, basically) before the text widget start to scroll right to make more characters visible. Even configuring the Ctext widget to be -width 1 -wrap char does not sort the problem - it wraps, but it's still far wider than the portion which shows on the screen. This is on ActiveTcl 8.4.9 (which has ctext 3.1) on Win XP SP2, by the way.TR - I was not able to reproduce this behaviour. I found a box with Win XP and SP2 now and tried to follow your description (using a freshly installed ActiveTcl 8.4.9). The widget scrolled as expected and nothing weird happend .. I am a bit confused now !?MG I've put three screenshots of it up on my website in this folder [1] . The image d1.jpg is what I get when I fire up a wish console and paste your code straight in - perfect. d2.jpg is what I get when I paste the code into the console of a particular app (it comes up terribly small), and d3.jpg is that same small window when maximised - as you can see, there's no scrollbar showing up on the right.The app I've been pasting it into (Potato MUSH (MUD) Client) doesn't alter the option database, or anything like that, so I'm not sure why it has such an adverse effect on the display of your code's window. but I just tried pasting it into another app's console (TriPeaks Solitaire, this time) and it came up perfectly. Curious..TR - OK. I think I know what might go on there. I had a look at your Potato MUSH Client and found that is uses Iwidgets. The widgets from the IWidgets set also have a panedwindow widget which shares the same class as the Tk core panedwindow. I would imagine that these two interfere in a way that makes my debugger do weird things. Have a look at this page about the iwidgets panedwindow to see what problems arise and how to probably fix them. Does this help'?MG Ahh yes, that hadn't occurred to me. I'm pretty sure you're right, and that is the problem. (That app actually deletes all the Tk bindings for the panedwindow, so they don't interfere with the IWidgets ones, which probably makes things even worse when the Tk panedwindow is used.) Thanks very much for looking into it and finding the problem :)See also Tkinspect
Category ApplicationCategory DebuggingCategory Dev. Tools