-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
81 lines (65 loc) · 2.46 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
from customtkinter import CTk
from tkinterdnd2.TkinterDnD import DnDWrapper, _require
from components import Navigation
from config.settings import AssetsImages, ScreenName
from screens import ScreenManager
from services.authServiceImpl import AuthServiceImpl
class App(CTk, DnDWrapper):
width: int = 1280
height: int = 720
def __init__(self) -> None:
super().__init__()
self.TkdndVersion = _require(self)
self.title("EasyCard")
self.iconbitmap(AssetsImages.ICON)
self.minsize(800, 600)
self._center_window()
self.authService = AuthServiceImpl()
self.currentScreen = ScreenName.DASHBOARD if self.is_authenticate() else ScreenName.LOGIN
self.navigation = Navigation(self, height=self._current_height)
self.screenManager = ScreenManager(
self,
authService=self.authService,
width=self._current_width - self.navigation.width,
height=self._current_height,
)
self.navigation.pack(side="left", fill="y")
self.screenManager.pack(side="right", fill="both", expand=True)
def _center_window(self) -> None:
"""Center the application window on the screen."""
self.update_idletasks()
x = (self.winfo_screenwidth() // 2) - (self.width // 2)
y = (self.winfo_screenheight() // 2) - (self.height // 2)
self.geometry(f"{self.width}x{self.height}+{x}+{y}")
def set_title(self, title: str) -> None:
"""
Set the title of the application window.
Args:
title (str): The title to be set.
"""
self.title(f"EasyCard - {title}")
def navigate(self, screen: str) -> None:
"""
Navigate to a specific screen.
Args:
screen (str): The name of the screen to navigate to.
"""
self.navigation.navigate(screen)
def is_authenticate(self) -> bool:
"""
Check if the user is authenticated and return a boolean value.
"""
response = self.authService.verifyAPIKey()
return response.is_success
def logout(self) -> None:
"""
Log out the user and navigate to the login screen.
"""
self.authService.logout()
self.screenManager.apiKey.set("")
self.navigate(ScreenName.LOGIN)
def reRenderScreenManager(self) -> None:
"""
Re-render the screen manager.
"""
self.screenManager.reInitializeScreens()