Skip to content

Commit 7a67ecc

Browse files
committed
ran it through a formater
1 parent 5cced6e commit 7a67ecc

File tree

2 files changed

+89
-34
lines changed

2 files changed

+89
-34
lines changed

BabbleApp/babbleapp.py

Lines changed: 84 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,16 @@
4040

4141
winmm = None
4242

43-
if os_type == 'Windows':
43+
if os_type == "Windows":
4444
try:
4545
from ctypes import windll
46+
4647
winmm = windll.winmm
4748
except OSError:
48-
print(f'\033[91m[{lang._instance.get_string("log.error")}] {lang._instance.get_string("error.winmm")}.\033[0m')
49-
49+
print(
50+
f'\033[91m[{lang._instance.get_string("log.error")}] {lang._instance.get_string("error.winmm")}.\033[0m'
51+
)
52+
5053
os.system("color") # init ANSI color
5154

5255
# Random environment variable to speed up webcam opening on the MSMF backend.
@@ -55,13 +58,16 @@
5558
page_url = "https://github.com/Project-Babble/ProjectBabble/releases/latest"
5659
appversion = "Babble v2.0.7"
5760

61+
5862
def timerResolution(toggle):
5963
if winmm != None:
6064
if toggle:
6165
rc = c_int(winmm.timeBeginPeriod(1))
6266
if rc.value != 0:
6367
# TIMEERR_NOCANDO = 97
64-
print(f'\033[93m[{lang._instance.get_string("log.warn")}] {lang._instance.get_string("warn.timerRes")} {rc.value}\033[0m')
68+
print(
69+
f'\033[93m[{lang._instance.get_string("log.warn")}] {lang._instance.get_string("warn.timerRes")} {rc.value}\033[0m'
70+
)
6571
else:
6672
winmm.timeEndPeriod(1)
6773

@@ -71,15 +77,17 @@ async def check_for_updates(config, notification_manager):
7177
try:
7278
response = requests.get(
7379
"https://api.github.com/repos/Project-Babble/ProjectBabble/releases/latest",
74-
timeout=10 # Add timeout
80+
timeout=10, # Add timeout
7581
)
7682
response.raise_for_status() # Will raise exception for HTTP errors
77-
83+
7884
data = response.json()
7985
latestversion = data.get("name")
80-
86+
8187
if not latestversion:
82-
print(f'[{lang._instance.get_string("log.warn")}] {lang._instance.get_string("babble.invalidVersionFormat")}')
88+
print(
89+
f'[{lang._instance.get_string("log.warn")}] {lang._instance.get_string("babble.invalidVersionFormat")}'
90+
)
8391
return
8492

8593
if appversion == latestversion:
@@ -90,16 +98,27 @@ async def check_for_updates(config, notification_manager):
9098
print(
9199
f'\033[93m[{lang._instance.get_string("log.info")}] {lang._instance.get_string("babble.needUpdateOne")} [{appversion}] {lang._instance.get_string("babble.needUpdateTwo")} [{latestversion}] {lang._instance.get_string("babble.needUpdateThree")}.\033[0m'
92100
)
93-
await notification_manager.show_notification(appversion, latestversion, page_url)
94-
101+
await notification_manager.show_notification(
102+
appversion, latestversion, page_url
103+
)
104+
95105
except requests.exceptions.Timeout:
96-
print(f'[{lang._instance.get_string("log.info")}] {lang._instance.get_string("babble.updateTimeout")}')
106+
print(
107+
f'[{lang._instance.get_string("log.info")}] {lang._instance.get_string("babble.updateTimeout")}'
108+
)
97109
except requests.exceptions.HTTPError as e:
98-
print(f'[{lang._instance.get_string("log.info")}] {lang._instance.get_string("babble.updateHttpError")}: {e}')
110+
print(
111+
f'[{lang._instance.get_string("log.info")}] {lang._instance.get_string("babble.updateHttpError")}: {e}'
112+
)
99113
except requests.exceptions.ConnectionError:
100-
print(f'[{lang._instance.get_string("log.info")}] {lang._instance.get_string("babble.noInternet")}')
114+
print(
115+
f'[{lang._instance.get_string("log.info")}] {lang._instance.get_string("babble.noInternet")}'
116+
)
101117
except Exception as e:
102-
print(f'[{lang._instance.get_string("log.info")}] {lang._instance.get_string("babble.updateCheckFailed")}: {e}')
118+
print(
119+
f'[{lang._instance.get_string("log.info")}] {lang._instance.get_string("babble.updateCheckFailed")}: {e}'
120+
)
121+
103122

