Commit 5d43b268 authored by Matt Cumber's avatar Matt Cumber
Browse files

Re #30905 Added Tyoe

Added daq or dwell type to the table. Fixed a problem with the code in widget. Added clear method
parent b14d4b16
......@@ -107,7 +107,8 @@ void LoadMuonNexus::init() {
declareProperty(
std::make_unique<ArrayProperty<std::string>>("PeriodsInformation"),
"An array of strings which hold period information. This array is in the "
"format ['NumberOfSequences', 'Labels', 'Frames', 'TotalFrames']. Empty "
"format ['NumberOfSequences', 'Labels', 'Type', 'Frames', "
"'TotalFrames']. Empty "
"strings "
"show no value "
"could be read from file.");
......
......@@ -124,9 +124,9 @@ void MuonNexusReader::readFromFile(const string &filename) {
handle.readData("name", nexus_instrument_name);
// Try to read in period information
std::vector<std::string> periodInformation{"period_sequences", "period_labels",
"frames_period_requested",
"frames_period_raw"};
std::vector<std::string> periodInformation{
"period_sequences", "period_labels", "period_type",
"frames_period_requested", "frames_period_raw"};
try {
handle.openGroup("beam", "NXbeam");
for (const auto &info : periodInformation) {
......@@ -137,7 +137,7 @@ void MuonNexusReader::readFromFile(const string &filename) {
handle.readData(info, temp);
tempString = std::to_string(temp);
} else if (info == "frames_period_requested" ||
info == "frames_period_raw") {
info == "frames_period_raw" || info == "period_type") {
std::vector<int> temp;
handle.readData(info, temp);
for (const auto &value : temp)
......
......@@ -231,6 +231,7 @@ class MuonDataContext(object):
self._loaded_data.clear()
self._current_runs = []
self._main_field_direction = ''
self.periods_info = []
def _base_run_name(self, run=None):
""" e.g. EMU0001234 """
......
......@@ -296,9 +296,3 @@ class GroupingTabModel(object):
def get_periods(self, name):
return self._groups_and_pairs[name].periods
def get_period_labels(self):
return self._data.period_labels
def get_num_period_cycles(self):
return self._data.num_period_cycles
......@@ -12,7 +12,7 @@ from Muon.GUI.Common import thread_model
from Muon.GUI.Common.run_selection_dialog import RunSelectionDialog
from Muon.GUI.Common.thread_model_wrapper import ThreadModelWrapper
from Muon.GUI.Common.utilities.run_string_utils import run_string_to_list
from Muon.GUI.Common.muon_period_info import MuonPeriodInfoWidget, HEADER_COLUMN_MAP, PERIOD_INFO_NOT_FOUND
from Muon.GUI.Common.muon_period_info import MuonPeriodInfoWidget, CONTEXT_MAP, PERIOD_INFO_NOT_FOUND
class GroupingTabPresenter(object):
......@@ -253,6 +253,7 @@ class GroupingTabPresenter(object):
self.update_description_text_to_empty()
def handle_new_data_loaded(self):
self.period_info_widget.clear()
if self._model.is_data_loaded():
self._model._context.show_raw_data()
self.update_view_from_model()
......@@ -281,20 +282,21 @@ class GroupingTabPresenter(object):
self.grouping_table_widget.plot_default_case()
def handle_period_information_button_clicked(self):
if self._model._data.periods_info:
if self._model.is_data_loaded() and self.period_info_widget.is_empty():
self._add_period_info_to_widget()
self.period_info_widget.show()
def _add_period_info_to_widget(self):
self.period_info_widget.number_of_sequences = self._model._data.periods_info[0]
names = self._model._data.periods_info[HEADER_COLUMN_MAP["Name"]].split(';')
frames = self._model._data.periods_info[HEADER_COLUMN_MAP["Frames"]].split(';')
total_frames = self._model._data.periods_info[HEADER_COLUMN_MAP["Total Frames"]].split(';')
names, frames, total_frames, count = self._fix_up_period_info_lists(names, frames, total_frames)
names = self._model._data.periods_info[CONTEXT_MAP["Name"]].split(';')
types = self._model._data.periods_info[CONTEXT_MAP["Type"]].split(';')
frames = self._model._data.periods_info[CONTEXT_MAP["Frames"]].split(';')
total_frames = self._model._data.periods_info[CONTEXT_MAP["Total Frames"]].split(';')
names, types, frames, total_frames, count = self._fix_up_period_info_lists(names, types, frames, total_frames)
for i in range(count):
self.period_info_widget.add_period_to_table(names[i], frames[i], total_frames[i])
self.period_info_widget.add_period_to_table(names[i], types[i], frames[i], total_frames[i])
def _fix_up_period_info_lists(self, names, frames, total_frames):
def _fix_up_period_info_lists(self, names, types, frames, total_frames):
# First find number of periods
count = max(len(names), len(frames), len(total_frames))
# Then make sure lists are correct size
......@@ -303,6 +305,11 @@ class GroupingTabPresenter(object):
names = [PERIOD_INFO_NOT_FOUND] * count
else:
names += [PERIOD_INFO_NOT_FOUND] * count-len(names)
if len(types) != count:
if types[0] == "":
types = [PERIOD_INFO_NOT_FOUND] * count
else:
types += [PERIOD_INFO_NOT_FOUND] * count-len(types)
if len(frames) != count:
if frames[0] == "":
frames = [PERIOD_INFO_NOT_FOUND] * count
......@@ -313,7 +320,7 @@ class GroupingTabPresenter(object):
total_frames = [PERIOD_INFO_NOT_FOUND] * count
else:
total_frames += [PERIOD_INFO_NOT_FOUND] * count - len(total_frames)
return names, frames, total_frames, count
return names, types, frames, total_frames, count
# ------------------------------------------------------------------------------------------------------------------
# Observer / Observable
......
......@@ -7,14 +7,23 @@
from qtpy import QtWidgets, PYQT4, QtCore
from Muon.GUI.Common.utilities import table_utils
HEADERS = ["Period Number", "Name", "Frames", "Total Frames"]
HEADERS = ["Period Number", "Name", "Type", "DAQ Number", "Frames", "Total Frames"]
HEADER_STYLE = "QHeaderView { font-weight: bold; }"
COLUMN_COUNT = 4
COLUMN_COUNT = 6
HEADER_COLUMN_MAP = {"Period Number": 0,
"Name": 1,
"Frames": 2,
"Total Frames": 3}
"Type": 2,
"DAQ Number": 3,
"Frames": 4,
"Total Frames": 5}
CONTEXT_MAP = {"Name": 1,
"Type": 2,
"Frames": 3,
"Total Frames": 4}
PERIOD_INFO_NOT_FOUND = "Not found"
DWELL_STRING = "-"
DAQ = "1"
DWELL = "2"
class MuonPeriodInfoWidget(QtWidgets.QWidget):
......@@ -27,7 +36,8 @@ class MuonPeriodInfoWidget(QtWidgets.QWidget):
self._label = None
self._table = None
self._number_of_sequencs = 0
self._number_of_sequences = 0
self._daq_count = 0
# Create layout
self._create_layout()
......@@ -39,19 +49,37 @@ class MuonPeriodInfoWidget(QtWidgets.QWidget):
@number_of_sequences.setter
def number_of_sequences(self, value):
self._number_of_sequences = value
if self.label:
if self._label:
if value:
self.label.setText("Run contains " + value + " cycles of periods")
self._label.setText("Run contains " + value + " cycles of periods")
else:
self.label.setText("Number of period cycles not found")
self._label.setText("Number of period cycles not found")
def add_period_to_table(self, name, frames, total_frames):
def add_period_to_table(self, name, type, frames, total_frames):
row_num = self._num_rows()
self.table.insertRow(row_num)
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
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))
if type == DAQ:
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)))
elif type == DWELL:
self._table.setItem(row_num, HEADER_COLUMN_MAP["Type"], self._new_text_widget("DWELL"))
self._table.setItem(row_num, HEADER_COLUMN_MAP["DAQ Number"], self._new_text_widget(DWELL_STRING))
self._table.setItem(row_num, HEADER_COLUMN_MAP["Frames"], self._new_text_widget(frames))
self._table.setItem(row_num, HEADER_COLUMN_MAP["Total Frames"], self._new_text_widget(total_frames))
def is_empty(self):
if self._num_rows() > 0:
return False
return True
def clear(self):
self._daq_count = 0
self.number_of_sequences = 0 # Use setter here to reset label
for row in reversed(range(self._num_rows())):
self._table.removeRow(row)
def _new_text_widget(self, text):
new_widget = table_utils.ValidatedTableItem(lambda text: True)
......@@ -60,16 +88,16 @@ class MuonPeriodInfoWidget(QtWidgets.QWidget):
return new_widget
def _num_rows(self):
return self.table.rowCount()
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._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.layout.addWidget(self._label)
self.layout.addWidget(self._table)
self.setLayout(self.layout)
self.setWindowTitle("Period Information")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment