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.


    Dynamic View Name error

    Pythonista
    3
    6
    3313
    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.
    • Omega0
      Omega0 last edited by

      I'm trying to use the page name as a sort of dynamic label, sending information to the user in a convenient way. I can get this to work using just the custom view but it doesn't seem to work when the view is being presented via the navigation view.

      Here's the code I'm testing with, any help would be appreciated:

      import ui
      
      class CustomView (ui.View):
          def __init__(self):
              ui.View.__init__(self, name = 'Test')
      
          def touch_began(self, touch):
              self.name = str(touch.location)
      
          def touch_moved(self, touch):
              self.name = str(touch.location)
      
          def touch_ended(self, touch):
              self.name = 'Test'
      
      view = CustomView()
      nav = ui.NavigationView(view)
      view.left_button_items = [ui.ButtonItem(image = ui.Image.named('ionicons-close-24'), action = lambda sender: nav.close())]
      nav.present(hide_title_bar = True)
      
      1 Reply Last reply Reply Quote 0
      • ccc
        ccc last edited by

        I found no useful clues...

        ui.did_load() is only called after ui.load_view() so it will not be called in your script.

        I did find a way to crash Pythonista but nothing of value.

        import ui
        view = ui.Label(name='hi')
        nav = ui.NavigationView(view)
        nav.present()
        nav.push_view(view)
        
        1 Reply Last reply Reply Quote 0
        • Omega0
          Omega0 last edited by

          I didn't realize that initially. I guess I just forgot to take it out after I figured it out.

          1 Reply Last reply Reply Quote 0
          • ?
            A Former User last edited by

            @ omega() It looks like the name of the View used for the navigation bar is taken from the View at time of instantiation and not updated dynamically or exposed as an attribute that you could update. I don't know if you are willing to show the title bar, if so, you can change the NavigationView's name from your functions...

            import ui
            
            class CustomView (ui.View):
                def __init__(self):
                    ui.View.__init__(self, name = 'Test')
            
                def touch_began(self, touch):
                    self.name = str(touch.location)
            
                def touch_moved(self, touch):
                    self.name = str(touch.location)
                    ###
                    self.navigation_view.name = str(touch.location)
                    ###
                    
            
                def touch_ended(self, touch):
                    self.name = 'Test'
            
            view = CustomView()
            nav = ui.NavigationView(view)
            view.left_button_items = [ui.ButtonItem(image = ui.Image.named('ionicons-close-24'), action = lambda sender: nav.close())]
            nav.present() #hide_title_bar = True)
            

            Edit: to remove global

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

              I would prefer to keep the title bar hidden (it just looks better that way), but I will use navigation view's name as a temporary solution. I was hoping for something that would force the navigation view to ask for the view's name again but I haven't seen anything like that in the documentation. Maybe this is just a bug?

              1 Reply Last reply Reply Quote 0
              • ?
                A Former User last edited by

                @Omega() By the way... cool button one liner! I like it.

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post
                Powered by NodeBB Forums | Contributors