Skip to content
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

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open

Added a DynamicWidgetContainer #718

wants to merge 22 commits into from

Conversation

ceprio
Copy link
Contributor

@ceprio ceprio commented Jan 13, 2022

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 ;)

Copy link
Member

@almarklein almarklein left a 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.

Comment on lines +61 to +65
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
Copy link
Member

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:
Copy link
Member

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
Copy link
Member

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?

Copy link
Contributor Author

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
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, will do.

ceprio and others added 2 commits January 26, 2022 08:06
@ceprio
Copy link
Contributor Author

ceprio commented Jan 26, 2022

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?

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants