Message Boards Message Boards

How to set up custom palette and stylesheet

Posted 10 years ago

Hello, I'm trying to create a package that, for some reasons, have to stay in a folder different from the standard ones (UserBaseDirectory or BaseDirectory). The problem is that even if I create the right folders' structure (e.g. MyApplication\FrontEnd\StyleSheets and \Palettes) the application is correctly loaded by a Get (that means the path is fully recognized by the kernel operation), the palette and the stylesheet are not visible inside the Mathematica menu. As described in the tutorials (tutorial/WorkingWithStylesheets and tutorial/CreatingPalettes#1453252323) this should be possible for both Palettes and StyleSheet.

Moreover, I also added the path to my application to $FrontEnd options "PalettePath" and "StyleSheetPath", using the Option inspector. The path seems to be recognised but the front end still doesn't show my palette and stylesheet.

Any help is appreciated.

P.S. the same question is here http://mathematica.stackexchange.com/questions/63313/stylesheet-for-custom-application

This does not answer your question about adding to the palettes menu automatically through placement in a directory structure, but perhaps it can be of use. The following code adds items to the top of the Palette Menu programmatically (it is somthing I figured out some years ago for a project of mine).

ClearAll[AddToPalettesMenu];
AddToPalettesMenu[paletteData : {{_String, _String} ..}] :=

  Module[{itemList, dummyFunction, tempFunction, temp},

   SetAttributes[ FrontEnd`AddMenuCommands, HoldRest];

   MathLink`CallFrontEnd[FrontEnd`ResetMenusPacket[{Automatic}]];

   itemList =
    Item[First[#], 
       FrontEnd`KernelExecute[{ 
         EvaluatePacket[dummyFunction@ Last[#]]}], 
       FrontEnd`MenuEvaluator -> Automatic] & /@ paletteData;

   temp =
    Function[x,
       tempFunction[{
          FrontEnd`AddMenuCommands["MenuListPalettesMenu", 
          x]}
        ]][itemList] /. dummyFunction -> ToExpression;

   temp /. tempFunction -> FrontEndExecute

   ];

To use this function, you supply a list of pairs of strings. In each pair, the first item is the title of the menu item that will appear. The second item is a function that will be executed when that menu item is chosen. When the function is executed it clears out any other previously added items and adds the new list of ones fresh. Restarting Mathematica removes the items. Or you can just execute

MathLink`CallFrontEnd[FrontEnd`ResetMenusPacket[{Automatic}]];

Here is an example of its use.

AddToPalettesMenu[{{"Square Root", 
   "CreatePalette[{Button[\"List files\",CreateDocument[{Column[FileNames[]]}]]}]"}}]

But, in your case you could use a NotebookOpen with a path pointing to your specific palette. Or you could define functions in your package which create a given palette programatically.

POSTED BY: David Reiss
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract