@@ -26,15 +26,20 @@ def add_item(soup, new_row, is_parameter, text):
26
26
new_row .append (new_item )
27
27
return new_row , soup
28
28
29
- def add_signature_to_table (soup , tmp_row , signature , language ):
29
+ def add_signature_to_table (soup , tmp_row , signature , language , type ):
30
30
""" Add a signature to an html table"""
31
31
new_item = soup .new_tag ('td' , style = "padding-left: 0.5cm;" )
32
32
33
33
if str (signature .get ('ret' , None )) != "None" :
34
34
new_item .append (signature .get ('ret' ) + ' =' )
35
- tmp_row .append (new_item )
35
+ tmp_row .append (new_item )
36
36
37
- tmp_row , soup = add_item (soup , tmp_row , False , "cv2." + signature .get ('name' , None ) + '(' )
37
+ tmp_name = signature .get ('name' , None )
38
+ if type is not "method" :
39
+ tmp_name = "cv2." + tmp_name
40
+ else :
41
+ tmp_name = "obj." + tmp_name
42
+ tmp_row , soup = add_item (soup , tmp_row , False , tmp_name + '(' )
38
43
tmp_row , soup = add_item (soup , tmp_row , True , signature ['arg' ])
39
44
tmp_row , soup = add_item (soup , tmp_row , False , ')' )
40
45
return tmp_row , soup
@@ -55,7 +60,7 @@ def add_bolded(soup, new_row, text):
55
60
return new_row , soup
56
61
57
62
58
- def create_description (soup , language , signatures ):
63
+ def create_description (soup , language , signatures , type ):
59
64
""" Insert the new Python / Java table after the current html c++ table """
60
65
assert signatures
61
66
tmp_table = soup .new_tag ('table' )
@@ -64,7 +69,7 @@ def create_description(soup, language, signatures):
64
69
new_row , soup = new_line (soup , tmp_table , new_row )
65
70
for s in signatures :
66
71
new_row , soup = new_line (soup , tmp_table , new_row )
67
- new_row , soup = add_signature_to_table (soup , new_row , s , language )
72
+ new_row , soup = add_signature_to_table (soup , new_row , s , language , type )
68
73
new_row , soup = new_line (soup , tmp_table , new_row )
69
74
return tmp_table , soup
70
75
@@ -79,82 +84,117 @@ def get_anchor_list(anchor, soup):
79
84
a_list .append (a )
80
85
return a_list
81
86
82
- def append_python_signatures_to_table (soup , signatures , table ):
83
- description , soup = create_description (soup , "Python:" , signatures )
84
- description ['class' ] = 'python_language'
85
- old = table .next_sibling
86
- if old .name != 'table' :
87
- old = None
88
- elif not 'python_language' in old .get ('class' , []):
89
- old = None
90
- # if already existed replace with the new
91
- if old is None :
92
- table .insert_after (description )
87
+ def is_static_method (element ):
88
+ if element .name == "table" :
89
+ tmp_element = element .find ('td' , {'class' : 'memname' })
90
+ if tmp_element is not None :
91
+ if 'static' in tmp_element .text :
92
+ return True
93
93
else :
94
- old .replace_with (description )
95
- table .insert_after (description )
94
+ if element ['class' ][0 ] == 'memItemRight' :
95
+ if "static" in element .previousSibling .text :
96
+ return True
97
+ return False
98
+
99
+ def append_python_signatures_to_table (soup , signatures , table , type ):
100
+ if type == "method" :
101
+ if is_static_method (table ):
102
+ type = "static" + type
103
+ description , soup = create_description (soup , "Python:" , signatures , type )
104
+ description ['class' ] = 'python_language'
105
+ soup = insert_or_replace (soup , table , description , "table" , "python_language" )
96
106
return soup
97
107
98
108
def get_heading_text (a ):
99
109
str = ""
100
- element = a .parent .parent
110
+ element = a .parent
111
+ if element is not None :
112
+ childs = element .find_all ('a' )
113
+ # the anchor should not be an argument of a function / method
114
+ if childs .index (a ) is not 0 :
115
+ return str
116
+ element = element .parent
101
117
if element is not None :
102
118
if element .has_attr ('class' ):
103
119
tmp_class = element ["class" ][0 ]
104
120
if "memitem:" in tmp_class and "python" not in tmp_class :
105
121
str = element .parent .find ("tr" ).text
106
122
return str
107
123
108
- def append_python_signatures_to_heading (soup , signatures , element , href ):
124
+ def insert_or_replace (soup , element , description , tag_name , tag_class ):
125
+ old = element .next_sibling
126
+ if old is not None :
127
+ if old .name != tag_name :
128
+ old = None
129
+ elif not tag_class in old .get ('class' , []):
130
+ old = None
131
+ # if already existed replace with the new
132
+ if old is None :
133
+ element .insert_after (description )
134
+ else :
135
+ old .replace_with (description )
136
+ return soup
137
+
138
+ def new_heading_td (soup , s , href , type ):
139
+ if href is None :
140
+ attrs = {'class' : 'memItemLeft' , 'valign' : 'top' , 'align' : 'right' }
141
+ new_td = soup .new_tag ('td' , ** attrs )
142
+ new_td .append (str (s .get ('ret' , None )))
143
+ else :
144
+ attrs = {'class' : 'memItemRight' , 'valign' : 'bottom' }
145
+ new_td = soup .new_tag ('td' , ** attrs )
146
+
147
+ # make the function name linkable
148
+ attrs_a = {'class' : 'el' , 'href' : href }
149
+ new_a = soup .new_tag ('a' , ** attrs_a )
150
+ tmp_name = str (s .get ('name' , None ))
151
+ if type is not "method" :
152
+ tmp_name = "cv2." + tmp_name
153
+ else :
154
+ tmp_name = "obj." + tmp_name
155
+ new_a .append (tmp_name )
156
+ new_td .append (new_a )
157
+
158
+ new_td .append ("(" + s ['arg' ] + ")" )
159
+ return soup , new_td
160
+
161
+ def append_python_signatures_to_heading (soup , signatures , element , href , type ):
162
+ if type == "method" :
163
+ if is_static_method (element ):
164
+ type = "static" + type
109
165
for s in signatures :
110
166
attrs = {'class' : 'memitem:python' }
111
167
new_tr = soup .new_tag ('tr' , ** attrs )
112
168
113
- attrs_left = {'class' : 'memItemLeft' , 'valign' : 'top' , 'align' : 'right' }
114
- new_td_left = soup .new_tag ('td' , ** attrs_left )
115
- new_td_left .append (str (s .get ('ret' , None )))
169
+ soup , new_td_left = new_heading_td (soup , s , None , type )
116
170
new_tr .append (new_td_left )
117
171
118
- attrs_right = {'class' : 'memItemRight' , 'valign' : 'bottom' }
119
- new_td_right = soup .new_tag ('td' , ** attrs_right )
120
- attrs_a = {'class' : 'el' , 'href' : href }
121
- new_a = soup .new_tag ('a' , ** attrs_a )
122
- new_a .append ('cv2.' + str (s .get ('name' , None )))
123
- new_td_right .append (new_a )
124
- new_td_right .append ("(" + s ['arg' ] + ")" )
125
-
172
+ soup , new_td_right = new_heading_td (soup , s , href , type )
126
173
new_tr .append (new_td_right )
127
174
128
- old = element .next_sibling
129
- if old is not None :
130
- if old .name != 'tr' :
131
- old = None
132
- elif not 'memitem:python' in old .get ('class' , []):
133
- old = None
134
- # if already existed replace with the new
135
- if old is None :
136
- element .insert_after (new_tr )
137
- else :
138
- old .replace_with (new_tr )
175
+ soup = insert_or_replace (soup , element , new_tr , "tr" , "memitem:python" )
139
176
return soup
140
177
141
178
def append_python_signature (function_variants , anchor_list , soup ):
142
179
type = anchor_list [0 ].type
143
- if type == "fn" :
180
+ if type == "method" or type == " fn" :
144
181
if len (anchor_list ) == 1 :
145
182
tmp_anchor = anchor_list [0 ].anchor
146
183
a_list = get_anchor_list (tmp_anchor , soup )
147
184
for a in a_list :
148
185
if a ['href' ] == "#" + tmp_anchor :
186
+ tmp_element = a .parent
187
+ # ignore the More... link <td class = mdescRight>
188
+ if tmp_element is None or tmp_element ['class' ][0 ] == 'mdescRight' :
189
+ continue
149
190
# Function Documentation (tables)
150
191
table = a .findNext ('table' )
151
192
if table is not None :
152
- soup = append_python_signatures_to_table (soup , function_variants , table )
153
- continue
154
- str = get_heading_text (a )
155
- if "Functions" in str :
156
- soup = append_python_signatures_to_heading (soup , function_variants , a .parent , a ['href' ])
157
- print ("One more" )
193
+ soup = append_python_signatures_to_table (soup , function_variants , table , type )
194
+ else :
195
+ str = get_heading_text (a )
196
+ if "Functions" in str :
197
+ soup = append_python_signatures_to_heading (soup , function_variants , a .parent , a ['href' ], type )
158
198
return soup
159
199
160
200
def update_html (file , soup ):
0 commit comments