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.


    Examples for dialogs.form_dialog() ?

    Pythonista
    dialogs python3
    6
    37
    18891
    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.
    • yas
      yas last edited by yas

      Can anyone give me examples on dialogs.form() ?

      Thanks in Advance

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

        dialogs.form_dialog(title='fu',fields=[{'type':'switch','key':'chrc','title':'yas','tint_color':'linen'}])
        

        How do I use sections?

        cvp 1 Reply Last reply Reply Quote 0
        • enceladus
          enceladus last edited by

          Look at this discussion
          https://forum.omz-software.com/topic/4260/dialogs-form_dialog-wrapper-helper

          1 Reply Last reply Reply Quote 1
          • cvp
            cvp @yas last edited by

            @yas

            import dialogs
            sections = []
            fields = []
            field = {'type':'switch','key':'chrc1','title':'yas','tint_color':'linen'}
            fields.append(field)
            sections.append(('title section 1', fields))
            fields = []
            field = {'type':'switch','key':'chrc2','title':'ying','tint_color':'linen'}
            fields.append(field)
            sections.append(('title section 2', fields))
            dialogs.form_dialog(title='fu',sections=sections)
            
            1 Reply Last reply Reply Quote 1
            • enceladus
              enceladus last edited by

              You could have footer also in the sections

              import dialogs
              import datetime
              
              form_list_of_sections = []
              
              sectionA_dicts = []
              sectionA_dicts.append(dict(type = 'text', title = 'First Name',
              key = 'first', placeholder = 'John'))
              
              sectionA_dicts.append(dict(type = 'text', title = 'Last Name',
              key = 'last', placeholder = 'Doe')) 
              
              sectionA_dicts.append(dict(type = 'number', title = 'age',
              key = 'age', placeholder='30')) 
              
              form_list_of_sections.append(('Section A', sectionA_dicts, 'Section A ends'))
              
              sectionB_dicts = []
              sectionB_dicts.append(dict(type = 'date', title = 'Date Of Birth',
              key = 'DOB', value = datetime.date.today()))
              
              sectionB_dicts.append(dict(type = 'url', title = 'Home Page',
                  key = 'homepage', placeholder = 'http://example.com')) 
                  
              form_list_of_sections.append(('Section B', sectionB_dicts, 'Section B ends'))
              
              sectionC_dicts = []
              sectionC_dicts.append(dict(type = 'email', title = 'email',
              key = 'email', placeholder = 'name@mailserver.com')) 
              
              sectionC_dicts.append(dict(type = 'switch', title = 'is_married',
              key = 'is_married', value = True))  
              
              sectionC_dicts.append(dict(type = 'check', title = 'is_registered',
              key = 'is_registered', value = False))  
              
              form_list_of_sections.append(('Section C', sectionC_dicts, 'Section C ends'))
              
              diag = dialogs.form_dialog(title = 'Form Dialog', sections=form_list_of_sections)
              print(diag)
              
              1 Reply Last reply Reply Quote 2
              • madivad
                madivad last edited by

                Not sure what’s happening here, if it is intended or something is broken in iOS, but a lot of fields appear to have their alignment broken. This is on the iPad with iPad os. Is there a way to force right alignment?

                example

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

                  @madivad True, I also remarked this problem but with the beta version of Pythonista3

                  Édit: temporarily, I've added some blanks at end of each field title

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

                    @cvp Do you mean it’s only a problem with the beta? I am on the beta.

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

                      @madivad said:

                      Do you mean it’s only a problem with the beta?

                      I think so

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

                        @cvp do you think there would be a workaround using the objc tools?

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

                          @madivad I think that Objectivec is not needed and that you could use tableview_cell_for_row delegate

                          Édit: but you need to have your own form_dialog, I think 😢

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

                            @cvp ok, thx

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

                              @madivad try this, waiting that @omz correct it

                              import dialogs
                              import datetime
                              
                              #================ copy dialogs.form_dialog: begin
                              import collections
                              import sys
                              PY3 = sys.version_info[0] >= 3
                              if PY3:
                              	basestring = str
                              
                              def my_form_dialog(title='', fields=None, sections=None, done_button_title='Done'):
                              	if not sections and not fields:
                              		raise ValueError('sections or fields are required')
                              	if not sections:
                              		sections = [('', fields)]
                              	if not isinstance(title, basestring):
                              		raise TypeError('title must be a string')
                              	for section in sections:
                              		if not isinstance(section, collections.Sequence):
                              			raise TypeError('Sections must be sequences (title, fields)')
                              		if len(section) < 2:
                              			raise TypeError('Sections must have 2 or 3 items (title, fields[, footer]')
                              		if not isinstance(section[0], basestring):
                              			raise TypeError('Section titles must be strings')
                              		if not isinstance(section[1], collections.Sequence):
                              			raise TypeError('Expected a sequence of field dicts')
                              		for field in section[1]:
                              			if not isinstance(field, dict):
                              				raise TypeError('fields must be dicts')
                              
                              	#========== modify textfield frame: begin
                              	c = dialogs._FormDialogController(title, sections, done_button_title=done_button_title)
                              	for s in range(0,len(c.sections)):
                              		for i in range(0,len(c.cells[s])):			# loop on rows of section s
                              			cell = c.cells[s][i]									
                              			print(cell.text_label.text)
                              			if len(cell.content_view.subviews) > 0:
                              				tf = cell.content_view.subviews[0] 		# ui.TextField of value in row
                              				tf.x += 20
                              				tf.width -= 20
                              	#========== modify textfield frame: end
                              				
                              	c.container_view.present('sheet')
                              	c.container_view.wait_modal()
                              	# Get rid of the view to avoid a retain cycle:
                              	c.container_view = None
                              	if c.was_canceled:
                              		return None
                              	return c.values
                              #================ copy dialogs.form_dialog: end
                              
                              form_list_of_sections = []
                              
                              sectionA_dicts = []
                              sectionA_dicts.append(dict(type = 'text', title = 'First Name',
                              key = 'first', placeholder = 'John'))
                              
                              sectionA_dicts.append(dict(type = 'text', title = 'Last Name',
                              key = 'last', placeholder = 'Doe')) 
                              
                              sectionA_dicts.append(dict(type = 'number', title = 'age',
                              key = 'age', placeholder='30')) 
                              
                              form_list_of_sections.append(('Section A', sectionA_dicts, 'Section A ends'))
                              
                              sectionB_dicts = []
                              sectionB_dicts.append(dict(type = 'date', title = 'Date Of Birth',
                              key = 'DOB', value = datetime.date.today()))
                              
                              sectionB_dicts.append(dict(type = 'url', title = 'Home Page',
                                  key = 'homepage', placeholder = 'http://example.com')) 
                                  
                              form_list_of_sections.append(('Section B', sectionB_dicts, 'Section B ends'))
                              
                              sectionC_dicts = []
                              sectionC_dicts.append(dict(type = 'email', title = 'email',
                              key = 'email', placeholder = 'name@mailserver.com')) 
                              
                              sectionC_dicts.append(dict(type = 'switch', title = 'is_married',
                              key = 'is_married', value = True))  
                              
                              sectionC_dicts.append(dict(type = 'check', title = 'is_registered',
                              key = 'is_registered', value = False))  
                              
                              form_list_of_sections.append(('Section C', sectionC_dicts, 'Section C ends'))
                              
                              diag = my_form_dialog(title = 'Form Dialog', sections=form_list_of_sections)
                              print(diag) 
                              
                              1 Reply Last reply Reply Quote 0
                              • cvp
                                cvp @madivad last edited by

                                @madivad better with

                                			if len(cell.content_view.subviews) > 0:
                                				tf = cell.content_view.subviews[0] 		# ui.TextField of value in row
                                				if type(tf) is ui.TextField:
                                					tf.x += 20
                                					tf.width -= 20 
                                
                                1 Reply Last reply Reply Quote 0
                                • ccc
                                  ccc last edited by

                                  @cvp said:

                                  if type(tf) is ui.TextField:

                                  PEP8: Avoid directly comparing types. Use isinstance(tf, ui.TextField) instead.

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

                                    @ccc ok, PEP are conventions. Why "Avoid directly comparing types"? Is there a technical reason? You have to agree that "type(tf) is xxx" is more readable than the PEP code 😀

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

                                      @ccc found that, and I like it, thus, forget my previous post 😀

                                      isinstance caters for inheritance (an instance of a derived class is an instance of a base class, too), while checking for equality of type does not (it demands identity of types and rejects instances of subtypes, AKA subclasses).

                                      Normally, in Python, you want your code to support inheritance, of course (since inheritance is so handy, it would be bad to stop code using yours from using it!), so isinstance is less bad than checking identity of types because it seamlessly supports inheritance.

                                      It's not that isinstance is good, mind you—it's just less bad than checking equality of types

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

                                        @cvp but but but...
                                        It's a text field, why not just align it right?

                                        I did just that and it's perfect now:

                                        tf.alignment=ui.ALIGN_RIGHT
                                        

                                        :)

                                        Is there a way to do that without creating our own custom dialogue type?

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

                                          @madivad said:

                                          Is there a way to do that without creating our own custom dialogue type?

                                          I don't think so because dialogs.form_dialog does the "present" and you can't modify something after the view presentation. But perhaps somebody else could find another way.

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

                                            @madivad said:

                                            tf.alignment=ui.ALIGN_RIGHT

                                            Good idea but sometimes, user may prefer a left alignment for text and a right alignment for numbers, thus, up to you 😀

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