-
-
Notifications
You must be signed in to change notification settings - Fork 695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get drop information out from windowview #3378
base: main
Are you sure you want to change the base?
Conversation
Got it working!!! 2024-07-22_23-18-15.mp4There are two problems still tho that I would love to get some help with.
I'll post the data tomorrow as it's quite late here 😄 |
Added all files to make the drag and drop working and included a _example.py in the root dir for you to try it out. Drop zone does still not work with |
Thanks for the pull request, @EmberLightVFX! |
No worries! I know you're busy with other stuff :) I haven't had much time myself to look into the problems but when I get some time I'll do my best. Any community help is highly appreciated tho! |
I finally got some time to try and tackle this again. So quick question. Are there any way to emit/broadcast directly from the python code? |
@falkoschindler |
Hi @EmberLightVFX, thanks for the update!
I'm not quite sure if I understand the question. |
@falkoschindler I just pushed an update where I added a asyncio check when the drop zone gets a __file-dropped event and it checks for data in the drop_queue (mp.Queue()). A bit cumbersome but it's the only way in how NiceGUI and webview works. So, how the drop zone have the path information but need to send the emit to everything that's listening. |
Btw, I left some print functions around just to be able to see what executes and when. I'll remove these when everything works as expected 😄 |
I have went through the code and fixed everything so it's now working as expected! |
So I have bin looking through the code and I don't see a way to comunicate to the correct thread as the reloadis done by uvicorn. |
From my understanding there isn't really any good way to get drop zone and reload to work at the same time because of all the different threads going on. Except that I think this PR is ready for review. I have still left my example python file but when all is accepted I'll remove it. |
Took some time to change the event usage from |
Hi @EmberLightVFX, I really appreciate the work you're putting into this PR! Hopefully we can turn it into a useful feature.
|
Yeah sorry for all updates I wrote here. Maybe a big too much.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @EmberLightVFX! And sorry for the confusion. I just tested _example.py once again and it seems to be working. Maybe I dropped onto the second drop zone which isn't connected to an event handler.
Now that I can see your changes more clearly, I started reviewing them in more detail. My two main concerns are the following:
-
The event mechanism sounds rather complicated. I'll look into it more closely and maybe we can find a simplification somewhere. But requiring
native=True
andreload=False
is quite a limitation. It would be great to fix it forreload=True
. And ultimately I would hope to supportui.drop_zone
fornative=False
as well. -
The amount of code for the "hover style" is quite significant, including additional events just to toggle the Tailwind classes. Would something like
ui.drop_zone().classes('outline-gray hover:outline-dashed')
be too much of a simplification? It switches even when hovering without dragging a file, but it simplifies the code sooo much.
If we were to keep the extra styling parameter(s), I'd try to handle the drag events right in JavaScript and switch classes and/or style there without involving the server. This reduces the need for these two events as well as needless latency.
Another remark regarding Tailwind classes: There is an option to run NiceGUI without Tailwind. For this scenario built-in elements shouldn't rely on Tailwind but use plain CSS instead.
I'll go through all your points when I get some time over but let me answer your two notes first:
|
I have now updated the code with all your comments. I have now also added two extra classes to the drop zone element. I think this is the best way to let users get the style they want for the drop zones. Things left to do but I'll wait with until we have decided how everything should be working:
|
Ok, thanks for the update! I still have some questions though:
Actually, when I think about it: We cannot raise when creating |
|
) | ||
for drop_handler in self._drop_handlers: | ||
handle_event(drop_handler, args) | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@EmberLightVFX This return
prevents the while loop from looping. Should we remove it, or replace while not drop_queue.empty():
with if not drop_queue.empty():
?
This is my WIP PR for issue #3372
Right now all it does is allow you to drag and drop files into the webview and it will print out the path to the file from the main thread.
The issue I'm still having is how to access the running nicegui instance on the main thread as currently the check for droped files happens in a separate thread that's running from the main thread (not multiprocessing).
Are there any other way for me to check the drop_queue from within the main thread and from there create an event that could be picked up like
ui.on("drop", my_func)
?