为什么不从自定义调色板运行ClearAll ["Global` *"]更新局部变量颜色? [英] Why doesn't running ClearAll["Global`*"] from a custom Palette update local variables colors?

查看:190
本文介绍了为什么不从自定义调色板运行ClearAll ["Global` *"]更新局部变量颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用执行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` *"]更新局部变量颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