#
#		Python GUI - Check boxes - PyObjC
#

import AppKit
from AppKit import NSOnState, NSOffState
from Actions import Action
from StdFonts import system_font
from ButtonBasedControls import ButtonBasedControl
from GCheckBoxes import CheckBox as GCheckBox

class CheckBox(ButtonBasedControl, GCheckBox):
    
    def __init__(self, title = "New Check Box", font = system_font, **kwds):
        ns_button = self._create_ns_button(title = title, font = font,
            ns_button_type = AppKit.NSSwitchButton,
            ns_bezel_style = AppKit.NSRoundedBezelStyle)
        GCheckBox.__init__(self, _ns_view = ns_button, **kwds)
    
    def get_on(self):
        return self._ns_view.state() <> NSOffState
    
    def set_on(self, v):
        if v:
            state = NSOnState
        else:
            state = NSOffState
        self._ns_view.setState_(state)

    def do_action(self):
        if not self._auto_toggle:
            self.on = not self.on
        Action.do_action(self)
