-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.py
231 lines (187 loc) · 8.42 KB
/
App.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# -*- coding: utf-8 -*-
"""
Created on Mon Jul 18 21:20:08 2022
@author: Dorian
"""
import os
import sys
import random
import time
import threading
from dotenv import load_dotenv
import pygame
from frames.LoadingFrame import LoadingFrame
from frames.OptubeFrame import OptubeFrame
from frames.ErrorFrame import ErrorFrame
from frames.SearchingFrame import SearchingFrame
from frames.SerieFrame import SerieFrame
from frames.MALRankingFrame import MALRankingFrame
from frames.SplashScreenFrame import SplashScreenFrame
import utils.mtTkinter as tk
from utils.DbManager import MongoDBManager
from utils.FileManager import FileManager, DIR_IMG_ICON
from utils.utils import *
from pymongo.mongo_client import MongoClient
from pymongo.server_api import ServerApi
import clr
import certifi
clr.AddReference('System.Windows.Forms')
clr.AddReference('System.Threading')
from System.Windows.Forms import Control
from System.Threading import Thread, ApartmentState, ThreadStart
from tkwebview2.tkwebview2 import have_runtime, install_runtime
class App(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
# source : https://yagisanatode.com/2018/02/24/how-to-center-the-main-window-on-the-screen-in-tkinter-with-python-3/
# Gets the requested values of the height and width.
windowWidth = 1100
windowHeight = 534
# Gets both half the screen width/height and window width/height
positionRight = int(self.winfo_screenwidth()/2 - windowWidth/2)
positionDown = int(self.winfo_screenheight()/3 - windowHeight/2)
# Positions the window in the center of the page.
self.geometry("{}x{}+{}+{}".format(windowWidth, windowHeight, positionRight, positionDown))
self.resizable(False, False)
self.iconbitmap(DIR_IMG_ICON + 'icon.ico')
self.title('Otaku Apuri (v1.2.6)')
self.series_available_sushiscan = []
self.series_available_manganato = []
self.current_frame = None
self.mongoclient = MongoClient("mongodb+srv://"+os.getenv('USER_PYMONGO')+":"+os.getenv('PASS_PYMONGO')+"@getmangacluster.zmh5nne.mongodb.net/?retryWrites=true&w=majority",
server_api=ServerApi('1'), tlsCAFile=certifi.where())
self.show_splashscreen_frame()
def set_series_available(self, source="sushiscan"):
self.series_available_sushiscan = MongoDBManager.get_all_series_pymongo(self.mongoclient, "sushiscan")
time.sleep(1)
self.series_available_manganato = MongoDBManager.get_all_series_pymongo(self.mongoclient, "manganato")
print("Manganato", len(self.series_available_manganato))
print("Sushiscan", len(self.series_available_sushiscan))
def show_searching_frame(self):
"""Show the SearchingFrame
"""
if self.current_frame :
# Supprimer tous les widgets enfants de la video_frame
for child in self.current_frame.winfo_children():
child.destroy()
self.current_frame.destroy()
self.current_frame = SearchingFrame(parent=self)
self.current_frame.pack(expand=True, fill="both")
self.title("Otaku Apuri (v1.2.6)")
def show_splashscreen_frame(self):
"""Show the SplashScreenFrame
"""
if self.current_frame :
# Supprimer tous les widgets enfants de la video_frame
for child in self.current_frame.winfo_children():
child.destroy()
self.current_frame.destroy()
self.current_frame = SplashScreenFrame(parent=self)
self.current_frame.pack(expand=True, fill="both")
def show_optube_frame(self):
"""Show the OptubeFrame
"""
if self.current_frame :
self.current_frame.mediaplayer.stop()
# Supprimer tous les widgets enfants de la video_frame
for child in self.current_frame.winfo_children():
child.destroy()
self.current_frame.destroy()
self.current_frame = OptubeFrame(parent=self, app=self)
self.current_frame.pack(expand=True, fill="both")
self.current_frame.splash_screen()
def show_loading_frame(self):
"""Show the LoadingFrame
- A quote is chose randomly
- If while the loading bar is animated
"""
if self.current_frame :
# Supprimer tous les widgets enfants de la video_frame
for child in self.current_frame.winfo_children():
child.destroy()
self.current_frame.destroy()
quote = random.choice(quotes_anime)
self.current_frame = LoadingFrame(parent=self, quote_txt=quote)
self.current_frame.pack(expand=True, fill="both")
if len(self.series_available_sushiscan) == 0:
thread = threading.Thread(target=self.set_series_available, daemon=True)
thread.start()
self.current_frame.animate()
def show_serie_frame(self, serie):
"""_summary_
Args:
serie (_type_): _description_
"""
if self.current_frame :
if type(self.current_frame) == SearchingFrame:
self.current_frame.mediaplayer.stop()
# Supprimer tous les widgets enfants de la video_frame
for child in self.current_frame.winfo_children():
child.destroy()
self.current_frame.destroy()
self.current_frame = SerieFrame(parent=self, serie_obj=serie)
self.current_frame.pack(expand=True, fill="both")
self.title(self.current_frame.serie_obj.titre)
def show_malranking_frame(self):
"""_summary_
"""
if self.current_frame :
self.current_frame.mediaplayer.stop()
# Supprimer tous les widgets enfants de la video_frame
for child in self.current_frame.winfo_children():
child.destroy()
self.current_frame.destroy()
self.current_frame = MALRankingFrame(parent=self, app=self)
self.current_frame.pack(expand=True, fill="both")
self.title("Top Manga - MyAnimeList.net")
def show_error_frame(self, error_msg):
"""_summary_
Args:
error_msg (_type_): _description_
"""
if self.current_frame :
# Supprimer tous les widgets enfants de la video_frame
for child in self.current_frame.winfo_children():
child.destroy()
self.current_frame.destroy()
self.current_frame = ErrorFrame(parent=self, error_txt=error_msg)
self.current_frame.pack(expand=True, fill="both")
self.title("Error")
###########
# TODO : revoir la gestion du pygame pour la musique etc...
# TODO : revoir la gestion du message d'erreur internet (position du bouton relancer showloading et showsearching)
# TODO : revoir la recherche via MAL (score doit être minimum de 10 sinon ce n'est pas le bon résultat)
# TODO : revoir la pipeline ETL pour MAL pour inclure les stats
# TODO : revoir les séries qui n'ont pas VOLUMES ou CHAPITRES
# TODO : revoir l'aspect graphique de l'application
# TODO : revoir l'onglet Stats
# TODO : essayer d'avoir des onglets de couleurs différentes
# TODO : Gérer toutes les exceptions
# TODO : Paginer les chapitres volumes
def main():
extDataDir = os.getcwd()
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
# sys._MEIPASS = C:\Users\xxxx\AppData\Local\Temp\_MEIxxxxxx
os.chdir(sys._MEIPASS)
extDataDir = sys._MEIPASS
# https://github.com/pyinstaller/pyinstaller/issues/5522#issuecomment-770858489
load_dotenv(dotenv_path=os.path.join(extDataDir, '.env'))
if not have_runtime():#没有webview2 runtime
print("install")
install_runtime()
thread_create_folders = threading.Thread(target=FileManager.create_tmp_folders, daemon=True)
thread_create_folders.start()
app = App()
app.mainloop()
if isinstance(app.current_frame, SerieFrame):
app.current_frame.frame_anime.stop(quit=True)
if isinstance(app.current_frame, OptubeFrame):
app.current_frame.quit()
app.mongoclient.close()
FileManager.delete_tmp_files()
pygame.quit()
if __name__ == "__main__":
t = Thread(ThreadStart(main))
t.ApartmentState = ApartmentState.STA
t.Start()
t.Join()