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.
Populate ui.Textview from user selections
-
Hi all,
I have multiple tableviews presented in navigationview. There is a textview in the root view. I want to collect all user selections (from all nav views) and display in textview.
-
I'm getting stuck on how to update the textview when a selection is made in deeper sub-levels.
-
What if the individual tables are generated from separate classes?
Can you point me towards a strategy to accomplish this task?
thanks
import ui import console class MyTableView(object): def __init__(self, items, name): self.items = items self.tv = ui.TableView() self.tv.name = self.name = name self.tv.delegate = self.tv.data_source = self def tableview_did_select(self, tableview, section, row): if self.name == 'House' and self.items[row] == 'Kitchen': print(self.name, row) pushed_view = eval('kitchen_tv.tv') tableview.navigation_view.push_view(pushed_view) # does not work. # print('pushed view: {}\nnav view: {}'.format(pushed_view.name,pushed_view.navigation_view)) # pushed_view.navigation_view.superview.superview['txv'].text += self.items[row] +'\n' elif self.name == 'Kitchen' and self.items[row] == 'Fruits': pushed_view = eval('fruit_tv.tv') tableview.navigation_view.push_view(pushed_view) # does not work pushed_view.navigation_view.superview.superview['txv'].text += self.items[row]+'\n' else: tableview.navigation_view.superview.superview['txv'].text += self.items[row]+'\n' #this works def tableview_number_of_sections(self, tableview): return 1 def tableview_number_of_rows(self, tableview, section): return len(self.items) def tableview_cell_for_row(self, tableview, section, row): cell = ui.TableViewCell() cell.text_label.text = self.items[row] return cell house_list = 'Bed Bath Kitchen'.split() kitchen_list = 'Fruits Vegetables Drinks'.split() fruit_list = 'Orange Grape Apple Banana'.split() house_tv = MyTableView(house_list, 'House') kitchen_tv = MyTableView(kitchen_list, 'Kitchen') fruit_tv = MyTableView(fruit_list, 'Fruits') root = ui.View(frame=(0,0,630,330),background_color= '#e3f4ff') txv = ui.TextView(name='txv', frame=(320,10,300,300), background_color='white') root.add_subview(txv) nav_base = ui.View(frame = (10,10,300,300), background_color= '#fafafa') #container for nav root.add_subview(nav_base) nav = ui.NavigationView(house_tv.tv) nav_base.add_subview(nav) root.present('sheet')
-
-
One strategy: global variables.
A cleaner strategy would be to define a custom root view class, that is the delegate of all of your tableviews. Then you have access to self, and whatever views you define as attributes.You can also, when you push your tableview in the first place, define an attribute of the tableview that lets you get back to the root /textview.
-
@JonB thanks for the suggestions.