-
Notifications
You must be signed in to change notification settings - Fork 262
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
Added a DynamicWidgetContainer #718
base: main
Are you sure you want to change the base?
Conversation
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! This looks like a nice contribution!
If I understand correctly, this new class is needed, because although the JS Widget supports dynamically changing parents, this does not really work for the PyWidget, right? (Sorry, I have not actively used Flexx for a while).
I left a few comments, but none are big issues, I think.
async_task = threading.Event() | ||
pos = len(self.pages) | ||
self.pages.append(async_task) # this is the new location for this instance | ||
while self.pages[pos] is not async_task: | ||
pos += 1 # in case some other thread added to the list |
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.
Shouldn't this block be dendented? (It's now under the if options is None
.)
@event.reaction("_emit_instantiate") | ||
def __instantiate(self, *events): | ||
with self: | ||
with events[0]['widget_type'](events[0]['style']) as page: |
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.
Could you please add a few lines of comments explaining the flow. As I understand it, first a threading.task
is appended to .pages
and that is exchanged for an actual page instance here. Does this trick have to do with thread-safety?
|
||
class Example(flx.PyWidget): | ||
|
||
# The CSS is not used by flex in PyWiget but it should be applied to the top div: TODO |
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.
There are a few TODO's in this this PR's code. Do you plan to fix these in this PR, or do you think that's not needed?
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.
This todo will need fixing to have PyWidget work like a Widget. I'm just not shure how to do it at this point.
@@ -0,0 +1,80 @@ | |||
from flexx import flx |
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.
Could you please add a short docstring at the top of the examples to briefly explain the purpose of the examples?
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.
Yes, will do.
Change to None comparision Co-authored-by: Almar Klein <[email protected]>
Co-authored-by: Almar Klein <[email protected]>
Yes, that is right. My goal is to have a flexx server that can dynamically serve a client application. The GUI of the client can change completely according to the user actions: view it as a web page that a user is browsing where the pages are dynamically generated by the flexx application. I'm currently working with that class and will try to put a better sample at one point. Especially the sample with the thread which is intended for a single client application and that should be extended to serve multiple browser clients. I will work on the requested changes (Though not right away for some of them; let me play more with the base class and come back with better samples). |
Hi Almarklein,
I've added a dynamic container for widgets. I'm using it for a few applications and I thought of sharing it as I see some questions regarding adding and removing widgets on the fly.
Look at the examples, it will show you what it is capable of.
Side note: The file flexx/event/_js.py was not working for me, there is some error in _clean_code_of_thread_stuff. It seem to block a lot of examples so you are probably on it. Just use the old version or the fixed one if you have one.
Have fun ;)