Beispiel #1
0
    def __init__(self, parent):
        QWidget.__init__(self, parent)

        self.oscillationId = None
        self.oscillationInfo = None

        self.dbServer = None

        results_box = QVBox(self)
        self.resultsBox = QWidget(results_box)
        QGridLayout(self.resultsBox, 6, 2, 1, 2)

        label1 = QLabel("Status:", self.resultsBox)
        self.resultsBox.layout().addWidget(label1, 0, 0)

        status_box = QHBox(self.resultsBox)
        self.resultStatus = readonlyLineEdit(status_box)
        HorizontalSpacer3(status_box)
        self.resultMessage = readonlyLineEdit(status_box)
        self.resultsBox.layout().addWidget(status_box, 0, 1)

        label2 = QLabel("Time:", self.resultsBox)
        self.resultsBox.layout().addWidget(label2, 1, 0)
        self.resultTime = readonlyLineEdit(self.resultsBox)
        self.resultsBox.layout().addWidget(self.resultTime, 1, 1)

        label3 = QLabel("Directory:", self.resultsBox)
        self.resultsBox.layout().addWidget(label3, 2, 0)
        self.resultDirectory = readonlyLineEdit(self.resultsBox)
        self.resultsBox.layout().addWidget(self.resultDirectory, 2, 1)

        label4 = QLabel("Template:", self.resultsBox)
        self.resultsBox.layout().addWidget(label4, 3, 0)
        self.resultTemplate = readonlyLineEdit(self.resultsBox)
        self.resultsBox.layout().addWidget(self.resultTemplate, 3, 1)

        label5 = QLabel("Images:", self.resultsBox)
        self.resultsBox.layout().addWidget(label5, 4, 0)
        images_box = QHBox(self.resultsBox)
        self.resultImages = readonlyLineEdit(images_box)
        HorizontalSpacer3(images_box)

        self.radioBox = QHButtonGroup(images_box)
        self.radioBox.setFrameShape(self.radioBox.NoFrame)
        self.radioBox.setInsideMargin(0)
        self.radioBox.setInsideSpacing(0)
        self.followView = QRadioButton("Follow images", self.radioBox)
        self.imageView = QRadioButton("View image:", self.radioBox)
        self.imageNumber = QSpinBox(images_box)
        self.imageNumber.setMinValue(1)
        self.imageNumber.setMaxValue(1)
        self.imageNumber.setEnabled(False)
        self.radioBox.setButton(0)
        QObject.connect(self.radioBox, SIGNAL("clicked(int)"),
                        self.imageModeChanged)
        QObject.connect(self.imageNumber, SIGNAL("valueChanged(int)"),
                        self.imageNumberChanged)
        QObject.connect(
            self.imageNumber.editor(),
            SIGNAL("textChanged(const QString &)"),
            self.imageTextChanged,
        )
        self.resultsBox.layout().addWidget(images_box, 4, 1)
        self.currentImageNumber = None

        label6 = QLabel("Comments:", self.resultsBox)
        self.resultsBox.layout().addWidget(label6, 5, 0)
        self.commentsBox = QHBox(self.resultsBox)
        self.resultComments = LineEditInput(self.commentsBox)
        self.connect(self.resultComments, PYSIGNAL("returnPressed"),
                     self.updateComments)
        HorizontalSpacer3(self.commentsBox)
        self.commentsButton = QToolButton(self.commentsBox)
        self.commentsButton.setUsesTextLabel(True)
        self.commentsButton.setTextPosition(QToolButton.BesideIcon)
        self.commentsButton.setTextLabel("Update ISPyB")
        QObject.connect(self.commentsButton, SIGNAL("clicked()"),
                        self.updateComments)
        self.resultsBox.layout().addWidget(self.commentsBox, 5, 1)

        VerticalSpacer(results_box)

        self.imageDisplay = DetectorImage(self)
        QObject.connect(self.imageDisplay, PYSIGNAL("imageUpdated"),
                        self.detectorImageUpdated)

        QHBoxLayout(self)
        self.layout().addWidget(results_box)
        self.layout().addWidget(self.imageDisplay)

        self.setEnabled(False)
    def __init__(self, parent):
        QWidget.__init__(self, parent)

        self.oscillationId = None
        self.oscillationInfo = None

        self.dbServer = None

        results_box = QVBox(self)
        self.resultsBox = QWidget(results_box)
        QGridLayout(self.resultsBox, 6, 2, 1, 2)

        label1 = QLabel("Status:", self.resultsBox)
        self.resultsBox.layout().addWidget(label1, 0, 0)

        status_box = QHBox(self.resultsBox)
        self.resultStatus = readonlyLineEdit(status_box)
        HorizontalSpacer3(status_box)
        self.resultMessage = readonlyLineEdit(status_box)
        self.resultsBox.layout().addWidget(status_box, 0, 1)

        label2 = QLabel("Time:", self.resultsBox)
        self.resultsBox.layout().addWidget(label2, 1, 0)
        self.resultTime = readonlyLineEdit(self.resultsBox)
        self.resultsBox.layout().addWidget(self.resultTime, 1, 1)

        label3 = QLabel("Directory:", self.resultsBox)
        self.resultsBox.layout().addWidget(label3, 2, 0)
        self.resultDirectory = readonlyLineEdit(self.resultsBox)
        self.resultsBox.layout().addWidget(self.resultDirectory, 2, 1)

        label4 = QLabel("Template:", self.resultsBox)
        self.resultsBox.layout().addWidget(label4, 3, 0)
        self.resultTemplate = readonlyLineEdit(self.resultsBox)
        self.resultsBox.layout().addWidget(self.resultTemplate, 3, 1)

        label5 = QLabel("Images:", self.resultsBox)
        self.resultsBox.layout().addWidget(label5, 4, 0)
        images_box = QHBox(self.resultsBox)
        self.resultImages = readonlyLineEdit(images_box)
        HorizontalSpacer3(images_box)

        self.radioBox = QHButtonGroup(images_box)
        self.radioBox.setFrameShape(self.radioBox.NoFrame)
        self.radioBox.setInsideMargin(0)
        self.radioBox.setInsideSpacing(0)
        self.followView = QRadioButton("Follow images", self.radioBox)
        self.imageView = QRadioButton("View image:", self.radioBox)
        self.imageNumber = QSpinBox(images_box)
        self.imageNumber.setMinValue(1)
        self.imageNumber.setMaxValue(1)
        self.imageNumber.setEnabled(False)
        self.radioBox.setButton(0)
        QObject.connect(self.radioBox, SIGNAL("clicked(int)"), self.imageModeChanged)
        QObject.connect(
            self.imageNumber, SIGNAL("valueChanged(int)"), self.imageNumberChanged
        )
        QObject.connect(
            self.imageNumber.editor(),
            SIGNAL("textChanged(const QString &)"),
            self.imageTextChanged,
        )
        self.resultsBox.layout().addWidget(images_box, 4, 1)
        self.currentImageNumber = None

        label6 = QLabel("Comments:", self.resultsBox)
        self.resultsBox.layout().addWidget(label6, 5, 0)
        self.commentsBox = QHBox(self.resultsBox)
        self.resultComments = LineEditInput(self.commentsBox)
        self.connect(
            self.resultComments, PYSIGNAL("returnPressed"), self.updateComments
        )
        HorizontalSpacer3(self.commentsBox)
        self.commentsButton = QToolButton(self.commentsBox)
        self.commentsButton.setUsesTextLabel(True)
        self.commentsButton.setTextPosition(QToolButton.BesideIcon)
        self.commentsButton.setTextLabel("Update ISPyB")
        QObject.connect(self.commentsButton, SIGNAL("clicked()"), self.updateComments)
        self.resultsBox.layout().addWidget(self.commentsBox, 5, 1)

        VerticalSpacer(results_box)

        self.imageDisplay = DetectorImage(self)
        QObject.connect(
            self.imageDisplay, PYSIGNAL("imageUpdated"), self.detectorImageUpdated
        )

        QHBoxLayout(self)
        self.layout().addWidget(results_box)
        self.layout().addWidget(self.imageDisplay)

        self.setEnabled(False)
