Example #1
0
    def __init__(self, parent, wid=wx.ID_ANY, pos=(0, 0), size=wx.DefaultSize,
                 style=wx.NO_BORDER, orientation=wx.HORIZONTAL):

        style |= wx.NO_BORDER
        wx.Panel.__init__(self, parent, wid, pos, size, style)

        self.SetBackgroundColour(parent.GetBackgroundColour())
        self.SetForegroundColour(parent.GetForegroundColour())

        self.tick_colour = wxcol_to_frgb(self.ForegroundColour)

        self._locked = False

        self.Bind(wx.EVT_PAINT, self.on_paint)
        self.Bind(wx.EVT_SIZE, self.on_size)

        self._orientation = orientation
        self._max_tick_width = 32  # Largest pixel width of any label in use
        self._tick_spacing = 120 if orientation == wx.HORIZONTAL else 80
        self._unit = None

        # Explicitly set the min size
        if self._orientation == wx.HORIZONTAL:
            self.SetMinSize((-1, 28))
        else:
            self.SetMinSize((42, -1))

        # The following properties are volatile, meaning that they can change often

        self._value_range = None  # 2 tuple with the minimum and maximum value
        self._tick_list = None  # Lust of 2 tuples, containing the pixel position and value
        self._vtp_ratio = None  # Ratio to convert value to pixel
        self._pixel_space = None  # Number of available pixels

        self.on_size()  # Force a refresh
Example #2
0
 def SetForegroundColour(self, col):
     ret = super(VisualRangeSlider, self).SetForegroundColour(col)
     self.content_color = wxcol_to_frgb(self.GetForegroundColour())
     # FIXME: content_color will have wrong value if currently Disabled
     # Probably has to do with the auto colour calculation for disabled
     # controls
     return ret
Example #3
0
    def __init__(self,
                 parent,
                 wid=-1,
                 pos=(0, 0),
                 size=wx.DefaultSize,
                 style=wx.NO_BORDER,
                 orientation=None):

        style = style | wx.NO_BORDER
        super(AxisLegend, self).__init__(parent, wid, pos, size, style)

        self.SetBackgroundColour(parent.GetBackgroundColour())
        self.SetForegroundColour(parent.GetForegroundColour())

        # Explicitly set the min size
        self.SetMinSize((-1, 40))

        self.Bind(wx.EVT_PAINT, self.on_paint)
        self.Bind(wx.EVT_SIZE, self.on_size)

        self.tick_colour = wxcol_to_frgb(self.ForegroundColour)

        self.ticks = None
        # The guiding distance between ticks in pixels
        self.tick_pixel_gap = 120
        self.orientation = orientation or self.HORIZONTAL

        self._unit = None

        self.on_size(None)
Example #4
0
    def _draw_gradient(self, dc, rect):
        """ Draw a vertical gradient background, using the background colour as a starting point
        """

        if rect.height < 1 or rect.width < 1:
            return

        dc.SetPen(wx.TRANSPARENT_PEN)

        # calculate gradient coefficients

        bck_col = wxcol_to_frgb(self.Parent.GetBackgroundColour())
        if self._mouse_hovering:
            col1 = change_brightness(bck_col, 0.15)
            col2 = change_brightness(bck_col, 0.10)
        else:
            col1 = change_brightness(bck_col, 0.10)
            col2 = bck_col

        r1, g1, b1 = col1
        r2, g2, b2 = col2
        rstep = (r2 - r1) / rect.height
        gstep = (g2 - g1) / rect.height
        bstep = (b2 - b1) / rect.height

        rf, gf, bf = col1
        for y in range(rect.y, rect.y + rect.height):
            cur_col = (rf * 255, gf * 255, bf * 255)
            dc.SetBrush(wx.Brush(cur_col, wx.BRUSHSTYLE_SOLID))
            dc.DrawRectangle(rect.x, rect.y + (y - rect.y), rect.width, rect.height)
            rf = rf + rstep
            gf = gf + gstep
            bf = bf + bstep
Example #5
0
    def __init__(self, parent, wid=-1, pos=(0, 0), size=wx.DefaultSize,
                 style=wx.NO_BORDER, orientation=None):

        style = style | wx.NO_BORDER
        super(AxisLegend, self).__init__(parent, wid, pos, size, style)

        self.SetBackgroundColour(parent.GetBackgroundColour())
        self.SetForegroundColour(parent.GetForegroundColour())

        # Explicitly set the min size
        self.SetMinSize((-1, 40))

        self.Bind(wx.EVT_PAINT, self.on_paint)
        self.Bind(wx.EVT_SIZE, self.on_size)

        self.tick_colour = wxcol_to_frgb(self.ForegroundColour)

        self.ticks = None
        # The guiding distance between ticks in pixels
        self.tick_pixel_gap = 120
        self.orientation = orientation or self.HORIZONTAL

        self._unit = None

        self.on_size(None)
