forked from M-Labs/artiq
browser: cleanup late select, align options with variables
This commit is contained in:
parent
3578ba17a3
commit
9a01d38439
|
@ -59,9 +59,9 @@ class DirsOnlyProxy(QtCore.QSortFilterProxyModel):
|
||||||
class ZoomIconView(QtWidgets.QListView):
|
class ZoomIconView(QtWidgets.QListView):
|
||||||
zoom_step = 2**.25
|
zoom_step = 2**.25
|
||||||
aspect = 2/3
|
aspect = 2/3
|
||||||
default_size = 15
|
default_size = 25
|
||||||
min_size = 2
|
min_size = 10
|
||||||
max_size = 200
|
max_size = 1000
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
QtWidgets.QListView.__init__(self)
|
QtWidgets.QListView.__init__(self)
|
||||||
|
@ -75,10 +75,10 @@ class ZoomIconView(QtWidgets.QListView):
|
||||||
|
|
||||||
def wheelEvent(self, ev):
|
def wheelEvent(self, ev):
|
||||||
if ev.modifiers() & QtCore.Qt.ControlModifier:
|
if ev.modifiers() & QtCore.Qt.ControlModifier:
|
||||||
z = self.zoom_step**(ev.angleDelta().y()/120.)
|
|
||||||
a = self._char_width*self.min_size
|
a = self._char_width*self.min_size
|
||||||
b = self._char_width*self.max_size
|
b = self._char_width*self.max_size
|
||||||
w = self.iconSize().width()*z
|
w = self.iconSize().width()*self.zoom_step**(
|
||||||
|
ev.angleDelta().y()/120.)
|
||||||
if a <= w <= b:
|
if a <= w <= b:
|
||||||
self.setIconSize(QtCore.QSize(w, w*self.aspect))
|
self.setIconSize(QtCore.QSize(w, w*self.aspect))
|
||||||
else:
|
else:
|
||||||
|
@ -86,8 +86,7 @@ class ZoomIconView(QtWidgets.QListView):
|
||||||
|
|
||||||
|
|
||||||
class FilesDock(QtWidgets.QDockWidget):
|
class FilesDock(QtWidgets.QDockWidget):
|
||||||
def __init__(self, datasets, main_window, root="",
|
def __init__(self, datasets, main_window, browse_root="", select=None):
|
||||||
select_file=None):
|
|
||||||
QtWidgets.QDockWidget.__init__(self, "Files")
|
QtWidgets.QDockWidget.__init__(self, "Files")
|
||||||
self.setObjectName("Files")
|
self.setObjectName("Files")
|
||||||
self.setFeatures(self.DockWidgetMovable | self.DockWidgetFloatable)
|
self.setFeatures(self.DockWidgetMovable | self.DockWidgetFloatable)
|
||||||
|
@ -97,7 +96,6 @@ class FilesDock(QtWidgets.QDockWidget):
|
||||||
|
|
||||||
self.datasets = datasets
|
self.datasets = datasets
|
||||||
self.main_window = main_window
|
self.main_window = main_window
|
||||||
self.override_restore_file = select_file
|
|
||||||
|
|
||||||
self.model = QtWidgets.QFileSystemModel()
|
self.model = QtWidgets.QFileSystemModel()
|
||||||
self.model.setFilter(QtCore.QDir.Drives | QtCore.QDir.NoDotAndDotDot |
|
self.model.setFilter(QtCore.QDir.Drives | QtCore.QDir.NoDotAndDotDot |
|
||||||
|
@ -114,7 +112,7 @@ class FilesDock(QtWidgets.QDockWidget):
|
||||||
lambda: self.rt.resizeColumnToContents(0))
|
lambda: self.rt.resizeColumnToContents(0))
|
||||||
self.rt.setAnimated(False)
|
self.rt.setAnimated(False)
|
||||||
self.rt.setRootIndex(rt_model.mapFromSource(
|
self.rt.setRootIndex(rt_model.mapFromSource(
|
||||||
self.model.setRootPath(root)))
|
self.model.setRootPath(os.path.abspath(browse_root))))
|
||||||
self.rt.setSelectionBehavior(self.rt.SelectRows)
|
self.rt.setSelectionBehavior(self.rt.SelectRows)
|
||||||
self.rt.setSelectionMode(self.rt.SingleSelection)
|
self.rt.setSelectionMode(self.rt.SingleSelection)
|
||||||
self.rt.selectionModel().currentChanged.connect(
|
self.rt.selectionModel().currentChanged.connect(
|
||||||
|
@ -131,6 +129,14 @@ class FilesDock(QtWidgets.QDockWidget):
|
||||||
self.rl.activated.connect(self.open_experiment)
|
self.rl.activated.connect(self.open_experiment)
|
||||||
self.splitter.addWidget(self.rl)
|
self.splitter.addWidget(self.rl)
|
||||||
|
|
||||||
|
self.restore_selected = select is None
|
||||||
|
if select is not None:
|
||||||
|
f = os.path.abspath(select)
|
||||||
|
if os.path.isdir(f):
|
||||||
|
self.select_dir(f)
|
||||||
|
else:
|
||||||
|
self.select_file(f)
|
||||||
|
|
||||||
def tree_current_changed(self, current, previous):
|
def tree_current_changed(self, current, previous):
|
||||||
idx = self.rt.model().mapToSource(current)
|
idx = self.rt.model().mapToSource(current)
|
||||||
self.rl.setRootIndex(idx)
|
self.rl.setRootIndex(idx)
|
||||||
|
@ -172,14 +178,16 @@ class FilesDock(QtWidgets.QDockWidget):
|
||||||
return
|
return
|
||||||
self.rl.setRootIndex(idx)
|
self.rl.setRootIndex(idx)
|
||||||
|
|
||||||
|
# ugly, see Spyder: late indexing, late scroll
|
||||||
def scroll_when_loaded(p):
|
def scroll_when_loaded(p):
|
||||||
if p != path:
|
if p != path:
|
||||||
return
|
return
|
||||||
self.model.directoryLoaded.disconnect(scroll_when_loaded)
|
self.model.directoryLoaded.disconnect(scroll_when_loaded)
|
||||||
QtCore.QTimer.singleShot(
|
QtCore.QTimer.singleShot(
|
||||||
100, lambda:
|
100, lambda:
|
||||||
self.rt.scrollTo(self.rt.model().mapFromSource(
|
self.rt.scrollTo(
|
||||||
self.model.index(path)), self.rt.PositionAtCenter))
|
self.rt.model().mapFromSource(self.model.index(path)),
|
||||||
|
self.rt.PositionAtCenter))
|
||||||
self.model.directoryLoaded.connect(scroll_when_loaded)
|
self.model.directoryLoaded.connect(scroll_when_loaded)
|
||||||
idx = self.rt.model().mapFromSource(idx)
|
idx = self.rt.model().mapFromSource(idx)
|
||||||
self.rt.expand(idx)
|
self.rt.expand(idx)
|
||||||
|
@ -203,13 +211,7 @@ class FilesDock(QtWidgets.QDockWidget):
|
||||||
}
|
}
|
||||||
|
|
||||||
def restore_state(self, state):
|
def restore_state(self, state):
|
||||||
if self.override_restore_file:
|
if self.restore_selected:
|
||||||
f = os.path.normpath(self.override_restore_file)
|
|
||||||
if os.path.isdir(f):
|
|
||||||
self.select_dir(f)
|
|
||||||
else:
|
|
||||||
self.select_file(f)
|
|
||||||
else:
|
|
||||||
self.select_dir(state["dir"])
|
self.select_dir(state["dir"])
|
||||||
self.select_file(state["file"])
|
self.select_file(state["file"])
|
||||||
self.rt.header().restoreState(QtCore.QByteArray(state["header"]))
|
self.rt.header().restoreState(QtCore.QByteArray(state["header"]))
|
||||||
|
|
|
@ -24,11 +24,11 @@ def get_argparser():
|
||||||
parser.add_argument("--db-file", default=default_db_file,
|
parser.add_argument("--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("--root", default="",
|
parser.add_argument("--browse-root", default="",
|
||||||
help="root path for directory tree "
|
help="root path for directory tree "
|
||||||
"(default %(default)s)")
|
"(default %(default)s)")
|
||||||
parser.add_argument("path", metavar="PATH", nargs="?",
|
parser.add_argument("select", metavar="SELECT", nargs="?",
|
||||||
help="browse path or file")
|
help="directory to browse or file to load")
|
||||||
verbosity_args(parser)
|
verbosity_args(parser)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
@ -86,6 +86,7 @@ def main():
|
||||||
smgr = state.StateManager(args.db_file)
|
smgr = state.StateManager(args.db_file)
|
||||||
|
|
||||||
datasets_sub = models.LocalModelManager(datasets.Model)
|
datasets_sub = models.LocalModelManager(datasets.Model)
|
||||||
|
datasets_sub.init({})
|
||||||
|
|
||||||
# initialize main window
|
# initialize main window
|
||||||
main_window = MainWindow()
|
main_window = MainWindow()
|
||||||
|
@ -93,8 +94,8 @@ 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.root,
|
d_files = files.FilesDock(datasets_sub, main_window, args.browse_root,
|
||||||
args.path)
|
select=args.select)
|
||||||
smgr.register(d_files)
|
smgr.register(d_files)
|
||||||
|
|
||||||
d_applets = applets.AppletsDock(main_window, datasets_sub)
|
d_applets = applets.AppletsDock(main_window, datasets_sub)
|
||||||
|
|
Loading…
Reference in New Issue