Fab Academy 2013

#1 Project proposal.

#2 Computer Aided Design

#3 Computer-Controlled Cutting

#4 Electronics Production

#5 3D Scanning and Printing

#6 Electronics Design

#7 Molding and Casting

#8 Embedded Programming

#9 Computer-Controlled Machining

#10 Input Devices

#11 Composites

#12 Interface and Application programming

#13 Output devices

#14 Networking and Communications

#15 Mechanical Design, Machine Design

#16 Applications and Implications

#17 Invention, Intellectual Property, and Income

#18 Project Development

#19 Final Project

Assignment Files

 

Interface and Application Programming:

For this assignment, we were required to write an application to interface with an input or output device.

I decided to use the temperature sensor I made during the Input Devices class (and its accompanying code) as a base. If you want to read about how I made this temperature sensor, please refer to this page.

I hooked up the temperature sensor to my computer and ran the original code, as a quick refresher to see what the interface looked like. Neil's original design is a simple white box with a red increasing bar inside a blue bar, with a text indicator as well.

I then opened up the Python file that came with the temperature sensor, and I started rooting around inside.
I quickly noticed a couple of variables I could easily start playing with. I saw a few references to HTML colour codes, so I decided to change those. I looked up a list of colour codes (found here) and started plugging in some new colours.
Another variable I changed was the defined font used for the text displaying the temperature.
A quick check showed me that I now had a new background colour, and also changed the colours of the text and the bars.

In the code I also noticed that it pulled from a library called Tkinter for certain graphic displays (such as the canvas that creates the bars). I looked up what kinds of commands you can apply to these, and found a few useful resources.
Pages I found particularly useful were the resource available at effbot and Tutorials Point.

Most of the changes I then made were applied to the Canvas, as I understood that that was the window being drawn.
I changed

root.title('hello.temp.45.py (q to exit)')
to
root.title('What temperature is it? (Press Q to exit)')
to change the title bar of the window.

In the canvas I then found a line creating a rectangle. On the effbot resource page I found that you could also use different geometric shapes. I decided to change the blue bar to an ellipse, and keep the red bar as red. This basically has the red bar squishing a blue ball as the temperature rises.

I also added a line of text above the bar using the create.text canvas command.
After all these changes, I was left with this:

I then tried to change the bars to images, or even to just add an image to the window. Unfortunately, this is something I couldn't figure out well enough. I tried adding the images to the code using the PhotoImage definitions provided for Tkinter, but I kept getting syntax errors with whatever code I put in.
I decided to scrap the images and try something else.

Checkboxes!

Tkinter has a references to checkboxes, so I added a few. After adding the code, the checkboxes actually showed up in another window. I noticed a definition called 'master' in the code I had added that was defined as Tk(). The canvas window had a similar definition, but as 'root'.
After I changed the references to 'master' to 'root', the checkboxes now appeared in the same window as the temperature bar, but under the canvas. I wasn't able to figure out how to add it to the canvas, but now that they're in the same window I wasn't too bothered.

Checking and unchecking the boxes is fun, but I wanted something to happen. Luckily, I figured out you can add a 'command' to the checkbox that is executed as you click on it. I combined the command with another one called tkMessageBox, which pops up a small dialog with some text.
This worked, except that the dialog appears when you both check or uncheck the boxes, and there's no way that I could get it to only execute on checking the box.


I cut my losses and continued on. There was already a command to shut down the application (by pressing Q), but I figured I could add a button to the interface that would do the same. The idea behind it is that it's easier to figure out if you have a visual cue.

I was able to add a button to the program, but if I tried to add it to the 'root' window, Python would crash. I tried a few different things, but I ended up having the button show up in a different window. I basically made a new definition attached to Tk(), and added a line of code to it:

Button(quittles, text='Quit', command=quit).grid(row=3, sticky=W, pady=4)
The button works, it shuts it down python so you can continue working in Terminal (or your other favourite command line).

If you're interested, the modified code for this assignment can be found on the Assignment Files page!