Skip to content

Commit

Permalink
Merge pull request #1085 from vasole/characteristic
Browse files Browse the repository at this point in the history
[GUI] XRF Energy table characteristic energies
  • Loading branch information
vasole authored Aug 12, 2024
2 parents 9d19f38 + 7336ca4 commit 345b135
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions PyMca5/PyMcaGui/physics/xrf/EnergyTable.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# The PyMca X-Ray Fluorescence Toolkit
#
# Copyright (c) 2004-2023 European Synchrotron Radiation Facility
# Copyright (c) 2004-2024 European Synchrotron Radiation Facility
#
# This file is part of the PyMca X-ray Fluorescence Toolkit developed at
# the ESRF.
Expand Down Expand Up @@ -39,6 +39,7 @@
from PyMca5.PyMcaGui.plotting import PyMca_Icons as Icons
from PyMca5.PyMcaGui.io import PyMcaFileDialogs
qt = QXTube.qt
QTable = qt.QTableWidget

QTVERSION = qt.qVersion()

Expand Down Expand Up @@ -280,23 +281,23 @@ def __tubeUpdated(self, d):
self.__calculating = 0
self.tubeButtonClicked()

QTable = qt.QTableWidget

class EnergyTable(QTable):
sigEnergyTableSignal = qt.pyqtSignal(object)
def __init__(self, parent=None, name="Energy Table",
energylist=None, weightlist=None, flaglist=None,offset=None,scatterlist=None):
energylist=None, weightlist=None, flaglist=None,offset=None,scatterlist=None,scattercolor=None):
QTable.__init__(self, parent)
if energylist is None:energylist=[]
if weightlist is None:weightlist =[]
if flaglist is None:flaglist =[]
if scatterlist is None:scatterlist =[]
if scatterlist is None:scatterlist = []
if scattercolor is None: scattercolor = qt.QColor(255, 20, 147)
if offset is None:offset = 0
self.energyList = energylist
self.weightList = weightlist
self.flagList = flaglist
self.offset = offset
self.scatterList = scatterlist
self._scatterColor = scattercolor
self.verticalHeader().hide()
self.dataColumns = 30
if QTVERSION < '4.0.0':
Expand Down Expand Up @@ -341,10 +342,28 @@ def __init__(self, parent=None, name="Energy Table",
for i in range(self.dataColumns):
_logger.debug("column adjustment missing")
self.cellChanged[int, int].connect(self.mySlot)
if hasattr(self, "cellDoubleClicked"):
self.cellDoubleClicked[int, int].connect(self._doubleClickSlot)

def _itemSlot(self, *var):
self.mySlot(self.currentRow(), self.currentColumn())

def _doubleClickSlot(self, row, col):
_logger.debug("cell %d %d double clicked" % (row, col))
if col // self.dataColumns:
_logger.debug("Not an Energy column")
return
item = self.cellWidget(row, col)
if item is None:
return
oldcolor = item.color
if oldcolor != self._scatterColor:
item.setColor(self._scatterColor)
else:
item.setColor(qt.Qt.white)
item.repaint(item.rect())
self.cellChanged.emit(row, col)

def __build(self,nrows=None):
#self.setNumRows(int(nrows/2))
if nrows is None: nrows = self.__rows *self.dataColumns
Expand All @@ -370,9 +389,10 @@ def __build(self,nrows=None):
if idx < len(self.scatterList):
if (self.scatterList[idx] is not None)and \
(self.scatterList[idx] != "None"):
if self.scatterList[idx]:color = qt.QColor(255, 20, 147)
if self.scatterList[idx]:
color = self._scatterColor
elif idx == 0:
color = qt.QColor(255, 20, 147)
color = self._scatterColor
if QTVERSION < '4.0.0':
#item= qttable.QCheckTableItem(self, text)
self.viewport().setPaletteBackgroundColor(color)
Expand All @@ -384,6 +404,8 @@ def __build(self,nrows=None):
item= ColorQTableItem(self, text, color)
self.setCellWidget(r, 0+coloffset, item)
item.stateChanged[int].connect(self._itemSlot)
if hasattr(item, "setToolTip"):
item.setToolTip("Double click on empty space at the to toggle inclusion as scatter peak (different color)")
else:
item.setText(text)
oldcolor = item.color
Expand Down Expand Up @@ -467,7 +489,7 @@ def getParameters(self):
continue
else:
energyflag = int(item.isChecked())
if item.color == qt.Qt.white:
if item.color != self._scatterColor:
scatterflag = 0
else:
scatterflag = 1
Expand Down Expand Up @@ -589,7 +611,7 @@ def _getDict(self):
flag = 1
else:
flag = 0
if selfitem.color != qt.Qt.white:
if selfitem.color == self._scatterColor:
scatterflag = 1
else:
scatterflag = 0
Expand Down

0 comments on commit 345b135

Please sign in to comment.