-
Notifications
You must be signed in to change notification settings - Fork 3
/
guihelpfuncs.py
173 lines (132 loc) · 5.54 KB
/
guihelpfuncs.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
from PyQt4.QtCore import *
from PyQt4.QtGui import *
coldict = {'blue':'b', 'lightblue':'#7A88FF', 'purple':'#AF7AFF', \
'orange':'#FFAF7A', 'bgcolor':'#DEDEDE'} #'blue':'#6600FF'
coldict_rgb = {'blue':(102, 0, 255), 'lightblue':(122, 136, 255), \
'purple':(175, 122, 255), 'orange':(255, 175, 122), \
'bgcolor':(222, 222, 222)}
def create_labeledbox(labeltext, direction='hor', stretch=None):
"""Convenience function to generate a layout with two QLabels"""
label = QLabel(labeltext)
box = QLabel()
box.setFrameStyle(QFrame.StyledPanel)
if direction=='hor':
layout = QHBoxLayout()
elif direction=='vert':
layout = QVBoxLayout()
layout.addWidget(label)
if not stretch:
layout.addWidget(box)
else:
layout.addWidget(box, stretch)
return box, layout
def create_labeledspinbox(labeltext, range=(0, 99), direction='hor',
stretch=None, intvals=True, active=False):
"""Convenience function to generate a layout with a labeled spinbox
If labelmsg is not None, right-clicking on the label emits a LabelMsg,
with `labelmsg` as the string argument.
"""
if active:
label = RightClickLabel(labeltext)
else:
label = QLabel(labeltext)
palette = QPalette()
palette.setBrush(QPalette.Foreground, Qt.black)
label.setPalette(palette)
if intvals:
box = QSpinBox()
else:
box = QDoubleSpinBox()
box.setRange(*range)
if direction=='hor':
layout = QHBoxLayout()
elif direction=='vert':
layout = QVBoxLayout()
layout.addWidget(label)
if not stretch:
layout.addWidget(box)
else:
layout.addWidget(box, stretch)
if active:
return box, layout, label
else:
return box, layout
def create_roibox(boxtext, xrange=(0, 2500), yrange=(0, 2500), color=None):
"""Returns a groupbox with ROI coordinate input boxes"""
x0, x0layout, x0label = create_labeledspinbox('X0', range=xrange,
active=True)
x1, x1layout, x1label = create_labeledspinbox('X1', range=xrange,
active=True)
y0, y0layout = create_labeledspinbox('Y0', range=yrange)
y1, y1layout = create_labeledspinbox('Y1', range=yrange)
x1.setValue(xrange[1])
y1.setValue(yrange[1])
setbutton = QPushButton("Set ROI")
clearbutton = QPushButton("Clear ROI")
boxlayout = QGridLayout()
boxlayout.addLayout(x0layout, 0, 0)
boxlayout.addLayout(x1layout, 1, 0)
boxlayout.addLayout(y0layout, 0, 1)
boxlayout.addLayout(y1layout, 1, 1)
boxlayout.addWidget(setbutton, 0, 2)
boxlayout.addWidget(clearbutton, 1, 2)
roibox = QGroupBox(boxtext)
roibox.setLayout(boxlayout)
roibox.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
return (roibox, [x0, x1, y0, y1], setbutton, clearbutton, [x0label, x1label])
class ImgCtrlBox():
def __init__(self, coldict, boxtext='Image Ctrl', color=None):
"""Returns a groupbox with a colormap combobox and vmin/max spinboxes."""
self.colmapCtrl = QComboBox()
for cmap in coldict.keys():
self.colmapCtrl.addItem(cmap)
self.colmapCtrl.setCurrentIndex(self.colmapCtrl.findText('gray'))
self.minCtrl, minlayout = create_labeledspinbox('vmin', range=(0, 1e5),
intvals=False)
self.maxCtrl, maxlayout = create_labeledspinbox('vmax', range=(0, 1e5),
intvals=False)
self.maxCtrl.setValue(1.35)
self.setVals = QPushButton("Set &values")
boxlayout = QGridLayout()
boxlayout.addLayout(minlayout, 0, 0)
boxlayout.addLayout(maxlayout, 1, 0)
boxlayout.addWidget(self.setVals, 0, 1)
boxlayout.addWidget(self.colmapCtrl, 1, 1)
self.colbox = QGroupBox(boxtext)
self.colbox.setLayout(boxlayout)
self.colbox.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
palette = QPalette()
imgctrl_color = QColor()
imgctrl_color.setNamedColor('steelblue')
palette.setBrush(QPalette.WindowText, imgctrl_color)
self.colbox.setPalette(palette)
class ImageMarker(QLabel):
"""Normal QLabel with the option to right-click and do something"""
def mousePressEvent(self, event):
"""Left-click is handled by MPL, right-click not."""
if event.button()==2:
self.emit(SIGNAL("ClearMarker"))
class RightClickLabel(QLabel):
"""Normal QLabel with the option to right-click and emit 'update' signal"""
def mousePressEvent(self, event):
"""Left-click is handled by MPL, right-click not."""
if event.button()==2:
self.emit(SIGNAL("LabelMsg"))
class MaxsizeDialog(QDialog):
def __init__(self, labeltext, parent=None):
"""This is a dialog to show error messages from plugins."""
super(MaxsizeDialog, self).__init__(parent)
self.setAttribute(Qt.WA_DeleteOnClose)
self.setWindowTitle('Odysseus - Plugin Error')
scrollArea = QScrollArea()
scrollArea.setWidgetResizable(True)
self.errorText = QLabel(labeltext)
self.errorText.setMaximumWidth(800)
self.errorText.setWordWrap(True)
scrollArea.setWidget(self.errorText)
self.scrollArea = scrollArea
layout = QVBoxLayout()
layout.addWidget(self.scrollArea)
self.setLayout(layout)
def sizeHint(self):
return QSize(850, 1000)