00be0832db42fd02fad757ad9cd8a4e08466406f
1 # Get A Clue (C) 2010 V. Harishankar
2 # Crossword puzzle maker program
3 # Licensed under the GNU GPL v3
5 # Main window class for GetAClue player
12 import crosswordpuzzle
15 def gtk_main_quit (self
, *args
):
18 # drawing for puzzle grid
19 def on_puzzlegrid_expose_event (self
, drawarea
, event
):
23 drawarea
.set_size_request (self
.puzzle
.cols
*30+2, self
.puzzle
.rows
*30+2)
25 # set background color to white
26 col
= drawarea
.window
.get_colormap ().alloc_color (gtk
.gdk
.Color ("white"))
27 drawarea
.window
.set_background (col
)
29 #numlayout = gtk.PrintContext().create_pango_layout ()
30 #numlayout.set_font_description (pango.FontDescription ("Sans 8"))
31 ctx
= drawarea
.window
.cairo_create ()
32 ctx
.set_line_width (1.5)
34 for row
in range (self
.puzzle
.rows
):
35 for col
in range (self
.puzzle
.cols
):
36 # if the area is not occupied
37 if (self
.puzzle
.data
[row
][col
].occupied_across
is False and
38 self
.puzzle
.data
[row
][col
].occupied_down
is False):
39 ctx
.rectangle (col
*30, row
*30, 30, 30)
42 ctx
.rectangle (col
*30, row
*30, 30, 30)
45 if self
.puzzle
.data
[row
][col
].numbered
<> 0:
46 ctx
.select_font_face ("Sans 7")
47 ctx
.move_to (col
*30+2, row
*30+10)
48 ctx
.show_text (str(self
.puzzle
.data
[row
][col
].numbered
))
52 def load_clues (self
):
53 # get the clues list store objects
54 across
= self
.ui
.get_object ("clues_across")
55 down
= self
.ui
.get_object ("clues_down")
61 clues_across
= self
.puzzle
.get_clues_across ()
62 clues_down
= self
.puzzle
.get_clues_down ()
63 # insert the numbers and the clues for across
64 for word
, clue
in clues_across
:
65 across
.append ([str(self
.puzzle
.data
[word
[1]][word
[2]].numbered
),
67 # insert the numbers and the clues for down
68 for word
, clue
in clues_down
:
69 down
.append ([ str(self
.puzzle
.data
[word
[1]][word
[2]].numbered
),
72 def open_file (self
, file):
73 self
.puzzle
= cPickle
.load (open (file, "rb"))
74 self
.window
.set_title ("GetAClue player - " + file)
77 def __init__ (self
, file_to_play
= None):
78 # load the user interface
79 self
.ui
= gtk
.Builder ()
80 self
.ui
.add_from_file ("playerwindow.glade")
83 self
.window
= self
.ui
.get_object ("mainwindow")
86 # set the cell renderer
87 cell
= gtk
.CellRendererText ()
88 tree_acol1
= self
.ui
.get_object ("tree_clues_across").get_column (0)
89 tree_acol2
= self
.ui
.get_object ("tree_clues_across").get_column (1)
90 tree_acol1
.pack_start (cell
)
91 tree_acol1
.add_attribute (cell
, "text", 0)
92 tree_acol2
.pack_start (cell
)
93 tree_acol2
.add_attribute (cell
, "text", 1)
95 tree_down
= self
.ui
.get_object ("tree_clues_down")
96 tree_dcol1
= self
.ui
.get_object ("tree_clues_down").get_column (0)
97 tree_dcol2
= self
.ui
.get_object ("tree_clues_down").get_column (1)
98 tree_dcol1
.pack_start (cell
)
99 tree_dcol1
.add_attribute (cell
, "text", 0)
100 tree_dcol2
.pack_start (cell
)
101 tree_dcol2
.add_attribute (cell
, "text", 1)
103 # connect the signals
104 self
.ui
.connect_signals (self
)
106 # set the puzzle to None
109 # open the file if it is set
111 self
.open_file (file_to_play
)