diff --git a/gui/control_main.py b/gui/control_main.py index c08dab53..8f106db9 100644 --- a/gui/control_main.py +++ b/gui/control_main.py @@ -17,11 +17,14 @@ from qt_epics.QtEpicsPVEntry import QtEpicsPVEntry from qt_epics.QtEpicsPVLabel import QtEpicsPVLabel from qtpy import QtCore, QtGui, QtWidgets -from qtpy.QtCore import QModelIndex, QRectF, Qt, QTimer +from qtpy.QtCore import QModelIndex, QRectF, Qt, QTimer, QProcess from qtpy.QtGui import QIntValidator -from qtpy.QtWidgets import QCheckBox, QFrame, QGraphicsPixmapItem, QApplication +from qtpy.QtWidgets import QCheckBox, QFrame, QGraphicsPixmapItem, QApplication, QMessageBox from devices import GonioDevice, CameraDevice, MD2Device, LightDevice, MD2ApertureDevice + + + import albulaUtils import daq_utils import db_lib @@ -50,7 +53,8 @@ SnapCommentDialog, StaffScreenDialog, UserScreenDialog, - CalculatorWindow + CalculatorWindow, + ProcessPopup ) from gui.raster import RasterCell, RasterGroup from QPeriodicTable import QPeriodicTable @@ -165,6 +169,7 @@ def __init__(self): self.centerMarkerCharSize = 20 self.centerMarkerCharOffsetX = 12 self.centerMarkerCharOffsetY = 18 + self.raster_output = None self.currentRasterCellList = [] self.redPen = QtGui.QPen(QtCore.Qt.red) self.bluePen = QtGui.QPen(QtCore.Qt.blue) @@ -243,6 +248,7 @@ def __init__(self): self.controlMasterCheckBox.setChecked(True) self.XRFInfoDict = self.parseXRFTable() # I don't like this + def setGuiValues(self, values): for item, value in values.items(): logger.info("resetting %s to %s" % (item, value)) @@ -1253,6 +1259,7 @@ def createSampleTab(self): hBoxSampleAlignLayout = QtWidgets.QHBoxLayout() centerLoopButton = QtWidgets.QPushButton("Center\nLoop") centerLoopButton.clicked.connect(self.autoCenterLoopCB) + self.init_autocenter() measureButton = QtWidgets.QPushButton("Measure") measureButton.clicked.connect(self.measurePolyCB) loopShapeButton = QtWidgets.QPushButton("Add Raster\nto Queue") @@ -1503,7 +1510,8 @@ def createSampleTab(self): self.dimpleCheckBox.setVisible(False) self.centeringComboBox.setVisible(False) annealButton.setVisible(False) - centerLoopButton.setVisible(False) + #unhiding center loop button + #centerLoopButton.setVisible(False) clearGraphicsButton.setVisible(False) saveCenteringButton.setVisible(False) selectAllCenteringButton.setVisible(False) @@ -1522,6 +1530,7 @@ def createSampleTab(self): #self.captureLowMag.set(cv2.CAP_PROP_BUFFERSIZE, 1) self.captureLowMag = daq_utils.lowMagCamURL self.capture = self.captureLowMag + #self.sampleCameraThread = VideoThread( # parent=self, delay=SAMPLE_TIMER_DELAY, camera_object=self.capture @@ -3022,8 +3031,75 @@ def omegaTweakCB(self, tv): self.popupServerMessage("You don't have control") def autoCenterLoopCB(self): + if self.auto_center_ongoing == True: + self.popupServerMessage("Auto center is already running") + return logger.info("auto center loop") - self.send_to_server("loop_center_xrec()") + autocenter_call = '/nsls2/data/nyx/legacy/Rudra/lsdcSpoofer/run_auto_center' + popup_info = ProcessPopup(parent = self, window_title='AutoCenter Info', main_text="Waiting for auto center, view detailed text for more info") + + popup_info.setIcon(QMessageBox.Information) + x = popup_info.open() + self.autocenter_process = QProcess(parent=self) + self.autocenter_process.readyReadStandardOutput.connect(lambda: popup_info.setDetailedText(bytes(self.autocenter_process.readAllStandardOutput()).decode("utf8"))) + self.autocenter_process.finished.connect(lambda: popup_info.setText("AUTO CENTERING FINISHED\n\nopen details for more information")) + self.autocenter_process.finished.connect(lambda: popup_info.setWindowTitle("Done")) + self.autocenter_process.finished.connect(self.close_autocenter) + + self.autocenter_process.start(autocenter_call) + self.auto_center_ongoing = True + + + + + # with subprocess.Popen(autocenter_call, stdout=subprocess.PIPE, bufsize=1, universal_newlines=True) as p: + # for line in p.stdout: + + # popup_info.setText(line + "") + + # if p.returncode != 0: + # raise subprocess.CalledProcessError(p.returncode, p.args) + + def init_autocenter(self): + self.autocenter_process = QProcess(parent=self) + pythondir = '/opt/conda_envs/lsdc-gui-2023-2-latest/bin/python3' + autocenter_call = '/nsls2/data/nyx/legacy/Rudra/lsdcSpoofer/autocenter_lucid.py' + self.autocenter_process.finished.connect(self.close_autocenter) + self.autocenter_process.start('{} {}'.format(pythondir, autocenter_call)) + self.auto_center_ongoing = True + + def close_autocenter(self): + self.auto_center_ongoing = False + self.autocenter_process.close() + + + def handle_raster_output(self, data): + self.raster_output = data + + + + + + def get_raster_coords(self): + logger.info("getting raster coordinates") + raster_call = '/nsls2/data/nyx/legacy/Rudra/lsdcSpoofer/get_raster_box' + self.raster_output = None + self.raster_process = QProcess(parent=self) + + self.raster_process.finished.connect(lambda: self.handle_raster_output(self.raster_process.readAllStandardOutput().data().decode('utf-8'))) + #self.raster_process.finished.connect(lambda: self.raster_process.close()) + self.raster_process.start(raster_call) + self.raster_process.waitForFinished() + return self.raster_output + + + + + + + + + def autoRasterLoopCB(self): self.selectedSampleID = self.selectedSampleRequest["sample"] diff --git a/gui/dialog/__init__.py b/gui/dialog/__init__.py index 653c2b05..3ccfa12c 100644 --- a/gui/dialog/__init__.py +++ b/gui/dialog/__init__.py @@ -7,3 +7,4 @@ from .screen_defaults import ScreenDefaultsDialog from .resolution_calculator import Calculator from .resolution_dialog import CalculatorWindow +from .process_monitor import ProcessPopup diff --git a/gui/dialog/process_monitor.py b/gui/dialog/process_monitor.py new file mode 100644 index 00000000..56c56916 --- /dev/null +++ b/gui/dialog/process_monitor.py @@ -0,0 +1,24 @@ +import logging +import typing + +from qtpy import QtCore, QtGui, QtWidgets +from qtpy.QtCore import Qt + +import daq_utils +import db_lib + +if typing.TYPE_CHECKING: + from lsdcGui import ControlMain + +logger = logging.getLogger() + +class ProcessPopup(QtWidgets.QMessageBox): + def __init__(self, parent: "ControlMain",window_title = 'Info', main_text = 'Waiting for somethign in GUI, open more details for more info', detailed_text = 'waiting'): + super(ProcessPopup, self).__init__(parent) + self.setWindowTitle(window_title) + self.setIcon(QtWidgets.QMessageBox.Question) + self.setText(main_text) + self.setDetailedText(detailed_text) + + +