我用执行ClearAll["Global`*"]的ActionMenu创建了一个自定义调色板.它执行所需的操作,但是前端不会立即将颜色从黑色更新为蓝色(标准),因为直接从笔记本单元执行ClearAll["Global`*"]时会发生这种情况(仅在执行其他操作之后才更新).有没有办法启动前端显示状态的刷新?
I created a custom palette, with an ActionMenu that executes ClearAll["Global`*"]. It performs the desired action, but the frontend doesn't instantly update the colors from black to blue (standard), as it happens when ClearAll["Global`*"] is executed directly from a notebook cell (it only updates after something else has been executed). Is there a way to initiate a refresh of the frontend display status?
编辑:显然,从调色板加载程序包时也会发生同样的情况(蓝色不会立即更新为黑色).
Apparently, the same happens when I load a package from a palette (blue doesn’t immediately update to black).
推荐答案虽然不是很优雅,但是可以工作(主循环必须在ClearAll之后调用一次):
Not exactly elegant, but it works (the main loop has to be called once after ClearAll):
ActionMenu["Clear", {"Clear global variables" :> (ClearAll["Global`*"]; Block[{nb}, nb = CreateDocument[ExpressionCell[42, "Input"], Visible -> False]; SelectionMove[nb, All, Notebook]; SelectionEvaluate[nb]; NotebookDelete[nb];])}]当然,应该使用新的Mathematica 8 NotebookEvaluate函数,但是似乎不可以 在这里工作(即
Of course, one should use the new Mathematica 8 NotebookEvaluate function, but it seems not to work here (i.e.,
ActionMenu["Clear", {"Clear global variables" :> (ClearAll["Global`*"]; Block[{nb}, nb = CreateDocument[ExpressionCell[42, "Input"], Visible -> False]; NotebookEvaluate[nb]; NotebookDelete[nb];])}]给出错误消息
Could not process unknown packet "1".更多推荐
为什么不从自定义调色板运行ClearAll ["Global` *"]更新局部变量颜色?
发布评论