Pythonista-Issues
Pythonista-Issues copied to clipboard
Console dialogs does not appear and freeze script
Hi,
I have a script that use console.alert and console.input_alert on top of its UI. However, these functions have stopped working in this script. Whenever I call them, they do not appear and the program freezes. If I hide Pythonista (by swapping to another app) and then return to Pythonista, the alert window appears but is unresponsive.
If I call these functions from an empty script with no UI, they seem to work fine. I wonder if there could be an issue with these functions on top of UIs.
This worked around a year ago when I last used the app, so I wonder if something has broken during an iOS update? Has anybody else seen this issue?
I am using a 2nd gen iPad Pro with iOS 17.1.2
Thanks, Rune
Here’s a reproducible case.
Open up the example file called “ColorMixer.py” under “User Interface”.
Change this function:
def copy_action(sender):
clipboard.set(sender.superview['label1'].text)
hud_alert('Copied')
To this:
def copy_action(sender):
if console.alert('Copy warning'):
clipboard.set(sender.superview['label1'].text)
hud_alert('Copied')
The script will hang when you press the ‘Copy’ button.
Try this
@ui.in_background
def copy_action(sender):
#clipboard.set(sender.superview['label1'].text)
#hud_alert('Copied')
import console
if console.alert('Copy warning'):
clipboard.set(sender.superview['label1'].text)
hud_alert('Copied')
Thanks! This fixed the problem in my script!
Does this mean @ui.in_background is how you should do it, or is it a workaround?
In the past, we did not need this line except in some cases, thus it is a workaround and you could find a very good explanation of @jonB in the forum, if I find it again, I'll post it here
Thanks :)
I can't find the topic, bad search arguments I guess, if you could already read this one https://forum.omz-software.com/topic/1156/console-input_alert-freeze
And this one https://forum-new.omz-software.com/topic/1119/can-t-show-an-alert/2