March 2, 2021

glimworm

Advances in world technology

animation – Circular Progress Bar using PySide

Iam developing a circular progress bar for my application. iam getting some instance code which implements circular progress bar making use of PyQt4. I experimented with to transform the PyQt4 code in to PySide code which satisfies my application. but when i try out to run the code iam finding mistake. plz aid me in this regard.

Iam attaching my code below as properly as the mistake iam receiving

newpysidecircprogbar.py

from pysidecircularprogressbar import QRoundProgressBar
#from qroundprogressbar import QRoundProgressBar
import sys
from PySide.QtGui import *
from PySide import QtCore, QtGui

from time import rest

class TstWidget(QtGui.QWidget):
    def __init__(self):
        super(variety(self), self).__init__()

        self.bar = QRoundProgressBar()
        self.bar.setFixedSize(300, 300)

        self.bar.setDataPenWidth(3)
        self.bar.setOutlinePenWidth(3)
        self.bar.setDecimals(1)
        self.bar.setFormat('%v | %p %')
        # self.bar.resetFormat()
        self.bar.setNullPosition(90)
        self.bar.setBarStyle(QRoundProgressBar.StyleDonut)
        self.bar.setDataColors([(0., QtGui.QColor.fromRgb(255,0,0)), (0.5, QtGui.QColor.fromRgb(255,255,0)), (1., QtGui.QColor.fromRgb(0,255,0))])
        self.bar.setMaximun(100)
        self.bar.setMinimun()
        self.bar.setRange(, 100)
        self.bar.setValue()

        button = QtGui.QPushButton("Commence", self)

        button.clicked.hook up(self.on_get started)

        lay = QtGui.QVBoxLayout()
        lay.addWidget(button)
        lay.addWidget(self.bar)
        self.setLayout(lay)

        self.myLongTask = TaskThread()
        self.myLongTask.notifyProgress.join(self.on_progress)

    def on_commence(self):
        self.myLongTask.start()

    def on_progress(self, i):
        self.bar.setValue(i)

class TaskThread(QtCore.QThread):
   notifyProgress = QtCore.pyqtSignal(int)

   def run(self):
       for i in selection(101):
           self.notifyProgress.emit(i)
           sleep(.1)

def most important():

    app = QtGui.QApplication(sys.argv)
    ex = TstWidget()
    ex.present()

    sys.exit(application.exec_())

if __title__ == '__main__':
    key()

pysideroundprogressbar.py

from PySide import QtCore, QtGui
course QRoundProgressBar(QtGui.QWidget):
StyleDonut = 1
StylePie = 2
StyleLine = 3

PositionLeft = 180
PositionTop = 90
PositionRight = 
PositionBottom = -90

UF_Value = 1
UF_% = 2
UF_MAX = 4

def __init__(self):
    tremendous(QRoundProgressBar, self).__init__()
    self.min = 
    self.max = 100
    self.price = 25

    self.nullPosition = self.PositionTop
    self.barStyle = self.StyleDonut
    self.outlinePenWidth =1
    self.dataPenWidth = 1
    self.rebuildBrush = Wrong
    self.structure = "%p%"
    self.decimals = 1
    self.updateFlags = self.UF_Per cent
    self.gradientData = []
    self.donutThicknessRatio = .75

def setRange(self, min, max):
    self.min = min
    self.max = max

    if self.max < self.min:
        self.max, self.min = self.min, self.max

    if self.value < self.min:
        self.value = self.min
    elif self.value> self.max:
        self.benefit = self.max

    if not self.gradientData:
        self.rebuildBrush = Accurate
    self.update()

def setMinimun(self, min):
    self.setRange(min, self.max)

def setMaximun(self, max):
    self.setRange(self.min, max)

def setValue(self, val):
    if self.benefit != val:
        if val < self.min:
            self.value = self.min
        elif val> self.max:
            self.worth = self.max
        else:
            self.benefit = val
        self.update()

def setNullPosition(self, placement):
    if situation != self.nullPosition:
        self.nullPosition = placement
        if not self.gradientData:
            self.rebuildBrush = Genuine
        self.update()

def setBarStyle(self, fashion):
    if model != self.barStyle:
        self.barStyle = type
        self.update()

def setOutlinePenWidth(self, penWidth):
    if penWidth != self.outlinePenWidth:
        self.outlinePenWidth = penWidth
        self.update()

def setDataPenWidth(self, penWidth):
    if penWidth != self.dataPenWidth:
        self.dataPenWidth = penWidth
        self.update()

def setDataColors(self, stopPoints):
    if stopPoints != self.gradientData:
        self.gradientData = stopPoints
        self.rebuildBrush = Genuine
        self.update()

def setFormat(self, format):
    if structure != self.format:
        self.format = format
        self.valueFormatChanged()

def resetFormat(self):
    self.format=""
    self.valueFormatChanged()

def setDecimals(self, depend):
    if depend >=  and rely != self.decimals:
        self.decimals = rely
        self.valueFormatChanged()

def setDonutThicknessRatio(self, val):
    self.donutThicknessRatio = max(., min(val, 1.))
    self.update()

def paintEvent(self, occasion):
    outerRadius = min(self.width(), self.height())
    baseRect = QtCore.QRectF(1, 1, outerRadius-2, outerRadius-2)

    buffer = QtGui.QImage(outerRadius, outerRadius, QtGui.QImage.Structure_ARGB32)
    buffer.fill()

    p = QtGui.QPainter(buffer)
    p.setRenderHint(QtGui.QPainter.Antialiasing)

    # information brush
    self.rebuildDataBrushIfNeeded()

    # history
    self.drawBackground(p, buffer.rect())

    # base circle
    self.drawBase(p, baseRect)

    # data circle
    arcStep = 360. / (self.max - self.min) * self.price
    self.drawValue(p, baseRect, self.benefit, arcStep)

    # heart circle
    innerRect, innerRadius = self.calculateInnerRect(baseRect, outerRadius)
    self.drawInnerBackground(p, innerRect)

    # text
    self.drawText(p, innerRect, innerRadius, self.benefit)

    # finally attract the bar
    p.close()

    painter = QtGui.QPainter(self)
    painter.drawImage(, , buffer)

def drawBackground(self, p, baseRect):
    p.fillRect(baseRect, self.palette().history())

def drawBase(self, p, baseRect):
    bs = self.barStyle
    if bs == self.StyleDonut:
        p.setPen(QtGui.QPen(self.palette().shadow().colour(), self.outlinePenWidth))
        p.setBrush(self.palette().foundation())
        p.drawEllipse(baseRect)
    elif bs == self.StylePie:
        p.setPen(QtGui.QPen(self.palette().base().coloration(), self.outlinePenWidth))
        p.setBrush(self.palette().foundation())
        p.drawEllipse(baseRect)
    elif bs == self.StyleLine:
        p.setPen(QtGui.QPen(self.palette().foundation().shade(), self.outlinePenWidth))
        p.setBrush(Qt.Qt.NoBrush)
        p.drawEllipse(baseRect.modified(self.outlinePenWidth/2, self.outlinePenWidth/2, -self.outlinePenWidth/2, -self.outlinePenWidth/2))

