def __pen_cache(self, palette: QPalette, state: QStyle.State) -> QPen: """Return a QPen from the `palette` for `state`.""" # NOTE: This method exists mostly to avoid QPen, QColor (de)allocations. key = palette.cacheKey(), int(state) & _State_Mask try: return self.__pen_lru_cache[key] except KeyError: pen = QPen(text_color_for_state(palette, state)) self.__pen_lru_cache[key] = pen return pen
def __pen_cache(self, palette: QPalette, state: QStyle.State) -> QPen: """Return a QPen from the `palette` for `state`.""" # NOTE: This method exists mostly to avoid QPen, QColor (de)allocations. key = palette.cacheKey(), int(state) & _State_Mask try: return self.__pen_lru_cache[key] except KeyError: cgroup = QPalette.Normal if state & QStyle.State_Active else QPalette.Inactive cgroup = cgroup if state & QStyle.State_Enabled else QPalette.Disabled role = QPalette.HighlightedText if state & QStyle.State_Selected else QPalette.Text pen = QPen(palette.color(cgroup, role)) self.__pen_lru_cache[key] = pen return pen