Ejemplo n.º 1
0
    def __init__(self, axes, text):
        Label.__init__(self, axes, text)

        # set textsize and align
        self.halign = 0
        self.fontSize = 12

        # set back color to be transparant
        self.bgcolor = ''

        # set position
        self.position = 0, -20, 1, 15

        # correct axes' position
        dy = -20
        axes.position.Correct(0, -dy, 0, dy)
Ejemplo n.º 2
0
 def __init__(self, axes, text):
     Label.__init__(self, axes, text)
     
     # set textsize and align
     self.halign = 0
     self.fontSize = 12
     
     # set back color to be transparant
     self.bgcolor = ''
     
     # set position
     self.position = 0, -20, 1, 15
     
     # correct axes' position
     dy = -20        
     axes.position.Correct(0, -dy, 0, dy) 
Ejemplo n.º 3
0
    def __init__(self, parent, *args, **kwargs):
        Label.__init__(self, parent, *args, **kwargs)

        # Get an edge
        self.edgeWidth = 1

        # Text is centered by default
        self.halign = 0

        # And changes appearance on mouse over
        self._isOver = False
        self.eventEnter.Bind(self._OnEnter)
        self.eventLeave.Bind(self._OnLeave)

        # Create new event and bind handlers to implement it
        self._eventPress = MouseEvent(self)
        self.eventMouseUp.Bind(self._OnPressDetectUp)
Ejemplo n.º 4
0
    def OnDestroy(self):
        Label.OnDestroy(self)

        # correct axes' position
        axes = self.parent
        if axes:
            dy = 20
            axes.position.Correct(0, -dy, 0, dy)
Ejemplo n.º 5
0
    def __init__(self, parent, *args, **kwargs):
        Label.__init__(self, parent, *args, **kwargs)

        # Get an edge
        self.edgeWidth = 1

        # Text is centered by default
        self.halign = 0

        # And changes appearance on mouse over
        self._isOver = False
        self.eventEnter.Bind(self._OnEnter)
        self.eventLeave.Bind(self._OnLeave)

        # Create new event and bind handlers to implement it
        self._eventPress = MouseEvent(self)
        self.eventMouseUp.Bind(self._OnPressDetectUp)
Ejemplo n.º 6
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)
Ejemplo n.º 7
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
Ejemplo n.º 8
0
 def OnDraw(self):
     
     # Get colormaps that apply
     par = self.parent
     if par is None:
         return
     elif isinstance(par, (BaseFigure, Axes)):
         mapables = par.FindObjects(Colormapable)
     elif isinstance(par, ColormapEditor):
         mapables = par.GetMapables()
     elif isinstance(par, ClimEditor):
         mapables = par.GetMapables()
     else:
         mapables = []
     
     # Get the last one
     mapable = None
     if mapables:
         mapable = mapables[-1]
     
     
     # get dimensions        
     w,h = self.position.size
     
     # Calc map direction
     if w > h:
         texCords = [0,0,1,1]
     else:
         texCords = [1,0,0,1]
     
     
     # draw plane
     if mapable:
         # Use it's colormap texture
         mapable._EnableColormap()
         # Disable alpha channel (by not blending)
         gl.glDisable(gl.GL_BLEND)
         gl.glColor(1.0, 1.0, 1.0, 1.0)
         # Draw quads
         gl.glBegin(gl.GL_QUADS)
         gl.glTexCoord1f(texCords[0]); gl.glVertex2f(0,0)
         gl.glTexCoord1f(texCords[1]); gl.glVertex2f(0,h)
         gl.glTexCoord1f(texCords[2]); gl.glVertex2f(w,h)
         gl.glTexCoord1f(texCords[3]); gl.glVertex2f(w,0)
         gl.glEnd()
         
         # Clean up
         gl.glEnable(gl.GL_BLEND)
         gl.glFlush()
         mapable._DisableColormap()
     
     # prepare                
     gl.glDisable(gl.GL_LINE_SMOOTH)
     
     # draw edges        
     if self.edgeWidth and self.edgeColor:
         clr = self.edgeColor
         gl.glColor(clr[0], clr[1], clr[2], 1.0)
         gl.glLineWidth(self.edgeWidth)
         #
         gl.glBegin(gl.GL_LINE_LOOP)
         gl.glVertex2f(0,0)
         gl.glVertex2f(0,h)
         gl.glVertex2f(w,h)
         gl.glVertex2f(w,0)
         gl.glEnd()
     
     if hasattr(mapable, 'clim'):
         # 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, mapable.clim)
         
         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 list(self._labelPool.values()):
             label.Destroy()
         self._labelPool = newLabelPool
         
         # Draw line pieces
         # prepare
         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)
     # clean up        
     gl.glEnable(gl.GL_LINE_SMOOTH)
Ejemplo n.º 9
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)