Labs
Leopard Lesson Plan #3
Advanced - Weather Recorder
Lesson Files - Download
Introduction
The weather conditions are always changing, and it's amazing how different they can be a state or even just a county away from where you are. This program starts us off by showing us what the conditions are like in Las Vegas, and it even includes an interactive Google Maps widget to fill us in on what the geography of the area is like.
In addition, a textedit control is used to enable each student to record his or her current observations about the area, and these observations are saved to a text file within the Leopard directory so that they can be recalled later on and added to.
Open Leopard. Now you are ready to begin.
First download all files that are needed for lessons Plan #3. Right click to save the file, then drag and drop into Leopard.
wbrecorder.lep
record.txt
Creating the Window
As usual, we'll use a standard window for this program with the exception that we'll also add a background color command to brighten it up a little bit. The colors that can be used are referenced in the User Guide, but for this example, we'll use blue.
window title
Weather Recorder
window size
648
590
background color
blue
end
Let's now add the rest of the components before the end command.
Adding WeatherBug Controls
Not only do we want a 250x250 WeatherBug control for the 89142 Las Vegas zip code, but we also want a WeatherBug Camera control that loads the LEVGS image.
89142
250x250
10
10
weatherbug camera
LEVGS
300
10
Using a Google Maps Widget
We first started using Web controls to embed weather maps in our Community WeatherBug program, but we'll now use one to embed a Google Maps widget in our current project.
The line of text under the name of the control may look cryptic, but it's standard widget code that is provided by a large number of online services, and there's no need to write it from scratch because all you have to do is copy and paste it from the source that provides the code. Make sure that the entire script code with the brackets (<>) is placed on one line so that the widget works correctly in Leopard. If you look closely, you'll notice the 89142 zip code in this line of code that was provided when the widget was customized on Google's site, and this tells the widget to load the map for that zip code.
Just like before, we don't want any scrollbars, and we make the clear along with the sizing of the control itself.
<script src="http://gmodules.com/ig/ifr?url=http://ralph.feedback.googlepages.com/ googlemap.xml&up_locname=Stone%20Mountain&up_loc=89142&up_zoom=Street& up_view=Satellite&synd=open&w=325&h=228&title=Google+Map&border=% 23ffffff%7C3px%2C1px+solid+%23999999&output=js"></script>
no scrollbars
300
260
323
267
Creating More Controls
Not only are we going to add two buttons, but we're also going to use a textedit control to collect input from the user. It's not going to contain any initial text like the buttons, but it's sized in the same way.
10
300
256
225
button
Load
80
275
40
20
buttontwo
Save
150
275
40
20
Establishing Onclick Events
The onclick events that we're going to use will perform some helpful functions.
The first one for the Load button places the contents of the “record.txt” file into the textedit control, and the second one saves the current text in the textedit control to the “record.txt” file. In this way, you can keep adding your observations to the file and see how they change over time.
Before you try to click on the Load button, make sure that you already have “record.txt” in your main Leopard directory so that the program has something to load. If the file isn't there, type in some observations, click the Save button, and then the “record.txt” file will be created for you.
read file textedit
record.txt
buttontwo onclick
textedit file
record.txt
Conclusion
Now that all of the required code has been added before the end command, we're now ready to run the complete program.
Here's the full program code from beginning to end:
window title
Weather Recorder
window size
648
590
background color
blue
weatherbug
89142
250x250
10
10
weatherbug camera
LEVGS
300
10
web
<script src="http://gmodules.com/ig/ifr?url=http://ralph.feedback.googlepages.com/ googlemap.xml&up_locname=Stone%20Mountain&up_loc=89142&up_zoom=Street& up_view=Satellite&synd=open&w=325&h=228&title=Google+Map&border=%23 ffffff%7C3px%2C1px+solid+%23999999&output=js"></script>
no scrollbars
300
260
323
267
textedit
10
300
256
225
button
Load
80
275
40
20
buttontwo
Save
150
275
40
20
button onclick
read file textedit
record.txt
buttontwo onclick
textedit file
record.txt
end
Additional Student Activities
- Modify the WeatherBug control, the WeatherBug camera image, and the Google Maps widget to display the information for other WeatherBug weather stations.
- Have each student save their observations for two or more locations in the textedit control over a period of time and then have them present their findings to the class.
- Use the Google Maps widget example as a basis to create other connected programs that use widgets and other live Internet content. You can find some content to use from here, although many additional sources exist as well.
