question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

QTreeWidget from list of path like strings

See original GitHub issue

I was about to code something up as a one off (and probably still wise for me to start there) but then I thought it might be ultimately a nice re-usable piece of Qt code we’d want to provide to plugin devs. I have a list of paths (they happen to come from inside a zip file from a url, but really they could also come from anywhere) - a small snapshot looks like

['RxRx19a/',
 'RxRx19a/LICENSE',
 'RxRx19a/images/',
 'RxRx19a/images/VERO-1/',
 'RxRx19a/images/VERO-1/Plate1/',
 'RxRx19a/images/VERO-1/Plate1/AC41_s4_w3.png',
 'RxRx19a/images/VERO-1/Plate1/G38_s3_w1.png',....]

and I’d like to use a QTreeWidget to browse them as described in posts like this one on stackoverflow.

When i select a path with a png I’d then like to trigger some calls that will lead to a new image being displayed in the viewer - i.e. turning napari into a little file browser for this remote zip. It might also be nice to have similar browser capability for local files too.

Curious what you think of this @tlambert03 or if you have any tips before I got going? I’d say this is more of a hobby use of napari rather than a top development priority, but always fun to be trying to push it in new ways 😃

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:16 (14 by maintainers)

github_iconTop GitHub Comments

3reactions
sofroniewncommented, Apr 27, 2020

Following up I made a new cool demo doing a similar thing but with my local file browser.

Clears and loads new image data via viewer.open_path / viewer.open when selected. Makes for fun browsing!!! Should probably remove the open/ cancel buttons

local_file_browser

import os
from qtpy.QtWidgets import QFileDialog
from qtpy.QtCore import Qt


file_dialog = QFileDialog()
file_dialog.setWindowFlags(Qt.Widget)
file_dialog.setModal(False)
file_dialog.setOption(QFileDialog.DontUseNativeDialog)


def open_path(path):
    if os.path.isfile(path):
        viewer.layers.select_all()
        viewer.layers.remove_selected()
        viewer.open_path(path)
        

file_dialog.currentChanged.connect(open_path)
1reaction
jnicommented, May 4, 2021

@JacksonMaxfield this is a different use case I think. Both a file browser and a world browser can live side by side in the napari plugin ecosystem. 😊 In the case of magicgui, I think we mostly want to support standard or quasi-standard widgets. Note that above the whole thing is a QFileDialog, so we can’t really go in and move things around.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Populating QTreeView from list of file paths - python
Is there a way to find duplicates rows in a QStandardItem or traverse the QStandardItemModel to find the existing QStandardItem? I've been ...
Read more >
Is there a way to list the full path of an item from QTreeView ...
From here I take each string and build a QByteArray that is passed to a TreeModel constructor and then I set that as...
Read more >
PyQt5 QTreeWidget tutorial: Load data, organize ... - YouTube
Learn how to use a Tree Widget, or QTreeWidget with Python PyQt5. Display hierarchical data in your Tree Widget. Format and resize your...
Read more >
highlight QTreeView selection based on a given string
Populates the tree from a given list of strings - example. "|ObjectA|ObjectB|ObjectC|..." such that the hierarchy is almost the same as the ...
Read more >
How to use QTreeWidget() in PySide2 - Nakoblog
1. The argument of QTreeWidget should be the list of strings. If you pass single string as a string list, each character becomes...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found