Comments (12)
No - I don't have a minimal example yet. I'm struggling to find what in the code causes the problem. My code is complex and uses the win32 api to position windows on the screen etc as well as using nicegui. I am trying to isolate the issue, but so far haven't had any luck.
I'd suggest closing the issue as solved. If I can create a minimal example I'll open a new issue. I don't think there is anything you can do as your suggested minimal examples work fine.
Working with version 1.4.18 is also fine for me. Again, I congratulate you on producing a great product. Its, imho, much better than any of the other gui libraries and treads a nice line between providing all the functionality required and ease of use.
from nicegui.
It works fine in version 1.4.18 - I haven't tried any later versions other than 1.4.26
from nicegui.
Hi @gavinpotter,
Technically there could be another client connected to a native app. Therefore awaiting JavaScript would still not be well defined.
But you can simply wrap your page into a page function and the problem should be gone.
from nicegui.
Thanks - but I'm struggling with your work around. Here is a minimal replicable example. I maybe doing something wrong with the page wrapping? When I hover the mouse over the label, I get the error message I described above.
#Minimal example
from nicegui import ui,app
class testClass():
@ui.page("/testClassinit")
def __init__(self):
self.label = ui.label("Hello world")
self.label.on("mouseenter",lambda: self.mouseEnter())
@ui.page("/mouseEnter")
async def mouseEnter(self):
s = await ui.run_javascript("window.innerHeight;")
ui.label("Mouse entered label")
app.on_startup(testClass)
ui.run(native=True)
from nicegui.
The @page
decorator doesn't work for class methods or initializers, but for functions only.
Assuming you want to keep app.on_startup
for some reason, you could arrange it like this:
def createUi():
@ui.page('/')
def index():
label = ui.label("Hello world")
label.on("mouseenter", mouseEnter)
async def mouseEnter():
innerHeight = await ui.run_javascript("window.innerHeight;")
ui.label(f"Mouse entered label ({innerHeight=})")
app.on_startup(createUi)
from nicegui.
Unfortunately my application is divided into 42 classes each performing a separate task for the user. Each class encapsulates state for the user, a set of class methods and a user interface built using nicegui. It is designed to run in native mode, so each user has a copy on their own laptop. Its not really practical to rewrite it in the manner you describe.
Thank you anyway.
from nicegui.
Ok, so how would your minimal example look like without page decorators? What is your main entry point?
Without adding page functions to testClass
, you could call it from a page function:
def create_main_page():
@ui.page('/')
def main_page():
testClass()
app.on_startup(create_main_page)
from nicegui.
Thank you that is very close and works on the minimal example, but unfortunately not on my full application. The reason why is that my main entry point is written as a coroutine not as a function (it automatically pulls in a number of files from the user's machine as well as setting up the nicegui interface and performs some other tasks best handled as async). The approach you suggested doesn't appear to work with coroutines. However, I can probably rewrite my code and separate out the interface creation into a function called with app.on_startup, and trigger the other functionality some other way.
Thanks for your help.
from nicegui.
It should also work with coroutines. And I wonder why you would need the on_startup
at all. Have you tried
@ui.page('/')
async def main_page():
t = testClass()
await t.build_ui() # or some other async functions of your classes
from nicegui.
Thank you, I will try it in the way suggested on Monday.
from nicegui.
OK - I've tried it with my code. I get different behaviour when I use app.on_startup and @ui.page("/"). It works properly with app.on_startup() but I get presented with a blank screeen when using ui.page("/"). I'm trying to find out why - its not to do with running in native mode, but I've not been able to isolate where my code is causing a problem. I'd suggest either mark this as closed, or leave it open until I figure out what is happening. As an observation, if you only have one client attached then the "RuntimeError: Cannot await JavaScript responses on the auto-index page. There could be multiple clients connected and it is not clear which one to wait for." is unnecessary which would resolve my problem.
from nicegui.
It works properly with app.on_startup() but I get presented with a blank screeen when using ui.page("/")
Do you have an minimal example?
As an observation, if you only have one client attached then the "RuntimeError: Cannot await JavaScript responses on the auto-index page. There could be multiple clients connected and it is not clear which one to wait for." is unnecessary which would resolve my problem.
But there is no guarantee that you'll always have just one client. We figured it would be quite hard to find such an issue if the error only appears when a second client is connected.
from nicegui.
Related Issues (20)
- Clearing value of `ui.editor` does not work on 2nd try HOT 5
- On the expectations of refreshable + user storage HOT 1
- nicegui-pack issure on windows: No module named 'typing_extensions' HOT 1
- ui.image will never load local image in single page app example HOT 6
- Using chatai, enter the question carriage return did not respond HOT 2
- Client has been deleted but is still being used. This is most likely a bug in your application code HOT 4
- Dark mode switch `ui.expansion()` color to white HOT 1
- ui.download N times when you open N tabs HOT 3
- Nice GUI table elements with buttons don't stick when organizing table HOT 2
- When calling props('color=None') (or white), class text-white is added HOT 3
- `app.shutdown` does not work with `ui.run_with` HOT 2
- What is wrong with on_value_change? HOT 4
- Javascript libraries not discovered in 1.4.27 HOT 2
- RuntimeError: app.storage.user needs a storage_secret passed in ui.run() HOT 8
- on air not working from UK HOT 2
- Make `client.ip` available before socket connection is established
- Input unable to add forward slash (/) when it is bind to path HOT 2
- on_upload doesn't seem to be working HOT 10
- Connection lost within 3 seconds when app is deployed on kubernetes HOT 1
- TypeError: Client.__init__() missing 1 required keyword-only argument: 'request'
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nicegui.