| MUSO | About FIT2022 | Assessment | Contacts | Laboratories | Lectures | Resources | Timetables | Tutorials |
| Last modified: 20070801:140456/added other set background solutions | FIT2022 AJH-2007-14 |
Objectives | Assignment 1 | Any Questions? | Submitting your Program
The objectives of this assignment are to:
The exercise is designed to be both fun, and useful! - you should be able to use it as a convenient way of using your background window to run through your favourite digital photographs.
A pdf version of this assignment sheet is also available.
You are to write a Python program to display a (background) image, and at the same time interact with the user. For this, you will need to use Python threads. You will need to visit the library page on Threads (or Threading) to see how to use them. Note that you may use either the low-level threads version in section 7.4, or the high-level version threading version found at section 7.5.
To display a background image on Mac OS X, one can use the following shell script:
"SetBackground-MacOSX.sh" 2.1 =Note that this works on Mac OS X only - bonus marks to the first five students who send me (ajh AT csse DOT monash DOT edu DOT au) an equivalent script to do the same thing under Windows/Linux/your favourite operating system. (5 marks to the first student, 4 to the second, 3 to the third, etc..) Note that it must display as a background image, that is, it must not appear in a separate window.
Jeff Parsons is the first to respond with a working solution for Linux/Gnome - congratulations, Jeff! 5 bonus marks for you!
"SetBackground-Gnome.sh" 2.2 =where
Just after I posted that message, another four appeared in my mailbox! Here they are (note that the bonus marks are now all gone
):
Note that this can either be run as a script:
<run as script 2.4> =or it can be imported as a python module, and called directly:
<run as subroutine 2.5> =Congratulations to Sohrab Hosseini, who gets 4 bonus marks! Sohrab comments that he thinks it only works for bmp files. I haven't tested that - if anyone can shed light on this, please let me know.
Sohrab adds:
Warning:You do not need to understand the following section: it is included for information and interest only. I had time to test the code for windows implementation of the wallpaper changer and I can confirm it does not work with any image format but bmp.
However, I've written a second version of the program (see below) that handles all of the common image types, in case you are interested. it does so by creating a temporary bmp file in the modules folder and piping that into win32 API. this program uses python imaging library (PIL) which, i believe, is not supplied with the standard python packages but can be freely downloaded from http://www.pythonware.com/products/pil/
I've also modified the program so the the wallpaper change is not permanent; i.e. after a reboot, the desktop wallpaper is reverted to the original (the image that was set before running this program). I thought it made more sense in the context of our exercise.
"SetBackground-Windows2.py" 2.6 =
Also to Rian McGuire, who sent in a similar solution to Jeff Parson's one above. 3 bonus marks to Rian!
Dmitri Nikulin has sent in a neat generic solution, which you can find on the fsetbg web page. 2 bonus marks to Dmitri!
Finally, Victoria Colquhoun collects the last bonus mark, for her solution which was also for Gnome.
My thanks to the 5 students who rose to the challenge!
Images to be displayed are determined by reading a database. The database file consists of a set of text lines, where each line contains the full file name (pathname) of the image, and a time value displaytime (in seconds). The two fields are separated by one or more blanks. The first line of the file contains just a single integer number, which is the ordinal number of the next image to be displayed.
The database must be updated as images are displayed, and a separate thread is to be used to perform the update, so that it runs concurrently with other activities in the program. The database should be updated whenever any information it contains is altered (including the next image number).
Here is a sample of what the database might look like:
"database.txt" 2.7 =
Warning:This exercise should be completed only after all other basic sections have been completed, and are working satisfactorily. Add a feature to your program to check before writing the database that it hasn't been (mutually) updated elsewhere. If the file has been modified, issue a warning to the user, and ask what should be done. Possibilities are: overwrite the file; abandon the update; abandon the update and read the new external database; etc..
Flag your addition in the code with a line # CHECK DB UNMODIFIED.
Now read on:
The background display is set in turn to each image pathname in the database and maintained for a fixed time, the time determined by the displaytime value stored in the database. At the conclusion of the time, or when a user command requires, a new image is chosen and displayed for the appropriate amount of time. The index number of the image is updated, and the database is marked as changed.
This section of the program is responsible for interacting with the user, and also runs asynchronously with the other sections.
The user input consists of a series of commands entered on standard input (sys.stdin). The commands are normally single characters, but make take parameters. Multiple commands may be entered on a single input line, but they must be separated by whitespace. You must include at least the following commands:
| n | display the next image immediately (cancelling the time on the currently displayed image). |
| p | display the previous image immediately (cancelling the time on the currently displayed image). |
| t d+ | set the time for the current image to be displayed to d+ seconds (d+ means one or more digits 0-9). |
| g d+ | go to image number d+ in the database and display. |
| q | quit the program |
Warning:This exercise should be completed only after all other basic sections have been completed, and are working satisfactorily. You may add other commands if you wish.
Now read on:
This section is the main body of the program, and is responsible for setting up the various subcomponents, initializing the threads, and gathering everything together upon the user entering the quit command.
If there is anything unclear, or something you think is needed is omitted, ask your question in the Anonymous Feedback Page and it will be answered as soon as possible.
Your program is to be submitted through MUSO as a tar file (uncompressed). The tar file should be named 12345678.tar, where 12345678 is your student ID number. It should contain display.py, the complete Python text of your program, in runnable form, together with a pdf file discussion.pdf. Do not submit these files directly as they will be discarded!
and please, no Word files!!
The discussion.pdf should contain a short (no more than an A4 page) summary with the following headings: Aims of this Exercise; Problems Encountered; Solutions Adopted; and Testing Strategies. Note that the Aims of the Exercise is not the same thing as the Objectives of the Exercise!
Warning:This exercise should be completed only after all other basic sections have been completed, and are working satisfactorily. You may also wish to add a section on Future Enhancements (not counted in the one page limit).
Now read on:
Your display program code must be laid out according to the following schema:
"display.py" 4.1 =| 20070801:140456 | 1.0.4 | ajh | added other set background solutions |
| 20070801:110124 | 1.0.3 | ajh | added Jeff Parson's Linux/Gnome Setbackground script |
| 20070731:144944 | 1.0.2 | ajh | released to csse server |
| 20070731:074014 | 1.0.1 | ajh | first draft |
| 20070718:160810 | 1.0.0 | ajh | stub only |
| This page maintained by John Hurst. Copyright Monash University Copyright Policy |
| ||
Generated at 20090702:1947 from an XML file modified on 20071002:0854 | |||