-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathDataVaultListWidget.py
55 lines (47 loc) · 1.71 KB
/
DataVaultListWidget.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
from PyQt4 import QtGui
from twisted.internet.defer import inlineCallbacks
import socket
class DataVaultList(QtGui.QWidget):
def __init__(self, tracename, parent=None):
super(DataVaultList, self).__init__()
self.tracename = tracename
self.connect()
@inlineCallbacks
def connect(self):
from labrad.wrappers import connectAsync
self.cxn = yield connectAsync(name=socket.gethostname() + ' Data Vault Client')
self.grapher = yield self.cxn.grapher
self.dv = yield self.cxn.data_vault
self.initializeGUI()
def initializeGUI(self):
mainLayout = QtGui.QVBoxLayout()
self.dataListWidget = QtGui.QListWidget()
self.dataListWidget.doubleClicked.connect(self.onDoubleclick)
mainLayout.addWidget(self.dataListWidget)
self.setWindowTitle('Data Vault')
self.setLayout(mainLayout)
self.populate()
self.show()
@inlineCallbacks
def populate(self):
self.dataListWidget.clear()
ls = yield self.dv.dir()
self.dataListWidget.addItem('...')
self.dataListWidget.addItems(sorted(ls[0]))
if ls[1] is not None:
self.dataListWidget.addItems(sorted(ls[1]))
@inlineCallbacks
def onDoubleclick(self, item):
item = self.dataListWidget.currentItem().text()
if item == '...':
yield self.dv.cd(1)
self.populate()
else:
try:
yield self.dv.cd(str(item))
self.populate()
except:
path = yield self.dv.cd()
yield self.grapher.plot((path, str(item)), self.tracename, False)
def closeEvent(self, event):
self.cxn.disconnect()