2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-25 19:28:26 +08:00

browser: double click

This commit is contained in:
Robert Jördens 2016-04-19 21:59:02 +02:00
parent ba24bbc8ed
commit 0b1b99be8a

View File

@ -60,8 +60,7 @@ class FilesDock(QtWidgets.QDockWidget):
def __init__(self, datasets, main_window, root=""): def __init__(self, datasets, main_window, root=""):
QtWidgets.QDockWidget.__init__(self, "Files") QtWidgets.QDockWidget.__init__(self, "Files")
self.setObjectName("Files") self.setObjectName("Files")
self.setFeatures(QtWidgets.QDockWidget.DockWidgetMovable | self.setFeatures(self.DockWidgetMovable | self.DockWidgetFloatable)
QtWidgets.QDockWidget.DockWidgetFloatable)
self.splitter = QtWidgets.QSplitter() self.splitter = QtWidgets.QSplitter()
self.setWidget(self.splitter) self.setWidget(self.splitter)
@ -95,15 +94,15 @@ class FilesDock(QtWidgets.QDockWidget):
self.splitter.addWidget(self.rt) self.splitter.addWidget(self.rt)
self.rl = QtWidgets.QListView() self.rl = QtWidgets.QListView()
self.rl.setViewMode(QtWidgets.QListView.IconMode) self.rl.setViewMode(self.rl.IconMode)
l = QtGui.QFontMetrics(self.font()).lineSpacing() l = QtGui.QFontMetrics(self.font()).lineSpacing()
self.rl.setIconSize(QtCore.QSize(20*l, 15*l)) self.rl.setIconSize(QtCore.QSize(20*l, 15*l))
self.rl.setFlow(QtWidgets.QListView.LeftToRight) self.rl.setFlow(self.rl.LeftToRight)
self.rl.setWrapping(True) self.rl.setWrapping(True)
self.rl.setModel(self.model) self.rl.setModel(self.model)
self.rl.selectionModel().currentChanged.connect( self.rl.selectionModel().currentChanged.connect(
self.list_current_changed) self.list_current_changed)
self.rl.doubleClicked.connect(self.open_experiment) self.rl.doubleClicked.connect(self.double_clicked)
self.splitter.addWidget(self.rl) self.splitter.addWidget(self.rl)
def tree_current_changed(self, current, previous): def tree_current_changed(self, current, previous):
@ -112,10 +111,10 @@ class FilesDock(QtWidgets.QDockWidget):
def list_current_changed(self, current, previous): def list_current_changed(self, current, previous):
info = self.model.fileInfo(current) info = self.model.fileInfo(current)
logger.info("opening %s", info.filePath())
f = open_h5(info) f = open_h5(info)
if not f: if not f:
return return
logger.info("loading datasets from %s", info.filePath())
with f: with f:
rd = {} rd = {}
try: try:
@ -126,12 +125,18 @@ class FilesDock(QtWidgets.QDockWidget):
rd[k] = True, group[k].value rd[k] = True, group[k].value
self.datasets.init(rd) self.datasets.init(rd)
def open_experiment(self, current): def double_clicked(self, current):
info = self.model.fileInfo(current) info = self.model.fileInfo(current)
logger.info("loading experiment for %s", info.filePath()) if info.isDir():
self.rl.setRootIndex(current)
idx = self.rt.model().mapFromSource(current)
self.rt.expand(idx)
self.rt.setCurrentIndex(idx)
return
f = open_h5(info) f = open_h5(info)
if not f: if not f:
return return
logger.info("loading experiment for %s", info.filePath())
with f: with f:
expid = pyon.decode(f["expid"].value) expid = pyon.decode(f["expid"].value)
@ -140,8 +145,6 @@ class FilesDock(QtWidgets.QDockWidget):
return return
idx = self.model.index(path) idx = self.model.index(path)
self.rl.setRootIndex(idx) self.rl.setRootIndex(idx)
idx = self.rt.model().mapFromSource(idx)
self.rt.expand(idx)
def scroll_when_loaded(p): def scroll_when_loaded(p):
if p != path: if p != path:
@ -152,6 +155,8 @@ class FilesDock(QtWidgets.QDockWidget):
self.rt.scrollTo(self.rt.model().mapFromSource( self.rt.scrollTo(self.rt.model().mapFromSource(
self.model.index(path)), self.rt.PositionAtCenter)) self.model.index(path)), self.rt.PositionAtCenter))
self.model.directoryLoaded.connect(scroll_when_loaded) self.model.directoryLoaded.connect(scroll_when_loaded)
idx = self.rt.model().mapFromSource(idx)
self.rt.expand(idx)
self.rt.setCurrentIndex(idx) self.rt.setCurrentIndex(idx)
def select_file(self, path): def select_file(self, path):