diff --git a/.gitignore b/.gitignore index 510085e..379f855 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ Cleopatra/Isotope Cleopatra/PlotTGraphTObjArray __pycache__ +IAEA_NuclearData.csv \ No newline at end of file diff --git a/PyGUIQt6/IAEANuclearData.py b/PyGUIQt6/IAEANuclearData.py index 730aa9b..63427ff 100644 --- a/PyGUIQt6/IAEANuclearData.py +++ b/PyGUIQt6/IAEANuclearData.py @@ -10,12 +10,14 @@ mp = 938.27208816 # +- 29 mn = 939.56542052 # +- 54 ma = 3727.37915 -class Isotope: - def __int__(self): - +class IsotopeClass: + def __init__(self): self.livechart = "https://nds.iaea.org/relnsd/v0/data?" self.data = None + self.DownloadData() + + def DownloadData(self): # Read the saved CSV file back into a DataFrame try : self.data = pd.read_csv('IAEA_NuclearData.csv') @@ -163,7 +165,7 @@ class Isotope: print(" Sa: %9.2f MeV" % self.GetSa(ASym)) print("=============================") - def PrintIsoWeb(self, ASym : str): + def PrintIsoHTML(self, ASym : str): [A, Z] = self.GetAZ(ASym) print("
========================= ", ASym) print("
A : %d, Z : %d, N : %d" % (A, Z, A-Z)) diff --git a/PyGUIQt6/PtolemyGUIPy.py b/PyGUIQt6/PtolemyGUIPy.py index a6aae6a..c52ef41 100755 --- a/PyGUIQt6/PtolemyGUIPy.py +++ b/PyGUIQt6/PtolemyGUIPy.py @@ -4,6 +4,7 @@ import os import platform import subprocess import sys +import time from functools import partial from PyQt6.QtWidgets import ( QApplication, QMainWindow, QGridLayout, QPushButton, @@ -41,6 +42,7 @@ class PlotWindow(QWidget): self.showMarker_checkBox = QCheckBox("Show Markers") self.showMarker_checkBox.stateChanged.connect(self.plot_plotly_graph) + self.html_file = None self.web_view = QWebEngineView() layout = QGridLayout(self) @@ -83,6 +85,10 @@ class PlotWindow(QWidget): # print(self.headers) def plot_plotly_graph(self): + + if self.html_file and os.path.exists(self.html_file): + os.remove(self.html_file) + # Create a Plotly figure fig = go.Figure() @@ -145,13 +151,16 @@ class PlotWindow(QWidget): ) # Save the plot as an HTML file in a temporary location - with tempfile.NamedTemporaryFile(delete=False, suffix=".html") as tmp_file: - fig.write_html(tmp_file.name) - html_file = tmp_file.name - - # Load the HTML file in QWebEngineView + timestamp = int(time.time() * 1000) # Unique timestamp in milliseconds + html_file = f"/tmp/plotwindow_{timestamp}.html" + fig.write_html(html_file) + self.html_file = html_file # Store for cleanup self.web_view.setUrl(QUrl.fromLocalFile(html_file)) + def __del__(self): + if os.path.exists(self.html_file): + os.remove(self.html_file) + ################################################## MainWindow class MyWindow(QMainWindow): def __init__(self): @@ -314,20 +323,6 @@ class MyWindow(QMainWindow): def file_exists(self,file_path): return os.path.exists(file_path) and os.path.isfile(file_path) - - def A_file_changed_after_B_file(self, file_a, file_b): - try: - modified_time_a = os.path.getmtime(file_a) - modified_time_b = os.path.getmtime(file_b) - - # Compare the modification times - return modified_time_a > modified_time_b - except FileNotFoundError as e: - print(f"Error: {e}") - return False - except Exception as e: - print(f"An error occurred: {e}") - return False def CalDWBA(self): @@ -367,10 +362,7 @@ class MyWindow(QMainWindow): # self.BashCommand("../Cleopatra/ExtractXSec " + self.DWBAFileName + ".out " + option) if self.chkPlot.isChecked() and self.file_exists(self.DWBAFileName + ".Xsec.txt") : - if self.A_file_changed_after_B_file(self.DWBAFileName + ".Xsec.txt", self.DWBAFileName + ".out") : - self.open_plot_window() - else: - self.leStatus.setText( self.DWBAFileName + ".Xsec.txt is not newer than " + self.DWBAFileName + ".out") + self.open_plot_window() def open_plot_window(self): if self.plot_window is None : @@ -385,6 +377,7 @@ class MyWindow(QMainWindow): def closeEvent(self, event): if self.plot_window: self.plot_window.close() # Close the PlotWindow when MainWindow closes + self.plot_window.__del__() event.accept() # Accept the event to proceed with closing the main window diff --git a/PyGUIQt6/test.py b/PyGUIQt6/test.py index 82aade1..1e7a4d9 100755 --- a/PyGUIQt6/test.py +++ b/PyGUIQt6/test.py @@ -1,7 +1,11 @@ #!/usr/bin/python3 -from IAEANuclearData import Isotope +from IAEANuclearData import IsotopeClass -iso = Isotope() +iso = IsotopeClass() -iso.PrintIso('16O') \ No newline at end of file +iso.PrintIso('16O') + +pd = iso.GetExList('16O', 10) + +print(pd) \ No newline at end of file