def __init__(self, cnvs, history_list_va): super(HistoryOverlay, self).__init__(cnvs) self.trail_colour = conversion.hex_to_frgb(gui.FG_COLOUR_HIGHLIGHT) self.pos_colour = conversion.hex_to_frgb(gui.FG_COLOUR_EDIT) self.fade = True # Fade older positions in the history list self.history = history_list_va # ListVA of (center, size) tuples self.history.subscribe(self._on_history_update)
def __init__(self, cnvs, spot_va=None): self.colour = conversion.hex_to_frgb(gui.FG_COLOUR_EDIT) self.highlight = conversion.hex_to_frgb(gui.FG_COLOUR_HIGHLIGHT) # Rendering attributes self._sect_count = 4 self._gap = 0.15 self._sect_width = 2.0 * math.pi / self._sect_count self._spot_radius = 12 # Spot position as a percentage (x, y) where x and y [0..1] self.r_pos = spot_va or TupleVA((0.5, 0.5)) self.r_pos.subscribe(self.on_spot_change)
def __init__(self, cnvs): super(PointsOverlay, self).__init__(cnvs) # A VA tracking the selected point self.point = None # The possible choices for point as a world pos => point mapping self.choices = {} self.min_dist = None # Appearance self.point_colour = conversion.hex_to_frgb( gui.FG_COLOUR_HIGHLIGHT) self.select_colour = conversion.hex_to_frgba( gui.FG_COLOUR_EDIT, 0.5) self.dot_colour = (0, 0, 0, 0.1) # The float radius of the dots to draw self.dot_size = MIN_DOT_RADIUS # None or the point over which the mouse is hovering self.cursor_over_point = None # The box over which the mouse is hovering, or None self.b_hover_box = None self.offset = None self.enabled = False
def __init__(self, cnvs): super(PolarOverlay, self).__init__(cnvs) self.canvas_padding = 0 # self.cnvs.canDrag = False # Rendering attributes self.center_x = None self.center_y = None self.radius = None self.inner_radius = None self.tau = 2 * math.pi self.num_ticks = 6 self.ticks = [] self.ticksize = 10 # Value attributes self.px, self.py = None, None self.tx, self.ty = None, None self.colour = conversion.hex_to_frgb(gui.SELECTION_COLOUR) self.colour_drag = conversion.hex_to_frgba(gui.SELECTION_COLOUR, 0.5) self.colour_highlight = conversion.hex_to_frgb(gui.FG_COLOUR_HIGHLIGHT) self.intensity_label = self.add_label("", align=wx.ALIGN_CENTER_HORIZONTAL, colour=self.colour_highlight) self.phi = None # Phi angle in radians self.phi_line_rad = None # Phi drawing angle in radians (is phi -90) self.phi_line_pos = None # End point in pixels of the Phi line self.phi_label = self.add_label("", colour=self.colour, align=wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_BOTTOM) self.theta = None # Theta angle in radians self.theta_radius = None # Radius of the theta circle in pixels self.theta_label = self.add_label("", colour=self.colour, align=wx.ALIGN_CENTER_HORIZONTAL) self.intersection = None # The intersection of the cirle and line in # pixels self.dragging = False # Calculate the characteristic values for the first time self.on_size()
def __init__(self, cnvs): super(PolarOverlay, self).__init__(cnvs) self.canvas_padding = 0 # self.cnvs.canDrag = False # Rendering attributes self.center_x = None self.center_y = None self.radius = None self.inner_radius = None self.tau = 2 * math.pi self.num_ticks = 6 self.ticks = [] self.ticksize = 10 # Value attributes self.px, self.py = None, None self.tx, self.ty = None, None self.colour = conversion.hex_to_frgb(gui.SELECTION_COLOUR) self.colour_drag = conversion.hex_to_frgba(gui.SELECTION_COLOUR, 0.5) self.colour_highlight = conversion.hex_to_frgb( gui.FG_COLOUR_HIGHLIGHT) self.intensity_label = self.add_label( "", align=wx.ALIGN_CENTER_HORIZONTAL, colour=self.colour_highlight) self.phi = None # Phi angle in radians self.phi_line_rad = None # Phi drawing angle in radians (is phi -90) self.phi_line_pos = None # End point in pixels of the Phi line self.phi_label = self.add_label("", colour=self.colour, align=wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_BOTTOM) self.theta = None # Theta angle in radians self.theta_radius = None # Radius of the theta circle in pixels self.theta_label = self.add_label("", colour=self.colour, align=wx.ALIGN_CENTER_HORIZONTAL) self.intersection = None # The intersection of the cirle and line in # pixels self.dragging = False # Calculate the characteristic values for the first time self.on_size()
def change_brightness(colour, weight): """ Brighten or darken a given colour See also wx.lib.agw.aui.aui_utilities.StepColour() and Colour.ChangeLightness() from 3.0 colf (tuple of 3+ 0<float<1): RGB colour (and alpha) weight (-1<float<1): how much to brighten (>0) or darken (<0) return (tuple of 3+ 0<float<1): new RGB colour :type colf: tuple :type weight: float :rtype : tuple """ _alpha = None if isinstance(colour, basestring): _col = hex_to_frgb(colour) _alpha = None elif isinstance(colour, tuple): if all([isinstance(v, float) for v in colour]): _col = colour[:3] _alpha = colour[-1] if len(colour) == 4 else None elif all([isinstance(v, int) for v in colour]): _col = rgb_to_frgb(colour[:3]) _alpha = colour[-1] if len(colour) == 4 else None else: raise ValueError("Unknown colour format (%s)" % (colour, )) elif isinstance(colour, wx.Colour): _col = wxcol_to_frgb(colour) _alpha = None else: raise ValueError("Unknown colour format") if weight > 0: # blend towards white f, lim = min, 1.0 else: # blend towards black f, lim = max, 0.0 weight = -weight new_fcol = tuple(f(c * (1 - weight) + lim * weight, lim) for c in _col[:3]) return new_fcol + (_alpha, ) if _alpha is not None else new_fcol
def test_text_view_overlay_size(self): cnvs = canvas.BitmapCanvas(self.panel) self.add_control(cnvs, wx.EXPAND, proportion=1, clear=True) ol = vol.TextViewOverlay(cnvs) cnvs.add_view_overlay(ol) for f in (False, True): msg = "TextViewOverlay sizes test {} flip" size = 0 y = 0 for i in range(10): y += 12 + size size = 10 + i * 3 ol.add_label(msg.format("with" if f else "without"), font_size=size, pos=(0, y), flip=f, colour=hex_to_frgb(gui.FG_COLOUR_EDIT)) test.gui_loop(50) ol.clear_labels()
def test_text_view_overlay_align(self): cnvs = canvas.BitmapCanvas(self.panel) self.add_control(cnvs, wx.EXPAND, proportion=1, clear=True) ol = vol.TextViewOverlay(cnvs) cnvs.add_view_overlay(ol) ol.add_label("TextViewOverlay left", pos=(ol.view_width / 2, 10), colour=hex_to_frgb(gui.FG_COLOUR_EDIT)) test.gui_loop(50) ol.add_label("TextViewOverlay right", pos=(ol.view_width / 2, 26), align=wx.ALIGN_RIGHT, colour=hex_to_frgb(gui.FG_COLOUR_EDIT)) test.gui_loop(50) ol.add_label("TextViewOverlay center", pos=(ol.view_width / 2, 42), align=wx.ALIGN_CENTER_HORIZONTAL, colour=hex_to_frgb(gui.FG_COLOUR_EDIT)) test.gui_loop(50) ol.add_label("|", pos=(ol.view_width / 2, 58), align=wx.ALIGN_CENTER_HORIZONTAL, colour=hex_to_frgb(gui.FG_COLOUR_EDIT)) ol.add_label("|", pos=(ol.view_width / 2, 74), align=wx.ALIGN_CENTER_HORIZONTAL, colour=hex_to_frgb(gui.FG_COLOUR_EDIT)) ol.add_label("Relative to the center", pos=(ol.view_width / 2, 90), align=wx.ALIGN_CENTER_HORIZONTAL, colour=hex_to_frgb(gui.FG_COLOUR_EDIT)) test.gui_loop(50) # Example on how a right aligned label can be kept on the right on resize def realign(evt): for label in ol.labels: label.pos = (ol.view_width / 2, label.pos[1]) evt.Skip() cnvs.Bind(wx.EVT_SIZE, realign) ol.canvas_padding = 0 ol.add_label("top left", pos=(0, 0), align=wx.ALIGN_LEFT, colour=hex_to_frgb(gui.FG_COLOUR_EDIT)) test.gui_loop(50) ol.add_label("top right", pos=(ol.view_width, 0), align=wx.ALIGN_RIGHT, colour=hex_to_frgb(gui.FG_COLOUR_EDIT)) test.gui_loop(50) ol.add_label("bottom left", pos=(0, ol.view_height), align=wx.ALIGN_BOTTOM, colour=hex_to_frgb(gui.FG_COLOUR_EDIT)) test.gui_loop(50) ol.add_label("bottom right", pos=(ol.view_width, ol.view_height), align=wx.ALIGN_RIGHT | wx.ALIGN_BOTTOM, flip=False, colour=hex_to_frgb(gui.FG_COLOUR_EDIT)) test.gui_loop(50) ol.add_label("SHOULD NOT BE SEEN!", pos=(ol.view_width, ol.view_height / 2), align=wx.ALIGN_LEFT, flip=False, colour=hex_to_frgb(gui.FG_COLOUR_EDIT)) test.gui_loop(50) ol.add_label("Visible because of flip", pos=(ol.view_width, ol.view_height / 2), align=wx.ALIGN_LEFT, flip=True, colour=hex_to_frgb(gui.FG_COLOUR_EDIT)) test.gui_loop(50)
def test_text_view_overlay_rotate(self): cnvs = canvas.BitmapCanvas(self.panel) self.add_control(cnvs, wx.EXPAND, proportion=1, clear=True) ol = vol.TextViewOverlay(cnvs) ol.canvas_padding = 0 cnvs.add_view_overlay(ol) # Text should exactly overlap rl = ol.add_label(u"█ you should only see red", pos=(0, 0), font_size=20, deg=0, flip=False, colour=hex_to_frgb(gui.FG_COLOUR_EDIT)) test.gui_loop(50) sl = ol.add_label(u"█ you should only see red", pos=(0, 0), font_size=20, colour=(1, 0, 0), align=wx.ALIGN_LEFT) test.gui_loop(100) self.assertEqual(rl.render_pos, sl.render_pos) ol.clear_labels() ol.add_label(u"█ no rotate", pos=(200, 0), font_size=20, colour=(1, 0, 0), align=wx.ALIGN_LEFT) tl = ol.add_label(u"█ rotate left", pos=(200, 25), font_size=20, deg=0, flip=False, colour=hex_to_frgb(gui.FG_COLOUR_EDIT)) tr = ol.add_label(u"rotate right █", pos=(200, 50), font_size=20, align=wx.ALIGN_RIGHT, deg=0, flip=False, colour=hex_to_frgb(gui.FG_COLOUR_EDIT)) tc = ol.add_label(u"rotate center █", pos=(200, 75), font_size=20, align=wx.ALIGN_CENTRE_HORIZONTAL, deg=0, flip=False, colour=hex_to_frgb(gui.FG_COLOUR_EDIT)) test.gui_loop(1000) for l in (tl, tr, tc): l.deg = 15 test.gui_loop(500) cnvs.Refresh()