La modération vous a écrit: Titre modifié pour plus de clarté : merci d'éviter les redondances inutiles.
Bonsoir,
Toujours et encore le script python d' extraction de données exif. Ce script rempli sa fonction. Le fichier contenant les données et bien créer. Par contre,à la fin de l' exécution de se script, je rencontre un problème:
La fenêtre de sélection d' un fichier s' ouvre à nouveau.
J' ai tenté de résoudre ce problème en utilisant successivement les méthodes suivantes:
quit(), exit(), sys.exit(), sys.exit(0), os._exit()
A chaque fois, j' ai le message d' erreur suivant la pièce jointe.
Pour info, le script à, malgré tout fonctionné. J' ai bien un fichier .txt contenant les données recherchées.
Je vous joins également le script dans sa dernière version mais pas finale.
Code : Tout sélectionner
#!/usr/bin/env python3
from uno import *
from exiftool import *
from datetime import datetime
from fractions import *
from sys import *
from os import chdir
# Sélectionner une photographie
fchslc = ' '
def fntslc(event=None):
ctx = XSCRIPTCONTEXT.getComponentContext()
create = ctx.ServiceManager.createInstance
filepicker = create("com.sun.star.ui.dialogs.FilePicker")
filepicker.execute()
global fchslc
fchslc = filepicker.Files[0]
dtpht = ' ';hrpht = ' '; exp = ' '; vlrfcl = ' '; vlrlngfcl = ' '; vrtbjc = ' '
pstfls = ' '; tpbjc = ' '
def dnxf():
# Extraction de la date et de l' heure de prise de vue
dt = datetime.strptime(dtcrt,"%Y:%m:%d %H:%M:%S")
global dtpht; global hrpht
dtpht = dt.strftime('%d-%m-%Y')
hrpht = dt.strftime('%H:%M:%S')
# Temps d' exposition
global exp
#x = int(1 / tmpxps)
#exp = Fraction(1, x)
# Valeur de focale
global vlrfcl
vlrfcl = 'f '+ str(round(fcl, 1))
global vlrlngfcl
vlrlngfcl = str(lngfcl)+ ' mm'
global tpbjc
if bjc == 53:
tpbjc = 'Canon EF-S 18-55mm f/3.5-5.6 III'
elif bjc == 39:
tpbjc = 'Canon EF 75-300mm f/4-5.6'
else:
tpbjc = 'Inconnu'
global vrtbjc
#y = vrt
#vrtbjc = format(y, '0.1f')
# Valeur de flash
global pstfls
if flash == 16:
pstfls = 'Inactif'
else:
pstfls = 'Actif'
#Ouverture de la fenêtre de sélection d' un fichier
fntslc()
# Recherche des balises du chemin du fichier
bls = '/'
pstbls = fchslc.rfind(bls,0,10)
xbls = fchslc.count(bls)
i = 0
while i <= xbls:
pstbls1 = fchslc.rfind(bls)
i = i + 1
bls2 = '.'
pstbls2 = fchslc.rfind(bls2)
# Chemin du fichier
chmfch = fchslc[pstbls:pstbls1 + 1]
# Nom de la photo
nmpht = fchslc[pstbls1 + 1:pstbls2]
# Type d' extention du fichier
xtn = fchslc[pstbls2 + 1:]
#Extraction du fabricant de l' appareil
chmfchslc = fchslc[pstbls:]
with ExifTool() as e:
marque = e.get_tag('Make', chmfchslc)
if marque == None:
print ("Il n' y a pas de données exif pour cette photographie !")
marque = 'Inconnue'; mdl = 'Inconnue'; dtpht = 'Inconnue'; hrpht = 'Inconnue'
dmspht = 'Inconnue'; tmpxps = 'Inconnue'; fcl = 'Inconnue'; lngfcl = 'Inconnue'
iso = 'Inconnue'; vrtbjc = 'Inconnue'; lmn = 'Inconnue'; flash = 'Inconnue'
bjc = 'Inconnue'
elif marque == 'Canon':
with ExifTool() as e:
mdl = e.get_tag('Model', chmfchslc) # Modèle appareil
dtcrt = e.get_tag('DateTimeOriginal', chmfchslc)# Date et heure prise de vue
dmspht = e.get_tag('ImageSize', chmfchslc) # Dimension de la photo
tmpxps = e.get_tag('ExposureTime', chmfchslc) # Temps d' exposition
fcl = e.get_tag('FNumber', chmfchslc) # Focale
lngfcl = e.get_tag('FocalLength', chmfchslc) # Longueur de focale
iso = e.get_tag('Iso', chmfchslc) # Sensibilité
vrt = e.get_tag('ApertureValue', chmfchslc) # Ouverture objectif
lmn = e.get_tag('LightValue', chmfchslc) # Luminosité
flash = e.get_tag('Flash', chmfchslc) # Position flash
bjc = e.get_tag('LensType', chmfchslc) # Objectif utilisé
dnxf()
elif marque == 'FUJIFILM':
with ExifTool() as e:
mdl = e.get_tag('Model', chmfchslc) # Modèle appareil
dtcrt = e.get_tag('DateTimeOriginal', chmfchslc)# Date et heure prise de vue
dmspht = e.get_tag('ImageSize', chmfchslc) # Dimension de la photo
tmpxps = e.get_tag('ExposureTime', chmfchslc) # Temps d' exposition
fcl = e.get_tag('FNumber', chmfchslc) # Focale
lngfcl = e.get_tag('FocalLength', chmfchslc) # Longueur de focale
iso = e.get_tag('Iso', chmfchslc) # Sensibilité
vrt = e.get_tag('ApertureValue', chmfchslc) # Ouverture objectif
lmn = e.get_tag('LightValue', chmfchslc) # Luminosité
flash = e.get_tag('Flash', chmfchslc) # Position flash
bjc = e.get_tag('LensType', chmfchslc) # Objectif utilisé
dnxf()
else:
with ExifTool() as e:
mdl = e.get_tag('Model', chmfchslc) # Modèle appareil
dtcrt = e.get_tag('DateTimeOriginal', chmfchslc)# Date et heure prise de vue
dmspht = e.get_tag('ImageSize', chmfchslc) # Dimension de la photo
tmpxps = e.get_tag('ExposureTime', chmfchslc) # Temps d' exposition
fcl = e.get_tag('FNumber', chmfchslc) # Focale
lngfcl = e.get_tag('FocalLength', chmfchslc) # Longueur de focale
iso = e.get_tag('Iso', chmfchslc) # Sensibilité
vrt = e.get_tag('ApertureValue', chmfchslc) # Ouverture objectif
lmn = e.get_tag('LightValue', chmfchslc) # Luminosité
flash = e.get_tag('Flash', chmfchslc) # Position flash
bjc = e.get_tag('LensType', chmfchslc) # Objectif utilisé
dnxf()
# Creation du fichier de sauvegarde
chdir('/home/elfouste/Documents/Python/MacroPython/Tst_Fch')
fch = 'FchDn.txt'
with open('FchDn.txt', 'w') as fch:
fch.write(chmfch)
fch.write(' - ')
fch.write(nmpht)
fch.write(' - ')
fch.write(xtn)
fch.write(' - ')
fch.write(marque)
fch.write(' - ')
fch.write(mdl)
fch.write(' - ')
fch.write(dtpht)
fch.write(' - ')
fch.write(hrpht)
fch.write(' - ')
fch.write(str(dmspht))
fch.write(' - ')
# fch.write(str(exp))
fch.write(' - ')
fch.write(str(vlrfcl))
fch.write(' - ')
fch.write(str(vlrlngfcl))
fch.write(' - ')
fch.write(str(iso))
fch.write(' - ')
fch.write(str(tpbjc))
fch.write(' - ')
# fch.write(str(vrtbjc))
# fch.write(str(lmn))
fch.write(' - ')
fch.write(pstfls)
quit()
Cordialement