示例#1
0
    def calc_ticks(self):
        """
        Calculates the tick marks' display string, value, and pixel value.

        High values are at the top of the scale, low at the bottom.
        """
        # First we need to determine the values for the ticks.
        pr = self.plot_range[1] - self.plot_range[0]
        spacing = pr / (self.num_ticks - 1)

        tick_values = wm_utils.frange(self.plot_range[0],
                                      self.plot_range[1] + 1, spacing)

        ticks = []
        for tick in tick_values:
            string = "{:.3f}".format(tick)
            value = tick
            # `grad_end_y - 1` so that the bottom tick is aligned correctly.
            pixel = wm_utils.rescale(tick, self.plot_range,
                                     (self.grad_end_y - 1, self.grad_start_y))
            # Putting gradient_end_y as the "low" for rescale makes the
            # high value be at the north end and the low value at the south.
            ticks.append((string, value, pixel))

        return ticks
示例#2
0
    def draw_gradient(self):
        """ Draws the Gradient, painted from North (high) to South (low) """
        #        self.mdc.GradientFillLinear((self.grad_start_x, self.grad_start_y,
        #                                     self.grad_w, self.grad_h),
        #                                    self.high_color,
        #                                    self.low_color,
        #                                    wx.SOUTH,
        #                                    )

        # Remake of the wx.DC.GradientFillLinear wx core function, but uses
        # my own algorithm for determining the colors.
        # Doing so ensures that both the gradient and the die colors match.

        # Save the old pen colors
        old_pen = self.mdc.GetPen()
        old_brush = self.mdc.GetBrush()
        delta = self.grad_h / 255  # height of one shade box
        if delta < 1:
            delta = 1  # max of 255 pts - fractional colors not defined.

        y = self.grad_start_y
        while y <= self.grad_end_y:
            val = wm_utils.rescale(y, (self.grad_start_y, self.grad_end_y),
                                   (1, 0))
            color = self.gradient.get_color(val)
            self.mdc.SetPen(wx.Pen(color))
            self.mdc.SetBrush(wx.Brush(color))
            self.mdc.DrawRectangle(self.grad_start_x, y, self.grad_w,
                                   delta + 1)
            y += delta

        # Set the pen and brush back to what they were
        self.mdc.SetPen(old_pen)
        self.mdc.SetBrush(old_brush)
示例#3
0
    def get_color(self, value):
        """
        Gets a color from the gradient.
        """
        # TODO: determine how wxPython's GradientFillLinear works and use that
        # instead of grabbing the color from the gradient.
        if value > self.plot_range[1]:
            color = self.oor_high_color
        elif value < self.plot_range[0]:
            color = self.oor_low_color
        else:
            try:
                #                pxl = int(wm_utils.rescale(value,
                #                                           self.plot_range,
                #                                           (self.grad_end_y - 1,
                #                                            self.grad_start_y)))
                #
                #                x_pt = self.grad_w // 2 + self.grad_start_x
                #                point = (x_pt, pxl)
                #                color = self.mdc.GetPixelPoint(point)

                # New Method
                pxl = wm_utils.rescale(value, self.plot_range, (0, 1))
                color = self.gradient.get_color(pxl)
                color = wx.Colour(*color)
            except ValueError:
                color = self.invalid_color
        return color
示例#4
0
    def calc_ticks(self):
        """
        Calculates the tick marks' display string, value, and pixel value.

        High values are at the top of the scale, low at the bottom.
        """
        # First we need to determine the values for the ticks.
        pr = self.plot_range[1] - self.plot_range[0]
        spacing = pr / (self.num_ticks - 1)

        tick_values = wm_utils.frange(self.plot_range[0],
                                      self.plot_range[1] + 1,
                                      spacing)

        ticks = []
        for tick in tick_values:
            string = "{:.3f}".format(tick)
            value = tick
            # `grad_end_y - 1` so that the bottom tick is aligned correctly.
            pixel = wm_utils.rescale(tick,
                                     self.plot_range,
                                     (self.grad_end_y - 1, self.grad_start_y))
            # Putting gradient_end_y as the "low" for rescale makes the
            # high value be at the north end and the low value at the south.
            ticks.append((string, value, pixel))

        return ticks
示例#5
0
    def get_color(self, value):
        """
        Gets a color from the gradient.
        """
        # TODO: determine how wxPython's GradientFillLinear works and use that
        # instead of grabbing the color from the gradient.
        if value > self.plot_range[1]:
            color = self.oor_high_color
        elif value < self.plot_range[0]:
            color = self.oor_low_color
        else:
            try:
#                pxl = int(wm_utils.rescale(value,
#                                           self.plot_range,
#                                           (self.grad_end_y - 1,
#                                            self.grad_start_y)))
#
#                x_pt = self.grad_w // 2 + self.grad_start_x
#                point = (x_pt, pxl)
#                color = self.mdc.GetPixelPoint(point)

                # New Method
                pxl = wm_utils.rescale(value,
                                       self.plot_range,
                                       (0, 1))
                color = self.gradient.get_color(pxl)
                color = wx.Colour(*color)
            except ValueError:
                color = self.invalid_color
        return color
示例#6
0
 def on_mouse_right_down(self, event):
     """ Used for debugging """
     print("Right-click - color from get_color()")
     pos = event.GetPosition()
     w, h = self.mdc.GetSize()  # change to gradient area
     if pos[0] < w and pos[1] < h:
         val = wm_utils.rescale(pos[1],
                                (self.grad_start_y, self.grad_end_y - 1),
                                reversed(self.plot_range))
         a = self.get_color(val)
         print("{}\t{}\t{}".format(pos, a, val))
示例#7
0
 def on_mouse_right_down(self, event):
     """ Used for debugging """
     print("Right-click - color from get_color()")
     pos = event.GetPosition()
     w, h = self.mdc.GetSize()       # change to gradient area
     if pos[0] < w and pos[1] < h:
         val = wm_utils.rescale(pos[1],
                                (self.grad_start_y, self.grad_end_y - 1),
                                reversed(self.plot_range))
         a = self.get_color(val)
         print("{}\t{}\t{}".format(pos, a, val))
示例#8
0
    def draw_gradient(self):
        """ Draws the Gradient, painted from North (high) to South (low) """
#        self.mdc.GradientFillLinear((self.grad_start_x, self.grad_start_y,
#                                     self.grad_w, self.grad_h),
#                                    self.high_color,
#                                    self.low_color,
#                                    wx.SOUTH,
#                                    )

        # Remake of the wx.DC.GradientFillLinear wx core function, but uses
        # my own algorithm for determining the colors.
        # Doing so ensures that both the gradient and the die colors match.

        # Save the old pen colors
        old_pen = self.mdc.GetPen()
        old_brush = self.mdc.GetBrush()
        delta = self.grad_h / 255           # height of one shade box
        if delta < 1:
            delta = 1       # max of 255 pts - fractional colors not defined.

        y = self.grad_start_y
        while y <= self.grad_end_y:
            val = wm_utils.rescale(y,
                                   (self.grad_start_y, self.grad_end_y),
                                   (1, 0))
            color = self.gradient.get_color(val)
            self.mdc.SetPen(wx.Pen(color))
            self.mdc.SetBrush(wx.Brush(color))
            self.mdc.DrawRectangle(self.grad_start_x,
                                   y,
                                   self.grad_w, delta + 1)
            y += delta

        # Set the pen and brush back to what they were
        self.mdc.SetPen(old_pen)
        self.mdc.SetBrush(old_brush)