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.


    Dialogs issue

    Pythonista
    dialogs
    2
    4
    4347
    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.
    • shaun-h
      shaun-h last edited by

      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 error

      Traceback (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 'close

      I hope all this code has formatted happily I'm posting this from my mobile and the form isn't that great.

      1 Reply Last reply Reply Quote 1
      • shaun-h
        shaun-h last edited by

        Does anyone have any thought as to a workaround for this?

        I assume this is a bug in the dialogs module.

        1 Reply Last reply Reply Quote 1
        • blmacbeth
          blmacbeth last edited by

          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()
          
          1 Reply Last reply Reply Quote 0
          • shaun-h
            shaun-h last edited by

            Thanks that works a treat

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