Beispiel #3
0
class DataCollectResultsWidget(QWidget):
    def __init__(self, parent):
        QWidget.__init__(self, parent)

        self.oscillationId = None
        self.oscillationInfo = None

        self.dbServer = None

        results_box = QVBox(self)
        self.resultsBox = QWidget(results_box)
        QGridLayout(self.resultsBox, 6, 2, 1, 2)

        label1 = QLabel("Status:", self.resultsBox)
        self.resultsBox.layout().addWidget(label1, 0, 0)

        status_box = QHBox(self.resultsBox)
        self.resultStatus = readonlyLineEdit(status_box)
        HorizontalSpacer3(status_box)
        self.resultMessage = readonlyLineEdit(status_box)
        self.resultsBox.layout().addWidget(status_box, 0, 1)

        label2 = QLabel("Time:", self.resultsBox)
        self.resultsBox.layout().addWidget(label2, 1, 0)
        self.resultTime = readonlyLineEdit(self.resultsBox)
        self.resultsBox.layout().addWidget(self.resultTime, 1, 1)

        label3 = QLabel("Directory:", self.resultsBox)
        self.resultsBox.layout().addWidget(label3, 2, 0)
        self.resultDirectory = readonlyLineEdit(self.resultsBox)
        self.resultsBox.layout().addWidget(self.resultDirectory, 2, 1)

        label4 = QLabel("Template:", self.resultsBox)
        self.resultsBox.layout().addWidget(label4, 3, 0)
        self.resultTemplate = readonlyLineEdit(self.resultsBox)
        self.resultsBox.layout().addWidget(self.resultTemplate, 3, 1)

        label5 = QLabel("Images:", self.resultsBox)
        self.resultsBox.layout().addWidget(label5, 4, 0)
        images_box = QHBox(self.resultsBox)
        self.resultImages = readonlyLineEdit(images_box)
        HorizontalSpacer3(images_box)

        self.radioBox = QHButtonGroup(images_box)
        self.radioBox.setFrameShape(self.radioBox.NoFrame)
        self.radioBox.setInsideMargin(0)
        self.radioBox.setInsideSpacing(0)
        self.followView = QRadioButton("Follow images", self.radioBox)
        self.imageView = QRadioButton("View image:", self.radioBox)
        self.imageNumber = QSpinBox(images_box)
        self.imageNumber.setMinValue(1)
        self.imageNumber.setMaxValue(1)
        self.imageNumber.setEnabled(False)
        self.radioBox.setButton(0)
        QObject.connect(self.radioBox, SIGNAL("clicked(int)"),
                        self.imageModeChanged)
        QObject.connect(self.imageNumber, SIGNAL("valueChanged(int)"),
                        self.imageNumberChanged)
        QObject.connect(
            self.imageNumber.editor(),
            SIGNAL("textChanged(const QString &)"),
            self.imageTextChanged,
        )
        self.resultsBox.layout().addWidget(images_box, 4, 1)
        self.currentImageNumber = None

        label6 = QLabel("Comments:", self.resultsBox)
        self.resultsBox.layout().addWidget(label6, 5, 0)
        self.commentsBox = QHBox(self.resultsBox)
        self.resultComments = LineEditInput(self.commentsBox)
        self.connect(self.resultComments, PYSIGNAL("returnPressed"),
                     self.updateComments)
        HorizontalSpacer3(self.commentsBox)
        self.commentsButton = QToolButton(self.commentsBox)
        self.commentsButton.setUsesTextLabel(True)
        self.commentsButton.setTextPosition(QToolButton.BesideIcon)
        self.commentsButton.setTextLabel("Update ISPyB")
        QObject.connect(self.commentsButton, SIGNAL("clicked()"),
                        self.updateComments)
        self.resultsBox.layout().addWidget(self.commentsBox, 5, 1)

        VerticalSpacer(results_box)

        self.imageDisplay = DetectorImage(self)
        QObject.connect(self.imageDisplay, PYSIGNAL("imageUpdated"),
                        self.detectorImageUpdated)

        QHBoxLayout(self)
        self.layout().addWidget(results_box)
        self.layout().addWidget(self.imageDisplay)

        self.setEnabled(False)

    def fontChange(self, oldFont):
        self.resultStatus.setFixedWidth(
            self.fontMetrics().width("#FINISHED.#"))

    def setDbServer(self, dbserver):
        self.dbServer = dbserver

    def setImageServer(self, image_server):
        self.imageDisplay.setImageServer(image_server)

    def updateComments(self):
        col_dict = {}
        col_dict["dataCollectionId"] = self.oscillationInfo[3][
            "collection_datacollectionid"]
        col_dict["comments"] = self.resultComments.text()
        self.dbServer.updateDataCollection(col_dict)

    def imageModeChanged(self, button):
        if button == 0:
            self.imageNumber.setEnabled(False)
        else:
            self.imageNumber.setEnabled(True)

    def imageCollected(self, osc_id, image_number):
        if self.oscillationInfo is None:
            return
        if osc_id != self.oscillationId:
            return
        if str(self.resultTime.text()) == "" or str(
                self.resultTemplate.text()) == "":
            self.updateOscillation(osc_id)
        if self.radioBox.selectedId() == 0:
            image = (int(self.oscillationInfo[3]["oscillation_sequence"][0]
                         ["start_image_number"]) + image_number - 1)

            template = self.oscillationInfo[3]["fileinfo"]["template"]
            directory = self.oscillationInfo[3]["fileinfo"]["directory"]
            self.imageDisplay.setWantedImage(directory, template, image)

    def imageTextChanged(self, img_number):
        # set yellow color
        if self.radioBox.selectedId() == 1:
            try:
                img_number = int(str(img_number))
            except (TypeError, ValueError):
                self.imageNumber.editor().setPaletteBackgroundColor(
                    QWidget.yellow)
            else:
                if self.currentImageNumber == img_number:
                    self.imageNumber.editor().setPaletteBackgroundColor(
                        QWidget.white)
                else:
                    self.imageNumber.editor().setPaletteBackgroundColor(
                        QWidget.yellow)

    def imageNumberChanged(self, img_number):
        if self.oscillationInfo is None:
            return

        if self.radioBox.selectedId() == 1:
            try:
                template = self.oscillationInfo[3]["fileinfo"]["template"]
            except KeyError:
                pass
            else:
                self.imageDisplay.setWantedImage(
                    self.oscillationInfo[3]["fileinfo"]["directory"],
                    template,
                    img_number,
                    False,
                )

    def detectorImageUpdated(self, filename, image_number, state):
        # print "DETECTOR IMAGE UPDATED",filename,image_number,state
        self.currentImageNumber = image_number
        if image_number is not None:
            self.imageNumber.blockSignals(True)
            self.imageNumber.setValue(image_number)
            self.imageNumber.blockSignals(False)
        if self.radioBox.selectedId() == 1:
            self.imageNumber.editor().setPaletteBackgroundColor(QWidget.white)

    def setOscillation(self, osc_id, osc_info=None):
        # print "DataCollectResultsWidget.setOscillation",osc_id,osc_info

        if osc_id is None:
            self.imageDisplay.clearImage(True)
            self.resultStatus.setText("")
            self.resultMessage.setText("")
            self.resultTime.setText("")
            self.resultDirectory.setText("")
            self.resultTemplate.setText("")
            self.resultImages.setText("")
            self.imageNumber.blockSignals(True)
            self.imageNumber.setMinValue(1)
            self.imageNumber.setMaxValue(1)
            self.imageNumber.blockSignals(False)
            self.resultComments.setText("")
            self.setEnabled(False)
            self.oscillationId = None
            self.oscillationInfo = None
            return

        self.oscillationId = osc_id
        if osc_info is not None:
            self.imageDisplay.clearImage()
            self.oscillationInfo = osc_info
        collect_dict = self.oscillationInfo[3]

        try:
            datacollectionid = collect_dict["collection_datacollectionid"]
        except KeyError:
            datacollectionid = None

        try:
            status = collect_dict["collection_code"]
        except KeyError:
            status_msg = "Ongoing..."
            status_detailed_msg = ""
            self.followView.setEnabled(True)
            if osc_info is not None:
                self.radioBox.setButton(0)
                self.imageNumber.setEnabled(False)
        else:
            try:
                msg = collect_dict["collection_message"]
            except KeyError:
                msg = ""
            else:
                try:
                    msg = msg.replace("DataCollect: ", "")
                    msg = msg[0].upper() + msg[1:] + "."
                except IndexError:
                    msg = ""
            status_detailed_msg = msg

            self.radioBox.setButton(1)
            self.imageNumber.setEnabled(True)
            self.followView.setEnabled(False)
            if status is None:
                status_msg = "Stopped!"
            elif status:
                status_msg = "Finished."
                status_detailed_msg = ""
            else:
                status_msg = "Failed!"

        try:
            start_time = collect_dict["collection_start_time"]
        except KeyError:
            time_msg = ""
        else:
            try:
                end_time = collect_dict["collection_end_time"]
            except KeyError:
                time_msg = "Started at %s" % start_time
            else:
                time_msg = "From %s to %s" % (start_time, end_time)

        directory = collect_dict["fileinfo"]["directory"]
        try:
            template = collect_dict["fileinfo"]["template"]
        except KeyError:
            template = ""
        first_image = int(
            collect_dict["oscillation_sequence"][0]["start_image_number"])
        last_image = (first_image + int(
            collect_dict["oscillation_sequence"][0]["number_of_images"]) - 1)
        self.imageNumber.blockSignals(True)
        self.imageNumber.setMinValue(first_image)
        self.imageNumber.setMaxValue(last_image)
        self.imageNumber.blockSignals(False)

        try:
            comments = collect_dict["comment"]
        except KeyError:
            comments = ""

        self.resultStatus.setText(status_msg)
        self.resultMessage.setText(status_detailed_msg)
        self.resultTime.setText(time_msg)
        self.resultDirectory.setText(directory)
        self.resultTemplate.setText(template)
        self.resultImages.setText("%d to %d" % (first_image, last_image))

        if datacollectionid is not None and self.dbServer is not None:
            self.resultComments.setReadOnly(False)
            self.commentsButton.setEnabled(True)
            # get current comments from ispyb (new thread? :P)!
            self.resultComments.setText("")
        else:
            self.resultComments.setText(comments)
            self.resultComments.setReadOnly(True)
            self.commentsButton.setEnabled(False)

        if osc_info is not None:
            if self.imageNumber.value() == first_image:
                self.imageNumber.valueChange()
            else:
                self.imageNumber.setValue(first_image)

        self.setEnabled(True)

    def updateOscillation(self, osc_id):
        if self.oscillationInfo is None:
            return
        if self.oscillationId == osc_id:
            self.setOscillation(self.oscillationId)

    def setUpdateIcon(self, icon_name):
        self.commentsButton.setPixmap(Icons.load(icon_name))
