conn.py 5.85 KB
import testPostgres as pf
import traceback
import sys
from tkinter import *
from tkinter import ttk, messagebox
import pandas as pd
import json
#import excel2nc as ex
#bd.cursor.execute("select  nextval('seq_int')")
#resultat2=bd.cursor.fetchone()
#print(resultat2)
def geoliste(g):
    r=[i for i in range(0,len(g)) if not g[i].isdigit()]
    return [int(g[0:r[0]]),int(g[r[0]+1:r[1]]),int(g[r[1]+1:r[2]]),int(g[r[2]+1:])]
def centrefenetre(fen):
    fen.update_idletasks()
    l,h,x,y=geoliste(fen.geometry())
    fen.geometry("%dx%d%+d%+d" % (l,h,(fen.winfo_screenwidth()-l)//2,(fen.winfo_screenheight()-h)//2))

class ConnGraphic(Tk):

    def __init__(self):
        Tk.__init__(self)
        #self.minsize(1200,700)
        self.title('connexion a la base de donnees')
        self.creerWidgets()

##interface pour la mission
    def creerWidgets(self):
        self.mainWindow = Frame(self, bg="blue")
        self.mainWindow.pack(fill=BOTH, expand=1)
        self.frameSaisie = Frame(self.mainWindow, bg="blue")
        self.frameSaisie.pack(fill=BOTH)
        self.frameResult10 = Frame(self.mainWindow)
        self.frameResult10.pack(fill=BOTH)

        self.frameResult = Frame(self.frameResult10, bd=4, relief=SUNKEN)
        self.frameResult.pack(side=LEFT,fill=X)
        self.ent_label = Label(self.frameResult,font=('arial',50,'bold'),bd=4,bg="blue", fg="white", text="Information de connection:")
        #self.ent_label.configure(font=('Helvetica', 12),bg="blue", fg="white")
        self.ent_label.pack(side=TOP,padx=5, pady=5)

        self.frameResult00 = Frame(self.frameResult, bd=4, relief=SUNKEN)
        self.frameResult00.pack(fill=BOTH,padx=5, pady=5)
        self.modified_label53321 = Label(self.frameResult00,font=('arial',50,'bold'),bd=4, text = "host:")
        #self.modified_label53321.configure(font=('Helvetica', 12))
        #self.modified_label53321.pack(side=LEFT,padx=5, pady=5)
        self.modified5332100=StringVar()
        self.modified_entry53321= Entry(self.frameResult00,font=('arial',50,'bold'),textvariable=self.modified5332100)

        self.modified_label53321.grid(row =0)
        self.modified_entry53321.grid(row =0, column=1)
        #self.modified_entry53321.pack(side=LEFT,padx=5, pady=5)
        #self.modified_entry53321.focus()
        #self.frameResult21 = Frame(self.frameResult10, bd=2, relief=SUNKEN)
        #self.frameResult21.pack(side=LEFT,fill=Y)
        self.modified_label51 = Label(self.frameResult00,font=('arial',50,'bold'),bd=4, text = "db info:")
        #self.modified_label51.configure(font=('Helvetica', 12))
        #self.modified_label51.pack(side=LEFT,padx=25, pady=25)
        self.modified_label51.grid(row =1, column =0)

        self.modified51=StringVar()
        self.modified_entry51=Entry(self.frameResult00,font=('arial',50,'bold'),textvariable=self.modified51)
        self.modified_entry51.grid(row =1, column =1)
        self.modified_label4 = Label(self.frameResult00,font=('arial',50,'bold'),bd=4, text = "User:")
        #self.modified_label4.configure(font=('Helvetica', 12))
        #self.modified_label4.pack(side=LEFT,padx=25, pady=25)
        #self.modified_label4.grid(row =0,column =4)
        self.modified4=StringVar()
        self.modified_entry4 = Entry(self.frameResult00,font=('arial',50,'bold'),bd=4,textvariable=self.modified4)
        self.modified_entry4.grid(row =2, column =1)
        self.modified_label4.grid(row =2, column =0)
        #self.modified_entry4.pack(side=LEFT,padx=25, pady=25)
        #self.modified_entry4.focus()
    #    self.modified_entry4.grid(row =1,column =4)

        #self.frameResult2112 = Frame(self.frameResult, bd=2, relief=SUNKEN)
        #self.frameResult2112.pack(side=LEFT,fill=Y)
        self.modified_label5 = Label(self.frameResult00,font=('arial',50,'bold'),bd=4, text = "Password:")
        #self.modified_label5.configure(font=('Helvetica', 12))
        self.modified_label5.grid(row =3, column =0)

        #self.modified_label5.pack(side=LEFT,padx=25, pady=25)
        self.modified5=StringVar()
        self.modified_entry5= Entry(self.frameResult00,font=('arial',50,'bold'),textvariable=self.modified5,show="*")

        self.modified_entry5.grid(row =3, column =1)

        self.btnan = Button(self.mainWindow,font=('arial',50,'bold'),bd=4, text="Se connecter", bg="blue", fg="white", command=self.seconnecter)
        self.btnan.pack()
        #self.btntablenew = Button(self.mainWindow, text="initialiser",font=('arial',50,'bold'),bd=4, bg="blue", fg="white",command=self.nouveauD)
        #self.btntablenew.pack()

        #self.frameButtontable1 = Frame(self.frameSaisie, bg="blue")
        #self.frameButtontable1.pack(side=LEFT)
        #self.btnacceuille = Button(self.frameResult00, text="Acceuil",font=('arial',50,'bold'),bd=4, bg="red", fg="white",command=self.acceuil)
        #self.btnacceuille.grid(row=3,column=2)

        self.exit_button = Button(self.mainWindow,font=('arial',50,'bold'),bd=4,bg="red",fg="black", text = "Exit", command = self.destroy)
        self.exit_button.pack()


    def nouveauD(self):
        #self.dose.set("")
        self.modified5332100.set("")
        self.modified51.set("")
        self.modified4.set("")
        self.modified5.set("")
    def seconnecter(self):
        playlist = {}
        playlist["identifiant"] = {}
        playlist["identifiant"]["user"]=self.modified4.get()
        playlist["identifiant"]["password"]=self.modified5.get()
        playlist["dbinfo"] = {}
        playlist["dbinfo"]["db"]=self.modified51.get()
        playlist["dbinfo"]["host"]=self.modified5332100.get()
        with open('conn1.json', 'w', encoding='utf-8') as f:
            json.dump(playlist, f, indent=4)
        self.destroy()
        #ex.bd.cursor.execute("select nom from groupe order by nom")
        #resultat1=ex.bd.cursor.fetchall()
        #print("bonjour",resultat1)
        #a=pf.recupconf("conn1.json")
        #bd=pf.GestionBD(a[0],a[1],a[2],a[3])
        #print(a)