Categories: Python | How To | Code Examples | S60
This page was last modified 08:24, 7 June 2008.
Displaying a thumbnail gallery
From Forum Nokia Wiki
This code displays the thumbnails gallery
First version
from appuifw import * from graphics import Image from key_codes import * #from status import * #from e32db import format_time import os, e32 dir = u'C:\\Nokia\\Images\\_PAlbTN\\' os.chdir(dir) fs = os.listdir('') mtime = os.path.getmtime # newest first fs.sort(lambda a,b: cmp(mtime(b), mtime(a))) app.body = canvas = Canvas() # show just 16 images for k in range(min(16, len(fs))): j, i = divmod(k, 4) im = Image.open(dir + fs[k]) canvas.blit(im, target=(2+44*i, 2+34*j)) canvas.rectangle([(0,0), (43,33)], 0xff, width=2) # selected x, y, k = 0, 0, 0 def move(dx, dy): global x, y, k canvas.rectangle([(44*x,34*y), (44*x+43,34*y+33)], 0xffffff, width=2) k = 4*y + x + 4*dy + dx y, x = divmod(k, 4) canvas.rectangle([(44*x,34*y), (44*x+43,34*y+33)], 0xff, width=2) if 0 <= k < len(fs): app.title = u''+fs[k] #status_on(format_time(mtime(fs[k]))) # move cursor and open image canvas.bind(EKeyUpArrow, lambda: move(0,-1)) canvas.bind(EKeyDownArrow, lambda: move(0,1)) canvas.bind(EKeyLeftArrow, lambda: move(-1,0)) canvas.bind(EKeyRightArrow,lambda: move(1,0)) canvas.bind(EKeySelect, lambda: Content_handler().open(dir[:-8]+fs[k])) # standard code for non-loop app lock = e32.Ao_lock() app.exit_key_handler = lock.signal lock.wait()
Second version
import appuifw import e32 import graphics import key_codes import os class FlickrS60Error(Exception): pass class FlickrS60Thumb: def __init__(self, path): self.path = unicode(path) self.listFile = [] self.ldivx = 0 self.ldivy = 0 self.lock = e32.Ao_lock() self.canvas = None self.img = graphics.Image.new((176, 144)) self.img_tmp = graphics.Image.new((42, 36)) self.x, self.y = 0, 0 self.p = 0 self.pages = 0 self.currpages = 0 self.mpath = 0 def OnRun(self): appuifw.app.exit_key_handler = self.lock.signal self._createList() self.canvas = appuifw.Canvas(redraw_callback=self.OnUpdate) appuifw.app.body = self.canvas self.canvas.bind(key_codes.EKeyRightArrow, lambda: self.move(1, 0)) self.canvas.bind(key_codes.EKeyLeftArrow, lambda: self.move(-1, 0)) self.canvas.bind(key_codes.EKeyUpArrow, lambda: self.move(0, -1)) self.canvas.bind(key_codes.EKeyDownArrow, lambda: self.move(0, 1)) self.canvas.bind(key_codes.EKeySelect, self.IMG) self._drawIMG() self.lock.wait() def OnUpdate(self, rect): self.canvas.blit(self.img) self.canvas.rectangle([(self.p+(42*self.x), 36*self.y), (self.p+(42*self.x)+42, (36*self.y)+36)], width=2, outline=0x123456) def move(self, x, y): self.x = (self.x+x)%4 self.y = (self.y+y) if x == 1: self.p = (self.p+2)%8 if x == -1: self.p = (self.p-2)%8 if self.y == 4: if self.currpages < self.pages-1: self.y = 0 self.currpages += 1 self._drawIMG(start=self.currpages) else: self.y = 3 if self.y == -1: if self.currpages > 0: self.y = 3 self.currpages -= 1 self._drawIMG(start=self.currpages) else: self.y = 0 self.mpath = (4*self.y + self.x)+(16*self.currpages) self.OnUpdate(None) def IMG(self): try: m = self.listFile[self.mpath].replace('_PalbTN\\', '') appuifw.Content_handler().open(m) except: pass def _drawIMG(self, start=0): self.img.clear(0xffffff) z = 0 for id in range(start*16, (start+1)*16): j, i = divmod(id-(start*16), 4) try: self.img_tmp.load(self.listFile[id]) self.img.blit(self.img_tmp, target=(z+(42*i)+(z+1), 36*j)) z = (z+1)%4 except: break self.OnUpdate(None) def _createList(self): try: for id in os.listdir(self.path): self.listFile.append(self.path + id) self.ldivx, self.ldivy = divmod(len(self.listFile), 16) self.pages = self.ldivx if self.ldivy <> 0: self.pages += 1 except: raise FlickrS60Error('Error in the list creation.') if __name__ == '__main__': FlickrS60Thumb('E:\\Images\\_PalbTN\\').OnRun()
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Does S60 Gallery support AIW to insert custom menu items? | JOM | Symbian Media (Graphics & Sounds) | 6 | 2008-06-12 08:22 |
| Cached webpages | jspencerg | General Discussion | 5 | 2008-01-23 04:03 |
| Question on FileConnection | pmgf_14 | Mobile Java General | 12 | 2006-12-05 09:45 |
| Multiple "Allow application to read data in:" prompts | selenatan | Mobile Java Networking & Messaging & Security | 3 | 2007-06-17 03:36 |
| Nokia N73 Gallery | Zonda | Graphics & Video & Streaming | 1 | 2007-02-23 09:04 |
