Skip to content

Fix of switching apps error #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions track.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(',')

Expand All @@ -40,8 +41,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:
Expand All @@ -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):
Expand Down Expand Up @@ -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()
Expand Down