Skip to end of metadata
Go to start of metadata


This portion of the assignment this week was an introduction to creating a GUI that displays and translates data. I modified a provided file in order to select different shapes to represent data points, and so that the program can read in a data file and plot points accordingly.

The provided code created a root window, set its dimensions and title, added semi-functional menus and a canvas, and set bindings for mouse clicks. Right mouse clicks added small circles to the canvas, and left button motion translated the circles.

Changing Shapes

First I made the command menu selections change the shape of subsequent markings. To do this, I created an instance variable self.shape to hold the string referring to the currently selected shape. By default, it is "circle," but when a new menu option is selected, the handleCmd function that is is bound to changes the value of self.shape. To make the program draw the appropriate shape, I added an if /elif block to the handleButton2 method. The canvas has methods to draw ovals and rectangles, so the circle and square points are easy to make. To make the cross, I used create_polygon, which accepts x and y coordinates for any number of points. At that point, the shapes drew themselves correctly, but the crosses disappeared when I tried to move them because of how the translation algorithm worked. Ovals and rectangles can be identified by only two points, but polygons are not. To make the translation algorithm work for polygons, I looped over every coordinate in the graphic and updated it according to the calculated mouse motion instead of explicitly doing it for only two coordinates.

Opening Files

The provided code created an "open" menu option that would bring up a file selection window, but did nothing with the chosen file. I added the capability for the program to process files where each line contains exactly two integers by plotting a point at each coordinate pair. The program simply loops over every line in the file object, extracts the two 3-digit numbers, stores them in an event object, and sends it to the handleButton2 function. I made my own event class definition for this, and since it had variables x and y, the button function gladly accepted it as an event.

Dialog Boxes

To make the program more user friendly, Jack and I figured out to make a dialog box with radio buttons to select the shape with. The "Options" menu now has the command "Select Shape," and when the user selects it, the dialog box appears. Forseeing that we would probably make several such boxes, we made a python module named dialogBoxes, in which we put our ShapeWindow.


The sort of 'polymorphism' I used to send my own event object to the button-handling function seems a little strange, but I guess it is sort of like creating an interface that only specifies the fields that the specific method uses -- in this case x and y variables. I suppose the flexibility is nice, but it also seems a little ambiguous.