2014-01-07 106 views
2

我有一個主窗口,當用戶選擇要上傳的文件,然後一個新的窗口將打開文件,即文件名,上傳速度,時間的顯示狀態左等(如IDM和xdman)進度條將無法正常工作,如果添加多個窗口(pyside)

當用戶添加一個文件上傳的一切過程以及

問題就來了,如果用戶想要添加更多的文件上傳

一個窗口將停止更新數據(這應該持續到上傳完成)

秒窗口顯示繼續更新信息,但進度條將獲得與第一窗口(我的意思是這兩個進度條將在第二個窗口顯示在同一時間混! ) 我應該如何讓他們分開? 這裏是短版的我的代碼明白我做了什麼!

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..... 

我認爲這是進度

由於我是新來的Python/pyside我要求幫助和here is the base of my code(我開始與這個答案)

這裏它有關的一切是我的短問題:如何添加單獨的獨特小部件以同時顯示多個進度欄?

謝謝你們閱讀這個無聊的問題

更新1: 這裏是軟件enter image description here

圖片當我添加Pharrell的歌曲上傳表和單獨的窗口同時顯示進度條以及,但是當我添加新的歌曲上傳(賈斯汀):

1在單獨的窗口中的進度條Pharrell的停止工作(如你所看到的比例是不一樣的)!

2,進度條(只在單獨的窗口中)新增加的歌曲節目都進步%的(它很快變爲10%和26%)

(在表中的所有情況進度條工作)

+0

你的問題不是無聊,但有點不清楚。你爲什麼需要兩個窗戶?爲什麼不把所有上傳添加到一個表?如果你解釋你的程序的總體設計是什麼,這將有所幫助。 – ekhumoro

+0

嗨ekhumoro,謝謝你再次幫助我。你是完美的。我只是更新了我的問題,以清除我的問題:) – Mohammadhzp

回答

1

據我從您發佈的代碼做出來,這個問題似乎是你沒有正確管理狀態窗口。

首先,我想你應該創建一個StatusTab類是這樣的:

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) 
     ... 

(當然,這個類也將有其他的方法和用於處理上載狀態,信息等屬性)。

接下來,您將需要一個容器來保存的StatusTab實例:

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

再像這樣創建它們:

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

更新他們是這樣的:

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

最後,您應該在不再需要時刪除它們:

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

顯然,上面的代碼是基於我的其他答案,但希望你可以適應它,以滿足您的需求。

+0

謝謝ekhumoro,你的解決方案工作完美,只是對你的代碼的編輯正在改變這個類StatusTab(QtGui .QTabWidget):到類StatusTab(QtGui.QDialog):並添加另一個像這樣的變量:self.tab = QtGui.QTabWidget,我會做最後的測試,看看我是否面臨一個問題,再次感謝你,R救生員: p – Mohammadhzp