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
|
classModifHeader:
# constructeur
header_info =""
file_image = ""
def__init__(self):
"le constructeur"
defpopup(self, headerTest, fileImage):
"""affiche dans une deuxieme fenetre le header
Parameters
----------
self :
headerTest : string
le header
fileImage : string
le chemin du fichier fit
"""
ModifHeader.file_image = fileImage
fInfos = Toplevel() # Popup -> Toplevel()
fInfos.title('Modifier header')
fInfos.config( bg="black")
cadre = Frame(fInfos, borderwidth=1,bg="black")
cadre.pack(fill=BOTH)
#le label contenant les info
scrollbarY = Scrollbar(cadre, activebackground ="white", bg="black", cursor="double_arrow", highlightbackground = "black", troughcolor ="black")
scrollbarY.pack(side=RIGHT, fill=Y)
scrollbarX = Scrollbar(cadre, orient='horizontal', activebackground ="white", bg="black", cursor="double_arrow", highlightbackground = "black", troughcolor ="black")
scrollbarX.pack(side=BOTTOM, fill=X)
ModifHeader.header_info = Text(cadre, bg="black",fg="white", cursor="xterm", insertbackground="white", undo="true", wrap='none', yscrollcommand=scrollbarY.set, xscrollcommand=scrollbarX.set)
scrollbarX.config(command=ModifHeader.header_info.xview)
ModifHeader.header_info.insert('1.0', repr(headerTest))
ModifHeader.header_info.pack(padx=10,pady=10)
#les bouton qui sont dans une frame
boutons = Frame(fInfos,borderwidth=1,bg="black")
boutons.pack(padx=10,pady=10,fill=X)
annuler = Button(boutons, text='Annuler',bg="black",fg="white", command=fInfos.destroy)
annuler.pack(side=RIGHT,padx=10,pady=10)
valider = Button(boutons, text='Valider',bg="black",fg="white", command=ModifHeader.valider)
valider.pack(side=LEFT,padx=10,pady=10)
defvalider():
"""Pour modifier le header
Parameters
----------
"""
contents = ModifHeader.header_info.get('1.0','end')#recupere le text ecrit par l'utilisateur
while( contents.find('\n') != -1):
posLigne = contents.find('\n') #recupeere ligne par ligne les information
ligne = contents[0:posLigne]
contents= contents[posLigne+1:len(contents)]
nom = ligne[0: (ligne.find("=")-1)]
contenu = ligne [(ligne.find("=")+1): len(ligne)]
#permet d'enregistrer mais ne marche pas
with fits.open(ModifHeader.file_image, 'update') as f:
for hdu in f:
hdu.header[nom]=contenu
showerror("header erreur", "Cette fonctionalité n'est pas disponible") |
Partager