-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.py
87 lines (70 loc) · 2.2 KB
/
helper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import ttkbootstrap as ttk
import os
import win32con
import win32api
import win32gui
import win32process
def time_to_string(t):
h = (t // 3600)
m = (t - (h * 3600)) // 60
s = (t - (h * 3600) - (m * 60))
return str(h).rjust(2, '0') + "h" + str(m).rjust(2, '0') + "m" + str(s).rjust(2, '0') + "s"
def enumWindowsToTitlesByPid(window, param):
pid = param.get("pid", None)
titles = param.get("titles", None)
if win32process.GetWindowThreadProcessId(window)[1] == pid:
title = win32gui.GetWindowText(window)
titles.append(title)
def titlesByPid(pid):
titles = []
param = {
"pid": pid,
"titles": titles,
}
win32gui.EnumWindows(enumWindowsToTitlesByPid, param)
return titles
def pidsByExecutable(executable):
pids = []
for pid in win32process.EnumProcesses():
try:
process = win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS, 0, pid)
except:
continue
try:
ex = win32process.GetModuleFileNameEx(process, None).split(os.path.sep)[-1]
except:
win32api.CloseHandle(process)
continue
if ex.lower() == executable.lower():
pids.append(pid)
win32api.CloseHandle(process)
return pids
def current_song(executable):
pids = pidsByExecutable(executable)
for pid in pids:
titles = titlesByPid(pid)
for title in titles:
if title != "":
return title
return ""
def configure_columns(tk):
tk.columnconfigure(0, weight=1)
tk.columnconfigure(1, weight=1)
tk.columnconfigure(2, weight=1)
tk.columnconfigure(3, weight=1)
tk.columnconfigure(4, weight=1)
tk.columnconfigure(5, weight=1)
tk.columnconfigure(6, weight=1)
tk.columnconfigure(7, weight=1)
tk.columnconfigure(8, weight=1)
tk.columnconfigure(9, weight=1)
tk.columnconfigure(10, weight=1)
tk.columnconfigure(11, weight=1)
def navigate_to_menu_view(view):
view.refresh()
view.tkraise()
def navigate_to_crud_view(view, name):
view.refresh(name)
view.tkraise()
def separator(view, row):
ttk.Separator(view).grid(column=0, columnspan=12, row=row, sticky=ttk.NSEW, pady=5)