mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-29 08:15:18 -04:00
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:
parent
53ff35dd6e
commit
31a054c933
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user