-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools.py
62 lines (44 loc) · 1.92 KB
/
tools.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
from screeninfo import get_monitors, common
def get_screen_dimensions():
try:
from dimensions import screen_width, screen_height
except ModuleNotFoundError: # No stored dimensions data:
pass
else:
print(f"Stored resolution value ({screen_width}x{screen_height}) has been used!")
print("To delete the stored value delete the file\"dimensions.py\"")
return screen_width, screen_height
try:
monitor = get_monitors()[0]
return monitor.width, monitor.height
except common.ScreenInfoError: # the game is propaply running in an android device
pass
print("\n\n\nIt seems like you are propaply running the game in an android phone because we were not able to detect your screen resolution informations, So we need you to manually enter your screen resolution values (width and height in pixels), you can get it from your device setting")
while True:
try:
screen_width = int(input("Width:\n"))
break
except ValueError:
print("Width must be a number, Try again.")
while True:
try:
screen_height = int(input("Height:\n"))
break
except ValueError:
print("height must be a number, Try again.")
store = input("Do you want us to store your screen resolutions values ?\nEnter Y or y for \"Yes\" any other thing for \"No\"\nTo delete them you will need to manually delete dimensions.py file in the working directory\n")
if store == "Y" or store == "y":
f = open("dimensions.py", "w")
f.write(f"screen_width = {screen_width}\nscreen_height = {screen_height}")
f.close()
return screen_width, screen_height
import netifaces as ni
def get_host_ip_address():
interfaces = ni.interfaces()
for interface in interfaces:
addrs = ni.ifaddresses(interface)
if ni.AF_INET in addrs:
ip = addrs[ni.AF_INET][0]['addr']
if ip != '127.0.0.1': # Skip localhost
return ip
return None