+ try:
+ # down word set the clue if found
+ dword, drow, dcol, dlen = self.puzzle.get_word_down (row, col)
+ sys.stdout.write (self.BLUE + "Down word at position: " + dword + "\n" + self.ENDCOL)
+ clue = raw_input (self.BRICKRED + "Clue for down word: " + self.ENDCOL)
+ if clue:
+ self.puzzle.data[drow][dcol].clue_down = clue
+ sys.stdout.write (self.BLUE + "Set clue: \n" + self.puzzle.data[drow][dcol].clue_down)
+ except crosswordpuzzle.NoWordException:
+ sys.stderr.write ("No down word found at that position\n")
+
+ # add a word to the puzzle
+ def on_add_word (self, across=True):
+ # first display the grid
+ self.print_puzzle ()
+ # get the row and column
+ srow = raw_input (self.BRICKRED + "Start row: " + self.ENDCOL)
+ scol = raw_input (self.BRICKRED + "Start col: " + self.ENDCOL)
+ # try converting it to number
+ try:
+ row = int (srow)
+ col = int (scol)
+ except ValueError:
+ sys.stderr.write ("Invalid row or column\n")
+ return
+ # get the word
+ word = raw_input (self.BRICKRED + "Word: " + self.ENDCOL)
+
+ # try to add the word to the puzzle grid
+ try:
+ if across == True:
+ self.puzzle.set_word_across (row, col, word)
+ else:
+ self.puzzle.set_word_down (row, col, word)
+ except crosswordpuzzle.TooLongWordException:
+ sys.stderr.write ("Word is too long to fit in the grid! Aborting.\n")
+ except crosswordpuzzle.IntersectWordException:
+ sys.stderr.write ("Word intersects badly with another word!\n")
+ except crosswordpuzzle.FrozenGridException:
+ sys.stderr.write ("Word cannot be added to a frozen puzzle.\n")
+
+ # Export to image/HTML
+ def on_export_image (self, solution=True):
+ try:
+ sys.stdout.write (self.BLUE + "Exporting puzzle to image/HTML\n")
+ pngfile = raw_input (self.BRICKRED + "Filename (PNG): " + self.ENDCOL)
+ if solution is False:
+ htmlfile = raw_input (self.BRICKRED + "Filename (HTML): " +
+ self.ENDCOL)
+ puztitle = raw_input (self.BRICKRED + "Title of puzzle: " +
+ self.ENDCOL)
+ self.puzzle.export_image (pngfile, htmlfile, puztitle, solution)
+ else:
+ self.puzzle.export_image (pngfile)
+
+ sys.stdout.write (self.BLUE + "Successfully exported!")
+ except crosswordpuzzle.FrozenGridException:
+ sys.stderr.write ("Cannot export as grid is not frozen/finalized\n")
+ except crosswordpuzzle.NoWordsException:
+ sys.stderr.write ("No words to export!\n")
+
+ # Export to across lite
+ def on_export_acrosslite (self):
+ try:
+ sys.stdout.write (self.BLUE + "Exporting to AcrossLite(tm) Format\n" +
+ self.ENDCOL)
+ title = raw_input (self.BRICKRED + "Puzzle title: " + self.ENDCOL)
+ name = raw_input (self.BRICKRED + "Author name: " + self.ENDCOL)
+ copyright = raw_input (self.BRICKRED + "Copyright: " + self.ENDCOL)
+ exportfile = raw_input (self.BRICKRED + "Export to file: " + self.ENDCOL)
+
+ acrosslite_str = self.puzzle.export_acrosslite (title, name, copyright)
+ fexport = open (exportfile, "w")
+ fexport.write (acrosslite_str)
+ fexport.close ()
+ sys.stdout.write (self.BLUE + "Exported AcrossLite(tm) File: " +
+ exportfile + "\n" + self.ENDCOL)
+ except crosswordpuzzle.FrozenGridException:
+ sys.stderr.write ("Cannot export as grid is not frozen/finalized\n")
+ except crosswordpuzzle.NoWordsException:
+ sys.stderr.write ("No words to export!\n")