puzzle
index
/home/jonny/Documents/python workspace/wordsearch_v2/src/puzzle.py

Copyright 2009 Jonny Jones and Ieuan Jones
 
    This file is part of FindThatWord.
 
    FindThatWord is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

 
Modules
       
cairo
copy
gobject
gtk
math
pango
pangocairo
random
string

 
Classes
       
__builtin__.object
Grid
Puzzle
Word

 
class Grid(__builtin__.object)
    letter grid in worsdearch puzzle
 
  Methods defined here:
__init__(self, puzzle)
x, y are the dimensions of the grid.  If y isn't supplied, a square grid is assumed
add_padding(self)
populate the empty cells in the grid with a hidden message
clear(self)
Clear the grid
draw_as_cairo(self, surface, start_x, start_y, size_x, size_y, show_solution, selected_word, max_cell_size)
Renders the grid onto a cairo surface.
Returns the font size used and the actual grid height
get_cell(self, x, y, result_type='words')
Return the content of reference (x,y).
result_type indicates the type of content to return:
    words = words placed in the grid
    padding = padding letters
    both = both types of content
get_grid_size(self)
get_padding_text(self)
Return the hidden message to be used for blank cells
set_cell(self, x, y, letter)
set_grid_size(self, x, y)

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class Puzzle(__builtin__.object)
    wordsearch puzzle
 
  Methods defined here:
__init__(self)
add_word(self, name, description=None)
add an individual word to the puzzle
clear_wordlist(self)
Clear the location of all words from the puzzle
delete_word(self, word_id)
Removes the word with an index of word_id
draw_as_cairo(self, surface, start_x, start_y, size_x, size_y, dpi, show_solution=True, selected_word=None, show_title=True, show_grid=True, show_words=True)
Draws the entire puzzle onto the Cairo surface.  dpi specifies the number of pixels per inch
draw_as_text(self, show_solution, show_title, show_grid, show_words)
Returns puzzle as a string for subsequent export
get_is_forced_size(self)
get_narrative(self)
get_optimum_size(self)
Returns the ideal grid size for the words in the puzzle
get_title(self)
get_word(self, word_id)
Returns the word object with position in list given by word_id
get_word_count(self)
get_wordlist(self)
Returns the puzzle's wordlist
move_word_up(self, word_id)
Moves the word with an index of word_id up one place
populate_grid(self)
Place all words on the puzzle grid.  Returns True if ssuccessful
resize_and_rebuild(self)
A word has changed.  Recalculate everything.  Returns false if all words not placed
resize_grid(self)
Resize the grid and place all the words in it
set_is_forced_size(self, is_forced_size)
set_narrative(self, narrative)
set_title(self, title)
sort_wordlist(self)
Sorts the word list alphabetically

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class Word(__builtin__.object)
    word in puzzle
 
  Methods defined here:
__init__(self, puzzle, word, clue=None)
puzzle is the puzzle to which the word is belongs
word is the word text displayed to the user
clue is optionally the word as it appears in the word list
clear(self)
clear the word's location
draw(self)
draws the word in the puzzle's grid.  This method does not update
the puzzle's hidden message
get_clue(self)
get_coordinates(self)
get_direction(self)
get_length(self)
get_possible_locations(self)
return a list of possible locations and directions where the word would
fit if the grid were empty
get_word(self)
get_word_alpha(self)
place(self)
find a free location in the grid and draw the word
Returns True if successful
set_coordinates(self, x=None, y=None)
set_direction(self, x=None, y=None)
test_draw(self)
checks whether the word will fit in the puzzle's grid
update(self, new_word, new_clue)
Change the word and / or description

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
Functions
       
to_alpha(text)
Remove non-aphabetic characters and switch to lower case

 
Data
        BG_COLOUR = (1, 1, 1)
GRID_COLOUR = (0.5, 0.5, 0.5)
PADDING_COLOUR = (0, 0, 0)
SELECTED_COLOUR = (0.5, 0.0, 0.75, 0.59999999999999998)
WORD_COLOUR = (0.75, 0.0, 0.0, 0.29999999999999999)