Gtk+3 error: 'GLocalFile' is not defined
Gtk+3 error: 'GLocalFile' is not defined
我正在使用以下方式在我的文件管理器中插入边栏:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import Gio
def on_open_location(placessidebar, location, flags):
# import pdb;
# pdb.set_trace()
location = placessidebar.get_location()
print("Opened URI: %s" % (GLocalFile.get_uri(location)))
def create_side_bar():
# side bar
placessidebar = Gtk.PlacesSidebar()
placessidebar.set_open_flags(Gtk.PlacesOpenFlags.NORMAL)
placessidebar.connect("open-location", on_open_location)
return placessidebar
但是每当我 运行 这个代码时:
NameError: name 'GLocalFile' is not defined
我尝试调试它并注意到以下几点:
location
<__gi__.GLocalFile object at 0x7f3ea42b5cf0 (GLocalFile at 0x1aaae40)>
location
是一个 GLocalFile
类型的参数,所以看到这个我也尝试了 __gi__.GLocalFile
并且正如预期的那样它给出了:
NameError: name '__gi__' is not defined
在网上搜索我看到每个人都使用相同的侧边栏代码,所以我在这里缺少什么?
GLocalFile
是仅供内部使用的 class,因此即使它出现在调试消息中,您也无法在 Python.
中访问它
(NameError: name 'GLocalFile' is not defined
是有道理的,因为您的程序中没有任何导入该名称的内容。)
根据documentation,Gtk.PlacesSidebar.get_location()
的return类型是Gio.File
,所以直接调用location.get_uri()
即可。
我正在使用以下方式在我的文件管理器中插入边栏:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import Gio
def on_open_location(placessidebar, location, flags):
# import pdb;
# pdb.set_trace()
location = placessidebar.get_location()
print("Opened URI: %s" % (GLocalFile.get_uri(location)))
def create_side_bar():
# side bar
placessidebar = Gtk.PlacesSidebar()
placessidebar.set_open_flags(Gtk.PlacesOpenFlags.NORMAL)
placessidebar.connect("open-location", on_open_location)
return placessidebar
但是每当我 运行 这个代码时:
NameError: name 'GLocalFile' is not defined
我尝试调试它并注意到以下几点:
location
<__gi__.GLocalFile object at 0x7f3ea42b5cf0 (GLocalFile at 0x1aaae40)>
location
是一个 GLocalFile
类型的参数,所以看到这个我也尝试了 __gi__.GLocalFile
并且正如预期的那样它给出了:
NameError: name '__gi__' is not defined
在网上搜索我看到每个人都使用相同的侧边栏代码,所以我在这里缺少什么?
GLocalFile
是仅供内部使用的 class,因此即使它出现在调试消息中,您也无法在 Python.
(NameError: name 'GLocalFile' is not defined
是有道理的,因为您的程序中没有任何导入该名称的内容。)
根据documentation,Gtk.PlacesSidebar.get_location()
的return类型是Gio.File
,所以直接调用location.get_uri()
即可。