Skip to content

Commit 164a77e

Browse files
Cartuchoalalek
authored andcommitted
add methods
1 parent 6174f62 commit 164a77e

File tree

2 files changed

+91
-51
lines changed

2 files changed

+91
-51
lines changed

doc/tools/add_signatures.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ def __init__(self):
7171
for c in classes:
7272
c_name = c.find("./name").text
7373
name = ns_name + '::' + c_name
74-
file = c.find("./filename").text
74+
file = c.find("./filename").text
7575
#print('Class: {} => {}'.format(name, file))
7676
files_dict = doxygen_scan.scan_class_methods(c, c_name, files_dict)
7777

7878
# test
7979
for file in files_dict:
8080
soup = html_functions.load_html_file(ROOT_DIR + file)
81-
if file == "d4/d86/group__imgproc__filter.html":#"d4/d86/group__imgproc__filter.html":
81+
if file == "dd/d9e/classcv_1_1VideoWriter.html":#"d4/d86/group__imgproc__filter.html":#"d4/d86/group__imgproc__filter.html":
8282
anchor_list = files_dict[file]
8383
counter = 0
8484
anchor_tmp_list = []

doc/tools/html_functions.py

Lines changed: 89 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,20 @@ def add_item(soup, new_row, is_parameter, text):
2626
new_row.append(new_item)
2727
return new_row, soup
2828

29-
def add_signature_to_table(soup, tmp_row, signature, language):
29+
def add_signature_to_table(soup, tmp_row, signature, language, type):
3030
""" Add a signature to an html table"""
3131
new_item = soup.new_tag('td', style="padding-left: 0.5cm;")
3232

3333
if str(signature.get('ret', None)) != "None":
3434
new_item.append(signature.get('ret') + ' =')
35-
tmp_row.append(new_item)
35+
tmp_row.append(new_item)
3636

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 + '(')
3843
tmp_row, soup = add_item(soup, tmp_row, True, signature['arg'])
3944
tmp_row, soup = add_item(soup, tmp_row, False, ')')
4045
return tmp_row, soup
@@ -55,7 +60,7 @@ def add_bolded(soup, new_row, text):
5560
return new_row, soup
5661

5762

58-
def create_description(soup, language, signatures):
63+
def create_description(soup, language, signatures, type):
5964
""" Insert the new Python / Java table after the current html c++ table """
6065
assert signatures
6166
tmp_table = soup.new_tag('table')
@@ -64,7 +69,7 @@ def create_description(soup, language, signatures):
6469
new_row, soup = new_line(soup, tmp_table, new_row)
6570
for s in signatures:
6671
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)
6873
new_row, soup = new_line(soup, tmp_table, new_row)
6974
return tmp_table, soup
7075

@@ -79,82 +84,117 @@ def get_anchor_list(anchor, soup):
7984
a_list.append(a)
8085
return a_list
8186

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
9393
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")
96106
return soup
97107

98108
def get_heading_text(a):
99109
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
101117
if element is not None:
102118
if element.has_attr('class'):
103119
tmp_class = element["class"][0]
104120
if "memitem:" in tmp_class and "python" not in tmp_class:
105121
str = element.parent.find("tr").text
106122
return str
107123

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
109165
for s in signatures:
110166
attrs = {'class': 'memitem:python'}
111167
new_tr = soup.new_tag('tr', **attrs)
112168

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)
116170
new_tr.append(new_td_left)
117171

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)
126173
new_tr.append(new_td_right)
127174

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")
139176
return soup
140177

141178
def append_python_signature(function_variants, anchor_list, soup):
142179
type = anchor_list[0].type
143-
if type == "fn":
180+
if type == "method" or type == "fn":
144181
if len(anchor_list) == 1:
145182
tmp_anchor = anchor_list[0].anchor
146183
a_list = get_anchor_list(tmp_anchor, soup)
147184
for a in a_list:
148185
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
149190
# Function Documentation (tables)
150191
table = a.findNext('table')
151192
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)
158198
return soup
159199

160200
def update_html(file, soup):

0 commit comments

Comments
 (0)