# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'a.ui'
#
# Created: Sat Oct 2 02:08:21 2010
# by: PyQt4 UI code generator 4.7.2
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
class Ui_MainWindow(QtGui.QMainWindow):
def __init__(self):
self.widget=QtGui.QMainWindow()
self.setupUi(self.widget)
def setupUi(self, MainWindow):
self.widget.setGeometry(QtCore.QRect(0, 0, 500, 500))
MainWindow.setObjectName("MainWindow")
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.but_show_proc = QtGui.QPushButton(self.centralwidget)
self.but_show_proc.setGeometry(QtCore.QRect(100, 400, 93, 27))
self.but_show_proc.setObjectName("but_show_proc")
self.tableWidget = QtGui.QTableWidget(self.centralwidget)
self.tableWidget.setGeometry(QtCore.QRect(90, 30, 340, 341))
self.tableWidget.setObjectName("tableWidget")
self.tableWidget.setColumnCount(3)
self.tableWidget.setRowCount(0)
item = QtGui.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(0, item)
item = QtGui.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(1, item)
item = QtGui.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(2, item)
self.but_shutdown = QtGui.QPushButton(self.centralwidget)
self.but_shutdown.setGeometry(QtCore.QRect(260, 400, 93, 27))
self.but_shutdown.setObjectName("but_shutdown")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 549, 23))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
QtCore.QObject.connect(self.but_shutdown,QtCore.SIGNAL("clicked()"),self.shutdown)
QtCore.QObject.connect(self.but_show_proc,QtCore.SIGNAL("clicked()"),self.show_process)
self.show_process()
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def show_process(self):
try:
import subprocess as subp
f1 = subp.Popen(['ps', '-au'], stdout = subp.PIPE)
lines = []
for l in f1.stdout.readlines():
lines.append(l)
self.tableWidget.setRowCount(len(lines[1:]))
r = 0
for x in lines[1:]:
item=QtGui.QTableWidgetItem()
item.setText(x.split(' ')[6])
self.tableWidget.setItem(r,0,item)
item=QtGui.QTableWidgetItem()
item.setText(x.split(' ')[8])
self.tableWidget.setItem(r,1,item)
item=QtGui.QTableWidgetItem()
item.setText(x.split(' ')[10])
self.tableWidget.setItem(r,2,item)
r += 1
except Exception, e:
print e
def shutdown(self):
import subprocess as subp
subp.Popen('poweroff')
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow",
"Task Manager", None, QtGui.QApplication.UnicodeUTF8))
self.but_show_proc.setText(QtGui.QApplication.translate("MainWindow",
"Refresh", None, QtGui.QApplication.UnicodeUTF8))
self.tableWidget.horizontalHeaderItem(0).setText(QtGui.QApplication.
translate("MainWindow", "PID", None, QtGui.QApplication.UnicodeUTF8))
self.tableWidget.horizontalHeaderItem(1).setText(QtGui.QApplication.
translate("MainWindow", "Cpu", None, QtGui.QApplication.UnicodeUTF8))
self.tableWidget.horizontalHeaderItem(2).setText(QtGui.QApplication.
translate("MainWindow", "Mem", None, QtGui.QApplication.UnicodeUTF8))
self.but_shutdown.setText(QtGui.QApplication.translate("MainWindow",
"Shutdown", None, QtGui.QApplication.UnicodeUTF8))
import sys
if __name__ == "__main__":
app=QtGui.QApplication(sys.argv)
obj=Ui_MainWindow()
obj.widget.show()
sys.exit(app.exec_())
Custom Search
Wednesday, November 3, 2010
howto pyqt project taskmanager
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment