서버에서 원격 스크립트를 실행하는 프로그램을 작성했습니다. 그래서 바를 가지고 진행 상황을 보여줄 필요가 있지만 코드를 실행할 때 GUI가 정지하기 시작합니다. QThread와 SIGNAL을 사용했지만 불행하게도 succedeed는 불가능합니다.스레드를 사용한 PyQt 진행률 표시
다음은 아래 코드입니다. 내가 방법을 updateProgressBar보고 기대하고
class dumpThread(QThread):
def __init__(self):
QThread.__init__(self)
def __del__(self):
self.wait()
def sendEstablismentCommands(self, connection):
# Commands are sending sequently with proper delay-timers #
connection.sendShell("telnet localhost 21000")
time.sleep(0.5)
connection.sendShell("admin")
time.sleep(0.5)
connection.sendShell("admin")
time.sleep(0.5)
connection.sendShell("cd imdb")
time.sleep(0.5)
connection.sendShell("dump subscriber")
command = input('$ ')
def run(self):
# your logic here
# self.emit(QtCore.SIGNAL('THREAD_VALUE'), maxVal)
self.sendEstablismentCommands(connection)
class progressThread(QThread):
def __init__(self):
QThread.__init__(self)
def __del__(self):
self.wait()
def run(self):
# your logic here
while 1:
maxVal = 100
self.emit(SIGNAL('PROGRESS'), maxVal)
class Main(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.connectButton.clicked.connect(self.connectToSESM)
def connectToSESM(self):
## Function called when pressing connect button, input are being taken from edit boxes. ##
## dumpThread() method has been designed for working thread seperate from GUI. ##
# Connection data are taken from "Edit Boxes"
# username has been set as hardcoded
### Values Should Be Defined As Global ###
username = "ntappadm"
password = self.ui.passwordEdit.text()
ipAddress = self.ui.ipEdit.text()
# Connection has been established through paramiko shell library
global connection
connection = pr.ssh(ipAddress, username, password)
connection.openShell()
pyqtRemoveInputHook() # For remove unnecessary items from console
global get_thread
get_thread = dumpThread() # Run thread - Dump Subscriber
self.progress_thread = progressThread()
self.progress_thread.start()
self.connect(self.progress_thread, SIGNAL('PROGRESS'), self.updateProgressBar)
get_thread.start()
def updateProgressBar(self, maxVal):
for i in range(maxVal):
self.ui.progressBar.setValue(self.ui.progressBar.value() + 1)
time.sleep(1)
maxVal = maxVal - 1
if maxVal == 0:
self.ui.progressBar.setValue(100)
def parseSubscriberList(self):
parsing = reParser()
def done(self):
QtGui.QMessageBox.information(self, "Done!", "Done fetching posts!")
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
main = Main()
main.show()
sys.exit(app.exec_())
는 신호라고, 그래서 과정은 별도의 스레드를 통과했다. 나는 실종 된 곳을 찾는다. 어떤 도움
어떻게 신호 정수를 정의 할 수 있습니다와 같은 진행률 표시 줄을 작성하는 더 나은 것입니까? 당신은 eloborate 수 있습니다 : progress_update = QtCore.Signal (int)? – nuriselcuk
1.'progressThread'의 목적은 무엇입니까? 당신은 워커 쓰레드가 있고 그에 따라 당신의 GUI를 업데이트하고 싶어서 제 3의 쓰레드의 필요성을 보지 못했습니다. 2. 왜 당신은'updateProgressBar'에 루프를 가지고 있습니까? 그리고 왜 각 반복 동안'maxVal'을 줄입니까? 그리고 왜 거기에 '시간 잠들기'가 있니? 물론 잠을 자면 메인 스레드가 멈 춥니 다. 또한'updateProgressBar'에 대한 각각의 호출은'maxVal'가 마지막 반복을 위해 0이기 때문에'self.ui.progressBar.setValue (100)'을 끝낼 것입니다. –