"""
Copyright (c) 2017, CodeLV.
Distributed under the terms of the MIT License.
The full license is in the file LICENSE, distributed with this software.
Created on Aug 25, 2017
@author: jrm
"""
from atom.api import Typed, Bool
from enamlnative.widgets.switch import ProxySwitch
from .bridge import ObjcMethod, ObjcProperty, ObjcCallback
from .uikit_control import UIControl, UiKitControl
[docs]class UISwitch(UIControl):
"""
"""
#: Properties
on = ObjcProperty('bool')
onTintColor = ObjcProperty('UIColor')
tintColor = ObjcProperty('UIColor')
thumbTintColor = ObjcProperty('UIColor')
onImage = ObjcProperty('UIImage')
offImage = ObjcProperty('UIImage')
#: Methods
#: Works but then doesn't let you change it
setOn = ObjcMethod('bool', dict(animated='bool'))
#: Callbacks
onValueChanged = ObjcCallback('bool')
[docs]class UiKitSwitch(UiKitControl, ProxySwitch):
""" An UiKit implementation of an Enaml ProxyToolkitObject.
"""
#: A reference to the toolkit widget created by the proxy.
widget = Typed(UISwitch)
# -------------------------------------------------------------------------
# Initialization API
# -------------------------------------------------------------------------
self.widget = UISwitch()
self.widget.onValueChanged.connect(self.on_checked_changed)
[docs] def on_checked_changed(self, on):
""" See https://stackoverflow.com/questions/19628310/ """
#: Since iOS decides to call this like 100 times for each defer it
d = self.declaration
with self.widget.setOn.suppressed():
d.checked = on
# -------------------------------------------------------------------------
# ProxySwitch API
# -------------------------------------------------------------------------
[docs] def set_checked(self, checked):
self.widget.setOn(checked, animated=True)
[docs] def set_show_text(self, show):
pass #: Has no text
[docs] def set_split_track(self, split):
pass
[docs] def set_text_off(self, text):
pass
[docs] def set_text_on(self, text):
pass