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.importctypes# An included library with Python install.# ctypes.windll.user32.MessageBoxW(0, "Open CHM", "Your title", 1) # OK onlymessageBox=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, IgnorereturnValue=messageBox(None,"Compile Help Module (CHM) now?","CHM and Python",1)ifreturnValue==1:print("Pressed OK")# How to compile a chm file in Python?# ---------------------------------importosos.system("D:/_batch/run-hhc.bat")elifreturnValue==2:print("user pressed cancel button!")
Following batch file is used by the Python script.
@echo off
REM -----------------------------------------REM batch file is located in D:\_batchREM HH project file is located in D:\_workingREM -----------------------------------------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 '//------------------------------------------------------------
ifnot%errorlevel%== 1 exit /B 1