1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
| from Tkinter import *
import commands
import os
import time
from PIL import Image, ImageTk
#recupDerniereImage : recupere la derniere image produite
def recupDerniereImage(): #code de debuggage
path=os.getcwd()
os.chdir(path)
liste_photo=[]
sortie1,liste_photo=commands.getstatusoutput('gphoto2 -L') #recupere la liste des fichiers
coupe_sortie=liste_photo.split()
print coupe_sortie
nombreSeparation=len(coupe_sortie)
numeroDernierePhoto=nombreSeparation-6
numeroDernierePhoto=coupe_sortie[numeroDernierePhoto]
numeroDernierePhoto=numeroDernierePhoto.replace("#"," ")
numeroDernierePhoto=numeroDernierePhoto.strip()
commandeRecuperationDernierePhoto=str("gphoto2 -p " + str(numeroDernierePhoto))
home = os.getenv("HOME")
focus=home+"/.focus"
os.chdir(focus)
print commandeRecuperationDernierePhoto
sortie1,recupPhoto=commands.getstatusoutput(commandeRecuperationDernierePhoto)
print os.getcwd()
splitRecupPhoto=recupPhoto.split()
lastarg=len(splitRecupPhoto)-1
nomDerniereImage=splitRecupPhoto[lastarg]
print str(nomDerniereImage)
#a enelver
nomDerniereImage="essai.png"
afficheimage(nomDerniereImage)
def appui(event):
print "clicked at", event.x, event.y
def relache(event):
print "Relache a", event.x, event.y
def afficheimage(lastimage):
home = os.getenv("HOME")
focus=home+"/.focus"
os.chdir(focus)
image=Image.open(lastimage) #ouvre /home/chezvous/.focus
x,y=image.size
print str(x) + " " + str(y)
X,Y=int((x*600.0)/y),600 #redimensionne l'image en 600*400
print str(X) + " " + str(Y)
image=image.resize((X,Y),Image.BICUBIC)
photo=ImageTk.PhotoImage(image) #creer le conteneur de l'imageTK
fenetre2=Toplevel() #ouvre une nouvelle fenetre
PartieImage = Canvas(fenetre2,bg='grey', width=X+1, height=Y+1) #fait un canevas ds la nouvelle fenetre
id=PartieImage.create_image(0,0,anchor = NW,image=photo, tags="canvasimage") #affiche l'image avec pour tag canvasimage
print "id =" + str(id) #affiche l'id de l'image
PartieImage.tag_bind('canvasimage',"<Button-1>", appui) #NE FONCTIONNE PAS : tente de lier a canvasimage l'evenement d'appui
PartieImage.pack()
fenetre2.update () #j'ai trouvé que ca pour afficher l'image
time.sleep(30)
fenetre.destroy()#code de debug
def principal():
"initialise les fenetres et detecte les appareils photos connectes"
status,listeAppareil=commands.getstatusoutput('gphoto2 --auto-detect') #recupere la liste des appareils
listeAppareil=listeAppareil.split()
i=len(listeAppareil)-4
appareil=''
while i<len(listeAppareil)-1:
appareil=appareil + ' '+ listeAppareil[i]
i=i+1
informations.configure(text = "Appareil : " + appareil + " pret")
#creation du bouton de recuperation d'images
Button(partiehaute, text="recuperer la derniere image", command=recupDerniereImage).pack()
def verifieAPN():
status,listeAppareil=commands.getstatusoutput('gphoto2 --auto-detect') #recupere la liste des appareils
listeAppareil=listeAppareil.split()
print listeAppareil
if (len(listeAppareil) > 3) :
appareilOK=True
else:
appareilOK=False
return appareilOK
def creerRepertoire():
home = os.getenv("HOME")
os.chdir(home)
focus=home+"/.focus"
status,output=commands.getstatusoutput('cd '+focus)
print status
if (status==0):
print "focus OK"
else:
print "focus NOK"
os.mkdir(focus)
print "focuss OK"
#------programme principal---------------- Main
#Creation des repertoires de travail
creerRepertoire()
fenetre=Tk() #fenetre principale
fenetre.title("Focus, aide a la mise au point")
informations=Label(fenetre) #fenetre d'informations
informations.pack()
partiehaute=Canvas(fenetre,bg='dark grey')
partiehaute.pack()
informations.configure(text = "Appareil non pret.")
fenetre.update()
#while verifieAPN()==False:
# fenetre.update()
# informations.configure(text = "Appareil non pret.")
# time.sleep(5)
principal()
fenetre.mainloop() |