Skip to content

Commit

Permalink
Merge pull request #15 from allenh1/update-to-pyqt5-and-python-3
Browse files Browse the repository at this point in the history
Update to PyQt5 and Python 3
  • Loading branch information
wolfc01 committed Jul 14, 2020
2 parents 3110f60 + e0fbcc2 commit ebd5d47
Show file tree
Hide file tree
Showing 18 changed files with 174 additions and 150 deletions.
2 changes: 1 addition & 1 deletion aboutui.py
Expand Up @@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA

from PyQt4 import QtGui, uic
from PyQt5 import QtGui, uic
import os

def doAboutWindow():
Expand Down
2 changes: 1 addition & 1 deletion colorlegend.py
Expand Up @@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA

from PyQt4 import QtGui, uic
from PyQt5 import QtGui, uic
import os

def doColorHelpLegend():
Expand Down
6 changes: 3 additions & 3 deletions cpuaffinity.py
@@ -1,4 +1,4 @@
from PyQt4 import QtGui, uic
from PyQt5 import QtGui, uic
import subprocess
import os
import utils.procutils
Expand Down Expand Up @@ -27,7 +27,7 @@ def doAffinity(cpuCount, process):
aff.__dict__[objName].setEnabled(False)

#check CPU checkboxes
for cpu in xrange(cpuCount):
for cpu in range(cpuCount):
for objName in aff.__dict__:
if objName == "checkBox_%s" %cpu:
if affinity & 2**cpu == 2**cpu:
Expand All @@ -41,7 +41,7 @@ def doAffinity(cpuCount, process):

#apply new affinity
newAff = 0
for cpu in xrange(cpuCount):
for cpu in range(cpuCount):
for objName in aff.__dict__:
if objName == "checkBox_%s" %cpu:
if aff.__dict__[objName].isChecked():
Expand Down
6 changes: 3 additions & 3 deletions logui.py
Expand Up @@ -16,8 +16,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA

from PyQt4.QtGui import QDialog
from PyQt4 import uic
from PyQt5.QtWidgets import QDialog
from PyQt5 import uic
from utils.procutils import getLog
import os

Expand Down Expand Up @@ -51,4 +51,4 @@ def close(self):
_inst = _LogWindowWrapper()
doLogWindow = _inst.createDialog
update = _inst.update
closeLogWindow = _inst.close
closeLogWindow = _inst.close
2 changes: 1 addition & 1 deletion messageui.py
Expand Up @@ -20,7 +20,7 @@
# implements a message UI capable of supressing messages which the user already knows
#

from PyQt4 import QtGui, uic
from PyQt5 import QtGui, uic
import os
dialog = None
import configobj
Expand Down
14 changes: 7 additions & 7 deletions networkoverview.py
Expand Up @@ -20,7 +20,7 @@
# Display network overview
#

from PyQt4 import QtCore, QtGui, uic
from PyQt5 import QtCore, QtGui, QtWidgets, uic
import utils.procutils
import plotobjects
import os
Expand Down Expand Up @@ -65,16 +65,16 @@ class networkOverviewUi(object):
def __init__(self, networkCards, depth, reader):
self.__reader__ = reader
self.__depth__ = depth
self.__dialog__ = QtGui.QDialog()
self.__dialog__ = QtWidgets.QDialog()
self.__ui__ = uic.loadUi(os.path.join(os.path.dirname(__file__), "./ui/networkinformation.ui"), baseinstance=self.__dialog__)
self.__networkCards__ = networkCards
self.__netPlotArray = []
for _i in xrange(_MAX_NOOFNETWORKCARDS):
for _i in range(_MAX_NOOFNETWORKCARDS):
self.__netPlotArray +=[[getattr(self.__ui__, "groupBoxNetworkCard_%02d" %_i),
getattr(self.__ui__, "qwtPlotNetworkCardHistory_%02d" %_i)]]
self.__tabs__ = {}

for card in xrange(_MAX_NOOFNETWORKCARDS):
for card in range(_MAX_NOOFNETWORKCARDS):
if card+1 > len(self.__networkCards__):
self.__netPlotArray[card][0].setVisible(False)
self.__netPlotArray[card].append(False)
Expand Down Expand Up @@ -108,8 +108,8 @@ def __init__(self, networkCards, depth, reader):

