Skip to content

Commit

Permalink
fix infinie loop
Browse files Browse the repository at this point in the history
  • Loading branch information
yskeno committed Mar 8, 2023
1 parent d5c15f7 commit 6aa5f5d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 32 deletions.
4 changes: 2 additions & 2 deletions WwiseAuthoringUtility.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ def main():
window.mainloop()

except CannotConnectToWaapiException as e:
window.show_error("CannotConnectToWaapiException",
window.result_error("CannotConnectToWaapiException",
f"{str(e)}\nIs Wwise running and Wwise Authoring API enabled?")

except Exception as e:
print(f'ERROR: {str(e)}')
window.show_error("ERROR", str(e))
window.result_error("ERROR", str(e))


if __name__ == "__main__":
Expand Down
8 changes: 3 additions & 5 deletions WwiseUtilityGUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
import tkinter.messagebox
import tkinter.ttk as ttk

from WwiseUtilityInterface import WwiseUtilityClient


class MainWindow(tkinter.Tk):
def __init__(self):
super().__init__()
self.withdraw()

self.client: WwiseUtilityClient = None
self.client = None

self.title("Wwise Authoring Utility")
self.iconbitmap(sys.executable)
Expand Down Expand Up @@ -47,13 +45,13 @@ def show_simple_info(self, title, message):
print(f"INFO: {title}: {message}")
tkinter.messagebox.showinfo(title, message, parent=self)

def show_warning(self, title, message):
def result_warning(self, title, message):
print(f"WARNING: {title}: {message}")
self.withdraw()
tkinter.messagebox.showwarning(title, message, parent=self)
self.close_window()

def show_error(self, title, message):
def result_error(self, title, message):
print(f"ERROR: {title}: {message}")
self.withdraw()
tkinter.messagebox.showerror(title, message, parent=self)
Expand Down
58 changes: 33 additions & 25 deletions WwiseUtilityInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,30 @@
import re

from waapi import WaapiClient, CannotConnectToWaapiException
from WwiseUtilityGUI import MainWindow


class WwiseUtilityClient(WaapiClient):

def _get_selected_objects_guid(self, type=''):
selected = self.call("ak.wwise.ui.getSelectedObjects", {
'options': {'return': ['id', 'name', 'type']}})['objects']
'options': {'return': ['id', 'type']}})['objects']
if type == '':
return tuple(v for d in selected for k, v in d.items() if k == 'id')
else:
return tuple(v for d in selected if d['type'] == type
for k, v in d.items() if k == 'id')

def _get_name_from_guid(self, guids):
def _get_name_from_guid(self, guids: tuple):
objects = self.call("ak.wwise.core.object.get",
{"from": {"id": guids},
{"from": {"id": list(guids)},
"options": {"return": ['name']}})['return']
return [obj['name'] for obj in objects]
return tuple(obj['name'] for obj in objects)

def connect_to_localhost(self, window):
def connect_to_localhost(self, window: MainWindow):
window.after_idle(lambda: window.set_current_process(
20, 'Get Connection Status...'))
connection_status = self.call(
connection_status: dict = self.call(
'ak.wwise.core.remote.getConnectionStatus')

# --- Connect to Localhost ---
Expand All @@ -42,7 +43,6 @@ def connect_to_localhost(self, window):
item for item in available_consoles['consoles'] if item['host'] == '127.0.0.1']
if len(local_consoles) == 0:
window.show_error('Error', 'Localhost was not found.')
self.disconnect()
return

# Select Localhost to connect.
Expand Down Expand Up @@ -75,9 +75,9 @@ def connect_to_localhost(self, window):
window.after_idle(lambda: window.set_current_process(
100, 'Disconnected.'))

self.disconnect()
window.close_window()

def auto_rename_container(self, window):
def auto_rename_container(self, window: MainWindow):
guids = self._get_selected_objects_guid()

failed_ids = set()
Expand All @@ -87,28 +87,31 @@ def auto_rename_container(self, window):
"transform": [{"select": ['children']}],
"options": {"return": ['name']}})['return']
if children is None:
failed_ids.append(guid)
failed_ids.add(guid)
continue

names = list(map(lambda object: object['name'], children))
common_name = os.path.commonprefix(names).rstrip('_ -0')

if not common_name:
container = self.call("ak.wwise.core.object.get",
{"from": {"id": [guid]},
"options": {"return": ['name']}})['return']
failed_ids.append(container[0]['name'])
failed_ids.add(guid)
continue

self.call("ak.wwise.core.object.setName", {
"object": guid, "value": common_name})

if len(failed_ids) > 0:
window.show_warning(
'Partially Complete', f'Complete but following container(s) wasn\'t renamed:\n No common prefix found.\n{failed_ids}')
window.close_window()
if len(failed_ids) == len(guids):
window.result_error(
'Auto rename failed', f"Could not rename object(s):\n\n Check using common words between children's object.")
else:
failed_names = '\n'.join(
self._get_name_from_guid(tuple(failed_ids)))
window.result_warning(
'Complete with Warning', f"Complete but following container(s) wasn\'t renamed:\n\n{failed_names}")
else:
window.close_window()

def auto_assign_switch_container(self, window):
def auto_assign_switch_container(self, window: MainWindow):
guids = self._get_selected_objects_guid(type='SwitchContainer')

failed_ids = set()
Expand Down Expand Up @@ -165,15 +168,20 @@ def auto_assign_switch_container(self, window):

if len(failed_ids) > 0:
if len(failed_ids) == len(guids):
window.show_error(
'Switch Assignment Incomplete', f"Could not assign object(s):\n\n Check SwitchContainer's State/Switch Group\n and use common words between object and state.")
window.result_error(
'Switch Assignment Not Complete', f"Could not assign object(s):\n\n Check SwitchContainer's State/Switch Group\n and use common words between object and state.")
else:
failed_names = '\n'.join(
self._get_name_from_guid(list(failed_ids)))
window.show_warning(
self._get_name_from_guid(tuple(failed_ids)))
window.result_warning(
'Complete with Warning', f"Finished but following object(s) wasn't assigned:\n\n{failed_names}")
window.close_window()
else:
window.close_window()

def custom_assign_switch_container(self, window):
# TODO:Write function.
pass

def auto_trim_wavefile(self, window, *guid):
def auto_trim_wavefile(self, window):
# TODO:Write function.
pass

0 comments on commit 6aa5f5d

Please sign in to comment.