Forum Archive

Simple (I think) alert dialog question

Appletrain

link textI 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.

cvp

@Appletrain said:

This doesn’t...

What is the problem? Without knowing what is input_frm, it is difficult to help

cvp

@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
Appletrain

It crashes Pythonista. It’s a switch on a simple test form. Does’t do anything. Tap the switch and pythonista locks up.

Appletrain

@cvp Thank you, that did it.

cvp

@Appletrain known problem of thread locked by alert...

cvp

@Appletrain read @jonb explanation in this very old topic or read here

cvp

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()).