+ # drawing for puzzle grid
+ def on_puzzlegrid_expose_event (self, drawarea, event):
+ # if puzzle is loaded
+ if self.puzzle:
+ # size the area
+ drawarea.set_size_request (self.puzzle.cols*30+2, self.puzzle.rows*30+2)
+
+ # set background color to white
+ col = drawarea.window.get_colormap ().alloc_color (gtk.gdk.Color ("white"))
+ drawarea.window.set_background (col)
+
+ #numlayout = gtk.PrintContext().create_pango_layout ()
+ #numlayout.set_font_description (pango.FontDescription ("Sans 8"))
+ ctx = drawarea.window.cairo_create ()
+ ctx.set_line_width (1.5)
+
+ for row in range (self.puzzle.rows):
+ for col in range (self.puzzle.cols):
+ # if the area is not occupied
+ if (self.puzzle.data[row][col].occupied_across is False and
+ self.puzzle.data[row][col].occupied_down is False):
+ ctx.rectangle (col*30, row*30, 30, 30)
+ ctx.fill ()
+ else:
+ ctx.rectangle (col*30, row*30, 30, 30)
+ ctx.stroke ()
+ # if numbered
+ if self.puzzle.data[row][col].numbered <> 0:
+ ctx.select_font_face ("Sans 7")
+ ctx.move_to (col*30+2, row*30+10)
+ ctx.show_text (str(self.puzzle.data[row][col].numbered))
+
+ return False
+
+ def load_clues (self):
+ # get the clues list store objects
+ across = self.ui.get_object ("clues_across")
+ down = self.ui.get_object ("clues_down")
+ across.clear ()
+ down.clear ()
+
+ # if puzzle is loaded
+ if self.puzzle:
+ clues_across = self.puzzle.get_clues_across ()
+ clues_down = self.puzzle.get_clues_down ()
+ # insert the numbers and the clues for across
+ for word, clue in clues_across:
+ across.append ([str(self.puzzle.data[word[1]][word[2]].numbered),
+ clue])
+ # insert the numbers and the clues for down
+ for word, clue in clues_down:
+ down.append ([ str(self.puzzle.data[word[1]][word[2]].numbered),
+ clue])
+
+ def open_file (self, file):
+ self.puzzle = cPickle.load (open (file, "rb"))
+ self.window.set_title ("GetAClue player - " + file)
+ self.load_clues ()
+