Forum Archive

Trouble performing actions using NavigationView

seriph

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()
ccc

Rename the .pyui file and change the extension from .pyui to .json and the file becomes readable as text. Change the file extension back to .pyui and it becomes a UI again.

cvp

@seriph at least error in

                sub_view = load_view("subView.pyui")

Need's to be ui.load_view...

cvp

@seriph you should read this topic to understand that there is no automatic way to know which view is currently presented in the NavigationView.

But self.nav_view is not the ui.View you want

seriph

Thank you, @ccc and @cvp for the helpful replies. I reviewed the reference @cvp suggested and it clear that NavigationView isn't the best tool for what I want to do: a program that displays the chords and lyrics from ChordPro files with the correct formatting and autoscrolling, including a scrollable list of the .chordpro files and a scrollable list of songs they contain.

I was able to repurpose a single TableView to handle all of this, which saved me from the complexity of working with NavigationView. I plan to try out the script in a guitar jam next month.

shahan67

Nützlicher für die Analyse des Systems ist jedoch das Overture hmi (VDM)-Modell, das eine automatische Zuführung von Bestellungen über eine kommaseparierte Wertedatei (.csv) ermöglicht. Dieser Ansatz ist sowohl flexibel als auch leistungsstark. Die Flexibilität ergibt sich aus der Möglichkeit, Szenarien mit unterschiedlichen Ordnungen zur Abdeckung statistischer Möglichkeiten zu erstellen, während die Leistungsfähigkeit aus der Wiederholbarkeit von Experimenten resultiert. Mit der gleichen .csv-Eingabedatei kann die Co-Simulation mit verschiedenen Parametern, aber gleichzeitig mit den gleichen Eingabereihenfolgen durchgeführt werden, wodurch ein detailliertes Bild des Verhaltens des Systems in kontrollierten, wiederholbaren Experimenten erzeugt wird.

Taranve73013446

I finally got around to trying this and i'm glad to say it works like a charm although I'd be interested to know how you handled client-side validation. When you display serserver-siderors, how did you automatically hide .net server-sidelidation when a useuser-enteredxt into the field so that client-sidelidation can take over? One approach is to set up jquery key and change events that remove the server-sidelidation error span for that input. I am just wondering whether your proach may be cleaner.