Skip to content

Commit

Permalink
Merge pull request #1032 from vasole/info
Browse files Browse the repository at this point in the history
Scan header motor information can be sorted by motor name or index
  • Loading branch information
vasole authored Sep 26, 2023
2 parents 04a2ca8 + 82c804f commit 03f559a
Showing 1 changed file with 58 additions and 75 deletions.
133 changes: 58 additions & 75 deletions PyMca5/PyMcaGui/io/SpecFileDataInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand All @@ -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() ]
Expand All @@ -119,41 +109,32 @@ def __createInfoTable(self):
self.__adjustTable(table)
self.addTab(table, "Info")

def __createTable(self, rows, head_par, head_val):
if qt.qVersion() < '4.0.0':
table= QTable(self)
def __createTable(self, rows, head_par, head_val, index=False):
table= QTable()
if index:
labels = ["Index"]
else:
table= QTable()
table.setColumnCount(2)
labels = []
labels = labels + [head_par, head_val]
table.setColumnCount(len(labels))
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)
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"]
Expand Down Expand Up @@ -188,17 +169,27 @@ def __createMotorTable(self):
print("Incorrent number of labels or values")
return
if num:
table= self.__createTable(num, "Motor", "Position")
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= self.__createTable(num, "Motor", "Position", index=True)
numbers = list(range(num))
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"]
Expand Down Expand Up @@ -241,12 +232,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("<BR>".join(text))
wid = qt.QTextEdit()
wid.insertHtml("<BR>".join(text))
wid.setReadOnly(1)
self.addTab(wid, "Scan Header")

Expand Down Expand Up @@ -274,12 +261,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("<BR>".join(text))
wid = qt.QTextEdit()
wid.insertHtml("<BR>".join(text))
wid.setReadOnly(1)
self.addTab(wid, "File Header")

Expand Down

0 comments on commit 03f559a

Please sign in to comment.