Exemplo n.º 1
0
class PieChart (QGraphicsView):
    def __init__(self,parent,total_value):
        super(PieChart,self).__init__(parent)
        self.my_scene = QGraphicsScene()
        #self.my_scene.setSceneRect(self.sceneRect())
        self.setScene(self.my_scene)
        #self.setBackgroundBrush(QBrush(QtCore.Qt.black, QtCore.Qt.SolidPattern));
        self.total_value = total_value

        self.initialize = False
        self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.margin = {'top':10,'bottom':10,'left':10,'right':10}        

        self.space = 30


        self.pie_items = []

    def setTotal (self, total):
        self.total_value = total
#     def setData (self,list_item):
# 
#         rect = QGraphicsRectItem(self.sceneRect())
#         rect.setBrush(QColor("red"))
#         self.scene().addItem(rect)
    
    def setData (self,list_items):
        size = min(self.frameSize().width()/2.0,self.frameSize().height())
        self.size_pie = QSize(size,size)
        #print ('size pie ',self.size_pie)
        if self.initialize == False:
            self.c_box = QComboBox()
            self.c_box.addItem("all")
            self.c_box.addItem("alive")
            self.c_box.addItem("dead")
            self.c_box.currentIndexChanged.connect(self.update)
            proxy = self.my_scene.addWidget(self.c_box)
            x = self.size_pie.width()+ self.space
            proxy.setPos(QPointF(x,self.margin['top']))    
            self.initialize = True

        self.data = list_items
        self.update()

    def update(self):

        restant = 360
        i = 0
        #self.my_scene.clear()
        for item in self.pie_items :
            self.my_scene.removeItem(item)
        self.pie_items = []
        self.scene().setSceneRect(QRectF(0,0,self.frameSize().width(),self.frameSize().height()))
        #print ('size',self.scene().sceneRect())
        #proxy = QGraphicsProxyWidget ()

        for item in self.data :
            if (i==len(self.data)-1 ):
                angle = restant
            else:
                try : 
                    angle = int(360*item[self.c_box.currentText()]/self.total_value[self.c_box.currentText()])
                except ZeroDivisionError:
                    angle = 0 
                    
            ellipse = Section(0,0,self.size_pie.width(),self.size_pie.height())

            y = (self.parent().size().height()-self.size_pie.height())/2.0
            x_pie = ((self.parent().size().width()/2.0)-self.size_pie.height())/2.0
            ellipse.setPos(x_pie,y)
 
            ellipse.setStartAngle(16*(360-restant))
            ellipse.setSpanAngle(angle*16)
            ellipse.setBrush(item['color'])
            self.my_scene.addItem(ellipse)
            self.pie_items.append(ellipse)
            # text pourcentage a afficher dans les portions de disque
            try :
                v = (item[self.c_box.currentText()]/self.total_value[self.c_box.currentText()])*100
            except ZeroDivisionError :
                v = 0
            text = QGraphicsSimpleTextItem("{0:5.2f}".format(v)+"%")
            trans = QTransform().translate(x_pie+self.size_pie.width()/2.0,y+self.size_pie.height()/2.0).rotate(((360-restant)+angle/2.0)*-1)
            pts = trans.map(QPointF(self.size_pie.width()/3.0,0))
            text.setPos(pts.x(),pts.y())
            self.my_scene.addItem(text)            
            self.pie_items.append(text)
            
            #libelle 
            rect = QGraphicsRectItem(0,0,10,10)
            x = x_pie + self.size_pie.width()+ self.space 
            interval_height = (self.parent().size().height()-self.margin['top']-self.margin['bottom'])/(len(self.data)+1)
            rect.setPos(QPointF(x,self.margin['top']+((i+1)*interval_height)))
            rect.setBrush(item['color'])
            self.my_scene.addItem(rect)
            self.pie_items.append(rect)
            text = QGraphicsSimpleTextItem(item['label']+ " ("+str(int(item[self.c_box.currentText()]))+")")
            pts = rect.pos()
            transform = QTransform().translate(30, 0)
            pts = transform.map(pts)
            text.setPos(pts)            
            self.my_scene.addItem(text)
            self.pie_items.append(text)
            restant = restant - angle
            i +=1

     #   self.fitInView(self.scene.sceneRect())
