Python Forum
[PyQt] cant import progress bar from another py file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] cant import progress bar from another py file
#1
Hello
First Im new in python and pyqt. I found progress bar py file on the internet and to use this file I should to import to main py file, so I did:
add __init__.py file to src folder as well in root folder
in main.py file I importing > from src.progressbar import prgBar
in main.py file in __init__ function self.someprogressbar = prgBar()
and set value for progress bar, but no luck so far.
here is the main.py code:
from PyQt4 import QtGui, QtCore
import sys
from src.testCprg import cPrg

class mainWindow(QtGui.QWidget):
    def __init__(self):
        
        self.otherFile = cPrg(self)
        
        super(mainWindow, self).__init__()
        
        
        self.initUI()

    def initUI(self):
        self.label = QtGui.QLabel(self)
        self.label.setText(self.otherFile.textas)
        self.label.setGeometry(200, 200, 60, 40)

        self.otherFile.setGeometry(100, 100, 200, 200)
        self.otherFile.setValue(0.5)
        
        self.setGeometry(0, 0, 800, 480)
        self.setWindowTitle('Window Title')



def main():
    app = QtGui.QApplication(sys.argv)
    gui = mainWindow()
    gui.show()
    sys.exit(app.exec_())

if __name__ == '__main__':
   main()
and here is progress bar code:
from PyQt4 import QtGui, Qt, QtCore
from PyQt4.Qt import QPen
import sys


class cPrg(QtGui.QWidget):

    def __init__(self, initialValue=0, parent=None, *args, **kwargs):
        super(cPrg, self).__init__(parent, *args, **kwargs)
        self.linewidth = 1
        self.setValue(initialValue)
        self.textas= 'textas cia'
        
 
    def setValue(self, val):
        val = float(min(max(val, 0), 1))
        self._value = -270 * val
        
        self.update()
    
    def paintEvent(self, e):
        print 'yoyo'
        painter = QtGui.QPainter(self)
        painter.setRenderHint(painter.Antialiasing)
        rect = e.rect()
        
        gauge_rect = QtCore.QRect(rect)
        size = gauge_rect.size()
        pos = gauge_rect.center()
        gauge_rect.moveCenter( QtCore.QPoint(pos.x()-size.width(), pos.y()-size.height()) )
        gauge_rect.setSize(size*.9)
        gauge_rect.moveCenter(pos)
        
        startAngle = 270 * 16  # <-- set start angle to draw arc
        endAngle = -270 * 16  # <-- set end arc angle
        
        painter.setPen(QPen(QtGui.QColor('#000000'), 3))#self.lineWidth))  # <-- arc color
        # painter.setBrush(QtCore.Qt.HorPattern)
        
        painter.drawArc(gauge_rect, startAngle, endAngle)  # <-- draw arc
        
        painter.end()
        super(cPrg,self).paintEvent(e)
Im not sure what is wrong but thinking something about paintevent (in main.py file this paintevent working). So anyone please can tell me what is wrong? thank you
P.S. I know this code is a big mess! :)
Reply


Messages In This Thread
cant import progress bar from another py file - by swipis - Dec-17-2016, 08:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Import a file and show file name on qcombobox GMCobraz 1 1,988 Jul-02-2020, 01:38 PM
Last Post: GMCobraz
  [PyQt] Import Excel file and use pandas WBPYTHON 2 5,723 Mar-22-2020, 11:28 AM
Last Post: WBPYTHON
  How can I measure progress and display it in the progress bar in the interface? Matgaret 2 5,961 Dec-11-2019, 03:30 PM
Last Post: Denni
  [Tkinter] Progress Bar While Sending an Email maxtimbo 3 4,128 Oct-09-2019, 09:13 PM
Last Post: woooee
  Progress Bar While Sending an Email maxtimbo 0 2,134 Oct-08-2019, 02:13 PM
Last Post: maxtimbo
  GUI Progress Bar Anysja 6 6,644 Aug-29-2018, 02:34 PM
Last Post: swetanjali
  PyQt5 - import rext from other file - despearte for help D_frucht 1 2,500 May-26-2018, 06:37 AM
Last Post: Barrowman

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020