-
-
Notifications
You must be signed in to change notification settings - Fork 402
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
automatic scroll down in text widget (write only) #515
Comments
to automatically scroll down an element you'll have to use JS, see an example below:
notice in the code above that self is a reference to your Remi App and you should change the 'customid' of the JS code to the HTML id of the text widget element on the page |
would like to ask @dddomodossola for a little help I am working on an app that shows a little console to output info to the user. After inserting the message the the element is scrolled down using JS code, but after scrolling down it goes back up automatically. should this really be happening? I'll paste a code here to show this behavior:
|
Hello @tuliomgui and @WAvdBeek , The code above is fine, it appends elements to a container and gets scrolled down by javascript. The problem is that remi updates the interface asyncronously, and so the scrollTop gets lost once the element is updated. if __name__ == "__main__":
start(MyApp, update_interval=0) And the code above should now work fine. BUT, my advice is to not to work this way. I suggest to PRE-pend text to a TextInput instead of appending elements. This way, you will not need to scroll nothing, the latest log id always on top. Kind Regards, |
Thank you @dddomodossola I'll give it a try |
Thanks! |
is it possible to append text to a text widget? |
try using the you can check the docs here |
Yes, that is what I am doing now, but I would be better to have a call between the server and client to append text only, e.g sending only the text to be added. |
Hello @WAvdBeek , why do you want to append text directly by websocket? Although this could be possible, I suggest you to use the method proposed by @tuliomgui . It doesn't cost more in terms of efficiency. import remi.gui as gui
from remi import start, App
import time
class MyApp(App):
def main(self):
# creating a container VBox type, vertical (you can use also HBox or Widget)
main_container = gui.VBox(width=300, style={'margin': '0px auto'})
bt_log = gui.Button("Append log")
bt_log.onclick.do(self.on_btlog_click)
main_container.append(bt_log)
self.txt_log = gui.TextInput(single_line=False, width = "100%", height = 150)
main_container.append(self.txt_log)
# returning the root widget
return main_container
def on_btlog_click(self, emitter):
log_message = str(time.time()) + " - a message example"
self.execute_javascript(f"""element = document.getElementById("{self.txt_log.identifier}");
element.textContent = "{log_message}" + "\\n" + element.textContent;""")
if __name__ == "__main__":
start(MyApp, address='0.0.0.0', port=0, start_browser=True) |
I have a text widget that I use for logging. hence each time a log entry is made this text is extended.
to have it nicely working for the end user, I like to automatically scroll down. How can this be achieved?
The text was updated successfully, but these errors were encountered: