From 79f55747bb54ed2f5145a2151a76f708e8af80fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=2E=20Armando=20Sol=C3=A9?= Date: Tue, 26 Sep 2023 12:37:51 +0200 Subject: [PATCH 1/3] Remove obsolete code --- PyMca5/PyMcaGui/io/SpecFileDataInfo.py | 99 +++++++++----------------- 1 file changed, 34 insertions(+), 65 deletions(-) diff --git a/PyMca5/PyMcaGui/io/SpecFileDataInfo.py b/PyMca5/PyMcaGui/io/SpecFileDataInfo.py index 83082a5c5..8d8d262d7 100644 --- a/PyMca5/PyMcaGui/io/SpecFileDataInfo.py +++ b/PyMca5/PyMcaGui/io/SpecFileDataInfo.py @@ -30,25 +30,19 @@ import sys from PyMca5.PyMcaGui import PyMcaQt as qt -try: - from silx.gui.widgets.TableWidget import TableWidget -except ImportError: - from PyMca5.PyMcaGui.misc.TableWidget import TableWidget +from PyMca5.PyMcaGui.misc.TableWidget import TableWidget QTVERSION = qt.qVersion() class QTable(TableWidget): def setText(self, row, col, text): - if qt.qVersion() < "4.0.0": - QTable.setText(self, row, col, text) + item = self.item(row, col) + if item is None: + item = qt.QTableWidgetItem(text, + qt.QTableWidgetItem.Type) + self.setItem(row, col, item) else: - item = self.item(row, col) - if item is None: - item = qt.QTableWidgetItem(text, - qt.QTableWidgetItem.Type) - self.setItem(row, col, item) - else: - item.setText(text) + item.setText(text) class SpecFileDataInfoCustomEvent(qt.QEvent): def __init__(self, ddict): @@ -84,13 +78,10 @@ class SpecFileDataInfo(qt.QTabWidget): ] def __init__(self, info, parent=None, name="DataSpecFileInfo", fl=0): - if QTVERSION < '4.0.0': - qt.QTabWidget.__init__(self, parent, name, fl) - self.setContentsMargins(5, 5, 5, 5) - else: - qt.QTabWidget.__init__(self, parent) - if name is not None:self.setWindowTitle(name) - self._notifyCloseEventToWidget = [] + qt.QTabWidget.__init__(self, parent) + if name is not None: + self.setWindowTitle(name) + self._notifyCloseEventToWidget = [] self.info= info self.__createInfoTable() self.__createMotorTable() @@ -99,14 +90,13 @@ def __init__(self, info, parent=None, name="DataSpecFileInfo", fl=0): self.__createEDFHeaderText() self.__createFileHeaderText() - if QTVERSION > '4.0.0': - def sizeHint(self): - return qt.QSize(2 * qt.QTabWidget.sizeHint(self).width(), - 3 * qt.QTabWidget.sizeHint(self).height()) + def sizeHint(self): + return qt.QSize(2 * qt.QTabWidget.sizeHint(self).width(), + 3 * qt.QTabWidget.sizeHint(self).height()) - def notifyCloseEventToWidget(self, widget): - if widget not in self._notifyCloseEventToWidget: - self._notifyCloseEventToWidget.append(widget) + def notifyCloseEventToWidget(self, widget): + if widget not in self._notifyCloseEventToWidget: + self._notifyCloseEventToWidget.append(widget) def __createInfoTable(self): pars= [ par for par in self.InfoTableItems if par[0] in self.info.keys() ] @@ -120,40 +110,27 @@ def __createInfoTable(self): self.addTab(table, "Info") def __createTable(self, rows, head_par, head_val): - if qt.qVersion() < '4.0.0': - table= QTable(self) - else: - table= QTable() + table= QTable() table.setColumnCount(2) table.setRowCount(rows) - if qt.qVersion() < '4.0.0': - table.setReadOnly(1) - table.setSelectionMode(QTable.SingleRow) - else: - table.setSelectionMode(qt.QTableWidget.NoSelection) + table.setSelectionMode(qt.QTableWidget.NoSelection) table.verticalHeader().hide() - if qt.qVersion() < '4.0.0': - table.setLeftMargin(0) - table.horizontalHeader().setLabel(0, head_par) - table.horizontalHeader().setLabel(1, head_val) - else: - labels = [head_par, head_val] - for i in range(len(labels)): - item = table.horizontalHeaderItem(i) - if item is None: - item = qt.QTableWidgetItem(labels[i], - qt.QTableWidgetItem.Type) - item.setText(labels[i]) - table.setHorizontalHeaderItem(i,item) + labels = [head_par, head_val] + for i in range(len(labels)): + item = table.horizontalHeaderItem(i) + if item is None: + item = qt.QTableWidgetItem(labels[i], + qt.QTableWidgetItem.Type) + item.setText(labels[i]) + table.setHorizontalHeaderItem(i,item) return table def __adjustTable(self, table): for col in range(table.columnCount()): table.resizeColumnToContents(col) - if qt.qVersion() > '4.0.0': - rheight = table.horizontalHeader().sizeHint().height() - for row in range(table.rowCount()): - table.setRowHeight(row, rheight) + rheight = table.horizontalHeader().sizeHint().height() + for row in range(table.rowCount()): + table.setRowHeight(row, rheight) def __createMotorTable(self): nameKeys = ["MotorNames", "motor_mne"] @@ -241,12 +218,8 @@ def __createHeaderText(self): return text= self.info.get("Header", None) if text is not None: - if qt.qVersion() < '4.0.0': - wid = qt.QTextEdit(self) - wid.setText("\n".join(text)) - else: - wid = qt.QTextEdit() - wid.insertHtml("
".join(text)) + wid = qt.QTextEdit() + wid.insertHtml("
".join(text)) wid.setReadOnly(1) self.addTab(wid, "Scan Header") @@ -274,12 +247,8 @@ def __createEDFHeaderText(self): def __createFileHeaderText(self): text= self.info.get("FileHeader", None) if text not in [None, []]: - if qt.qVersion() < '4.0.0': - wid = qt.QTextEdit(self) - wid.setText("\n".join(text)) - else: - wid = qt.QTextEdit() - wid.insertHtml("
".join(text)) + wid = qt.QTextEdit() + wid.insertHtml("
".join(text)) wid.setReadOnly(1) self.addTab(wid, "File Header") From d35b33440b703de66892e583844006696e8f48f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=2E=20Armando=20Sol=C3=A9?= Date: Tue, 26 Sep 2023 12:56:47 +0200 Subject: [PATCH 2/3] Allow copy to clipboard --- PyMca5/PyMcaGui/io/SpecFileDataInfo.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/PyMca5/PyMcaGui/io/SpecFileDataInfo.py b/PyMca5/PyMcaGui/io/SpecFileDataInfo.py index 8d8d262d7..c17856a4f 100644 --- a/PyMca5/PyMcaGui/io/SpecFileDataInfo.py +++ b/PyMca5/PyMcaGui/io/SpecFileDataInfo.py @@ -109,13 +109,17 @@ def __createInfoTable(self): self.__adjustTable(table) self.addTab(table, "Info") - def __createTable(self, rows, head_par, head_val): + def __createTable(self, rows, head_par, head_val, index=False): table= QTable() - table.setColumnCount(2) + if index: + labels = ["Index"] + else: + labels = [] + labels = labels + [head_par, head_val] + table.setColumnCount(len(labels)) table.setRowCount(rows) - table.setSelectionMode(qt.QTableWidget.NoSelection) + #table.setSelectionMode(qt.QTableWidget.NoSelection) table.verticalHeader().hide() - labels = [head_par, head_val] for i in range(len(labels)): item = table.horizontalHeaderItem(i) if item is None: @@ -165,15 +169,17 @@ def __createMotorTable(self): print("Incorrent number of labels or values") return if num: - table= self.__createTable(num, "Motor", "Position") + table= self.__createTable(num, "Motor", "Position", index=True) + numbers = list(range(num)) if sys.version_info > (3, 3): sorted_list = sorted(names, key=str.casefold) else: sorted_list = sorted(names) for i in range(num): idx = names.index(sorted_list[i]) - table.setText(i, 0, str(names[idx])) - table.setText(i, 1, str(pos[idx])) + table.setText(i, 0, "%d" % numbers[idx]) + table.setText(i, 1, str(names[idx])) + table.setText(i, 2, str(pos[idx])) self.__adjustTable(table) self.addTab(table, "Motors") From 82c804f8e3128c233a1ac4bac9c1ff1a2ae413c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=2E=20Armando=20Sol=C3=A9?= Date: Tue, 26 Sep 2023 13:32:21 +0200 Subject: [PATCH 3/3] Allow sorting by index or by name. --- PyMca5/PyMcaGui/io/SpecFileDataInfo.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/PyMca5/PyMcaGui/io/SpecFileDataInfo.py b/PyMca5/PyMcaGui/io/SpecFileDataInfo.py index c17856a4f..83809368f 100644 --- a/PyMca5/PyMcaGui/io/SpecFileDataInfo.py +++ b/PyMca5/PyMcaGui/io/SpecFileDataInfo.py @@ -171,17 +171,25 @@ def __createMotorTable(self): if num: table= self.__createTable(num, "Motor", "Position", index=True) numbers = list(range(num)) - if sys.version_info > (3, 3): - sorted_list = sorted(names, key=str.casefold) - else: - sorted_list = sorted(names) - for i in range(num): - idx = names.index(sorted_list[i]) - table.setText(i, 0, "%d" % numbers[idx]) - table.setText(i, 1, str(names[idx])) - table.setText(i, 2, str(pos[idx])) + def sort_column(column, table=table, numbers=numbers, names=names, positions=pos): + if column == 1: + sorted_list = sorted(names, key=str.casefold) + sorted_list = [names.index(x) for x in sorted_list] + else: + sorted_list = [int(x) for x in numbers] + for i in range(num): + idx = sorted_list[i] + table.setText(i, 0, "%d" % numbers[idx]) + table.setText(i, 1, str(names[idx])) + table.setText(i, 2, str(pos[idx])) + sort_column(0) + tip = "Copy selection to clipboard with CTRL-C." + tip += "\nDoubleclick on Index or Motor header to sort accordingly." + table.setToolTip(tip) self.__adjustTable(table) self.addTab(table, "Motors") + headerView = table.horizontalHeader() + headerView.sectionDoubleClicked[int].connect(sort_column) def __createCounterTable(self): nameKeys = ["LabelNames", "counter_mne"]