import appuifw import urllib import e32 class App: def __init__(self): # List of items on tab 0 (Exeter) self.exeter_maps = { 'http://www4.devon.gov.uk/webcam/mbarton/mbarton1.jpg':u'Marsh Barton Road', 'http://www4.devon.gov.uk/webcam/mbarton/mbarton2.jpg':u'Trusham Road', } # List of items on tab 1 (M5) self.m5_maps = { 'http://www4.devon.gov.uk/webcam/m5j30/cctv1.jpg':u'Sandygate West', 'http://www4.devon.gov.uk/webcam/m5j30/cctv2.jpg':u'Sandygate East' } # List of items on tab 2 (Torquay) self.torquay_maps = { 'http://www4.devon.gov.uk/webcam/m5j30/cctv3.jpg':u'Penn Inn Roundabout', 'http://212.104.136.164/webcam/images/torquay_harbour.jpg':u'Torquay Harbour' } # Synchronisation self.lock = e32.Ao_lock() # Handle our own exit events self.old_exit_key = appuifw.app.exit_key_handler appuifw.app.exit_key_handler = self.exit_handler # Set the current tab to 0 and display it self.maps_list = (self.exeter_maps, self.m5_maps, self.torquay_maps) self.current_tab = 0 appuifw.app.set_tabs([u'Exeter', u'M5 J30', u'Torquay'], self.display_tab) self.display_tab( 0 ) # Reset our current title to something approopriate self.old_title = appuifw.app.title appuifw.app.title = u"Traffic Cameras" # Add a load image option to the menu appuifw.app.menu = [(u"Load Image", self.load)] # Wait for input self.lock.wait() def exit_handler(self): # Exit handler, remember to reset the application title appuifw.app.title = self.old_title self.lock.signal() def display_tab(self, id): # Push a listbox to each tab when they are displayed self.lb = appuifw.Listbox(self.maps_list[id].values(), self.load) appuifw.app.body = self.lb self.current_tab = id def wait(self): appuifw.note(u"Fetching traffic camera image, please wait...", "info") def load(self): # Load an image when a Listbox() value is selected try: # Grab the currently selected item in the listbox, # and the current tab id so we can make the query item = self.lb.current() id = self.current_tab # Set the Listbox() to tell the user we're doing something self.lb.set_list([u"Please wait..." ]) # Lookup the URL for that tab and item k = self.maps_list[id].keys() url = "%s" % k[item] # Lookup the place name for that tab and item m = self.maps_list[id].values() name = "%s" % m[item] # Disable the menu, no multiple pulls appuifw.app.menu = [(u"Load Image", self.wait)] # Popup an info note to tell the user we're doing something appuifw.note(u"Fetching traffic camera image of " + name, "info") # Grab the image over GPRS urllib.urlretrieve(url, "C:\\traffic.jpg") content_handler = appuifw.Content_handler() content_handler.open("C:\\traffic.jpg") except IOError: appuifw.note(u"Could not fetch the image.",'error') except Exception, E: appuifw.note(u"Could not open the data, %s"%E,'error') # All done, reenable the menu, and set the listbox # back to the original list values appuifw.app.menu = [(u"Load Image", self.load)] self.display_tab( id ) A = App()