Various Mathematica user interfaces are Mathematica notebook files. It seems to be quite common for these notebook files to contain only part of the information in themselves and to load different elements from one or multiple *.tr files via FrontEndResource
or FrontEndResourceString
. Some of the user interfaces are entirely based on a *.tr file. One example for these is the "ColorSchemeSelector"
, which can be displayed in the front-end using
FrontEndResource["ColorSchemeSelector"] // CellPrint
and is based on
FileNameJoin[{$InstallationDirectory, "SystemFiles", "FrontEnd", "TextResources",
"ColorSchemeSelector.tr"}]
How to create and use such files for my own applications?
For illustration purpose, here is an example for an user interface (without any function) that makes use of different parts of multiple front-end resource files that are part of Mathematica.
Panel @ Grid[
{
{FrontEndResourceString["codeAssistColorSchemeChooseMenuString"],
SpanFromLeft},
{ToExpression@FrontEndResource["FEExpressions", "TimeObjectIcon"],
ToExpression@FrontEndResource["SliderBarHorizontal"]},
{},
{Button[FrontEndResource["ColorSchemeChooserStrings", "okButtonText"],
Null],
Button[FrontEndResourceString["yesButtonText"], Null]}
}]
I'd want the *.tr file to be located within the folder structure of the app. However, as it is part of this question how to get that working and to test what works as expected, I copied the relatively empty TokenTranslationDictionary.tr into my $UserBaseDirectory
CopyFile[FileNameJoin[{$InstallationDirectory, "SystemFiles", "FrontEnd", "TextResources",
"TokenTranslationDictionary.tr"}],
FileNameJoin[{$UserBaseDirectory, "SystemFiles", "FrontEnd", "TextResources",
"TokenTranslationDictionary.tr"}]]
and replaced the
{
}
with
{
"testText" -> "just some text",
"testText2" -> "some more text"
}
@|
@| just a comment
@|
@@resource myFEResource1
resource1
@|
@@resource myFEResource2
{
"TestText" -> "this is resource 2"
}
@|
which should be the correct syntax, base on the other *.tr files.
Nevertheless, after restarting Mathematica only
FrontEndResource["TokenTranslationDictionary", "testText"]
"just some text"
and
FrontEndResource["TokenTranslationDictionary", "testText2"]
"some more text"
return the expected output. But
FrontEndResourceString["myFEResource1"]
and
FrontEndResource["myFEResource2", "TestText"]
return
$Failed
Therefore it appears to me that the available resource
s are defined somewhere and not even adding a new resource
to an existing *.tr file is possible.
How to make it possible to use my own *.tr files with their own resource
definitions via FrontEndResource
and FrontEndResourceString
?
If that is not possible, what are the best alternatives that allow a similar information organization and importing by the front-end?
$FrontEndSession's
TaggingRules
as a replacement, what do you think? $\endgroup$TaggingRules
and then use the front-end in the logic file to get the design elements. As long as one isn't using big graphics, pre-occupying the memory isn't a problem and could remove the delays one experiences when usingFrontEndResource
. $\endgroup$