Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Calling console.quicklook() on a UI button action?
-
Hi there,
In my program I have a GUI with a button which, when pressed, is supposed to bring up a Quick Look of a particular file. I decorated the button function with @ui.in_background and yet when the button is pressed, no Quick Look view pops up. On the first press, nothing happens and on the second press Pythonista as a whole hangs and needs to be force-closed via the app switcher. An example is the following, where the pyui file just contains a single button whose action references the button function.# coding: utf-8 import ui import console @ui.in_background def button(sender): console.quicklook('file.ics') ui.load_view('Untitled 2').present('sheet')
-
I think
console.quicklook()
needs a full file path as an argument. What is the path to the file? -
The file is in the same directory as the script so that is the full path of the file. The statement works just fine when it's not called from a ui function or when it's called from the console, it's just something about being called via a button action that prevents it from working.
-
https://omz-forums.appspot.com/pythonista/post/5256919912546304
Short answer: you must close any ui views before running quicklook. Longer answer, you have to use ui.delay to make sure the view is finished hiding before calling quicklook. For actual code. See thread above.
-
Thank you, that worked brilliantly! Neither threading.Timer nor ui.delay were working properly; they just hung the program.<Br>
<code>
v.close()<Br>
time.sleep(1)
<br>console.quicklook('file.ics')</code>
<Br>worked perfectly though.