Debian Codegraph @

gi/overrides/Pango.py

raw
1 # Copyright (C) 2010 Paolo Borelli <[email protected]>
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
16 # USA
17
18 from __future__ import annotations
19
20 import typing
21
22 from ..overrides import override
23 from ..module import get_introspection_module
24
25 # Typing relies on https://github.com/pygobject/pygobject-stubs.
26 if typing.TYPE_CHECKING:
27 # Import stubs for type checking this file.
28 # FIXME: For IDE typing support, you need to copy
29 # pygobject-stubs/src/gi-stubs/repository/*.pyi to gi/repository/
30 from gi.repository import Pango
31 from typing_extensions import Self
32
33 # Type annotations cannot have `Pango.` prefix because they are copied into
34 # Pango stubs module which cannot refer to itself. Use type aliases.
35 Context = Pango.Context
36 else:
37 from gi.module import get_introspection_module
38
39 Pango = get_introspection_module("Pango")
40
41 __all__ = []
42
43
44 class FontDescription(Pango.FontDescription):
45 @staticmethod
46 def __new__(cls: type[Self], string: str | None = None) -> Self:
47 if string is not None:
48 return Pango.font_description_from_string(string) # type: ignore[return-value]
49 return Pango.FontDescription.new() # type: ignore[return-value]
50
51
52 FontDescription = override(FontDescription)
53 __all__.append("FontDescription")
54
55
56 class Layout(Pango.Layout):
57 def __new__(cls: type[Self], context: Context) -> Self:
58 return Pango.Layout.new(context) # type: ignore[return-value]
59
60 def set_markup(self, text: str, length: int = -1) -> None:
61 super().set_markup(text, length)
62
63 def set_text(self, text: str, length: int = -1) -> None:
64 super().set_text(text, length)
65
66
67 Layout = override(Layout)
68 __all__.append("Layout")