-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
169 lines (126 loc) · 3.88 KB
/
main.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import flet as ft, time, sys, os
from PIL import Image
def main(page: ft.Page):
#Necessary for relative path to assets
try:
os.chdir(sys._MEIPASS)
print('Running from executable...')
except:
pass
pokemon_gif = "pikachu.gif"
pokemon_pil = Image.open(f"assets/{pokemon_gif}")
ball_img = "poke-ball.png"
delay = 0.5
page.window_visible = False
page.window_always_on_top = True
page.window_width = (pokemon_pil.width*1.5)+120
page.window_height = (pokemon_pil.height*1.5)+120
page.window_title_bar_hidden = True
page.window_bgcolor = ft.colors.TRANSPARENT
page.bgcolor = ft.colors.TRANSPARENT
page.window_title_bar_hidden = True
page.window_frameless = True
page.window_maximizable = False
page.window_skip_task_bar = True
page.update()
def launch_pokemon():
pokemon.opacity = 1
page.update()
time.sleep(delay)
pokemon.color = "grey"
pokemon.opacity = 0
page.update()
time.sleep(delay)
#Display pokemon gif and exit button
exit_btn.data['show'] = True
pokemon.src = pokemon_gif
pokemon.color = None
pokemon.opacity = 1
pokemon.data['iswithdrawn'] = False
page.update()
def withdraw_pokemon():
pokemon.color = "grey"
pokemon.opacity = 0
page.update()
time.sleep(delay)
#Display pokeball
pokemon.color = None
pokemon.src = ball_img
pokemon.opacity = 1
pokemon.data['iswithdrawn'] = True
page.update()
def run(e=None):
if pokemon.data['iswithdrawn']:
launch_pokemon()
else:
withdraw_pokemon()
def exit_app():
#Hide exit button
exit_btn.data['show'] = False
exit_btn.visible = False
if not pokemon.data['iswithdrawn']:
withdraw_pokemon()
time.sleep(delay)
page.window_close()
def on_hover(is_hovered):
if is_hovered.data == "true" and exit_btn.data['show']:
exit_btn.visible = True
else:
exit_btn.visible = False
page.update()
def on_focused(window_event):
if window_event.data == "focus":
background_container.border = ft.border.all(2, ft.colors.WHITE)
background_container.bgcolor = "#262626"
else:
background_container.border = None
background_container.bgcolor = None
page.update()
pokemon = ft.Image(
src=ball_img,
fit=ft.ImageFit.CONTAIN, animate_opacity=500, opacity=0,
width=pokemon_pil.width*1.5,
height=pokemon_pil.height*1.5,
data={'iswithdrawn':True}
)
background_container = ft.Container(
content=pokemon,
on_long_press=run,
left=0,
border_radius=5,
border=ft.border.all(2, ft.colors.WHITE),
bgcolor="#262626"
)
exit_btn = ft.IconButton(
icon=ft.icons.CLOSE,
on_click=lambda _: exit_app(),
visible=False,
bgcolor=ft.colors.RED_ACCENT,
icon_color=ft.colors.WHITE, icon_size=10,
width=28, height=28,
data={'show':False}
)
app_content = ft.Stack(
[
background_container,
ft.Container(
content=exit_btn,
right=0
),
],
width=page.window_width, height=page.window_height
)
page.add(
ft.WindowDragArea(
content=ft.Container(
content=app_content,
on_hover=on_hover
)
)
)
#A hack to apply and respect the window properties
page.window_visible = True
page.update()
run()
page.on_window_event = on_focused
ft.app(target=main, assets_dir="assets", name="Poke-DeskBuddy")