-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.pyw
More file actions
169 lines (124 loc) · 4.2 KB
/
main.pyw
File metadata and controls
169 lines (124 loc) · 4.2 KB
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
from functools import wraps
from os import path
from traceback import format_exc
from typing import Callable, Literal, ParamSpec, TypeVar
from webview import SAVE_DIALOG, create_window, start
P = ParamSpec("P")
R = TypeVar("R")
def handle_api_errors(func: Callable[P, R]) -> Callable[P, R]:
@wraps(func)
def wrapper(*args: P.args, **kwargs: P.kwargs):
try:
return func(*args, **kwargs)
except Exception:
raise Exception(format_exc())
return wrapper
class Api:
@handle_api_errors
def getSystemInfo(self):
from py.PCI_IRQs import get_system_info
return get_system_info()
@handle_api_errors
def getDisplayInfo(self):
from py.DISPLAY_INFO import get_display_info
return get_display_info()
@handle_api_errors
def writeRegistryValue(
self,
hkey_str: Literal["HKLM", "HKCU"],
path: str,
name: str,
type: int,
value: int | str,
):
from py.utils import write_registry_value
write_registry_value(hkey_str, path, name, type, value)
@handle_api_errors
def deleteRegistryValue(
self, hkey_str: Literal["HKLM", "HKCU"], path: str, value: str
):
from py.utils import delete_registry_value
delete_registry_value(hkey_str, path, value)
@handle_api_errors
def deleteRegistryKey(self, path: str, key: str):
from py.utils import delete_registry_key
delete_registry_key(path, key)
@handle_api_errors
def createRegistryKey(self, path: str):
from py.utils import create_registry_key
create_registry_key(path)
@handle_api_errors
def openURL(self, url: str):
from webbrowser import open
open(url)
@handle_api_errors
def getIfeoData(self):
from py.IFEO import get_ifeo_data
return get_ifeo_data()
@handle_api_errors
def getSchedulingInfo(self):
from py.SCHEDULING import get_scheduling_info
return get_scheduling_info()
@handle_api_errors
def getPowerSettings(self):
from py.POWER_SETTINGS import get_power_settings
return get_power_settings()
@handle_api_errors
def writeValueIndex(
self,
scheme_guid_str: str,
subgroup_guid_str: str,
setting_guid_str: str,
value_index: int,
is_ac: bool,
):
from py.POWER_SETTINGS import write_value_index
write_value_index(
scheme_guid_str, subgroup_guid_str, setting_guid_str, value_index, is_ac
)
@handle_api_errors
def setActiveScheme(self, scheme_guid_str: str):
from py.POWER_SETTINGS import set_active_scheme
set_active_scheme(scheme_guid_str)
@handle_api_errors
def getCompatibilityOptions(self):
from py.COMPATIBILITY_OPTIONS import get_compatibility_options
return get_compatibility_options()
@handle_api_errors
def saveFile(self, file_name: str, file_types: tuple[str], content: str):
path = window.create_file_dialog(
SAVE_DIALOG,
directory="/",
save_filename=file_name,
file_types=file_types,
)
if path is None:
return
with open(str(path), "w", encoding="utf-8") as file:
file.write(content)
@handle_api_errors
def exportPowerScheme(self, guid: str, file_name: str, file_types: tuple[str]):
path = window.create_file_dialog(
SAVE_DIALOG,
directory="/",
save_filename=file_name,
file_types=file_types,
)
if path is None:
return
from subprocess import CREATE_NO_WINDOW, run
run(
["powercfg", "/export", str(path), guid],
check=True,
creationflags=CREATE_NO_WINDOW,
)
def on_shown():
window.maximize()
if __name__ == "__main__":
isDevEnv = not path.exists(path.join(path.dirname(__file__), "gui/index.html"))
entry_point = "http://localhost:5173/" if isDevEnv else "gui/index.html"
window = create_window(
"Windows MultiTool", entry_point, js_api=Api(), text_select=True
)
window.events.shown += on_shown
start(ssl=True, debug=isDevEnv)