Пример #1
0
def mise_a_jour_interface():
    fichier1 = read_file_path(1)
    fichier2 = read_file_path(2)

    #Ici, on regarde si le chemin du fichier est vide, si c'est le cas, on affiche un message d'attention, sinon on affiche le chemin du fichier.
    if fichier1 != "":
        button_file1.configure(fg="green")
        button_display.configure(state="normal")
        button_save.configure(state="normal")
        button_display_windows.configure(state="normal")

        menubar.entryconfigure(2, state=NORMAL)
        menubar.entryconfigure(3, state=NORMAL)
    else:
        button_file1.configure(fg="#F3421C")
    if fichier2 != "":

        button_file2.configure(fg="green")
        button_display.configure(state="normal")
        button_save.configure(state="normal")
        button_display_windows.configure(state="normal")

        menubar.entryconfigure(2, state=NORMAL)
        menubar.entryconfigure(3, state=NORMAL)
    else:
        button_file2.configure(fg="#F3421C")

    if fichier1 == "" and fichier2 == "":
        button_display.configure(state="disabled")
        button_save.configure(state="disabled")
        button_display_windows.configure(state="disabled")
        menubar.entryconfigure(2, state=DISABLED)
        menubar.entryconfigure(3, state=DISABLED)
    fenetre.update_idletasks()
Пример #2
0
def generate_graph(dimension, fichier, b=False):
    
    graphique = True
    
    #On ouvre les fichiers contenant les chemins des deux fichiers selectionné
    #On ouvre le fichier 1
    fichier1 = read_file_path(1)
    #On ouvre le fichier 2
    fichier2 = read_file_path(2)
    
    #On importe les vecteurs de valeurs
    reel1= np.loadtxt(r'data/matrix/r1.vec')
    imaginaire1 = np.loadtxt(r'data/matrix/i1.vec')
    reel2 = np.loadtxt(r'data/matrix/r2.vec')
    imaginaire2 = np.loadtxt(r'data/matrix/i2.vec')
    w, h =read_resolution()
    axe = plt.figure(1, figsize=(w, h))
    a = plt.subplot(1, 1, 1)
    
    
    if dimension == 2:
        if fichier1 != "":
            plt.scatter(reel1, imaginaire1, c = 'black', marker = 'o', s = 200, label="Original solution")
            graphique = True
        if fichier2 != "":
            plt.scatter(reel2, imaginaire2, c = 'red', marker = '+', s = 200, label="Final solution")
            graphique = True
        
    elif dimension == 1:
            
            if fichier1 != "":
                plt.scatter(reel1, imaginaire1, c = 'black', marker = 'o', s = 200, label="Original solution")
                graphique = True
            if fichier2 != "":
                plt.scatter(reel2, imaginaire2, c = 'red', marker = '+', s = 200, label="Final solution")
                graphique = True
    else: 
        messagebox.showerror("Error", "Impossible to generate the graph, the dimension is incorrect")
        graphique = False
        
    #Si tout est ok pour l'enregistrement, on savegarde le graphique
    if graphique == True :
        if b == True:
            u = np.loadtxt(r'data/custom/axe.vec')
            a.set_xlim(u[0], u[1])
            a.set_ylim(u[2], u[3])
        plt.legend(loc='best')
        plt.savefig(fichier, dpi=300)
        plt.show()
    return graphique
Пример #3
0
def open_file(number):

    #On charge les chemins déjà présent
    if number == 1:
        fichier = read_file_path(1)
    else:
        fichier = read_file_path(2)
    #On enregistre ce que contient l'adresse du fichier précédente
    fichier_precedent = fichier

    #On demande à l'utilisateur de choisir son fichier texte
    fichier = filedialog.askopenfilename(filetypes=[('Text file', '.txt')])

    #Si le fichier choisi est différent du fichier précédent alors le graphique n'est plus valable, on va donc pouvoir en refaire un et mettre à jour l'affichage.
    if fichier_precedent != fichier:
        file = open("data/files/file" + str(number) + ".txt", "w")
        file.write(fichier)
Пример #4
0
def mise_a_jour_interface():
    fichier1 = read_file_path(1)
    fichier2 = read_file_path(2)

    #Nettoyage du canves affichant les adresses
    can.delete(ALL)

    #Ici, on regarde si le chemin du fichier est vide, si c'est le cas, on affiche un message d'attention, sinon on affiche le chemin du fichier.
    if fichier1 != "":
        text_1 = can.create_text(400, 10, text=fichier1, fill="black")
    else:
        text_1 = can.create_text(400,
                                 10,
                                 text="Warning : No original file selected",
                                 fill="red")
    if fichier2 != "":
        text_2 = can.create_text(400, 30, text=fichier2, fill="black")
    else:
        text_2 = can.create_text(400,
                                 30,
                                 text="Warning : No final file selected",
                                 fill="red")
    fenetre.update_idletasks()
Пример #5
0
def display_graph_ext(dimension, b=False):

    root = Tk.Tk()
    root.wm_title("SMG2S UI")

    graphique = True

    #On ouvre les fichiers contenant les chemins des deux fichiers selectionnes
    #On ouvre le fichier 1
    fichier1 = read_file_path(1)
    #On ouvre le fichier 2
    fichier2 = read_file_path(2)

    print(fichier1, " & ", fichier2)

    f = Figure(figsize=(8, 6), dpi=100)
    a = f.add_subplot(1, 1, 1)

    reel1 = loadtxt(r'data/matrix/r1.vec')
    imaginaire1 = loadtxt(r'data/matrix/i1.vec')
    reel2 = loadtxt(r'data/matrix/r2.vec')
    imaginaire2 = loadtxt(r'data/matrix/i2.vec')

    if dimension == 2:
        if fichier1 != "":
            a.scatter(reel1,
                      imaginaire1,
                      c='black',
                      marker='o',
                      s=200,
                      label="Initial Eigenvalues")
            graphique = True
        if fichier2 != "":
            a.scatter(reel2,
                      imaginaire2,
                      c='red',
                      marker='+',
                      s=200,
                      label="Computed Eigenvalues")
            graphique = True

    elif dimension == 1:

        if fichier1 != "":
            a.scatter(reel1,
                      imaginaire1,
                      c='black',
                      marker='o',
                      s=200,
                      label="Initial Eigenvalues")
            graphique = True
        if fichier2 != "":
            a.scatter(reel2,
                      imaginaire2,
                      c='red',
                      marker='+',
                      s=200,
                      label="Computed Eigenvalues")
            graphique = True
    else:
        Tk.messagebox.showerror(
            "Error",
            "Impossible to generate the graph, the dimension is incorrect")
        graphique = False
    if graphique == True:
        if b == True:
            u = loadtxt(r'data/custom/axe.vec')
            a.set_xlim(u[0], u[1])
            a.set_ylim(u[2], u[3])
        a.legend(bbox_to_anchor=(0, 1.02, 1, .102),
                 loc=3,
                 ncol=2,
                 borderaxespad=0)
        show()

    # a tk.DrawingArea
    canvas = FigureCanvasTkAgg(f, master=root)
    canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)

    toolbar = NavigationToolbar2TkAgg(canvas, root)
    toolbar.update()
    canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)

    def on_key_event(event):
        print('you pressed %s' % event.key)
        key_press_handler(event, canvas, toolbar)

    canvas.mpl_connect('key_press_event', on_key_event)

    def _quit():
        root.quit()  # stops mainloop
        root.destroy()  # this is necessary on Windows to prevent
        # Fatal Python Error: PyEval_RestoreThread: NULL tstate

    button = Tk.Button(master=root, text='Quit', command=_quit)
    button.pack(side=Tk.BOTTOM)

    Tk.mainloop()
