Code Monkey home page Code Monkey logo

Comments (16)

sofroniewn avatar sofroniewn commented on June 29, 2024 3

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)

from magicgui.

tlambert03 avatar tlambert03 commented on June 29, 2024 1

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.

tlambert03 avatar tlambert03 commented on June 29, 2024 1

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.

jni avatar jni commented on June 29, 2024 1

@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.

sofroniewn avatar sofroniewn commented on June 29, 2024

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

file_browser

from magicgui.

tlambert03 avatar tlambert03 commented on June 29, 2024

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.

sofroniewn avatar sofroniewn commented on June 29, 2024

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.

tlambert03 avatar tlambert03 commented on June 29, 2024

another potentially useful section here: https://doc.qt.io/qt-5/model-view-programming.html#using-views-with-an-existing-model

from magicgui.

sofroniewn avatar sofroniewn commented on June 29, 2024

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!!!

Screen Shot 2020-04-26 at 1 41 01 PM

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.

tlambert03 avatar tlambert03 commented on June 29, 2024

😍🤯

from magicgui.

sofroniewn avatar sofroniewn commented on June 29, 2024

@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.

sofroniewn avatar sofroniewn commented on June 29, 2024

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.

jni avatar jni commented on June 29, 2024

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.

sofroniewn avatar sofroniewn commented on June 29, 2024

Code from above https://github.com/sofroniewn/image-demos/blob/master/examples/rxrx19_browser.py

from magicgui.

evamaxfield avatar evamaxfield commented on June 29, 2024

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.

evamaxfield avatar evamaxfield commented on June 29, 2024

Yep makes sense to me. Love the progress either way 🙂

from magicgui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.