0
私は継続的に更新したい(システムリソースの使用状況を表示する)3つの進捗バーを持つ簡単なダイアログを持っています。ドキュメントを読むことから、は、x
ミリ秒ごとにファンクションを起動する正しい方法です(これにより、進行状況バーが更新されます)。しかし、私はそれを働かせることができず、私はなぜそれほど知りません。タイマーのタイムアウト信号を更新機能に接続するのは比較的簡単ですが、決して起動するようには見えません。ここでPyQt4:QTimerを使用して進捗バーを継続的に更新します
は私のコードです:
import sys
from PyQt4 import QtGui, QtCore
import psutil
class Tiny_System_Monitor(QtGui.QWidget):
def __init__(self):
super(Tiny_System_Monitor, self).__init__()
self.initUI()
def initUI(self):
mainLayout = QtGui.QHBoxLayout()
self.cpu_progressBar = QtGui.QProgressBar()
self.cpu_progressBar.setTextVisible(False)
self.cpu_progressBar.setOrientation(QtCore.Qt.Vertical)
mainLayout.addWidget(self.cpu_progressBar)
self.vm_progressBar = QtGui.QProgressBar()
self.vm_progressBar.setOrientation(QtCore.Qt.Vertical)
mainLayout.addWidget(self.vm_progressBar)
self.swap_progressBar = QtGui.QProgressBar()
self.swap_progressBar.setOrientation(QtCore.Qt.Vertical)
mainLayout.addWidget(self.swap_progressBar)
self.setLayout(mainLayout)
timer = QtCore.QTimer()
timer.timeout.connect(self.updateMeters)
timer.start(1000)
def updateMeters(self):
cpuPercent = psutil.cpu_percent()
vmPercent = getattr(psutil.virtual_memory(), "percent")
swapPercent = getattr(psutil.swap_memory(), "percent")
self.cpu_progressBar.setValue(cpuPercent)
self.vm_progressBar.setValue(vmPercent)
self.swap_progressBar.setValue(swapPercent)
print "updated meters"
def main():
app = QtGui.QApplication(sys.argv)
ex = Tiny_System_Monitor()
ex.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
は私が必要なものだけ、ありがとう!ほとんど常にシンプルなものです。ガベージコレクションで勉強しているうちに私を許してください...(私は基本的なPythonの本を読む必要があります) – Spencer