Skip to content

qtmaterialsymbols

IconicFont

Bases: QObject

Main class for managing icons.

Source code in client/ayon_ui_qt/vendor/qtmaterialsymbols/iconic_font.py
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
class IconicFont(QtCore.QObject):
    """Main class for managing icons."""

    def __init__(self):
        super().__init__()
        self._painter = CharIconPainter()
        self._icon_cache = {}

    def get_charmap(self) -> Dict[str, int]:
        return get_char_mapping()

    def get_font(self, size: int, filled: bool) -> QtGui.QFont:
        """Return a QFont corresponding to the given size."""
        if filled:
            font = QtGui.QFont(_get_font_name_filled())
        else:
            font = QtGui.QFont(_get_font_name())
        font.setPixelSize(round(size))
        return font

    def get_icon_with_options(self, options: IconOptions) -> QtGui.QIcon:
        """Return a QIcon object corresponding to the provided icon name."""
        if QtWidgets.QApplication.instance() is None:
            warnings.warn(
                "You need to have a running QApplication!"
            )
            return QtGui.QIcon()

        cache_key = options.identifier
        if cache_key in self._icon_cache:
            return self._icon_cache[cache_key]

        output = self._icon_by_painter(self._painter, options)
        self._icon_cache[cache_key] = output
        return output

    def get_icon(
        self,
        icon_name: Optional[str] = None,
        color: Optional[Union[QtGui.QColor, str]] = None,
        opacity: Optional[float] = None,
        scale_factor: Optional[float] = None,
        offset: Optional[Position] = None,
        hflip: bool = False,
        vflip: bool = False,
        rotate: int = 0,
        fill: bool = True,
        **kwargs
    ) -> QtGui.QIcon:
        """Return a QIcon object corresponding to the provided icon name."""
        if QtWidgets.QApplication.instance() is None:
            warnings.warn(
                "You need to have a running QApplication!"
            )
            return QtGui.QIcon()

        options = IconOptions.from_data(
            icon_name=icon_name,
            color=color,
            opacity=opacity,
            scale_factor=scale_factor,
            offset=offset,
            hflip=hflip,
            vflip=vflip,
            rotate=rotate,
            fill=fill,
            **kwargs
        )
        cache_key = options.identifier
        if cache_key in self._icon_cache:
            return self._icon_cache[cache_key]
        return self.get_icon_with_options(options)

    def _icon_by_painter(self, painter, options):
        """Return the icon corresponding to the given painter."""
        engine = CharIconEngine(self, painter, options)
        return QtGui.QIcon(engine)

get_font(size, filled)

Return a QFont corresponding to the given size.

Source code in client/ayon_ui_qt/vendor/qtmaterialsymbols/iconic_font.py
139
140
141
142
143
144
145
146
def get_font(self, size: int, filled: bool) -> QtGui.QFont:
    """Return a QFont corresponding to the given size."""
    if filled:
        font = QtGui.QFont(_get_font_name_filled())
    else:
        font = QtGui.QFont(_get_font_name())
    font.setPixelSize(round(size))
    return font

get_icon(icon_name=None, color=None, opacity=None, scale_factor=None, offset=None, hflip=False, vflip=False, rotate=0, fill=True, **kwargs)

Return a QIcon object corresponding to the provided icon name.

Source code in client/ayon_ui_qt/vendor/qtmaterialsymbols/iconic_font.py
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
def get_icon(
    self,
    icon_name: Optional[str] = None,
    color: Optional[Union[QtGui.QColor, str]] = None,
    opacity: Optional[float] = None,
    scale_factor: Optional[float] = None,
    offset: Optional[Position] = None,
    hflip: bool = False,
    vflip: bool = False,
    rotate: int = 0,
    fill: bool = True,
    **kwargs
) -> QtGui.QIcon:
    """Return a QIcon object corresponding to the provided icon name."""
    if QtWidgets.QApplication.instance() is None:
        warnings.warn(
            "You need to have a running QApplication!"
        )
        return QtGui.QIcon()

    options = IconOptions.from_data(
        icon_name=icon_name,
        color=color,
        opacity=opacity,
        scale_factor=scale_factor,
        offset=offset,
        hflip=hflip,
        vflip=vflip,
        rotate=rotate,
        fill=fill,
        **kwargs
    )
    cache_key = options.identifier
    if cache_key in self._icon_cache:
        return self._icon_cache[cache_key]
    return self.get_icon_with_options(options)

get_icon_with_options(options)

Return a QIcon object corresponding to the provided icon name.

Source code in client/ayon_ui_qt/vendor/qtmaterialsymbols/iconic_font.py
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
def get_icon_with_options(self, options: IconOptions) -> QtGui.QIcon:
    """Return a QIcon object corresponding to the provided icon name."""
    if QtWidgets.QApplication.instance() is None:
        warnings.warn(
            "You need to have a running QApplication!"
        )
        return QtGui.QIcon()

    cache_key = options.identifier
    if cache_key in self._icon_cache:
        return self._icon_cache[cache_key]

    output = self._icon_by_painter(self._painter, options)
    self._icon_cache[cache_key] = output
    return output