summaryrefslogtreecommitdiff
path: root/jfr_playoff/gui/icons.py
blob: f700bb1476fcb6472beb2c2974f9c91ae62321c5 (plain)
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
import os, sys

import Tkinter as tk

class GuiImage(object):
    icons = {}

    @staticmethod
    def __get_base_path():
        try:
            return os.path.join(sys._MEIPASS, 'res')
        except:
            return os.path.abspath(os.path.dirname(__file__))

    @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)