Giter Club home page Giter Club logo

Comments (15)

tlambert03 avatar tlambert03 commented on July 28, 2024 1

My mind is suitably blown.

not to hijack the thread, but here's another revelation:

from qtpy.QtWidgets import QApplication, QPushButton

app = QApplication([])

button = QPushButton("Push Me")
button.clicked.connect(lambda e: print("clicked!"))
button.show()  # obviously, not shown yet

app.processEvents()  # now you see the button
# buuuuut.... try to click on it.
# it appears that the app has crashed... spinning pinwheel of death

app.processEvents()  # 🤯  (prints "clicked!")

app.exec_()  # click to your heart's content
# then close the window 
# (by default Qt quits the event loop when the last window is gone)

# make a new one
button2 = QPushButton("Push Me2")
button2.clicked.connect(lambda e: print("clicked2!"))
button2.show()  # not shown yet

# go nuts
%gui qt

so, %gui qt, and app.exec_() are just glorified versions of:

while True:
    app.processEvents()

from napari.github.io.

jni avatar jni commented on July 28, 2024 1

Not quite: if it runs while building the docs, it will run as an independent ipython notebook. (That’s one of the whole points we all agree is nice about using Jupyter book here).

@tlambert03 yeah but we'll do stuff like create the viewer, fix the camera settings, (nothing happens), then call nbscreenshot, which will create a viewer window that instantly becomes non-responsive, right? That's not super great user experience for that notebook! 😂

from napari.github.io.

GenevieveBuckley avatar GenevieveBuckley commented on July 28, 2024

I was trying a fix in #110 but the CI tests are failing, so we'll have to resolve that problem first

from napari.github.io.

tlambert03 avatar tlambert03 commented on July 28, 2024

Also just want to point out... you don't technically need it there at all (except for possible educational purposes). But I don't think you need to actually execute it (so it could be in a pure markdown cell)

from napari.github.io.

GenevieveBuckley avatar GenevieveBuckley commented on July 28, 2024

I think the educational purposes are pretty important! Especially if this is no longer a thing.

from napari.github.io.

jni avatar jni commented on July 28, 2024

@GenevieveBuckley I think @tlambert03's point is that the string is not exactly accurate — we don't have to start the event loop before import. We probably should start it before making a viewer, and we must (I think? @tlambert03?) start it before the nbscreenshot.

So yeah, educational purposes are absolutely critical, we should just make sure we educate correctly — the issue you link to shows that we had a lot of muddled ideas about event loops in napari before, and now that we are sorting them out, we risk confusing a lot of the community.

from napari.github.io.

tlambert03 avatar tlambert03 commented on July 28, 2024

yep, definitely wasn't trying to diminish the educational purpose. was just trying to point out that, in the context of removing the error (what this post was about), you can just not execute that cell at all and you'll be fine. by "not execute" I don't mean to imply that you need to delete it... that's what I meant by put it in a "pure markdown cell": in other words, let it be part of the narrative if you want to, but if the error you're getting by executing that cell is causing you grief, just don't execute it.

It's only necessary if you want to have an interactive IPython session (which you are not doing here).

we don't have to start the event loop before import.

correct

We probably should start it before making a viewer

totally optional. you can call %gui qt after making a viewer too and it will show a viewer and not block...

and we must (I think? @tlambert03?) start it before the nbscreenshot.

nope actually. not necessary there either. nbscreenshot will processEvents for you... (this was actually necessary otherwise you'd have no layer list in the viewer)

so, to be clear: you can completely remove %gui qt here and the docs will be fine. I know I keep referring to it, but have a look at the recent magicgui docs in napari, where I do just that. again, I'm not saying that you should remove all mention of %gui qt... but you don't need to execute it.

from napari.github.io.

tlambert03 avatar tlambert03 commented on July 28, 2024

side note: should we have a short zoom session sometime (with anyone interested) to talk about all the confusing Qt things?

from napari.github.io.

jni avatar jni commented on July 28, 2024

nbscreenshot will processEvents for you...

My mind is suitably blown.

should we have a short zoom session sometime (with anyone interested) to talk about all the confusing Qt things?

Yes, probably, plus update the event loop doc, and e.g. link to it when people use napari.gui_qt().

from napari.github.io.

GenevieveBuckley avatar GenevieveBuckley commented on July 28, 2024

@GenevieveBuckley I think @tlambert03's point is that the string is not exactly accurate — we don't have to start the event loop before import. We probably should start it before making a viewer, and we must (I think? @tlambert03?) start it before the nbscreenshot.

Ooooh, I see. So we're not arguing about whether there should be an explanation included, it's that the content I've written is incorrect. That's fine, we should replace that with something that is correct. (Which probably means Talley will need to write it, since he understands it best)

from napari.github.io.

GenevieveBuckley avatar GenevieveBuckley commented on July 28, 2024

so, to be clear: you can completely remove %gui qt here and the docs will be fine. I know I keep referring to it, but have a look at the recent magicgui docs in napari, where I do just that. again, I'm not saying that you should remove all mention of %gui qt... but you don't need to execute it.

But if we remove it and a new user downloads the notebook, they will not be able to run it properly (assuming they launch jupyter with the usual jupyter notebook command).

I care way less about whether it's strictly necessary to build the docs, and much more about whether we're showing people the same way we expect them to use napari most often.

from napari.github.io.

jni avatar jni commented on July 28, 2024

Yeah, we probably don't need to remove it, but we can e.g. have a link out to the updated docs which should explain everything we just discussed.

from napari.github.io.

tlambert03 avatar tlambert03 commented on July 28, 2024

But if we remove it and a new user downloads the notebook, they will not be able to run it properly (assuming they launch jupyter with the usual jupyter notebook command).

Not quite: if it runs while building the docs, it will run as an independent ipython notebook. (That’s one of the whole points we all agree is nice about using Jupyter book here).

I’m sorry I’m having difficulty explaining this here. I certainly wasn’t saying to remove it. I was just trying to offer an option for removing the error that opened this post. We can have the discussion about how best to present this to users somewhere else

from napari.github.io.

tlambert03 avatar tlambert03 commented on July 28, 2024

Ok, to summarize: leave in the gui qt, explain why it’s there. If you’d like to (but you don’t have to!!) you can comment it out and tell people to uncomment it. I’ll open an issue elsewhere where we can discuss how we can simplify this

from napari.github.io.

GenevieveBuckley avatar GenevieveBuckley commented on July 28, 2024

Given napari/napari#2406 we can probably get rid of the %gui qt stuff entirely (starting from napari version 0.4.7)

from napari.github.io.

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.