Services & Resources / Wolfram Forums / MathGroup Archive
-----

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: [mg111853] Re: Creating a simple state inspector for Mathematica
  • From: "Sjoerd C. de Vries" <sjoerd.c.devries at gmail.com>
  • Date: Sun, 15 Aug 2010 07:38:44 -0400 (EDT)
  • References: <i45rgt$g5a$1@smc.vnet.net>

Hi Jason,

Nice idea and programming. It is always surprising how succinct a
reasonable complex idea can be programmed in Mathematica.

I changed the code a bit and it seems to work now, but I have not done
deep debugging.

My changes:

1. Ariel ==> Arial
2. I remove the symbol in the inspector context as well if it is
removed from the Global context. If you don't do that the line (#1 =
#2) &[Symbol["inspector`" <> #1], False] part yields False=False
(i.e., Set, not Equal) when you re-create a variable you have Removed
before. This happens because the evaluation cycle of Mathematica first
replaces the Symbol part with the corresponding variable and then with
its value.

The code:

Dynamic@Refresh[
  Grid[Partition[(OpenerView[{Row[{Style[#, FontFamily -> "Arial"],
           Spacer[6],
           Button[Style["Clear", 10],
            ToExpression["Clear[" <> # <> "]"],
            Appearance -> "Palette"], Spacer[6],
           Button[Style["Remove", 10],
            ToExpression[
             "Remove[" <> # <> "," <> "inspector`" <> # <> "]"],
            Appearance -> "Palette"]}
          ],
         Framed[Dynamic[Symbol[#]], ImageSize -> Scaled[1],
          Background -> White]
         },
        ToExpression["Dynamic[inspector`" <> # <> "]"]] &) /@
     Names["Global`*"],
    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]],
  UpdateInterval -> 1]

(*Whenever a new symbol is created in the Global` context,create a \
shadow symbol in the inspector` context to track whether or not the \
value of the symbol is shown.*)
$NewSymbol = (If[#2 == "Global`", (#1 = #2) &[
      Symbol["inspector`" <> #1], False]] &);

Cheers -- Sjoerd

On Aug 14, 12:35 pm, "J. McKenzie Alexander" <ja... at lse.ac.uk> wrote:
> Hi,
>
> I'm trying to create a simple "state inspector" for Mathematica. Ideally,
> I'd like to have a dynamically updated list of all the symbols in Global`=
,
>  with the option of displaying their values, and the ability to Clear o=
r Remove symbols by clicking on a button. Now, I've managed to put together=
 something which *almost* does what I want, but it has a slight bug. What's=
 the bug? You can Clear a symbol by clicking on the button named "Clear", b=
ut clicking on the button named "Remove" generates an error. I don't unders=
tand why.
>
> Here's the code:
>
> (*
> The following creates a 3-column Grid of OpenerViews. The
> first entry in the OpenerView is the name of the symbol. If the disclosur=
e
> triangle of the OpenerView is toggled, it shows the current value of that
> symbol (using Dynamic). If you read the code closely, you will see that
> the state of the OpenerView for symbol X - either True or False - is stor=
ed
> in a symbol named inspector`X. This is done so that the value of the symb=
ol
> is consistently shown or hidden as the Grid is redrawn (which happens
> whenever new symbols are added or removed from the Global context).
> *)
> Dynamic@Refresh[
>   Grid[
>    Partition[
>     (OpenerView[
>         {
>          Row[{
>            Style[#, FontFamily -> "Ariel"],
>            Spacer[6],          
>            Button[Style["Clear", 10],
>             ToExpression["Clear[" <> # <> "]"],
>             Appearance -> "Palette"],
>            Spacer[6],          
>            Button[Style["Remove", 10],
>             ToExpression["Remove[" <> # <> "]"],
>             Appearance -> "Palette"]
>            }],
>          Framed[Dynamic[Symbol[#]], ImageSize -> Scaled[1],
>           Background -> White]
>          }, ToExpression["Dynamic[inspector`" <> # <> "]"]
>         ] &) /@ Names["Global`*"], 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]
>    ],
>   UpdateInterval -> 1
>   ]
>
> (*
> Whenever a new symbol is created in the Global` context, create
> a shadow symbol in the inspector` context to track whether
> or not the value of the symbol is shown.
> *)
> $NewSymbol = (If[#2 == "Global`",
>      (#1 = #2) &[Symbol["inspector`" <> #1], False]
>      ] &);
>
> Any help would be greatly appreciated!
>
> I know the above code is probably horribly inefficient and might not scal=
e well if a lot of symbols are present. But it does seem to work pretty wel=
l so far. I was pleased to note that if a symbol contains a Graphics object=
, the OpenerView correctly displays the graphic. And if a symbol has a 3D g=
raphics object, you can rotate the graphic inside the toggled OpenerView!
>
> Cheers,
>
> Jason
>
> --
> Dr J. McKenzie Alexander
> Department of Philosophy, Logic and Scientific Method
> London School of Economics and Political Science
> Houghton Street, London WC2A 2AE
>
> Please access the attached hyperlink for an important electronic communic=
ations disclaimer:http://www.lse.ac.uk/collections/planningAndCorporatePoli=
cy/legalandC...



  • Prev by Date: Re: A new graphic user interface
  • Next by Date: Re: Clearing RAM Memory during evaluation
  • Previous by thread: Re: Creating a simple state inspector for Mathematica
  • Next by thread: Re: Creating a simple state inspector for Mathematica