I am unable to use button actions on a table view, all within a subview using NavigationView. I would like to be able to click a button on the subview and have it manipulate the table view, but even trying to print the contents of objects in the subview isn't working, as shown below. I expect I am simply referencing the variables the wrong way, but I have not been able to get through this impasse. I get errors shown as comments in the code below.
To create the example below, I use two pyui files which I have summarized. If there is a way to share the pyui files in the forum, let me know. I tried embedding the json for the pyui as a string, but that didn't work. And I am sorry the example code is so complicated. I am happy to provide clarification.
import ui
# rootView.pyui contents:
# Text Field: name = displayString, action = none
# Button: name = displayButton, action = self.bt_display
# Table View: name = rootviewListTable
# subView.pyui contents:
# Text Field: name = svDisplayString, action = none
# Button: name = svDisplayButton, action = self.bt_svDisplay
# Button: name = attributesButton, action = self.bt_attributes
# Table View: name = svText
def make_button_item(action, image_name):
return ui.ButtonItem(action=action, image=ui.Image.named(image_name))
class navviewManager(ui.View):
def __init__(self):
self.currentSongTitle = ""
self.root_view = ui.load_view("rootView.pyui")
self.root_view.left_button_items = [
make_button_item(self.bt_close, "ionicons-close-24")
]
self.root_view.right_button_items = [
make_button_item(self.bt_subview, "ionicons-arrow-right-b-24")
]
self.nav_view = ui.NavigationView(self.root_view)
self.nav_view.present(hide_title_bar=True)
def bt_subview(self, sender):
sub_view = load_view("subView.pyui")
sub_view.name = "subview"
myText = "This is myText"
myList = ui.ListDataSource(myText)
myTextTable= sub_view["svText"]
myTextTable.data_source = myTextTable.delegate = myList
myTextTable.data_source.delete_enabled = myTextTable.editing = False
self.nav_view.push_view(sub_view)
def bt_display(self, sender):
displayTerm = self.root_view["displayString"].text
myList = ui.ListDataSource(displayTerm)
myRootListTable = self.root_view["rootviewListTable"]
myRootListTable.data_source = myRootListTable.delegate = myList
myRootListTable.data_source.delete_enabled = myRootListTable.editing = False
myRootListTable.reload_data()
def bt_svDisplay(self, sender):
svDisplayTerm = self.nav_view["svDisplayString"].text
# AttributeError: 'NoneType' object has no attribute 'text'
myList = ui.ListDataSource(svDisplayTerm)
svListTable = self.nav_view["svText"]
svListTable.data_source = svListTable.delegate = myList
svListTable.data_source.delete_enabled = svListTable.editing = False
svListTable.reload_data()
def bt_attributes(self, sender):
print(self.root_view["displayString"].text) # OK
print(vars(self.root_view["displayString"])) # OK
print(vars(self.nav_view["svDisplayString"]))
# TypeError: vars() argument must have __dict__ attribute
def bt_close(self, sender):
self.nav_view.close()
manager = navviewManager()