Пример #6
0
def read_files():
    #On ouvre le fichier 1
    fichier1 = read_file_path(1)
    #On ouvre le fichier 2
    fichier2 = read_file_path(2)

    exp = r"[0-9]+(\.)?[0-9]*"
    # Booléen qui permet de stocker si on a déjà rencontré la ligne de la dimension.
    premiere_ligne = False
    dimension = 0
    if fichier1 == "" and fichier2 == "":
        messagebox.showerror("Error", "No files were opened")
        return -1
    else:
        if fichier1 != "":
            presence_fichier1 = True
            with open(fichier1, "r") as f:
                for line in f.readlines():
                    donnees = line.split()

                    #On regarde si le premier caractère n'est pas un espace est un chiffre
                    print(re.match(exp, donnees[0]))
                    if re.match(exp, donnees[0]) is not None:
                        if premiere_ligne == False:
                            premiere_ligne = True
                            dimension = 0
                            for x in line.split(" "):
                                if re.match(exp, x):
                                    dimension += 1
                            dimension = dimension - 1
                            print("Dimension : ", dimension,
                                  "premiere_ ligne : ", premiere_ligne)
                            #On créé les vecteurs qui stockera les informations a afficher
                            reel1 = []
                            imaginaire1 = []

                        else:
                            reel1.append(Decimal(donnees[1]))
                            if dimension == 2:
                                imaginaire1.append(Decimal(donnees[2]))
                            else:
                                imaginaire1.append(0)

            np.savetxt(r'data/matrix/r1.vec', reel1)
            np.savetxt(r'data/matrix/i1.vec', imaginaire1)
        else:
            presence_fichier1 = False
            messagebox.showwarning("Warning",
                                   "The original file is not loaded")

        premiere_ligne = False
        if fichier2 != "":
            presence_fichier2 = True
            with open(fichier2, "r") as f:
                for line in f.readlines():
                    donnees = line.split()

                    #On regarde si le premier caractère n'est pas un espace est un chiffre
                    print(re.match(exp, donnees[0]))
                    if re.match(exp, donnees[0]) is not None:
                        if premiere_ligne == False:
                            premiere_ligne = True
                            ancienne_dimension = dimension
                            dimension = 0
                            for x in line.split(" "):
                                if re.match(exp, x):
                                    dimension += 1
                            dimension = dimension - 1
                            #On créé les vecteurs qui stockera les informations a afficher
                            reel2 = []
                            imaginaire2 = []

                        else:
                            reel2.append(Decimal(donnees[1]))
                            if dimension == 2:
                                imaginaire2.append(Decimal(donnees[2]))
                            else:
                                imaginaire2.append(0)
            f.close
            np.savetxt(r'data/matrix/r2.vec', reel2)
            np.savetxt(r'data/matrix/i2.vec', imaginaire2)
        else:
            presence_fichier2 = False
            messagebox.showwarning("Warning", "The final file is not loaded")
        if presence_fichier1 == presence_fichier2 == True:
            if ancienne_dimension != dimension:
                messagebox.showwarning(
                    "Error",
                    "The selected files are not the same size. Please check the files"
                )
                return -1
            else:
                return dimension
        else:
            return dimension
