Exemple #1
0
 def __init__(self, parent):
     Box.__init__(self, parent)
     
     # init size
     self.position.w = 300
     self.position.h = 40
     
     # Slider specific stuff
     self._fullRange = Range(0,1)
     self._range = Range(0,1)
     self._refRange = Range(0,1) # For sliding
     self._showTicks = False
     
     # Set bgcolor and edge
     self.bgcolor = (0.6, 0.8, 0.6)
     self._frontColor = 0.5, 0.7, 0.9
     self.edgeWidth = 1
     
     # A slider should respond to mouse
     self.hitTest = True
     
     # Create label centered at the box
     self._label = Label(self)
     self._label.position = 0,0,1,1
     self._label.halign = 0
     self._label.bgcolor = None
     
     # State variables
     self._isOver = False
     self._sliderDown = False
     self._sliderRefx = 0.0
     
     # Pool of labels for tickmarks, to reuse them
     self._wobjects = [] # So we can have Text objects
     self._labelPool = {}
     
     # Calculate dots now
     self._SliderCalcDots()
     
     # Create new events
     self._eventSliding = BaseEvent(self)
     self._eventSliderChanged = BaseEvent(self)
     
     # To changes appearance on mouse over
     self.eventEnter.Bind(self._SliderOnEnter)
     self.eventLeave.Bind(self._SliderOnLeave)
     
     # Bind to events
     self.eventMouseDown.Bind(self._SliderOnDown)
     self.eventMouseUp.Bind(self._SliderOnUp)
     self.eventMotion.Bind(self._SliderOnMotion)
     self.eventPosition.Bind(self._SliderCalcDots)
Exemple #2
0
 def __init__(self, parent):
     Box.__init__(self, parent)
     
     # Set color
     self.bgcolor = 'w'
     
     # How soon the mouse snaps to a node
     self._snapWidth = 5
     
     # The currently selected node (or None if nothing is selected)
     self._selectedNode = None
     
     # The nodes and lines of R,G,B and A
     self._allNodes = [Pointset(2) for i in range(4)]
     self._allLines = [Pointset(2) for i in range(4)]
     
     # Init nodes
     for nodes in self._allNodes:
         nodes.append(0,1)
         nodes.append(1,0)
     self._allNodes[3][0,1] = 0 # alpha is completele ones by default
     
     # Init lines
     for line in self._allLines:
         for i in np.linspace(0,1,256):
             line.append(i,1) # the actual map will be 1-line
     
     # Make lines correct now
     for nodes, line in zip(self._allNodes, self._allLines):
         self._NodesToLine(nodes, line)
     
     # The node and line currently in control
     self._nodes = self._allNodes[3]
     self._line = self._allLines[3] 
     
     # Bind events
     self.eventMotion.Bind(self._OnMotion)
     self.eventMouseUp.Bind(self._OnUp)
     self.eventMouseDown.Bind(self._OnDown)
     self.eventDoubleClick.Bind(self._OnDoubleClick)
     self.hitTest = True # enable firing events
 def __init__(self, parent):
     Box.__init__(self, parent)
     
     # Set color
     self.bgcolor = 'w'
     
     # How soon the mouse snaps to a node
     self._snapWidth = 5
     
     # The currently selected node (or None if nothing is selected)
     self._selectedNode = None
     
     # The nodes and lines of R,G,B and A
     self._allNodes = [Pointset(2) for i in range(4)]
     self._allLines = [Pointset(2) for i in range(4)]
     
     # Init nodes
     for nodes in self._allNodes:
         nodes.append(0,1)
         nodes.append(1,0)
     self._allNodes[3][0,1] = 0 # alpha is completele ones by default
     
     # Init lines
     for line in self._allLines:
         for i in np.linspace(0,1,256):
             line.append(i,1) # the actual map will be 1-line
     
     # Make lines correct now
     for nodes, line in zip(self._allNodes, self._allLines):
         self._NodesToLine(nodes, line)
     
     # The node and line currently in control
     self._nodes = self._allNodes[3]
     self._line = self._allLines[3] 
     
     # Bind events
     self.eventMotion.Bind(self._OnMotion)
     self.eventMouseUp.Bind(self._OnUp)
     self.eventMouseDown.Bind(self._OnDown)
     self.eventDoubleClick.Bind(self._OnDoubleClick)
Exemple #4
0
 def __init__(self, parent):        
     Box.__init__(self, parent)
     
     self._label = Label(self, '')
     self._label.bgcolor = ''
     self.eventPosition.Bind(self._OnPositionChange)
     
     # Pool of labels for tickmarks, to reuse them
     self._wobjects = [] # So we can have Text objects
     self._labelPool = {}
     
     # If attached to axes, correct that axes' size
     if isinstance(parent, Axes):
         
         # Init position
         x = parent.position.width + 5
         self.position = x, 0.0, 30, 1.0 
         
         # Keep informed of axes movment
         self.parent.eventPosition.Bind(self._OnAxesPositionChange)
         
         # Correct axes' position
         self.parent.position.Correct(dw=-100) # 30 + 70
