1+ """ Import the necessary modules for the program to work """
12import sys
23import os
34import psutil
1112 QTableWidget , QHeaderView , QSplitter , QTableWidgetItem , QLabel , QTextBrowser , QTabWidget , QProgressBar
1213)
1314
14- prevDrive = None
1515
16+
17+ """ Function to load the CSS style for the program """
1618def loadStyle ():
1719 user_css_path = os .path .join (os .path .expanduser ("~" ), "rmstyle.css" )
1820 stylesheet = None
@@ -39,6 +41,9 @@ def loadStyle():
3941 else :
4042 print ("No QApplication instance found. Stylesheet not applied." )
4143
44+
45+
46+ """ Thread for fetching the processes """
4247class ProcessFetcher (QThread ):
4348 update_processes = pyqtSignal (list )
4449 update_stats = pyqtSignal (float , float , str )
@@ -70,6 +75,9 @@ def run(self):
7075 self .update_stats .emit (cpu_usage , memory_info .percent , disk_display )
7176 self .update_drives .emit (psutil .disk_partitions ())
7277
78+
79+
80+ """ Dialog for displaying System Information """
7381class SystemInfoDialog (QDialog ):
7482 def __init__ (self , parent = None ):
7583 super ().__init__ (parent )
@@ -82,7 +90,7 @@ def __init__(self, parent=None):
8290
8391 def display_system_info (self ):
8492 try :
85- process = subprocess .Popen ("systeminfo" , stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True , shell = True )
93+ process = subprocess .Popen ("systeminfo" , stdout = subprocess .PIPE , stderr = subprocess .PIPE , shell = True , encoding = "mbcs" )
8694 stdout , stderr = process .communicate ()
8795 if process .returncode == 0 :
8896 self .info_browser .setPlainText (stdout )
@@ -91,13 +99,17 @@ def display_system_info(self):
9199 except Exception as e :
92100 self .info_browser .setPlainText (f"An error occurred: { str (e )} " )
93101
102+
103+
104+ """ Main class for the program """
94105class Resmon (QMainWindow ):
95106 def __init__ (self ):
96107 super ().__init__ ()
97108 self .setWindowTitle ("Resmon" )
98109 self .setGeometry (100 , 100 , 770 , 700 )
99110 self .always_on_top = False
100111 self .selected_pid = None
112+ self .prev_drive = None
101113 self .init_ui ()
102114 self .fetcher = ProcessFetcher ()
103115 self .fetcher .update_processes .connect (self .update_process_table )
@@ -227,10 +239,9 @@ def update_process_table(self, process_data):
227239 self .process_table .selectRow (row_to_select )
228240
229241 def update_drives (self , drive_data ):
230- global prevDrive
231- if drive_data == prevDrive :
242+ if drive_data == self .prev_drive :
232243 return
233- prevDrive = drive_data
244+ self . prev_drive = drive_data
234245 disks = drive_data
235246 for i in reversed (range (self .disk_tab_layout .count ())):
236247 self .disk_tab_layout .itemAt (i ).widget ().setParent (None )
@@ -347,6 +358,9 @@ def view_system_info(self):
347358 dialog = SystemInfoDialog (self )
348359 dialog .exec_ ()
349360
361+
362+
363+ """ Dialog for starting a process """
350364class StartProcessDialog (QDialog ):
351365 def __init__ (self , parent = None ):
352366 super ().__init__ (parent )
0 commit comments