MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

SelectionPlaceholder in Packages

  • To: mathgroup at smc.vnet.net
  • Subject: [mg90236] SelectionPlaceholder in Packages
  • From: "David Park" <djmpark at comcast.net>
  • Date: Thu, 3 Jul 2008 06:10:11 -0400 (EDT)

I'm having a lot of difficulty in using a SelectionPlaceholder in a 
CreatePalette statement that is in a package. The problem is that it gets 
the package context attached to it and if I try to write a 'Global`' in 
front of it I obtain syntax errors when loading the package. Here is a 
preliminary 'in notebook' example that does what I want.  I include several 
features that are in my actual example such as the HoldFirst attribute and 
Grid construction. I also include a Global` context on the placeholder even 
though it is not necessary here. The Defer is necessary to keep from 
displaying the evaluated version of foo.

Attributes[foo] = {HoldFirst};
foo[x_] := x^2

TestPalette :=
 CreatePalette[
  Defer@Grid[{{PasteButton[foo[Global` \[SelectionPlaceholder]]]}}],
  WindowTitle -> "TestPalette",
  WindowMargins -> Automatic,
  ClosingAutoSave -> False]

TestPalette;

That all works.  Now, here is a package version. Create a TestPalette folder 
in your private Applications folder and save the notebook there under the 
name TestPackage'.

___________________________________________________________

Notebook[{

Cell[CellGroupData[{
Cell["TestPackage", "Section"],

Cell[BoxData[
 RowBox[{
 "BeginPackage", "[", "\"\<TestPalette`TestPackage`\>\"",
  "]"}]], "Input",
 InitializationCell->True],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"foo2", "::", "usage"}], "=",
   "\"\<foo2[x] is a test function.\>\""}], ";"}]], "Input",
 InitializationCell->True],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"TestPalette2", "::", "usage"}], "=",
   "\"\<TestPalette2 will launch a palette to paste the foo function.\
\>\""}], ";"}]], "Input",
 InitializationCell->True],

Cell[BoxData[
 RowBox[{"Begin", "[", "\"\<`Private`\>\"", "]"}]], "Input",
 InitializationCell->True],

Cell[BoxData[
 RowBox[{
  RowBox[{"Attributes", "[", "foo2", "]"}], "=",
  RowBox[{"{", "HoldFirst", "}"}]}]], "Input",
 InitializationCell->True],

Cell[BoxData[
 RowBox[{
  RowBox[{"foo2", "[", "x_", "]"}], ":=",
  SuperscriptBox["x", "2"]}]], "Input",
 InitializationCell->True],

Cell[BoxData[
 RowBox[{"TestPalette2", ":=", "\[IndentingNewLine]",
  RowBox[{"CreatePalette", "[",
   RowBox[{
    RowBox[{"Defer", "@",
     RowBox[{"Grid", "[",
      RowBox[{"{",
       RowBox[{"{",
        RowBox[{"Global`testsymbol", ",",
         RowBox[{"PasteButton", "[",
          RowBox[{"foo2", "[", "\[SelectionPlaceholder]", "]"}],
          "]"}]}], "}"}], "}"}], "]"}]}], ",", "\[IndentingNewLine]",

    RowBox[{"WindowTitle", "\[Rule]", "\"\<TestPalette2\>\""}], ",",
    "\[IndentingNewLine]",
    RowBox[{"WindowMargins", "\[Rule]", "Automatic"}], ",",
    "\[IndentingNewLine]",
    RowBox[{"ClosingAutoSave", "\[Rule]", "False"}]}],
   "]"}]}]], "Input",
 InitializationCell->True],

Cell[BoxData[
 RowBox[{"End", "[", "]"}]], "Input",
 InitializationCell->True],

Cell[BoxData[
 RowBox[{"EndPackage", "[", "]"}]], "Input",
 InitializationCell->True]
}, Open  ]]
},
AutoGeneratedPackage->Automatic,
WindowSize->{607, 750},
WindowMargins->{{Automatic, 191}, {Automatic, 62}},
FrontEndVersion->"6.0 for Microsoft Windows (32-bit) (May 21, 2008)",
StyleDefinitions->"Default.nb"
]

___________________________________________________________

In the TestPackage Grid I include an extra Global`testsymbol object to show 
that usually this construction works all right. Now if one loads the package 
and evaluates TestPalette2:

Needs["TestPalette`TestPackage`"]

TestPalette2

the palette is displayed but it has the private package context on the 
selection placeholder. But if I use Global`\[SelectionPlaceholder] then I 
obtain a syntax error when reading the package. I can't find any way to get 
it into the Global context.

Does anyone know how to do this? Thanks in advance.

-- 
David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/




  • Prev by Date: Re: Printing, WYSIWYG, and Window Magnification?
  • Next by Date: Re: Problem with parametric minimization
  • Previous by thread: Differing curvature measures in NonlinearRegress
  • Next by thread: Re: SelectionPlaceholder in Packages