Package sudoku :: Module sudoku_GUI :: Class SudokuGUI
[hide private]
[frames] | no frames]

Class SudokuGUI

object --+
         |
        SudokuGUI

This class contains the user interface for the Sudoku game program.

Instance Methods [hide private]
 
__init__(self, chart)
Creates and makes visible a new frame, which displays the given sudoku chart.
 
create_components(self)
Creates components for the GUI's application frame.
 
number_entered(self, event)
Event handler method: reacts to the user signaling that new text has been entered to a text field by reading whatever is in the field and updating the model accordingly.
 
input_received(self, field)
Examines the contents of the given text field and tries to update the game model (the Sudoku chart) and lock the field (set it as uneditable).
int
read_input(self, field)
Parses the contents of the given text field as an integer that is to be stored in a Sudoku cell.
int
try_to_set_number(self, row, column, new_number)
Tries to update the game model (the Sudoku chart) by filling the cell at the given position with the given number.

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, chart)
(Constructor)

 

Creates and makes visible a new frame, which displays the given sudoku chart.

Parameters:
  • chart (chart object) - a sudoku grid to be displayed in a frame
Overrides: object.__init__

number_entered(self, event)

 

Event handler method: reacts to the user signaling that new text has been entered to a text field by reading whatever is in the field and updating the model accordingly.

Parameters:
  • event (event object) - the event that contains the widget whose contents should be examined

input_received(self, field)

 

Examines the contents of the given text field and tries to update the game model (the Sudoku chart) and lock the field (set it as uneditable). If the input is not parseable, clears the field instead. If a mistake was made by the user (new number violates Sudoku rules), the method causes the program to exit.

Parameters:
  • field (widget object) - the field that should be read

read_input(self, field)

 

Parses the contents of the given text field as an integer that is to be stored in a Sudoku cell.

Parameters:
  • field (widget object) - the field that should be read
Returns: int
the integer input read from the field, or zero if the input is not parseable or not between 0 and chart size - 1

try_to_set_number(self, row, column, new_number)

 

Tries to update the game model (the Sudoku chart) by filling the cell at the given position with the given number. If the indicated cell is not empty to begin with, the method does nothing. If the number placement violates Sudoku rules, the method causes the program to exit.

Parameters:
  • row (int) - a row index (between 0 and chart size - 1)
  • column (int) - a column index (between 0 and chart size - 1)
  • new_number - a number to place in the indicated cell
Returns: int