# Cell output controlled by CellFrameLabel Checkbox?

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"}]&)]
]


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"}]&)]
]


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?

-

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.

unchecked:

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

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.

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.

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.

-
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