Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/pynxc/waxy/imagelist.py
diff options
context:
space:
mode:
Diffstat (limited to 'pynxc/waxy/imagelist.py')
-rw-r--r--pynxc/waxy/imagelist.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/pynxc/waxy/imagelist.py b/pynxc/waxy/imagelist.py
new file mode 100644
index 0000000..f23c91d
--- /dev/null
+++ b/pynxc/waxy/imagelist.py
@@ -0,0 +1,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)