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.


    Separate portrait and landscape views

    Pythonista
    2
    4
    1593
    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.
    • Dog2puppy
      Dog2puppy last edited by

      Hi. I recently started using Pythonista and was wondering if it’s possible to have separate views for portrait and landscape and to switch between them dynamically on the fly.

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

        @Dog2puppy Hello, welcome here.

        As usual, I'm not sure I correctly understand. Is this what you want?

        import ui
        
        class MyView(ui.View):
        	
        	def __init__(self):
        		self.background_color = 'white'
        		
        		vp = ui.View(name='portrait')
        		vp.flex = 'WH'
        		vp.border_width = 4
        		vp.border_color = 'red'
        		self.add_subview(vp)
        		vp.add_subview(ui.Label(frame=(10,10,100,32),text = vp.name))
        		
        		vl = ui.View(name='landscape')
        		vl.flex = 'WH'
        		vl.frame = self.bounds
        		vl.border_width = 4
        		vl.border_color = 'blue'
        		self.add_subview(vl)
        		vl.add_subview(ui.Label(frame=(10,10,100,32),text = vl.name))
        		
        	def layout(self):
        		self['portrait'].hidden  = self.width > self.height
        		self['landscape'].hidden = self.width < self.height
        		
        vp = MyView()
        vp.present()
        
        Dog2puppy 1 Reply Last reply Reply Quote 1
        • Dog2puppy
          Dog2puppy @cvp last edited by

          @cvp That does what I needed. Thanks! Also happy Easter if you celebrate it.

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

            @Dog2puppy Thanks, same for you

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