def paint(cr, size): def slant_grain(n): for i in np.linspace(-2.0, +2.0, 2.0*(n+1)): cr.move_to(-2.0, -2.0+i) cr.line_to(+2.0, +2.0+i) def grid_grain(n): for i in np.linspace(-1.0, +1.0, (n+1)): cr.move_to(i, -1.0) cr.line_to(i, +1.0) cr.move_to(-1.0, i) cr.line_to(+1.0, i) if n == 0: return cr.set_operator(cairo.OPERATOR_OVER) cr.set_source_rgba( accessors.getitem(foreground_color, 0, 0.0), accessors.getitem(foreground_color, 1, 0.0), accessors.getitem(foreground_color, 2, 0.0), accessors.getitem(foreground_color, 3, 1.0) ) cr.set_line_width(1.0/(n+1)) grid_grain(n)
def paint(cr, size): if background_color is not None: cr.set_operator(cairo.OPERATOR_OVER) cr.set_source_rgba( accessors.getitem(background_color, 0, 0.0), accessors.getitem(background_color, 1, 0.0), accessors.getitem(background_color, 2, 0.0), accessors.getitem(background_color, 3, 1.0) ) cr.paint()
def color_modifiers_hsva(self): color = accessors.getitem(self, "color", None) color_h = accessors.getitem(color, "h", None) color_s = accessors.getitem(color, "s", None) color_v = accessors.getitem(color, "v", None) color_a = accessors.getitem(color, "a", None) h = accessors.getattr(color_h, "data", None) if color_h is not None else 1.0 s = accessors.getattr(color_s, "data", None) if color_s is not None else 1.0 v = accessors.getattr(color_v, "data", None) if color_v is not None else 1.0 a = accessors.getattr(color_a, "data", None) if color_a is not None else 1.0 return np.array([h, s, v, a], dtype=np.float32)
def paint(cr, size): cr.set_operator(cairo.OPERATOR_OVER) cr.set_source_rgba( accessors.getitem(background_color, 0, 0.0), accessors.getitem(background_color, 1, 0.0), accessors.getitem(background_color, 2, 0.0), accessors.getitem(background_color, 3, 1.0) ) cr.paint() if n == 0: return cr.set_source_rgba( accessors.getitem(foreground_color, 0, 0.0), accessors.getitem(foreground_color, 1, 0.0), accessors.getitem(foreground_color, 2, 0.0), accessors.getitem(foreground_color, 3, 1.0) ) cr.set_line_width(1.0/(n+1)) for i in np.linspace(-1.0, +1.0, (n+1)): cr.move_to(i, -1.0) cr.line_to(i, +1.0) cr.move_to(-1.0, i) cr.line_to(+1.0, i)
def __getitem__(self, key): try: return accessors.getitem(self._data, key) except KeyError: result = self._factory(key) self._data[key] = result return result
def __delitem__(self, key): key = str(key) old_value = accessors.getitem(objects.itemsof(self), key, None) if old_value is not None: old_value.data_changed.unsubscribe(_notify) accessors.delitem(objects.itemsof(self), key)
def get_or_create_axis(self, key, *args, **kwargs): result = accessors.getitem(self.axes, key, None) if result is None: result = Axis(*args, **kwargs) result.data_changed.subscribe(self.axis_data_changed) accessors.setitem(self.axes, key, result) return result
def get_or_create_mark(self, key, *args, **kwargs): result = accessors.getitem(self.marks, key, None) if result is None: result = Mark(*args, **kwargs) result.data_changed.subscribe(self.mark_data_changed) accessors.setitem(self.marks, key, result) return result
def default_properties(cls, obj, options=None): position = Property(title="Position", type="Vector", default=None, visible=False) for i in range(defaults.DEFAULT_N): position[i] = Property(title=str(i), type="Decimal", default=None, visible=False) size = Property(title="Size", type="Vector", default=None, visible=False) for i in range(defaults.DEFAULT_N): size[i] = Property(title=str(i), type="Decimal", default=None, visible=False) offset = Property(title="Offset", type="Vector", default=None, visible=False) for i in range(defaults.DEFAULT_N): offset[i] = Property(title=str(i), type="Decimal", default=None, visible=False) color = Property(title="Color", type="Color", options=accessors.getitem(options, "color", None)) color["primary"] = Property(title="Primary", type="Color", default="#ffffff", visible=False) color["secondary"] = Property(title="Secondary", type="Color", default="#ffffff", visible=False) color["palette"] = Property(title="Palette", type="String", default="brewer.ylgnbu", visible=False) color["h"] = Property(title="Hue", type="Decimal", default=1.0, visible=False) color["s"] = Property(title="Saturation", type="Decimal", default=1.0) color["v"] = Property(title="Value", type="Decimal", default=1.0) color["a"] = Property(title="Alpha", type="Decimal", default=1.0, visible=False) shape = Property(title="Shape", type="Shape", options=accessors.getitem(options, "shape", None)) shape["index"] = Property(title="Index", type="Integer", default=0, visible=False) shape["palette"] = Property(title="Palette", type="String", default="geometric.geometric_black", visible=False) texture = Property(title="Texture", type="Texture", default=None, options=accessors.getitem(options, "texture", None)) texture["index"] = Property(title="Index", type="Integer", default=0, visible=False) texture["palette"] = Property(title="Palette", type="String", default="basic.grid", visible=False) delta_size = Property(title="Size", type="Decimal", default=0.5) delta_offset = Property(title="Motion", type="Decimal", default=0.0) label = Property(title="Label", type="String", default="") obj.setdefault("position", position) obj.setdefault("size", size) obj.setdefault("offset", offset) obj.setdefault("color", color) obj.setdefault("shape", shape) obj.setdefault("texture", texture) obj.setdefault("delta_size", delta_size) obj.setdefault("delta_offset", delta_offset) obj.setdefault("label", label)
def __setitem__(self, key, value): def _notify(obj, key_, value_): self.data_changed(self, (key,) + key_, value_) old_value, new_value = accessors.getitem(objects.itemsof(self), key, None), value if old_value is not None: old_value.data_changed.unsubscribe(_notify) accessors.setitem(objects.itemsof(self), key, value) if new_value is not None: new_value.data_changed.subscribe(_notify)
def radial_gradient(stops, p0=0.0, r0=0.0, p1=0.0, r1=1.0, **kwargs): source = cairo.RadialGradient( accessors.getitem(p0, 0, p0), accessors.getitem(p0, 1, 0.0), r0, accessors.getitem(p1, 0, p1), accessors.getitem(p1, 1, 0.0), r1 ) for i, color in stops: source.add_color_stop_rgba(i, accessors.getitem(color, 0, 0.0), accessors.getitem(color, 1, 0.0), accessors.getitem(color, 2, 0.0), accessors.getitem(color, 3, 1.0) ) def paint(cr, size): cr.set_source(source) cr.paint() return _normal(paint, **kwargs)
def linear_gradient(stops, p0=-1.0, p1=+1.0, **kwargs): source = cairo.LinearGradient( accessors.getitem(p0, 0, p0), accessors.getitem(p0, 1, 0.0), accessors.getitem(p1, 0, p1), accessors.getitem(p1, 1, 0.0) ) for i, color in stops: source.add_color_stop_rgba(i, accessors.getitem(color, 0, 0.0), accessors.getitem(color, 1, 0.0), accessors.getitem(color, 2, 0.0), accessors.getitem(color, 3, 1.0) ) def paint(cr, size): cr.set_source(source) cr.paint() return _normal(paint, **kwargs)
def color_a(self): return accessors.getattr(accessors.getitem(accessors.getitem(self, "color", None), "a", None), "data", None)
def color_secondary_hsva(self): color = accessors.getitem(self, "color", None) return self.color_secondary.hsva if color is not None and not color.bound else np.array([0,0,1,1], dtype=np.float32) #np.ones(4, dtype=np.float32)
def color_secondary(self): from .. import colors value = accessors.getattr(accessors.getitem(accessors.getitem(self, "color", None), "secondary", None), "data", None) if isinstance(value, str): return colors.Color.from_hex(value) return value
def delta_size(self): return accessors.getattr(accessors.getitem(self, "delta_size", None), "data", None)
def shape_index(self): value = accessors.getattr(accessors.getitem(accessors.getitem(self, "shape", None), "index", None), "data", None) return value
def show_background(self): return accessors.getattr(accessors.getitem(self, "show_background", None), "data", False)
def show_shading(self): return accessors.getattr(accessors.getitem(self, "show_shading", None), "data", False)
def default_color_palette(self, value): return accessors.setattr(accessors.getitem(accessors.getitem(self, "color", None), "palette", None), "default", value)
def title(self): return accessors.getitem(objects.attrsof(self), "title", str(self.index))
def __getitem__(self, key): return accessors.getitem(objects.itemsof(self), key)
def texture(self): return accessors.getattr(accessors.getitem(self, "texture", None), "data", None)
def shape_palettes(self): from .. import palettes value = accessors.getattr(accessors.getitem(accessors.getitem(self, "shape", None), "palette", None), "data", None) return palettes.shape_palettes(value)
def label(self): return accessors.getattr(accessors.getitem(self, "label", None), "data", None)
def show_overflow(self): return accessors.getattr(accessors.getitem(self, "show_overflow", None), "data", False)
def delta_offset(self): return accessors.getattr(accessors.getitem(self, "delta_offset", None), "data", None)
def show_guides(self): return accessors.getattr(accessors.getitem(self, "show_guides", None), "data", True)
def touch_move(self, value): try: accessors.getitem(self._touches, value.identifier) accessors.setitem(self._touches, value.identifier, value) except Exception: pass
def color_palettes(self): from .. import palettes value = accessors.getattr(accessors.getitem(accessors.getitem(self, "color", None), "palette", None), "data", None) return palettes.color_palettes(value)