muon_period_info_widget.py 5.13 KB
Newer Older
1
2
3
4
5
6
# 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 +
7
from qtpy import QtWidgets, QtCore
8
9
from Muon.GUI.Common.utilities import table_utils

Matt Cumber's avatar
Matt Cumber committed
10
HEADERS = ["Period Number", "Name", "Type", "DAQ Number", "Frames", "Total Good Frames", "Counts", "Tag"]
11
HEADER_STYLE = "QHeaderView { font-weight: bold; }"
Matt Cumber's avatar
Matt Cumber committed
12
COLUMN_COUNT = 8
Matt Cumber's avatar
Matt Cumber committed
13
14
HEADER_COLUMN_MAP = {"Period Number": 0,
                     "Name": 1,
Matt Cumber's avatar
Matt Cumber committed
15
16
17
                     "Type": 2,
                     "DAQ Number": 3,
                     "Frames": 4,
Matt Cumber's avatar
Matt Cumber committed
18
                     "Total Good Frames": 5,
Matt Cumber's avatar
Matt Cumber committed
19
20
                     "Counts": 6,
                     "Tag": 7}
Matt Cumber's avatar
Matt Cumber committed
21
22
23
CONTEXT_MAP = {"Name": 1,
               "Type": 2,
               "Frames": 3,
Matt Cumber's avatar
Matt Cumber committed
24
               "Total Good Frames": 4,
Matt Cumber's avatar
Matt Cumber committed
25
26
               "Counts": 5,
               "Tag": 6}
Matt Cumber's avatar
Matt Cumber committed
27
PERIOD_INFO_NOT_FOUND = "Not found"
Matt Cumber's avatar
Matt Cumber committed
28
NOT_DAQ_STRING = "-"
Matt Cumber's avatar
Matt Cumber committed
29
30
DAQ = "1"
DWELL = "2"
Matt Cumber's avatar
Matt Cumber committed
31
CYCLES_NOT_FOUND = "Number of period cycles not found"
Matt Cumber's avatar
Matt Cumber committed
32
INFO_DELIM = ';'
33
34
35
36
37


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

    - Number of sequences is a string value
