Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use property() & implement Abstract Base Class PangoObject #47

Merged
merged 37 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
2a9c2f5
refactor(Layout): use `property()`
cAttte Oct 1, 2022
5da1335
refactor(Context): use `property()`
cAttte Oct 1, 2022
1d819b8
feat: create PangoObject class
cAttte Oct 1, 2022
b190915
fix(PangoObject): defaulting arguments, properties, etc.
cAttte Oct 1, 2022
52d3be5
refactor(Rectangle): use `property()` and `PangoObject`
cAttte Oct 1, 2022
56a98c3
refactor(FontDescription): use `property()` and `PangoObject`
cAttte Oct 1, 2022
c73e391
fix(init): include PangoObject
cAttte Oct 1, 2022
e5b3041
refactor(*): implement PangoObject
cAttte Oct 1, 2022
b2ea74a
fix(PangoObject): fix repr
cAttte Oct 1, 2022
f4de6a3
fix(Color): fix constructor
cAttte Oct 1, 2022
1dd9a65
refactor(PangoObject): use `@property`
cAttte Oct 1, 2022
f7c9f60
fix(*): fix references to `_init_pointer()` and `pointer()`
cAttte Oct 1, 2022
6c9859f
test(*): update tests
cAttte Oct 1, 2022
a3cb7f5
docs(PangoObject): add property Docstrings
cAttte Oct 1, 2022
a6d15b8
test(Attribute): update
cAttte Oct 1, 2022
e76282f
test(*): fix tests
cAttte Oct 1, 2022
a898cbc
fix(PangoObject): fix `__eq__` and `__init__`
cAttte Oct 1, 2022
64e72bc
Merge branch 'master' into master
cAttte Oct 2, 2022
1ec2a30
fix(AttrList): remove _EQ_METHOD not available in Pango 1.0.0
cAttte Oct 2, 2022
f10046f
fix(AttrList): overwrite `__eq__()`
cAttte Oct 2, 2022
6031587
style(*): fix linting issues
cAttte Oct 2, 2022
5091185
test(Color): fix comparison test
cAttte Oct 2, 2022
80a4a2e
fix(Color): overwrite `__copy__()`
cAttte Oct 2, 2022
e8b6fe1
docs(PangoObject): link to ABC, add PO to Low Level Functionality
cAttte Oct 2, 2022
a094c39
fix(Color): fix `copy()` method name
cAttte Oct 2, 2022
4a8433a
test(Attribute): fix string
cAttte Oct 3, 2022
de9343a
test(Attr*): fix two equality tests
cAttte Oct 5, 2022
ffdd288
fix(Color, GII): remove GC to avoid Segfault
cAttte Oct 5, 2022
5e4b1b9
docs(Color): add leifgehrmann's link comment
cAttte Oct 5, 2022
adf646e
test(Color): test `from_pointer()`
cAttte Oct 5, 2022
288b020
test(Layout): fix attribute tests
cAttte Oct 5, 2022
f70f55a
fix(Layout): terrible typo!
cAttte Oct 5, 2022
ab98f56
style(PangoObject): lint
cAttte Oct 5, 2022
77c5111
refactor(AttrList): in `__eq__()`, don't check pointers
cAttte Oct 6, 2022
5d533fb
refactor(PangoObject, AttrList): check for pointer equality first
cAttte Oct 7, 2022
85dbaa9
test(PangoObject): increase coverage
cAttte Oct 7, 2022
d80c0de
style(PangoObject): lint
cAttte Oct 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,8 @@ ________________
.. autofunction:: pangocffi.pango_version

.. autofunction:: pangocffi.pango_version_string

Pango Object
____________

.. autoclass:: PangoObject
1 change: 1 addition & 0 deletions pangocffi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def _dlopen(dl_name: str, generated_ffi, names: List[str]):
from .version import * # noqa
from .enums import * # noqa
from .convert import * # noqa
from .pango_object import PangoObject # noqa
from .font_description import FontDescription # noqa
from .rectangle import Rectangle # noqa
from .item import Item # noqa
Expand Down
73 changes: 19 additions & 54 deletions pangocffi/attr_list.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from . import ffi, pango, Attribute
from . import ffi, pango, Attribute, PangoObject


