File: togglebutton.py

package info (click to toggle)
pythoncard 0.8.1-8.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 5,352 kB
  • ctags: 4,594
  • sloc: python: 42,401; makefile: 55; sh: 22
file content (70 lines) | stat: -rw-r--r-- 2,219 bytes parent folder | download | duplicates (4)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

"""
__version__ = "$Revision: 1.2 $"
__date__ = "$Date: 2004/05/13 02:40:24 $"
"""

import wx
from PythonCard import event, widget

# KEA 2004-05-06
# expose the same interface as CheckBox

class ToggleButtonMouseClickEvent(event.MouseClickEvent):
    binding = wx.EVT_TOGGLEBUTTON
    id = wx.wxEVT_COMMAND_TOGGLEBUTTON_CLICKED

ToggleButtonEvents = (ToggleButtonMouseClickEvent,)

class ToggleButtonSpec(widget.WidgetSpec):
    def __init__(self):
        events = list(ToggleButtonEvents)
        attributes = {
            'label' : { 'presence' : 'optional', 'default':'ToggleButton' },
            'checked' : { 'presence' : 'optional', 'default' : 0 } }
        widget.WidgetSpec.__init__(self, 'ToggleButton', 'Widget', events, attributes )


class ToggleButton(widget.Widget, wx.ToggleButton):
    """
    A toggle button.
    """

    _spec = ToggleButtonSpec()

    def __init__( self, aParent,  aResource ) :
        wx.ToggleButton.__init__(
            self,
            aParent, 
            widget.makeNewId(aResource.id),
            aResource.label, 
            aResource.position, 
            aResource.size,
            style = wx.CLIP_SIBLINGS | wx.NO_FULL_REPAINT_ON_RESIZE,
            name = aResource.name 
            )

        widget.Widget.__init__( self, aParent, aResource)

        if aResource.checked:
            self.SetValue(True)

        self._bindEvents(event.WIDGET_EVENTS + ToggleButtonEvents)
    
    checked = property(wx.ToggleButton.GetValue, wx.ToggleButton.SetValue)
    label = property(wx.ToggleButton.GetLabel, wx.ToggleButton.SetLabel)

    # KEA 2004-05-06
    # you can't actually set the foregroundColor and backgroundColor of
    # a ToggleButton so I wonder whether we should have those as valid
    # attributes? The same goes for other components where some of our
    # base attributes don't make any sense. OTOH, having the attribute
    # which fails silently when it tries to set it gives some symmetry
    # to the components and gets rid of the need for try/except blocks
    # when processing a group of component attributes.


import sys
from PythonCard import registry
registry.Registry.getInstance().register(sys.modules[__name__].ToggleButton)