#create tab per network card
for card in self.__networkCards__:
tab = QtGui.QWidget()
self.__tabs__[card] = [tab, [QtGui.QLabel(tab) for _ in xrange(13)], [QtGui.QLabel(tab) for _ in xrange(13)]]
tab = QtWidgets.QWidget()
self.__tabs__[card] = [tab, [QtWidgets.QLabel(tab) for _ in range(13)], [QtWidgets.QLabel(tab) for _ in range(13)]]
self.__ui__.tabWidget.addTab(tab, "")
self.__ui__.tabWidget.setTabText(self.__ui__.tabWidget.indexOf(tab), card)
ymargin=20
Expand Down Expand Up @@ -165,7 +165,7 @@ def setFontSize(self, fontSize):

def update(self):
"""update the state of this diaglog"""
for plot in xrange(_MAX_NOOFNETWORKCARDS):
for plot in range(_MAX_NOOFNETWORKCARDS):
if plot+1 <= len(self.__networkCards__):
self.__netPlotArray[plot][3].update()

Expand Down
18 changes: 10 additions & 8 deletions plotobjects/__init__.py
Expand Up @@ -16,8 +16,8 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA


from PyQt4 import QtCore, QtGui
import PyQt4.Qwt5 as Qwt
from PyQt5 import QtCore, QtGui
import PyQt5.Qwt as Qwt

class scaleObject:
pass
Expand All @@ -32,22 +32,24 @@ def __init__(self, name, penWidth, lineColor, fillColor, plot):
self.__curve__.attach(plot)

#work around to get nicer plotting.
self.__curveExt__ = Qwt.QwtPlotCurve(name+" extra")
self.__curveExt__ = Qwt.QwtPlotCurve(name + " extra")
self.__curveExt__.setPen(QtGui.QPen(lineColor))
self.__curveExt__.attach(plot)
def setData(self, x, y):
self.__curve__.setData(x, y)
self.__curveExt__.setData(x,y)

def setData(self, x, y):
self.__curve__.setSamples(x, y)
self.__curveExt__.setSamples(x, y)
# self.__curve__.setData(list(x), y)
# self.__curveExt__.setData(list(x),y)


class procExpPlot(object):
def __init__(self, qwtPlot, scale=None, hasGrid=True):
self.__plot__ = qwtPlot
if hasGrid:
self.__curveCpuPlotGrid= Qwt.QwtPlotGrid()
self.__curveCpuPlotGrid.setMajPen(QtGui.QPen(QtGui.QColor(0,100,0), 0, QtCore.Qt.SolidLine))
self.__curveCpuPlotGrid.setMinPen(QtGui.QPen(QtGui.QColor(0,100,0), 0, QtCore.Qt.SolidLine))
self.__curveCpuPlotGrid.setMajorPen(QtGui.QPen(QtGui.QColor(0,100,0), 0, QtCore.Qt.SolidLine))
self.__curveCpuPlotGrid.setMinorPen(QtGui.QPen(QtGui.QColor(0,100,0), 0, QtCore.Qt.SolidLine))
self.__curveCpuPlotGrid.enableXMin(True)
self.__curveCpuPlotGrid.attach(self.__plot__)
self.__plot__.setCanvasBackground(QtGui.QColor(0,0,0))
Expand Down
82 changes: 45 additions & 37 deletions procexp.py
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3
# This file is part of the Linux Process Explorer
# See www.sourceforge.net/projects/procexp
#
Expand All @@ -24,11 +24,9 @@

#create qt app early, in order to show unhandled exceptions graphically.
import sys
from PyQt4 import QtCore, QtGui, uic
from PyQt5 import QtCore, QtGui, QtWidgets, uic
import utils.procutils

app = QtGui.QApplication(sys.argv)

import procreader.reader
import logui
import aboutui
Expand Down Expand Up @@ -120,11 +118,11 @@ def performMenuAction(action):
selectedItem = g_mainUi.processTreeWidget.selectedItems()[0]
except IndexError:
return
process = str(selectedItem.data(1,0).toString())
if g_singleProcessUiList.has_key(process):
process = str(selectedItem.data(1,0))
if process in g_singleProcessUiList.keys():
g_singleProcessUiList[process].makeVisible()
else:
if g_procList.has_key(int(process)):
if int(process) in g_procList.keys():
g_singleProcessUiList[process] = singleprocess.singleUi(process, g_procList[int(process)]["cmdline"], g_procList[int(process)]["name"], g_reader, int(g_settings["historySampleCount"]))
elif action is g_mainUi.actionSaveSettings:
saveSettings()
Expand Down Expand Up @@ -152,7 +150,7 @@ def performMenuAction(action):
elif action is g_mainUi.actionSet_affinity:
try:
selectedItem = g_mainUi.processTreeWidget.selectedItems()[0]
process = str(selectedItem.data(1,0).toString())
process = str(selectedItem.data(1,0))
except IndexError:
return
cpuaffinity.doAffinity(g_reader.getCpuCount(), process)
Expand Down Expand Up @@ -192,7 +190,7 @@ def loadSettings():

