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.


    How to detect retina display

    Pythonista
    3
    3
    2453
    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.
    • mikashkin
      mikashkin last edited by

      Hello,

      Working on the project I found that I need to detect what type of the screen have device that running my code. And made this simple detector. Probaby it is not something big, but for me this is first bites of code that uses objc bindings. Hope you will find it useful

      Grab the gist isretina.py or code

      from objc_util import *
      us = ObjCClass('UIScreen')
      if us.mainScreen().scale() == 2.0:
      	print('Retina')
      elif us.mainScreen().scale() == 3.0:
      	print('iPhone Plus')
      else:
      	print('Non retina')
      
      1 Reply Last reply Reply Quote 1
      • omz
        omz last edited by omz

        You could also use scene.get_screen_scale() for this (which is basically just a wrapper around [[UIScreen mainScreen] scale) – nothing wrong with your code, just wanted to point out that it's not necessary to delve into ObjC for this.

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

          from objc_util import ObjCClass
          scale = ObjCClass('UIScreen').mainScreen().scale()
          print({2: 'Retina', 3: 'iPhone Plus'}.get(scale, 'Non retina'))
          
          1 Reply Last reply Reply Quote 1
          • First post
            Last post
          Powered by NodeBB Forums | Contributors