-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.py
36 lines (27 loc) · 1.02 KB
/
utils.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
import logging
from PyQt5.QtCore import QRect
from PyQt5.QtWidgets import QApplication
def get_center_rect(rect):
w = min(rect.width(), rect.height())
center_x = (rect.left() + rect.right()) >> 1
center_y = (rect.top() + rect.bottom()) >> 1
return QRect(center_x - (w >> 1), center_y - (w >> 1), w, w)
def get_screen_center_rect(current_rect):
screen_center = QApplication.desktop().availableGeometry().center()
current_rect.moveCenter(screen_center)
return current_rect
def logging_wrap(func):
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except Exception as e:
print(e)
logging.exception(e)
return wrapper
def init_logging():
FILE_NAME = "log.txt"
file_handler = logging.FileHandler(FILE_NAME, encoding="utf-8")
FORMAT = "%(asctime)s %(filename)s[line:%(lineno)d]\t"\
"%(levelname)s\t%(message)s"
logging.basicConfig(handlers=[file_handler],
level=logging.INFO, format=FORMAT)