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

MathGroup Archive 2009

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

Search the Archive

Re: Question on Dynamic with "DockedCell"

  • To: mathgroup at smc.vnet.net
  • Subject: [mg104154] Re: [mg104137] Question on Dynamic with "DockedCell"
  • From: Adam Griffith <adamg at wolfram.com>
  • Date: Wed, 21 Oct 2009 06:30:27 -0400 (EDT)
  • References: <200910200854.EAA06280@smc.vnet.net> <4ADDFCBD.1080103@wolfram.com> <9e0fbc710910201324w6d190c45p5ca838c8b02fe1fd@mail.gmail.com>

Hi Jason,

Yes, the documentation on these topics is in the works for a future 
Mathematica release.

The trick here is to notice that the option DockedCells takes low-level 
cell expressions. So anything that is included must be written in the 
low-level box structure of the front end. For example, type something 
into an input cell, run it, and then choose Cell>Show Cell Expression on 
the output cell to view the low-level code.

So what I did here:
    Notebook[........ , 
DockedCells->Cell[BoxData[ToBoxes at DynamicModule[..... all code.....]], 
"DockedCell"]]

was to let the front end generate the necessary box structure for the 
DynamicModule by using ToBoxes[] since I didn't want to have to write it 
myself. For example,

In[1]:= ToBoxes[a + b^2]

Out[1]= RowBox[{"a", "+", SuperscriptBox["b", "2"]}]

Then since we are dealing with boxes, the contents are wrapped in 
BoxData[].

Hope this helps,
-Adam

Jason Ledbetter wrote:
> Hmm. That organizational structure is different than what I'm using. I 
> guess I need to comprehend the box structure of mathematica... for 
> example "BoxData" doesn't seem to be a  documented primitive (It is 
> referenced inside the Cell[] documentation as a one-liner).
>
> Is there a how-to or otherwise some documentation that describes when 
> to use BoxData vs. ToBoxes vs. whatever or is it one of those "It 
> depends and it's complicated" things?
>
> -jbl
>
> On Tue, Oct 20, 2009 at 2:09 PM, Adam Griffith <adamg at wolfram.com 
> <mailto:adamg at wolfram.com>> wrote:
>
>     I would suggest placing the code for the menus in a DynamicModule.
>
>
>     Notebook[........ ,
>     DockedCells->Cell[BoxData[ToBoxes at DynamicModule[..... all
>     code.....], "DockedCell"]]
>
>     -Adam
>
>
>     Jason Ledbetter wrote:
>
>         Folk,
>         I'm attempting to create a dynamically-appearing set of
>         choices/menus using
>         ButtonBar in a notebook window but I've been unable to get the
>         desired
>         affect to date. I've cobbled together the following code which
>         almost does
>         what I'm looking for but I could use some pointers in getting
>         the rest of
>         the way.
>
>         The goal here is for the "topMenu" items to appear when the
>         notebook is
>         first instantiated and for the "secondMenu" option to appear
>         when a
>         "topMenu" option is selected. As it stands now, I'm having to
>         start with the
>         "secondMenu" option pre-defined to a bogus value.
>
>         If I were to abstract my goal some more, I'm trying to figure
>         out how to
>         dynamically add/remove RowBox items that include ButtonBars
>         from the
>         notebook based on options that are selected.
>
>         I'm guessing that I somehow need to programmatically generate
>         the contents
>         of a Dynamically wrapped RowBox (e.g., Dynamic[RowBox[...]])
>         but I'm not
>         quite sure how to go about that just yet.
>
>         Any help is greatly appreciated...
>
>         Here's what I have thus far:
>
>         --snip--
>         Module[
>
>          {topMenu, secondMenu},
>
>          topMenu = {"option1", "option2"};
>          secondMenu = {"No option selected"};
>
>          menuChoice[choice_] := Module[{},
>            Switch[choice,
>             "option1", secondMenu = {"one", "selected"},
>             "option2", secondMenu = {"two", "selected"}, _, Print[choice]
>             ]];
>
>          CreateWindow[DockedCells -> Cell[
>             RowBox[
>              {
>               ToBoxes[
>                ButtonBar[ToString[#] :> menuChoice[#] & /@ topMenu]
>                ],
>               ToBoxes[
>                Dynamic[
>                 ButtonBar[ToString[#] :> menuChoice[#] & /@ secondMenu]
>                 ]
>                ]
>               }
>              ],
>             "DockedCell"],
>           TextAlignment -> Center
>           ]
>          ];
>
>         --snip--
>
>
>         thanks,
>
>
>         -jbl
>          
>
>


  • Prev by Date: Re: Question on Dynamic with "DockedCell"
  • Next by Date: Re: Re: How to find which variable caused the trigger in Manipulate[]
  • Previous by thread: Re: Question on Dynamic with "DockedCell"
  • Next by thread: Re: Question on Dynamic with "DockedCell"