#load default settings for undefined settings
for item in g_defaultSettings:
if g_settings.has_key(item):
if item in g_settings.keys():
pass
else:
g_settings[item] = g_defaultSettings[item]
Expand All @@ -210,7 +208,7 @@ def loadSettings():

#load default settings for undefined settings
for item in g_defaultSettings:
if g_settings.has_key(item):
if item in g_settings.keys():
pass
else:
g_settings[item] = g_defaultSettings[item]
Expand Down Expand Up @@ -271,14 +269,22 @@ def prepareUI(mainUi):

#create a timer which triggers the process explorer to update its contents
g_timer = QtCore.QTimer(mainUi.processTreeWidget)
QtCore.QObject.connect(g_timer, QtCore.SIGNAL("timeout()"), updateUI)
QtCore.QObject.connect(mainUi.processTreeWidget, QtCore.SIGNAL('customContextMenuRequested(const QPoint&)'), onContextMenu)
QtCore.QObject.connect(mainUi.menuFile, QtCore.SIGNAL('triggered(QAction*)'), performMenuAction)
QtCore.QObject.connect(mainUi.menuProcess, QtCore.SIGNAL('triggered(QAction*)'), performMenuAction)
QtCore.QObject.connect(mainUi.menuOptions, QtCore.SIGNAL('triggered(QAction*)'), performMenuAction)
QtCore.QObject.connect(mainUi.menuSettings, QtCore.SIGNAL('triggered(QAction*)'), performMenuAction)
QtCore.QObject.connect(mainUi.menuView, QtCore.SIGNAL('triggered(QAction*)'), performMenuAction)
QtCore.QObject.connect(mainUi.menuHelp, QtCore.SIGNAL('triggered(QAction*)'), performMenuAction)
g_timer.timeout.connect(updateUI)
# QtCore.QObject.connect(g_timer, QtCore.SIGNAL("timeout()"), updateUI)
mainUi.processTreeWidget.customContextMenuRequested.connect(onContextMenu)
# QtCore.QObject.connect(mainUi.processTreeWidget, QtCore.SIGNAL('customContextMenuRequested(const QPoint&)'), onContextMenu)
mainUi.menuFile.triggered.connect(performMenuAction)
# QtCore.QObject.connect(mainUi.menuFile, QtCore.SIGNAL('triggered(QAction*)'), performMenuAction)
mainUi.menuProcess.triggered.connect(performMenuAction)
# QtCore.QObject.connect(mainUi.menuProcess, QtCore.SIGNAL('triggered(QAction*)'), performMenuAction)
mainUi.menuOptions.triggered.connect(performMenuAction)
# QtCore.QObject.connect(mainUi.menuOptions, QtCore.SIGNAL('triggered(QAction*)'), performMenuAction)
mainUi.menuSettings.triggered.connect(performMenuAction)
# QtCore.QObject.connect(mainUi.menuSettings, QtCore.SIGNAL('triggered(QAction*)'), performMenuAction)
mainUi.menuView.triggered.connect(performMenuAction)
# QtCore.QObject.connect(mainUi.menuView, QtCore.SIGNAL('triggered(QAction*)'), performMenuAction)
mainUi.menuHelp.triggered.connect(performMenuAction)
# QtCore.QObject.connect(mainUi.menuHelp, QtCore.SIGNAL('triggered(QAction*)'), performMenuAction)

