-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcycle.py
More file actions
137 lines (93 loc) · 2.88 KB
/
cycle.py
File metadata and controls
137 lines (93 loc) · 2.88 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
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
# -*- coding: utf-8 -*-
# Pyblab
# Copyright (C) 2021 Marco Pizzocaro <m.pizzocaro@inrim.it>
#
# This file is part of Pyblab.
#
# Pyblab is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyblab is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Pyblab. If not, see <https://www.gnu.org/licenses/>.
from .scope import *
import time
import PySimpleGUI as sg
class Cycle(object):
"""
Basic Empty Cycle
a cycle has 3 methods.
1. pre()
2. wait_for_data()
3. post()
wait_for_data does what it says on the tin and save the data in self._data
self.n stores the number of acquisitions (between *all* cycles)
pre and post are to be defined by subclass of Cycle to do special things.
"""
def __init__(self, acq, synth=None, filo=None, name="", aux_synth=None, aux_freq=0.):
self.acq = acq
self.name = str(name)
self.synth = synth
self.file = filo
self.aux_synth = aux_synth
self.aux_freq = aux_freq
self.newdata_event = threading.Event()
self.newdata = []
self.scope = None
self.control = None
self.header = None
self.n = -1
def wait_for_data(self):
self._data, acq_n = self.acq.get_data()
self.n += 1
def pre(self):
pass
def post(self):
pass
def timetag(self):
return time.time()
def set_scope(self, **kwargs):
self.scope = Multiscope(self, **kwargs)
return self.scope
def set_control(self, **kwargs):
self.control = Control(self, self.scope, **kwargs)
return self.control
def close(self):
if self.scope:
self.scope.close()
if self.control:
self.control.close()
class Control(object):
"""
Basic Empty Control
Layout shoud be a PySimpleGUI layot shoud be defined y subclasses to provide
control to the exepriment.
"""
def __init__(self, cycle, scope, title=""):
self.layout = []
self.cycle = cycle
self.scope = scope
def on_event(self, event, values):
""" Process event, values from a PySimpleGUI windows read to do seomthing."""
pass
def close(self):
pass
def input_num(name, key, initial_value='', unit=''):
textunit = ''
if unit:
textunit = ' /' + unit
return [
sg.Text(name + textunit, size = (10, 1)),
sg.Input(initial_value, key=key, size=(13,1), justification='right')
]
def input_bool(name, key, initial_value=''):
return [
sg.Text(name, size = (10, 1)),
sg.Slider(range=(0,1), key=key, default_value=initial_value, orientation='h', size=(10,None), enable_events=True),
]