Export as image functionality halfway done
[getaclue.git] / crosswordpuzzlecreator.py
index 710de09..1816ff6 100644 (file)
@@ -193,6 +193,19 @@ class CrosswordPuzzleCreator:
                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=False):
+               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)
+
+               except crosswordpuzzle.FrozenGridException:
+                       sys.stderr.write ("Cannot export as grid is not frozen/finalized")
+
        # Export to across lite
        def on_export_acrosslite (self):
                try:
@@ -233,6 +246,8 @@ class CrosswordPuzzleCreator:
                                sys.stdout.write ("9. Display clues\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")
+                               sys.stdout.write ("I. Export solution as image\n")
                                sys.stdout.write ("X. Exit to main menu\n" + self.ENDCOL)
                                ch = raw_input (self.BRICKRED + "Your choice: " + self.ENDCOL)
                                if ch == "1":
@@ -253,6 +268,10 @@ class CrosswordPuzzleCreator:
                                        self.save_puzzle ()
                                elif ch == "E" or ch == "e":
                                        self.on_export_acrosslite ()
+                               elif ch == "H" or ch == "h":
+                                       self.on_export_image ()
+                               elif ch == "I" or ch == "i":
+                                       self.on_export_image (True)
                                elif ch == "X" or ch == "x":
                                        break