Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/pynxc/waxy/imagelist.py
blob: f23c91d7729d99451cc8b19347f24e7121deab3b (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
30
31
32
33
34
35
36
37
38
"""\
imagelist.py

Wax's version of the wxImageList is a bit more user-friendly:

Rather than forcing you to keep the indexes around or know them by heart,
you can (optionally) add names for the images you add, then look them up to
retrieve the index:

  imagelist.Add(bitmap, 'folder')
  imagelist.Add(bitmap, 'folder_open')

  somecontrol.SetItemImage(node, imagelist['folder'])

"""

import wx

class ImageList(wx.ImageList):

    def __init__(self, *args, **kwargs):
        wx.ImageList.__init__(self, *args, **kwargs)
        self._names = {}

    def Add(self, bitmap, name=None):
        if isinstance(bitmap, str) or isinstance(bitmap, unicode):
            bitmap = wx.BitmapFromImage(wx.Image(bitmap))
           
        index = wx.ImageList.Add(self, bitmap)
        if name:
            self._names[name] = index

        return index
    def GetIndexByName(self, name):
        return self._names[name]

    def __getitem__(self, name):
        return self.GetIndexByName(name)