class AttrList:
class AttrList(PangoObject):
"""
The :class:`AttrList` represents a list of attributes(:class:`Attribute`)
that apply to a section of text. The attributes are, in general, allowed
Expand All @@ -13,34 +13,9 @@ class AttrList:
one paragraph of text due to internal structures.
"""

def __init__(self) -> None:
self._init_pointer(pango.pango_attr_list_new())

def _init_pointer(self, pointer: ffi.CData):
self._pointer = ffi.gc(pointer, pango.pango_attr_list_unref)

def get_pointer(self) -> ffi.CData:
"""
Returns the pointer to the AttrList
:return:
the pointer to the AttrList.
"""
return self._pointer

@classmethod
def from_pointer(cls, pointer: ffi.CData) -> "AttrList":
"""
Instantiates a :class:`AttrList` from a pointer.
:return:
the AttrList.
"""
if pointer == ffi.NULL:
raise ValueError("Null pointer")
self = object.__new__(cls)
self._pointer = pointer
return self
_INIT_METHOD = pango.pango_attr_list_new
_GC_METHOD = pango.pango_attr_list_unref
_COPY_METHOD = pango.pango_attr_list_copy

def _ref(self) -> None:
"""
Expand All @@ -56,18 +31,6 @@ def _unref(self) -> None:
"""
pango.pango_attr_list_unref(self._pointer)

def copy(self) -> "AttrList":
"""
Copy :class:`AttrList` and return an identical new.
"""
return AttrList.from_pointer(pango.pango_attr_list_copy(self._pointer))

def __copy__(self) -> "AttrList":
return self.copy()

def __deepcopy__(self, memo) -> "AttrList":
return self.copy()

def insert(self, attr: Attribute) -> None:
"""
Insert the given attribute into the PangoAttrList. It will be inserted
Expand All @@ -80,7 +43,7 @@ def insert(self, attr: Attribute) -> None:
"""
assert isinstance(attr, Attribute), "attr isn't a Attribute"
self._ref()
pango.pango_attr_list_insert(self._pointer, attr.get_pointer())
pango.pango_attr_list_insert(self._pointer, attr.pointer)

def insert_before(self, attr: Attribute) -> None:
"""
Expand All @@ -94,7 +57,7 @@ def insert_before(self, attr: Attribute) -> None:
"""
assert isinstance(attr, Attribute), "attr isn't a Attribute"
self._ref()
pango.pango_attr_list_insert_before(self._pointer, attr.get_pointer())
pango.pango_attr_list_insert_before(self._pointer, attr.pointer)

def change(self, attr: Attribute) -> None:
"""
Expand All @@ -115,7 +78,7 @@ def change(self, attr: Attribute) -> None:
"""
assert isinstance(attr, Attribute), "attr isn't a Attribute"
self._ref()
pango.pango_attr_list_change(self._pointer, attr.get_pointer())
pango.pango_attr_list_change(self._pointer, attr.pointer)

def splice(self, attr_list: "AttrList", pos: int, length: int):
"""
Expand Down Expand Up @@ -156,14 +119,16 @@ def splice(self, attr_list: "AttrList", pos: int, length: int):
length,
)

def __eq__(self, other: "AttrList") -> bool:
if isinstance(other, AttrList):
return bool(
pango.pango_attr_list_equal(
self.get_pointer(),
other.get_pointer(),
)
)
raise NotImplementedError
# avoid _EQ_METHOD since pango_attr_list_equal is a newer method
def __eq__(self, other) -> bool:
if isinstance(other, PangoObject):
if self.pointer == other.pointer:
return True
else:
return bool(pango.pango_attr_list_equal(
self.pointer, other.pointer
))

return False

# TODO: pango_attr_list_filter ()
Loading