NAME
Tk::LineNumberText - Line numbers for your favorite Text-derived widget
SYNOPSIS
$linenumtext = $parent->LineNumberText(?options?);
EXAMPLE
use Tk;
use Tk::LineNumberText;
my $mw=tkinit;
$mw->LineNumberText(
-widget=>'Text',
-wrap=>'word',
-font=>['Courier',12],
-bg=>'white')->pack(-fill=>'both', -expand=>1);
MainLoop;
SUPER-CLASS
The LineNumberText
class is derived from the Frame
class. However, this mega widget is comprised of a ROText
as a container for the line numbers and a Scrolled Text
widget (or any other widget derived from Tk::Text). See DESCRIPTION below for details.
By default, all methods are delegated to the Text derived widget which is created at instantiation. Therefore all the methods for the widget chosen should be accessible through LineNumberText
.
DESCRIPTION
LineNumberText is a composite widget consisting of a ROText for the linenumbers and any other derived widget from Tk::Text. It has been tested using Text, CodeText and TextEdit. Line numbers will change as text is edited either programmatically or interactively.
As stated above, all options available to any Scrolled
Text-based widget should be accessible. There are also some extra widget-specific options as defined below.
WIDGET-SPECIFIC OPTIONS
- -widget
-
Name of the Tk::Text derived widget to use (such as Text, CodeText or TextEdit). Note: This option needs to be passed as a string at creation. Do not pass a reference to an existing widget. This widget will be created at instantiation and will default to a Tk::Text if this option is not provided or if the widget chosen cannot be used. This option cannot be changed or queried using configure or cget respectively.
- -linenumfg
-
Foreground color of the line numbers.
- -linenumbg
-
Background color of the line numbers.
- -linenumside
-
Specifies which side of the widget to place the line numbers. Must be either left or right. Default is left.
- -curlinehighlight
-
Accepts a boolean value to determine whether or not to highlight the line number of the insertion cursor. Default is 1 (on).
- -curlinebg
-
Background color of the line number for the current line of the insertion cursor. Default is cyan.
- -curlinefg
-
Foreground color of the line number for the current line of the insertion cursor. Default is black.
WIDGET METHODS
As stated above, all methods default to the Text-derived widget. Otherwise currently only two extra methods exist.
- showlinenum
-
Shows (Ie. grid) the linenumber widget.
- hidelinenum
-
Hides (Ie. gridForget) the linenumber widget.
ADVERTISED WIDGETS
The following widgets are advertised:
- scrolled
-
The text or text-derived widget.
- text
-
The text or text-derived widget. (Same as scrolled above)
- frame
-
The frame containing the scrollbars and text widget (As per the Tk::Scrolled method)
- yscrollbar
-
The Scrollbar widget using for vertical scrolling (if it exists)
- xscrollbar
-
The Scrollbar widget using for horizontal scrolling (if it exists)
- corner
-
A frame in the corner between the vertical and horizontal scrollbars
- linenum
-
The ROText widget used for the line numbers.
BUGS
There will always be a line number on the first display line. Even if the text could actually be wrapped from a line which is off screen. I did this to ensure that at least one line number is shown at all times. I am considering this a beta-release until I receive some feedback.
TO DO
As suggested by Dean Arnold - I had all intentions of adding availability of images on the line number margin, however it isn't as simple as I first thought. So, time and effort have held me back from completing this. I wanted to get something on CPAN early. So I would like to get some feedback on the approach I have taken.
Since all the widgets are advertised, you can feel free to sub-class or just add your own bindings. I have intentionally left one character at the end of each line number so images can be include using imageCreate from Tk::Text.
AUTHOR
Jack Dunnigan dunniganj@cpan.org
This code was inspired by ctext.tcl written by George Staplin. This may be distributed under the same conditions as Perl.