DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Gallery Thumbnails

03.10.2006
| 3879 views |
  • submit to reddit
        
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()
    

Comments

Snippets Manager replied on Mon, 2012/05/07 - 2:21pm

I was very lazy with this snippet. I almost decided not to publish it. But then do it anyway. Things that could be improved - more explanation about the code - redraw() - redraw also scrollable to more than 16 images - changing directory to E:\ or sub-directory (also display how many images are there in the sub-dir) After thinking how much is left to be done, I stop. ^_^ Well, I really wish there were a good, free gallery app.

Snippets Manager replied on Thu, 2006/03/09 - 12:56pm

I also forget 3) open image in the python app not with the gallery (it's better) and allowing me to zoom !

Snippets Manager replied on Thu, 2006/03/09 - 12:56pm

hello , Very cool indeed but there are missing some things ... 1) After opening a thumbnail and I go back to python gallery , all thumbnails disapeared (I suspect not using callback_redraw in Canvas widget !) 2) If I have more than 16 thumbnails , I always see image name in the title but not the frame cursor ! (thumbnails would have to scroll to show hidden others)