qt简单界面更新代码(菜鸟级)(部分代码)
self.timers_1=QtCore.QTimer(self)
self.timers_1.timeout.connect(self.min_1)
self.timers_1.start(1000)
def getCPUstate(self,interval=1):
return (" CPU: " + str(psutil.cpu_percent(interval)) + "%")
def getMemorystate(self):
phymem = psutil.phymem_usage()
buffers = getattr(psutil, 'phymem_buffers', lambda: 0)()
cached = getattr(psutil, 'cached_phymem', lambda: 0)()
used = phymem.total - (phymem.free + buffers + cached)
line = " Memory: %5s%% %6s/%s" % (
phymem.percent,
str(int(used / 1024 / 1024)) + "M",
str(int(phymem.total / 1024 / 1024)) + "M")
#self.n.start(1000)
self._tools.threaings_python_cache.setText(unicode(line))
def poll(self,interval):
tot_before = psutil.network_io_counters()
pnic_before = psutil.network_io_counters(pernic=True)
tot_after = psutil.network_io_counters()
pnic_after = psutil.network_io_counters(pernic=True)
cpu_state = self.getCPUstate(interval)
memory_state =self.getMemorystate()
return (tot_before, tot_after, pnic_before, pnic_after,cpu_state,memory_state)
def refresh_window(self,tot_before, tot_after, pnic_before, pnic_after,cpu_state,memory_state):
#self.n.start(1000)
self._tools.threaings_python_cpu.setText(unicode(cpu_state))
def min_1(self):
interval = 1
args = self.poll(interval)
self.refresh_window(*args)
interval = 1
self.timers_1.timeout.connect(self.min_1)核心语句是这句