-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindowmani.py
88 lines (85 loc) · 5.01 KB
/
windowmani.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
88
import pygetwindow as pygw
import pandas as pd
def list_open_windows():
windows = pygw.getAllTitles()
window_props = ['Name', 'Width', 'Height', 'Left', 'Top']
windowdf = pd.DataFrame(columns=window_props)
for window_title in windows:
window = pygw.getWindowsWithTitle(window_title)[0]
if window.width > 1 and window.title != "Program Manager" and window.title != 'Settings':
if 'Brave' in window.title and window.left < 500:
window_name = 'Brave#1'
elif 'Brave' in window.title and window.left > 500:
window_name = 'Brave#2'
elif 'Total Commander' in window.title:
window_name = 'Total Commander'
elif 'Visual Studio Code' in window.title:
window_name = 'Visual Studio Code'
elif 'Thunderbird' in window.title:
window_name = 'Thunderbird'
elif 'Discord' in window.title:
window_name = 'Discord'
elif 'Outlook' in window.title:
window_name = 'Outlook'
elif 'Slack' in window.title:
window_name = 'Slack'
else:
window_name = 'File Explorer'
windowdf_append = {'Name': window_name, 'Width': window.width, 'Height': window.height, 'Left': window.left, 'Top': window.top}
windowdf.loc[len(windowdf)] = windowdf_append
print(windowdf)
windowdf.to_csv('Running_windows.csv', index=False)
def restore_open_windows():
input_file = input('Enter the name of the .csv file with the saved window data: ')
windowdf = pd.read_csv(input_file)
windowdf.set_index('Name', inplace=True)
windows = pygw.getAllTitles()
count = 0
for window_title in windows:
window = pygw.getWindowsWithTitle(window_title)[0]
if window.width > 1 and window.title != "Program Manager" and window.title != 'Settings':
if 'Brave' in window.title and count == 0:
window_name = 'Brave#1'
window.moveTo(int(windowdf.loc[window_name, 'Left']), int(windowdf.loc[window_name, 'Top']))
window.resizeTo(int(windowdf.loc[window_name, 'Width']), int(windowdf.loc[window_name, 'Height']))
count = 1
elif 'Brave' in window.title and count > 0:
window_name = 'Brave#2'
window.moveTo(int(windowdf.loc[window_name, 'Left']), int(windowdf.loc[window_name, 'Top']))
window.resizeTo(int(windowdf.loc[window_name, 'Width']), int(windowdf.loc[window_name, 'Height']))
elif 'Total Commander' in window.title:
window_name = 'Total Commander'
window.moveTo(int(windowdf.loc[window_name, 'Left']), int(windowdf.loc[window_name, 'Top']))
window.resizeTo(int(windowdf.loc[window_name, 'Width']), int(windowdf.loc[window_name, 'Height']))
elif 'Visual Studio Code' in window.title:
window_name = 'Visual Studio Code'
window.moveTo(int(windowdf.loc[window_name, 'Left']), int(windowdf.loc[window_name, 'Top']))
window.resizeTo(int(windowdf.loc[window_name, 'Width']), int(windowdf.loc[window_name, 'Height']))
elif 'Thunderbird' in window.title:
window_name = 'Thunderbird'
window.moveTo(int(windowdf.loc[window_name, 'Left']), int(windowdf.loc[window_name, 'Top']))
window.resizeTo(int(windowdf.loc[window_name, 'Width']), int(windowdf.loc[window_name, 'Height']))
elif 'Discord' in window.title:
window_name = 'Discord'
window.moveTo(int(windowdf.loc[window_name, 'Left']), int(windowdf.loc[window_name, 'Top']))
window.resizeTo(int(windowdf.loc[window_name, 'Width']), int(windowdf.loc[window_name, 'Height']))
elif 'Outlook' in window.title:
window_name = 'Outlook'
window.moveTo(int(windowdf.loc[window_name, 'Left']), int(windowdf.loc[window_name, 'Top']))
window.resizeTo(int(windowdf.loc[window_name, 'Width']), int(windowdf.loc[window_name, 'Height']))
elif 'Slack' in window.title:
window_name = 'Slack'
window.moveTo(int(windowdf.loc[window_name, 'Left']), int(windowdf.loc[window_name, 'Top']))
window.resizeTo(int(windowdf.loc[window_name, 'Width']), int(windowdf.loc[window_name, 'Height']))
else:
window_name = 'File Explorer'
window.moveTo(int(windowdf.loc[window_name, 'Left']), int(windowdf.loc[window_name, 'Top']))
window.resizeTo(int(windowdf.loc[window_name, 'Width']), int(windowdf.loc[window_name, 'Height']))
if __name__ == "__main__":
io = input('Do you want to save (1) or restore (2) your windows?: ')
if io == '1':
list_open_windows()
elif io == '2':
restore_open_windows()
else:
print('Invalid input, please specify 1 or 2!')