I'm seeing a difference and possible bug in the behavior of the editor module. (using version 1.5)
I want to read a file's contents. It works when running a basic script, but not when triggered by a button press.
Spent awhile on this, I believe this is the simplest path to reproduce:
- Create two scripts, one called "ReadMe.py" and one called "RunMe.py"
- Put some junk text in ReadMe
- Open RunMe and add a UI (calling the necessary load_view and present)
- Create a method called open_script, using the code below
- Create a button
- Set the action of the button to be open_script
- Run the UI, click the button
Code:
from console import hud_alert
def open_script(sender):
editor.open_file('ReadMe.py')
time.sleep(0.5) # give time for file to be loaded
hud_alert(editor.get_path())
hud_alert(editor.get_text())
You'll see the path and first line of RunMe rather than ReadMe. Although when you close the UI, you'll be on the ReadMe script.
But if you run the logic of open_script just on its own, not through the UI, everything works as expected.
Please advise a workaround or correct my misunderstanding?
Thank you for Pythonista!