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