mirror of https://github.com/m-labs/artiq.git
browser: various fixes, handle startup path, connect activated
This commit is contained in:
parent
b00089c3d3
commit
c80510287b
|
@ -37,7 +37,7 @@ class ResultIconProvider(QtWidgets.QFileIconProvider):
|
||||||
|
|
||||||
|
|
||||||
class FilesDock(QtWidgets.QDockWidget):
|
class FilesDock(QtWidgets.QDockWidget):
|
||||||
def __init__(self, datasets, main_window, root=None):
|
def __init__(self, datasets, main_window, path):
|
||||||
QtWidgets.QDockWidget.__init__(self, "Files")
|
QtWidgets.QDockWidget.__init__(self, "Files")
|
||||||
self.setObjectName("Files")
|
self.setObjectName("Files")
|
||||||
self.setFeatures(QtWidgets.QDockWidget.DockWidgetMovable |
|
self.setFeatures(QtWidgets.QDockWidget.DockWidgetMovable |
|
||||||
|
@ -46,24 +46,23 @@ class FilesDock(QtWidgets.QDockWidget):
|
||||||
self.splitter = QtWidgets.QSplitter()
|
self.splitter = QtWidgets.QSplitter()
|
||||||
self.setWidget(self.splitter)
|
self.setWidget(self.splitter)
|
||||||
|
|
||||||
if root is None:
|
|
||||||
root = QtCore.QDir.currentPath()
|
|
||||||
|
|
||||||
self.datasets = datasets
|
self.datasets = datasets
|
||||||
self.main_window = main_window
|
self.main_window = main_window
|
||||||
|
|
||||||
self.rt_model = QtWidgets.QFileSystemModel()
|
self.rt_model = QtWidgets.QFileSystemModel()
|
||||||
self.rt_model.setFilter(QtCore.QDir.NoDotAndDotDot |
|
self.rt_model.setFilter(QtCore.QDir.NoDotAndDotDot |
|
||||||
QtCore.QDir.AllDirs)
|
QtCore.QDir.AllDirs | QtCore.QDir.Drives)
|
||||||
|
|
||||||
self.rt = QtWidgets.QTreeView()
|
self.rt = QtWidgets.QTreeView()
|
||||||
self.rt.setModel(self.rt_model)
|
self.rt.setModel(self.rt_model)
|
||||||
self.rt.setRootIndex(self.rt_model.setRootPath(root))
|
self.rt.setRootIndex(self.rt_model.setRootPath(""))
|
||||||
self.rt.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
|
self.rt.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
|
||||||
self.rt.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
|
self.rt.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
|
||||||
self.rt.selectionModel().currentChanged.connect(
|
self.rt.selectionModel().currentChanged.connect(
|
||||||
self.tree_current_changed)
|
self.tree_current_changed)
|
||||||
self.rt.setRootIsDecorated(False)
|
self.rt.hideColumn(1)
|
||||||
|
self.rt.hideColumn(2)
|
||||||
|
self.rt.hideColumn(3)
|
||||||
self.splitter.addWidget(self.rt)
|
self.splitter.addWidget(self.rt)
|
||||||
|
|
||||||
self.rl = QtWidgets.QListView()
|
self.rl = QtWidgets.QListView()
|
||||||
|
@ -72,13 +71,16 @@ class FilesDock(QtWidgets.QDockWidget):
|
||||||
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(QtWidgets.QListView.LeftToRight)
|
||||||
self.rl.setWrapping(True)
|
self.rl.setWrapping(True)
|
||||||
|
self.rl.setResizeMode(QtWidgets.QListView.Adjust)
|
||||||
self.tree_current_changed(self.rt.currentIndex(), None)
|
self.tree_current_changed(self.rt.currentIndex(), None)
|
||||||
|
self.rl.activated.connect(self.open_experiment)
|
||||||
self.splitter.addWidget(self.rl)
|
self.splitter.addWidget(self.rl)
|
||||||
|
|
||||||
def showEvent(self, ev):
|
if path is not None:
|
||||||
self.rt.hideColumn(1)
|
self.select(path)
|
||||||
self.rt.hideColumn(2)
|
self.already_selected = True
|
||||||
self.rt.hideColumn(3)
|
else:
|
||||||
|
self.already_selected = False
|
||||||
|
|
||||||
def tree_current_changed(self, current, previous):
|
def tree_current_changed(self, current, previous):
|
||||||
path = self.rt_model.filePath(current)
|
path = self.rt_model.filePath(current)
|
||||||
|
@ -114,23 +116,36 @@ 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 select(self, path):
|
def select(self, file_or_dir):
|
||||||
idx = self.rt_model.index(path)
|
file_or_dir = os.path.abspath(file_or_dir)
|
||||||
if not idx.isValid():
|
if os.path.isdir(file_or_dir):
|
||||||
return
|
idx = self.rt_model.index(file_or_dir)
|
||||||
self.rt.expand(idx)
|
if idx.isValid():
|
||||||
self.rt.scrollTo(idx)
|
self.rt.expand(idx)
|
||||||
self.rt.setCurrentIndex(idx)
|
self.rt.setCurrentIndex(idx)
|
||||||
self.rl.setCurrentIndex(self.rl_model.index(path))
|
self.rt.scrollTo(idx)
|
||||||
|
else:
|
||||||
|
idx = self.rt_model.index(os.path.dirname(file_or_dir))
|
||||||
|
if idx.isValid():
|
||||||
|
self.rt.expand(idx)
|
||||||
|
self.rt.setCurrentIndex(idx)
|
||||||
|
self.rt.scrollTo(idx)
|
||||||
|
|
||||||
|
idx = self.rl_model.index(file_or_dir)
|
||||||
|
if idx.isValid():
|
||||||
|
self.rl.setCurrentIndex(idx)
|
||||||
|
self.rl.scrollTo(idx)
|
||||||
|
|
||||||
|
def open_experiment(self, index):
|
||||||
|
print(self.rl_model.filePath(index))
|
||||||
|
|
||||||
def save_state(self):
|
def save_state(self):
|
||||||
return {
|
return {
|
||||||
"selected": self.rl_model.filePath(self.rt.currentIndex()),
|
"selected": self.rl_model.filePath(self.rl.currentIndex()),
|
||||||
"header": bytes(self.rt.header().saveState()),
|
|
||||||
"splitter": bytes(self.splitter.saveState()),
|
"splitter": bytes(self.splitter.saveState()),
|
||||||
}
|
}
|
||||||
|
|
||||||
def restore_state(self, state):
|
def restore_state(self, state):
|
||||||
self.select(state["selected"])
|
|
||||||
self.rt.header().restoreState(QtCore.QByteArray(state["header"]))
|
|
||||||
self.splitter.restoreState(QtCore.QByteArray(state["splitter"]))
|
self.splitter.restoreState(QtCore.QByteArray(state["splitter"]))
|
||||||
|
if not self.already_selected:
|
||||||
|
self.select(state["selected"])
|
||||||
|
|
|
@ -25,7 +25,7 @@ def get_argparser():
|
||||||
"--db-file", default=default_db_file,
|
"--db-file", default=default_db_file,
|
||||||
help="database file for local browser settings "
|
help="database file for local browser settings "
|
||||||
"(default: %(default)s)")
|
"(default: %(default)s)")
|
||||||
parser.add_argument("PATH", nargs="?", help="browse path or file")
|
parser.add_argument("path", nargs="?", help="browse path or file")
|
||||||
verbosity_args(parser)
|
verbosity_args(parser)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ def main():
|
||||||
status_bar = QtWidgets.QStatusBar()
|
status_bar = QtWidgets.QStatusBar()
|
||||||
main_window.setStatusBar(status_bar)
|
main_window.setStatusBar(status_bar)
|
||||||
|
|
||||||
d_files = files.FilesDock(datasets_sub, main_window)
|
d_files = files.FilesDock(datasets_sub, main_window, args.path)
|
||||||
smgr.register(d_files)
|
smgr.register(d_files)
|
||||||
|
|
||||||
d_applets = applets.AppletsDock(main_window, datasets_sub)
|
d_applets = applets.AppletsDock(main_window, datasets_sub)
|
||||||
|
@ -119,9 +119,6 @@ def main():
|
||||||
|
|
||||||
smgr.load()
|
smgr.load()
|
||||||
|
|
||||||
if args.PATH:
|
|
||||||
d_files.select(args.PATH)
|
|
||||||
|
|
||||||
smgr.start()
|
smgr.start()
|
||||||
atexit_register_coroutine(smgr.stop)
|
atexit_register_coroutine(smgr.stop)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue