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.


    ui.dump_view() function?

    Pythonista
    2
    18
    3395
    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.
    • RocketBlaster05
      RocketBlaster05 last edited by

      I'm trying to remove a loaded ui view from the screen after a button is pressed. I assumed that ui.dumpview() would remove said view but it keeps giving me an error saying "Expected a ui.View or subclass." Am I even using this function properly? If not, is there another way of removing a loaded ui view from the scene? I have tried all different names for the ui.View I am using and it does not seem to register it.

      Thanks!

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

        @RocketBlaster05 never seen dumpview. I know dump_view but it does not remove a view.
        Did you try your_ui_view.close()?

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

          I used ui.load_view("MainMenu") with the present and such. I want to call on it to close but it says that MainMenu isnt defined. Is there somewhere else I have to define it?

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

            @RocketBlaster05 yes, use

            mm = ui.load_view('MainMenu')
            .
            .
            .
            mm.close()
            
            RocketBlaster05 1 Reply Last reply Reply Quote 0
            • RocketBlaster05
              RocketBlaster05 @cvp last edited by

              @cvp It... isn't closing it. I have it defined and there is no errors yet it refuses to close the view. I'm getting really confused right now lol. I'll keep looking at it but it just doesn't seem to want to work.

              cvp 2 Replies Last reply Reply Quote 0
              • cvp
                cvp @RocketBlaster05 last edited by

                @RocketBlaster05 could you paste your code here or, if it is big, paste a link

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

                  @RocketBlaster05 is the view presented? You can only close a presented view

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

                    @cvp

                    #all necessary imports are present already. 
                    class Menu (ui.View): #main menu setup
                       def __init__(self):
                           ui.View.__init__(self)
                           self.scene_view = scene.SceneView()
                           self.present(hide_title_bar=True)
                           self.scene_view.frame = self.bounds
                           self.add_subview(self.scene_view)
                           ui.load_view(‘MainMenu’).present(‘fullscreen’, hide_title_bar=True)
                    
                    def button_tapped_learn(Learn): #button on ui
                        LearnText() #scene for what I am trying to present
                        ui.load_view(‘LearnPage’).present(‘fullscreen’, hide_title_bar = True) #ui I want to present
                        ui.load_view(‘MainMenu’).close() #line that doesn’t work but doesn’t give me an error. Tried subbing it for mm and other nicknames.
                    
                    class LearnText (Scene):
                       def setup(self):
                           self.background_color = ‘white’
                    
                    if __name__ == ‘__main__’:
                       Menu()
                    
                    RocketBlaster05 1 Reply Last reply Reply Quote 0
                    • RocketBlaster05
                      RocketBlaster05 @RocketBlaster05 last edited by

                      @RocketBlaster05 said:

                      @cvp

                      #all necessary imports are present already. 
                      class Menu (ui.View): #main menu setup
                         def __init__(self):
                             ui.View.__init__(self)
                             self.scene_view = scene.SceneView()
                             self.present(hide_title_bar=True)
                             self.scene_view.frame = self.bounds
                             self.add_subview(self.scene_view)
                             ui.load_view(‘MainMenu’).present(‘fullscreen’, hide_title_bar=True)
                      
                      def button_tapped_learn(Learn): #button on ui
                          LearnText() #scene for what I am trying to present
                          ui.load_view(‘LearnPage’).present(‘fullscreen’, hide_title_bar = True) #ui I want to present
                          ui.loadview(‘MainMenu’).close() #line that doesn’t work but doesn’t give me an error. Tried subbing it for mm and other nicknames.
                      
                      class LearnText (Scene):
                         def setup(self):
                             self.background_color = ‘white’
                      
                      if __name__ == ‘__main__’:
                         Menu()
                      

                      And just as a heads up, all of this code works as intended except for the close function

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

                        @RocketBlaster05 you didn't pass via a variable
                        Thé ui.load_view(‘MainMenu’) that your presented is not the same object as the ui.load_view(‘MainMenu’) that you close

                               self.mm = ui.load_view(‘MainMenu’)
                               self.mm.present(‘fullscreen’, hide_title_bar=True)
                        .
                        .
                        .
                               self.mm.close()
                        
                        1 Reply Last reply Reply Quote 0
                        • cvp
                          cvp last edited by cvp

                          This should work but without the pyui files, I can't test

                          class Menu (ui.View): #main menu setup
                             def __init__(self):
                                 ui.View.__init__(self)
                                 self.scene_view = scene.SceneView()
                                 self.present(hide_title_bar=True)
                                 self.scene_view.frame = self.bounds
                                 self.add_subview(self.scene_view)
                                 self.mm = ui.load_view(‘MainMenu’)
                                 self.mm.present(‘fullscreen’, hide_title_bar=True)
                          
                          def button_tapped_learn(Learn): #button on ui
                              global m
                              LearnText() #scene for what I am trying to present
                              m.mm.close() #line that doesn’t work but doesn’t give me an error. Tried subbing it for mm and other nicknames.
                              m.mm = ui.load_view(‘LearnPage’)
                              m.mm.present(‘fullscreen’, hide_title_bar = True) #ui I want to present
                          
                          class LearnText (Scene):
                             def setup(self):
                                 self.background_color = ‘white’
                          
                          if __name__ == ‘__main__’:
                             global m
                             m = Menu()
                          
                          RocketBlaster05 1 Reply Last reply Reply Quote 0
                          • RocketBlaster05
                            RocketBlaster05 @cvp last edited by RocketBlaster05

                            @cvp yes this worked very well! It closed it out but now it says there is an animation in progress or there is a view already presented specifically with the m.mm present line

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

                              @RocketBlaster05 perhaps you could insert a time.sleep(0.2) between the first view closing and the new view presenting

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

                                @cvp I have tried the sleep function but it freezes the close animation as well. I can only assume I'd have to move the loading portion around or something. I hope I find this soon because my app will have a lot of UI in it and this is a very important part lol.

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

                                  @RocketBlaster05 could you try this

                                  def button_tapped_learn(Learn): #button on ui
                                      global m
                                      LearnText() #scene for what I am trying to present
                                      m.mm.close() 
                                      ui.delay(start_LearnPage,0.2)
                                      
                                  def start_LearnPage():
                                      global m
                                      m.mm = ui.load_view(‘LearnPage’)
                                      m.mm.present(‘fullscreen’, hide_title_bar = True) #ui I want to present
                                  
                                  RocketBlaster05 1 Reply Last reply Reply Quote 0
                                  • RocketBlaster05
                                    RocketBlaster05 @cvp last edited by

                                    @cvp Finally! This is working perfectly! However I must say that either due to my Ipad or the length of the close() animation the shortest time I can get this to consistently work is 0.55 seconds. It is not an issue and I think it will be just fine. Thank you so much!

                                    cvp 2 Replies Last reply Reply Quote 0
                                    • cvp
                                      cvp @RocketBlaster05 last edited by

                                      @RocketBlaster05 😅

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

                                        @RocketBlaster05 if you have several views with same kind of process, you could avoid additional def for each view by

                                        from   functools import partial
                                        .
                                        .
                                        .
                                        def button_tapped_learn(Learn): #button on ui
                                            global m
                                            LearnText() #scene for what I am trying to present
                                            m.mm.close() 
                                            m.mm = ui.View(name='LearnPage')
                                            ui.delay(partial(m.mm.present,'fullscreen', hide_title_bar = True),0.55)
                                        
                                        1 Reply Last reply Reply Quote 0
                                        • First post
                                          Last post
                                        Powered by NodeBB Forums | Contributors