From bd70c4a24a183cd40ad4a6981c0ac3229e9b1ef6 Mon Sep 17 00:00:00 2001 From: Mykola Grymalyuk Date: Sun, 7 May 2023 13:29:13 -0600 Subject: [PATCH] GUI: Add error handling for object deletion --- resources/wx_gui/gui_build.py | 1 - resources/wx_gui/gui_entry.py | 7 ++++--- resources/wx_gui/gui_menubar.py | 14 -------------- resources/wx_gui/gui_support.py | 11 +++++++++++ resources/wx_gui/gui_sys_patch.py | 8 ++++---- 5 files changed, 19 insertions(+), 22 deletions(-) delete mode 100644 resources/wx_gui/gui_menubar.py diff --git a/resources/wx_gui/gui_build.py b/resources/wx_gui/gui_build.py index d0cbfbc5c..13b5365c8 100644 --- a/resources/wx_gui/gui_build.py +++ b/resources/wx_gui/gui_build.py @@ -97,7 +97,6 @@ class BuildFrame(wx.Frame): ) dialog.SetYesNoLabels("Install to disk", "View build log") - self.on_install() if dialog.ShowModal() == wx.ID_YES else self.install_button.Enable() diff --git a/resources/wx_gui/gui_entry.py b/resources/wx_gui/gui_entry.py index 45c394fd1..9d3269320 100644 --- a/resources/wx_gui/gui_entry.py +++ b/resources/wx_gui/gui_entry.py @@ -7,9 +7,9 @@ from resources import constants from resources.wx_gui import ( gui_main_menu, gui_build, - gui_menubar, gui_install_oc, - gui_sys_patch + gui_sys_patch, + gui_support ) from resources.sys_patch import sys_patch_detect @@ -53,7 +53,8 @@ class EntryPoint: screen_location=None, **({"patches": patches} if "--gui_patch" in sys.argv or "--gui_unpatch" in sys.argv else {}) ) - self.frame.SetMenuBar(gui_menubar.GenerateMenubar().generate()) + if self.frame: + self.frame.SetMenuBar(gui_support.GenerateMenubar().generate()) atexit.register(self.OnCloseFrame) if "--gui_patch" in sys.argv: diff --git a/resources/wx_gui/gui_menubar.py b/resources/wx_gui/gui_menubar.py deleted file mode 100644 index c1a1e9b19..000000000 --- a/resources/wx_gui/gui_menubar.py +++ /dev/null @@ -1,14 +0,0 @@ -# Generates menubar for wxPython to use - -import wx - -class GenerateMenubar: - - def __init__(self) -> None: - self.menubar: wx.MenuBar = None - - - def generate(self) -> wx.MenuBar: - self.menubar = wx.MenuBar() - - return self.menubar \ No newline at end of file diff --git a/resources/wx_gui/gui_support.py b/resources/wx_gui/gui_support.py index d4e029e12..535be2013 100644 --- a/resources/wx_gui/gui_support.py +++ b/resources/wx_gui/gui_support.py @@ -10,6 +10,17 @@ from pathlib import Path from resources import constants +class GenerateMenubar: + + def __init__(self) -> None: + self.menubar: wx.MenuBar = None + + + def generate(self) -> wx.MenuBar: + self.menubar = wx.MenuBar() + return self.menubar + + class PayloadMount: def __init__(self, global_constants: constants.Constants, frame: wx.Frame) -> None: diff --git a/resources/wx_gui/gui_sys_patch.py b/resources/wx_gui/gui_sys_patch.py index 104323f5d..8c2bcbbb1 100644 --- a/resources/wx_gui/gui_sys_patch.py +++ b/resources/wx_gui/gui_sys_patch.py @@ -36,13 +36,12 @@ class SysPatchMenu(wx.Frame): self.return_button: wx.Button = None self.frame_modal = wx.Dialog(self, title=title, size=(360, 200)) + self.SetPosition(screen_location) if screen_location else self.Centre() if patches: return self._generate_elements_display_patches(self.frame_modal, patches) - - self.SetPosition(screen_location) if screen_location else self.Centre() self.frame_modal.ShowWindowModal() @@ -260,8 +259,9 @@ class SysPatchMenu(wx.Frame): else: if patches["Validation: Patching Possible"] is False: start_button.Disable() - if patches["Validation: Unpatching Possible"] is False: - revert_button.Disable() + if can_unpatch is False: + revert_button.Disable() + # Relaunch as root if not root uid = os.geteuid()