Example #6
0
    def _draw_gradient(self, dc, rect):
        """ Draw a vertical gradient background, using the background colour
        as a starting point.
        """

        if rect.height < 1 or rect.width < 1:
            return

        dc.SetPen(wx.TRANSPARENT_PEN)

        # calculate gradient coefficients

        bck_col = wxcol_to_frgb(self.parent.GetBackgroundColour())
        if self._mouse_is_over:
            col1 = change_brightness(bck_col, 0.15)
            col2 = change_brightness(bck_col, 0.10)
        else:
            col1 = change_brightness(bck_col, 0.10)
            col2 = bck_col

        r1, g1, b1 = col1
        r2, g2, b2 = col2
        rstep = (r2 - r1) / rect.height
        gstep = (g2 - g1) / rect.height
        bstep = (b2 - b1) / rect.height

        rf, gf, bf = col1
        for y in range(rect.y, rect.y + rect.height):
            currCol = (rf * 255, gf * 255, bf * 255)
            dc.SetBrush(wx.Brush(currCol, wx.SOLID))
            dc.DrawRectangle(rect.x, rect.y + (y - rect.y), rect.width,
                             rect.height)
            rf = rf + rstep
            gf = gf + gstep
            bf = bf + bstep
Example #7
0
    def __init__(self, parent, wid=wx.ID_ANY, value=(0.0, 1.0), min_val=0.0,
                 max_val=1.0, size=(-1, -1), pos=wx.DefaultPosition,
                 style=wx.NO_BORDER, name="VisualRangeSlider"):

        style |= wx.NO_FULL_REPAINT_ON_RESIZE
        super(VisualRangeSlider, self).__init__(parent, wid, pos, size, style)

        self.content_color = wxcol_to_frgb(self.GetForegroundColour())
        self.select_color = (1.0, 1.0, 1.0, self.sel_alpha)

        if size == (-1, -1): # wxPython follows this too much to always do it
            self.SetMinSize((-1, 40))

        self.name = name
        self.content_list = []

        # Two separate buffers are used, one for the 'complex' content
        # background rendering and one for the selection.
        self._content_buffer = None
        self._buffer = None

        # The minimum and maximum values
        self.min_value = min_val
        self.max_value = max_val

        # The selected range (within self.range)
        self.value = value
        # Selected range in pixels
        self.pixel_value = (0, 0)

        # Layout Events
        self.Bind(wx.EVT_PAINT, self.OnPaint)
        self.Bind(wx.EVT_SIZE, self.OnSize)

        # Data events
        self.Bind(wx.EVT_MOTION, self.OnMotion)
        self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
        self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
        self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave)
        self.Bind(wx.EVT_ENTER_WINDOW, self.OnEnter)
        self.Bind(wx.EVT_MOUSE_CAPTURE_LOST, self.OnCaptureLost)

        self.mode = None

        self.drag_start_x = None # px : position at the beginning of the drag
        self.drag_start_pv = None # pixel_value at the beginning of the drag

        self._percentage_to_val = self._linear_prec_to_val
        self._val_to_percentage = self._linear_val_to_perc

        self._SetValue(self.value) # will update .pixel_value and check range

        # OnSize called to make sure the buffer is initialized.
        # This might result in OnSize getting called twice on some
        # platforms at initialization, but little harm done.
        self.OnSize(None)
Example #8
0
    def __init__(self, parent, wid=wx.ID_ANY, size=(-1, -1),
                 pos=wx.DefaultPosition, style=wx.NO_BORDER, name="Histogram"):
        style |= wx.NO_FULL_REPAINT_ON_RESIZE
        super(Histogram, self).__init__(parent, wid, pos, size, style)

        if size == (-1, -1): # wxPython follows this too much to always do it
            self.SetMinSize((-1, 40))

        self._content_buffer = None
        self.content_list = []
        self.content_color = wxcol_to_frgb(self.GetForegroundColour())

        self.Bind(wx.EVT_SIZE, self.OnSize)
        self.Bind(wx.EVT_PAINT, self.OnPaint)

        self.OnSize(None)
Example #9
0
 def SetForegroundColour(self, col):  #pylint: disable=W0221
     ret = super(Histogram, self).SetForegroundColour(col)
     self.content_color = wxcol_to_frgb(self.GetForegroundColour())
     return ret