Exemplo n.º 2
0
class GUI(QtWidgets.QMainWindow):
    
    def __init__(self,game):
        super().__init__()
        self.setCentralWidget(QtWidgets.QWidget()) # QMainWindown must have a centralWidget to be able to add layouts
        self.horizontal = QtWidgets.QHBoxLayout() # Horizontal main layout
        self.centralWidget().setLayout(self.horizontal)
        self.btn1 = QPushButton("New wave",self)
        self.btn1.move(660,600)
        self.btn1.clicked.connect(self.activateWave)        
        
        items = ("level1", "level2", "level3", "level4","level5")
        item, ok = QInputDialog.getItem(self, "Select level","levels", items, 0, False)
        self.game = game
        self.game.loadMap(item)
        #self.start.addButton(QAbstractButton, QMessageBox_ButtonRole)
        self.map = game.map.map
        
        self.initWindow()
        self.loadTextures()

        self.drawMap()
        self.drawHp()
        self.squares()
        self.placeButtons()
        self.drawPlayerStats()
        self.drawTowerPrices()
        self.updateGame()
        self.placeTower = 0 # 0 for not active, 1 for arrow, 2 for gun and 3 for laser  
        self.timer = QtCore.QTimer()
        self.timer.start(50) # Milliseconds
        self.timer.timeout.connect(self.updateGame)
    
    def initWindow(self):
        self.setGeometry(40, 40, 800, 640)
        self.setWindowTitle('Tower Defense')
        #self.setFixedSize(self.size())
        self.show()
        self.showFullScreen()
        # Add a scene for drawing 2d objects
        self.scene = QGraphicsScene(self)
        self.scene.setSceneRect(0, 0, 640, 640)

        # Add a view for showing the scene
        self.view = QGraphicsView(self.scene, self)
        self.view.show()
        self.view.setAlignment(QtCore.Qt.AlignTop | QtCore.Qt.AlignLeft)
        self.view.adjustSize()
        self.horizontal.addWidget(self.view)
    
    def closeGui(self):
        self.close()

    
    def drawMap(self):
        dark = QColor(20,20,20)
        light = QColor(211,211,211)
        brush = QBrush()
        pen = QPen()
        pen.setColor(QColor(0, 0, 0, 75))
        # Create graphic objects for map squares
        for y in range(0,len(self.map)):
            for x in range(0,len(self.map[y])):
                shape = QGraphicsRectItem(self.map[y][x].size*x,self.map[y][x].size*y,self.map[y][x].size,self.map[y][x].size)
                if self.map[y][x].isWall:
                    brush.setTexture(self.grass)
                else:
                    brush.setTexture(self.gravel)
                self.map[y][x].shape = shape
                shape.setPen(pen)
                shape.setBrush(brush)
                self.scene.addItem(shape)
    
    def loadTextures(self):
        self.grass = QPixmap("grass.png")
        self.gravel = QPixmap("gravel2.png")
        self.arrow = QPixmap("arrow.png")
        self.kappa = QPixmap("kappa.png")
        self.miro = QPixmap("pikkumiro.png")
        self.heart = QPixmap("heart.png")

 
    def visualizeBfs(self):
        shape = QGraphicsRectItem(self.square.size*self.square.coord.x,self.square.size*self.square.coord.y,
                                  self.square.size,self.square.size)
        shape.setBrush(QColor(0,255,0))
        self.scene.addItem(shape)
        self.update()
        self.square = self.square.cameFrom
        
    def drawEnemies(self):
        # Go through enemies in the game and draw them
        for enemy in self.game.enemies:
            if enemy.shape == None:
                if enemy.etype == 0:
                    shape = QGraphicsEllipseItem(0,0,20,20)
                    enemy.r = 10
                elif enemy.etype == 1:
                    shape = QGraphicsEllipseItem(0,0,30,30)
                    enemy.r = 15
                elif enemy.etype == 2:
                    shape = QGraphicsEllipseItem(0,0,40,40)
                    enemy.r = 20
                shape.setBrush(QColor(0,255,0))
                shape.setX(enemy.x)
                shape.setY(enemy.y)
                self.scene.addItem(shape)
                enemy.shape = shape
            ratio = enemy.hp/enemy.maxHp
            enemy.shape.setBrush(QColor((1-ratio)*255,ratio*255,0))
            enemy.shape.setX(enemy.x-enemy.r)
            enemy.shape.setY(enemy.y-enemy.r)
            if enemy.shape.collidesWithItem(self.game.endSquare.shape):
                if self.game.player.lose == False:
                    self.game.player.hp -= 1
                    self.scene.removeItem(self.health.pop())
                enemy.goal=True
            if enemy.dead:
                if enemy.etype == 0:
                    self.game.player.getGold(10)
                    self.game.player.getPoints(100)
                elif enemy.etype == 1:
                    self.game.player.getGold(50)
                    self.game.player.getPoints(500)
                elif enemy.etype == 2:
                    self.game.player.getGold(120)
                    self.game.player.getPoints(1000)
            if enemy.dead or enemy.goal:
                self.scene.removeItem(enemy.shape)
                self.game.enemies.remove(enemy)
            self.update()
    
    def drawTowers(self):
        for tower in self.game.towers:
            if tower.shape == None:
                shape = QGraphicsRectItem(0,0,40,40)
                shape.setX(tower.x)
                shape.setY(tower.y)
                if tower.ttype == 1:
                    shape.setBrush(QColor(120,100,20))
                elif tower.ttype == 2:
                    shape.setBrush(QColor(70,70,50))
                elif tower.ttype ==3:
                    shape.setBrush(QColor(20,20,20))
                self.scene.addItem(shape)
                tower.shape = shape
                #r = QGraphicsEllipseItem(tower.x+20-tower.range,tower.y+20-tower.range,tower.range*2,tower.range*2)
                #self.scene.addItem(r)
            if tower.ttype == 3:
                for enemy in self.game.enemies:
                    if tower.canFire(enemy):
                        if enemy in tower.firesAt:
                            i = tower.firesAt.index(enemy)
                            tower.lines[i].setLine(tower.x+20,tower.y+20,enemy.x,enemy.y)
                        else:
                            line = QGraphicsLineItem(tower.x+20,tower.y+20,enemy.x,enemy.y)
                            line.setPen(QColor(255,0,0))
                            self.scene.addItem(line)
                            tower.firesAt.append(enemy)
                            tower.lines.append(line)
                        enemy.hp -= tower.damage
                        if enemy.hp <= 0:
                            i = tower.firesAt.index(enemy)
                            self.scene.removeItem(tower.lines[i])
                    else:
                        if enemy in tower.firesAt:
                            i = tower.firesAt.index(enemy)
                            self.scene.removeItem(tower.lines[i])
    
    def drawProjectiles(self):
        for projectile in self.game.projectiles:
            if projectile.shape == None:
                if projectile.ptype == 1:
                    shape = QGraphicsPixmapItem(self.arrow)
                elif projectile.ptype == 2:
                    shape = QGraphicsEllipseItem(0,0,5,5)
                    shape.setBrush(QColor(0,0,0))
                shape.setX(projectile.x)
                shape.setY(projectile.y)
                self.scene.addItem(shape)
                projectile.shape = shape
            projectile.shape.setX(projectile.x)
            projectile.shape.setY(projectile.y)
            if projectile.ptype == 1:
                projectile.shape.setRotation(projectile.rotation)
            if projectile.shape.collidesWithItem(projectile.enemy.shape):
                projectile.enemy.getHit(projectile.damage)
                self.scene.removeItem(projectile.shape)
                self.game.projectiles.remove(projectile)
            self.update()
    
    def updateGame(self):
        self.game.updateAll()
        self.checkButtons()
        self.drawEnemies()
        self.drawTowers()
        self.drawProjectiles()
        self.checkGameOver()
        self.updatePlayerStats()
        if self.game.over:
            box = QMessageBox()
            box.setWindowTitle("Game Over")
            box.setText("You got "+str(self.game.player.points)+" points.")
            box.setStandardButtons(QMessageBox.Ok)
            box.buttonClicked.connect(self.closeGui)
            retval = box.exec_()
        
    def mousePressEvent(self, event):
        if self.placeTower != 0:  
            pos = event.pos()
            x = floor(pos.x()/self.game.squareSize)
            y = floor(pos.y()/self.game.squareSize)
            self.game.addTower(x,y,self.placeTower)
            self.placeTower = 0
    
    def placeButtons(self):
        for b in self.game.buttons:
            self.scene.addItem(b)
    
    def checkButtons(self):
        for b in self.game.buttons:
            if b.activated and b.type == 1:
                self.placeTower = 1
            elif b.activated and b.type ==2:
                self.placeTower = 2
            elif b.activated and b.type == 3:
                self.placeTower = 3
        if self.game.buttons[0].activated == False and self.game.buttons[1].activated == False and self.game.buttons[2].activated == False:
            self.placeTower = 0
    
    def squares(self):
        shape2 = QGraphicsRectItem(0,0,40,40)
        shape2.setX(self.game.endSquare.x)
        shape2.setY(self.game.endSquare.y)
        shape2.setBrush(QColor(0,0,200,0))
        shape2.setPen(QColor(0,0,0,0))
        self.scene.addItem(shape2)
        self.game.endSquare.shape = shape2
        
        self.update()
    
    def drawHp(self):
        self.health = []
        hpcount = self.game.player.hp
        for i in range(0,hpcount):
            heart = QGraphicsPixmapItem(self.heart)
            heart.setY(660)
            heart.setX(20+i*50)
            self.scene.addItem(heart)
            self.health.append(heart)
        
    
    def activateWave(self):
        if not self.game.wave.active:
            self.game.wave.active = True
            self.game.wave.generateEnemies()
    
    def checkGameOver(self):
        if self.game.player.lose:
            self.game.over = True
    
    def drawPlayerStats(self):
        font = QFont("Arial",20)
        self.gold = QLabel("Gold: " + str(self.game.player.gold))
        self.gold.setFont(font)
        self.gold.move(QPoint(545,660))
        self.points = QLabel("Points: " + str(self.game.player.points))
        self.points.setFont(font)
        self.points.move(QPoint(545,705))
        self.wavenum = QLabel("Wave number: " + str(self.game.wave.level))
        self.wavenum.setFont(font)
        self.wavenum.move(QPoint(20,705))
        self.scene.addWidget(self.wavenum)
        self.scene.addWidget(self.gold)
        self.scene.addWidget(self.points)
    
    
    def updatePlayerStats(self):
        self.gold.setText("Gold: "+str(self.game.player.gold))
        self.points.setText("Points: "+str(self.game.player.points))
        self.wavenum.setText("Wave number: " + str(self.game.wave.level))
        wg = self.gold.fontMetrics().width(self.gold.text())
        wp = self.points.fontMetrics().width(self.points.text())
        wn = self.wavenum.fontMetrics().width(self.wavenum.text())
        self.wavenum.setFixedWidth(wn)
        self.gold.setFixedWidth(wg)
        self.points.setFixedWidth(wp)
    
    def drawTowerPrices(self):
        font = QFont("Arial",15)
        arrowtower = QLabel("50")
        arrowtower.setFont(font)
        arrowtower.move(QPoint(650,70))
        self.scene.addWidget(arrowtower)

        guntower = QLabel("100")
        guntower.setFont(font)
        guntower.move(QPoint(650,150))
        self.scene.addWidget(guntower)

        lasertower = QLabel("500")
        lasertower.setFont(font)
        lasertower.move(QPoint(650,230))
        self.scene.addWidget(lasertower)
        
        

        
        
            

        
