我如何在dm-script
代码和python
代码之间进行协调,这两种代码都是在数字显微照片中执行的
在我的特殊情况下,我有复杂的对话。因为对话框在python
中不受支持,但在dm-script
中,我在dm-script
中编写了我的对话框。现在的问题是从对话框传递到python代码
考虑下面的例子:
import DigitalMicrograph as DM
script = """string field_value = "";
class ButtonDialog : UIFrame{
void field_changed(object self, TagGroup field){
field_value = field.DLGGetStringValue();
}
object init(object self){
TagGroup dlg, dlg_items, field;
dlg = DLGCreateDialog("Type in a number", dlg_items);
dlg.DLGAddElement(DLGCreateLabel("Number:"));
field = DLGCreateIntegerField(0, 10, "field_changed");
dlg.DLGAddElement(field);
self.super.init(dlg);
return self;
}
}
object dialog = alloc(ButtonDialog).init();
dialog.pose();
"""
DM.ExecuteScriptString(script)
# how do I get this?
field_value = ""
DM脚本调用Python脚本
这个答案显示了Python和DM脚本之间的一些通信,但却形成了相反的一面。它还使用持久标记组作为传输代理
从DM脚本向Python内外传递简单值
从DM脚本传入和传出Python中的图像数据
若要在
dm-script
和python
之间同步数据,同时两者都在同一实例中运行(在本例中,线程也可以针对不同的线程进行修改),可以使用持久标记dm-script
正在设置持久标记python
然后可以再次读取持久性标记更新:Python模块
由于下面提到的限制以及不断增长且不可读的代码,我决定为此编写自己的python模块。使用^{} 可以很容易地从数字显微照片执行具有变量同步的dm脚本代码
请查看以下示例:
这隐藏了所有与dm脚本相关的保存和问题(如下所述)。它允许使用
list
和dict
以及bool
、str
、int
和float
等基本类型。所有类型和值都可以以pythonic的方式使用,而无需关心dm脚本类型。dm脚本可以移动到一个单独的文件中,以进一步清理代码请注意,对于调试,有一个
exec_dmscript(debug=True, debug_file="path/to/file")
开关将代码保存到给定的debug_file
。然后可以在GMS中手动执行该文件,显示错误基本数据类型
对于
string
和number
等基本数据类型,可以手动创建和添加代码。下面的例子说明了这个想法:正如人们所看到的,这种方法有一些缺点。有很多代码创建设置和同步,只需输入一个数字。这使得代码混乱不堪。还可以将dm脚本代码保存在一个单独的文件中,该文件添加了python文件打开。在此代码中调试dm脚本代码也很困难。最后,标记组在python端的移动也有一些限制(请查看下面的内容)
局限性
更新:下面提到的python模块可以处理
TagGrou
和TagList
,因为它将它们线性化并使用单独的键和类型保存请注意
TagGroup
很难同步TagGroup
不能分配给变量。一旦它们被使用,它们就不再可用。这可以通过以下非常简单的代码来说明:此代码将生成输出
这表明您不能将
TagGroup
分配给python变量异步思想
这可以扩展到异步应用程序。
dm-script
和python
实现可以设置观察持久标记的线程。(请注意,您可以使用TagGroupMarkAsChanged()
将TagGroup
标记为已修改),这两个标记完全不同。然后两者都可以向标记添加命令和/或数据。另一个“实例”可以读取和处理它们这必须手动编码。这(目前)不包括在
execdmscript
模块中相关问题 更多 >
编程相关推荐