mirror of
https://github.com/m-labs/artiq.git
synced 2024-12-25 11:18:27 +08:00
Revert "browser: various fixes, handle startup path, connect activated"
This reverts commit c80510287b
.
This commit is contained in:
parent
c80510287b
commit
1f92e034da
@ -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"])
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user