What is the recommended way to set up definitions for or initialize a palette?

*To*: mathgroup at smc.vnet.net*Subject*: [mg123944] What is the recommended way to set up definitions for or initialize a palette?*From*: Szabolcs Horvát <szhorvat at gmail.com>*Date*: Sun, 1 Jan 2012 02:28:24 -0500 (EST)*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com

Dear MathGroup, Suppose we need to create a palette with several buttons. These buttons do complex tasks and need to share some functions (i.e. there's a set of custom functions that several of the buttons might call). These functions may also depend on some standard packages. Question: What is the best way to define these functions, so they can be used by the palette? I'd prefer to make the palette as self-contained as possible, and open it from the Palettes menu (i.e. it is not convenient to have the palette open as the side effect of loading a package). Some things to point out: * This must work even when the kernel * I am not completely sure if it is necessary to use fully qualified names (i.e. JLink`JavaNew instead of JavaNew) in the code if the packages that are being used are not guaranteed to be loaded when the palette is opened. * I'm interested in both one-button and multi-button palette solutions. -------------8<------------- Here's a simplified example to show what I'm doing currently (this is different code from what I have and is only for illustration). I'm sure there's a lot of room for improvement! button=Button["do it!", Module[{}, (* one-time initialization *) If[!ValueQ[myPalette`defined], Needs["GraphUtilities`"]; myPalette`defined=True; myPalette`doIt[] := Print["done!"]; ]; (* button functionaliry *) GraphUtilities`GraphPath[{1->2},1,2]; (* use package function *) myPalette`doIt[]; ] ] CreatePalette[button] -- Szabolcs Horv=E1t Mma QA site proposal: http://area51.stackexchange.com/proposals/37304