Skip to content

Commit a940e98

Browse files
author
Leandro Inocencio
committed
We cannot inspect the buildin functions, but we can wrap them.
1 parent 176fb59 commit a940e98

File tree

3 files changed

+54
-12
lines changed

3 files changed

+54
-12
lines changed

example_nodes/math_node.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
11
#!/usr/bin/python
22
# -*- coding: utf-8 -*-
3-
import math
3+
import example_nodes.wrappers.math as math
44
import inspect
55
from functools import partial
6-
7-
# add basic math functions to math library
8-
math.add = lambda x, y: x + y
9-
math.sub = lambda x, y: x - y
10-
math.mul = lambda x, y: x * y
11-
math.div = lambda x, y: x / y
12-
13-
# Transform float to functions
14-
for constant in ['pi', 'e', 'tau', 'inf', 'nan']:
15-
setattr(math, constant, partial(lambda x: x, getattr(math, constant)))
16-
176
from NodeGraphQt import BaseNode
187

198

example_nodes/wrappers/__init__.py

Whitespace-only changes.

example_nodes/wrappers/math.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from math import *
2+
3+
_pi = pi
4+
_e = e
5+
_tau = tau
6+
_inf = inf
7+
_nan = nan
8+
9+
# add contants as functions
10+
11+
12+
def pi():
13+
print('pi', _pi)
14+
return _pi
15+
16+
17+
def e():
18+
print('e', _e)
19+
return _e
20+
21+
22+
def tau():
23+
print('tau', _tau)
24+
return _tau
25+
26+
27+
def inf():
28+
print('inf', _inf)
29+
return _inf
30+
31+
32+
def nan():
33+
print('nan', _nan)
34+
return _nan
35+
36+
37+
# add basic math functions to math library
38+
39+
40+
def add(x, y):
41+
return x + y
42+
43+
44+
def sub(x, y):
45+
return x - y
46+
47+
48+
def mul(x, y):
49+
return x * y
50+
51+
52+
def div(x, y):
53+
return x / y

0 commit comments

Comments
 (0)