MathGroup Archive 2010

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

Search the Archive

Re: Creating a simple state inspector for Mathematica

  • To: mathgroup at smc.vnet.net
  • Subject: [mg111919] Re: Creating a simple state inspector for Mathematica
  • From: ADL <alberto.dilullo at tiscali.it>
  • Date: Thu, 19 Aug 2010 07:20:03 -0400 (EDT)
  • References: <i45rgt$g5a$1@smc.vnet.net> <i48jk4$e71$1@smc.vnet.net> <i4d666$6m4$1@smc.vnet.net>

Based on Sjoerd's interesting solution and other comments, I made a
few variations which I found useful, so I share them with you.

The following function "Inspect" accepts a context and displays a grid
with expandable definitions, more or less suitable for copying and
pasting (some care must be taken with strings).
Moreover, in case a subcontext is present (like e.g. `Private`), which
may make internal variables less readable, this context may be
provided as a second argument so that it disappears as a prefix from
the definitions.

The function does not contain Refresh anymore so that it allows
exploration of contexts like FE`.

Perhaps, experts about Dynamic interaction, may actually do better.

ADL

ClearAll[Inspect];

Inspect[context_String, subcontext:(_String):""]:=
Module[{cont,temp},
  Print[ Style[context, FontFamily -> "Arial", Bold,FontSize->20] ];
  Dynamic [
    Grid[
      Partition[
        (
          OpenerView[
          {
            Row[{
              Style[#, FontFamily -> "Arial", Bold],
              Spacer[12],
              Button[Style["Clear", 10], ToExpression["Clear[" <> # <>
"]"]],
              Spacer[6],
              Button[Style["ClearAll", 10], ToExpression["ClearAll["
<> # <> "]"]]
            }],
            Framed[
              Pane[
                Dynamic[
                  BeginPackage[context];
                  If[subcontext != "", Begin[subcontext]];
                  temp=ToString[Definition[#], OutputForm];
                  End[];
                  If[subcontext != "", End[]];
                  temp
                ],
                ImageSize ->{Scaled[1], 80},
                Scrollbars ->Automatic
              ],
              Background -> LightYellow
            ]
          }
          ] &
        ) /@
          Names[context<>"*"],
        3, 3, {1, 1}, {}
      ],
      Alignment -> {Left, Baseline},
      Background -> {Automatic, {{RGBColor[0.98996, 0.950057,
0.785382], RGBColor[1, 0.983169, 0.877287]}}},
      ItemSize -> Scaled[.333]
    ],
    ContinuousAction->False,
    SynchronousUpdating->False
  ]
]


  • Prev by Date: Re: How to make dynamic strings?
  • Next by Date: Re: NonLinearModelFit crash (restart) the mathematica (v7.0) kernel.
  • Previous by thread: Re: Creating a simple state inspector for Mathematica
  • Next by thread: Re: Creating a simple state inspector for Mathematica