PageRenderTime 23ms CodeModel.GetById 12ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/examples/dynamictable/DayFilterWidget.py

http://pyjamas.googlecode.com/
Python | 65 lines | 46 code | 19 blank | 0 comment | 4 complexity | c411ae5d55b69e6471765c111b88634d MD5 | raw file
 1from ui import Composite, CheckBox, HorizontalPanel, VerticalPanel, Button, HasAlignment
 2
 3class DayCheckBox(CheckBox):
 4
 5    def __init__(self, owner, caption, day):
 6        CheckBox.__init__(self, caption)
 7
 8        self.day = day
 9        self.addClickListener(owner.dayCheckBoxListener)
10        self.setChecked(owner.calendar.getDayIncluded(day))
11
12
13class DayCheckBoxListener:
14    def __init__(self, calendar):
15        self.calendar = calendar
16        
17    def onClick(self, sender):
18        self.calendar.setDayIncluded(sender.day, sender.isChecked())
19
20
21class DayFilterWidget(Composite):
22
23    def __init__(self, calendar):
24        Composite.__init__(self)
25    
26        self.calendar = calendar
27        self.dayCheckBoxListener = DayCheckBoxListener(calendar)
28        self.outer = VerticalPanel()
29        self.initWidget(self.outer)
30        self.setStyleName("DynaTable-DayFilterWidget")
31        self.outer.add(DayCheckBox(self, "Sunday", 0))
32        self.outer.add(DayCheckBox(self, "Monday", 1))
33        self.outer.add(DayCheckBox(self, "Tuesday", 2))
34        self.outer.add(DayCheckBox(self, "Wednesday", 3))
35        self.outer.add(DayCheckBox(self, "Thursday", 4))
36        self.outer.add(DayCheckBox(self, "Friday", 5))
37        self.outer.add(DayCheckBox(self, "Saturday", 6))
38
39        self.buttonAll = Button("All", self)
40        self.buttonNone = Button("None", self)
41
42        hp = HorizontalPanel()
43        hp.setHorizontalAlignment(HasAlignment.ALIGN_CENTER)
44        hp.add(self.buttonAll)
45        hp.add(self.buttonNone)
46        
47        self.outer.add(hp)
48        self.outer.setCellVerticalAlignment(hp, HasAlignment.ALIGN_BOTTOM)
49        self.outer.setCellHorizontalAlignment(hp, HasAlignment.ALIGN_CENTER)
50        
51    def setAllCheckBoxes(self, checked):
52        for widget in self.outer:
53            if widget.setChecked:
54                widget.setChecked(checked)
55                self.dayCheckBoxListener.onClick(widget)
56    
57    def onClick(self, sender):
58        if self.buttonAll == sender:
59            self.setAllCheckBoxes(True)
60        elif self.buttonNone == sender:
61            self.setAllCheckBoxes(False)
62
63
64        
65