2

I have a main window,when user choose a file to upload,then a new window will open an show status of file i.e filename,upload speed,time left and etc(like IDM and xdman)

when user add a file to upload everything process as well

the problem came up if user want to add more file to upload

first window will stop updating data(which should continue till upload finish)

second window show continue updating info but the progressbar will get mixed with the first window(I mean both progressbar will show in second window at the same time !!! ) How I supposed to keep them separate ? here is the short version of my code to understand what I did !

class Window(QtGui.QWidget):
 def __init__(self, parent=None):
    super(Window, self).__init__(parent)
    self.table = QtGui.QTableWidget(self)#progressbar work perfectly in table but not in new windows !

 def handleAddUpload(self):
    #choosing a file codes go here

    progress = QtGui.QProgressBar(self.table)
    progress.setRange(0, len(data))
    #two above line will add progressbar to table !
    tabs = self.createTab() #caling createTab for creating new window for...

 def handleUploadProgress(self, key, sent, total):
 #handleeUploadProgress method call rapidly since data needs to be stream and update !


   progress = self.table.cellWidget(key, 0)
   progress.setValue(sent)
#two above line will update value in table without any problem

   self.procbar.setValue(sent) #this line call progressbar value from createTab()

 def createTab(self): #all my problems are in this method
    self.tab = QtGui.QTabWidget()
    layout = QtGui.QVBoxLayout(self)
    tab = QtGui.QWidget()
    layout1 = QtGui.QVBoxLayout(tab)
    self.procbar = QtGui.QProgressBar()
    self.procbar.setStyleSheet("")
    self.procbar.setRange(0, 0) #a range added in handleaddupload,for shorting this I didn't show that
    self.procbar.setValue(0)

    layout1.addWidget(self.procbar)
    self.tab.addTab(tab, 'Upload Status')
    layout.addWidget(self.tab)
    self.tab.show()

 def handleUploadFinished(self, key):
    #codes.....

I think this is all which related to progressbar

Since I'm new to python/pyside I asked for help and here is the base of my code(I started with this answer)

Here is my short question : How to add separate unique widgets to show for more than one progressbar at same time ?

Thanks guys for reading this boring question

update 1 : Here is a picture of softwareenter image description here

When I add Pharrell song to upload both progress bar in table and separate window display as well,but when I added new song for upload(justin) :

1- the progress bar in separate window for Pharrell stop working(as you can see percentage is not the same) !

2-progress bar(Just in separate window) for new added song show both progress percent(it rapidly change to 10% and 26%)

(in all situation progress bar in table is working)

Community
  • 1
  • 1
Mohammadhzp
  • 498
  • 7
  • 20
  • Your question is not boring, but it is a little unclear. Why do you need two windows? Why not add all the uploads to one table? It would help if you explained what the overall design of your program is. – ekhumoro Jan 07 '14 at 21:12
  • Hi ekhumoro,thank you for helping me again very much.you are perfect.I just updated my question for clearing my question :) – Mohammadhzp Jan 08 '14 at 04:56

1 Answers1

1

As far as I can make out from the code you've posted, the problem appears to be that you are not managing the status windows correctly.

Firstly, I think you should create a StatusTab class something like this:

class StatusTab(QtGui.QTabWidget):
    def __init__(self, parent=None):
        QtGui.QTabWidget.__init__(self, parent)
        layout = QtGui.QVBoxLayout(self)
        tab = QtGui.QWidget(self)
        layout1 = QtGui.QVBoxLayout(tab)
        self.procbar = QtGui.QProgressBar(tab)
        self.procbar.setStyleSheet("")
        self.procbar.setRange(0, 0)
        self.procbar.setValue(0)
        layout1.addWidget(self.procbar)
        self.addTab(tab, 'Upload Status')
        layout.addWidget(tab)
        ...

(Of course, this class will also have other methods and attributes for dealing with the upload status, info, etc).

Next, you will need a container to hold instances of StatusTab:

class Window(QtGui.QWidget):
    def __init__(self, address):
        QtGui.QWidget.__init__(self)
        ...
        self._uploaders = {}
        self._statustabs = {}

And then create them like this:

    def handleAddUpload(self):
        ...
        statustab = StatusTab(self)
        self._statustabs[row] = statustab

Update them like this:

    def handleUploadProgress(self, key, sent, total):
        ...
        statusbar = self._statusbars[key]
        statusbar.procbar.setValue(sent)

Finally, you should delete them once they are no longer needed:

    def handleUploadFinished(self, key):
        ...
        uploader = self._uploaders.pop(key)
        uploader.deleteLater()
        statustab = self._statustabs.pop(key)
        statustab.deleteLater()

Obviously, the above code is based on my other answer, but hopefully you can adapt it to suit your needs.

ekhumoro
  • 115,249
  • 20
  • 229
  • 336
  • Thanks ekhumoro,your solution worked perfectly,just an edit on your code is changing this class StatusTab(QtGui.QTabWidget): to class StatusTab(QtGui.QDialog): and add another var like this : self.tab = QtGui.QTabWidget,I will do final testing to see if I face a problem,thank you again,you R life saver :p – Mohammadhzp Jan 08 '14 at 09:21