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.


    Get current screen or orientation width?

    Pythonista
    5
    8
    5745
    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.
    • JonB
      JonB last edited by

      In the new ui module, is there a way to get screen width?
      Or, to change popover location to a different corner? For instance, by default popover goes to top right... How would I go about moving it to the bottom right, and have it stay there across orientation changes?

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

        Can't you just get the width by using root_view.width?

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

          If I could find such a root_view, then yes. Superview() on a view returns nothing. I couldn't find anything in the ui module that looked like screen width

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

            It's not really possible, I'm afraid. You can't change the location of a popover after it's been presented, and there's no good way to determine the current device orientation (and ui.get_screen_size is orientation-independent, so that won't help).

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

              Sheesh, not sure how I missed ui.get_screen_size ... that's what I was looking for. Thanks!

              Actually, get_keyboard_frame changes with orientation, so can be used to determine orientation. I was trying to put a pop up near they console entry, so that'll work perfect.

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

                For what it's worth:

                ui.WebView().eval_js('window.orientation')
                

                Returns the orientation (0,90,180, 270), so is an easy way to get orientation!

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

                  What am I doing wrong?

                  import ui
                  print('\nRotate your device to see the various orientations.')
                  old_orientation = None
                  while True:
                      new_orientation = ui.WebView().eval_js('window.orientation')
                      if old_orientation != new_orientation:
                          print('Screen orientation is {}.'.format(new_orientation))
                          old_orientation = new_orientation
                  
                  1 Reply Last reply Reply Quote 0
                  • ?
                    A Former User last edited by

                    @ccc I think you need...

                    import ui
                    print('\nRotate your device to see the various orientations.')
                    
                    v=ui.WebView()
                    v.hidden = True
                    v.present('panel')
                    
                    old_orientation = None
                    while True:
                    	new_orientation = v.eval_js('window.orientation')
                    	if old_orientation != new_orientation:
                    		print('Screen orientation is {}.'.format(new_orientation))
                    		old_orientation = new_orientation
                    

                    Note: it gives -90 not 270 (I'll update the code I posted for JonB in the Unsupported File Type thread)

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