forked from HaeffnerLab/RealSimpleGrapher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrsg.py
More file actions
112 lines (94 loc) · 3.23 KB
/
rsg.py
File metadata and controls
112 lines (94 loc) · 3.23 KB
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
"""
The Real Simple Grapher
"""
import sys
from GraphWindow import GraphWindow
from RSGDataset import RSGDataset
from PyQt5 import QtGui
from PyQt5.QtWidgets import *
a = QApplication(sys.argv)
import qt5reactor
qt5reactor.install()
from twisted.internet.defer import inlineCallbacks
from twisted.internet import reactor
from labrad.server import LabradServer, setting
"""
### BEGIN NODE INFO
[info]
name = Real Simple Grapher
version = 1.0
description =
instancename = Real Simple Grapher
[startup]
cmdline = %PYTHON% %FILE%
timeout = 20
[shutdown]
message = 987654321
timeout = 5
### END NODE INFO
"""
class RealSimpleGrapher(LabradServer):
name = "Real Simple Grapher"
@inlineCallbacks
def initServer(self):
self.listeners = set()
self.gui = GraphWindow(reactor, cxn=self.client)
self.gui.setWindowTitle("Real Simple Grapher")
self.gui.setWindowIcon(QtGui.QIcon("icon.png"))
self.dv = yield self.client.data_vault
self.pv = yield self.client.parametervault
def make_dataset(self, dataset_location):
cxt = self.client.context()
ds = RSGDataset(self.dv, cxt, dataset_location, reactor)
return ds
def do_plot(self, dataset_location, graph, send_to_current):
if (graph != "current") and send_to_current:
# add the plot to the Current tab as well as an additional
# specified tab for later examination
ds = self.make_dataset(dataset_location)
self.gui.graphDict["current"].add_dataset(ds)
ds = self.make_dataset(dataset_location)
if graph in self.gui.hidden_tabs:
self.gui.insert_closed_tab(graph)
self.gui.hidden_tabs.remove(graph)
self.gui.graphDict[graph].add_dataset(ds)
# tabindex = self.gui.indexOf(self.gui.tabDict[graph])
# self.gui.setCurrentIndex(tabindex)
def do_imshow(self, data, image_size, graph, name):
self.gui.graphDict[graph].update_image(data, image_size, name)
@setting(
1,
"Plot",
dataset_location=["(*s, s)", "(*s, i)"],
graph="s",
send_to_current="b",
returns="",
)
def plot(self, c, dataset_location, graph, send_to_current=True):
self.do_plot(dataset_location, graph, send_to_current)
@setting(
2,
"Plot with axis",
dataset_location=["(*s, s)", "(*s, i)"],
graph="s",
axis="*v",
send_to_current="b",
returns="",
)
def plot_with_axis(self, c, dataset_location, graph, axis, send_to_current=True):
minim = min(axis)
maxim = max(axis)
if (graph != "current") and (send_to_current is True):
self.gui.graphDict["current"].set_xlimits(
[minim[minim.units], maxim[maxim.units]]
)
self.gui.graphDict[graph].set_xlimits([minim[minim.units], maxim[maxim.units]])
self.do_plot(dataset_location, graph, send_to_current)
@setting(
3, "Plot image", image="*i", image_size="*i", graph="s", name="s", returns=""
)
def plot_image(self, c, image, image_size, graph, name=""):
self.do_imshow(image, image_size, graph, name)
if __name__ == "__main__":
from labrad import util
util.runServer(RealSimpleGrapher())