-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsicrypt.py
79 lines (58 loc) · 2.01 KB
/
sicrypt.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
from PySide6 import QtCore, QtWidgets
from typing import Any
#Утилитарные функции
def deepget(self: dict, key: str, default: Any = None, sep: str = '.'):
steps = key.split(sep)
fetched = self
for stepKey in steps:
fetched = fetched.get(stepKey, NotImplemented)
if (fetched is NotImplemented):
return default
return fetched
def deepupdate(self: dict, key: str, value: Any, sep: str = '.'):
pass
#Доступ к компонентам
def app() -> QtWidgets.QApplication:
return QtWidgets.QApplication.instance()
def tr(*args, **kwargs) -> str:
return app().translate(*args, **kwargs)
def log():
return app().log
def options(key: str = None, default: Any = None, sep: str = '.') -> dict | Any:
if (key):
return app().options(key, default, sep)
return app().options
def ui():
return app().ui
def hardware():
return app().hardware
def web() -> FastAPI:
return app().web
from inspection.logger import SicryptLogger
class SicryptComponent(object):
'''
Класс для большого количества похожих
друг на друга объектов, имеющих общие атрибуты имени и логгера.
'''
def __init__(
self,
name: str,
*args,
loggerName: str = '',
displayName: str = '',
**kwargs
) -> None:
super().__init__(*args, **kwargs) #устранение ошибки инициализации
self.name = name
self.displayName = displayName
self.logger = SicryptLogger(
loggerName if loggerName else
f'{name[0].capitalize()}{name[1:]}'
)
class SicryptWorker(QtCore.QThread):
def __init__(self, f) -> None:
super().__init__()
self.f = f
def run(self):
self.f()
super().run()