omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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

    Pythonista
    3
    9
    3942
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Grun6
      Grun6 last edited by

      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

      Phuket2 1 Reply Last reply Reply Quote 0
      • Phuket2
        Phuket2 @Grun6 last edited by

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

        1 Reply Last reply Reply Quote 0
        • Grun6
          Grun6 last edited by

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

          cvp Phuket2 2 Replies Last reply Reply Quote 0
          • cvp
            cvp @Grun6 last edited by cvp

            @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):					
            
            1 Reply Last reply Reply Quote 1
            • Phuket2
              Phuket2 @Grun6 last edited by

              @Grun6 , did @cvp solution work for you. Sorry for the quick response and bad formatting, I was just off to bed and I seen you post, thought I spotted the answer.
              I have to set up the 3 backticks shortcut on my MacPro :).
              Anyway, let us know if you need more help

              cvp 1 Reply Last reply Reply Quote 0
              • cvp
                cvp @Phuket2 last edited by cvp

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

                Phuket2 1 Reply Last reply Reply Quote 0
                • Phuket2
                  Phuket2 @cvp last edited by

                  @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 :)

                  cvp 1 Reply Last reply Reply Quote 0
                  • cvp
                    cvp @Phuket2 last edited by

                    @Phuket2 ๐Ÿฅƒis good for us๐Ÿ˜‚

                    1 Reply Last reply Reply Quote 0
                    • Grun6
                      Grun6 last edited by

                      @cvp and @Phuket2 thank you for your responses

                      The behaviour was exactly that the form_dialog returned to calling code before it's end when called from the tableview. And the decorator @ui.in_background fixes it.
                      Thanks!

                      G

                      1 Reply Last reply Reply Quote 1
                      • First post
                        Last post
                      Powered by NodeBB Forums | Contributors