pyedifice / pyedifice

Declarative GUI framework for Python and Qt
https://pyedifice.github.io
MIT License
416 stars 16 forks source link

Hot reload not working in all scenarios #184

Open Napam opened 2 months ago

Napam commented 2 months ago

Hi, I am following the tutorial: https://pyedifice.github.io/

I copy pasted the code:


from edifice import App, Label, Window, component

@component
def HelloWorld(self):
    with Window():
        Label("Hello World!")

if __name__ == "__main__":
    App(HelloWorld()).start() 

and ran the following:

python -m edifice main.py HelloWorld

I then tried to change the text to Hello World!!!!!!, but nothing happens. I restart the application, then I can see the changes.

Runtime environment:

Python: Tried both Python 3.12 and 3.10 Qt: PySide6_Essentials==6.7.3 Watchdog: 5.0.2 Edifice: 2.1.0 OS: MacOS Sequoia Version 15.0

Tried both nevim and vscode, neither triggered a hot reload


I tried setting the log level to debug (the root logger), but nothing showed up.

jamesdbrock commented 2 months ago

Yes, thanks for opening this issue. This is a limitation of the hot-reloader, which should be documented and fixed.

The hot-reloader cannot reload the component which contains the Window.

In this case we can refactor the program to put the Window in a separate component.

from edifice import App, Label, Window, component

@component
def HelloWorldInner(self):
    Label(text="Hello World! ", word_wrap=False)

@component
def HelloWorld(self):
    with Window(style={"padding":100}):
        HelloWorldInner()

if __name__ == "__main__":
    App(HelloWorld()).start()

And then hot-reloading will work for changes to the HelloWorldInner component when we run in the Edifice Runner

python -m edifice main.py HelloWorld

I'm going to mention this in the docs and leave this issue open until it is fixed.

jamesdbrock commented 2 months ago

Published new docs with a note about this https://pyedifice.github.io/developer_tools.html#dynamic-hot-reload

Napam commented 2 months ago

Great to hear :) I tried using your workaround now and it works! (from the little I have tried so far). This looks very promising!