-
Notifications
You must be signed in to change notification settings - Fork 0
/
control_relay.py
144 lines (119 loc) · 5.45 KB
/
control_relay.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
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 12 18:26:34 2013
@author: JG
"""
import numpy as np
from PySide import QtCore
from PySide import QtGui
#project specific items
import plot_tools
import control
import analysis
class ControlRelay(QtCore.QObject):
def __init__(self,tab):
self.tab = tab
self.window = control.ControlWindow()
self.current_tab = self.tab.currentWidget()
self.c = Communicate()
self.connect_events()
def connect_events(self):
self.window.connect(self.window.update, QtCore.SIGNAL('clicked()'),
self.update_values)
self.c.mincolor_sig.connect(self.update_mincolor_from_control)
self.c.maxcolor_sig.connect(self.update_maxcolor_from_control)
self.c.imageslice_sig.connect(self.update_imageslice_from_control)
self.c.graphslicex_sig.connect(self.update_graphslicex_from_control)
self.c.graphslicey_sig.connect(self.update_graphslicey_from_control)
self.window.ev.clicked.connect(self.display_ev)
self.window.wavelength.clicked.connect(self.display_wavelength)
def update_current(self):
self.current_tab = self.tab.currentWidget()
if self.current_tab.dataview.display_ev:
self.window.ev.setChecked(True)
else:
self.window.wavelength.setChecked(True)
self.window.update_label()
def display_ev(self):
self.current_tab.show_ev()
def display_wavelength(self):
self.current_tab.show_wavelength()
def update_graphslicex_from_control(self):
"""
takes control panel input and changes the current tab's
x coordinate for the displayed graph
"""
self.current_tab.dataview.x = int(self.window.graphslicex.text())
self.current_tab.marker.set_xdata(self.current_tab.dataview.x)
plot_tools.plot_graph(self.current_tab.img2,
self.current_tab.graph_axes,
self.current_tab.data,
self.current_tab.dataview)
def update_graphslicey_from_control(self):
"""
takes control panel input and changes the current tab's
y coordinate for the displayed graph
"""
self.current_tab.dataview.y = int(self.window.graphslicey.text())
self.current_tab.marker.set_ydata(self.current_tab.dataview.y)
plot_tools.plot_graph(self.current_tab.img2,
self.current_tab.graph_axes,
self.current_tab.data,
self.current_tab.dataview)
def update_imageslice_from_control(self):
"""
updates the imageslice from the input from the control panel.
the image displayed is the image with the first integer value
of the input
"""
slice_input = float(self.window.imageslice.text())
if self.current_tab.dataview.display_ev:
imageval = analysis.ev_to_index(slice_input,
self.current_tab.data)
self.current_tab.slider.setValue(imageval)
else:
imageval = analysis.wavelength_to_index(slice_input,
self.current_tab.data)
self.current_tab.slider.setValue(self.current_tab.number_of_slices\
- 1-imageval)
def update_maxcolor_from_control(self):
"""
takes control panel input and changes the current tab's
max color for the displayed graph
"""
self.current_tab.dataview.currentmaxvalcolor = int(self.window.maxcolor.text())
plot_tools.plot_image(self.current_tab.img,
self.current_tab.img_axes,
self.current_tab.data,
self.current_tab.dataview)
def update_mincolor_from_control(self):
"""
takes control panel input and changes the current tab's
min color for the displayed graph
"""
self.current_tab.dataview.currentminvalcolor = int(self.window.mincolor.text())
plot_tools.plot_image(self.current_tab.img,
self.current_tab.img_axes,
self.current_tab.data,
self.current_tab.dataview)
def update_values(self):
"""Updates values in main window and clears textboxes"""
objects = {self.c.maxcolor_sig:self.window.maxcolor,
self.c.mincolor_sig:self.window.mincolor,
self.c.imageslice_sig:self.window.imageslice,
self.c.graphslicex_sig:self.window.graphslicex,
self.c.graphslicey_sig:self.window.graphslicey}
for signal, item in objects.iteritems():
if item.text() != '':
signal.emit()
else:
pass
item.setText('')
class Communicate(QtCore.QObject):
"""Connects control panel to main window"""
maxcolor_sig = QtCore.Signal()
mincolor_sig = QtCore.Signal()
imageslice_sig = QtCore.Signal()
imageslice_sig = QtCore.Signal()
graphslicex_sig = QtCore.Signal()
graphslicey_sig = QtCore.Signal()