Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
4e6be21a
Commit
4e6be21a
authored
Aug 27, 2018
by
Hamdi Sahloul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support enum arguments for Python binding
parent
f89e4e7d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
7 deletions
+10
-7
gen2.py
modules/python/src2/gen2.py
+10
-7
No files found.
modules/python/src2/gen2.py
View file @
4e6be21a
...
...
@@ -680,7 +680,7 @@ class FuncInfo(object):
defval0
=
"0"
tp1
=
tp
.
replace
(
"*"
,
"_ptr"
)
tp_candidates
=
[
a
.
tp
,
normalize_class_name
(
self
.
namespace
+
"."
+
a
.
tp
)]
if
any
(
tp
in
codegen
.
enum
_t
ypes
for
tp
in
tp_candidates
):
if
any
(
tp
in
codegen
.
enum
T
ypes
for
tp
in
tp_candidates
):
defval0
=
"static_cast<
%
s>(
%
d)"
%
(
a
.
tp
,
0
)
amapping
=
simple_argtype_mapping
.
get
(
tp
,
(
tp
,
"O"
,
defval0
))
...
...
@@ -855,7 +855,7 @@ class PythonWrapperGenerator(object):
self
.
classes
=
{}
self
.
namespaces
=
{}
self
.
consts
=
{}
self
.
enum
_t
ypes
=
[]
self
.
enum
T
ypes
=
[]
self
.
code_include
=
StringIO
()
self
.
code_types
=
StringIO
()
self
.
code_funcs
=
StringIO
()
...
...
@@ -914,8 +914,11 @@ class PythonWrapperGenerator(object):
#print(cname + ' => ' + str(py_name) + ' (value=' + value + ')')
def
add_enum
(
self
,
name
,
decl
):
enumname
=
normalize_class_name
(
name
)
self
.
enum_types
.
append
(
enumname
)
enumType
=
normalize_class_name
(
name
)
if
enumType
.
endswith
(
"<unnamed>"
):
enumType
=
None
else
:
self
.
enumTypes
.
append
(
enumType
)
const_decls
=
decl
[
3
]
for
decl
in
const_decls
:
...
...
@@ -992,10 +995,10 @@ class PythonWrapperGenerator(object):
self
.
code_ns_reg
.
write
(
'static ConstDef consts_
%
s[] = {
\n
'
%
wname
)
for
name
,
cname
in
sorted
(
ns
.
consts
.
items
()):
self
.
code_ns_reg
.
write
(
' {"
%
s",
%
s
},
\n
'
%
(
name
,
cname
))
self
.
code_ns_reg
.
write
(
' {"
%
s",
static_cast<long>(
%
s)
},
\n
'
%
(
name
,
cname
))
compat_name
=
re
.
sub
(
r"([a-z])([A-Z])"
,
r"\1_\2"
,
name
)
.
upper
()
if
name
!=
compat_name
:
self
.
code_ns_reg
.
write
(
' {"
%
s",
%
s
},
\n
'
%
(
compat_name
,
cname
))
self
.
code_ns_reg
.
write
(
' {"
%
s",
static_cast<long>(
%
s)
},
\n
'
%
(
compat_name
,
cname
))
self
.
code_ns_reg
.
write
(
' {NULL, 0}
\n
};
\n\n
'
)
def
gen_namespaces_reg
(
self
):
...
...
@@ -1040,7 +1043,7 @@ class PythonWrapperGenerator(object):
self
.
add_const
(
name
.
replace
(
"const "
,
""
)
.
strip
(),
decl
)
elif
name
.
startswith
(
"enum"
):
# enum
self
.
add_enum
(
name
.
r
eplace
(
"enum "
,
""
)
.
strip
()
,
decl
)
self
.
add_enum
(
name
.
r
split
(
" "
,
1
)[
1
]
,
decl
)
else
:
# function
self
.
add_func
(
decl
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment