Pythonista-Issues icon indicating copy to clipboard operation
Pythonista-Issues copied to clipboard

Console dialogs does not appear and freeze script

Open superrune opened this issue 1 year ago • 7 comments
trafficstars

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

superrune avatar Dec 28 '23 11:12 superrune

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.

superrune avatar Dec 28 '23 11:12 superrune

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')

cvpe avatar Jan 03 '24 08:01 cvpe

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?

superrune avatar Jan 03 '24 11:01 superrune

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

cvpe avatar Jan 03 '24 11:01 cvpe

Thanks :)

superrune avatar Jan 03 '24 11:01 superrune

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

cvpe avatar Jan 03 '24 12:01 cvpe

And this one https://forum-new.omz-software.com/topic/1119/can-t-show-an-alert/2

cvpe avatar Jan 03 '24 12:01 cvpe