Games:...:Dg2Tk(3pm)
π Games:...:Dg2Tk β the perl/Tk glow-up page π
okay so bestie, welcome to Games:...:Dg2Tk(3pm), part of the User Contributed Perl Documentation situation. it's a Perl module, it lives in the Games::Go::Sgf2Dg family, and it is literally here to turn your Games::Go::Sgf2Dg::Diagram objects into perl/Tk windows. yes. windows. plural. slay. β¨
π NAME π
Games::Go::Sgf2Dg::Dg2Tk β convert Games::Go::Sgf2Dg::Diagrams to perl/Tk windows π¦
β¨ SYNOPSIS β¨
use Games::Go::Sgf2Dg::Dg2Tk
my $dg2tk = B<Games::Go::Sgf2Dg::Dg2Tk-E<gt>new> (options);
my $canvas = $dg2tk->convertDiagram($diagram);
π DESCRIPTION π
so a Games::Go::Sgf2Dg::Dg2Tk object takes a Games::Go::Sgf2Dg::Diagram object and converts it into a Tk::Canvas item. that's the whole gig, and it ate. π₯
the close method calls Tk::MainLoop to dispays the collection of Canvases. (yes, "dispays". we keep the original spelling, no cap. π)
now, the bindings, because you will be keyboard-pilled:
- the normal editing keys: Up, Down, Next (
PageDown) and Prior (PageUp) traverse the NoteBook tabs. π§ - Tab and Shift-tab also work as expected. iconic behaviour, truly.
- 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. there you go, now it's visible. π
πΈ NEW πΈ
my $dg2tk = Games::Go::Sgf2Dg::Dg2Tk->new (?options?)
any options you pass to Dg2Tk that it does not recognize get passed in turn to the Tk::Canvas widgets as they're created. lowkey a plot twist: this may cause errors if Tk::Canvas also doesn't recognize them. so like, vibe check your options first. π
a new Games::Go::Sgf2Dg::Dg2Tk takes the following options:
boardSizeX => numberboardSizeY => 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. periodt.
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. it's giving crop tool. βοΈ
diaCoords => sub { # convert $x, $y to Games::Go::Sgf2Dg::Diagram coordinates }
this callback defines a subroutine to convert coordinates from $x, $y to whatever coordinates are used in the Games::Go::Sgf2Dg::Diagram object. the default diaCoords converts 1-based $x, $y to 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
see also the diaCoords method below. π«Ά
π¦ METHODS π¦
$dg2tk->configure (option => value, ?...?)
change Dg2Tk options from values passed at new time. glow-up your settings mid-flight, bestie. β¨
my $coord = $dg2mp->diaCoords ($x, $y)
provides access to the diaCoords option (see above). returns coordinates in the converter's coordinate system for board coordinates ($x, $y). for example, to get a specific intersection structure:
my $int = $diagram->get($dg2mp->diaCoords(3, 4));
$dg2tk->print ($text ? , ... ?)
for most Dg2 converters, print inserts diagram source code (TeX, ASCII, whatever) directly into the diagram source stream. since Tk displays the diagrams immediately, there is no concept of a source stream, so print just generates a warning. β οΈ not me expecting output and getting a warning instead π
$dg2tk->printComment ($text ? , ... ?)
adds $text to the diagram comments. π¬
$dg2tk->comment ($comment ? , ... ?)
for most Dg2 converters, comment inserts comments into the diagram source code (TeX, ASCII, whatever). since Tk displays the diagrams immediately, there is no concept of a source stream, so comment does nothing. literally does nothing. it's a decorative method. π
my $canvas = $dg2tk->convertDiagram ($diagram)
converts a Games::Go::Sgf2Dg::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 close time). the main character method, fr fr. π
my $converted_text = $dg2tk->convertText ($text)
converts $text into 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. π
$dg2tk->close
prints any final text to the diagram (currently none) and closes the dg2tk object. also closes file if appropriate. the goodbye moment. π₯Ί
$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');
yes you have to go one level deeper. iykyk. π³οΈ
π SEE ALSO π
sgf2dg(1)β Script to convert SGF format files to Go diagrams
π BUGS π
We ain't got to show you no stinkin' bugs!
and that's the whole page, bestie. not a single stinkin' bug to be found. π
okay so this was perl v5.30.0, dated 2019-10-27, and it's the Games:...:Dg2Tk(3pm) page. thank you for coming to my ted talk. go make some Go diagrams. mwah. πβ¨π
π¦ where this page comes from
- debian bookworm: sgf2dg 4.252-1
- debian trixie: sgf2dg 4.252-1
- ubuntu jammy: sgf2dg 4.252-1
- ubuntu noble: sgf2dg 4.252-1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms