1 - singola foto (tempo=0) con visualizzazione di tasti decisionali
questa parte va abbastanza bene (anche se è da rivedere e devo fare la parte utilizzo)
2 - foto in sequenza (tempo>0) con proiezione a tempo
questa parte va ma ha un problema che non riesco a risolvere: tra una foto e l'altra compare, anche se
per breve tempo, la scrivania. Naturalmente questo disturba moltissimo la visione
Vorrei un vostro aiuto per:
a - avere il passaggio da una foto all'altra in modo istantaneo (un sistema più efficiente dal mio)
b . in alternativa avere uno sfondo nero anzichè la scrivania
forse non c'è soluzione, ma io spero sempre.... grazie. ( non vorrei gettare tutto il lavoro nel cestino...)
Codice: Seleziona tutto
def FOTO (tempo,ft,b1="",b2="",b3="",b4="",b5="",b6="",q="4",r=.9,tst="E",root=""):
# tempo : 0: visualizzazione singola foto, > 0 proiezione (tempo: da 2 in su)
# ft : percorso foto da visualizzare
# b1 : etichetta eventuale bottone scelta
# b2...b6 : eventuali altri bottoni scelta
# q : qualità: 1=NEAREST 2=BILINEAR 3=BICUBIC 4=ANTIALIAS
# r : coefficente riduzione (1=1:1 .5 metà 2=doppio)
# tst : opzioni= 'E' attiva tasto Escape, 'F' full screen + attivazione Escape
# << PYscelta : exit "+","-","I","F","=","",b1,...b6, "E"
# è necessario installare Python-imaging e Python-imaging-tk
# richiede: from PIL import Image, ImageTk, ImageFilter
PYscelta=[""]
def seclikE(x): seclikUN("E") # escape
def seclikF(x): seclikUN("F") # fine (End)
def seclikI(x): seclikUN("I") # Inizio (home)
def seclikD(x): seclikUN("+") # pag. giu
def seclikP(x): seclikUN("-") # pag. su
def seclikR(x): seclikUN("=") # return (invio)
def seclik1(): seclikUN(b1) # bottone 1
def seclik2(): seclikUN(b2) # bottone 2 ecc.
def seclik3(): seclikUN(b3)
def seclik4(): seclikUN(b4)
def seclik5(): seclikUN(b5)
def seclik6(): seclikUN(b6)
#
def seclikUN(z):
PYscelta[0]=z
print 77,PYscelta
root.destroy()
def cl1(xx): root.quit()
#
if "F" in tst: tst+="E" # se Full screen attiva Escape
# gestione foto
ftw = Image.open(ft)
a= ftw.size; ww=a[0]; hh=a[1]
if hh>ww:r=r*0.62 # foto verticale
rp=970.00/ww
r=r*rp
ww=int(ww*r); hh=int(hh*r)
if q=="4":ftw = ftw.resize((ww, hh), Image.ANTIALIAS) # best down-sizing filter
elif q=="3":ftw = ftw.resize((ww, hh), Image.BICUBIC) # cubic spline interpolation in a 4x4 environment
elif q=="2":ftw = ftw.resize((ww, hh), Image.BILINEAR) # linear interpolation in a 2x2 environment
else: ftw = ftw.resize((ww, hh), Image.NEAREST) # use nearest neighbour
try:
if root <> "": root.destroy() # foto precedente persistente
except: pass
#
root = Tk()
root.title(ft)
if "E" in tst and "F" in tst: root.attributes('-fullscreen', True)
ftw = ImageTk.PhotoImage(ftw) #converte
wv = ftw.width(); hv = ftw.height()
x=y=0 #shift
root.geometry("%dx%d+%d+%d" % (wv, hv, x, y))
panel1 = Label(root, image=ftw)
panel1.pack(side='top', fill='both', expand='yes')
if b6<> "": button6 = Button(panel1,text=b6, command=seclik6).pack(side='bottom',anchor="se")
if b5<> "": button5 = Button(panel1,text=b5, command=seclik5).pack(side='bottom',anchor="se")
if b4<> "": button4 = Button(panel1,text=b4, command=seclik4).pack(side='bottom',anchor="se")
if b3<> "": button3 = Button(panel1,text=b3, command=seclik3).pack(side='bottom',anchor="se")
if b2<> "": button2 = Button(panel1,text=b2, command=seclik2).pack(side='bottom',anchor="se")
if b1<> "": button1 = Button(panel1,text=b1, command=seclik1).pack(side='bottom',anchor="se")
root.bind('<End>',seclikF) # predefiniti
root.bind('<Home>',seclikI)
root.bind('<Next>',seclikD)
root.bind('<Prior>',seclikP)
root.bind('<Return>',seclikR)
if "E" in tst: root.bind('<Escape>',seclikE)
panel1.image = ftw
if tempo > 0: # proiezione temporizzata
PYscelta=[""]
action2=lambda nn=1:cl1(1000)
root.after(int(tempo*1000),action2) # per la gestione a tempo
root.mainloop()
try: root.update() # per ridurre l'intervallo tra le due foto
except: PYscelta=["E"]
else:
root.mainloop() # visualizzazione di una foto
return PYscelta[0], root
####
listaft=[.....] # lista foto jpg
xx=""
n=0
while n < len(listaft):
ftx=PYfile[n]
tempo=3
z,xx=FOTO(tempo,ftx,b1="bottone 1",b2="bottone 2",r=1.2,tst="E",root=xx)
print z
if z=="E": sys.exit()
n+=1
if n>8: sys.exit() # blocco di sicurezza per le prove
