~ubuntu-branches/ubuntu/raring/wxwidgets2.8/raring

« back to all changes in this revision

Viewing changes to wxPython/demo/ItemsPicker.py

  • Committer: Package Import Robot
  • Author(s): Stéphane Graber
  • Date: 2012-01-07 13:59:25 UTC
  • mfrom: (1.1.9) (5.1.10 sid)
  • Revision ID: package-import@ubuntu.com-20120107135925-2601miy9ullcon9j
Tags: 2.8.12.1-6ubuntu1
* Resync from Debian, changes that were kept:
  - debian/rules: re-enable mediactrl. This allows libwx_gtk2u_media-2.8 to be
    built, as this is required by some applications (LP: #632984)
  - debian/control: Build-dep on libxt-dev for mediactrl.
  - Patches
    + fix-bashism-in-example
* Add conflict on python-wxgtk2.8 (<< 2.8.12.1-6ubuntu1~) to python-wxversion
  to guarantee upgrade ordering when moving from pycentral to dh_python2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import wx
 
2
from wx.lib.itemspicker import ItemsPicker, \
 
3
                               EVT_IP_SELECTION_CHANGED, \
 
4
                               IP_SORT_CHOICES, IP_SORT_SELECTED,\
 
5
                               IP_REMOVE_FROM_CHOICES
 
6
 
 
7
#----------------------------------------------------------------------
 
8
 
 
9
class TestPanel(wx.Panel):
 
10
    def __init__(self, parent, log):
 
11
        self.log = log
 
12
        wx.Panel.__init__(self, parent, -1)
 
13
        sizer = wx.BoxSizer(wx.HORIZONTAL)
 
14
        box = wx.StaticBox(self,-1,"ItemPicker styles")
 
15
        boxSizer = wx.StaticBoxSizer(box,wx.VERTICAL)
 
16
        self.sortChoices = wx.CheckBox(self,-1,'IP_SORT_CHOICES')
 
17
        boxSizer.Add(self.sortChoices)
 
18
        self.sortSelected = wx.CheckBox(self,-1,'IP_SORT_SELECTED')
 
19
        boxSizer.Add(self.sortSelected)
 
20
        self.removeFromChoices = wx.CheckBox(self,-1,'IP_REMOVE_FROM_CHOICES')
 
21
        boxSizer.Add(self.removeFromChoices)
 
22
        sizer.Add(boxSizer,0,wx.ALL,10)
 
23
        b = wx.Button(self,-1,"Go")
 
24
        b.Bind(wx.EVT_BUTTON,self.Go)
 
25
        sizer.Add(b,0,wx.ALL,10)
 
26
        self.SetSizer(sizer)
 
27
    
 
28
    def Go(self,e):
 
29
        style = 0
 
30
        if self.sortChoices.GetValue():
 
31
            style |= IP_SORT_CHOICES
 
32
        if self.sortSelected.GetValue():
 
33
            style |= IP_SORT_SELECTED
 
34
        if self.removeFromChoices.GetValue():
 
35
            style |= IP_REMOVE_FROM_CHOICES
 
36
        d = ItemsPickerDialog(self, style, self.log)
 
37
        d.ShowModal()
 
38
        
 
39
        
 
40
class ItemsPickerDialog(wx.Dialog):
 
41
    def __init__(self,parent, style, log):
 
42
        wx.Dialog.__init__(self,parent)
 
43
        self.log = log
 
44
        sizer =wx.BoxSizer(wx.VERTICAL)
 
45
        b = wx.Button(self, -1, "Add Item")
 
46
        b.Bind(wx.EVT_BUTTON, self.OnAdd)
 
47
        sizer.Add(b, 0, wx.ALL, 5)
 
48
        self.ip = ItemsPicker(self,-1, 
 
49
                          ['ThisIsItem3','ThisIsItem2','ThisIsItem1'],
 
50
                          'Stuff:', 'Selected stuff:',ipStyle = style)
 
51
        self.ip.Bind(EVT_IP_SELECTION_CHANGED, self.OnSelectionChange)
 
52
        self.ip._source.SetMinSize((-1,150))
 
53
        sizer.Add(self.ip, 0, wx.ALL, 10)
 
54
        self.SetSizer(sizer)
 
55
        self.itemCount = 3
 
56
        self.Fit()
 
57
            
 
58
    def OnAdd(self,e):
 
59
        items = self.ip.GetItems()
 
60
        self.itemCount += 1
 
61
        newItem = "item%d" % self.itemCount
 
62
        self.ip.SetItems(items + [newItem])
 
63
        
 
64
    def OnSelectionChange(self, e):
 
65
        self.log.write("EVT_IP_SELECTION_CHANGED %s\n" % \
 
66
                        ",".join(e.GetItems()))
 
67
 
 
68
#----------------------------------------------------------------------
 
69
 
 
70
def runTest(frame, nb, log):
 
71
    win = TestPanel(nb, log)
 
72
    return win
 
73
 
 
74
#----------------------------------------------------------------------
 
75
 
 
76
 
 
77
 
 
78
overview = """<html><body>
 
79
<h2><center>ItemsPicker </center></h2> 
 
80
    
 
81
ItemsPicker is a widget that allows the user to choose a set of picked
 
82
items out of a given list
 
83
 
 
84
</body></html>
 
85
"""
 
86
        
 
87
 
 
88
if __name__ == '__main__':
 
89
    import sys,os
 
90
    import run
 
91
    run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
 
92