Пример #1
0
class ControlPointBar(DirectWaitBar):
    def __init__(self, barColor=(255,0,0,1), pos=(1.0,0,0.9)): 
        self.bar = DirectWaitBar(pos = pos, barColor = barColor, text="",
        value=70, range=100, frameSize=(-0.3,0.3,0,0.03), frameColor=(0,0,255,1))
        

    def setValue(self, value):
        self.bar['value'] = float(value)
        self.setPos((0,0,0))

    def hide(self):
        self.bar.hide()
    
    # to make inherited setPos available for this object
    def show(self):
        self.bar.show()
    
    # to make inherited setPos available for this object
    def setPos(self, pos):
        self.bar.setPos(pos)
Пример #2
0
class ValueBar(rootsim.RootSim):
    """Display Value in a loading bar fashion"""
    def __init__(self, path, scale=0.5, extraText='', decimal=0, showOverValues=1):
        rootsim.RootSim.__init__(self, path, scale=scale)
        self.extraText = extraText
        self.currentValue = 0.0
        self.maxValue = 0.0
        self.barValue = 0.0
        self.scale = scale
        self.decimal = decimal
        self.showOverValues = showOverValues
        self.myText = ''
        self.textOverValue = None
        self.myBar = DirectWaitBar(text = '0 / 0', scale = scale, 
                                   frameColor = globals.colors['guiblue2'],
                                   borderWidth = (0.01, 0.01))
        self.barColor = globals.colors['guiblue1']
    
    def setMyPosition(self, x, y, z):
        self.x = x
        self.y = y
        self.z = z
        self.myBar.setPos(x, y, z)
        if self.textOverValue != None:
            barWidth = self.myBar.getWidth()*self.scale/2.0
            barHeight = self.myBar.getHeight()*self.scale/3.0
            self.textOverValue.setMyPosition(x+barWidth, y, z-barHeight)
    
    def updateMyBar(self):
        """Update the bar on the screen"""
        self.myBar['text'] = self.myText
        self.myBar['value'] = self.barValue
        self.myBar['barColor'] = self.barColor
    
    def setMyValues(self, currentValue, maxValue):
        self.currentValue = float(currentValue)
        self.maxValue = float(maxValue)
        self.setMyText()
        self.setBarValue()
        self.updateMyBar()
        self.writeOverValue()
    
    def setMyText(self):
        if self.currentValue == self.maxValue:
            if self.decimal == 1:
                self.myText = '%s' % self.currentValue
            else:
                self.myText = '%d' % self.currentValue
        else:
            if self.decimal == 1:
                self.myText = '%s / %s' % (self.currentValue, self.maxValue)
            else:
                self.myText = '%d / %d' % (self.currentValue, self.maxValue)
        self.myText = self.myText + ' %s' % self.extraText
    
    def setBarValue(self):
        """Bar Value can only be from 0 to 100"""
        if self.currentValue > self.maxValue:
            self.barValue = 100
        elif self.maxValue == 0:
            self.barValue = 0
        else:
            self.barValue = (self.currentValue / self.maxValue) * 100.0
    
    def setColor(self, color):
        """set the text color = Vec4(red, green, blue, alpha)"""
        self.barColor = color
        self.updateMyBar()
    
    def writeOverValue(self):
        """Set the textOverValue text if currentValue > maxValue"""
        if self.showOverValues == 1:
            value = self.currentValue - self.maxValue
            self.clearText(self.textOverValue)
            if int(value) > 0:
                self.textOverValue = textonscreen.TextOnScreen(self.path, '+ %d' % value,
                                                               self.scale/8.0, parent=aspect2d)
                self.textOverValue.writeTextToScreen(self.x, self.y, self.z)
                self.textOverValue.setColor(globals.colors['guiyellow'])
    
    def clearText(self, textSim):
        """If sim exists remove from panda"""
        if textSim != None:
            textSim.destroy()
            textSim = None
    
    def destroy(self):
        """remove Bar, text"""
        self.myBar.destroy()
        self.clearText(self.textOverValue)