def __init__(self, default="#000000", hide_input=False, sage_color=True, label=None): self.sage_color = sage_color self.sage_mode = CONFIG.EMBEDDED_MODE["sage_mode"] self.enable_sage = CONFIG.EMBEDDED_MODE["enable_sage"] if self.sage_mode and self.enable_sage and self.sage_color: from sagenb.misc.misc import Color if isinstance(default, Color): self.default = default elif isinstance(default, str): self.default = Color(default) else: self.default = Color("#000000") else: self.default = default if isinstance(default,str) else "#000000" self.hide_input = hide_input self.label = label
def __init__(self, default="#000000", hide_input=False, sage_color=True, label=None): self.sage_color = sage_color if self.sage_color: try: from sagenb.misc.misc import Color self.sage_mode = True; except: self.sage_mode = False; if self.sage_mode and self.sage_color: if isinstance(default, Color): self.default = default elif isinstance(default, str): self.default = Color(default) else: self.default = Color("#000000") else: self.default = default if isinstance(default,str) else "#000000" self.hide_input = hide_input self.label = label
class ColorSelector(InteractControl): """ A color selector interact control :arg default: initial color (either as an html hex string or a Sage Color object, if sage is installed. :arg bool hide_input: Toggles whether the hex value of the color picker should be displayed in an input box beside the control. :arg bool sage_color: Toggles whether the return value should be a Sage Color object (True) or html hex string (False). If Sage is unavailable or if the user has deselected "sage mode" for the computation, this value will always end up False, regardless of whether the user specified otherwise in the interact. :arg str label: the label of the control, ``""`` for no label, and a default value (None) of the control's variable. """ def __init__(self, default="#000000", hide_input=False, sage_color=True, label=None): self.sage_color = sage_color self.sage_mode = CONFIG.EMBEDDED_MODE["sage_mode"] self.enable_sage = CONFIG.EMBEDDED_MODE["enable_sage"] if self.sage_mode and self.enable_sage and self.sage_color: from sagenb.misc.misc import Color if isinstance(default, Color): self.default = default elif isinstance(default, str): self.default = Color(default) else: self.default = Color("#000000") else: self.default = default if isinstance(default,str) else "#000000" self.hide_input = hide_input self.label = label def message(self): """ Get a color selector control configuration message for an ``interact_prepare`` message :returns: configuration message :rtype: dict """ self.return_value = {'control_type':'color_selector', 'hide_input': self.hide_input, 'raw':False, 'label':self.label} if self.sage_mode and self.enable_sage and self.sage_color: self.return_value["default"] = self.default.html_color() else: self.return_value["default"] = self.default return self.return_value def adapter(self, v, globs): if self.sage_mode and self.enable_sage and self.sage_color: from sagenb.misc.misc import Color return Color(v) else: return v
def adapter(self, v, globs): if self.sage_mode and self.enable_sage and self.sage_color: from sagenb.misc.misc import Color return Color(v) else: return v