COMP 304B Object-Oriented Software Design -- Assignment 1

COMP 304B Object-Oriented Software Design - Assignment 1

Practical information

Goals

This assignment will make you familiar with unit testing and object-oriented GUI programming in Python/Tkinter.

Your assignment should clearly present:

  1. The tests corresponding to the requirements listed below.
  2. An implementation of the requirements given below. This mostly consists of implementing methods of the class SpreadsheetGridView
  3. The results of the tests on your implementation.

Upload all source and result files to WebCT and provide links to them from your index.html file.

Requirements

The ultimate goal is to build a fully functional spreadsheet application. Such an application needs a GUI and that is the focus of this assignment. In a later assignment, using the ``Observer Design Pattern'', we will construct a system with keeps the data in the spreadsheet in a single place (the subject), with multiple observers showing views of that data (and updating whenever the subject changes). In this assignment, you need to complete and develop a unittest suite for the SpreadsheetGridView class in the file SSGridView_start.py. SpreadsheetGridView will contain the static as well as dynamic description of a single observer. An instantance of SpreadsheetGridView with for example
 rows=4
 columns=8
 cellHeight=18
 cellWidth=50
 padHor=10
 padVer=20
looks like

The static aspects of SpreadsheetGridView

The static aspects of SpreadsheetGridView are provided in the file SSGridView_start.py. You must add the dynamics.

The window contains a button "Print View" which will bring up a file selection dialog. It allows for the generation of a Postscript file containing the spreadsheet image.

The "Quit View" button will close the window (as will the "X" in the right hand corner of the window - this event is caught by the Window Manager and passed on to the application).

The canvas on which the spreadsheet grid appears can be larger than the window and so scroll bars are provided. Note how this means that screen coordinates need not be identical to canvas coordinates.

The spreadsheet grid currently only contains empty cells. In later prototypes cells may contain a string representation of entered data (actually, of the result of evaluating the formula in that cell when in viewing mode and the formula itself when in editing mode).

The spreadsheet grid has exactly two mobile rectangles on it. A thick black rectangle selectedCellFrame outlines the currently selected (for entering data) cell. A thin blue rectangle overCellFrame outlines the cell the mouse is currently over.At any point in time, the coordinates of the cell the mouse is over will be displayed in blue in a rectangle at the top of the window. The empty field to the right of that will in a future prototype display the formula in the currently selected cell.

The dynamic aspects of SpreadsheetGridView

  1. Whenever the mouse moves over the drawarea canvas, the blue overCellFrame rectangle is moved to the "nearest" actual grid cell (the mouse might namely be over the canvas but outside the grid).
  2. For efficiency reasons, the overCellFrame rectangle should only be moved if when the mouse moves to a different cell.
  3. When mouse button 1 is clicked over the drawarea canvas, the black selectedCellFrame rectangle is moved to the (nearest) cell the mouse is over.
  4. For efficiency reasons, the selectedCellFrame rectangle should only be moved if when the mouse moves to a different cell.
  5. Pressing the Up, Down, Left, and Right keyboard arrows moves the selectedCellFrame rectangle in the appropriate direction. Note how this is done modulo the height and width of the grid: when moving Left and reaching the end of the grid, the next selected cell will be the first of the next row. Similarly in other directions.
  6. Note how the previous implies that if one presses any one of the buttons as many times as there are cells in the grid, one should get back to the same cell.
  7. Pressing a key in the drawarea will currently only check whether the key is in the set of valid keys. Later, the actual string entered will be validated and stored (in the subject). Valid keys are listed in the given SpreadsheetGridView. If an invalid key is entered, the InvalidKeyError exception should be raised.
  8. Pressing backspace should be ignored.

Unit Testing

You must produce a list of tests (mention their type) to check whether the above requirements are satisfied in an implementation.

These test should be implemented in a file test.py using the PyUnit testing framework.

Resources

References


Hans Vangheluwe January 2004.