From f1a098203be8c44a52ed5d2a72982a3f634d4df6 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 2 Jan 2017 16:42:09 +0200 Subject: py: Move helpers to the pykms module Instead of forcing applications to import the helpers manually, move them to pykms by turning it into a python module. Signed-off-by: Laurent Pinchart --- py/pykms/CMakeLists.txt | 8 +++++-- py/pykms/__init__.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 py/pykms/__init__.py (limited to 'py/pykms') diff --git a/py/pykms/CMakeLists.txt b/py/pykms/CMakeLists.txt index 3e6e0e1..a671b7a 100644 --- a/py/pykms/CMakeLists.txt +++ b/py/pykms/CMakeLists.txt @@ -21,6 +21,10 @@ target_link_libraries(pykms kms++ kms++util ${LIBDRM_LIBRARIES}) # Don't add a 'lib' prefix to the shared library set_target_properties(pykms PROPERTIES PREFIX "") +set_target_properties(pykms PROPERTIES LIBRARY_OUTPUT_DIRECTORY "") -# XXX Where should pykms.so be installed? -#install(TARGETS pykms DESTINATION lib) +configure_file(__init__.py __init__.py COPYONLY) + +set(PY_DESTDIR lib/python${PYTHON_VERSION}/site-packages/pykms) +install(FILES __init__.py DESTINATION ${PY_DESTDIR}) +install(TARGETS pykms DESTINATION ${PY_DESTDIR}) diff --git a/py/pykms/__init__.py b/py/pykms/__init__.py new file mode 100644 index 0000000..d4cdc43 --- /dev/null +++ b/py/pykms/__init__.py @@ -0,0 +1,60 @@ +from .pykms import * + +# +# Common RGB colours +# + +red = RGB(255, 0, 0) +green = RGB(0, 255, 0) +blue = RGB(0, 0, 255) +yellow = RGB(255, 255, 0) +purple = RGB(255, 0, 255) +white = RGB(255, 255, 255) +cyan = RGB(0, 255, 255) + +# +# DrmObject API extensions +# + +def __obj_set_prop(self, prop, value): + if self.card.has_atomic: + areq = AtomicReq(self.card) + areq.add(self, prop, value) + if areq.commit_sync() != 0: + print("commit failed") + else: + if self.set_prop_value(prop, value) != 0: + print("setting property failed") + +def __obj_set_props(self, map): + if self.card.has_atomic: + areq = AtomicReq(self.card) + + for key, value in map.items(): + areq.add(self, key, value) + + if areq.commit_sync() != 0: + print("commit failed") + else: + for propid,propval in map.items(): + if self.set_prop_value(propid, propval) != 0: + print("setting property failed") + +DrmObject.set_prop = __obj_set_prop +DrmObject.set_props = __obj_set_props + +# +# Card API extensions +# + +def __card_disable_planes(self): + areq = AtomicReq(self) + + for p in self.planes: + areq.add(p, "FB_ID", 0) + areq.add(p, "CRTC_ID", 0) + + if areq.commit_sync() != 0: + print("disabling planes failed") + +Card.disable_planes = __card_disable_planes -- cgit v1.2.3