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.
Simple (I think) alert dialog question
-
[link text](link url)I hope someone can help on this.
This works...
def alert_action(sender): print('got here') #print(dialogs.alert('Change to inactive', 'Are you sure?', 'Ok')) input_frm['switch1'].action=alert_action
This doesn’t...
def alert_action(sender): print('got here') print(dialogs.alert('Change to inactive', 'Are you sure?', 'Ok')) input_frm['switch1'].action=alert_action
and it locks up Pythonista
I just can’t see what’s wrong.
-
@Appletrain said:
This doesn’t...
What is the problem? Without knowing what is input_frm, it is difficult to help
-
@Appletrain this works
import ui import dialogs @ui.in_background def alert_action(sender): print('got here') print(dialogs.alert('Change to inactive', 'Are you sure?', 'Ok')) input_frm = ui.View() switch1 = ui.Switch(name='switch1') input_frm.add_subview(switch1) input_frm.frame = (0,0,400,400) input_frm.present('sheet') input_frm['switch1'].action=alert_action
-
It crashes Pythonista. It’s a switch on a simple test form. Does’t do anything. Tap the switch and pythonista locks up.
-
@cvp Thank you, that did it.
-
@Appletrain known problem of thread locked by alert...
-
@Appletrain read @jonb explanation in this very old topic or read here
-
And that is the example of the ui module doc for ui.in_background
ui.in_background(fn) Call a function on the main interpreter thread. This is useful to perform long-running tasks from an action or delegate callback without blocking the UI. It can also be used for functions that don’t support being called from the main UI thread (e.g. console.alert()).