1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
import os, sys
import Tkinter as tk
class GuiImage(object):
icons = {}
@staticmethod
def __get_base_path():
try:
return os.path.join(sys._MEIPASS, 'res').decode(
sys.getfilesystemencoding())
except:
return os.path.abspath(os.path.dirname(__file__)).decode(
sys.getfilesystemencoding())
@staticmethod
def get_path(imageType, code, fileType='gif'):
return os.path.join(
GuiImage.__get_base_path(), imageType, '%s.%s' % (code, fileType))
@staticmethod
def __get_image(imageType, cache, code, fileType='gif'):
if code not in cache:
path = GuiImage.get_path(imageType, code, fileType)
cache[code] = tk.PhotoImage(file=path)
return cache[code]
@staticmethod
def get_icon(code):
return GuiImage.__get_image('icons', GuiImage.icons, code)
|