Exemplo n.º 3
0
class MatplotTinderUI(QWidget, UI):

    def __init__(self, parent=None):
        super().__init__(parent)

        matplot_widget = FigureCanvas(Figure())
        self._ax = matplot_widget.figure.subplots()

        self._scene = QGraphicsScene()
        self.matplot_graphics_widget = self._scene.addWidget(matplot_widget)
        self.matplot_graphics_widget.setParent(self)


        self.red_brush = QBrush(Qt.SolidPattern)
        self.red_brush.setColor(QColor(255, 0, 0, 50))

        self.pen = QPen()
        self.pen.setColor(QColor(0, 0, 0, 0))


        self._scene.addEllipse(0, self.height()/2, self.height()/2, self.height(), QPen(Qt.NoPen), self.red_brush)




        self._view = QGraphicsView(self._scene)
        self._view.setGeometry(250, 250, 500, 500)

        layout = QVBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(self._view)
        self.setLayout(layout)

        id = QGestureRecognizer.registerRecognizer(PanGestureRecognizer())
        self.grabGesture(id)

    def show_image(self, img, cmap=Defaults.cmap, interpolation='gaussian'):
        self._ax.clear()
        self._ax.axis('off')
        self._ax.imshow(img.data, cmap=cmap, interpolation=interpolation)
        self._ax.figure.canvas.draw()

    def connect_multi_classification_listener(self, action):
        pass

    def connect_single_classification_listener(self, action):
        pass

    def connect_skip_classification_listener(self, action):
        self.skip = action

    def event(self, event):
        if event.type() == QEvent.Gesture and event.gesture(Qt.PanGesture):
            self.pan_triggered(event.gesture(Qt.PanGesture))
        else:
            super().event(event)
        return True

    def pan_triggered(self, pan_gesture):
        delta = pan_gesture.delta()
        self.matplot_graphics_widget.setPos(self.matplot_graphics_widget.x() + delta.x(), self.matplot_graphics_widget.y() + delta.y())
        if pan_gesture.state() == Qt.GestureFinished:
            # self._check_if_classified()
            self.reset()

    def mouseDoubleClickEvent(self, a0):
        # self.reset()
        print('mouseclick')
        self.skip()

    def reset(self):
        self.animation = QPropertyAnimation(self.matplot_graphics_widget, b'pos')
        self.animation.setStartValue(self.matplot_graphics_widget.pos())
        self.animation.setEndValue(QPointF(100, 100))
        self.animation.setDuration(100)
        self.animation.start()

    def paintEvent(self, event):
        self.matplot_graphics_widget.setRotation(self.get_rotation())
        self.update()

    def get_rotation(self):
        pic = [self.matplot_graphics_widget.x(), -self.matplot_graphics_widget.y()]
        pivot = [0, -500]
        v1 = np.subtract(pic, pivot)
        v2 = np.subtract([0, 0], pivot)
        a = np.arccos(np.divide(np.abs(np.dot(v1, v2)), (np.linalg.norm(v1) * np.linalg.norm(v2))))
        if self.matplot_graphics_widget.x() < 0:
            return -a * 10
        return a * 10
