From a7ca41075d0157a296bd74416cc40e62905c6e6d Mon Sep 17 00:00:00 2001 From: suchintan-p <56782241+suchintan-p@users.noreply.github.com> Date: Sat, 7 Dec 2019 17:35:08 +0530 Subject: [PATCH 1/2] Fix of switching apps "_exceptions" is not an attribute of psutil, hence attribute error was shown. --- track.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/track.py b/track.py index 8ce072e..44d38c7 100644 --- a/track.py +++ b/track.py @@ -40,8 +40,8 @@ def active_window_process_name(self): logging.warning(f'App name: {app_name}') if app_name in self.titles: return app_name - except psutil._exceptions.NoSuchProcess: - logging.warning(psutil._exceptions.NoSuchProcess) + except psutil.NoSuchProcess: + logging.warning(psutil.NoSuchProcess) window_title = win32gui.GetWindowText(fore_win_id) logging.warning(f'Window title {window_title}') try: From 31ba8de6167c74cdbec1cc70c466d7d5f9b41f58 Mon Sep 17 00:00:00 2001 From: suchintan-p <56782241+suchintan-p@users.noreply.github.com> Date: Sun, 8 Dec 2019 15:33:16 +0530 Subject: [PATCH 2/2] Report in Tkinter GUI window Used matplotlib.backends.backend_tkagg --- track.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/track.py b/track.py index 44d38c7..bb67be2 100644 --- a/track.py +++ b/track.py @@ -2,7 +2,8 @@ import win32gui import psutil import win32process -import matplotlib.pyplot as plotter +from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg as fcta +from matplotlib.figure import Figure as fig from pathlib import Path import json import configparser as cp @@ -13,7 +14,7 @@ class TrackTime: def __init__(self): config = cp.ConfigParser() config.read('conf.ini') - DEF = config['DEFAULT'] + DEF = config['DEFAULT'] self.titles = DEF['titles'].split(',') self.ignore_processes = DEF['ignore'].split(',') @@ -68,7 +69,7 @@ def start_recording(self): self.stop_btn.pack(side='left') self.start_btn['state']='disabled' self.stop_btn['state']='normal' - self.recording=True + self.recording=True self.record(None, 0) def stop_recording(self): @@ -110,20 +111,19 @@ def save_data(self): with open('data.json','w+') as file: file.write(data) - def create_report(self): + def create_report(self): del self.data_dict[None] for process in self.ignore_processes: if process in self.data_dict.keys(): del self.data_dict[process] labels = list(self.data_dict.keys()) val = list(self.data_dict.values()) - logging.warning(labels) - logging.warning(val) - plotter.pie(val, labels=labels, autopct='%1.2f', startangle=90) - plotter.legend() - plotter.show() - - + self.figure = fig() + subplot = self.figure.add_subplot() + subplot.title.set_text("Report") + subplot.pie(val,labels=labels,autopct='%1.2f',startangle=90) + piechart = fcta(self.figure, self.root) + piechart.get_tk_widget().pack() try: tracker = TrackTime()