摘要
解决GNU Radio的内嵌代码块无法打开编辑器的问题.通过修改py脚本实现使用VSCode编辑内嵌代码.
问题描述
环境:
- 系统macOS 13.5
- GNU Radio Companion 3.10.8.0 (Python 3.10.13)
代码块 | 选择应用程序是空的 | 选择应用程序是空的 |
---|---|---|
实现
修改
/Users/workspace/radioconda/lib/python3.10/site-packages/gnuradio/grc/gui/Dialogs.py
def choose_editor(parent, config):
"""
Give the option to either choose an editor or use the default.
"""
content_type = Gio.content_type_from_mime_type("text/x-python")
if content_type == "*":
# fallback to plain text on Windows if no useful x-python association
content_type = Gio.content_type_from_mime_type("text/plain")
dialog = Gtk.AppChooserDialog.new_for_content_type(
parent,
Gtk.DialogFlags.MODAL,
content_type,
)
dialog.set_heading("Choose an editor below")
widget = dialog.get_widget()
widget.set_default_text("Choose an editor")
widget.set_show_default(True)
widget.set_show_recommended(True)
widget.set_show_fallback(True)
editor = None
response = dialog.run()
if response == Gtk.ResponseType.OK:
appinfo = dialog.get_app_info()
editor = config.editor = appinfo.get_executable()
dialog.destroy()
# 设置默认编辑器
editor = "/Applications/Visual Studio Code.app/Contents/MacOS/Electron"
return editor
注意是使用app内的可执行文件.
效果
- 启动gnu radio companion
gnuradio-companion &
- 点击打开编辑器以直接打开VSCode编辑代码
图片 | 动图 |
---|---|
参考文献
如何在windows上编辑gnuradio的python块?
如何在windows上编辑gnuradio的python块?我已经安装了python,比如PyScripter,Anaconda,但是按下‘使用默认值’‘在编辑器中打开’下面的两行错误将运行
我想任何编辑都行。我刚用代码试了一下。唯一的缺点是文件对话框默认不显示隐藏的文件,因此您需要右键单击对话,然后选择显示它们的选项,然后导航到您想要的目录(如果不更改目录就不会更新,或者可能有刷新选项。
如果您安装了Python,您可以使用Idle,可以像我一样使用,或者使用记事本(或者Notepad++作为其他回答状态)。numpy和gnuradio的导入被Visual代码标记为未解决,所以我还没有脱离困境,但作为一个编辑器,它工作得很好。
It is easily reproduced. Just create an embedded Python block in Windows and double-click it, and click "Open in Editor". A dialogue to choose the editor presents 3 options 1) Choose an editor, 2) Use the default editor 3) Cancel. Using the default editor gives the error "Unable to load the default editor, please choose an editor". Choosing an editor opens a file dialogue box, which curiously does not allow browsing the entire system. For instance, c:\users\username\AppData is not visible, although a directory called "Application Data" appears in the same place. Navigating into it shows no files, when there are actually hundreds of files there, including the default location of Visual Studio Code.
I tried setting the default editor to a shortcut to vscode.exe, which could be seen from the dialogue box. That yielded the error "Error opening an external editor. Please select a different editor", after which the clicking the "Open in Editor" button does not open the dialogue to choose the editor, but just produces the same error message.
Restarting gnu radio fixed that problem. Then I stumbled upon the right click menu in the file dialogue that adds hidden files to the view, and that works. Absent vscode, perhaps Idle or Notepad would suffice for casual use.
73,
Chris VE3NRT
Hi all,
This is not a fix, but a hack. Maybe it will help you
标签:executable,gnuradio,GNU,default,代码,Radio,choose,config,editor From: https://www.cnblogs.com/qsbye/p/17919805.html