mirror of https://github.com/m-labs/artiq.git
browser: cleanup dir/file restore, closes #527
This commit is contained in:
parent
92f3757c74
commit
e7d6ad2595
|
@ -120,7 +120,7 @@ class FilesDock(QtWidgets.QDockWidget):
|
|||
dataset_changed = QtCore.pyqtSignal(str)
|
||||
metadata_changed = QtCore.pyqtSignal(dict)
|
||||
|
||||
def __init__(self, datasets, browse_root="", restore_selection=True):
|
||||
def __init__(self, datasets, browse_root=""):
|
||||
QtWidgets.QDockWidget.__init__(self, "Files")
|
||||
self.setObjectName("Files")
|
||||
self.setFeatures(self.DockWidgetMovable | self.DockWidgetFloatable)
|
||||
|
@ -161,8 +161,6 @@ class FilesDock(QtWidgets.QDockWidget):
|
|||
self.rl.activated.connect(self.list_activated)
|
||||
self.splitter.addWidget(self.rl)
|
||||
|
||||
self.restore_selection = restore_selection
|
||||
|
||||
def tree_current_changed(self, current, previous):
|
||||
idx = self.rt.model().mapToSource(current)
|
||||
self.rl.setRootIndex(idx)
|
||||
|
@ -213,9 +211,11 @@ class FilesDock(QtWidgets.QDockWidget):
|
|||
|
||||
def select_dir(self, path):
|
||||
if not os.path.exists(path):
|
||||
logger.warning("directory does not exist %s", path)
|
||||
return
|
||||
idx = self.model.index(path)
|
||||
if not idx.isValid():
|
||||
logger.warning("directory invalid %s", path)
|
||||
return
|
||||
self.rl.setRootIndex(idx)
|
||||
|
||||
|
@ -237,22 +237,29 @@ class FilesDock(QtWidgets.QDockWidget):
|
|||
|
||||
def select_file(self, path):
|
||||
if not os.path.exists(path):
|
||||
logger.warning("file does not exist %s", path)
|
||||
return
|
||||
self.select_dir(os.path.dirname(path))
|
||||
idx = self.model.index(path)
|
||||
if not idx.isValid():
|
||||
logger.warning("file invalid %s", path)
|
||||
return
|
||||
self.rl.setCurrentIndex(idx)
|
||||
|
||||
def save_state(self):
|
||||
return {
|
||||
state = {
|
||||
"dir": self.model.filePath(self.rl.rootIndex()),
|
||||
"file": self.model.filePath(self.rl.currentIndex()),
|
||||
"splitter": bytes(self.splitter.saveState()),
|
||||
}
|
||||
idx = self.rl.currentIndex()
|
||||
if idx.isValid():
|
||||
state["file"] = self.model.filePath(idx)
|
||||
else:
|
||||
state["file"] = None
|
||||
return state
|
||||
|
||||
def restore_state(self, state):
|
||||
if self.restore_selection:
|
||||
self.select_dir(state["dir"])
|
||||
self.select_file(state["file"])
|
||||
self.splitter.restoreState(QtCore.QByteArray(state["splitter"]))
|
||||
self.select_dir(state["dir"])
|
||||
if state["file"] is not None:
|
||||
self.select_file(state["file"])
|
||||
|
|
|
@ -43,7 +43,7 @@ def get_argparser():
|
|||
|
||||
|
||||
class Browser(QtWidgets.QMainWindow):
|
||||
def __init__(self, smgr, datasets_sub, browse_root, restore_selection,
|
||||
def __init__(self, smgr, datasets_sub, browse_root,
|
||||
master_host, master_port):
|
||||
QtWidgets.QMainWindow.__init__(self)
|
||||
smgr.register(self)
|
||||
|
@ -68,8 +68,7 @@ class Browser(QtWidgets.QMainWindow):
|
|||
QtCore.Qt.ScrollBarAsNeeded)
|
||||
self.setCentralWidget(self.experiments)
|
||||
|
||||
self.files = files.FilesDock(datasets_sub, browse_root,
|
||||
restore_selection)
|
||||
self.files = files.FilesDock(datasets_sub, browse_root)
|
||||
smgr.register(self.files)
|
||||
|
||||
self.files.dataset_activated.connect(
|
||||
|
@ -146,13 +145,9 @@ def main():
|
|||
smgr = state.StateManager(args.db_file)
|
||||
|
||||
browser = Browser(smgr, datasets_sub, args.browse_root,
|
||||
args.select is not None, args.server,
|
||||
args.port)
|
||||
args.server, args.port)
|
||||
widget_log_handler.callback = browser.log.append_message
|
||||
|
||||
if args.select is not None:
|
||||
browser.files.select(args.select)
|
||||
|
||||
if os.name == "nt":
|
||||
# HACK: show the main window before creating applets.
|
||||
# Otherwise, the windows of those applets that are in detached
|
||||
|
@ -161,6 +156,10 @@ def main():
|
|||
smgr.load()
|
||||
smgr.start()
|
||||
atexit_register_coroutine(smgr.stop)
|
||||
|
||||
if args.select is not None:
|
||||
browser.files.select(args.select)
|
||||
|
||||
browser.show()
|
||||
loop.run_until_complete(browser.exit_request.wait())
|
||||
|
||||
|
|
Loading…
Reference in New Issue