class GridEventProcessor(EventProcessor): def initialize(self): self.register('Initialize', self.update_axes) self.register('Pan', self.update_axes) self.register('Zoom', self.update_axes) self.register('Reset', self.update_axes) self.register('Animate', self.update_axes) self.register(None, self.update_axes) def update_axes(self, parameter): nav = self.get_processor('navigation') # print nav if not nav: return viewbox = nav.get_viewbox() # nvb = nav.normalization_viewbox nvb = getattr(self.parent.paint_manager, 'normalization_viewbox', None) # print nvb # initialize the normalizer if nvb is not None: if not hasattr(self, 'normalizer'): # normalization viewbox self.normalizer = DataNormalizer() self.normalizer.normalize(nvb) x0, y0, x1, y1 = viewbox x0 = self.normalizer.unnormalize_x(x0) y0 = self.normalizer.unnormalize_y(y0) x1 = self.normalizer.unnormalize_x(x1) y1 = self.normalizer.unnormalize_y(y1) viewbox = (x0, y0, x1, y1) # print nvb, viewbox text, coordinates, n = get_ticks_text(*viewbox) if nvb is not None: coordinates[:,0] = self.normalizer.normalize_x(coordinates[:,0]) coordinates[:,1] = self.normalizer.normalize_y(coordinates[:,1]) # here: coordinates contains positions centered on the static # xy=0 axes of the screen position = np.repeat(coordinates, 2, axis=0) position[:2 * n:2,1] = -1 position[1:2 * n:2,1] = 1 position[2 * n::2,0] = -1 position[2 * n + 1::2,0] = 1 axis = np.zeros(len(position)) axis[2 * n:] = 1 self.set_data(visual='grid_lines', position=position, axis=axis) coordinates[n:, 0] = -.95 coordinates[:n, 1] = -.95 t = "".join(text) n1 = len("".join(text[:n])) n2 = len("".join(text[n:])) axis = np.zeros(n1+n2) axis[n1:] = 1 self.set_data(visual='grid_text', text=text, coordinates=coordinates, axis=axis)
class GridEventProcessor(EventProcessor): def initialize(self): self.register('Initialize', self.update_axes) self.register('Pan', self.update_axes) self.register('Zoom', self.update_axes) self.register('Reset', self.update_axes) self.register('Animate', self.update_axes) self.register(None, self.update_axes) def update_axes(self, parameter): nav = self.get_processor('navigation') # print nav if not nav: return viewbox = nav.get_viewbox() # nvb = nav.normalization_viewbox nvb = getattr(self.parent.paint_manager, 'normalization_viewbox', None) # print nvb # initialize the normalizer if nvb is not None: if not hasattr(self, 'normalizer'): # normalization viewbox self.normalizer = DataNormalizer() self.normalizer.normalize(nvb) x0, y0, x1, y1 = viewbox x0 = self.normalizer.unnormalize_x(x0) y0 = self.normalizer.unnormalize_y(y0) x1 = self.normalizer.unnormalize_x(x1) y1 = self.normalizer.unnormalize_y(y1) viewbox = (x0, y0, x1, y1) # print nvb, viewbox text, coordinates, n = get_ticks_text(*viewbox) if nvb is not None: coordinates[:, 0] = self.normalizer.normalize_x(coordinates[:, 0]) coordinates[:, 1] = self.normalizer.normalize_y(coordinates[:, 1]) # here: coordinates contains positions centered on the static # xy=0 axes of the screen position = np.repeat(coordinates, 2, axis=0) position[:2 * n:2, 1] = -1 position[1:2 * n:2, 1] = 1 position[2 * n::2, 0] = -1 position[2 * n + 1::2, 0] = 1 axis = np.zeros(len(position)) axis[2 * n:] = 1 self.set_data(visual='grid_lines', position=position, axis=axis) coordinates[n:, 0] = -.95 coordinates[:n, 1] = -.95 t = "".join(text) n1 = len("".join(text[:n])) n2 = len("".join(text[n:])) axis = np.zeros(n1 + n2) axis[n1:] = 1 self.set_data(visual='grid_text', text=text, coordinates=coordinates, axis=axis)