A (Standard) Way to Get Help on and Remove Packages

This code snippet is designed to get help on or remove a package from an experiment
As a suggestion for making this standard ... the package should follow a
few conventions as explained in CAPITAL LETTERS as DEFINED or OPTIONAL

MyPackage#Help() will show the help window for the package
MyPackage#RemoveMe() will remove the package named MyPackage

To use this, change all occurrances of the phrase "MyPackage" to the name of your package. Include your package functions in the section marked for them.

// OPTIONAL IGOR PRO INFORMATION

#pragma rtGlobals=1
#pragma IgorVersion=6.10

// DEFINED PACKAGE INFORMATION
// package name and version number
// substitute the name of your package for "MyPackage"
// also define a version number for your package

#pragma ModuleName=MyPackage
#pragma version=1.0

// OPTIONAL HIDE PARAMETER
// hides your package from the procedure windows list
// this parameter is not needed when your package is also an IndependentModule

#pragma hide=1

// DEFINED PACKAGE STRING CONSTANTS
// When you have none of these, you must still define them but set them blank
// ie Static StrConstant theProcedureFile = ""
// thePackage - name of your package
// thePackageFolder - where you store your package values
// theProcedureFile - the (main) procedure file associated with your package
// hasHelp - 0: no help provided; 1 - help file (appropriately named by package name) is provided

Static StrConstant thePackage="MyPackage"
Static StrConstant thePackageFolder="root:Packages:MyPackage"
Static StrConstant theProcedureFile = "MyPackage.ipf"
Static Constant hasHelp = 1

// OPTIONAL LANGUAGE LOCALIZATION
// Otherwise remove this and the next optional part

#define English

// OPTIONAL STRING CONSTANTS
// example shown on how to use language localization
// otherwise substitute an actual string for KillMeRequest in the RemoveMe() function

#ifdef English
Static StrConstant KillMeRequest="Do you really want to remove MyPackage?"
#endif
#ifdef Deutsch
Static StrConstant KillMeRequest="Soll MyPackage wirklich entfernt werden?"
#endif

// START DEFINED PACKAGE FUNCTIONS
// (start) put your definitions, includes, functions, macros, and other components in this section


// (end) put your definitions, includes, functions, macros, and other components in this section
// END DEFINED PACKAGE FUNCTIONS

// DEFINED HELP FUNCTION
// call with topic = "topic string" to get specific help on a particular topic string

Static Function Help([topic])
      string topic

       string HelpStr = ""

    if (!hasHelp)
               sprintf HelpStr, "NO HELP FOR PACKAGE %s!", thePackage
        DoAlert 0, HelpStr
        return 0
    endif

    if (strlen(thePackage)!=0)
                if (ParamIsDefault(topic))
                 DisplayHelpTopic/K=1 thePackage
                else
                         sprintf HelpStr, "%s[%s]" thePackage, topic
                 DisplayHelpTopic/K=1 HelpStr
                endif
    else
        DoAlert 0, "NO PACKAGE NAME FOR HELP!"
        return -1
    endif
    return 0
end

// DEFINED REMOVEME FUNCTION
// Remove Me
// quiet (optional): 0 (default) - prompt to remove; anything else - no prompt

Static Function RemoveMe([quiet])
    variable quiet
   
    if (ParamIsDefault(quiet) || (quiet == 0))
        DoAlert 1, KillMeRequest   
        if (V_flag == 2)
            return 0
        endif
    endif
       
    if (strlen(thePackageFolder)!=0)
        KillDataFolder/Z $thePackageFolder
    endif
   
    string theCmd
    if (strlen(thePackage)!=0)
        sprintf theCmd "DELETEINCLUDE \"%s\"" thePackage
        Execute/P/Z/Q theCmd
    endif
    if (strlen(theProcedureFile)!=0)
        sprintf theCmd "CloseProc/NAME=\"%s\"" theProcedureFile
        Execute/P/Z/Q theCmd
    endif
   
    return 0
end
Jeffrey,

thanks very much for this snippet!
I was about to write a standard package removal mechanism myself, but this is a great starting point.

Just two minor comments:
1) In the language part, the StrConstant construct requires a literal string, so one has to write something like:
#ifdef English
Static StrConstant KillMeRequest = "Do you really want to remove MyPackage ?"
#endif
#ifdef Deutsch
Static StrConstant KillMeRequest = "Soll MyPackage wirklich entfernt werden ?"
#endif


2) The header of function lacks the definition of the optional topic parameter, thus we need:
Static Function Help([topic])
string topic


Wolfgang Harneit
Yes, thank you. Changes in process. Also thanks for the corrections to my German.

I wonder, should this coding perhaps be formalized into a modular package??? I am using it now as an ending in all my other packages.

What do you think?

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH

Forum

Support

Gallery

Igor Pro 9

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More