-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWindow.py
133 lines (117 loc) · 5.12 KB
/
Window.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import flet
from APIGetter import APIGetter
import webbrowser
import os
import sys
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
class Window(flet.UserControl):
def __init__(self):
super().__init__()
def build(self):
self._players = []
self._api_getter = APIGetter()
player_names = self._api_getter.get_player_data()
for i in range(0, 5):
if i < len(player_names):
self._players.append(flet.TextButton(text=player_names[i], data=player_names[i], on_click=self.get_op_gg_single))
else:
self._players.append(flet.TextButton(text='N/A', data='', on_click=self.get_op_gg_single))
print(resource_path("bg.png"))
return flet.Column(
controls=[
flet.Container(
width=400,
height=800,
image_src = resource_path("images\\bg.png"),
#gradient is backup for when image isn't working
gradient=flet.LinearGradient(
colors=[
'#8c00fc',
'#9c14fc',
'#af2efa',
'#c74ef4',
'#de6df1',
'#ed81ee',
],
stops=[0.0,0.2,0.4,0.6,0.8,1.0]
),
image_fit = flet.ImageFit.COVER,
margin=-10,
padding=25,
content=flet.Column(
controls=[
flet.Container(
width=400,
height=200,
content=flet.Row(
alignment='center',
spacing=20,
controls=[
flet.ElevatedButton(
text='Refresh',
bgcolor=flet.colors.BLUE_GREY_100,
color=flet.colors.BLACK,
on_click=self.set_names,
data='Refresh Names',
),
flet.ElevatedButton(
text='OP.GG',
bgcolor=flet.colors.BLUE_GREY_100,
color=flet.colors.BLACK,
on_click=self.get_op_gg_multi,
data='OP.GG',
)
]
)
),
flet.Container(
width=400,
height=500,
content=flet.Column(
horizontal_alignment='center',
spacing=50,
controls=[
self._players[0],
self._players[1],
self._players[2],
self._players[3],
self._players[4],
]
)
)
]
)
)
]
)
def set_names(self, e):
player_names = self._api_getter.get_player_data()
for i in range(0, 5):
if i < len(player_names):
self._players[i].text = player_names[i]
self._players[i].data = player_names[i]
else:
self._players[i].text = 'N/A'
self._players[i].data = ''
self.update()
def get_op_gg_single(self, e):
print(e.control.data)
if e.control.data:
url = self._api_getter.get_single_lookup_opgg(e.control.data)
webbrowser.open(url=url, new=0, autoraise=True)
self.update()
def get_op_gg_multi(self, e):
player_data = self._api_getter.get_player_data()
if player_data:
self.set_names(player_data)
print('hiewr', player_data)
url = self._api_getter.get_multi_lookup_opgg(player_data)
webbrowser.open(url=url, new=0, autoraise=True)
self.update()