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.


    Trouble performing actions using NavigationView

    Pythonista
    navigationview
    5
    7
    1144
    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.
    • seriph
      seriph last edited by

      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()
      
      cvp 2 Replies Last reply Reply Quote 0
      • ccc
        ccc last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • cvp
          cvp @seriph last edited by cvp

          @seriph at least error in

                          sub_view = load_view("subView.pyui")
          

          Need's to be ui.load_view...

          1 Reply Last reply Reply Quote 0
          • cvp
            cvp @seriph last edited by 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

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

              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.

              1 Reply Last reply Reply Quote 1
              • shahan67
                shahan67 last edited by

                This post is deleted!
                1 Reply Last reply Reply Quote 0
                • Taranve73013446
                  Taranve73013446 last edited by

                  This post is deleted!
                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post
                  Powered by NodeBB Forums | Contributors