如何在 python3 中使用 GtkSource.FileLoader
how to use GtkSource.FileLoader in python3
正如文档所建议的那样 here,有一个 GtkSource.View 对象,我已经检索了它的缓冲区并作为参数传入 GtkSource.FileLoader.new 。基本上这是我的代码:
# set file loader
file = GtkSource.File()
file.set_location(Gio.File.new_for_path('/home/ishan/Desktop/net_neutrality/index.html'))
x = GtkSource.FileLoader.new(self.code.get_buffer(), file)
#self.code refers to a GtkSource.View object
现在的主要问题是,我没有看到从文件中加载任何内容。 SourceView 是空白的。那么我应该调用 GtkSource.FileLoader.load_async 以便 "sort of" 触发加载吗?还是我还缺少其他东西?
是的,您需要调用 load_async 将文件加载到缓冲区。
正如文档所建议的那样 here,有一个 GtkSource.View 对象,我已经检索了它的缓冲区并作为参数传入 GtkSource.FileLoader.new 。基本上这是我的代码:
# set file loader
file = GtkSource.File()
file.set_location(Gio.File.new_for_path('/home/ishan/Desktop/net_neutrality/index.html'))
x = GtkSource.FileLoader.new(self.code.get_buffer(), file)
#self.code refers to a GtkSource.View object
现在的主要问题是,我没有看到从文件中加载任何内容。 SourceView 是空白的。那么我应该调用 GtkSource.FileLoader.load_async 以便 "sort of" 触发加载吗?还是我还缺少其他东西?
是的,您需要调用 load_async 将文件加载到缓冲区。