tomkirn
Feb 03, 2015 - 19:46
Hi all,
When trying to use a dialogs.list_dialog from within an Ui.view I got no result back from dialog. Is this a bug or do I misunderstood something?
Regards
Tom
Hi all,
When trying to use a dialogs.list_dialog from within an Ui.view I got no result back from dialog. Is this a bug or do I misunderstood something?
Regards
Tom
Apparently UI and dialogs don't mix:
@ui.in_background line is commented out then action() only runs once you have closed view.@ui.in_background line is not commented out then dialogs.list_dialog() always returns None.import dialogs, ui
@ui.in_background # try it with this line commented out and with this line not commented out.
def action(sender):
print('action() starts')
#sender.superview.hidden = True
#sender.superview.sent_to_back()
print(dialogs.list_dialog(sender.title, sender.title))
#sender.superview.hidden = False
print('action() ends')
view = ui.View()
button = ui.Button(title='Show List')
button.action = action
view.add_subview(button)
view.present()
button.center = view.center
# view.wait_modal() # FIX: commented out as suggested by @omz below.
If you remove the view.wait_modal() line, it should work.
That works!
Ok, got it. I forgot the @ui.in_background
Now it works
When using the dialogs module, is the size of the text_dialogs box fixed or can it be made a specified size?
It uses a fixed size, but you could define your own text_dialog function like this:
import dialogs
import ui
def custom_text_dialog(size=(500, 500), title='', text='', font=('<system>', 16), autocorrection=None, autocapitalization=ui.AUTOCAPITALIZE_SENTENCES, spellchecking=None, done_button_title='Done'):
c = dialogs._TextDialogController(title=title, text=text, font=font, autocorrection=autocorrection, autocapitalization=autocapitalization, spellchecking=spellchecking, done_button_title=done_button_title)
c.view.bounds = (0, 0, size[0], size[1])
c.view.present('sheet')
c.view.begin_editing()
c.view.wait_modal()
return c.text
print 'Result:', custom_text_dialog(size=(300, 400))
(this is basically just a variation of the actual text_dialog source code)