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.


    Getting the row title of the selected row

    Pythonista
    4
    17
    6704
    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.
    • techteej
      techteej last edited by

      Not sure why I'm getting errors here, but I'm trying to get the title of the selected row chosen (or the name of whatever is in the row)

      if sender.items[title] == 'Notepad':
      		ui.load_view('Notepad').present()
      else:
      		pass
      
      1 Reply Last reply Reply Quote 0
      • polymerchm
        polymerchm last edited by

        I believe you want:

        if sender.items['title'] == 'Notepad':
        

        etc
        etc

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

          Also, the following code is unnecessary and can safely be removed.

          else:
              pass
          
          1 Reply Last reply Reply Quote 0
          • techteej
            techteej last edited by

            Using @polymerchm's method gives me the following error:

            List indices must be integers, not str

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

              type(sender.items) will show you that sender.items is a list.

              Lists are indeed indexed by integers, not by strings.

              Does type(title) show you that title is a string or an integer?

              You could try if sender.items[int(title)] == 'Notepad': if title contains a string that represents an integer.

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

                type(title) is not defined

                type('title') shows a string

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

                  Can you post the code, not just the snippet? Might be easier to help.

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

                    Same as above post

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

                      OK. If title is undefined then why would you expect your code above to work??

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

                        As I said in my original post, I am not sure what I need. I want to get the text in the row selected.

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

                          Tech,
                          Keep in mind, none of us here has access to your code, so we are just guessing what you are trying to do,and where you are trying to do it ( are you in a table view action function? Or some button action? We have no idea, and the meaning of sender is different!). Also, in your original post you said you were getting an error... But didn't mention what error you are getting.

                          So, rather than guess, I'll point you to

                          https://github.com/humberry/ui-tutorial/blob/master/ShowTableView.py

                          which shows an example of how to get the text of the currently selected row, from within the ListDataSource action. See line 45.

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

                            @JonB Here is my full program. I am trying to launch different ui.Views based on the TEXT INSIDE OF A CELL.

                            Example Table:

                            Blah >

                            Blah >

                            Notepad >

                            If I click Notepad, I would like Notepad to launch.

                            # coding: utf-8
                            
                            import ui
                            from datetime import datetime, date
                            current_date = datetime.strftime(date.today(), "%A, %B %d, %Y")
                            schedule = 'A Day'
                            
                            def nav(sender):
                            	if sender.items[int('title')] == 'Notepad':
                            		ui.load_view('Notepad').present()
                            	else:
                            		pass
                            
                            v = ui.load_view('SoarNet')
                            v['todays_date'].text = ('Today is ' + current_date)
                            v['schedule'].text = schedule
                            v.present(orientations=['landscape'], hide_title_bar=True)
                            
                            1 Reply Last reply Reply Quote 0
                            • ccc
                              ccc last edited by

                              In the main part of your script, you need to add a line like:

                              v['tableview1'].delegate.action = nav # alternatively, this could be done in the .pyui file

                              And then the if statement in nav() becomes:

                              if sender.items[sender.selected_row]['title'] == 'Notepad':

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

                                I'll presume that you are using a tableview to store your selection. Start small and replace the ui.load_view with a print statement to ensure you are actually getting in here. Next, I presume you hardcoded nav as the action to this view in the gui editor. That's okay. "sender" is the returned the tableview object. The "items" are actually in sender.data_source.items. Get the selected row via:

                                row = sender.selected_row
                                if sender.data_source.items[row]['title'] == 'Notepad':
                                   print "got here"
                                

                                Using NavigationViews is a much easier way to switch between views. Look at my flashcard program @ https://github.com/polymerchm/flashcard to see how I switch between the "flashcard view" and the "dictionary views". Also getting the items and changing them programmatically.

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

                                  @ccc Thanks!

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

                                    @polymerchm wrote "sender" is the returned the tableview object.

                                    sender is the ui.ListDataSource object, not the ui.TableView object which makes things easier.

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

                                      Thaanks for the clarification.

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