forked from M-Labs/artiq
1
0
Fork 0

Revert "browser: various fixes, handle startup path, connect activated"

This reverts commit c80510287b.
This commit is contained in:
Robert Jördens 2016-04-20 13:20:33 +02:00
parent c80510287b
commit 1f92e034da
2 changed files with 28 additions and 40 deletions

View File

@ -37,7 +37,7 @@ class ResultIconProvider(QtWidgets.QFileIconProvider):
class FilesDock(QtWidgets.QDockWidget): class FilesDock(QtWidgets.QDockWidget):
def __init__(self, datasets, main_window, path): def __init__(self, datasets, main_window, root=None):
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,23 +46,24 @@ 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.Drives) QtCore.QDir.AllDirs)
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("")) self.rt.setRootIndex(self.rt_model.setRootPath(root))
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.hideColumn(1) self.rt.setRootIsDecorated(False)
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()
@ -71,16 +72,13 @@ 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)
if path is not None: def showEvent(self, ev):
self.select(path) self.rt.hideColumn(1)
self.already_selected = True self.rt.hideColumn(2)
else: self.rt.hideColumn(3)
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)
@ -116,36 +114,23 @@ 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, file_or_dir): def select(self, path):
file_or_dir = os.path.abspath(file_or_dir) idx = self.rt_model.index(path)
if os.path.isdir(file_or_dir): if not idx.isValid():
idx = self.rt_model.index(file_or_dir) return
if idx.isValid(): self.rt.expand(idx)
self.rt.expand(idx) self.rt.scrollTo(idx)
self.rt.setCurrentIndex(idx) self.rt.setCurrentIndex(idx)
self.rt.scrollTo(idx) self.rl.setCurrentIndex(self.rl_model.index(path))
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.rl.currentIndex()), "selected": self.rl_model.filePath(self.rt.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"])

View File

@ -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, args.path) d_files = files.FilesDock(datasets_sub, main_window)
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,6 +119,9 @@ 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)