6
$\begingroup$

In a particular notebook, I've got a docked cell with a status readout that depends on a package I've written. It doesn't display properly before the package is loaded. The notebook has an initialization cell that loads the package, but of course that won't happen until the user explicitly evaluates initialization cells or evaluates something else and is prompted to evaluate such cells. To avoid a broken display, the package sets a global variable when loaded, and the docked cell has a Dynamic object that monitors this global variable, displaying "Please evaluate initialization cells!" when it's undefined and the normal status readout when its defined.

This works as intended when opening the notebook, but if the user quits the kernel with Quit[] or the menu item, the Dynamic object does NOT seem to notice, and so continues showing the status readout as if everything were normal. I need a way to make the Dynamic content change when the kernel quits, so the user knows he/she needs to evaluate initialization cells again.

This is more of an issue than it might seem, because (a) I'm working with very novice users, and (b) the notebook has other interactive features (like a big important button) that fail silently and confusingly when the package has not been loaded.

I get that Dynamic objects probably can't react sensibly to a kernel quit because the kernel is what makes them be responsive... So can anyone suggest any clever hacks that will let me change a displayed text item when the kernel quits?

$\endgroup$
  • 1
    $\begingroup$ Have you seen the symbol $Epilog? You might be able to set that so it will set some flag and update your dynamic object before quitting. $\endgroup$ – N.J.Evans Sep 14 '15 at 20:18
  • $\begingroup$ Nice! I was hoping for something like that, but searching on phrases like "kernel quit callback" didn't turn anything up. $\endgroup$ – ibeatty Sep 14 '15 at 20:19
  • $\begingroup$ Update us when you find a solution, I'm curious myself how it ends up working. $\endgroup$ – N.J.Evans Sep 14 '15 at 20:34
  • $\begingroup$ I would try using the Initialization option to Dynamic and call the package in that Initialization within the Dynamic in your docked cell. $\endgroup$ – Mike Honeychurch Sep 16 '15 at 0:10
  • $\begingroup$ Hmm, interesting. Will try. $\endgroup$ – ibeatty Sep 17 '15 at 0:36
1
$\begingroup$

As a possibility you can edit the stylesheet of the notebook by replacing the Input cell style with something like that

Cell[StyleData["Input"], CellProlog:>(if[!packageisloaded===True,packageisloaded=True;Get["yourpackagefile"]])]

So that you can be sure your package is loaded before any other evaluation in the notebook.

Stil does not resolve the dead screen issue, but it could help I hope.

$\endgroup$
  • $\begingroup$ Your if can be replaced by Needs@package` if I'm not mistaken. $\endgroup$ – Kuba Oct 20 '15 at 7:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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