muon_period_info.py 2.99 KB
Newer Older
1
2
3
4
5
6
7
8
9
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2021 ISIS Rutherford Appleton Laboratory UKRI,
#   NScD Oak Ridge National Laboratory, European Spallation Source,
#   Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
from qtpy import QtWidgets, PYQT4, QtCore
from Muon.GUI.Common.utilities import table_utils

Matt Cumber's avatar
Matt Cumber committed
10
HEADERS = ["Period Number", "Name", "Frames", "Total Frames"]
11
HEADER_STYLE = "QHeaderView { font-weight: bold; }"
Matt Cumber's avatar
Matt Cumber committed
12
13
14
15
16
17
COLUMN_COUNT = 4
HEADER_COLUMN_MAP = {"Period Number": 0,
                     "Name": 1,
                     "Frames": 2,
                     "Total Frames": 3}
PERIOD_INFO_NOT_FOUND = "Not found"
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47


class MuonPeriodInfoWidget(QtWidgets.QWidget):
    """
    This is a simple widget used by the Muon GUI's to display additional information about periods of a run.
    """

    def __init__(self, parent=None):
        super(MuonPeriodInfoWidget, self).__init__(parent)

        self._label = None
        self._table = None
        self._number_of_sequencs = 0

        # Create layout
        self._create_layout()

    @property
    def number_of_sequences(self):
        return self._number_of_sequences

    @number_of_sequences.setter
    def number_of_sequences(self, value):
        self._number_of_sequences = value
        if self.label:
            if value:
                self.label.setText("Run contains " + value + " cycles of periods")
            else:
                self.label.setText("Number of period cycles not found")

Matt Cumber's avatar
Matt Cumber committed
48
    def add_period_to_table(self, name, frames, total_frames):
49
50
        row_num = self._num_rows()
        self.table.insertRow(row_num)
Matt Cumber's avatar
Matt Cumber committed
51
52
53
54
        self.table.setItem(row_num, HEADER_COLUMN_MAP["Period Number"], self._new_text_widget(str(row_num + 1)))  # Set period number
        self.table.setItem(row_num, HEADER_COLUMN_MAP["Name"], self._new_text_widget(name))  # Set name
        self.table.setItem(row_num, HEADER_COLUMN_MAP["Frames"], self._new_text_widget(frames))  # Set frames
        self.table.setItem(row_num, HEADER_COLUMN_MAP["Total Frames"], self._new_text_widget(total_frames))  # Set total frames
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75

    def _new_text_widget(self, text):
        new_widget = table_utils.ValidatedTableItem(lambda text: True)
        new_widget.setText(text)
        new_widget.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable)
        return new_widget

    def _num_rows(self):
        return self.table.rowCount()

    def _create_layout(self):
        self.label = QtWidgets.QLabel("Run contains 0 cycles of periods")
        self.table = QtWidgets.QTableWidget(0, COLUMN_COUNT, parent=self)
        self.table.setHorizontalHeaderLabels(HEADERS)
        self.table.horizontalHeader().setStyleSheet(HEADER_STYLE)
        self.table.verticalHeader().setVisible(False)
        self.layout = QtWidgets.QVBoxLayout()
        self.layout.addWidget(self.label)
        self.layout.addWidget(self.table)
        self.setLayout(self.layout)
        self.setWindowTitle("Period Information")