Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/pynxc/waxy/combobox.py~
blob: 853cdb48a0901c47aac479cb456606d4676b7870 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
# combobox.py

import wx
import containers
import styles
import waxyobject

class ComboBox(wx.ComboBox, waxyobject.WaxyObject):

    __events__ = {
        'Select': wx.EVT_COMBOBOX,
        'TextChanged': wx.EVT_TEXT,
    }

    def __init__(self, parent, choices=[], size=None, **kwargs):
        style = 0
        style |= self._params(kwargs)
        style |= styles.window(kwargs)

        wx.ComboBox.__init__(self, parent, wx.NewId(), "",
         size=size or (-1,-1), choices=choices, style=style)
        self.SetDefaultFont()

        self.BindEvents()
        styles.properties(self, kwargs)

    def SetItems(self, items):
        """ Clear the internal list of items, and set new items.  <items> is
            a list of 2-tuples (string, data). """
        self.Clear()
        for s, data in items:
            self.Append(s, data)

    def GetItems(self):
        """ Return a list of 2-tuples (string, data). """
        items = []
        for i in range(self.GetCount()):
            s = self.GetString(i)
            data = self.GetClientData(i)
            items.append((s, data))
        return items

    #
    # style parameters

    def _params(self, kwargs):
        flags = wx.CB_DROPDOWN # default
        flags |= styles.stylebool('simple', wx.CB_SIMPLE, kwargs)
        flags |= styles.stylebool('readonly', wx.CB_READONLY, kwargs)
        flags |= styles.stylebool('sort', wx.CB_SORT, kwargs)
        return flags