-
Notifications
You must be signed in to change notification settings - Fork 6
/
TraceListWidget.py
126 lines (106 loc) · 4.98 KB
/
TraceListWidget.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
from PyQt4 import QtGui
from PyQt4 import QtCore
from ParameterListWidget import ParameterList
from DataVaultListWidget import DataVaultList
from FitWindowWidget import FitWindow
from PredictSpectrumWidget import PredictSpectrum
from GUIConfig import traceListConfig
class TraceList(QtGui.QListWidget):
def __init__(self, parent):
super(TraceList, self).__init__()
self.parent = parent
self.windows = []
self.config = traceListConfig()
self.setStyleSheet("background-color:%s;" % self.config.background_color)
try:
self.use_trace_color = self.config.use_trace_color
except AttributeError:
self.use_trace_color = False
self.name = 'pmt'
self.initUI()
def initUI(self):
self.trace_dict = {}
item = QtGui.QListWidgetItem('Traces')
item.setCheckState(QtCore.Qt.Checked)
self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.customContextMenuRequested.connect(self.popupMenu)
def addTrace(self, ident, color):
item = QtGui.QListWidgetItem(ident)
if self.use_trace_color:
foreground_color = self.parent.getItemColor(color)
item.setForeground(foreground_color)
else:
item.setForeground(QtGui.QColor(255, 255, 255))
item.setBackground(QtGui.QColor(0, 0, 0))
item.setCheckState(QtCore.Qt.Checked)
self.addItem(item)
self.trace_dict[ident] = item
def removeTrace(self, ident):
item = self.trace_dict[ident]
row = self.row(item)
self.takeItem(row)
item = None
def changeTraceListColor(self, ident, new_color):
item = self.trace_dict[ident]
item.setForeground(self.parent.getItemColor(new_color))
def popupMenu(self, pos):
menu = QtGui.QMenu()
item = self.itemAt(pos)
if (item == None):
dataaddAction = menu.addAction('Add Data Set')
spectrumaddAction = menu.addAction('Add Predicted Spectrum')
action = menu.exec_(self.mapToGlobal(pos))
if action == dataaddAction:
dvlist = DataVaultList(self.parent.name)
self.windows.append(dvlist)
dvlist.show()
if action == spectrumaddAction:
ps = PredictSpectrum(self)
self.windows.append(ps)
ps.show()
else:
ident = str(item.text())
parametersAction = menu.addAction('Parameters')
togglecolorsAction = menu.addAction('Toggle colors')
fitAction = menu.addAction('Fit')
selectColorMenu = menu.addMenu("Select color")
redAction = selectColorMenu.addAction("Red")
greenAction = selectColorMenu.addAction("Green")
yellowAction = selectColorMenu.addAction("Yellow")
cyanAction = selectColorMenu.addAction("Cyan")
magentaAction = selectColorMenu.addAction("Magenta")
whiteAction = selectColorMenu.addAction("White")
colorActionDict = {redAction:"r", greenAction:"g", yellowAction:"y", cyanAction:"c", magentaAction:"m", whiteAction:"w"}
action = menu.exec_(self.mapToGlobal(pos))
if action == parametersAction:
# option to show parameters in separate window
dataset = self.parent.artists[ident].dataset
pl = ParameterList(dataset)
self.windows.append(pl)
pl.show()
if action == togglecolorsAction:
# option to change color of line
new_color = self.parent.colorChooser.next()
#self.parent.artists[ident].artist.setData(color = new_color, symbolBrush = new_color)
self.parent.artists[ident].artist.setPen(new_color)
if self.parent.show_points:
self.parent.artists[ident].artist.setData(pen = new_color, symbolBrush = new_color)
self.changeTraceListColor(ident, new_color)
else:
self.parent.artists[ident].artist.setData(pen = new_color)
self.changeTraceListColor(ident, new_color)
if action == fitAction:
dataset = self.parent.artists[ident].dataset
index = self.parent.artists[ident].index
fw = FitWindow(dataset, index, self)
self.windows.append(fw)
fw.show()
if action in colorActionDict.keys():
new_color = colorActionDict[action]
self.parent.artists[ident].artist.setPen(new_color)
if self.parent.show_points:
self.parent.artists[ident].artist.setData(pen = new_color, symbolBrush = new_color)
self.changeTraceListColor(ident, new_color)
else:
self.parent.artists[ident].artist.setData(pen = new_color)
self.changeTraceListColor(ident, new_color)