tkwidgets: change how TreeNode icons are located/loaded

This makes it follow the regular resolution rules of the model-path and doesn't risk a RuntimeError when importing the module.
This commit is contained in:
rdb 2019-09-06 13:39:22 +02:00
parent 53ff35dd6e
commit 31a054c933

View File

@ -19,14 +19,14 @@ __all__ = ['TreeNode', 'TreeItem']
# - keep track of object ids to allow more careful cleaning
# - optimize tree redraw after expand of subnode
import os
import os, sys
from direct.showbase.TkGlobal import *
from panda3d.core import *
# Initialize icon directory
ICONDIR = ConfigVariableSearchPath('model-path').findFile(Filename('icons')).toOsSpecific()
if not os.path.isdir(ICONDIR):
raise RuntimeError("can't find DIRECT icon directory (%s)" % repr(ICONDIR))
if sys.version_info < (3, 0):
FileNotFoundError = IOError
class TreeNode:
@ -70,14 +70,14 @@ class TreeNode:
self.parent = None
def geticonimage(self, name):
try:
if name in self.iconimages:
return self.iconimages[name]
except KeyError:
pass
file, ext = os.path.splitext(name)
ext = ext or ".gif"
fullname = os.path.join(ICONDIR, file + ext)
image = PhotoImage(master=self.canvas, file=fullname)
fn = Filename("icons", name)
if not fn.resolveFilename(getModelPath().value, "gif"):
raise FileNotFoundError("couldn't find \"%s\"" % (fn))
image = PhotoImage(master=self.canvas, file=fn.toOsSpecific())
self.iconimages[name] = image
return image