1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 """Defines a switch button."""
17
18 from warnings import warn
19
20 from muntjac.ui.button import Button, IClickListener
21 from muntjac.data.property import IProperty
22
23
25
26 CLIENT_WIDGET = None
27
29 """Creates a new switch button.
30
31 @param args: tuple of the form
32 - (caption, initialState)
33 1. the caption of the switch button
34 2. the initial state of the switch button
35 - (caption, listener)
36 1. the caption of the switch button
37 2. the click listener
38 - (caption, target, methodName)
39 1. the Button caption.
40 2. the Object having the method for listening button clicks.
41 3. the name of the method in target object, that receives
42 button click events.
43 - (state, dataSource)
44 1. the Initial state of the switch-button.
45 2. boolean property
46 - (caption)
47 1. the switch button caption
48 """
49 nargs = len(args)
50 if nargs == 0:
51 super(CheckBox, self).__init__()
52 self.setSwitchMode(True)
53 elif nargs == 1:
54 caption, = args
55 super(CheckBox, self).__init__(caption, False)
56 elif nargs == 2:
57 if isinstance(args[1], IClickListener):
58 caption, listener = args
59 super(CheckBox, self).__init__(caption, listener)
60 self.setSwitchMode(True)
61 elif isinstance(args[1], IProperty):
62 caption, dataSource = args
63 super(CheckBox, self).__init__(caption, dataSource)
64 self.setSwitchMode(True)
65 else:
66 caption, initialState = args
67 super(CheckBox, self).__init__(caption, initialState)
68 elif nargs == 3:
69 caption, target, methodName = args
70 super(CheckBox, self).__init__(caption, target, methodName)
71 self.setSwitchMode(True)
72 else:
73 raise ValueError, 'too many arguments'
74
75
77 warn('CheckBox is always in switch mode', DeprecationWarning)
78
79 if self._switchMode and not switchMode:
80 raise NotImplementedError, ('CheckBox is always in switch '
81 'mode (consider using a Button)')
82
83 super(CheckBox, self).setSwitchMode(True)
84
85
87 raise NotImplementedError, "CheckBox does not support disable on click"
88