Games::Go::Dg2Tk3pm
Perl extension to convert games::go::diagrams to perl/tk windows.
Usage
use Games::Go::Dg2Tk
my $dg2tk = B<Games::Go::Dg2Tk-E<gt>new> (options);my $canvas = $dg2tk->convertDiagram($diagram);
Overview
A Games::Go::Dg2Tk object converts a Games::Go::Diagram object into Tk::Canvas item. The close method calls Tk::MainLoop to dispays the collection of Canvases.
Bindings for the normal editing keys: Up, Down, Next (PageDown) and Prior (PageUp) traverse the NoteBook tabs. Tab and Shift-tab also work as expected.
Left and Right keys select the previous or next NoteBook tab, but don't display it. Space and Enter (carriage return) display the selected tab.
Methods
- my $dg2tk =
Games::Go::Dg2Tk->new(?options?) -
Any options passed to Dg2Tk that are not recognized are passed in turn to the Tk::Canvas widgets as they are created (which may cause errors if Tk::Canvas also does not recognize them).
A
newGames::Go::Dg2Tk takes the following options:
General Dg2 Converter Options:
boardSize=> number-
Sets the size of the board.
Default: 19
doubleDigits=> true | false-
Numbers on stones are wrapped back to 1 after they reach 100. Numbers associated with comments and diagram titles are not affected.
Default: false
coords=> true | false-
Generates a coordinate grid.
Default: false
topLine=> number (Default: 1)
bottomLine=> number (Default: 19)
leftLine=> number (Default: 1)
rightLine=> number (Default: 19)-
The edges of the board that should be displayed. Any portion of the board that extends beyond these numbers is not included in the output.
diaCoords=> sub { # convert $x, $y to Games::Go::Diagram coordinates }-
This callback defines a subroutine to convert coordinates from
$x,$yto whatever coordinates are used in the Games::Go::Diagram object. The defaultdiaCoordsconverts 1-based$x,$yto the same coordinates used in SGF format files. You only need to define this if you're using a different coordinate system in the Diagram.Default:
sub { my ($x,$y) =@_;
$x= chr($x - 1 + ord('a')); # convert 1 to 'a', etc
$y= chr($y - 1 + ord('a'));
return("$x$y"); }, # concatenate two letters
- $dg2tk->
configure(option => value, ?...?) -
Change Dg2Tk options from values passed at
newtime.
- $dg2tk->
print($text ? , ... ?) -
For most Dg2 converters,
printinserts diagram source code (TeX, ASCII, whatever) directly into the diagram source stream. Since Tk diplays the diagrams immediately, there is no concept of a source stream, soprintjust generates a warning.
- $dg2tk->
printComment($text ? , ... ?) -
Adds
$textto the diagram comments.
- $dg2tk->
comment($comment ? , ... ?) -
For most Dg2 converters,
commentinserts comments into the diagram source code (TeX, ASCII, whatever). Since Tk diplays the diagrams immediately, there is no concept of a source stream, socommentdoes nothing.
- my $canvas = $dg2tk->
convertDiagram($diagram) -
Converts a Games::Go::Diagram into a Tk::Canvas widget. Returns a reference to the Canvas. The Canvas is also added to the Tk::NoteBook collection of diagrams that are displayed (at
closetime).
- my $converted_text = $dg2tk->
convertText($text) -
Converts
$textinto text for display - gee, that's not very hard. In fact, this method simply returns whatever is passed to it. This is really just a place-holder for more complicated converters.Returns the converted text.
- $title = $dg2tk->
convertProperties(\%sgfHash) -
convertPropertiestakes a reference to a hash of properties as extracted from an SGF file. Each hash key is a property ID and the hash value is a reference to an array of property values:$hash->{propertyId}->[values]. The following SGF properties are recognized:- GN GameName
- EV EVent
- RO ROund
- PW PlayerWhite
- WR WhiteRank
- PB PlayerBlack
- BR BlackRank
- DT DaTe
- PC PlaCe
- GC GameComment
- KM KoMi
- RE REsult
- TM TiMe
Both long and short property names are recognized, and all unrecognized properties are ignored with no warnings. Note that these properties are all intended as game-level notations.
- $dg2tk->
close -
prints any final text to the diagram (currently none) and closes the dg2tk object. Also closesfileif appropriate.
- $dg2tk->
notebook -
Returns a reference to the notebook of Tk::Canvas objects.
- $dg2tk->
diagrams -
Returns a reference to the list of Tk::Canvas objects that make up the Tk::NoteBook of diagrams. Note that each item in the list is actually a Tk::Scrolled object, the actual Tk::Canvas object is:
my $canvas = $dg2tk->diagrams->[$idx]->Subwidget('scrolled');
Copyright and license
Copyright (C) 2005 by Reid Augustin
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.5 or, at your option, any later version of Perl 5 you may have available.
Releases
7 releases since Debian 4.0 (Etch); the text changed 3 times.