Skip to content

Commit e64f1a4

Browse files
committed
Add the pyframebuffer Decorator API
1 parent 2bb74ff commit e64f1a4

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

pyframebuffer/__init__.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
"""
22
Core Python sources of the pyframebuffer module.
33
"""
4+
import functools
45
from pyframebuffer.color import getColorValue
56

67
import _pyfb as fb # type: ignore
78

8-
__all__ = ["openfb", "MAX_FRAMEBUFFERS"]
9+
__all__ = ["openfb", "MAX_FRAMEBUFFERS", "fbuser"]
910
MAX_FRAMEBUFFERS = fb.MAX_FRAMEBUFFERS
1011

1112

@@ -204,3 +205,26 @@ def openfb(num):
204205
@return The Framebuffer object
205206
"""
206207
return Framebuffer(fbnum=num)
208+
209+
210+
def fbuser(fn):
211+
"""
212+
Decorator to open a framebuffer via the Decorator API.
213+
214+
@param fn The function to wrap
215+
216+
@return The wrapper function
217+
"""
218+
@functools.wraps(fn)
219+
def wrapper(*args, **kwargs):
220+
argl = list(args)
221+
fbnum = argl[0]
222+
ret_val = None
223+
with openfb(fbnum) as fb_obj:
224+
argl[0] = fb_obj
225+
args = tuple(argl)
226+
ret_val = fn(*args, **kwargs)
227+
228+
return ret_val
229+
230+
return wrapper

0 commit comments

Comments
 (0)