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
-
Using @polymerchm's method gives me the following error:
List indices must be integers, not str
-
type(sender.items)
will show you thatsender.items
is a list.Lists are indeed indexed by integers, not by strings.
Does
type(title)
show you thattitle
is a string or an integer?You could try
if sender.items[int(title)] == 'Notepad':
iftitle
contains a string that represents an integer. -
type(title) is not defined
type('title') shows a string
-
Can you post the code, not just the snippet? Might be easier to help.
-
Same as above post
-
OK. If
title
is undefined then why would you expect your code above to work?? -
As I said in my original post, I am not sure what I need. I want to get the text in the row selected.
-
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.
-
@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)
-
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 fileAnd then the
if
statement innav()
becomes:if sender.items[sender.selected_row]['title'] == 'Notepad':
-
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.
-
@ccc Thanks!
-
@polymerchm wrote "sender" is the returned the tableview object.
sender
is the ui.ListDataSource object, not the ui.TableView object which makes things easier. -
Thaanks for the clarification.