Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm trying to create a modified version of the Default.nb StyleSheet that adds a docked cell to act as a status bar along the top of every notebook to display some basic information (user login name and login time, generated when my set of packages is loaded). My current implementation, which isn't functioning as I want it to, assigns the cell data I want to display in the status bar to a variable in the Global context:

$StatusBar = ToBoxes[Dynamic[Row[{
      Item[
       If[ValueQ[$PersonID],
        Style[$PersonName <> " logged in at " <> $LoginTime, 
         Darker[Darker[Green]], FontFamily -> "Arial"],
        Style["Not logged in!", Darker[Red], FontFamily -> "Arial"]
        ]
       ]
      }], 
    TrackedSymbols :> {$PersonID, $PersonName, $LoginTime}]];

I've created a new stylesheet that inherits everything from Default.nb, but with modified Notebook Options Settings to add the desired DockedCells (I've omitted the non-relevant Options):

Cell[StyleData["Notebook"],
      DockedCells->Cell[BoxData[$StatusBar]],
      <...>
]

Unfortunately, the DockedCells Option defined in the StyleSheet doesn't seem to recognize the $StatusBar variable I've created to populate it. All I get is a docked cell displaying $StatusBar (verbatim). I'm not sure if this is a context issue, an evaluation order issue, or something else altogether.

It would be even more convenient if I could define the $StatusBar variable within the stylesheet so that it doesn't have to be recreated when my packages are loaded. However, I'm skeptical that this is possible. Is there any way to actually evaluate code within a StyleSheet?

share|improve this question
add comment

1 Answer

I often create styles using CellPrint:

enter image description here

Once you have created the style definition go to Format > Edit Stylesheet and past this style definition cell into the private stylesheet:

enter image description here

You should then see the docked cell in your notebook:

enter image description here

But once you give values to your variables it should work

enter image description here

You should probably also remove some unwanted stuff from the style definition:

enter image description here

BTW you may want to choose a different test to ValueQ. I saw a Q&A the other day (can't remember which one) in which it does not always give what you expect due to

ValueQ gives False only if expr would not change if it were to be entered as Mathematica input.

share|improve this answer
    
Your suggestion above works fine if the contents of $StatusBar have been evaluated before executing the CellPrint statement that generates the StyleData cell. What I'm interested in is defining a new Default Stylesheet with that variable unevaluated (as it will be if I open a notebook to which the Stylesheet is applied before I load my packages), and having it populate when my packages are loaded. Is this possible? –  bdot Nov 12 '13 at 2:57
    
Yes. But you should ask that in your question. –  Mike Honeychurch Nov 12 '13 at 3:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.