Display FHUG Wiki Help (code snippet)

Description

This snippet provides a popup GUI that displays help pages from the FHUG Wiki Knowledge Base.

Requires: iuplua iupluaole luacom

Code

DisplayHelp.fh_lua
--[[
@Title:		Display FHUG Wiki Help Snippet
@Author:	Mike Tate
@LastUpdated:	Jan 2015
@Version:	1.2
@Description:	Displays FHUG Wiki help pages in a popup GUI.
]]
 
	require "iuplua"			-- To access GUI window builder
	require "iupluaole"			-- To access OLE subsystem
	require "luacom"			-- To access COM subsystem
 
	StrPlugin	= "Display FHUG Wiki"	-- Plugin title & version
	StrIssue	= " V1.0"
	StrRed		= "255 000 000"		-- Color attributes
	StrGreen	= "000 120 000"
	StrBlue		= "000 000 255"
	StrBlack	= "000 000 000"
	StrWhite	= "255 255 255"
	StrBigMargin	= "10x10"		-- Layout attributes
	StrMinMargin	= "1x1"
	StrGap		= "10"
	StrFontFace	= string.gsub(iup.GetGlobal("DEFAULTFONT"),",.*","")
	StrFontHead	= StrFontFace..", Bold -16"
	StrFontBody	= StrFontFace..",      -16"
 
	StrFHUG = "http://www.fhug.org.uk/wiki/doku.php?id="
 
-- GUI Help & Advice Dialogue --
function GUI_HelpDialogue()
 
	local function doActivateMainHelpButton()
		if BtnMainHelp then BtnMainHelp.active = "YES" end
	end
 
	-- Create the WebBrowser based on its ProgID and connect it to LuaCOM
	local	oleControl = iup.olecontrol{ "Shell.Explorer.1", designmode="NO", }
		oleControl:CreateLuaCOM()
 
	-- Create each GUI button with title and tooltip
	local btnMain  = iup.button { title="Ancestral Sources Data Entry" , tip="Ancestral Sources Data Entry window" }
	local btnPath  = iup.button { title="Ancestral Sources Options" , tip="Ancestral Sources Options window" }
	local btnClose = iup.button { title="Close this Window" , tip="Close this Help and Advice window" }
 
	-- The following control is global to allow Main GUI to alter font
	HboxHelp = iup.hbox { font=StrFontBody, margin=StrMinMargin, homogeneous="YES", btnMain, btnPath, btnClose, }
 
	local strExpChild = "NO"
	local iupVersion = iup.GetGlobal("VERSION")
	if iupVersion == "3.5" then strExpChild = "YES" end	-- V3.1 for IUP 3.11.2
 
	local dialogHelp = iup.dialog { title=StrPlugin.." Help & Advice", background=StrWhite, startfocus=btnClose, rastersize="1000x700",
				iup.vbox { alignment="ACENTER", gap=StrGap, margin=StrBigMargin, expandchildren=strExpChild,
					oleControl,
					HboxHelp,
				},
				close_cb=function() doActivateMainHelpButton() end,
			}
 
	local strFHUG = StrFHUG.."plugins:help:ancestral_sources_data_entry:"
 
	-- Set other GUI control attributes
	for iupName, tblAttr in pairs( {
		-- Control= 1~fgcolor	, 2~Navigate URL		, 3~action function()
		[btnMain] = { StrBlue	, strFHUG.."ancestral_sources_data_entry", false },
		[btnPath] = { StrBlue	, strFHUG.."options"		, false },
		[btnClose]= { StrRed	, false				, function() dialogHelp:destroy() doActivateMainHelpButton() end }, -- return iup.CLOSE may also be needed before end
		} ) do
		iupName.expand	= "HORIZONTAL"
		iupName.size	= "x10"
		iupName.fgcolor	= tblAttr[1]
		if tblAttr[2] then iupName.action = function() oleControl.com:Navigate(tblAttr[2]) end end
		if tblAttr[3] then iupName.action = tblAttr[3] end
	end
 
	dialogHelp:show()
	dialogHelp.rastersize=iup.NULL	-- Allow window to be resized
 
	oleControl.com:Navigate(strFHUG.."ancestral_sources_data_entry")
 
	if (iup.MainLoopLevel()==0) then iup.MainLoop() end
 