40
41
42
43
44
45
46
    """

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

        self._label = None
        self._table = None
Matt Cumber's avatar
Matt Cumber committed
47
        self._number_of_sequences = None
Matt Cumber's avatar
Matt Cumber committed
48
        self._daq_count = 0
49
50
51
52
53
54
55
56
57

        # Create layout
        self._create_layout()

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

    @number_of_sequences.setter
Matt Cumber's avatar
Matt Cumber committed
58
    def number_of_sequences(self, value: str):
59
        self._number_of_sequences = value
Matt Cumber's avatar
Matt Cumber committed
60
        if self._label:
61
            if value:
Matt Cumber's avatar
Matt Cumber committed
62
                self._label.setText("Run contains " + value + " cycles of periods")
63
            else:
Matt Cumber's avatar
Matt Cumber committed
64
                self._label.setText(CYCLES_NOT_FOUND)
65

Matt Cumber's avatar
Matt Cumber committed
66
67
68
69
    @property
    def daq_count(self):
        return self._daq_count

Matt Cumber's avatar
Matt Cumber committed
70
71
    def add_period_to_table(self, name=PERIOD_INFO_NOT_FOUND, period_type=PERIOD_INFO_NOT_FOUND,
                            frames=PERIOD_INFO_NOT_FOUND, total_frames=PERIOD_INFO_NOT_FOUND,
Matt Cumber's avatar
Matt Cumber committed
72
                            counts=PERIOD_INFO_NOT_FOUND, tag=PERIOD_INFO_NOT_FOUND):
73
        row_num = self._num_rows()
Matt Cumber's avatar
Matt Cumber committed
74
75
76
        self._table.insertRow(row_num)
        self._table.setItem(row_num, HEADER_COLUMN_MAP["Period Number"], self._new_text_widget(str(row_num + 1)))
        self._table.setItem(row_num, HEADER_COLUMN_MAP["Name"], self._new_text_widget(name))
Matt Cumber's avatar
Matt Cumber committed
77
        if period_type == DAQ:
Matt Cumber's avatar
Matt Cumber committed
78
79
80
            self._daq_count += 1
            self._table.setItem(row_num, HEADER_COLUMN_MAP["Type"], self._new_text_widget("DAQ"))
            self._table.setItem(row_num, HEADER_COLUMN_MAP["DAQ Number"], self._new_text_widget(str(self._daq_count)))
Matt Cumber's avatar
Matt Cumber committed
81
            self._table.setItem(row_num, HEADER_COLUMN_MAP["Counts"], self._new_text_widget(counts))
Matt Cumber's avatar
Matt Cumber committed
82
        elif period_type == DWELL:
Matt Cumber's avatar
Matt Cumber committed
83
            self._table.setItem(row_num, HEADER_COLUMN_MAP["Type"], self._new_text_widget("DWELL"))
Matt Cumber's avatar
Matt Cumber committed
84
85
            self._table.setItem(row_num, HEADER_COLUMN_MAP["DAQ Number"], self._new_text_widget(NOT_DAQ_STRING))
            self._table.setItem(row_num, HEADER_COLUMN_MAP["Counts"], self._new_text_widget(NOT_DAQ_STRING))
Matt Cumber's avatar
Matt Cumber committed
86
        self._table.setItem(row_num, HEADER_COLUMN_MAP["Frames"], self._new_text_widget(frames))
Matt Cumber's avatar
Matt Cumber committed
87
        self._table.setItem(row_num, HEADER_COLUMN_MAP["Total Good Frames"], self._new_text_widget(total_frames))
Matt Cumber's avatar
Matt Cumber committed
88
89
90
91
92
        try:
            tag = "{:04b}".format(int(tag))
        except ValueError:
            tag = PERIOD_INFO_NOT_FOUND
        self._table.setItem(row_num, HEADER_COLUMN_MAP["Tag"], self._new_text_widget(tag))
Matt Cumber's avatar
Matt Cumber committed
93
94
95
96
97
98
99
100

    def is_empty(self):
        if self._num_rows() > 0:
            return False
        return True

    def clear(self):
        self._daq_count = 0
Matt Cumber's avatar
Matt Cumber committed
101
        self.number_of_sequences = None  # Use setter here to reset label
Matt Cumber's avatar
Matt Cumber committed
102
103
        for row in reversed(range(self._num_rows())):
            self._table.removeRow(row)
104
105
106
107
108
109
110
111

    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):
Matt Cumber's avatar
Matt Cumber committed
112
        return self._table.rowCount()
113
114

    def _create_layout(self):
Matt Cumber's avatar
Matt Cumber committed
115
        self._label = QtWidgets.QLabel(CYCLES_NOT_FOUND)
Matt Cumber's avatar
Matt Cumber committed
116
117
118
119
        self._table = QtWidgets.QTableWidget(0, COLUMN_COUNT, parent=self)
        self._table.setHorizontalHeaderLabels(HEADERS)
        self._table.horizontalHeader().setStyleSheet(HEADER_STYLE)
        self._table.verticalHeader().setVisible(False)
Matt Cumber's avatar
Matt Cumber committed
120
121
122
        header = self._table.horizontalHeader()
        for i in range(COLUMN_COUNT):
            header.setSectionResizeMode(i, QtWidgets.QHeaderView.ResizeToContents)
123
        self.layout = QtWidgets.QVBoxLayout()
Matt Cumber's avatar
Matt Cumber committed
124
125
        self.layout.addWidget(self._label)
        self.layout.addWidget(self._table)
126
127
        self.setLayout(self.layout)
        self.setWindowTitle("Period Information")