diff --git a/base.py b/base.py
index 3ccf6b2..4474eb7 100644
--- a/base.py
+++ b/base.py
@@ -26,7 +26,6 @@ from qtpy.QtWidgets import (QAction, QApplication, QDialog, QFrame, QLabel,
QProgressBar, QScrollArea, QSizePolicy,
QSplashScreen, QVBoxLayout, QWidget)
-
from pyqtacc.bdbase.utils import _line
from pyqtacc.bdbase.enumkind import Facility, MsgSeverity, UserMode
from pyqtacc.bdbase.helpbrowser import HelpBrowser
@@ -35,11 +34,9 @@ from pyqtacc.bdbase.savehdf import QSaveHDF
from pyqtacc.bdbase.hdf5filemenu import HDF5GroupBox
from pyqtacc.bdbase.sendelog import QSendToELOG
-
from pyqtacc.bdbase.screenshot import QScreenshot
from pyqtacc.bdbase.guiframe import GUIFrame
-
from caqtwidgets.pvwidgets import QNoDockWidget
import PyCafe
@@ -60,18 +57,6 @@ CENTRAL_WIDGET_MINIMUM_HEIGHT = 840
CENTRAL_WIDGET_MINIMUM_WIDTH = 1240
SLS_CENTRAL_WIDGET_MINIMUM_HEIGHT = 840
SLS_CENTRAL_WIDGET_MINIMUM_WIDTH = 940
-'''
-def _line():
- """Macro to return the current line number.
-
- The current line number within the file is used when
- reporting messages to the message logging window.
-
- Returns:
- int: Current line number.
- """
- return inspect.currentframe().f_back.f_lineno
-'''
class BaseWindow(QMainWindow):
""" BaseWindow
@@ -96,8 +81,9 @@ class BaseWindow(QMainWindow):
self.all_data = self.parent.all_data
self.all_data_2 = self.parent.all_data_2
- def __del__(self):
- self.wait()
+ #Causes QThread::wait: Thread tried to wait on itself
+ #def __del__(self):
+ # self.wait()
def run(self):
attach_files = []
@@ -110,6 +96,7 @@ class BaseWindow(QMainWindow):
def extract_and_attach(i, nfig, name, all_fig_data):
canvas = 'Canvas {0}'.format(i+1)
name_base = name.replace(' ', '_').lower()
+ write_message_fired = False
if all_fig_data[canvas] is not None:
nfig_canvas = len(all_fig_data[canvas])
@@ -143,7 +130,7 @@ class BaseWindow(QMainWindow):
attach_files.append(save_dest)
- write_message_fired = False
+
try:
resultsSeq = self.settings.data["GUI"]["resultsSeq"]
titleSeq = self.settings.data["GUI"]["subResultsTabTitle"]
@@ -154,7 +141,6 @@ class BaseWindow(QMainWindow):
except KeyError as ex:
pass
-
try:
resultsSeq = self.settings.data["GUI2"]["resultsSeq"]
titleSeq = self.settings.data["GUI2"]["subResultsTabTitle"]
@@ -165,8 +151,6 @@ class BaseWindow(QMainWindow):
except KeyError as ex:
pass
-
-
#Not so nice.. send a signal instead?
if attach_files:
self.parent.attach_files = attach_files
@@ -185,61 +169,81 @@ class BaseWindow(QMainWindow):
self.parent = parent
self.from_dialog=from_dialog
- def __del__(self):
- self.wait()
+ #Only a precaution, not experienced
+ #Causes QThread::wait: Thread tried to wait on itself
+ #def __del__(self):
+ # self.wait()
def run(self):
"""Run hdf thread
"""
QApplication.processEvents(QEventLoop.ExcludeUserInputEvents, 5000)
-
self.all_data = self.parent.all_data
#Reanalysis data
-
+
if self.all_data is not None:
- ts_in_seconds = self.all_data['Ambient data']['Time in seconds']
+ try:
+ if 'Time in seconds' in self.all_data['Ambient data']:
+ ts_in_seconds = self.all_data['Ambient data'][
+ 'Time in seconds']
+ else:
+ ts_in_seconds = None
+ except KeyError:
+ ts_in_seconds = None
+
now_in_seconds = None
from_hdf = False
- if 'Reanalysis time in seconds' in self.all_data['Processed data']:
- from_hdf = bool(self.all_data['Processed data']['Reanalysis time'])
- if from_hdf:
- now_in_seconds = self.all_data['Processed data'][
- 'Reanalysis time in seconds']
-
+
+ try:
+ if 'Reanalysis time in seconds' in self.all_data[
+ 'Processed data']:
+ from_hdf = bool(
+ self.all_data['Processed data']['Reanalysis time'])
+ if from_hdf:
+ now_in_seconds = self.all_data['Processed data'][
+ 'Reanalysis time in seconds']
+
+ #Double check
+ if not from_hdf:
+ if 'from_hdf' in self.all_data['Processed data']:
+ from_hdf = bool(self.all_data['Processed data'][
+ 'from_hdf'])
+
+ except KeyError:
+ now_in_seconds = None
+
+ self.parent.from_hdf = from_hdf
+
+ print("t=========================>", ts_in_seconds, " // ", now_in_seconds)
+ print("from hdf5=========================>", from_hdf)
+
if self.parent.hdf_filename is None or not self.from_dialog:
self.parent.set_new_hdf_filename(ts_in_seconds,
now_in_seconds)
-
- #else:
- # self.parent.set_new_hdf_filename(ts_in_seconds,
- # now_in_seconds)
- #print("Parent Thread after ==>", self.parent.hdf_filename)
-
- #Open hdf5file here and
- #mess = "HDF save to file {0} proceeding...".format(
- # self.parent.hdf_filename)
- #self.parent.trigger_log_message.emit(MsgSeverity.INFO.name,
- # _pymodule, _line(),
- # mess, {})
try:
+ print("FILENAME ==", self.parent.hdf_filename, flush=True)
with h5py.File(self.parent.hdf_filename, 'w') as dataH5:
- self.parent.add_pvs_to_hdf(
- dataH5, pv_list=self.parent.pv_machine_list,
- from_hdf=from_hdf)
-
- self.parent.add_general_to_hdf(dataH5)
-
- self.parent.add_to_hdf(dataH5, proc=True, raw=True)
-
- self.parent.hdf_save_completed = True
+ #experiment
+ if not from_hdf:
+ self.parent.add_pvs_to_hdf(
+ dataH5, pv_list=self.parent.pv_machine_list,
+ from_hdf=from_hdf)
+
+ #general
+ #if not from_hdf:
+ self.parent.add_general_to_hdf(dataH5)
+ self.parent.add_to_hdf(dataH5, proc=True, raw=True)
+ self.parent.hdf_save_completed = True
+
_mess = "Processed data saved to {}".format(
self.parent.hdf_filename)
self.parent.trigger_log_message.emit(
- MsgSeverity.INFO.name, _pymodule, _line(), _mess, {})
+ MsgSeverity.INFO.name, _pymodule, _line(), _mess,
+ {})
except OSError as e:
- _mess = "OSError in saving to file {0}: {1}".format(
+ _mess = "OSError in saving to file {0}: \n{1}".format(
self.parent.hdf_filename, str(e))
self.parent.trigger_log_message.emit(
MsgSeverity.ERROR.name, _pymodule, _line(), _mess, {})
@@ -258,13 +262,14 @@ class BaseWindow(QMainWindow):
self.all_data = all_data
self.hdf_filename_loaded = self.parent.hdf_filename_loaded
- def __del__(self):
- self.wait()
+ #Only a precaution, not experienced
+ #Causes QThread::wait: Thread tried to wait on itself
+ #def __del__(self):
+ # self.wait()
def run(self):
"""Run hdf thread
"""
-
if not hasattr(self.analysis_procedure, 'load_hdf_file'):
mess = ("Analysis not configured for HDF analysis! " +
@@ -277,8 +282,6 @@ class BaseWindow(QMainWindow):
self.all_data = self.analysis_procedure.load_hdf_file(
self.hdf_filename_loaded)
-
-
if not self.all_data:
self.parent.trigger_progressbar.emit(PROGRESS_THREAD_END)
return
@@ -310,6 +313,7 @@ class BaseWindow(QMainWindow):
# Emit results
if all_dict is not None:
+ self.parent.from_hdf = True
self.trigger_thread_event.emit(all_dict)
mess = "HDF file {} analysis succeeded".format(
self.hdf_filename_loaded)
@@ -391,7 +395,6 @@ class BaseWindow(QMainWindow):
self.settings = ReadJSON(self.appname)
-
#Read out current_logbook
self.cafe = PyCafe.CyCafe()
@@ -411,10 +414,10 @@ class BaseWindow(QMainWindow):
self.hdf_filename_loaded = "NONE" #For loading into hdf dockwidget
self.hdf_filename = None #For saving
self.hdf_dialog = None
+ self.from_hdf = False
self.daq_analysis_completed = False
-
self.setObjectName("MainWindow")
self.setWindowTitle(self.appname)
@@ -424,20 +427,7 @@ class BaseWindow(QMainWindow):
self.menu = self.menuBar()
-
- '''
- try:
- dirname = self.settings.data["stdout"]["destination"]
- except KeyError:
- dirname = "/tmp/"
-
- if not os.path.exists(dirname):
- os.mkdir(dirname)
-
- fname = dirname + self.appname + ".log"
- file_obj = os.open(fname, os.O_RDWR|os.O_CREAT)
- os.close(file_obj)
- '''
+
self.elog_dest = self.settings.data["Elog"]["destination"]
self.screenshot_dest = self.settings.data["screenshot"]["destination"]
@@ -891,16 +881,21 @@ class BaseWindow(QMainWindow):
_mess, QMessageBox.Ok)
return False
- if self.daq_analysis_completed and not self.hdf_save_completed:
- if 'Reanalysis time' in self.all_data['Processed data']:
- if not self.all_data['Processed data']['Reanalysis time']:
- _mess = ("Are you sure you wish to exit " +
- "without saving data to HDF?")
- qm = QMessageBox()
- reply = qm.warning(self, "Exit", _mess,
- QMessageBox.Yes | QMessageBox.No)
- if reply == QMessageBox.No:
- return False
+ if self.daq_analysis_completed and not self.hdf_save_completed \
+ and not self.from_hdf:
+ if self.all_data is not None:
+ try:
+ if 'Reanalysis time' in self.all_data['Processed data']:
+ if not self.all_data['Processed data']['Reanalysis time']:
+ _mess = ("Are you sure you wish to exit " +
+ "without saving data to HDF?")
+ qm = QMessageBox()
+ reply = qm.warning(self, "Exit", _mess,
+ QMessageBox.Yes | QMessageBox.No)
+ if reply == QMessageBox.No:
+ return False
+ except KeyError:
+ pass
return True
@Slot()
@@ -1005,9 +1000,11 @@ class BaseWindow(QMainWindow):
QApplication.processEvents()
if self.autopost_epics:
self.save_to_epics()
+
QApplication.processEvents()
if self.autopost_hdf:
self.save_to_hdf()
+
QApplication.processEvents()
if self.autopost_elog:
self.send_to_elog()
@@ -1073,7 +1070,7 @@ class BaseWindow(QMainWindow):
if not self.daq_analysis_completed:
QMessageBox.information(self, "HDF", (
- ("No data to save to hdf5; no measurement undertaken!")),
+ ("No data to save to hdf; no measurement undertaken!")),
QMessageBox.Ok)
QApplication.processEvents()
return False
@@ -1144,8 +1141,9 @@ class BaseWindow(QMainWindow):
print(_mess, flush=True)
self.trigger_log_message.emit(
MsgSeverity.WARN.name, _pymodule, _line(), _mess,
- {})
+ {})
return isOK
+
if from_hdf:
return isOK
@@ -1193,8 +1191,11 @@ class BaseWindow(QMainWindow):
user_dict['User'] = getpass.getuser()
if self.all_data is not None:
- time_in_seconds = self.all_data['Ambient data']['Time in seconds']
- now = datetime.fromtimestamp(time_in_seconds)
+ if 'Time in seconds' in self.all_data['Ambient data']:
+ time_in_seconds = self.all_data['Ambient data']['Time in seconds']
+ now = datetime.fromtimestamp(time_in_seconds)
+ else:
+ now = datetime.now()
else:
now = datetime.now()
@@ -1222,19 +1223,14 @@ class BaseWindow(QMainWindow):
""" This uses the widget interface to allow the user to enter
additional meta-data
"""
-
+
if not self.verify_save_to_hdf():
return False
input_options = OrderedDict()
- #print(self.all_data['Ambient data'])
- #print(self.all_data['Processed data'])
-
- #QCombobox if list
- #input_options['QComboBox'] = ['one', 'two', 'three']
- #input_options['Comment'] = 'Please enter a comment'
if self.all_data is not None:
+
ts_in_seconds = self.all_data['Ambient data']['Time in seconds']
now_in_seconds = None
if 'Reanalysis time in seconds' in self.all_data['Processed data']:
@@ -1249,9 +1245,7 @@ class BaseWindow(QMainWindow):
self.hdf_dialog = QSaveHDF(self, input_options=input_options,
from_dialog=True)
- #user_dict = self.hdf_dialog.get_data()
- #self.hdf_filename = user_dict['Destination']
- #print("filename", self.hdf_filename)
+
def verify_send_to_elog(self):
@@ -1274,12 +1268,11 @@ class BaseWindow(QMainWindow):
if self.save_hdf_thread.isRunning():
return True
- if not self.hdf_save_completed:
+ if not self.hdf_save_completed and not self.from_hdf:
_mess = ("Opening ELOG, but please note that data have not " +
"been saved to HDF. " +
"
Click on the HDF icon to do this if desired")
- QMessageBox.information(self, "ELOG", _mess,
- QMessageBox.Ok)
+ QMessageBox.information(self, "ELOG", _mess, QMessageBox.Ok)
return True
return True
@@ -1746,7 +1739,8 @@ class BaseWindow(QMainWindow):
@Slot()
def start_analysis_thread(self):
-
+ '''Slot to self.start_wgt button trigger in guiframe.py
+ '''
if not self.analysis_procedure:
mess = "Analysis thread not configured for this application"
self.show_log_message(MsgSeverity.ERROR, _pymodule, _line(), mess)
@@ -1821,6 +1815,7 @@ class BaseWindow(QMainWindow):
@Slot(dict)
def receive_analysis_results(self, all_dict):
self.all_data = all_dict
+ print("self.all_data", self.all_data.keys(), flush=True)
self.gui_frame.canvas_update(all_dict['Figure data'])
@@ -1873,7 +1868,7 @@ class BaseWindow(QMainWindow):
else:
pass
- #print("receive_analysis_results=========================>", flush=True)
+ print("receive_analysis_results=========================>", flush=True)
@Slot()
def receive_abort_analysis(self):
@@ -2121,3 +2116,59 @@ class BaseWindow(QMainWindow):
- # {1}
{2}
- #