end -- function GUI_HelpDialogue

Usage

-- GUI Main Dialogue --
function GUI_MainDialogue()
 
	-- Create each GUI label and button with title, etc
	local	lblMessage	= iup.label	{ title="Example of FHUG Wiki Help", alignment="ACENTER", font=StrFontHead, }
		BtnMainHelp	= iup.button	{ title="Help and Advice" }
	local	btnCancel	= iup.button	{ title="Cancel Plugin" }
 
	local	vboxMain	= iup.vbox { font=StrFontBody, expandchildren="YES", alignment="ACENTER", gap=StrGap, margin=StrBigMargin,
					lblMessage, BtnMainHelp, btnCancel,
				}
 
	-- Create dialogue and turn off resize, menubox, maximize and minimize
	local	dialogMain	= iup.dialog { title=StrPlugin..StrIssue, dialogframe="YES", background=StrWhite, startfocus=btnCancel, size="QUARTERxQUARTER", vboxMain,
					close_cb=function() return iup.CLOSE end,
				}
 
	-- Set other GUI attributes for labels and buttons
	for iupName, tblAttr in pairs( {
		-- Control	= 1~fgcolor	, 2~action function()
		[lblMessage]	= { StrBlack	, false },
		[BtnMainHelp]	= { StrBlue	, function() BtnMainHelp.active="NO" GUI_HelpDialogue() end },
		[btnCancel]	= { StrRed	, function() return iup.CLOSE end },
		} ) do
		iupName.expand	= "YES"
		iupName.fgcolor	= tblAttr[1]
		if tblAttr[2] then iupName.action = tblAttr[2] end
	end
 
	dialogMain:showxy(100,100)
 
	if (iup.MainLoopLevel()==0) then iup.MainLoop() end
 
end -- function GUI_MainDialogue
 
GUI_MainDialogue()

Alternate Quick Version

Requires: iupluaweb

helpdialog.lua
function dlgHelp(sUrl,sTitle)
    local sPath = 'http://www.fhug.org.uk/wiki/?id=plugins:help:'..sUrl
    local btn_ok = iup.button { title="Close",padding = '5x5',size='50'}
    local btn_back = iup.button { title="<-",padding = '5x5',size='20',tip='Page Back'}
    local btn_forward = iup.button { title="->",padding = '5x5',size='20',tip='Page Forward'}
 
    local wb = iup.webbrowser{} 
 
    local strExpChild = 'NO'
    local iupVersion = iup.GetGlobal('VERSION')
    if iupVersion == '3.5' then strExpChild = 'YES' end  -- V3.1 for IUP 3.11.2
 
    local vbox = iup.vbox {
        wb,
        iup.hbox{
        btn_ok,btn_back,btn_forward;expandchildren = strExpChild, expand = 'YES'},
        expandchildren = strExpChild, alignment = 'ACENTER', gap = '5', margin = '5x5', expand = 'YES'
    }
    local dlg = iup.dialog{vbox;expandchildren = 'YES', title = sTitle, size = 'HALFxHALF', 
                           startfocus = btn_ok, close_cb = function() return iup.CLOSE end}
 
    function btn_ok:action(dlg)
        return iup.CLOSE
    end
    function btn_back:action(dlg)
        wb.backforward = -1
    end
    function btn_forward:action(dlg)
        wb.backforward = 1
    end
 
    dlg:show()
    wb.value = sPath
    dlg.minsize = dlg.size
    iup.MainLoop()
    dlg:destroy()
    return
end

Alternate Usage

require "iupluaweb" 
dlgHelp('index','Plugin Help & Advice')