Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Gallery Thumbnails

DZone's Guide to

Gallery Thumbnails

·
Free Resource

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()

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}