-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathblacs_tabs.py
More file actions
236 lines (180 loc) · 9.85 KB
/
Copy pathblacs_tabs.py
File metadata and controls
236 lines (180 loc) · 9.85 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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
from blacs.device_base_class import DeviceTab
from labscript import LabscriptError
from blacs.tab_base_classes import define_state,Worker
from blacs.tab_base_classes import MODE_MANUAL, MODE_TRANSITION_TO_BUFFERED, MODE_TRANSITION_TO_MANUAL, MODE_BUFFERED
from blacs.device_base_class import DeviceTab
import os
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import QSize
from PyQt5 import uic
class KeysightScopeTab(DeviceTab):
'''The device class handles the creation + interaction with the GUI ~ QueueManager'''
def initialise_workers(self):
# Here we can change the initialization properties in the connection table
worker_initialisation_kwargs = self.connection_table.find_by_name(self.device_name).properties
# Adding porperties as follows allows the blacs worker to access them
# This comes in handy for the device initialization
worker_initialisation_kwargs['address'] = self.BLACS_connection
# Create the device worker
self.create_worker(
'main_worker',
'labscript_devices.KeysightScope.blacs_workers.KeysightScopeWorker',
worker_initialisation_kwargs,
)
self.primary_worker = 'main_worker'
def initialise_GUI(self):
# The osci widget
self.osci_widget = OsciTab()
self.get_tab_layout().addWidget(self.osci_widget)
# Connect radio buttons (activate slot)
for i in range(10):
self.radio_button = self.osci_widget.findChild(QRadioButton, f"activeRadioButton_{i}")
self.radio_button.clicked.connect(lambda checked, i=i: self.activate_radio_button(i))
# Connect load buttons (load current)
self.load_button = self.osci_widget.findChild(QPushButton, f"loadButton_{i}")
self.load_button.clicked.connect(lambda clicked, i=i: self.load_current_config(i))
# Connect reset buttons (default buttons)
self.default_button = self.osci_widget.findChild(QPushButton, f"defaultButton_{i}")
self.default_button.clicked.connect(lambda clicked, i=i: self.default_config(i))
# Loads the Osci Configurations
self.init_osci()
return
@define_state(MODE_MANUAL|MODE_BUFFERED|MODE_TRANSITION_TO_BUFFERED|MODE_TRANSITION_TO_MANUAL,True,True)
def init_osci(self, widget=None ):
list_dict_config = yield(self.queue_work(self._primary_worker,'init_osci'))
for key,value in list_dict_config.items():
if value:
self.osci_widget.load_parameters(current_dict=value , table_index= key)
else:
self.default_config( button_id=key)
@define_state(MODE_MANUAL|MODE_BUFFERED|MODE_TRANSITION_TO_BUFFERED|MODE_TRANSITION_TO_MANUAL,True,True)
def activate_radio_button(self,buttton_id, widget=None ):
yield(self.queue_work(self._primary_worker,'activate_radio_button',buttton_id))
@define_state(MODE_MANUAL|MODE_BUFFERED|MODE_TRANSITION_TO_BUFFERED|MODE_TRANSITION_TO_MANUAL,True,True)
def load_current_config(self,button_id, widget=None ):
dict_config = yield(self.queue_work(self._primary_worker,'load_current_config',button_id))
self.osci_widget.load_parameters(current_dict=dict_config , table_index= button_id)
@define_state(MODE_MANUAL|MODE_BUFFERED|MODE_TRANSITION_TO_BUFFERED|MODE_TRANSITION_TO_MANUAL,True,True)
def default_config(self,button_id, widget=None ):
dict_config = yield(self.queue_work(self._primary_worker,'default_config',button_id))
self.osci_widget.load_parameters(current_dict=dict_config , table_index= button_id)
class TabTemplate(QWidget):
""" A Tab template class that defines the oscilloscope configuration in a table format,
designed to describe the most important settings for the ten available storage slots of the oscilloscope."""
def __init__(self,parent=None):
super().__init__(parent)
tab_template_name = 'tab_template.ui'
tab_template_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),tab_template_name)
uic.loadUi(tab_template_path,self)
class OsciTab(QWidget):
""" The oscilloscope Widget """
def __init__(self, parent=None):
super().__init__(parent)
tabs_name = 'tabs.ui'
tabs_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),tabs_name)
uic.loadUi(tabs_path,self)
# --- Children
self.tabWidget = self.findChild(QTabWidget,"tabWidget")
self.previous_checked_index = None
self.label_active_setup = self.findChild(QLabel,"label_active_setup")
self.button_group = QButtonGroup(self)
reset_icon = self.style().standardIcon(QStyle.SP_BrowserReload)
load_icon = self.style().standardIcon(QStyle.SP_DialogOpenButton)
for i in range(self.tabWidget.count()):
# --- Promote Tabs
self.tabWidget.removeTab(i)
self.tabWidget.insertTab(i, TabTemplate(), f"s{i}") # Add the new widget to the layout
tab = self.tabWidget.widget(i)
# --- LoadButtons
self.load_button = tab.findChild(QPushButton , "loadButton")
self.load_button.setObjectName(f"loadButton_{i}")
self.load_button.setIcon(load_icon)
self.load_button.setIconSize(QSize(16,16))
if i !=0:
self.load_button.setEnabled(False) # init condition
# --- resetButtons
self.default_button = tab.findChild(QPushButton , "defaultButton")
self.default_button.setObjectName(f"defaultButton_{i}")
self.default_button.setIcon(reset_icon)
self.default_button.setIconSize(QSize(16,16))
if i !=0:
self.default_button.setEnabled(False) # init condition
for i in range(self.tabWidget.count()):
tab = self.tabWidget.widget(i)
# --- RadioButtons
radio_button = tab.findChild(QRadioButton, "activeRadioButton")
radio_button.setObjectName(f"activeRadioButton_{i}")
self.button_group.addButton(radio_button)
self.button_group.setId(radio_button, i )
radio_button.toggled.connect(self.radio_toggled )
# --- TableWidgets
self.tableWidget = tab.findChild(QTableWidget, "tableWidget")
self.tableWidget.setObjectName(f"table_{i}")
self.tableWidget.setRowCount(30)
self.tableWidget.setColumnCount(2)
self.tableWidget.setHorizontalHeaderLabels(["Parameter", "Value"])
self.tableWidget.setEditTriggers(QTableWidget.NoEditTriggers)
header = self.tableWidget.horizontalHeader()
header.setSectionResizeMode(QHeaderView.Stretch) # Stretch all columns to fill the space
# --- Style Sheet
self.sh_tab = """
QTabBar::tab {
background: qlineargradient(x1:0, y1:0, x2:0, y2:1,
stop:0 #ffffff, stop:1 #dddddd);
border: 1px solid #aaa;
border-top-left-radius: 8px;
border-top-right-radius: 8px;
padding: 10px 20px;
color: #333;
font-weight: bold;
}
"""
self.sh_selected_tab = """
QTabBar::tab:selected {
background: qlineargradient(x1:0, y1:0, x2:0, y2:1,
stop:0 #7BD77B, stop:1 #68C068);
color: white;
border-bottom: 2px solid #339933;
}
"""
self.tabWidget.setStyleSheet(self.sh_tab + self.sh_selected_tab)
# --- init
self.button_group.button(0).setChecked(True)
self.tabWidget.setCurrentIndex(0)
# --- Connecting the radio buttons
def radio_toggled (self):
selected_button = self.sender()
if self.previous_checked_index is not None:
self.tabWidget.setTabText(self.previous_checked_index, f"s{self.previous_checked_index}" )
tab = self.tabWidget.widget(self.previous_checked_index)
self.load_button = tab.findChild(QPushButton, f"loadButton_{self.previous_checked_index}")
self.default_button = tab.findChild(QPushButton , f"defaultButton_{self.previous_checked_index}")
if self.load_button:
self.load_button.setEnabled(False)
if self.default_button:
self.default_button.setEnabled(False)
if selected_button.isChecked():
index = self.button_group.id(selected_button)
self.label_active_setup.setText("Active setup : " + self.tabWidget.tabText(index) )
self.tabWidget.setTabText(index,f"🔴")
tab = self.tabWidget.widget(index)
self.load_button = tab.findChild(QPushButton,f"loadButton_{index}")
self.default_button = tab.findChild(QPushButton , f"defaultButton_{index}")
if self.load_button:
self.load_button.setEnabled(True)
if self.default_button:
self.default_button.setEnabled(True)
self.previous_checked_index = index
# --- Fill TableWidget
def load_parameters(self, current_dict , table_index):
for i, (key, value) in enumerate(current_dict.items()):
self.tableWidget= self.findChild(QTableWidget, f"table_{table_index}")
self.tableWidget.setItem(i, 0, QTableWidgetItem(str(key)))
self.tableWidget.setItem(i, 1, QTableWidgetItem(str(value)))
# ------------------------------------------------- Tests
if __name__ == "__main__":
app = QApplication(sys.argv)
window = OsciTab()
window.show()
sys.exit(app.exec())