From 1f92e034dae57c34d6fbde2471e940246aca875b Mon Sep 17 00:00:00 2001 From: Robert Jordens Date: Wed, 20 Apr 2016 13:20:33 +0200 Subject: [PATCH] Revert "browser: various fixes, handle startup path, connect activated" This reverts commit c80510287b9239119249c0ba815f69b279839fae. --- artiq/browser/files.py | 61 +++++++++++++-------------------- artiq/frontend/artiq_browser.py | 7 ++-- 2 files changed, 28 insertions(+), 40 deletions(-) diff --git a/artiq/browser/files.py b/artiq/browser/files.py index 25e6115a4..51e034f2c 100644 --- a/artiq/browser/files.py +++ b/artiq/browser/files.py @@ -37,7 +37,7 @@ class ResultIconProvider(QtWidgets.QFileIconProvider): class FilesDock(QtWidgets.QDockWidget): - def __init__(self, datasets, main_window, path): + def __init__(self, datasets, main_window, root=None): QtWidgets.QDockWidget.__init__(self, "Files") self.setObjectName("Files") self.setFeatures(QtWidgets.QDockWidget.DockWidgetMovable | @@ -46,23 +46,24 @@ class FilesDock(QtWidgets.QDockWidget): self.splitter = QtWidgets.QSplitter() self.setWidget(self.splitter) + if root is None: + root = QtCore.QDir.currentPath() + self.datasets = datasets self.main_window = main_window self.rt_model = QtWidgets.QFileSystemModel() self.rt_model.setFilter(QtCore.QDir.NoDotAndDotDot | - QtCore.QDir.AllDirs | QtCore.QDir.Drives) + QtCore.QDir.AllDirs) self.rt = QtWidgets.QTreeView() 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.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection) self.rt.selectionModel().currentChanged.connect( self.tree_current_changed) - self.rt.hideColumn(1) - self.rt.hideColumn(2) - self.rt.hideColumn(3) + self.rt.setRootIsDecorated(False) self.splitter.addWidget(self.rt) self.rl = QtWidgets.QListView() @@ -71,16 +72,13 @@ class FilesDock(QtWidgets.QDockWidget): self.rl.setIconSize(QtCore.QSize(20*l, 15*l)) self.rl.setFlow(QtWidgets.QListView.LeftToRight) self.rl.setWrapping(True) - self.rl.setResizeMode(QtWidgets.QListView.Adjust) self.tree_current_changed(self.rt.currentIndex(), None) - self.rl.activated.connect(self.open_experiment) self.splitter.addWidget(self.rl) - if path is not None: - self.select(path) - self.already_selected = True - else: - self.already_selected = False + def showEvent(self, ev): + self.rt.hideColumn(1) + self.rt.hideColumn(2) + self.rt.hideColumn(3) def tree_current_changed(self, current, previous): path = self.rt_model.filePath(current) @@ -116,36 +114,23 @@ class FilesDock(QtWidgets.QDockWidget): rd[k] = True, group[k].value self.datasets.init(rd) - def select(self, file_or_dir): - file_or_dir = os.path.abspath(file_or_dir) - if os.path.isdir(file_or_dir): - idx = self.rt_model.index(file_or_dir) - if idx.isValid(): - self.rt.expand(idx) - self.rt.setCurrentIndex(idx) - 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 select(self, path): + idx = self.rt_model.index(path) + if not idx.isValid(): + return + self.rt.expand(idx) + self.rt.scrollTo(idx) + self.rt.setCurrentIndex(idx) + self.rl.setCurrentIndex(self.rl_model.index(path)) def save_state(self): 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()), } def restore_state(self, state): + self.select(state["selected"]) + self.rt.header().restoreState(QtCore.QByteArray(state["header"])) self.splitter.restoreState(QtCore.QByteArray(state["splitter"])) - if not self.already_selected: - self.select(state["selected"]) diff --git a/artiq/frontend/artiq_browser.py b/artiq/frontend/artiq_browser.py index c74219f43..347e08946 100755 --- a/artiq/frontend/artiq_browser.py +++ b/artiq/frontend/artiq_browser.py @@ -25,7 +25,7 @@ def get_argparser(): "--db-file", default=default_db_file, help="database file for local browser settings " "(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) return parser @@ -91,7 +91,7 @@ def main(): status_bar = QtWidgets.QStatusBar() 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) d_applets = applets.AppletsDock(main_window, datasets_sub) @@ -119,6 +119,9 @@ def main(): smgr.load() + if args.PATH: + d_files.select(args.PATH) + smgr.start() atexit_register_coroutine(smgr.stop)