Exemplo n.º 4
0
class HistoChart (QGraphicsView):
    def __init__(self,parent,size=QSize(400,400)):
        super(HistoChart,self).__init__(parent)
        self.my_scene = QGraphicsScene()
        #self.my_scene.setSceneRect(self.sceneRect())
        self.setScene(self.my_scene)
        #self.setBackgroundBrush(QBrush(QtCore.Qt.black, QtCore.Qt.SolidPattern));
        
        
        self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.size_text_width = -1
        self.margin = {'top':10,'bottom':10,'left':10,'right':10}        
        self.initialize = False
        self.max_length_text = 10
        self.histo_items = []


    
    def setData (self,list_items):
        size = min(self.frameSize().width()/2.0,self.frameSize().height())
        self.size_pie = QSize(size,size)
        self.data = list_items
        if self.initialize == False:
            self.c_box = QComboBox()
            self.c_box.addItem("warrior")
            self.c_box.addItem("rank")
            self.c_box.addItem("power")
            self.c_box.currentIndexChanged.connect(self.update)
            proxy = self.my_scene.addWidget(self.c_box)
            
            proxy.setPos(QPointF(0.0,self.margin['top']))    
            self.margin['top']+=self.c_box.height()
            self.initialize = True
        self.update()

    def update(self):

        
        i = 0
        #self.my_scene.clear()
        for item in self.histo_items :
            self.my_scene.removeItem(item)
        self.histo_items = []
        self.scene().setSceneRect(QRectF(0,0,self.frameSize().width(),self.frameSize().height()))

        max = -1
        for value in self.data.values():
            if value[self.c_box.currentText()] > max:
                max = value[self.c_box.currentText()]


        size_text_number = QGraphicsTextItem(str(max)).boundingRect().width()+10
        interval= self.parent().size().height()-self.margin['top']-self.margin['bottom']
        interval = interval /len(self.data)
        

        temp = "aaaaaaaaaaaaaaaaa"
        if len(temp)> self.max_length_text:
            data = temp[:self.max_length_text]+"."
        else :
            data = temp
        self.size_text_width = QGraphicsTextItem(data).boundingRect().width()+10
        #print ('width:',self.size_text_width)
        horizontal_size = self.parent().size().width()- self.margin['left']- self.margin['right']-self.size_text_width- size_text_number
        try:
            ratio = horizontal_size/ max
        except ZeroDivisionError :
            ratio = 0


        i = 0
        for groupe,value in zip(self.data.keys(),self.data.values()) :

            if self.c_box.currentText() == "warrior":
                title_str = 'Nombre de Heros'
                bar_all = QGraphicsRectItem(0,self.margin['top'],value['warrior']*ratio,interval*0.8)
                bar_all.setPos(self.size_text_width,interval*0.2+(i*interval))
                gradient = QLinearGradient(QPointF(bar_all.rect().width()/2,0),QPointF(bar_all.rect().width()/2,bar_all.rect().height()+self.margin['top']))
                gradient.setColorAt(0,QColor('white'))
                gradient.setColorAt(1,QColor('red'))
                brush = QBrush(gradient)            
                #brush.setTexture(QPixmap(":/textures/"+groupe.attribs['color']))
                bar_all.setBrush(brush)
                self.my_scene.addItem(bar_all)
                self.histo_items.append(bar_all)
    
                bar_alive = QGraphicsRectItem(0,self.margin['top'],value['alive']*ratio,interval*0.8)
                bar_alive.setPos(self.size_text_width,interval*0.2+(i*interval))
                gradient = QLinearGradient(QPointF(bar_alive.rect().width()/2,0),QPointF(bar_alive.rect().width()/2,bar_alive.rect().height()+self.margin['top']))
    #             gradient.setStart(QPointF(0.5,0))
    #             gradient.setStop(QPointF(0.5,1))
                gradient.setColorAt(0,QColor('white'))
                gradient.setColorAt(1,QColor('green'))
                brush = QBrush(gradient)
                
                bar_alive.setBrush(brush)
                self.my_scene.addItem(bar_alive)
                self.histo_items.append(bar_alive)
    
                text_nb_warriors= QGraphicsTextItem(str(value['warrior']))
                text_nb_warriors.setDefaultTextColor(QColor('green'))
                trans = QTransform().translate(bar_all.pos().x()+bar_all.rect().width()+10,interval*0.2+(i*interval)+self.margin['top'])
                pts = trans.map(QPointF(0,0.0))
                text_nb_warriors.setPos(pts.x(),pts.y())
                self.my_scene.addItem(text_nb_warriors)            
                self.histo_items.append(text_nb_warriors)


            #bar ranl
            elif self.c_box.currentText()== "rank":
                title_str = "Rank Moyen"
                bar_rank = QGraphicsRectItem(0,self.margin['top'],value['rank']*ratio,interval*0.8)
                bar_rank.setPos(self.size_text_width, interval*0.2+(i*interval))
                gradient = QLinearGradient(QPointF(bar_rank.rect().width()/2,0),QPointF(bar_rank.rect().width()/2,bar_rank.rect().height()+self.margin['top']))
    #             gradient.setStart(QPointF(0.5,0))
    #             gradient.setStop(QPointF(0.5,1))
                gradient.setColorAt(0,QColor('white'))
                gradient.setColorAt(1,QColor('red'))
                brush = QBrush(gradient)
                
                bar_rank.setBrush(brush)
                self.my_scene.addItem(bar_rank)
                self.histo_items.append(bar_rank)
    
                # value
                text_rank = QGraphicsTextItem("{0:1.1f}".format(value['rank']))
                text_rank.setDefaultTextColor(QColor('red'))
                trans = QTransform().translate(bar_rank.pos().x()+bar_rank.rect().width()+10,interval*0.2+(i*interval)+self.margin['top'])
                pts = trans.map(QPointF(0,0.0))
                text_rank.setPos(pts.x(),pts.y())
                self.my_scene.addItem(text_rank)            
                self.histo_items.append(text_rank)
    

            else:
                title_str = "Puissance"
                bar_rank = QGraphicsRectItem(0,self.margin['top'],value['power']*ratio,interval*0.8)
                bar_rank.setPos(self.size_text_width, interval*0.2+(i*interval))
                gradient = QLinearGradient(QPointF(bar_rank.rect().width()/2,0),QPointF(bar_rank.rect().width()/2,bar_rank.rect().height()+self.margin['top']))
    #             gradient.setStart(QPointF(0.5,0))
    #             gradient.setStop(QPointF(0.5,1))
                gradient.setColorAt(0,QColor('white'))
                gradient.setColorAt(1,QColor('blue'))
                brush = QBrush(gradient)
                
                bar_rank.setBrush(brush)
                self.my_scene.addItem(bar_rank)
                self.histo_items.append(bar_rank)
    
                # value
                try :
                    valeur = (value['power']/max)*100
                except ZeroDivisionError :
                    valeur = 0
                text_rank = QGraphicsTextItem("{0:1.1f}".format(valeur))
                text_rank.setDefaultTextColor(QColor('blue'))
                trans = QTransform().translate(bar_rank.pos().x()+bar_rank.rect().width()+10,interval*0.2+(i*interval)+self.margin['top'])
                pts = trans.map(QPointF(0,0.0))
                text_rank.setPos(pts.x(),pts.y())
                self.my_scene.addItem(text_rank)            
                self.histo_items.append(text_rank)


            #dessin du titre
            title = QGraphicsTextItem(title_str)
            title.setPos(self.margin['left']+self.size_text_width+horizontal_size/2.0,self.c_box.pos().y())
            self.my_scene.addItem(title)
            self.histo_items.append(title)
    
            #affichage des label colonne de gauche
            if len(groupe.name)> self.max_length_text:
                data = groupe.name[:self.max_length_text]+".."
            else :
                data = groupe.name
            text = QGraphicsTextItem(data)
            #text.setTextWidth(20)

            trans = QTransform().translate(self.margin['left'],interval*0.2+(i*interval)+self.margin['top'])
            pts = trans.map(QPointF(0,0.0))
            text.setPos(pts.x(),pts.y())
            self.my_scene.addItem(text)            
            self.histo_items.append(text)

            i +=1

     #   self.fitInView(self.scene.sceneRect())