Assignment 7: Worth 15% of the Homework grade Due: Wednesday, August 5th at 11:59 pm To turnin programs for Assignment 7 (hamgui.py and ham.py) from lectura, type % turnin 380assignment7 hamgui.py % turnin 380assignment7 ham.py 1. The object of this assignment is to become familiar with the Tk GUI library and the Tkinter Python module. Both of your text books have material on Tk, but on-line references seem superior. We will be handing out materials in class, but you might want to look closely at the materials at: http://wiki.python.org/moin/TkInter The Tkinter reference manual from New Mexico Tech is especially good. "Thinking in Tkinter" is good for an introductory document. We will handing out both documents in class. You are ONLY to use Tkinter (and tkFileDialog) for the GUI for this assignment: do not PMW or Qt or Tix or any other GUI tools. You are of course free to use other standard Python libraries (sys, os, etc.). For this assignment, you will be extending Assignment 6 by adding a Graphical User Interface (GUI) to your Hamiltonian-Cycle finder. This GUI program will display your full graphs on the screen and graphically show all solutions found by your engine. You load your graph from a file and display it on screen; when you are happy with your graph, you will submit it to your Hamiltonian-Cycle engine to find all cycles through the graph. Obviously, you will reuse your ham.py from last assignment. We won't be checking that code (ham.py) closely, but if it doesn't give you the right answer, it will hurt you. When you start the application: % python hamgui.py You should be greeted with the first display on the following page. Your display should look JUST LIKE the GUI on the following page. The labels, button, title, initial values should all be the same. Notice also that the focus starts on the "Submit" button: this is also important. One thing to note: The title of the window should be the same ("Hamiltonian Graph Utility"), although your window manager will determine what your close, resize, etc. buttons on the very top look like. The Canvas should be initially empty when you start. The Top Row: The top row has two buttons: Load and Quit. Activating the Quit button should cleanly (no weird message) bring down all windows associated with the hamgui and exit the program. Note that the Quit button is purposely offset away from the Enty so ask to avoid accidentally user interaction. Activating the Load Button should bring up a File Selection Dialog IN THE CURRENT DIRECTORY and it can only look at .adj files (for the adjacency matrices). * If the file contains a valid adjacency matrix (like from Assignment 6), then it will load it and display the graph on screen. At the point, the Load button should grey out to indicate you can't load anymore. The Compute button should go active (see below). * If the file DOES NOT contain a valid adjacency matrix, then nothing should happen (no buttons should change state). The user should have the chance to Load another file with a legal adjacency matrix. The top row also contains an Entry field and a Label. They will both be greyed out until (a) the user has loaded a valid matrix and then (b) activated the Compute button. By default, the entry should have a 0 displayed in it and the Label next to it should say "# Answers:??" to indicate there have been no answers computed yet. See the attached picture. Note that we were very clear to say "Activating" for all the buttons above. If you click on one of the buttons above and move the mouse pointer away from the button before you release, this does NOT activate the button. You need to press and release the button while keeping the mouse pointer right on top of the button you wish to activate. (This corresponds to the "command bindings" on Buttons we will discuss in class: it's also in the "Thinking in Tkinter" document by Stephen Ferg) The buttons can also be activated and navigated through the keyboard. Pressing the Tab key should move through the buttons (and Entry widget). Pressing the Return key, while the focus is on the button also activates it. We will be testing if your application also allows this kind of keyboard input. There is a Compute button that should be greyed out by default. It should sit in a row by itself under the top row. If a valid adjacency matrix is loaded, then the Compute button is ungreyed so the user may press it. The Compute button is in a row all by itself and does NOT expand to fill the row: it should be centered. The Canvas : The big empty area in the GUI is a Canvas where we will be placing the graph and seeing what the adjacency matrix looks like. The Canvas will be 400 pixels by 400 pixels. We WILL NOT be worrying about scrolling the canvas. When the application first comes up, the Canvas should be empty. After you have loaded an adjacency matrix, the graph will be plotted on the screen where each vertex would be equidistant on a circle. See the attached examples. We will providing code to help you figure out where to place the points so they are essentially on the circle. The vertices of the graph should be plotted in black and have a bounding box of 10 x 10. The edges of the graph should be plotted in grey and have a width of 6. Computing : Once the initial graph has been loaded, the user can activate the Compute button. Doing this will cause the application to find all Hamiltonian Cycles in the given graph (this obviously may take a few minutes). The user knows the program is ready to accept input again because then the Label widget and the Entry widget at the top become active. The Label widget updates to show the number of hamiltonian cycles found: "# Answers:120" [Or whatever the number is]. The Entry becomes active starting with the number 0. The user may then display Hamiltonian Cycles on the graph. Everytime the user updates the number in the entry and hits the return key, the graph updates, showing a Hamiltonian Cycle in the graph. The cycle should be displayed in white with a width of 4 pixels. See below. If the user enters a number bigger than or less than the number of answers, it resets to zero. If there are no answers (i.e, no Hamiltonian Cycles), then it should still reset to zero and just not display anything. Details of grading: In this assignment, we will be interacting with your GUI to grade it. We have tried to specify all the things we will be looking for in your GUI in this handout, but clarifications may still be needed. Be watching the web page. You should submit your (working) tsp code (ham.py) with your your hamgui.py so that it can compute. In a "production version", we would be using your cham code instead. But the purpose of this assignment is to learn Tk, although integrating it with some of the last assignment is important too. I suggest you attack the problem in phases: Get the buttons laid out first, get the buttons "basically" working, get the Canvas plotting the graph, then plot the answers. Don't be afraid to use print to print out valuable information such as the event.x and event.y and when you enter and leave callback routines.