Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1998
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1998

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

Search the Archive

Re: Button to open notebook?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg13423] Re: Button to open notebook?
  • From: "Allan Hayes" <hay at haystack.demon.cc.uk>
  • Date: Thu, 23 Jul 1998 03:33:20 -0400
  • References: <6ousdf$ji2@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Murray Eisenberg wrote in message <6ousdf$ji2 at smc.vnet.net>... (Original
message below *****************************)

Murray,
Here is how I get a hyperlink or button in notebookA (say) to open a
another notebook Buttons3 in the the same folder notebookA. - click
outside cells to get an input line - open panel Input > Create
Hyperlink - click Browser
- in browser find Buttons3.nb
- double click Buttons3.nb (or click Open) - in panel click OK
- put the text "To Buttons3" in the hyperlink

The cell expression for the cell containing the hyperlink is

Cell[TextData[ButtonBox["To Buttons3",
  ButtonData:>{"Buttons3.nb", None},
  ButtonStyle->"Hyperlink"]], "Input"]

To get a conventional button appearence, change TextData to BoxData:

Cell[BoxData[ButtonBox["To Buttons3",
  ButtonData:>{"Buttons3.nb", None},
  ButtonStyle->"Hyperlink"]], "Input"]

This will still have the hypertext style text: to avoid this:

- select the button
- use the Option inspector to insert the options ButtonFunction and
Active explicitely and set ButtonStyle -> None (or as I  have done
delete ButtonStyle from cell expression)

Cell[BoxData[
    ButtonBox[
      RowBox[{"To", " ", "Buttons3"}],
      ButtonFunction:>(FrontEndExecute[ {
          FrontEnd`NotebookLocate[ #2]}]&),
      ButtonData:>{"Buttons3.nb", None},
      Active->True]], "Input"]

There is nothing "hard wired" in any of these.

However, to open a notebook not in the same folde the ButtonData will
have to instruct how for up the directory tree to go before following
the path down to the target notebook (specified by folder names and
file name). Unless this information is appropriate for the notebooks
etc pasted into a new situation then it seems that the button will not
work ( I'm not sure if the option CharacterEncoding option is necessary
- I can delete it from my button code with apparently no effect).

Allan
-------

********************************************************************

>AIM: I want to create a button that, when clicked, opens another
>notebook in the same directory as the one containing that button.
>
>QUESTION 1: Is a hypertext button transportable across platforms and
>immune to a move of both the notebooks -- the source with the button
>and the target to be opened -- together to another directory?  I ask
>because I created such a hypertext button and its expression is:
>
>Cell[BoxData[
>    ButtonBox["Cat",
>      ButtonData:>{
>        FrontEnd`FileName[ {
>          ParentDirectory[ ], "Temp"}, "Cat.nb", CharacterEncoding ->
>"WindowsANSI"], None},
>      ButtonStyle->"Hyperlink"]], "Input"]
>
>This seems to have some hard-coding of the source notebook's current
>directory ("Temp") as well as the "WindowsANSI" character encoding.
>
>If this will be OK when I move the notebooks together on my computer, or
>transport them to another platform (Mac), then I will be happy.
>
>I will be even happier if I can have an answer to the following
>question.
>
>QUESTION 2: Trying to finesse my uncertainty as to the answer to
>Question 1, I first  tried the following.  In one cell I evaluated the
>following expression:
>
>thisnotebookdir = "FileName" /.
>NotebookInformation[EvaluationNotebook[]]/. FrontEnd`FileName[d_List,
>nam_, ___] :> ToFileName[d];
>
>Then I created a button whose expression is:
>
>Cell[BoxData[
>    ButtonBox[
>      StyleBox[
>        RowBox[{"Open", " ", "notebook"}],
>        FontSize->13,
>        FontColor->RGBColor[0, 0, 1]],
>
tonFunction:>(NotebookOpen[ 
>          StringJoin[ thisnotebookdir, "Cat.nb"]]&),
>      ButtonEvaluator->Automatic,
>      Active->True,
>      ButtonStyle->None,
>      ButtonNote->"\"Open notebook Cat\""]], "Input",
>  FontSize->24]
>
>This works just fine.  But it is not a clean solution, since it requires
>the separately defined variable thisnotebookdir.
>
>So I tried to modify the preceding button expression so as to include
>the value that variable in place:
>
>Cell[BoxData[
>    ButtonBox[
>      St
yleBox[
>        RowBox[{"Open", " ", "notebook"}],
>        FontFamily->"Helvetica",
>        FontSize->13,
>        FontColor->RGBColor[0, 0, 1]],
>
tonFunction:>(NotebookOpen[ 
>          StringJoin[ 
>            ReplaceAll[ "FileName", 
>              ReplaceAll[ 
>                NotebookInformation[ 
>                  EvaluationNotebook[ ]], FrontEnd`FileName[ d_List,
>nam_, ___] :>
>    ToFileName[ d]]], 
>            "Cat.nb"]]&),
>      ButtonEvaluator->Automatic,
>      Active->True,
>      ButtonStyle->None,
>      ButtonNote->"\"Open notebook Cat\""]], "Input",
>  FontSize->24] 
>
>But if I now click on this button, evaluation never seems to end -- the
>kernel keeps running an evaluation and the target notebook does not get
>opened.
>
>Diagnosis?  Cure?
>
>--
>  Murray Eisenberg                       Internet: 
>murray at math.umass.edu
>  Mathematics & Statistics Dept.            Voice:  413-545-2859 (W)
>  University of Massachusetts                       413-549-1020 (H)
>  Amherst, MA 01003                           Fax:  413-545-1801
>




  • Prev by Date: Re: Re: Gradient Option in FindMinimum
  • Next by Date: plotting findroot
  • Previous by thread: Button to open notebook?
  • Next by thread: Animation