为什么不从自定义调色板运行ClearAll ["Global` *"]更新局部变量颜色?

编程入门 行业动态 更新时间:2024-10-23 13:24:34
本文介绍了为什么不从自定义调色板运行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` *"]更新局部变量颜色?

本文发布于:2023-11-08 20:43:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1570407.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:调色板   自定义   变量   不从   局部

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!