104123
class ThreadManager:
105124
def __init__(self, cancellation_event):
@@ -121,7 +140,11 @@ def shutdown_all(self, timeout=5.0):
121140

122141
# Call shutdown methods on associated objects if available
123142
for thread, shutdown_obj in self.threads:
124-
if shutdown_obj and hasattr(shutdown_obj, 'shutdown') and callable(shutdown_obj.shutdown):
143+
if (
144+
shutdown_obj
145+
and hasattr(shutdown_obj, "shutdown")
146+
and callable(shutdown_obj.shutdown)
147+
):
125148
try:
126149
self.logger.debug(f"Calling shutdown on {shutdown_obj}")
127150
shutdown_obj.shutdown()
@@ -131,16 +154,21 @@ def shutdown_all(self, timeout=5.0):
131154
# Join threads with the specified timeout
132155
for thread, _ in self.threads:
133156
if thread.is_alive():
134-
self.logger.debug(f"Joining thread: {thread.name} with timeout {timeout}s")
157+
self.logger.debug(
158+
f"Joining thread: {thread.name} with timeout {timeout}s"
159+
)
135160
thread.join(timeout=timeout)
136161

137162
# Remove terminated threads from the list
138163
self.threads = [(t, s) for t, s in self.threads if t.is_alive()]
139164

140165
if self.threads:
141-
self.logger.warning(f"{len(self.threads)} threads still alive: {[t.name for t, _ in self.threads]}")
166+
self.logger.warning(
167+
f"{len(self.threads)} threads still alive: {[t.name for t, _ in self.threads]}"
168+
)
142169
else:
143-
self.logger.info("All threads terminated successfully")
170+
self.logger.info("All threads terminated successfully")
171+
144172

145173
async def async_main():
146174
ensurePath()
@@ -153,13 +181,13 @@ async def async_main():
153181
lang("Locale", config.settings.gui_language)
154182

155183
config.save()
156-
184+
157185
notification_manager = NotificationManager()
158186
await notification_manager.initialize()
159-
187+
160188
# Run the update check
161189
await check_for_updates(config, notification_manager)
162-
190+
163191
# Uncomment for low-level Vive Facial Tracker logging
164192
# logging.basicConfig(filename='BabbleApp.log', filemode='w', encoding='utf-8', level=logging.INFO)
165193

@@ -246,7 +274,17 @@ async def async_main():
246274
),
247275
],
248276
# Keep at bottom!
249-
[sg.Text(f'- - - {lang._instance.get_string("general.windowFocus")} - - -', key="-WINFOCUS-", background_color=bg_color_clear, text_color="#F0F0F0", justification="center", expand_x=True, visible=False)],
277+
[
278+
sg.Text(
279+
f'- - - {lang._instance.get_string("general.windowFocus")} - - -',
280+
key="-WINFOCUS-",
281+
background_color=bg_color_clear,
282+
text_color="#F0F0F0",
283+
justification="center",
284+
expand_x=True,
285+
visible=False,
286+
)
287+
],
250288
]
251289

