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.
Dialogs issue
-
I have found an issue with the dialogs module and I'm not sure why @omz you might be able to explain.
The code here is a simple example of it.
# coding: utf-8 import ui import dialogs def dia_test(sender): dialogs.form_dialog(title='Test',fields=[{'type':'text','title':'Some Title'}]) class testtv (object): def tableview_did_select(self, tableview, section, row): dia_test(None) def tableview_number_of_rows(self, tv, s): return 1 def tableview_cell_for_row(self, tv, s, r): cell = ui.TableViewCell('default') cell.text_label.text = 'Test' cell.selectable = True return cell view = ui.TableView() dbo = testtv() view.data_source = dbo view.delegate = dbo view.right_button_items = [ui.ButtonItem(title='Press me!', action=dia_test)] view.present()
When I click the bar button item press me the form dialog appears ok and I can click done and it dismisses happily.
If I call the same function from the tableview_did_select The form dialog appears but when I click done I get the following errorTraceback (most recent call last):
File "/var/mobile/Containers/Bundle/Application/CEBD1281-94B0-4EEC-BA60-D9599A5873CD/Pythonista.app/Frameworks/PythonistaKit.framework/pylib/site-packages/dialogs.py", line 365, in done_action
self.container_view.close()
AttributeError: 'NoneType' object has no attribute 'closeI hope all this code has formatted happily I'm posting this from my mobile and the form isn't that great.
-
Does anyone have any thought as to a workaround for this?
I assume this is a bug in the dialogs module.
-
Here is the fix. The problem is that
dialogs
produces a model view, and Python needs to know that, or bad things happen. This is done by using the decorator@ui.inbackground
.# coding: utf-8 import ui import dialogs @ui.in_background def dia_test(sender): dialogs.form_dialog(title='Test',fields=[{'type':'text','title':'Some Title'}]) class testtv (object): def tableview_did_select(self, tableview, section, row): dia_test(None) def tableview_number_of_rows(self, tv, s): return 1 def tableview_cell_for_row(self, tv, s, r): cell = ui.TableViewCell('default') cell.text_label.text = 'Test' cell.selectable = True return cell view = ui.TableView() dbo = testtv() view.data_source = dbo view.delegate = dbo view.right_button_items = [ui.ButtonItem(title='Press me!', action=dia_test)] view.present()
-
Thanks that works a treat