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.


    tableview_did_select

    Pythonista
    4
    13
    3523
    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.
    • Appletrain
      Appletrain last edited by ccc

      I’m launching a standard dialog from tableview_did_select

      def tableview_did_select(self, tableview, section, row):
              self.selected_row = row
              self.selected_section = section
              print(dialogs.list_dialog('list dialog', items=['happy', 'days', 'are', 'here', 'again']))
      

      This always returns None!

      However, if it’s launched from a ui.ButtonItem on the same view it works properly and returns the selected item.

      def cancel_action(sender):     
          print(dialogs.list_dialog('list dialog', items=['happy', 'days', 'are', 'here', 'again']))    
          ui.end_editing()
          ds.container_view.close()
      

      This always returns the selected item

      Any suggestions on making tableview_did_select work?

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

        @Appletrain, please use the friendly code button </> to surround code with backticks and make it much more readable.

        So the dialog comes up, you make the selection normally, but the return value is None?

        Very curious: if you put the dialog call in another function that you call from did_select with ui.delay (very small delay), it works.

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

          @Appletrain put @ui.in_background just before the def

          @ui.in_background	
          def tableview_did_select(self, tableview, section, row): 
          
          mikael 1 Reply Last reply Reply Quote 1
          • mikael
            mikael @cvp last edited by

            @cvp, cool!

            But then I do not really understand why ui.delay and the button action handler worked, as they are both run on the main UI thread, as is tableview_did_select.

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

              @mikael I don't understand too but I often (not always) meet this problem.
              The problem comes from the wait_modal in the dialog, it doesn't wait sometimes

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

                @cvp @mikael this question is me trying to understnd.

                is it posible the dialoge is making a synchronus call? or possible the dialoge delegate method is retuning before the diloge skipping dialoge return all together?

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

                  @stephen I think it is something like that..

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

                    This post is deleted!
                    1 Reply Last reply Reply Quote 0
                    • stephen
                      stephen last edited by stephen

                      @mikael @cvp @Appletrain sorry about post miss-hap.. i found this to work. but it bypasses dialogs module..

                      import ui
                      
                      class DataSource(object):
                      	def __init__(self, items):
                      		self.items=items
                      		
                      	def tableview_cell_for_row(self, tableview, section, row):
                      		# Create and return a cell for the given section/row
                      		cell = ui.TableViewCell()
                      		cell.text_label.text =  self.items[row]
                      		return cell
                      	
                      	def tableview_number_of_sections(self, tableview):
                      		# Return the number of sections (defaults to 1)
                      		return 1
                      
                      	def tableview_number_of_rows(self, tableview, section):
                      		# Return the number of rows in the section
                      		return len(self.items)
                      
                      class TV:
                      	def __init__(self):
                      		self.menu_one_options = ['Banana', 'Orenge', 'Grape']
                      		self.menu_two_options = ['happy', 'days', 'are', 'here', 'again']
                      		frame=(0, 0, 200, 600)
                      		
                      		self.selected=''
                      		
                      		self.tv1 = ui.TableView(frame=frame)
                      		self.tv1.name='menu-one'
                      		self.tv1.delegate = self
                      		self.tv1.hidden=False
                      		self.tv1.data_source = DataSource(self.menu_one_options)
                      		self.tv1.present('sheets')
                      		
                      		self.tv2 = ui.TableView(frame=frame)
                      		self.tv2.name='menu-two'
                      		self.tv2.delegate = self
                      		self.tv2.hidden=True
                      		self.tv2.data_source = DataSource(self.menu_two_options)
                      		
                      		
                      	def tableview_did_select(self, tableview, section, row):
                      		if not self.tv1.hidden:
                      			self.selected += tableview.data_source.items[row] + ' '
                      			self.tv1.hidden=True
                      			self.tv2.present('sheets')
                      			self.tv2.hidden=False
                      		elif not self.tv2.hidden:
                      			self.selected += tableview.data_source.items[row]
                      			print (self.selected)
                      			self.tv2.hidden=True
                      			self.tv1.close()
                      			self.tv2.close()
                      
                      
                      cvp 1 Reply Last reply Reply Quote 0
                      • cvp
                        cvp @stephen last edited by

                        @stephen said:

                        @ Appletrain

                        One space to be removed 🙄

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

                          @cvp 😅😅 oops

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

                            Thank you all. @ui.in_backround solved it.

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

                              @Appletrain youpee

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