-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from uzair-ashraf/uzair/add-a-gui
Setup UI, Intensity based muscle groups, 1.0.0 release
- Loading branch information
Showing
16 changed files
with
568 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,63 @@ | ||
import json | ||
import params | ||
import os | ||
import json | ||
|
||
|
||
class Config: | ||
def __init__(self, server_port: int, owo_ip: str, intensity: int, frequency: int): | ||
self.server_port = server_port | ||
self.owo_ip = owo_ip | ||
self.intensity = intensity | ||
self.frequency = frequency | ||
def __init__(self): | ||
self.APP_NAME = 'VRChatOWOSuit' | ||
self.default_config = { | ||
"server_port": 9001, | ||
"owo_ip": "", | ||
"should_detect_ip": True, | ||
"should_connect_on_startup": False, | ||
"frequency": 100, | ||
"intensities": { | ||
params.owo_suit_Pectoral_L: 60, | ||
params.owo_suit_Pectoral_R: 60, | ||
params.owo_suit_Abdominal_L: 60, | ||
params.owo_suit_Abdominal_R: 60, | ||
params.owo_suit_Arm_L: 60, | ||
params.owo_suit_Arm_R: 60, | ||
params.owo_suit_Dorsal_L: 60, | ||
params.owo_suit_Dorsal_R: 60, | ||
params.owo_suit_Lumbar_L: 60, | ||
params.owo_suit_Lumbar_R: 60, | ||
} | ||
} | ||
self.current_config = None | ||
|
||
def get_by_key(self, key: str): | ||
return self.current_config.get(key) | ||
|
||
def update(self, key: str, nextValue): | ||
if (key in self.current_config): | ||
self.current_config[key] = nextValue | ||
|
||
def read_config_from_disk(self): | ||
appdata_path = os.environ.get('LOCALAPPDATA') | ||
app_directory = os.path.join(appdata_path, self.APP_NAME) | ||
os.makedirs(app_directory, exist_ok=True) | ||
config_path = os.path.join(app_directory, 'config.json') | ||
if os.path.exists(config_path): | ||
with open(config_path, 'r') as file: | ||
data = json.load(file) | ||
return data | ||
else: | ||
with open(config_path, 'w') as file: | ||
json.dump(self.default_config, file, indent=4) | ||
return self.default_config | ||
|
||
def write_config_to_disk(self): | ||
if self.current_config == None: | ||
return | ||
appdata_path = os.environ.get('LOCALAPPDATA') | ||
app_directory = os.path.join(appdata_path, self.APP_NAME) | ||
os.makedirs(app_directory, exist_ok=True) | ||
config_path = os.path.join(app_directory, 'config.json') | ||
with open(config_path, 'w') as file: | ||
json.dump(self.current_config, file, indent=4) | ||
|
||
def get() -> Config: | ||
server_port = 9001 | ||
owo_ip = "" | ||
intensity = 10 | ||
frequency = 100 | ||
try: | ||
f = open('./vrc-owo-suit.config.json') | ||
data = json.load(f) | ||
f.close() | ||
if ("server_port" in data and type(data['server_port']) is int): | ||
print(f"Using server_port {data['server_port']}.") | ||
server_port = data['server_port'] | ||
if ("owo_ip" in data and type(data['owo_ip']) is str): | ||
print(f"Using owo_ip {data['owo_ip']}.") | ||
owo_ip = data['owo_ip'] | ||
if ("intensity" in data and type(data['intensity']) is int): | ||
print(f"Using intensity {data['intensity']}.") | ||
intensity = data['intensity'] | ||
if ("frequency" in data and type(data['frequency']) is int): | ||
print(f"Using frequency {data['frequency']}.") | ||
frequency = data['frequency'] | ||
except: | ||
print("Config file not found, using default settings") | ||
finally: | ||
return Config(server_port, owo_ip, intensity, frequency) | ||
def init(self): | ||
self.current_config = self.read_config_from_disk() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import atexit | ||
from concurrent.futures import ThreadPoolExecutor | ||
|
||
|
||
class Event: | ||
def __init__(self, max_workers=3): | ||
self.listeners = [] | ||
self.executor = ThreadPoolExecutor(max_workers=max_workers) | ||
atexit.register(self.executor.shutdown) | ||
|
||
def add_listener(self, func): | ||
self.listeners.append(func) | ||
|
||
def remove_listener(self, func): | ||
self.listeners.remove(func) | ||
|
||
def dispatch(self, *args, **kwargs): | ||
for listener in self.listeners: | ||
self.executor.submit(listener, *args, **kwargs) |
Oops, something went wrong.