5
$\begingroup$

This question is based on my earlier question about randomizing labs for students in my computer lab courses. There a perfectly good solution was posted; however, because of privilege problems, I cannot use the exact method there, as I do not have the ability to modify global settings.

So now I've decided on a different approach: having an input field at the top of the lab, where the student is prompted to enter their name, and hit a button "Begin Lab". The button will use the name (among other things) as a seed to randomize the lab. All well and good.

However, before that button is clicked, I would like to "gray out" or hide all other cells in the lab. In other words, the only active, usable cell is this one containing the "Begin Lab" button, until that button is clicked!

Is this possible? Can it be done without making changes to the global settings (preferably) ?

$\endgroup$

2 Answers 2

4
$\begingroup$

One possibility would be to (programmatically) add dynamic options to all cells. E.g., one cell could look like :

Cell["1-1", "Input",
 Evaluatable->Dynamic[eval],
 CellOpen->Dynamic[open],
 Background->Dynamic[bcolor]]

Then, if you evaluate in a subsequenc cell (or by Button) this:

eval = True; open = True; bcolor = LightGray

the Cell becomes visible.

Kind of scary, because the cells all get closed once you quit the kernel, but maybe with Deploy or another button you could fix that.

$\endgroup$
4
$\begingroup$

Here's an option that allows you to work from the stylesheet and avoid any of the pernicious issues with Dynamic and slow notebooks.

The trick will be to use the TaggingRules to store metadata and then to query that with FrontEnd`CurrentValue. The FrontEnd`* is important as it allows the computations to occur only in the front end itself and so there's no slow communication.

My sample way to set the stylesheet looked like (note that you want to set the current cell to be Evaluatable before running this)

SetOptions[EvaluationNotebook[], 
 StyleDefinitions ->
  Notebook[
   {
    Cell[StyleData[StyleDefinitions -> "Default.nb"]],
    Cell[
     StyleData["Input"],
     Evaluatable ->
      FrontEnd`CurrentValue[
       FrontEnd`EvaluationNotebook[], 
       {TaggingRules, "HasUUID"}, 
       False
       ],
     ShowCellBracket -> FrontEnd`CurrentValue[
       FrontEnd`EvaluationCell[],
       Evaluatable
       ],
     CellOpen -> FrontEnd`CurrentValue[
       FrontEnd`EvaluationCell[],
       Evaluatable
       ]
     ]
    }
   ]
 ]

Where I use CellOpen and ShowCellBracket to hide content until we're ready to show it. You can tune this to your needs/hide other cells/introduce more customizations.

With a button to start the lab this before clicking this looks like

enter image description here

and after clicking we have

enter image description here

The benefit of the stylesheet approach is that you can delete that first cell and edit the notebook and only revert the TaggingRules right before you're ready to distribute. No evaluation needed on the students' parts and it "just works".

There's not even a warning about Dynamic content.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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