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
|
# Modules
from tkinter import *
from tkinter import ttk
from tkinter.filedialog import *
from openpyxl import load_workbook
import os, time
from os import listdir
import win32file
import win32event
import win32con
import threading, time
from os.path import isfile, join
RepertoireASurv="."
EleveCourant=""
before=[""]
after=[""]
IndiceEleveCourant=0
toto=""
# Fonctions
def ouvrir_fichier():
global EleveCourant, IndiceEleveCourant, before, RepertoireASurv
FichierExcel = askopenfilename(title="Choisir une liste d'élèves",filetypes=[('Excel files','.xlsx'),('all files','.*')])
if FichierExcel:
Fichier = load_workbook(FichierExcel)
Feuille = Fichier.active
i=1
LabelNomFichier['text']=FichierExcel
liste.delete(0,END)
for row in Feuille.iter_rows(min_row = 2, min_col = 1, max_col = 4, values_only=True):
Eleve = row[0]+' '+row[1]+' '+row[2]
liste.insert(i,Eleve)
i=i+1
liste.selection_set(0)
EleveCourant = liste.get(ACTIVE).replace(" ","_")
IndiceEleveCourant = liste.curselection()
RepertoireASurv = askdirectory(title="Choisir le répertoire de prise de vue")
if RepertoireASurv:
LabelRepertoire['text']=RepertoireASurv
before = [f for f in listdir(RepertoireASurv) if isfile(join(RepertoireASurv, f))]
def selection_eleve(self):
global EleveCourant, after, before, RepertoireASurv, IndiceEleveCourant
print("Traitement eleve")
# Renommer les fichiers de l'élève précédent
after = [f for f in listdir(RepertoireASurv) if isfile(join(RepertoireASurv, f))]
added = [f for f in after if not f in before]
if added:
for fichier in added:
NouveauFichier = EleveCourant + "_" + fichier[-8:]
renommerOK=False
while not renommerOK:
try :
os.rename(RepertoireASurv+'/'+fichier,RepertoireASurv+'/'+NouveauFichier)
renommerOK=True
except IOError :
#fichier occupé
renommerOK=False
liste.itemconfigure(IndiceEleveCourant,background="#5afb55")
before = [f for f in listdir(RepertoireASurv) if isfile(join(RepertoireASurv, f))]
# Nouvel élève sélectionné
IndiceEleveCourant = liste.curselection()
liste.activate(IndiceEleveCourant)
EleveCourant = liste.get(ACTIVE).replace(" ","_")
def quitter():
selection_eleve(toto)
Photoscol.destroy()
# Initialisations
# Widgets et code
Photoscol = Tk()
Photoscol.title('Photoscol')
Photoscol.geometry('565x800')
#Bouton choix fichier élèves
BoutonFichier = Button(Photoscol, text="Fichier élèves", command=ouvrir_fichier, width=20)
BoutonFichier.grid(row=0, column = 0,sticky=NW, padx=10, pady=10)
#Liste d'élèves en cours
LabelNomFichier = Label(Photoscol, text="Choisir un fichier élèves", bg='#ffffff', width=52, anchor="w")
LabelNomFichier.grid(row=0, column=1, sticky=NW, padx=10, pady=10)
#Répertoire à surveiller
LabelRepertoireASurveiller = Label(Photoscol, text="Répertoire de prise de vue", bg='#f0f0f0', width=20, anchor="w")
LabelRepertoireASurveiller.grid(row=1, column=0, sticky=NW, padx=10, pady=10)
#Chemin Répertoire à surveiller
LabelRepertoire = Label(Photoscol, text="Répertoire de prise de vue", bg='#ffffff', width=52, anchor="w")
LabelRepertoire.grid(row=1, column=1, sticky=NW, padx=10, pady=10)
#Affichage liste élèves
liste = Listbox(Photoscol, width=90, bg="Ivory", height=40)
liste.grid(row=3, columnspan=2, sticky=NW, padx=10)
#Sortir de l'appli
BoutonQuitter = Button(Photoscol, text='Quitter', width=70, command=quitter)
BoutonQuitter.grid(row=4, columnspan=2, padx=10, pady=20)
liste.bind('<<ListboxSelect>>',selection_eleve)
Photoscol.mainloop()
# Fin widget et code |
Partager