"""Series 60 GUI for IMDbPY Copyright (C) 2005 Tero Saarni This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Description: This application is an interface to Internet Movie Database. It runs on Python interpreter for Series 60 mobile phones. The IMDb web site is accessed using unmodified IMDbPY module written by Davide Alberani (http://imdbpy.sourceforge.net/). This program is still only a proof of concept e.g. there is no installer available at the moment. Download imdbpy from its website, copy the imdb subdirectory to phone and if necessary add it to sys.path. In addition you need to copy following modules from Python 2.2.2: sgmllib.py, markupbase.py, htmllib.py, htmlentitydefs.py and formatter.py. These are not included in Python for Series 60 by default. http://kotisivu.mtv3.fi/terosaarni/python/imdbpygui/ """ __version__ = "0.3" __author__ = "Tero Saarni " __license__ = 'GPL' # # Version history # # 2005-03-21 initial version # 2005-03-25 upgrade to IMDbPY v1.8 which gives a big performance improvement: # query times went from ~10 minutes to less than 2 min # 2005-05-01 upgrade to IMDbPY v1.9 and highly optimized "mobile" access # method. Now searches take: ~5sec for movie hits and ~15sec for # details. # import e32 import thread from appuifw import app, query, Listbox, Form, FFormViewModeOnly class Application: def __init__(self): self._lock = e32.Ao_lock() self._sig = None self._exit = False self._old = {'title': app.title, 'exit': app.exit_key_handler, 'body': app.body, 'menu': app.menu } def send(self, sig): #print 'SEND: name=%s data=%s' % (sig.name, sig.data) self._sig = sig self._lock.signal() def exit(self): self._exit = True def mainloop(self): while 1: self._lock.wait() #print 'RECV: name=%s data=%s' % (self._sig.name, self._sig.data) self.signal_handler(self._sig) if self._exit: break app.menu = self._old['menu'] app.body = self._old['body'] app.exit_key_handler = self._old['exit'] app.title = self._old['title'] def signal_handler(self, sig): pass class Signal: def __init__(self, name, data=None): self.name = name self.data = data class ImdbGui(Application): def __init__(self): Application.__init__(self) self.db = None self.movie_title = None self.movies = None self.details = None app.title = u'IMDb' app.exit_key_handler = self.handle_exit app.menu = [(u'Exit', self.handle_exit)] # import imdb on background thread.start_new_thread(self.handle_init, ()) def handle_init(self): self.send(Signal('query')) import imdb self.db = imdb.IMDb('mobile') self.send(Signal('search')) def handle_exit(self): self.send(Signal('close')) def handle_select(self): self.send(Signal('details', app.body.current())) def handle_get_movies(self): self.movies = self.db.search_movie(self.movie_title, results=15) mlist = [ unicode(m['title'], 'latin-1') for m in self.movies ] self.send(Signal('matches', mlist)) def handle_get_details(self): self.db.update(self.details) self.send(Signal('show')) def signal_handler(self, sig): if sig.name == 'query': self.movie_title = query(u'Search for movie:', 'text') app.body = Listbox([u"Please wait..."]) elif sig.name == 'search': # run imdbpy on background so that gui wont block thread.start_new_thread(self.handle_get_movies, ()) elif sig.name == 'matches': app.body = Listbox(sig.data, self.handle_select) elif sig.name == 'details': self.details = self.movies[sig.data] app.body = Listbox([u"Retrieving details..."]) # run imdbpy on background so that gui wont block thread.start_new_thread(self.handle_get_details, ()) elif sig.name == 'show': m = self.details director = '%s' % m['director'][0] rating = '%s/10' % m['rating'] genres = ' '.join(m['genres']) runtime = '%s min' % m['runtime'][0] data = [(u'Title', 'text', unicode(m['title'], 'latin-1')), (u'Year', 'text', unicode(m['year'], 'latin-1')), (u'Genre', 'text', unicode(genres, 'latin-1')), (u'Director', 'text', unicode(director, 'latin-1')), (u'Runtime', 'text', unicode(runtime, 'latin-1')), (u'Rating', 'text', unicode(rating, 'latin-1'))] f = Form(data, FFormViewModeOnly) f.execute() elif sig.name == 'close': self.exit() if __name__ == '__main__': a = ImdbGui() a.mainloop()