Commit d63915e5 authored by Shubham  .'s avatar Shubham .
Browse files

Add documentation help files for NumPy

parent c5c3f937
### Steps to generate `qhp` and `qhcp`
Copy the file named `qthelp_generator.py` to the location where the `NumPy` HTML files exists. Then simply run the command `python qthelp_generator.py`. This script does the task of extracting the keywords from `Numpy_v1.19/genindex.html` and generation of QtHelp files named `qhp` and `qhcp`.
NOTE: Copy the script named `qthelp_generator.py` inside the directory `Numpy_v1.19/`. Official python documentation can be downloaded from https://numpy.org/doc/.
### Creation of `qhc` and `qch`
Use the following command to generate the above said files.
qhelpgenerator help.qhcp -o help.qhc
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
# ---
# Copyright (C) 2020 Shubham <aryan100jangid@gmail.com>
#
# Script to parse index and generate a txt file containing all the keywords
# and then generate QtHelp files using the keywords generated
import os
import re
from bs4 import BeautifulSoup
# QtHelp files
qhp = open('./help.qhp', 'w')
qhcp = open('./help.qhcp', 'w')
index = open("genindex.html", "r")
#######################################
#code for generation of QtHelp files##
######################################
# populate qhp file with headers and table of contents
qhp.writelines("""<?xml version="1.0" encoding="UTF-8"?>
<QtHelpProject version="1.0">
<namespace>org.kde.numpy.1.19</namespace>
<virtualFolder>doc</virtualFolder>
<customFilter name="NumPy">
<filterAttribute>NumPy Documentation</filterAttribute>
<filterAttribute>1.19</filterAttribute>
</customFilter>
<filterSection>
<toc>
<section title="NumPy v1.19 Manual" ref="index.html">
<section title="For users:" ref="index.html">
<section title="Setting Up" ref="user/setting-up.html"></section>
<section title="Quickstart Tutorial" ref="user/quickstart.html"></section>
<section title="Absolute Beginners Tutorial" ref="user/absolute_beginners.html"></section>
<section title="Tutorials" ref="user/tutorials_index.html"></section>
<section title="How Tos" ref="user/howtos_index.html"></section>
<section title="NumPy API Reference" ref="reference/index.html"></section>
<section title="Explanations" ref="user/explanations_index.html"></section>
<section title="F2Py Guide" ref="f2py/index.html"></section>
<section title="Glossary" ref="glossary.html"></section>
</section>
</section>
</toc>\n
<keywords>""")
# code to write keywords to qhp file
html = index.read()
soup = BeautifulSoup(html, features='html.parser')
for i in soup.find_all('a'):
# replace the characters which produces error while qhcp file
keyword = i.text.replace("<", "").replace("&", "")
keyword = re.sub(r" ?\([^)]+\)", "", keyword)
link = i['href']
if keyword != "":
line = '<keyword name = "{}" ref = "{}"/>\n'.format(keyword, link)
qhp.write(line)
# write the tail
qhp.writelines("""</keywords>
<files>
<file>./*</file>
<file>_static/*</file>
<file>_static/img/*</file>
<file>_images/*</file>
<file>_images/math/*</file>
<file>_sources/*</file>
<file>dev/*</file>
<file>dev/conducct/*</file>
<file>dev/gitwash/*</file>
<file>dev/gitwash/governance/*</file>
<file>docs/*</file>
<file>f2py/*</file>
<file>reference/*</file>
<file>reference/c-api/*</file>
<file>reference/dist-utils/*</file>
<file>reference/generated/*</file>
<file>reference/random/*</file>
<file>release/*</file>
<file>user/*</file>
<file>user/plots/*</file>
</files>
</filterSection>
</QtHelpProject> """)
# populate qhcp file
qhcp.writelines("""<?xml version="1.0" encoding="utf-8" ?>
<QHelpCollectionProject version="1.0">
<docFiles>
<generate>
<file>
<input>help.qhp</input>
<output>help.qch</output>
</file>
</generate>
<register>
<file>help.qch</file>
</register>
</docFiles>
</QHelpCollectionProject>""")
##############################################################
#qhp, qhcp input files are generate, now generate output files
#############################################################
stream = os.popen('qhelpgenerator help.qhcp -o help.qhc')
qhp.close()
qhcp.close()
index.close()
add_subdirectory(Python_v3.8.4)
add_subdirectory(NumPy_v1.19)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME}/documentation/Python PATTERN "CMakeLists.txt" EXCLUDE)
......@@ -53,7 +53,7 @@ DocumentationPanelWidget::DocumentationPanelWidget(QWidget* parent) : QWidget(pa
{
// Maintain a map of backend -> doc files
m_helpFiles.insert(QLatin1String("Maxima"), {QLatin1String("Maxima_v5.42"), QLatin1String("Maxima_v5.44")});
m_helpFiles.insert(QLatin1String("Python"), {QLatin1String("Python_v3.8.4")});
m_helpFiles.insert(QLatin1String("Python"), {QLatin1String("Python_v3.8.4"), QLatin1String("NumPy_v1.19")});
m_helpFiles.insert(QLatin1String("Octave"), {QLatin1String("Octave_v5.2.0")});
m_textBrowser = new QWebEngineView(this);
......@@ -334,6 +334,19 @@ void DocumentationPanelWidget::updateBackend(const QString& newBackend, const QS
void DocumentationPanelWidget::updateDocumentation()
{
// First Unregister any previously registered documentation and then proceed
/*if(!m_engine->registeredDocumentations().isEmpty())
{
for(const QString& fileName : m_engine->registeredDocumentations())
{
const QString& fileNamespace = QHelpEngineCore::namespaceName(fileName);
if(!fileName.isEmpty() && m_engine->registeredDocumentations().contains(fileNamespace))
{
m_engine->unregisterDocumentation(fileName);
}
}
}*/
const QString& docSelected = m_documentationSelector->currentText();
const QString& fileName = QStandardPaths::locate(QStandardPaths::AppDataLocation,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment