Games:...:Dg2Tk(3pm)

πŸ“¦
version 4.252 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble

πŸ’– 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 => number
  • boardSizeY => 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