code: def cmp_mode(b, a):
          
          tmp = cmp(Q.CGDisplayModeIsUsableForDesktopGUI(a),
                    Q.CGDisplayModeIsUsableForDesktopGUI(b))
          if tmp != 0: return tmp
          tmp = cmp(our_IsUsableForDesktopGUI(a),
                    our_IsUsableForDesktopGUI(b))
          if tmp != 0: return tmp
          tmp = cmp(guess_bitDepth(Q.CGDisplayModeCopyPixelEncoding(a)),
                    guess_bitDepth(Q.CGDisplayModeCopyPixelEncoding(b)))
          if tmp != 0: return tmp
          tmp = cmp(Q.CGDisplayModeGetHeight(a) * Q.CGDisplayModeGetWidth(a),
                    Q.CGDisplayModeGetHeight(b) * Q.CGDisplayModeGetWidth(b))
          if tmp != 0: return tmp
          tmp = cmp(Q.CGDisplayModeGetHeight(a),
                    Q.CGDisplayModeGetHeight(b))
          if tmp != 0: return tmp
          tmp = cmp(Q.CGDisplayModeGetWidth(a),
                    Q.CGDisplayModeGetWidth(b))
          if tmp != 0: return tmp
          return cmp(Q.CGDisplayModeGetRefreshRate(a),
                     Q.CGDisplayModeGetRefreshRate(b))
docs: A comparison function for displaymodes