Comments (16)
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
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)
from magicgui.
I think I might need a refresher. It kinda seems like the best example here was just using the Qt file browser connected to an event that loads and shows the image, yeah? If the main use case here was file-tree related, I think this is better as a napari example with a direct Qt file widget. but if I'm missing a more general type-to-widget opportunity, let me know
from magicgui.
yeah, the magicgui file dialog is just a line edit with a button that opens up a "pick a file" dialog. This is a full-blown QFileDialog
(which i'm struggling to fit into my mental model of magicgui at the moment)
from magicgui.
@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.
from magicgui.
Here is my code snippet which kind of works to create the tree widget
treeWidget = QTreeWidget()
# Determine at set number of columns
n_columns = np.max([f.count('/') for f in filenames]) + 1
treeWidget.setColumnCount(n_columns)
# Create tree
tree_root = (None, {})
for f in filenames:
parts = f.split('/')
node = tree_root
for i, p in enumerate(parts):
if p != '':
if p not in node[1]:
node[1][p] = (QTreeWidgetItem(node[0]), {})
node[1][p][0].setText(i, p)
node = node[1][p]
# Add top level items
for node in tree_root[1].values():
treeWidget.addTopLevelItem(node[0])
Doesn't look too bad ... but I imagine there is a better/ more standard way to do this
from magicgui.
awesome! I definitely think this is useful. need some time to look a little closer, but already looks cool :)
i wonder whether QFileSystemModel could be useful here? Or does it not work for your list of strings if you don't necessarily want every file?
from magicgui.
i wonder whether QFileSystemModel could be useful here? Or does it not work for your list of strings if you don't necessarily want every file?
ooo that sounds promising!! will check it out
from magicgui.
another potentially useful section here: https://doc.qt.io/qt-5/model-view-programming.html#using-views-with-an-existing-model
from magicgui.
Thanks! Here is my "browser" for this recent 450GB data release from Recursion - It's a little slow because the remote zip stuff is slow, see my image.sc post, but it does work!!!
Here are a couple key pieces
# decorate your function with the ``@magicgui`` decorator
@magicgui(call_button="fetch")
def fetch_image():
viewer.status = 'Button Clicked!'
print(viewer.status)
item = treeWidget.currentItem()
if item.text(6).endswith('.png') or item.text(5).endswith('_w'):
file_split = item.full_path.split('/')
file = ''
for f in file_split[:-3]:
file += f + '/'
for f in file_split[-3:]:
file += f
viewer.status = 'Fetching: ' + file
print(viewer.status)
images = get_image_stack(path, file)
viewer.status = 'Recieved!'
print(viewer.status)
viewer.layers.select_all()
viewer.layers.remove_selected()
viewer.add_image(images, channel_axis=0)
treeWidget = QTreeWidget()
# Determine at set number of columns
n_columns = np.max([f.count('/') for f in adj_filenames]) + 1
treeWidget.setColumnCount(n_columns)
# Create tree
tree_root = (None, {})
for f in adj_filenames:
parts = f.split('/')
node = tree_root
for i, p in enumerate(parts):
if p != '':
if p not in node[1]:
node[1][p] = (QTreeWidgetItem(node[0]), {})
node[1][p][0].setText(i, p)
node[1][p][0].full_path = f
node = node[1][p]
# Add top level items
for node in tree_root[1].values():
treeWidget.addTopLevelItem(node[0])
def get_image_stack(path, file):
with RemoteZip(path) as zip:
image_data = []
for c in list(range(1, 6)):
adj_file = f'{file[:-5]}{c}.png'
image_data.append(zip.read(adj_file))
return np.array([imread(imd) for imd in image_data])
Once we have it nicely figured out I can write up a tutorial - it's pretty fun to use (though would be better if faster and call was not blocking the UI)
from magicgui.
😍🤯
from magicgui.
@jni just asked me about turning this into a plugin (or contribution to magicgui?). It's been a while since the last comments on here, curious @tlambert03 if things have advanced in this area/ if you have any new recommendations here
from magicgui.
I think napari example/ napari plugin for file browsing is all @jni wanted, but maybe we could build it using pieces from the magicgui file dialog? https://github.com/napari/magicgui/blob/master/examples/file_dialog.py
Direct Qt file widget approach might be simpler though. Maybe we'll poke around later and then update this thread.
from magicgui.
Yeah it would be awesome if we could specify a QFileDialog widget for files, just like you can specify RadioButton instead of combo boxes for enums. Am I missing some difficulty @tlambert03 ? I guess not all front ends have such a widget but there's not full parity on everything is there?
Then you could make an auto-run file -> layers plug-in with this and things would just work, no?
from magicgui.
Code from above https://github.com/sofroniewn/image-demos/blob/master/examples/rxrx19_browser.py
from magicgui.
Just saw this thread from napari and would ask that instead of the "Look in" directory dropdown to have just a text box that the user can pass a string. Reason being I was also in the process of working on a general "ObjectTreeModel" for napari image loading backed by fsspec
to allow object browsing of remote as well:
Very minimal but working tree for local or remote:
https://github.com/JacksonMaxfield/napari-aicsimageio/blob/feature/object-tree/napari_aicsimageio/widgets/object_tree.py
Doesn't have all the fancy bells and whistles though so maybe not 🤷
from magicgui.
Yep makes sense to me. Love the progress either way 🙂
from magicgui.
Related Issues (20)
- Styling Widgets HOT 7
- `Container.parent` type annotation incorrect HOT 1
- docs: pymdownx.inlinehilite (via mkdocs-gallery) breaking autorefs HOT 6
- `Literal` and `widget_type="RadioButtons"` not compatible HOT 1
- Add support for toolbars HOT 2
- Improve matplotlib example by implementing abstraction HOT 8
- MainWindow for ipywidgets HOT 5
- Errors in rendered widget image with 16-bit screen HOT 2
- File dialog for ipynb backend HOT 2
- How can we programatically intercept keystokes like `delete` in a magicgui table? HOT 3
- No parent with parent_changed HOT 1
- build_widget doesn't populate defaults when given a class object, rather than a class instance HOT 1
- Tests failing in tests
- user input validation HOT 5
- ListEdit widget buttons should be nested and always use horizontal layout HOT 2
- ComboBox with sections HOT 6
- Dropdown list from ipynb allows duplicates but ComboBox from Qt only keep unique item names HOT 5
- File dialog in background HOT 4
- optional params as checkbox with widget HOT 4
- DirectWrite: CreateFontFaceFromHDC() failed HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from magicgui.