252290
if config.cam_display_id in [Tab.CAM]:
@@ -261,36 +299,45 @@ async def async_main():
261299
# the cam needs to be running before it is passed to the OSC
262300
if config.settings.gui_ROSC:
263301
osc_receiver = VRChatOSCReceiver(cancellation_event, config, cams)
264-
osc_receiver_thread = threading.Thread(target=osc_receiver.run, name="OSCReceiverThread")
302+
osc_receiver_thread = threading.Thread(
303+
target=osc_receiver.run, name="OSCReceiverThread"
304+
)
265305
thread_manager.add_thread(osc_receiver_thread, shutdown_obj=osc_receiver)
266306
ROSC = True
267307

268308
# Create the window
269309
window = sg.Window(
270-
f"{AppConstants.VERSION}", layout, icon=os.path.join('Images', 'logo.ico'), background_color=bg_color_clear )
271-
310+
f"{AppConstants.VERSION}",
311+
layout,
312+
icon=os.path.join("Images", "logo.ico"),
313+
background_color=bg_color_clear,
314+
)
315+
272316
# Run the main loop
273317
await main_loop(window, config, cams, settings, thread_manager)
274-
318+
275319
# Cleanup after main loop exits
276320
timerResolution(False)
277-
print(f'\033[94m[{lang._instance.get_string("log.info")}] {lang._instance.get_string("babble.exit")}\033[0m')
321+
print(
322+
f'\033[94m[{lang._instance.get_string("log.info")}] {lang._instance.get_string("babble.exit")}\033[0m'
323+
)
324+
278325

279326
async def main_loop(window, config, cams, settings, thread_manager):
280327
tint = AppConstants.DEFAULT_WINDOW_FOCUS_REFRESH
281328
fs = False
282-
329+
283330
while True:
284331
event, values = window.read(timeout=tint)
285-
332+
286333
if event in ("Exit", sg.WIN_CLOSED):
287334
# Exit code here
288335
for cam in cams:
289336
cam.stop()
290337
thread_manager.shutdown_all()
291338
window.close()
292339
return
293-
340+
294341
try:
295342
# If window isn't in focus increase timeout and stop loop early
296343
if window.TKroot.focus_get():
@@ -322,7 +369,10 @@ async def main_loop(window, config, cams, settings, thread_manager):
322369
config.cam_display_id = Tab.CAM
323370
config.save()
324371

325-
elif values[UIConstants.SETTINGS_RADIO_NAME] and config.cam_display_id != Tab.SETTINGS:
372+
elif (
373+
values[UIConstants.SETTINGS_RADIO_NAME]
374+
and config.cam_display_id != Tab.SETTINGS
375+
):
326376
cams[0].stop()
327377
settings[1].stop()
328378
settings[2].stop()
@@ -371,13 +421,15 @@ async def main_loop(window, config, cams, settings, thread_manager):
371421
for setting in settings:
372422
if setting.started():
373423
setting.render(window, event, values)
374-
424+
375425
# Rather than await asyncio.sleep(0), yield control periodically
376426
await asyncio.sleep(0.001) # Small sleep to allow other tasks to rundef main():
377427
asyncio.run(async_main())
378428

429+
379430
def main():
380431
asyncio.run(async_main())
381432

433+
382434
if __name__ == "__main__":
383435
main()

BabbleApp/constants.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ class UIConstants:
1111
CALIB_SETTINGS_RADIO_NAME = "-CALIBSETTINGSRADIO-"
1212
WINDOW_FOCUS_KEY = "-WINFOCUS-"
1313

14+
1415
class AppConstants:
1516
VERSION = "Babble v2.0.7"
1617
GITHUB_REPO_URL = "https://github.com/Project-Babble/ProjectBabble/releases/latest"
17-
GITHUB_API_URL = "https://api.github.com/repos/Project-Babble/ProjectBabble/releases/latest"
18+
GITHUB_API_URL = (
19+
"https://api.github.com/repos/Project-Babble/ProjectBabble/releases/latest"
20+
)
1821
DEFAULT_WINDOW_FOCUS_REFRESH = 33
19-
UNFOCUSED_WINDOW_REFRESH = 100
22+
UNFOCUSED_WINDOW_REFRESH = 100

0 commit comments

Comments
 (0)