From 63118d7d43b958ba444ef16e1a871c6209bf1043 Mon Sep 17 00:00:00 2001 From: Mykola Grymalyuk Date: Thu, 12 May 2022 11:46:53 -0600 Subject: [PATCH] gui_main.py: Add work-around for broke pulse() on non-Metal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Applicable for non-Metal Macs running Monterey, NSProgressBar’s indeterminate function is broken when called by wxWidgets/wxPython --- gui/gui_main.py | 30 +++++++++++++++++++++++++++--- resources/constants.py | 1 + resources/defaults.py | 1 + 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/gui/gui_main.py b/gui/gui_main.py index fef81c610..5dc558f31 100644 --- a/gui/gui_main.py +++ b/gui/gui_main.py @@ -30,6 +30,8 @@ class wx_python_gui: self.finished_auto_patch = False self.finished_cim_process = False self.target_disk = "" + self.pulse_forward = False + self.non_metal_required = self.use_non_metal_alternative() # Backup stdout for usage with wxPython self.stock_stdout = sys.stdout @@ -98,6 +100,26 @@ class wx_python_gui: self.frame.SetSize(self.WINDOW_WIDTH_MAIN, self.WINDOW_HEIGHT_MAIN) sys.stdout = self.stock_stdout sys.stderr = self.stock_stderr + + def use_non_metal_alternative(self): + if self.constants.detected_os >= os_data.os_data.monterey: + if self.constants.host_is_non_metal is True: + return True + return False + + def pulse_alternative(self, progress_bar): + if self.non_metal_required is True: + if progress_bar.GetValue() == 0: + self.pulse_forward = True + + elif progress_bar.GetValue() == 100: + self.pulse_forward = False + + if self.pulse_forward: + progress_bar.SetValue(progress_bar.GetValue() + 1) + else: + progress_bar.SetValue(progress_bar.GetValue() - 1) + time.sleep(0.005) def preflight_check(self): if ( @@ -626,10 +648,11 @@ class wx_python_gui: thread_disk = threading.Thread(target=get_disks) thread_disk.start() + self.progress_bar.Pulse() while thread_disk.is_alive(): - self.progress_bar.Pulse() + self.pulse_alternative(self.progress_bar) wx.GetApp().Yield() self.progress_bar.Destroy() list_disks = self.list_disks @@ -1186,6 +1209,7 @@ class wx_python_gui: ) ) self.progress_bar.Centre(wx.HORIZONTAL) + self.progress_bar.Pulse() self.return_to_main_menu = wx.Button(self.frame, label="Return to Main Menu") @@ -1212,7 +1236,7 @@ class wx_python_gui: thread_ia.start() while thread_ia.is_alive(): - self.progress_bar.Pulse() + self.pulse_alternative(self.progress_bar) wx.GetApp().Yield() available_installers = self.available_installers else: @@ -1432,8 +1456,8 @@ class wx_python_gui: self.verifying_chunk_label.Centre(wx.HORIZONTAL) thread_install = threading.Thread(target=installer.install_macOS_installer, args=(self.constants.payload_path,)) thread_install.start() + self.progress_bar.Pulse() while thread_install.is_alive(): - self.progress_bar.Pulse() wx.App.Get().Yield() self.progress_bar.SetValue(self.progress_bar.GetRange()) diff --git a/resources/constants.py b/resources/constants.py index 2413407ef..31afdc6a0 100644 --- a/resources/constants.py +++ b/resources/constants.py @@ -187,6 +187,7 @@ class Constants: self.root_patcher_succeded = False # Determine if root patcher succeeded self.booted_oc_disk = None # Determine current disk OCLP booted from self.start_build_install = False # Determine if build install should be started + self.host_is_non_metal = False # Determine if host is non-metal (ie. enable UI hacks) self.legacy_accel_support = [ os_data.os_data.big_sur, diff --git a/resources/defaults.py b/resources/defaults.py index ac11bde2a..58af072f3 100644 --- a/resources/defaults.py +++ b/resources/defaults.py @@ -38,6 +38,7 @@ class generate_defaults: settings.secure_status = False settings.sip_status = False settings.allow_fv_root = True + settings.host_is_non_metal = True if settings.computer.gpus: for gpu in settings.computer.gpus: if gpu.arch == device_probe.NVIDIA.Archs.Kepler: