+class Connector:
+ def __init__(self, name=None):
+ self.name = name # connector name, e.g. "HDMI1"
+ self.edid = None # EDID string for the connector, or None if disconnected
+ self.resolutions = set() # list of Resolution objects, empty if disconnected
+ self.preferredResolution = None
+
+ def __str__(self):
+ return str(self.name)
+
+ def __repr__(self):
+ return """<Connector "%s" EDID="%s" resolutions="%s">""" % (str(self.name), str(self.edid), ", ".join(str(r) for r in self.resolutions))
+
+ def isConnected(self):
+ assert (self.edid is None) == (len(self.resolutions)==0)
+ return self.edid is not None
+
+ def addResolution(self, resolution):
+ assert isinstance(resolution, Resolution)
+ self.resolutions.add(resolution)
+
+ def appendToEdid(self, s):
+ if self.edid is None:
+ self.edid = s
+ else:
+ self.edid += s
+
+ def getPreferredResolution(self):
+ if self.preferredResolution:
+ return self.preferredResolution
+ return max(self.resolutions, key=lambda r: r.pixelCount())