Zum Inhalt

Python

Kompiliere eine CHM Hilfedatei

Hier ist eine kurze Beschreibung, wie man eine CHM-Hilfedatei mit Python und einer Batch-Datei kompiliert.

run-hhc.py
print ("*******************************")
print ("We compile a CHM help file  ...")
print ("*******************************")
# First import the 'ctypes' module. 
# 'ctypes' provides C compatible data types and allows calling functions in DLLs or shared libraries.
import ctypes  # An included library with Python install.
# ctypes.windll.user32.MessageBoxW(0, "Open CHM", "Your title", 1) # OK only
messageBox = ctypes.windll.user32.MessageBoxA
# documentation: https://msdn.microsoft.com/en-us/library/windows/desktop/ms645505(v=vs.85).aspx
# 1=OK Cancel, 2=Cancel, Retry, Ignore
returnValue = messageBox(None,"Compile Help Module (CHM) now?", "CHM and Python", 1) 

if returnValue == 1:
    print("Pressed OK")
    # How to compile a chm file in Python?
    # ---------------------------------
    import os   
    os.system("D:/_batch/run-hhc.bat")

elif returnValue == 2: 
    print("user pressed cancel button!")

Die folgende Batch-Datei wird vom Python-Skript verwendet.

run-hhc.bat
@echo off
REM -----------------------------------------
REM batch file  is located in D:\_batch
REM HH project file is located in D:\_working
REM -----------------------------------------
cd ..\_working
echo '//--- HH Compiler start --------------------------------------
"C:\Program Files (x86)\HTML Help Workshop\hhc" foobar.hhp
echo '//--- HH Compiler end   --------------------------------------
echo '//--- errorlevel -------------------------------------------
echo %errorlevel%
echo '//------------------------------------------------------------
if not %errorlevel% == 1 exit /B 1