Reset grid functionality implemented
[getaclue.git] / crosswordpuzzlecreator.py
index 1816ff6..1e62315 100644 (file)
@@ -146,9 +146,8 @@ class CrosswordPuzzleCreator:
                        aword, arow, acol, alen = self.puzzle.get_word_across (row, col)
                        sys.stdout.write (self.BLUE + "Across word at position: " + aword + "\n" + self.ENDCOL)
                        clue = raw_input (self.BRICKRED + "Clue for across word: " + self.ENDCOL)
-                       if clue:
-                               self.puzzle.data[arow][acol].clue_across = clue
-                               sys.stdout.write (self.BLUE + "Set clue: \n" + self.puzzle.data[arow][acol].clue_across)
+                       self.puzzle.data[arow][acol].clue_across = clue
+                       sys.stdout.write (self.BLUE + "Set the clue: \n" + self.puzzle.data[arow][acol].clue_across)
                except crosswordpuzzle.NoWordException:
                        sys.stderr.write ("No across word found at that position\n")
 
@@ -157,9 +156,8 @@ class CrosswordPuzzleCreator:
                        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)
+                       self.puzzle.data[drow][dcol].clue_down = clue
+                       sys.stdout.write (self.BLUE + "Set the clue: \n" + self.puzzle.data[drow][dcol].clue_down)
                except crosswordpuzzle.NoWordException:
                        sys.stderr.write ("No down word found at that position\n")
 
@@ -194,17 +192,24 @@ class CrosswordPuzzleCreator:
                        sys.stderr.write ("Word cannot be added to a frozen puzzle.\n")
 
        # Export to image/HTML
-       def on_export_image (self, solution=False):
+       def on_export_image (self, solution=True):
                try:
                        sys.stdout.write (self.BLUE + "Exporting puzzle to image/HTML\n")
-                       filename = raw_input (self.BRICKRED + "Filename (PNG): " + self.ENDCOL)
-
-                       self.puzzle.export_image (filename, solution)
-                       sys.stdout.write (self.BLUE + "Successfully exported to file: " +
-                                                       filename + "\n" + self.ENDCOL)
+                       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")
+                       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):
@@ -244,6 +249,7 @@ class CrosswordPuzzleCreator:
                                sys.stdout.write ("7. Unfreeze grid\n")
                                sys.stdout.write ("8. Set clue for word\n")
                                sys.stdout.write ("9. Display clues\n")
+                               sys.stdout.write ("R. Reset grid\n")
                                sys.stdout.write ("S. Save puzzle\n")
                                sys.stdout.write ("E. Export to AcrossLite(TM) format\n")
                                sys.stdout.write ("H. Export puzzle as image/HTML\n")
@@ -264,14 +270,16 @@ class CrosswordPuzzleCreator:
                                        self.on_set_clue ()
                                elif ch == "9":
                                        self.on_display_clues ()
+                               elif ch == "R" or ch == "r":
+                                       self.on_reset_grid ()
                                elif ch == "S" or ch == "s":
                                        self.save_puzzle ()
                                elif ch == "E" or ch == "e":
                                        self.on_export_acrosslite ()
                                elif ch == "H" or ch == "h":
-                                       self.on_export_image ()
+                                       self.on_export_image (False)
                                elif ch == "I" or ch == "i":
-                                       self.on_export_image (True)
+                                       self.on_export_image ()
                                elif ch == "X" or ch == "x":
                                        break
 
@@ -297,6 +305,15 @@ class CrosswordPuzzleCreator:
                self.load_puzzle ()
                self.do_puzzle_loop ()
 
+       # when user chooses to reset grid
+       def on_reset_grid (self):
+               ans = raw_input (self.BRICKRED +
+                       "This will clear the entire grid! Are you sure (Y/N)? " + self.ENDCOL)
+               if ans == "y" or ans == "Y":
+                       self.puzzle.reset_grid ()
+                       sys.stdout.write (self.BLUE + "Grid has been cleared of all data!"
+                                               + self.ENDCOL + "\n")
+
        # Main application loop
        def do_main_loop (self):
                # display the menu