Exemple #5
0
    def OnDraw(self):
        Box.OnDraw(self)

        # Create color dict
        colors = {
            self._allLines[0]: (1, 0, 0),
            self._allLines[1]: (0, 1, 0),
            self._allLines[2]: (0, 0, 1),
            self._allLines[3]: (0, 0, 0)
        }

        # prepare scaling
        gl.glPushMatrix()
        w, h = self.position.size
        gl.glScale(w, h, 1)

        # prepare
        gl.glPointSize(7)
        gl.glLineWidth(1)
        gl.glEnable(gl.GL_POINT_SMOOTH)  # round points
        gl.glEnableClientState(gl.GL_VERTEX_ARRAY)

        # Draw lines
        for line in self._allLines:
            if len(line) and line is not self._line:
                gl.glColor(*colors[line])
                gl.glVertexPointerf(line.data)
                gl.glDrawArrays(gl.GL_LINE_STRIP, 0, len(line))

        # Draw the line under control (using a thicker line)
        gl.glColor(*colors[self._line])
        gl.glLineWidth(2)
        gl.glVertexPointerf(self._line.data)
        gl.glDrawArrays(gl.GL_LINE_STRIP, 0, len(self._line))

        # draw nodes
        gl.glColor(*colors[self._line])
        gl.glVertexPointerf(self._nodes.data)
        gl.glDrawArrays(gl.GL_POINTS, 0, len(self._nodes))

        # clean up
        gl.glPopMatrix()
        gl.glDisableClientState(gl.GL_VERTEX_ARRAY)
        gl.glDisable(gl.GL_POINT_SMOOTH)
Exemple #6
0
 def OnDraw(self):
     
     # Draw bg color and edges
     Box.OnDraw(self)
     
     # Margin
     d1 = 2
     d2 = d1+1
     
     # Get normalize limits        
     t1, t2 = self._getNormalizedSliderLimits()
     
     # Get widget shape
     w, h = self.position.size
     
     # Calculate real dimensions of patch
     if w > h:
         x1, x2 = max(d2, t1*w), min(w-d1, t2*w)            
         y1, y2 = d1, h-d2
         #
         dots1 = self._dots1 + Point(x1, 0)
         dots2 = self._dots2 + Point(x2, 0)
         #
         diff = abs(x1-x2)
         #
         self._label.textAngle = 0
     else:            
         x1, x2 = d2, w-d1
         y1, y2 = max(d1, t1*h), min(h-d2, t2*h)
         #
         dots1 = self._dots1 + Point(0, y1)
         dots2 = self._dots2 + Point(0, y2)
         #
         diff = abs(y1-y2)
         #
         self._label.textAngle = -90
     
     # Draw slider bit
     clr = self._frontColor
     gl.glColor(clr[0], clr[1], clr[2], 1.0)            
     #
     gl.glBegin(gl.GL_POLYGON)
     gl.glVertex2f(x1,y1)
     gl.glVertex2f(x1,y2)
     gl.glVertex2f(x2,y2)
     gl.glVertex2f(x2,y1)
     gl.glEnd()
     
     
     # Draw dots
     if True:
         
         # Prepare
         gl.glColor(0,0,0,1)
         gl.glPointSize(1)
         gl.glDisable(gl.GL_POINT_SMOOTH)
         
         # Draw
         gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
         if isinstance(self, RangeSlider) and diff>5:
             gl.glVertexPointerf(dots1.data)
             gl.glDrawArrays(gl.GL_POINTS, 0, len(dots1))
         if diff>5:
             gl.glVertexPointerf(dots2.data)
             gl.glDrawArrays(gl.GL_POINTS, 0, len(dots2))
         gl.glDisableClientState(gl.GL_VERTEX_ARRAY)
     
     
     if self._showTicks:
         
         # Reset color to black
         gl.glColor(0,0,0,1)
         
         # Draw ticks
         if w>h:
             p0 = Point(0, h)
             p1 = Point(w, h)
             delta = Point(0,3)
             halign, valign = 0, 0
             xoffset, yoffset = -8, -2
         else:
             p0 = Point(w, h)
             p1 = Point(w, 0)
             delta = Point(3,0)
             halign, valign = -1, 0
             xoffset, yoffset = 5, -8
         
         # Get tickmarks
         ticks, ticksPos, ticksText = GetTicks(p0, p1, self._fullRange)
         
         newLabelPool = {}
         linePieces = Pointset(2)
         for tick, pos, text in zip(ticks, ticksPos, ticksText):
             pos2 = pos + delta
             
             # Add line piece
             linePieces.append(pos); linePieces.append(pos2)
             
             # Create or reuse label
             if tick in self._labelPool:
                 label = self._labelPool.pop(tick)
             else:
                 label = Label(self, ' '+text+' ')
                 label.bgcolor = ''
             
             # Position label and set text alignment
             newLabelPool[tick] = label
             label.halign, label.valign = halign, valign
             label.position.x = pos2.x + xoffset
             label.position.w = 16
             label.position.y = pos2.y + yoffset
         
         # Clean up label pool
         for label in self._labelPool.values():
             label.Destroy()
         self._labelPool = newLabelPool
         
         # Draw line pieces
         gl.glLineWidth(1)
         gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
         gl.glVertexPointerf(linePieces.data)
         gl.glDrawArrays(gl.GL_LINES, 0, len(linePieces))
         gl.glDisableClientState(gl.GL_VERTEX_ARRAY)