Skip to content

Commit

Permalink
Last update to qch viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
windelbouwman committed Oct 3, 2014
1 parent b27203a commit 093dee1
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 64 deletions.
34 changes: 34 additions & 0 deletions compress_docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

echo "Collecting docs (all qt help projects)"
find build -name \*.qhp | while read line; do
echo "Adding qt help project $line"
FILENAME=$(basename $line)
QCH_FILE="docs/${FILENAME%.*}.qch"
echo "OUTPUT: $QCH_FILE"
qhelpgenerator $line -o $QCH_FILE
done

PROJ_FILE=docs.qhcp

cat > ${PROJ_FILE} << EOF
<?xml version="1.0" encoding="utf-8" ?>
<QHelpCollectionProject version="1.0">
<docFiles>
<register>
EOF

find docs -name \*.qch | while read line; do
echo "Adding qch file $line"
echo "<file>$line</file>" >> ${PROJ_FILE}
done

cat >> ${PROJ_FILE} << EOF
</register>
</docFiles>
</QHelpCollectionProject>
EOF

# TODO: adjust qhcp according to results..
qcollectiongenerator ${PROJ_FILE} -o docs/docs.qhc

rm ${PROJ_FILE}
2 changes: 1 addition & 1 deletion gen_pyserial.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ if [[ ! -f build/pyserial-2.7/documentation/build/qthelp/pySerial.qhp ]]; then
tar xzf ../src/pyserial-2.7.tar.gz

cd pyserial-2.7/documentation
sphinx-build -b qthelp . build/qthelp
sphinx-build -b qthelp -D html_theme=agogo . build/qthelp
cd ../../..
fi
35 changes: 1 addition & 34 deletions make_docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,11 @@ set +e
# $BASH $line
#done

# For test with travis:
$BASH gen_python.sh

set -e

echo "Collecting docs (all qt help projects)"
find build -name \*.qhp | while read line; do
echo "Adding qt help project $line"
FILENAME=$(basename $line)
QCH_FILE="docs/${FILENAME%.*}.qch"
echo "OUTPUT: $QCH_FILE"
qhelpgenerator $line -o $QCH_FILE
done

PROJ_FILE=docs.qhcp

cat > ${PROJ_FILE} << EOF
<?xml version="1.0" encoding="utf-8" ?>
<QHelpCollectionProject version="1.0">
<docFiles>
<register>
EOF

find docs -name \*.qch | while read line; do
echo "Adding qch file $line"
echo "<file>$line</file>" >> ${PROJ_FILE}
done

cat >> ${PROJ_FILE} << EOF
</register>
</docFiles>
</QHelpCollectionProject>
EOF

# TODO: adjust qhcp according to results..
qcollectiongenerator ${PROJ_FILE} -o docs/docs.qhc

rm ${PROJ_FILE}
source compress_docs.sh

zip -r docs.zip docs

66 changes: 37 additions & 29 deletions qchviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
Display the specified qch file in qt help engine.
"""

from pyzolib.qt import QtCore, QtGui, QtHelp
from PyQt4 import QtCore, QtGui, QtHelp
import argparse
import glob


class HelpBrowser(QtGui.QTextBrowser):
""" Override textbrowser to implement load resource """
def __init__(self, engine):
super().__init__()
QtGui.QTextBrowser.__init__(self)
self._engine = engine

def loadResource(self, typ, url):
Expand All @@ -27,59 +28,66 @@ def loadResource(self, typ, url):


class QchViewer(QtGui.QWidget):
"""
Show help contents and browse qt help files.
"""
""" Show help contents and browse qt help files. """
def __init__(self, parent=None, collection_filename='qch_viewer_docs.qhc'):
"""
Initializes an assistance instance.
When collection_file is none, it is determined from the
appDataDir.
"""
super().__init__(parent)
QtGui.QWidget.__init__(self, parent)
self.setWindowTitle('QchViewer')
self._engine = QtHelp.QHelpEngine(collection_filename)

# The main players:
self._content = self._engine.contentWidget()
self._helpBrowser = HelpBrowser(self._engine)

self.content_model = self._engine.contentModel()
self.splitter = QtGui.QSplitter(self)
self.splitter.addWidget(self._content)
self.splitter.addWidget(self._helpBrowser)

layout = QtGui.QVBoxLayout(self)
layout.addWidget(self.splitter)

# Connect clicks:
self._content.linkActivated.connect(self._helpBrowser.setSource)

self.content_model = self._engine.contentModel()
self.content_model.contentsCreated.connect(self.select_first)

# Important, call setup data to load the files:
self._engine.setupData()

def select_first(self):
# Select first entry:
idx = self.content_model.index(0, 0)
selection_model = self._content.selectionModel()
selection_model.select(idx, QtGui.QItemSelectionModel.Select)
self._content.activated.emit(idx)

def add_doc(self, doc_file):
self._engine.registerDocumentation(doc_file)
if not self.content_model.isCreatingContents():
self._engine.registerDocumentation(doc_file)

def screenshot_all(self):
""" Take screenshot of all content and quit """
for row in range(self.content_model.rowCount()):
print('Taking shot')
idx = self.content_model.index(row, 0)
self._content.activated.emit(idx)
pm = QtGui.QPixmap(self.size())
self.render(pm)
pm.save('screen_{}.png'.format(row))


if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--doc_file')
parser.add_argument('qch_file', nargs="*", help="Document file to add to the collection")
parser.add_argument('-s', action='store_true', help="Take screenshots and quit")
parser.add_argument('--qhc', help="Use this qhc file as collection file.")
args = parser.parse_args()
app = QtGui.QApplication([])
view = QchViewer()

# Construct viewer:
if args.qhc:
view = QchViewer(collection_filename=args.qhc)
else:
view = QchViewer()

view.show()
view.resize(1024, 768)
view.splitter.setSizes([200, 800])
if args.doc_file:
view.add_doc(args.doc_file)
app.exec()
def on_complete():
view.content_model.contentsCreated.disconnect(on_complete)
for qch_file in args.qch_file:
view.add_doc(qch_file)
if args.s:
view.screenshot_all()
view.close()
view.content_model.contentsCreated.connect(on_complete)
app.exec_()
9 changes: 9 additions & 0 deletions shoot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

Xvfb :1 &

export DISPLAY=:1

python qchviewer.py -s --qhc docs/docs.qhc

killall Xvfb

0 comments on commit 093dee1

Please sign in to comment.