forked from KevinBytesTheDust/CVAmp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreen.py
76 lines (53 loc) · 2.05 KB
/
screen.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
import logging
logger = logging.getLogger(__name__)
def get_screen_resolution(kind):
try:
import tkinter as tk
root = tk.Tk()
except Exception as e:
logger.exception(e)
return 500
return_value = None
if kind == "width":
return_value = root.winfo_screenwidth()
if kind == "height":
return_value = root.winfo_screenheight()
root.destroy()
return return_value
class Screen:
def __init__(self, window_width, window_height):
self.window_width_offset = 100
self.window_height_offset = 50
self.window_width = window_width
self.window_height = window_height
self.screen_width = get_screen_resolution("width")
self.screen_height = get_screen_resolution("height")
self.spawn_locations = self.generate_spawn_locations()
def generate_spawn_locations(self):
spawn_locations = []
cols = int(self.screen_width / (self.window_width - self.window_width_offset))
rows = int(self.screen_height / (self.window_height - self.window_height_offset))
index = 0
for row in range(rows):
for col in range(cols):
spawn_locations.append(
{
"index": index,
"x": col * (self.window_width - self.window_width_offset),
"y": row * (self.window_height - self.window_height_offset),
"width": self.window_width,
"height": self.window_height,
"free": True,
}
)
index += 1
return spawn_locations
def get_free_screen_location(self):
free_keys = [screen_info for screen_info in self.spawn_locations if screen_info["free"]]
if not free_keys:
return None
lowest_location_info = free_keys[0]
lowest_location_info["free"] = False
return lowest_location_info
def get_default_location(self):
return self.spawn_locations[0]