def drawValue(self, p, baseRect, value, arcLength):
    # practically nothing to draw
    if price == self.min:
        return

    # for Line model
    if self.barStyle == self.StyleLine:
        p.setPen(QtGui.QPen(self.palette().emphasize().colour(), self.dataPenWidth))
        p.setBrush(Qt.Qt.NoBrush)
        p.drawArc(baseRect.altered(self.outlinePenWidth/2, self.outlinePenWidth/2, -self.outlinePenWidth/2, -self.outlinePenWidth/2),
                  self.nullPosition * 16,
                  -arcLength * 16)
        return

    # for Pie and Donut styles
    dataPath = QtGui.QPainterPath()
    dataPath.setFillRule(Qt.Qt.WindingFill)

    # pie phase outer
    dataPath.moveTo(baseRect.centre())
    dataPath.arcTo(baseRect, self.nullPosition, -arcLength)
    dataPath.lineTo(baseRect.heart())

    p.setBrush(self.palette().highlight())
    p.setPen(QtGui.QPen(self.palette().shadow().colour(), self.dataPenWidth))
    p.drawPath(dataPath)

def calculateInnerRect(self, baseRect, outerRadius):
    # for Line design and style
    if self.barStyle == self.StyleLine:
        innerRadius = outerRadius - self.outlinePenWidth
    else:    # for Pie and Donut variations
        innerRadius = outerRadius * self.donutThicknessRatio

    delta = (outerRadius - innerRadius) / 2.
    innerRect = QtCore.QRectF(delta, delta, innerRadius, innerRadius)
    return innerRect, innerRadius

def drawInnerBackground(self, p, innerRect):
    if self.barStyle == self.StyleDonut:
        p.setBrush(self.palette().alternateBase())

        cmod = p.compositionMode()
        p.setCompositionMode(QtGui.QPainter.CompositionMode_Supply)

        p.drawEllipse(innerRect)

        p.setCompositionMode(cmod)

def drawText(self, p, innerRect, innerRadius, worth):
    if not self.structure:
        return

    textual content = self.valueToText(worth)

    # !!! to revise
    f = self.font()
    # f.setPixelSize(innerRadius * max(.05, (.35 - self.decimals * .08)))
    f.setPixelSize(innerRadius * 1.8 / len(text))
    p.setFont(f)

    textRect = innerRect
    p.setPen(self.palette().text().colour())
    p.drawText(textRect, Qt.Qt.AlignCenter, textual content)

def valueToText(self, worth):
    textToDraw = self.structure

    structure_string = '' + ':.f'.format(self.decimals) + ''

    if self.updateFlags & self.UF_Value:
        textToDraw = textToDraw.change("%v", format_string.format(benefit))

    if self.updateFlags & self.UF_P.c:
        per cent = (benefit - self.min) / (self.max - self.min) * 100.
        textToDraw = textToDraw.exchange("%p", format_string.format(%))

    if self.updateFlags & self.UF_MAX:
        m = self.max - self.min + 1
        textToDraw = textToDraw.exchange("%m", format_string.format(m))

    return textToDraw

def valueFormatChanged(self):
    self.updateFlags = 

    if "%v" in self.structure:
        self.updateFlags |= self.UF_Benefit

    if "%p" in self.structure:
        self.updateFlags |= self.UF_%

    if "%m" in self.structure:
        self.updateFlags |= self.UF_MAX

    self.update()

def rebuildDataBrushIfNeeded(self):
    if self.rebuildBrush:
        self.rebuildBrush = Wrong

        dataBrush = QtGui.QConicalGradient()
        dataBrush.setCenter(.5,.5)
        dataBrush.setCoordinateMode(QtGui.QGradient.StretchToDeviceMode)

        for pos, color in self.gradientData:
            dataBrush.setColorAt(1. - pos, coloration)

        # angle
        dataBrush.setAngle(self.nullPosition)

        p = self.palette()
        p.setBrush(QtGui.QPalette.Spotlight, dataBrush)
        self.setPalette(p)

This the error iam receiving

Traceback (most current simply call very last):
File “C:Python27newpysidecircprogbar.py”, line 50, in
class TaskThread(QtCore.QThread):
File “C:Python27newpysidecircprogbar.py”, line 52, in TaskThread
QtCore.Sign = QtCore.pyqtSignal(int)
AttributeError: ‘module’ item has no attribute ‘pyqtSignal’