7

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?

ibeatty
  • 2,533
  • 11
  • 22
  • 1
    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. – N.J.Evans Sep 14 '15 at 20:18
  • Nice! I was hoping for something like that, but searching on phrases like "kernel quit callback" didn't turn anything up. – ibeatty Sep 14 '15 at 20:19
  • Update us when you find a solution, I'm curious myself how it ends up working. – N.J.Evans Sep 14 '15 at 20:34
  • I would try using the Initialization option to Dynamic and call the package in that Initialization within the Dynamic in your docked cell. – Mike Honeychurch Sep 16 '15 at 00:10
  • Hmm, interesting. Will try. – ibeatty Sep 17 '15 at 00:36
  • So do you want to do something on kernel start or kernel quit? If you are not sure maybe you could just say what behaviour would you like to have. I mean, the title may be missleading. – Kuba Oct 15 '15 at 09:32
  • p.s. I wouldn't put any Dynamics to DockedCells, only Controllers, that's because of this "issue": Dynamic cells after Kernel restart/quit – Kuba Oct 15 '15 at 09:39
  • @ibeatty are you still interested in that issue? – Kuba Dec 14 '15 at 09:50
  • @Kuba Yes, I am. I've been using $Epilog as suggested by N.J.Evans, and it's mostly working for me. Sometimes the docked cell's state isn't updating as it should, but I haven't had the bandwidth to dig in and figure out why. (This was for a course-in-progress this past semester, so I was scrambling to keep ahead of the students. Now that the term has ended, the pressure is off, and I can cook up a better framework for next time I teach this course.) – ibeatty Dec 16 '15 at 01:15
  • @N.J.Evans BTW, that's why I haven't reported my solution yet. It's definitely imperfect. – ibeatty Dec 16 '15 at 01:15

1 Answers1

1

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.

Nikolay Gromov
  • 502
  • 2
  • 8