class DataCollectResultsWidget(QWidget):
    def __init__(self, parent):
        QWidget.__init__(self, parent)

        self.oscillationId = None
        self.oscillationInfo = None

        self.dbServer = None

        results_box = QVBox(self)
        self.resultsBox = QWidget(results_box)
        QGridLayout(self.resultsBox, 6, 2, 1, 2)

        label1 = QLabel("Status:", self.resultsBox)
        self.resultsBox.layout().addWidget(label1, 0, 0)

        status_box = QHBox(self.resultsBox)
        self.resultStatus = readonlyLineEdit(status_box)
        HorizontalSpacer3(status_box)
        self.resultMessage = readonlyLineEdit(status_box)
        self.resultsBox.layout().addWidget(status_box, 0, 1)

        label2 = QLabel("Time:", self.resultsBox)
        self.resultsBox.layout().addWidget(label2, 1, 0)
        self.resultTime = readonlyLineEdit(self.resultsBox)
        self.resultsBox.layout().addWidget(self.resultTime, 1, 1)

        label3 = QLabel("Directory:", self.resultsBox)
        self.resultsBox.layout().addWidget(label3, 2, 0)
        self.resultDirectory = readonlyLineEdit(self.resultsBox)
        self.resultsBox.layout().addWidget(self.resultDirectory, 2, 1)

        label4 = QLabel("Template:", self.resultsBox)
        self.resultsBox.layout().addWidget(label4, 3, 0)
        self.resultTemplate = readonlyLineEdit(self.resultsBox)
        self.resultsBox.layout().addWidget(self.resultTemplate, 3, 1)

        label5 = QLabel("Images:", self.resultsBox)
        self.resultsBox.layout().addWidget(label5, 4, 0)
        images_box = QHBox(self.resultsBox)
        self.resultImages = readonlyLineEdit(images_box)
        HorizontalSpacer3(images_box)

        self.radioBox = QHButtonGroup(images_box)
        self.radioBox.setFrameShape(self.radioBox.NoFrame)
        self.radioBox.setInsideMargin(0)
        self.radioBox.setInsideSpacing(0)
        self.followView = QRadioButton("Follow images", self.radioBox)
        self.imageView = QRadioButton("View image:", self.radioBox)
        self.imageNumber = QSpinBox(images_box)
        self.imageNumber.setMinValue(1)
        self.imageNumber.setMaxValue(1)
        self.imageNumber.setEnabled(False)
        self.radioBox.setButton(0)
        QObject.connect(self.radioBox, SIGNAL("clicked(int)"), self.imageModeChanged)
        QObject.connect(
            self.imageNumber, SIGNAL("valueChanged(int)"), self.imageNumberChanged
        )
        QObject.connect(
            self.imageNumber.editor(),
            SIGNAL("textChanged(const QString &)"),
            self.imageTextChanged,
        )
        self.resultsBox.layout().addWidget(images_box, 4, 1)
        self.currentImageNumber = None

        label6 = QLabel("Comments:", self.resultsBox)
        self.resultsBox.layout().addWidget(label6, 5, 0)
        self.commentsBox = QHBox(self.resultsBox)
        self.resultComments = LineEditInput(self.commentsBox)
        self.connect(
            self.resultComments, PYSIGNAL("returnPressed"), self.updateComments
        )
        HorizontalSpacer3(self.commentsBox)
        self.commentsButton = QToolButton(self.commentsBox)
        self.commentsButton.setUsesTextLabel(True)
        self.commentsButton.setTextPosition(QToolButton.BesideIcon)
        self.commentsButton.setTextLabel("Update ISPyB")
        QObject.connect(self.commentsButton, SIGNAL("clicked()"), self.updateComments)
        self.resultsBox.layout().addWidget(self.commentsBox, 5, 1)

        VerticalSpacer(results_box)

        self.imageDisplay = DetectorImage(self)
        QObject.connect(
            self.imageDisplay, PYSIGNAL("imageUpdated"), self.detectorImageUpdated
        )

        QHBoxLayout(self)
        self.layout().addWidget(results_box)
        self.layout().addWidget(self.imageDisplay)

        self.setEnabled(False)

    def fontChange(self, oldFont):
        self.resultStatus.setFixedWidth(self.fontMetrics().width("#FINISHED.#"))

    def setDbServer(self, dbserver):
        self.dbServer = dbserver

    def setImageServer(self, image_server):
        self.imageDisplay.setImageServer(image_server)

    def updateComments(self):
        col_dict = {}
        col_dict["dataCollectionId"] = self.oscillationInfo[3][
            "collection_datacollectionid"
        ]
        col_dict["comments"] = self.resultComments.text()
        self.dbServer.updateDataCollection(col_dict)

    def imageModeChanged(self, button):
        if button == 0:
            self.imageNumber.setEnabled(False)
        else:
            self.imageNumber.setEnabled(True)

    def imageCollected(self, osc_id, image_number):
        if self.oscillationInfo is None:
            return
        if osc_id != self.oscillationId:
            return
        if str(self.resultTime.text()) == "" or str(self.resultTemplate.text()) == "":
            self.updateOscillation(osc_id)
        if self.radioBox.selectedId() == 0:
            image = (
                int(
                    self.oscillationInfo[3]["oscillation_sequence"][0][
                        "start_image_number"
                    ]
                )
                + image_number
                - 1
            )

            template = self.oscillationInfo[3]["fileinfo"]["template"]
            directory = self.oscillationInfo[3]["fileinfo"]["directory"]
            self.imageDisplay.setWantedImage(directory, template, image)

    def imageTextChanged(self, img_number):
        # set yellow color
        if self.radioBox.selectedId() == 1:
            try:
                img_number = int(str(img_number))
            except (TypeError, ValueError):
                self.imageNumber.editor().setPaletteBackgroundColor(QWidget.yellow)
            else:
                if self.currentImageNumber == img_number:
                    self.imageNumber.editor().setPaletteBackgroundColor(QWidget.white)
                else:
                    self.imageNumber.editor().setPaletteBackgroundColor(QWidget.yellow)

    def imageNumberChanged(self, img_number):
        if self.oscillationInfo is None:
            return

        if self.radioBox.selectedId() == 1:
            try:
                template = self.oscillationInfo[3]["fileinfo"]["template"]
            except KeyError:
                pass
            else:
                self.imageDisplay.setWantedImage(
                    self.oscillationInfo[3]["fileinfo"]["directory"],
                    template,
                    img_number,
                    False,
                )

    def detectorImageUpdated(self, filename, image_number, state):
        # print "DETECTOR IMAGE UPDATED",filename,image_number,state
        self.currentImageNumber = image_number
        if image_number is not None:
            self.imageNumber.blockSignals(True)
            self.imageNumber.setValue(image_number)
            self.imageNumber.blockSignals(False)
        if self.radioBox.selectedId() == 1:
            self.imageNumber.editor().setPaletteBackgroundColor(QWidget.white)

    def setOscillation(self, osc_id, osc_info=None):
        # print "DataCollectResultsWidget.setOscillation",osc_id,osc_info

        if osc_id is None:
            self.imageDisplay.clearImage(True)
            self.resultStatus.setText("")
            self.resultMessage.setText("")
            self.resultTime.setText("")
            self.resultDirectory.setText("")
            self.resultTemplate.setText("")
            self.resultImages.setText("")
            self.imageNumber.blockSignals(True)
            self.imageNumber.setMinValue(1)
            self.imageNumber.setMaxValue(1)
            self.imageNumber.blockSignals(False)
            self.resultComments.setText("")
            self.setEnabled(False)
            self.oscillationId = None
            self.oscillationInfo = None
            return

        self.oscillationId = osc_id
        if osc_info is not None:
            self.imageDisplay.clearImage()
            self.oscillationInfo = osc_info
        collect_dict = self.oscillationInfo[3]

        try:
            datacollectionid = collect_dict["collection_datacollectionid"]
        except KeyError:
            datacollectionid = None

        try:
            status = collect_dict["collection_code"]
        except KeyError:
            status_msg = "Ongoing..."
            status_detailed_msg = ""
            self.followView.setEnabled(True)
            if osc_info is not None:
                self.radioBox.setButton(0)
                self.imageNumber.setEnabled(False)
        else:
            try:
                msg = collect_dict["collection_message"]
            except KeyError:
                msg = ""
            else:
                try:
                    msg = msg.replace("DataCollect: ", "")
                    msg = msg[0].upper() + msg[1:] + "."
                except IndexError:
                    msg = ""
            status_detailed_msg = msg

            self.radioBox.setButton(1)
            self.imageNumber.setEnabled(True)
            self.followView.setEnabled(False)
            if status is None:
                status_msg = "Stopped!"
            elif status:
                status_msg = "Finished."
                status_detailed_msg = ""
            else:
                status_msg = "Failed!"

        try:
            start_time = collect_dict["collection_start_time"]
        except KeyError:
            time_msg = ""
        else:
            try:
                end_time = collect_dict["collection_end_time"]
            except KeyError:
                time_msg = "Started at %s" % start_time
            else:
                time_msg = "From %s to %s" % (start_time, end_time)

        directory = collect_dict["fileinfo"]["directory"]
        try:
            template = collect_dict["fileinfo"]["template"]
        except KeyError:
            template = ""
        first_image = int(collect_dict["oscillation_sequence"][0]["start_image_number"])
        last_image = (
            first_image
            + int(collect_dict["oscillation_sequence"][0]["number_of_images"])
            - 1
        )
        self.imageNumber.blockSignals(True)
        self.imageNumber.setMinValue(first_image)
        self.imageNumber.setMaxValue(last_image)
        self.imageNumber.blockSignals(False)

        try:
            comments = collect_dict["comment"]
        except KeyError:
            comments = ""

        self.resultStatus.setText(status_msg)
        self.resultMessage.setText(status_detailed_msg)
        self.resultTime.setText(time_msg)
        self.resultDirectory.setText(directory)
        self.resultTemplate.setText(template)
        self.resultImages.setText("%d to %d" % (first_image, last_image))

        if datacollectionid is not None and self.dbServer is not None:
            self.resultComments.setReadOnly(False)
            self.commentsButton.setEnabled(True)
            # get current comments from ispyb (new thread? :P)!
            self.resultComments.setText("")
        else:
            self.resultComments.setText(comments)
            self.resultComments.setReadOnly(True)
            self.commentsButton.setEnabled(False)

        if osc_info is not None:
            if self.imageNumber.value() == first_image:
                self.imageNumber.valueChange()
            else:
                self.imageNumber.setValue(first_image)

        self.setEnabled(True)

    def updateOscillation(self, osc_id):
        if self.oscillationInfo is None:
            return
        if self.oscillationId == osc_id:
            self.setOscillation(self.oscillationId)

    def setUpdateIcon(self, icon_name):
        self.commentsButton.setPixmap(Icons.load(icon_name))