Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyloner committed Mar 2, 2017
1 parent 82c770d commit de8c0e0
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 25 deletions.
40 changes: 35 additions & 5 deletions proc/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from proc import *
import time
import random
import os
import signal

class CPU(QtCore.QThread):
_cpu_infor_signal=QtCore.pyqtSignal(dict)
Expand Down Expand Up @@ -36,7 +38,7 @@ def run(self):
while True:
infor=get_process_infor()
self._proc_infor_signal.emit(infor)
time.sleep(1)
time.sleep(4)

class Network(QtCore.QThread):
_net_infor_signal=QtCore.pyqtSignal(dict)
Expand Down Expand Up @@ -81,6 +83,7 @@ def draw_network(self,painter):
net_now=self.network_data[0]
text_font=QFont()
text_font.setPointSize(10)
#text_font.setItalic(True)
for i in range(2):
painter.setPen(QPen(QColor(100,120,30),2))
painter.setBrush(self.colors[i]);
Expand Down Expand Up @@ -149,6 +152,7 @@ def draw_cpus(self,painter):
width=int(750/length)
text_font=QFont()
text_font.setPointSize(20-2*length)
#text_font.setItalic(True)
line_colors={}
for i in range(length):
painter.setPen(QPen(QColor(100,120,30),2))
Expand Down Expand Up @@ -193,8 +197,8 @@ def __init__(self):
self.init_signal()
self.cpu_data=[]
self.mem_data=[]
self.pro_data=[]
self.net_data=[]
self.process_data=[]

def init_signal(self):
self.cpu._cpu_infor_signal.connect(self.load_cpu_infor)
Expand All @@ -215,6 +219,15 @@ def load_cpu_infor(self,infor):
self.cpu_data.insert(0,infor)
self.draw_cpu=DrawCPU(self.cpu_data)
self.cpu_gridLayout.addWidget(self.draw_cpu,0,0)
self.pushButton.clicked.connect(self.close_process)

def close_process(self):
try:
index=self.tableWidget.currentRow()
pid=self.process_data[index]
os.kill(int(pid),signal.SIGKILL)
except:
pass

def load_memory_infor(self,infor):
try:
Expand All @@ -230,12 +243,29 @@ def load_network_infor(self,infor):
except:
pass
self.net_data.insert(0,infor)
self.net_data=self.net_data[:50]
self.draw_net=DrawNetwork(self.net_data)
self.net_gridLayout.addWidget(self.draw_net,0,0)

def load_process_infor(self,infor):
pass

def load_process_infor(self,result):
self.tableWidget.clearContents()
self.process_data.clear()
self.process_data=result
self.tableWidget.setColumnCount(5)
self.tableWidget.setRowCount(len(result))
keys=['Pid','Name','State','VmRSS','Threads']
for num in range(len(self.process_data)):
line=[]
item=self.process_data[num]
for key in keys:
try:
line.append(item[key])
except:
line.append('')
for i in range(5):
newitem=QtWidgets.QTableWidgetItem()
newitem.setText(str(line[i]))
self.tableWidget.setItem(num,i,newitem)

if __name__ == '__main__':
import sys
Expand Down
30 changes: 15 additions & 15 deletions proc/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,25 @@
<attribute name="title">
<string>进程</string>
</attribute>
<widget class="QTreeWidget" name="treeWidget">
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>0</x>
<y>460</y>
<width>113</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>结束进程</string>
</property>
</widget>
<widget class="QTableWidget" name="tableWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>741</width>
<width>761</width>
<height>461</height>
</rect>
</property>
Expand Down Expand Up @@ -118,19 +131,6 @@
</property>
</column>
</widget>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>0</x>
<y>460</y>
<width>113</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>结束进程</string>
</property>
</widget>
</widget>
</widget>
</widget>
Expand Down
11 changes: 9 additions & 2 deletions proc/proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,16 @@ def get_network_infor():

def get_process_infor():
result = []
for dirname in os.listdir('.'):
for dirname in os.listdir('/proc'):
try:
pid = int(dirname)
except:
continue
return []
item={}
for line in open('/proc/%s/status'%dirname,'r',encoding='utf-8'):
line = line.replace('\n', '').replace('\t', '').replace(' ', '').split(':')
key = line[0]
value = line[1]
item[key] = value
result.append(item)
return result
3 changes: 0 additions & 3 deletions proc/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,9 @@ def retranslateUi(self, MainWindow):
item.setText(_translate("MainWindow", "内存"))
item = self.tableWidget.horizontalHeaderItem(4)
item.setText(_translate("MainWindow", "线程数"))
item = self.tableWidget.horizontalHeaderItem(5)
item.setText(_translate("MainWindow", "用户"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.Process_infor), _translate("MainWindow", "进程"))
self.menu.setTitle(_translate("MainWindow", "菜单"))
self.actionCPU.setText(_translate("MainWindow", "CPU"))
self.actionMem.setText(_translate("MainWindow", "Mem"))
self.actionProcess.setText(_translate("MainWindow", "Process"))
self.actionExit.setText(_translate("MainWindow", "Exit"))

0 comments on commit de8c0e0

Please sign in to comment.