Пример #7
0
def generate_graph(dimension):

    graphique = True

    #On ouvre les fichiers contenant les chemins des deux fichiers selectionné
    #On ouvre le fichier 1
    fichier1 = read_file_path(1)
    #On ouvre le fichier 2
    fichier2 = read_file_path(2)

    #On importe les vecteurs de valeurs
    reel1 = np.loadtxt(r'data/matrix/r1.vec')
    imaginaire1 = np.loadtxt(r'data/matrix/i1.vec')
    reel2 = np.loadtxt(r'data/matrix/r2.vec')
    imaginaire2 = np.loadtxt(r'data/matrix/i2.vec')
    plt.figure(1, figsize=(8, 6))
    plt.subplot(1, 1, 1)
    if dimension == 2:
        if fichier1 != "":
            plt.scatter(reel1,
                        imaginaire1,
                        c='black',
                        marker='o',
                        s=200,
                        label="Original solution")
            graphique = True
        if fichier2 != "":
            plt.scatter(reel2,
                        imaginaire2,
                        c='red',
                        marker='+',
                        s=200,
                        label="Final solution")
            graphique = True

    elif dimension == 1:

        if fichier1 != "":
            plt.scatter(reel1,
                        imaginaire1,
                        c='black',
                        marker='o',
                        s=200,
                        label="Original solution")
            graphique = True
        if fichier2 != "":
            plt.scatter(reel2,
                        imaginaire2,
                        c='red',
                        marker='+',
                        s=200,
                        label="Final solution")
            graphique = True
    else:
        messagebox.showerror(
            "Error",
            "Impossible to generate the graph, the dimension is incorrect")
        graphique = False
    if graphique == True:
        plt.legend(loc='best')
        plt.savefig('data/graphic_brut.png', dpi=500)
        plt.show()
    return graphique
Пример #8
0
def display_graph_int(dimension, root, canvas, b=False):

    for w in root.winfo_children():
        w.destroy()
    graphique = True

    #On ouvre les fichiers contenant les chemins des deux fichiers selectionnes
    #On ouvre le fichier 1
    fichier1 = read_file_path(1)
    #On ouvre le fichier 2
    fichier2 = read_file_path(2)

    print(fichier1, " & ", fichier2)

    f = Figure(figsize=(8, 6), dpi=100)
    a = f.add_subplot(1, 1, 1)

    reel1 = loadtxt(r'data/matrix/r1.vec')
    imaginaire1 = loadtxt(r'data/matrix/i1.vec')
    reel2 = loadtxt(r'data/matrix/r2.vec')
    imaginaire2 = loadtxt(r'data/matrix/i2.vec')

    if dimension == 2:
        if fichier1 != "":
            a.scatter(reel1,
                      imaginaire1,
                      c='black',
                      marker='o',
                      s=200,
                      label="Original solution")
            graphique = True
        if fichier2 != "":
            a.scatter(reel2,
                      imaginaire2,
                      c='red',
                      marker='+',
                      s=200,
                      label="Final solution")
            graphique = True

    elif dimension == 1:

        if fichier1 != "":
            a.scatter(reel1,
                      imaginaire1,
                      c='black',
                      marker='o',
                      s=200,
                      label="Original solution")
            graphique = True
        if fichier2 != "":
            a.scatter(reel2,
                      imaginaire2,
                      c='red',
                      marker='+',
                      s=200,
                      label="Final solution")
            graphique = True
    else:
        Tk.messagebox.showerror(
            "Error",
            "Impossible to generate the graph, the dimension is incorrect")
        graphique = False
    if graphique == True:
        if b == True:
            u = loadtxt(r'data/custom/axe.vec')
            a.set_xlim(u[0], u[1])
            a.set_ylim(u[2], u[3])
        show()

    # a tk.DrawingArea
    canvas = FigureCanvasTkAgg(f, master=root)
    canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)

    toolbar = NavigationToolbar2TkAgg(canvas, root)
    toolbar.update()
    canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)

    def on_key_event(event):
        print('you pressed %s' % event.key)
        key_press_handler(event, canvas, toolbar)

    canvas.mpl_connect('key_press_event', on_key_event)

    def _quit():
        #        canvas.quit()     # stops mainloop
        #        canvas.destroy()  # this is necessary on Windows to prevent
        # Fatal Python Error: PyEval_RestoreThread: NULL tstate
        for w in root.winfo_children():
            w.destroy()

    button = Tk.Button(master=root, text='Quit', command=_quit)
    button.pack(side=Tk.BOTTOM)

    Tk.mainloop()


# If you put root.destroy() here, it will cause an error if
# the window is closed with the window manager.