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.

The following generates a Cell that returns the state of the checkbox when evaluated:

CellPrint[
  ExpressionCell[
    {DynamicModule[{val=True}
      , Checkbox[
          Dynamic[val, (val=#; SetOptions[EvaluationCell[], TaggingRules->{"value"->val}])&]
        ]
      ]
    , Dynamic@CurrentValue[{TaggingRules,"value"}]
    }
  , TaggingRules->{"value"->True}
  , Evaluatable->True
  , CellEvaluationFunction->(CurrentValue[{TaggingRules,"value"}]&)]
]

Works

Moving the checkbox into the frame label breaks the functionality. Why?

CellPrint[
  ExpressionCell[
    Dynamic@CurrentValue[{TaggingRules,"value"}]
  , TaggingRules->{"value"->True}
  , CellFrameLabels->
    {
      {ToBoxes[
        DynamicModule[{val=True}
        , Checkbox[
            Dynamic[val, (val=#; SetOptions[Print[FullForm@EvaluationCell[]];EvaluationCell[], TaggingRules->{"value"->val}])&]
          ]
        ]
      ], None}
    , {None,None}
    }
  , Evaluatable->True
  , CellEvaluationFunction:>(Print[FullForm@EvaluationCell[]];CurrentValue[{TaggingRules,"value"}]&)]
]

Fails

Printing the EvaluationCell[] shows that SetOptions is setting the TaggingRules on the FrameLabel cell, not the main cell. How does one update the tagging rules of the main cell from within a frame?

share|improve this question

1 Answer 1

Given that the objective has been clarified as "How does one update the tagging rules of the main cell from within a frame?" here is a solution:

CellPrint[
 ExpressionCell[Dynamic@CurrentValue[{TaggingRules, "value"}],
  CellTags -> {"X"},
  TaggingRules -> {"value" -> True}, 
  CellFrameLabels -> {{ToBoxes[
      DynamicModule[{val = True}, Checkbox[Dynamic[val, (val = #;
           NotebookLocate["X"]; 
           SetOptions[NotebookSelection@EvaluationNotebook[], 
            TaggingRules -> {"value" -> val}]) &]]]], None}, {None, 
     None}},
  Evaluatable -> True]]

checked:

We begin with the checkbox checked and the tagging rules "value" for the cell displayed as True.

enter image description here

unchecked:

We uncheck the checkbox. The tagging rules "value" for the cell is now set to False.

enter image description here

We can toggle the checkbox over and over to confirm that this does exactly what the OP has sought. You can use show expression if in doubt to verify that the tagging rule has changed locally in what the OP calls the "main cell" -- and not at the notebook level.

enter image description here

And you can do other things to monitor events. Here we see that the notebook level tagging rules are not affected but the local cell tagging rules change with the value of the checkbox.

enter image description here

enter image description here

And so on. In summary the tagging rule in the "main cell" has been updated by checking/unchecking a checkbox located in a cell frame.

share|improve this answer
    
I'm trying to pass the state of the checkbox to the CellEvaluationFunction; for example, to toggle reporting of stderr during evaluation of a shellCell. Would like to make this a style, so setting the notebook's tagging rules seems out-of-place. –  JxB Feb 11 '13 at 22:44
    
@JxB well you should completely re-write the question to reflect what you actually want to do -- there is no point in asking a question that is unrelated to what you actually want. It wastes everyones time. As it stands you have asked about having a checkbox in the cell frame and I have answered showing that it works. –  Mike Honeychurch Feb 11 '13 at 22:54
    
...and in any case changing the checkbox is not a kernel evaluation. CellEvaluationFunction requires you to be doing kernel evaluations so you are not going to be able to use variable dynamic control settings. CellEvaluationFunction can only take whatever the setting is at the time you evaluate the cell. –  Mike Honeychurch Feb 11 '13 at 23:02
    
Mike, thank you for your answer. What I actually want to do is stated boldly in the question's body: "How does one update the tagging rules of the main cell from within a frame?" :) Sorry for the confusion, was it the title? –  JxB Feb 12 '13 at 0:10
    
@JxB right, so CellEvaluationFunction actually has nothing to do with your question after all. Thanks for the clarification :) –  Mike Honeychurch Feb 12 '13 at 1:45

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.