MathGroup Archive 2011

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

Search the Archive

Re: Execute on notebook creation

  • To: mathgroup at smc.vnet.net
  • Subject: [mg117265] Re: Execute on notebook creation
  • From: Achilleas Lazarides <achilleas.lazarides at gmx.com>
  • Date: Sun, 13 Mar 2011 05:26:53 -0500 (EST)

OK, thanks for the reply. I'll probably stick with creating new 
documents from my palette, more or less as you suggest.

On 11 Mar 2011, at 19:20, Jason Ledbetter wrote:

> I was working on a project that needed something similar to what you 
> have
> asked.
>
> There isn't a method to automatically execute code when a notebook is
> created. Apparently it's a security feature.
>
> Options that are ~= close:
>
> A)
>
> 1) Create a notebook with a defined InitializationCell that will add 
> the
> docked cells to the evaluation notebook.
> 2) Save that notebook to disk.
> 3) Open that notebook
> 4) Click "yes" to the popup(!!) that asks about evaluating
> InitializationCells.
>
> B)
>
> 1) Write a function called "newNotebook[]" (or whatever)
> that programmatically, creates a notebook using CreateDocument[] and
> NotebookWrite[] with a docked cell then SelectionMoves[] past the 
> docked
> cell into the normal notebook (SelectionMove+dockedCells are ~= broken 
> in
> Mathematica 7, works in Mathematica 8).
> 2) Load the .m with newNotebook[] defined in your init.m.
> 3) run newNotebook[] any time you want a new notebook with the docked 
> cell
> instead of file->new->notebook.
>
> That code would look something like this: (this is a skeleton from 
> some test
> work I was doing so you'll have to clean it up but it should run as 
> is)
>
> --snip--
>
> foo[] := foo[Unique[foo]];
> foo[fooID_] := Module[
> {
> f = fooID
> },
>
> f@"doc" = CreateDocument[];
> SetSelectedNotebook[f@"doc"];
>
> dockConfig =
> Panel@Row[
>   {
>    Text["This is my ID:"],
>    Dynamic[f],
>    Text["Value: "],
>    Dynamic[f@"value"]
>    }
>   ];
>
> SetOptions[f@"doc",
> DockedCells -> Cell[BoxData@ToBoxes@dockConfig, Background ->
> LightGray]];
> SelectionMove[f@"doc", After, Notebook];
> NotebookWrite[f@"doc",
> Cell@BoxData@ToBoxes@Slider[Dynamic[f@"value"], {{"one", "two",
> "three"}}]];
> ]
>
> --snip--
>
> There may be other options, but if one wants to futz with specific 
> contexts
> and such, DockedCells begins to be much more of a pain than a 
> feature...
>
> Hope this helps.
>
> -jbl
>


  • Prev by Date: Re: Create a notebook with both input and output cells
  • Next by Date: Re: Contour line colors from z coord of a 3D plot
  • Previous by thread: Re: Execute on notebook creation
  • Next by thread: Set persistent default notebook window size and location