src/extras/examples/weather_maps.py
changeset 0 ca70ae20a155
equal deleted inserted replaced
-1:000000000000 0:ca70ae20a155
       
     1 # Simple GUI example
       
     2 
       
     3 # Copyright (c) 2005 Nokia Corporation
       
     4 #
       
     5 # Licensed under the Apache License, Version 2.0 (the "License");
       
     6 # you may not use this file except in compliance with the License.
       
     7 # You may obtain a copy of the License at
       
     8 #
       
     9 #     http://www.apache.org/licenses/LICENSE-2.0
       
    10 #
       
    11 # Unless required by applicable law or agreed to in writing, software
       
    12 # distributed under the License is distributed on an "AS IS" BASIS,
       
    13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    14 # See the License for the specific language governing permissions and
       
    15 # limitations under the License.
       
    16 
       
    17 
       
    18 import socket
       
    19 import urllib
       
    20 
       
    21 import e32
       
    22 import appuifw
       
    23 
       
    24 # List of triplets "Name", "URL", "extension"
       
    25 choices=[(u"US Graphical Forecast", "http://weather.gov/forecasts/graphical/images/thumbnail/Thumbnail_Wx4_conus.png", "png"),
       
    26          (u"US Radar Image", "http://weather.gov/mdl/radar/rcm1pix_b.gif", "gif"),
       
    27          (u"US Satellite Image", "http://weather.gov/satellite_images/national.jpg", "jpg") ]
       
    28 tempfile_without_extension = "c:\\weather"
       
    29 
       
    30 old_title = appuifw.app.title
       
    31 appuifw.app.title = u"Weather forecast"
       
    32 
       
    33 L = [ x[0] for x in choices ]
       
    34 index = appuifw.popup_menu(L, u"Select picture")
       
    35 
       
    36 if index is not None:
       
    37     url = choices[index][1]
       
    38     ext = choices[index][2]
       
    39     tempfile = tempfile_without_extension + "." + ext
       
    40 
       
    41     try:
       
    42         print "Retrieving information..."
       
    43         urllib.urlretrieve(url, tempfile)
       
    44         lock=e32.Ao_lock()
       
    45         content_handler = appuifw.Content_handler(lock.signal)
       
    46         content_handler.open(tempfile)
       
    47         # Wait for the user to exit the image viewer.
       
    48         lock.wait()
       
    49         print "Image viewer finished."
       
    50     except IOError:
       
    51         print "Could not fetch the image."
       
    52     except:
       
    53         print "Could not open data received."
       
    54 
       
    55 appuifw.app.title = old_title
       
    56