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.
Nonetype form dialogs returns - varying behavior
-
Hello,
I am faced with the following situation:
1- I have a simple view that I load which contains a button and a tableview.
2- I have set the button's action to a function that calls a form dialogs, and I capture the result when the form is filled in a variable called "result". The return type of a form dialog is a dictionary. Hence type(result) is dict
3- In my tableview, I have set the action of my ListDataSource object to a similar function. Tapping one row of the table calls a form dialog. When I press the "Done" button in the form dialog, I get an error 'NoneType' object has no attribute 'close'. I checked and the same variable "result" when used in this context is NoneType. I do not understand that difference in behaviour.To reproduce do the following:
create a pyui file called interface with a button called button1 and a tableview called tableview1. Then:import ui, dialogs listitems = ['foo','bar'] def getform(sender): fields = [{'type':'text' ,'key':'fname' ,'value':'' ,'title':'First name' }] result = dialogs.form_dialog(fields = fields) v = ui.load_view('interface') mainlist = v['tableview1'] LDS = ui.ListDataSource(listitems) mainlist.data_source = mainlist.delegate = LDS LDS.action = getform v['button2'].action = getform v.present('sheet')
I would be grateful if someone could explain the difference in behaviours.
Thank you,G
-
@Grun6 ,
Hi I am not in front of Pytonisita now, just on my desktop. But your function 'getform' is not returning a result.
the line
result = dialogs.form_dialog(fields = fields)
could be
return dialogs.form_dialog(fields = fields) -
@Phuket2
no that does not change anything. Returning the dictionary or assigning a variable to it does not change the weird behaviour that it would be NoneType when triggered from the tableview...
Any ideas ? -
@Grun6 In some cases, the form_dialog returns to calling code before it's real end, due to a problem of thread with wait_modal performed by form_dialog.
Try@ui.in_background def getform(sender):
-
-
@Phuket2 Hi, just to say, I don't use any shortcut for the 3 backticks, I use the </> just here-above, in edit mode of course.
-
@cvp , hi. Hope you are having a nice Sunday. LOL, you are right. I forgot about </> :) It's because, I have a shortcut setup that after typing 3 comms I get the back ticks followed by python. You can see sometimes when I post, I forget to delete the python from the end block.
I am not sure it makes a difference here or not, but some sites, if you dont follow the backticks with python, it does format the code but sometimes not as good. I a feeling the old Pythonista Forum was like that.Also last night, I had a of whiskey's so the brain was not that good. I was only on my computer because I had to check something quickly before going to bed :)
-
@Phuket2 ๐ฅis good for us๐
-