gtk를 사용하여 해당 파일의 기본 아이콘을 얻고 싶습니다.
이 방법을 python3에서 시도했지만 오류가 발생했습니다.
from gi.repository import Gio as gio
from gi.repository import Gtk
import os
def get_icon_filename(filename,size):
#final_filename = "default_icon.png"
final_filename = ""
if os.path.isfile(filename):
# Get the icon name
file = gio.File(filename)
file_info = file.query_info('standard::icon')
file_icon = file_info.get_icon().get_names()[0]
# Get the icon file path
icon_theme = gtk.icon_theme_get_default()
icon_filename = icon_theme.lookup_icon(file_icon, size, 0)
if icon_filename != None:
final_filename = icon_filename.get_filename()
return final_filename
print(get_icon_filename("/home/newtron/Desktop/Gkite_Logo.png",64))
Err
File "geticon", line 11, in get_icon_filename
file = gio.File(filename)
TypeError: GInterface.__init__() takes exactly 0 arguments (1 given)
나는 gio 모듈에 대한 이전 경험이 없습니다. 내 코드에 문제가 있습니까? 이 오류에 대한 해결책이없는 경우.
내 친구 @stovfl이 말했듯이 python2에 이전 Gi 및 Gtk 코드를 사용했기 때문입니다. 그러나 새 버전의 gio.File
속성에는 다음과 같은 파일 속성의 종류를 지정하는 하위 속성 (클래스)이 더 많이 있습니다.
new_for_path
클래스 나는 이것을 내 코드에서 사용하고 그것을 일했습니다. 실제로이 코드는 다른 StackOverflow 토론에서 얻었습니다.
다시 확인했을 때 python3 코드가 있습니다.
#!/usr/bin/env python
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gio as gio
from gi.repository import Gtk as gtk
import os
def get_icon_filename(filename,size):
#final_filename = "default_icon.png"
final_filename = ""
if os.path.isfile(filename):
# Get the icon name
file = gio.File.new_for_path(filename)
file_info = file.query_info('standard::icon',0)
file_icon = file_info.get_icon().get_names()[0]
# Get the icon file path
icon_theme = gtk.IconTheme.get_default()
icon_filename = icon_theme.lookup_icon(file_icon, size, 0)
if icon_filename != None:
final_filename = icon_filename.get_filename()
return final_filename
print(get_icon_filename("/home/newtron/Desktop/counter.desktop",48))
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다