#prepare the plot
global g_curveCpuHist
Expand Down Expand Up @@ -342,13 +348,13 @@ def addProcessAndParents(proc, procList):
"""
global g_mainUi

if g_treeProcesses.has_key(proc): #process already exists, do nothing
if proc in g_treeProcesses.keys(): #process already exists, do nothing
return g_treeProcesses[proc]

g_treeProcesses[proc] = QtGui.QTreeWidgetItem([])
g_treeProcesses[proc] = QtWidgets.QTreeWidgetItem([])
g_greenTopLevelItems[proc] = g_treeProcesses[proc]

if procList[proc]["PPID"] > 0 and procList.has_key(procList[proc]["PPID"]): #process has a parent
if procList[proc]["PPID"] > 0 and (procList[proc]["PPID"] in procList.keys()): #process has a parent
parent = addProcessAndParents(procList[proc]["PPID"],procList)
parent.addChild(g_treeProcesses[proc])
else: #process has no parent, thus it is toplevel. add it to the treewidget
Expand All @@ -361,7 +367,7 @@ def delChild(item, childtodelete):
""" Delete child, search recursively
"""
if item != None:
for index in xrange(item.childCount()):
for index in range(item.childCount()):
thechild = item.child(index)
if thechild != None:
if thechild == childtodelete:
Expand All @@ -373,7 +379,7 @@ def expandChilds(parent):
""" expand all childs of given parent
"""
global g_mainUi
for index in xrange(parent.childCount()):
for index in range(parent.childCount()):
thechild = parent.child(index)
if thechild != None:
g_mainUi.processTreeWidget.expandItem(thechild)
Expand All @@ -385,7 +391,7 @@ def expandAll():
""" expand all subtrees
"""
global g_mainUi
for topLevelIndex in xrange(g_mainUi.processTreeWidget.topLevelItemCount()):
for topLevelIndex in range(g_mainUi.processTreeWidget.topLevelItemCount()):
item = g_mainUi.processTreeWidget.topLevelItem(topLevelIndex)
expandChilds(item)

Expand All @@ -407,13 +413,13 @@ def updateUI():
#color all green processes with default background
defaultBgColor = app.palette().color(QtGui.QPalette.Base)
for proc in g_greenTopLevelItems:
for column in xrange(g_greenTopLevelItems[proc].columnCount()):
g_greenTopLevelItems[proc].setBackgroundColor(column, defaultBgColor)
for column in range(g_greenTopLevelItems[proc].columnCount()):
g_greenTopLevelItems[proc].setBackground(column, defaultBgColor)
g_greenTopLevelItems = {}

#delete all red widgetItems
for proc in g_redTopLevelItems:
for topLevelIndex in xrange(g_mainUi.processTreeWidget.topLevelItemCount()):
for topLevelIndex in range(g_mainUi.processTreeWidget.topLevelItemCount()):
topLevelItem = g_mainUi.processTreeWidget.topLevelItem(topLevelIndex)
delChild(topLevelItem, g_redTopLevelItems[proc])
if topLevelItem == g_redTopLevelItems[proc]:
Expand All @@ -432,7 +438,7 @@ def updateUI():
item = g_treeProcesses[proc]
if item.parent() is not None:
parentItem = item.parent()
for idx in xrange(parentItem.childCount()):
for idx in range(parentItem.childCount()):
if item == parentItem.child(idx):
parentItem.takeChild(idx)
g_mainUi.processTreeWidget.addTopLevelItem(g_treeProcesses[proc])
Expand All @@ -447,8 +453,8 @@ def updateUI():
#color all deleted processed red
for proc in g_redTopLevelItems:
try:
for column in xrange(g_redTopLevelItems[proc].columnCount()):
g_redTopLevelItems[proc].setBackgroundColor(column, QtGui.QColor(255,0,0))
for column in range(g_redTopLevelItems[proc].columnCount()):
g_redTopLevelItems[proc].setBackground(column, QtGui.QColor(255,0,0))
except RuntimeError:
pass

Expand Down Expand Up @@ -476,8 +482,8 @@ def updateUI():
if g_firstUpdate == False:
for proc in g_greenTopLevelItems:
item = g_greenTopLevelItems[proc]
for column in xrange(item.columnCount()):
item.setBackgroundColor(column, QtGui.QColor(0,255,0))
for column in range(item.columnCount()):
item.setBackground(column, QtGui.QColor(0,255,0))

if (len(closedProc) > 0) or (len(newProc) > 0):
expandAll()
Expand Down Expand Up @@ -544,13 +550,15 @@ def updateUI():
except:
import traceback
utils.procutils.log("Unhandled exception:%s" %traceback.format_exc())
print traceback.format_exc()
print(traceback.format_exc())

g_firstUpdate = False

if __name__ == "__main__":

g_mainWindow = QtGui.QMainWindow()
print("Call to __main__")
app = QtWidgets.QApplication(sys.argv)
print("app created: '%s'" % app)
g_mainWindow = QtWidgets.QMainWindow()
g_mainUi = uic.loadUi(os.path.join(os.path.dirname(__file__), "./ui/main.ui"), baseinstance=g_mainWindow)
prepareUI(g_mainUi)
loadSettings()
Expand Down Expand Up @@ -579,8 +587,8 @@ def updateUI():

signal.signal(signal.SIGINT, signal.SIG_DFL)

app.exec_()
return_code = app.exec_()
tcpip_stat.tcpStat().stop()
rootproxy.end()
sys.exit()
sys.exit(return_code)

2 changes: 2 additions & 0 deletions procreader/__init__.py
Expand Up @@ -21,3 +21,5 @@
Reads from the /proc filesystem.
'''

from procreader.singleprocess import singleProcessDetailsAndHistory

0 comments on commit ebd5d47

Please sign in to comment.