This repository has been archived by the owner on Jul 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gui_main.py
128 lines (96 loc) · 4.61 KB
/
gui_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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
__/\\\______________/\\\_____/\\\\\\\\\\\\__/\\\________/\\\_____________________________________________________________________
_\/\\\_____________\/\\\___/\\\//////////__\/\\\_______\/\\\_____________________________________________________________________
_\/\\\_____________\/\\\__/\\\_____________\//\\\______/\\\___/\\\_______________________________________________________________
_\//\\\____/\\\____/\\\__\/\\\____/\\\\\\\__\//\\\____/\\\___\///______/\\\\\\\\___/\\____/\\___/\\_____/\\\\\\\\___/\\/\\\\\\\__
__\//\\\__/\\\\\__/\\\___\/\\\___\/////\\\___\//\\\__/\\\_____/\\\___/\\\/////\\\_\/\\\__/\\\\_/\\\___/\\\/////\\\_\/\\\/////\\\_
___\//\\\/\\\/\\\/\\\____\/\\\_______\/\\\____\//\\\/\\\_____\/\\\__/\\\\\\\\\\\__\//\\\/\\\\\/\\\___/\\\\\\\\\\\__\/\\\___\///__
____\//\\\\\\//\\\\\_____\/\\\_______\/\\\_____\//\\\\\______\/\\\_\//\\///////____\//\\\\\/\\\\\___\//\\///////___\/\\\_________
_____\//\\\__\//\\\______\//\\\\\\\\\\\\/_______\//\\\_______\/\\\__\//\\\\\\\\\\___\//\\\\//\\\_____\//\\\\\\\\\\_\/\\\_________
______\///____\///________\////////////__________\///________\///____\//////////_____\///__\///_______\//////////__\///__________
"""
import ctypes
import logging
import os
import sys
from PyQt5.QtGui import QIcon, QFontDatabase
from PyQt5.QtWidgets import QApplication
from src.data import get_log_dir
from src.utils import get_app_version, get_today
from src.gui.login.form import LoginForm
def get_data_path(relative_path: str) -> str:
# This needs to be in current file
bundle_dir = getattr(sys, '_MEIPASS', os.path.abspath(os.path.dirname(__file__)))
res = os.path.join(bundle_dir, relative_path)
return relative_path if not os.path.exists(res) else res
def check_py_ver() -> None:
version = sys.version_info[0:3]
if version < (3, 6, 0):
sys.exit('WGViewer requires Python >= 3.6.0; your version of Python is ' + sys.version)
else:
pass
def init_app_settings() -> None:
WGV_APP.setWindowIcon(APP_ICON)
if sys.platform.startswith('win32'):
app_id = f'PWYQ.WarshipGirlsViewer.WGViewer.{get_app_version()}'
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(app_id)
else:
pass
# This property holds the base name of the desktop entry for this application
WGV_APP.setDesktopFileName("WGViewer")
WGV_APP.setApplicationVersion(get_app_version())
def init_fonts() -> None:
QFontDatabase().addApplicationFont(get_data_path('assets/fonts/Consolas.ttf'))
def init_logging() -> None:
_level = logging.DEBUG
_format = ' %(asctime)s - %(name)s - %(levelname)s - %(message)s'
_log_filename = f'wgviewer-{get_today()}.log'
_log_filepath = get_data_path(os.path.join(get_log_dir(), _log_filename))
_handlers = [logging.FileHandler(filename=_log_filepath, encoding='utf-8'), logging.StreamHandler()]
logging.basicConfig(level=_level, format=_format, handlers=_handlers)
def init_qsettings() -> None:
WGV_APP.setOrganizationName("WarshipGirls")
WGV_APP.setOrganizationDomain("https://github.com/WarshipGirls")
WGV_APP.setApplicationName("Warship Girls Viewer")
def _realrun() -> None:
login_form.show()
login_form.raise_()
def _testrun() -> None:
dev_warning = "\n\n==== TEST WARNING ====\n"
dev_warning += "In test run, api calls to server won't work!\n"
dev_warning += "In order to test offline, one real run (to get server data sample) is required!\n"
dev_warning += "==== WARNING END ====\n"
logging.warning(dev_warning)
mi.start_rendering()
# ================================
# Entry Point
# ================================
if __name__ == '__main__':
WGV_APP = QApplication([])
APP_ICON = QIcon(get_data_path('assets/favicon.ico'))
init_app_settings()
init_qsettings()
init_fonts()
# https://stackoverflow.com/q/43109355/14561914
init_logging()
logging.debug(f"\nWGViewer {get_app_version()} STARTS\n")
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
# running in a PyInstaller bundle
login_form = LoginForm()
_realrun()
else:
# running in a normal Python process
check_py_ver()
assert (len(sys.argv) == 2)
if int(sys.argv[1]):
login_form = LoginForm()
_realrun()
else:
from src.gui.main_interface import MainInterface
from src import data as wgr_data
mi = MainInterface(wgr_data.load_cookies(), None, False)
_testrun()
sys.exit(WGV_APP.exec_())
# End of File