import json import dearpygui.dearpygui as dpg from vrutil.utils import loaded, store _STEAM_VR_SETTINGS_FILE = '{steam_dir}/config/steamvr.vrsettings' class SteamVrSettings: """Steam VR related settings""" def __init__(self, steam_dir): self._settings_file_path = _STEAM_VR_SETTINGS_FILE.format(steam_dir=steam_dir) self._enable_vulkan_async_item = None def create_views(self): with dpg.collapsing_header(label='Steam VR', default_open=True): self._enable_vulkan_async_item = dpg.add_checkbox( label='enableLinuxVulkanAsync', default_value=self._is_vulkan_async_enabled(), callback=self._enable_vulkan_async, ) dpg.add_spacer(height=10) def reload(self, steam_dir=None): if steam_dir is not None: self._settings_file_path = _STEAM_VR_SETTINGS_FILE.format(steam_dir=steam_dir) dpg.set_value(self._enable_vulkan_async_item, self._is_vulkan_async_enabled()) def _is_vulkan_async_enabled(self): with open(self._settings_file_path, 'r') as f: data_content = json.load(f) enabled = data_content['steamvr']['enableLinuxVulkanAsync'] loaded('SteamVR enableLinuxVulkanAsync', enabled) return enabled def _enable_vulkan_async(self, _sender, enabled, _user_data): store('SteamVR enableLinuxVulkanAsync', enabled) with open(self._settings_file_path, 'r') as f: data_content = json.load(f) data_content['steamvr']['enableLinuxVulkanAsync'] = enabled with open(self._settings_file_path, 'w') as f: json.dump(data_content, f, indent=3, separators=(',', ' : ')) self.reload()