# TTTLetter class
"""Implements the functionality of a letter in Boggle."""

from graphics import *

class TTTLetter:
    """A TTT letter has several attributes that define it:
           *  _row, _col coordinates indicate its position in the grid (ints)
           *  _textObj denotes the Text object from the graphics module,
              which has attributes such as size, style, color, etc
              and supports methods such as getText(), setText() etc.
    """

    __slots__ = ['_row', '_col', '_textObj']

    def __init__(self, win, col=-1, row=-1, letter=""):

        # global variables needed for graphical testing
        xInset = 50; yInset = 50; size = 50

        # set row and column attributes
        self._col = col
        self._row = row

        self._textObj = Text(Point(xInset + size * col + size / 2,
                                  yInset + size * row + size / 2), letter)

        self._textObj.setSize(20)
        self._textObj.setStyle("bold")
        self._textObj.setTextColor("black")
        self._textObj.draw(win)

    def getLetter(self):
        """Returns letter (text of type str) associated with property textObj"""
        return self._textObj.getText()

    def setLetter(self, char):
        self._textObj.setText(char)

    def __str__(self):
        l, col, row = self.getLetter(), self._col, self._row
        return "{} at Board position ({}, {})".format(l, col, row)

    def __repr__(self):
        return str(self)

if __name__ == "__main__":
    win = GraphWin("Tic Tac Toe", 400, 400)

    letter = TTTLetter(win, 1, 1, "X")
    letter2 = TTTLetter(win, 1, 2, "O")
    letter3 = TTTLetter(win, 2, 1, "X")

    letter2.setLetter("T")
    print(letter2)

    # pause and wait for mouse click
    point = win.getMouse()
